home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
112.lha
/
Tabs
/
detab.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-20
|
2KB
|
80 lines
/* detab.c - proper expansion of TABs while printing a file */
#include "stdio.h"
#define MAXTAB 35
void _wb_parse(){} /* null routine */
main(argc, argv)
int argc;
char *argv[];
{
FILE *in, *out, *fopen();
int tabcol[MAXTAB];
register int c, outcol, index;
/* define columns with TAB stops */
tabcol[0] = 10;
for ( index = 1; index < MAXTAB; index++ )
tabcol[index] = tabcol[index-1] + 8;
if ( argc != 3 )
{
printf("Usage: %s infile outfile\n",argv[0]);
exit(20);
}
/* open input file */
if ( (in = fopen(argv[1], "r") ) == NULL)
{
printf("Can't open %s for input.\n", argv[1]);
exit(20);
}
/* open file */
if ( (out = fopen(argv[2], "w") ) == NULL)
{
printf("Can't open %s for output.\n", argv[2]);
exit(20);
}
/* process the file */
outcol = 1;
index = 0;
while ( (c = getc(in)) != EOF )
{
if ( c == '\n' ) /* it's a newline */
{
outcol = 1;
index = 0;
}
if ( c == '\t' ) /* it's a TAB! */
{
/* look for next TAB stop */
while ( tabcol[index] <= outcol )
{
index++;
if ( index >= MAXTAB )
{
printf("\nToo many TABs in line.\n");
exit(20);
}
}
/* expand TAB to spaces */
while ( outcol < tabcol[index] )
{
putc(' ', out);
outcol++;
}
}
else
/* copy character exactly */
{
putc(c, out);
outcol++;
}
}
fclose(in);
fclose(out);
}