1 /* fold - folds long lines Author: Terrence W. Holm */
3 /* Usage: fold [ -width ] [ file ... ] */
9 #define DEFAULT_WIDTH 80
11 int column
= 0; /* Current column, retained between files */
13 int main(int argc
, char **argv
);
14 void Fold(FILE *f
, int width
);
20 int width
= DEFAULT_WIDTH
;
24 if (argc
> 1 && argv
[1][0] == '-') {
25 if ((width
= atoi(&argv
[1][1])) <= 0) {
26 fprintf(stderr
, "Bad number for fold\n");
35 for (i
= 1; i
< argc
; ++i
) {
36 if ((f
= fopen(argv
[i
], "r")) == NULL
) {
54 while ((c
= getc(f
)) != EOF
) {
56 column
= (column
/ TAB
+ 1) * TAB
;
58 column
= column
> 0 ? column
- 1 : 0;
59 else if (c
== '\n' || c
== '\r')
66 column
= c
== '\t' ? TAB
: 1;