home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TABS.ZIP
/
CLEAN.C
next >
Wrap
C/C++ Source or Header
|
1990-09-20
|
1KB
|
64 lines
/* clean [1.0.2] - 03-Dec-87 18:59 John Layman */
/*****************************************************************************\
* This filter removes trailing blanks from each line of a file. When the /s *
* option is in effect the high bit is stripped from characters above 0x7F. *
* *
* Synopsis: clean [/s] *
* *
\*****************************************************************************/
#include <stdio.h>
#include <string.h>
#define BOOLEAN char
#define TRUE 1
#define FALSE 0
main(argc,argv)
int argc;
char *argv[];
{
int ch, cnt;
BOOLEAN stripsw = FALSE;
if (argc > 1)
{
if (argc != 2)
{
fputs("Too many arguments\n",stderr);
exit(1);
}
if ((stricmp(argv[1],"s") == 0) || (stricmp(argv[1],"/s") == 0))
stripsw = TRUE;
else
{
fputs("Invalid option\n",stderr);
exit(1);
}
}
cnt = 0;
while ((ch = getchar()) != EOF)
{
if (stripsw)
ch &= 0x7F;
if (ch == ' ')
{
cnt++;
continue;
}
if (ch == '\n')
cnt = 0;
else
{
while (cnt)
{
putchar(' ');
cnt--;
}
}
putchar(ch);
}
}