/**************************************************************************** * tabset.c * * * * Bob Goeke MIT Center for Space Research 617-253-1910* * goeke@space.mit.edu * * * $Log: tabset.c,v $ * Revision 1.3 2013/07/27 20:44:54 goeke * Add pod * * Revision 1.2 2001/01/26 21:14:36 goeke * Added -w flag to screen out directives. * * Revision 1.1 1995/09/19 19:06:36 goeke * Initial revision * ****************************************************************************/ #include #define NAME "tabset" #define TITLE "TABSET.C Version 1.0 16 September 1995" #define INPUT 2048 #define TAB '\t' #define TABCOUNT 128 /* number of tabs allowed */ #define ERROR(A,B) { fprintf(stderr,"%s: ",NAME); \ fprintf(stderr,(A),(B)); exit(1); } unsigned html; /* set for html ignores */ /* * Change tabs to spaces * Takes an array of tab stops as args */ expand(stop,explicit) unsigned *stop,explicit; { char cc; unsigned mm,count; mm = 0; count = 0; while ( EOF != (cc=getchar()) ) { switch(cc) { case TAB: if ( cc == TAB ) { if (explicit!=0) /* find next stop */ for( ; stop[mm]<=count; mm++ ) ; for( ; count at end on input.\n"); exit(1); } putchar(cc); break; } default: putchar(cc); count++; break; } } } main(argc, argv) int argc; char *argv[]; { unsigned tab[TABCOUNT]; unsigned kk; /* index for tab array */ unsigned likeatty; /* set for typewriter equiv */ likeatty = 0; /* default is explicit tabs */ html = 0; /* default is to not process html codes in a special way*/ kk = 0; /* set up first tab default */ for(argc--,argv++; argc>0; argc--,argv++ ) /* sweep the entire argument list */ { if( **argv == '-' ) /* if this argument is a flag of some type */ { switch(*(++*argv)) { case 'T': case 't': if ( 1 != sscanf(++*argv,"%d",&tab[kk++]) ) { fprintf(stderr, "unknown argument format: %s\n", *argv); help(); } break; case 'L': case 'l': likeatty++; break; case 'H': case 'h': help(); break; /* this is never reached! */ case 'W': case 'w': html++; break; default: fprintf(stderr, "%s: unknown flag '%c' invoked.\n",NAME,**argv); help(); } /* switch */ } /* if(**argv=='-') */ else { fprintf(stderr,"No additional arguments allowed.\n"); help(); } } /* for(all arguments) */ if (kk==0) /* fill in first one in default */ tab[kk++] = 8; for ( ; kk =head2 NAME tabset -- substitues space characters for tabs =head2 USAGE dbprint [-h[elp] \ [-l[iteral] \ [-t[ab]# [-t[ab]# ... [-t[ab]# \ [-w[eb] \ STDOUT =head2 FLAGS -h prints help message -l operates as a literal typewriter, skipping to next available tab -t uses the given number as a tab stop (default: every 8 characters) -w ignore all HTML constructs =head2 DESCRIPTION The text presented at STDIN is stripped of tab characters and spaces are inserted to provide the functionality. By default tabs are located every 8 characters. When one or more tabs are provided, those numbers are used. By default a tab position which has been passed by is ignored in the output. Use of the B<-l> flag causes the output to always use the next available flag. Use of the B<-w> flag causes the program not to count HTML constructs of the form C, but only explicit character spaces are inserted, not C<;nbsp>. =head2 BUGS Note that there no spaces betwee the B<-t> flag and its argument. Supplying text with more tabs on a line than are explicitly provided for leads to uneven results. =head2 SEE ALSO =head4 High Level programs dbprint =head4 Low Level programs =head2 AUTHOR Bob Goeke =head2 RCS Information $Id: tabset.c,v 1.3 2013/07/27 20:44:54 goeke Exp goeke $ =cut ***************************************************************************************************************/