Commit code, circa 2010
This commit is contained in:
41
wrap.c
Executable file
41
wrap.c
Executable file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
|
||||
const char *usage = "\
|
||||
wrap - wrap a text file.\n\
|
||||
Usage: wrap <infile> <outfile>\n";
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if ( argc < 3 ) {
|
||||
printf("%s", usage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE *in = fopen(argv[1], "r");
|
||||
FILE *out = fopen(argv[2], "w");
|
||||
int cn = 0;
|
||||
char c = 0x00;
|
||||
|
||||
if ( !in || !out ) {
|
||||
printf("Failed to open input/output file.\n");
|
||||
in ? fclose(in) : 0 ;
|
||||
out ? fclose(out) : 0 ;
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ( !feof(in) ) {
|
||||
c = fgetc(in);
|
||||
if ( cn > 60 &&
|
||||
( c == ' ' || c == '\n' || c == '\t' )) {
|
||||
fputc('\n', out);
|
||||
cn = 0;
|
||||
if ( c != '\t' ) continue;
|
||||
}
|
||||
fputc(c, out);
|
||||
cn++;
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user