/**********************************
  STRIPPER.C : A program to find 
  all [TAB]s in a text file and
  replace them with a space. 
  INPUT: File name through calling.
  OUPUT: Number of tabs replaced.
 **********************************/

#include <stdio.h>
#include <string.h>

#define SPACE 32
#define TAB   9

main(argc,argv)
int argc;
char *argv[];
{
	FILE *input, *output, *fopen();
	register int c=0,x=0,t=0;
	int s;
	char *string;
	
	if((argc==1)||(argc>3))
	{
		printf("\nSTRIPPER: Written by Sean Kennedy on 08-27-92\n");
		printf("USAGE   : Stripper [filename] <spaces>\n");
		printf("FUNCTION: Removes [TAB] char from file and replaces\n");
		printf("          with <spaces> of [SPACE] characters.\n");
		exit(5);
	}
	
	if(argc==3)
	  s = atoi(argv[2]);

	input=fopen(argv[1],"rb");
	if(!input)
	{
		printf("\nERROR:Unable to open input file [%s]...Aborting!!!\n",argv[1]);
		exit(20);
	}
	
	output=fopen("temp","wb");
	if(!output)
	{
		printf("\nERROR:Unable to open output file [temp]...Aborting!!!\n");
		fclose(input);
		exit(20);
	}
	
	while((c=fgetc(input))!=EOF)
	{
		if(c==TAB)
		{
		  x+=1;
		  c=SPACE;
		  for(t=0;t<=s;t++)
		    fputc(c,output);
		}
		else
		  fputc(c,output);
	}

	if(input)
		fclose(input);
	if(output)
		fclose(output);

 sprintf(string,"Copy temp to %s",argv[1]);
	Execute(string,0,0);
 Execute("Delete temp",0,0);
	
	printf("\nTotal [TABS] Replaced ====>%d\n",x);
} 
