1 #include "stdio.h"
2 #include "string.h"
3
main(int argc,char * argv[])4 int main( int argc , char * argv[] )
5 {
6 char line1[2560] , line2[256] ;
7 char starter[256] = "t" ;
8 char killer[256] = "bytes" ;
9 char * cpt ;
10 int idone, narg ;
11
12 if( argc > 1 && strcmp(argv[1],"-help")==0 ){
13 fprintf(stderr,
14 "Usage: ccatt [options] < input > output\n"
15 "Copies stdin to stdout, concatenating lines that don't begin with\n"
16 "the 'starter' string. By default, the starter string is \"t\".\n"
17 "Options:\n"
18 " -starter string --> Use 'string' for the starter.\n"
19 " -killer string --> Use 'string' for the killer.\n"
20 ) ;
21 exit(0) ;
22 }
23
24 narg = 1 ;
25 while( narg < argc && argv[narg][0] == '-' ){
26
27 if( strcmp(argv[narg],"-starter") == 0 ){
28 strcpy(starter,argv[++narg]) ;
29 narg++ ; continue ;
30 }
31
32 if( strcmp(argv[narg],"-killer") == 0 ){
33 strcpy(killer,argv[++narg]) ;
34 narg++ ; continue ;
35 }
36
37 fprintf(stderr,"Don't know option: %s\n",argv[narg]) ;
38 exit(1) ;
39 }
40
41 cpt = gets(line1) ; if( cpt == NULL ) exit(0) ;
42 idone = 0 ;
43
44 do{
45 cpt = gets(line2) ;
46 if( cpt == NULL ){ printf("%s\n",line1) ; break ; }
47
48 if( strstr(line2,killer) == line2 ) continue ; /* skip this line */
49
50 if( strstr(line2,starter) == line2 ){ /* next line starts OK */
51 printf("%s\n",line1) ; /* so write line1 out */
52 strcpy(line1,line2) ; /* and move line2 up to be line1 */
53
54 } else { /* next line doesn't start OK */
55 strcat(line1,line2) ; /* so tack it onto line1 */
56 idone++ ;
57 }
58 } while(1) ;
59
60 fprintf(stderr,"%d lines catenated\n",idone) ;
61 exit(0) ;
62 }
63