|
|
1.1 root 1: /*
2: * Split output lines with \ along whitespace boundarys.
3: * Adds a \n at end of line if none exists.
4: */
5: #include <misc.h>
6:
7: void
8: splitter(ofp, line, limit)
9: FILE *ofp;
10: char *line;
11: {
12: int pos, /* display location on line */
13: i, /* data location on line */
14: j, /* location of last white space on 0 */
15: c, w; /* current char and work */
16:
17: for (pos = j = i = 0; c = line[i]; i++) {
18: if ((pos >= limit) && j) { /* split condition */
19: w = line[j];
20: line[j] = '\0';
21: fprintf(ofp, "%s \\\n", line);
22: line += j;
23: line[pos = i = j = 0] = w;
24: }
25: switch (c) {
26: case '\n':
27: j = pos = 0;
28: break;
29: case '\t':
30: pos |= 7;
31: case ' ':
32: j = i;
33: default:
34: pos++;
35: }
36: }
37: fprintf(ofp, "%s", line);
38: if(pos)
39: fputc('\n', ofp);
40: }
41: #ifdef TEST
42: main()
43: {
44: char buf[100];
45:
46: while (NULL != ask(buf, "string"))
47: splitter(stdout, buf, 20);
48: }
49: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.