/* noendspac.c - remove trailing spaces from each line. */ /* does NOT remove tabs etc. */ /* due to annoying habits of C runtime system, doesn't handle '\f' etc well */ /* ufilter3.c - prototype filter program - line (actually record) oriented */ /* this modularises input & output : so you can easily break RPG cycle */ /***************************************\ * * * fails for binary files * * * \***************************************/ #include #include #define BUFSIZ 4096 char buffer[BUFSIZ]; main(argc,argv) char **argv; BEGIN int howlong; /* char length of this record */ char * recinp(); char * p; buffer[0] = '.'; /* sentinel */ WHILE (recinp(buffer+1,BUFSIZ,&howlong)) DO FOR (p=buffer+howlong-1; *p==' '; p--) /* -1 skips '\n' */ DO OD howlong = p - buffer; recout(buffer+1,howlong); OD END char * recinp(buf,max,len) /* NULL if eof. buffer address */ char * buf; int max; int * len; /* length of buffer */ BEGIN * len = fget(buf,max,stdin); IF (ferror(stdin)) THEN error("read failure $$ferr=%oo\7\n",$$ferr); FI return (feof(stdin)?NULL:buffer); END recout(where,len) char * where; int len; BEGIN fput(where,len,stdout); IF (ferror(stdout)) THEN error("write failed $$ferr=%oo\7\n",$$ferr); FI END /* end: ufilter3.c */ /* end: noendspac.c */