| 1 | /*- |
| 2 | * Copyright (c) 1992 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This code is derived from software contributed to Berkeley by |
| 6 | * Rodney Ruddock of the University of Guelph. |
| 7 | * |
| 8 | * %sccs.include.redist.c% |
| 9 | */ |
| 10 | |
| 11 | #ifndef lint |
| 12 | static char sccsid[] = "@(#)l.c 5.1 (Berkeley) %G%"; |
| 13 | #endif /* not lint */ |
| 14 | |
| 15 | #include "ed.h" |
| 16 | |
| 17 | /* |
| 18 | * This is the list command. It's not wrapped in with n and p because |
| 19 | * of the unambiguous printing needed. |
| 20 | */ |
| 21 | |
| 22 | void |
| 23 | l(inputt, errnum) |
| 24 | |
| 25 | FILE *inputt; |
| 26 | int *errnum; |
| 27 | |
| 28 | { |
| 29 | int l_cnt, l_len=1; |
| 30 | |
| 31 | if (start_default && End_default) |
| 32 | start = End = current; |
| 33 | else if (start_default) |
| 34 | start = End; |
| 35 | |
| 36 | if (start == NULL) |
| 37 | { |
| 38 | strcpy(help_msg, "bad address"); |
| 39 | *errnum = -1; |
| 40 | return; |
| 41 | } |
| 42 | start_default = End_default = 0; |
| 43 | |
| 44 | if (rol(inputt, errnum)) /* for "command-suffix pairs" */ |
| 45 | return; |
| 46 | |
| 47 | current = start; |
| 48 | while (1) |
| 49 | { |
| 50 | /* print out the line character-by-character and split the line |
| 51 | * when line length is at line_length. |
| 52 | */ |
| 53 | if (sigint_flag) |
| 54 | SIGINT_ACTION; |
| 55 | if (current == NULL) |
| 56 | break; |
| 57 | get_line(current->handle, current->len); |
| 58 | for (l_cnt=0; l_cnt<current->len; l_cnt++) |
| 59 | { |
| 60 | /* check if line needs to be broken first */ |
| 61 | if ((l_len)%line_length == 0) |
| 62 | putchar('\n'); |
| 63 | /* print out the next character */ |
| 64 | if (text[l_cnt] == '\b') /* backspace (cntl-H) */ |
| 65 | fwrite("\\b", sizeof(char), 2, stdout); |
| 66 | else if (text[l_cnt] == '\t') /* horizontal tab */ |
| 67 | fwrite("\\t", sizeof(char), 2, stdout); |
| 68 | else if (text[l_cnt] == '\n') /* newline, not that there is one */ |
| 69 | fwrite("\\n", sizeof(char), 2, stdout); |
| 70 | else if (text[l_cnt] == '\v') /* vertical tab */ |
| 71 | fwrite("\\v", sizeof(char), 2, stdout); |
| 72 | else if (text[l_cnt] == '\f') /* form feed */ |
| 73 | fwrite("\\f", sizeof(char), 2, stdout); |
| 74 | else if (text[l_cnt] == '\r') /* return */ |
| 75 | fwrite("\\r", sizeof(char), 2, stdout); |
| 76 | else if ((text[l_cnt] < 32) || (text[l_cnt] > 126)) /* not printable */ |
| 77 | /* 127 is del */ |
| 78 | { |
| 79 | putchar('\\'); |
| 80 | putchar(text[l_cnt]/64+'0'); |
| 81 | putchar(text[l_cnt]/8+'0'); |
| 82 | putchar(text[l_cnt]%8+'0'); |
| 83 | l_len += 2; |
| 84 | } |
| 85 | else if (text[l_cnt] == '\\') |
| 86 | fwrite("\\\\", sizeof(char), 2, stdout); |
| 87 | else |
| 88 | { |
| 89 | l_len--; |
| 90 | putchar(text[l_cnt]); |
| 91 | } |
| 92 | l_len += 2; |
| 93 | } |
| 94 | l_len = 1; |
| 95 | putchar('\n'); |
| 96 | if (current == End) |
| 97 | break; |
| 98 | current = current->below; |
| 99 | } /* end-while */ |
| 100 | |
| 101 | *errnum = 1; |
| 102 | } /* end-l */ |