home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TABS.ZIP
/
DETAB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-20
|
3KB
|
99 lines
/* detab [1.0.2] - 07-Dec-87 16:35 John Layman */
/*****************************************************************************\
* This filter removes tabs from a file by expanding them to blanks. *
* *
* Synopsis: detab [t1..tn] *
* *
* where the optional parameter(s) indicate tab positions. *
* *
* When no parameter is present, the filter presumes the default system tab *
* settings (i.e. where column MOD 8 = 1). *
* *
* When a single parameter is present, it is considered to be the tab gap *
* (i.e. tabs are where column MOD gap = 1). *
* *
* When multiple parameters are present, they explicitly define each tab *
* position. *
\*****************************************************************************/
#include <stdio.h>
#define DEFAULT 8
#define MAXLEN 255
void chktab(), settab(), settabs();
char pos[MAXLEN]; /* tab bar, where tab stops == '\t' */
int hi; /* column of highest (rightmost) tab stop */
main(argc,argv)
int argc;
char *argv[];
{
int ch, col, i;
if (argc == 1)
settabs(DEFAULT);
else
if (argc == 2)
settabs(atoi(argv[1]));
else
for (i = 1; i < argc; i++)
settab(atoi(argv[i]));
col = 1;
while ((ch = getchar()) != EOF)
if (ch == '\t')
do
{
putchar(' ');
col++;
}
while (col < hi && pos[col] != '\t');
else
{
putchar(ch);
if (ch == '\n')
col = 1;
else
col++;
}
}
void settab(col)
int col;
{
chktab(col);
pos[col] = '\t';
if (col > hi)
hi = col;
}
void settabs(gap)
int gap;
{
int col;
chktab(gap);
for (col = gap+1; col <= MAXLEN; col += gap)
{
pos[col] = '\t';
hi = col;
}
}
void chktab(col)
int col;
{
if (col < 1 || col > MAXLEN)
{
fputs("Invalid parameter\n",stderr);
exit(1);
}
}