wrap.c - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
wrap.c (475B)
---
1 #include <stdio.h>
2
3 int
4 main(void)
5 {
6 /* softwrap: try to wrap on word boundary, otherwise hardwrap */
7 int c, i = 0, sw = 72, hw = 79;
8
9 while ((c = getchar()) != EOF) {
10 if (c == '\n') {
11 i = 0;
12 } else {
13 /* start of rune, wrongly assume 1 rune is 1 column for now */
14 if ((c & 0xc0) != 0x80) { /* start of character */
15 if (i > hw || (i > sw && (c == ' ' || c == '\t'))) {
16 putchar('\n');
17 i = 0;
18 }
19 i++;
20 }
21 }
22 putchar(c);
23 }
24
25 return 0;
26 }