Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
ccatt.c
Go to the documentation of this file.00001 #include "stdio.h"
00002 #include "string.h"
00003
00004 int main( int argc , char * argv[] )
00005 {
00006 char line1[2560] , line2[256] ;
00007 char starter[256] = "t" ;
00008 char killer[256] = "bytes" ;
00009 char * cpt ;
00010 int idone, narg ;
00011
00012 if( argc > 1 && strcmp(argv[1],"-help")==0 ){
00013 fprintf(stderr,
00014 "Usage: ccatt [options] < input > output\n"
00015 "Copies stdin to stdout, concatenating lines that don't begin with\n"
00016 "the 'starter' string. By default, the starter string is \"t\".\n"
00017 "Options:\n"
00018 " -starter string --> Use 'string' for the starter.\n"
00019 " -killer string --> Use 'string' for the killer.\n"
00020 ) ;
00021 exit(0) ;
00022 }
00023
00024 narg = 1 ;
00025 while( narg < argc && argv[narg][0] == '-' ){
00026
00027 if( strcmp(argv[narg],"-starter") == 0 ){
00028 strcpy(starter,argv[++narg]) ;
00029 narg++ ; continue ;
00030 }
00031
00032 if( strcmp(argv[narg],"-killer") == 0 ){
00033 strcpy(killer,argv[++narg]) ;
00034 narg++ ; continue ;
00035 }
00036
00037 fprintf(stderr,"Don't know option: %s\n",argv[narg]) ;
00038 exit(1) ;
00039 }
00040
00041 cpt = gets(line1) ; if( cpt == NULL ) exit(0) ;
00042 idone = 0 ;
00043
00044 do{
00045 cpt = gets(line2) ;
00046 if( cpt == NULL ){ printf("%s\n",line1) ; break ; }
00047
00048 if( strstr(line2,killer) == line2 ) continue ;
00049
00050 if( strstr(line2,starter) == line2 ){
00051 printf("%s\n",line1) ;
00052 strcpy(line1,line2) ;
00053
00054 } else {
00055 strcat(line1,line2) ;
00056 idone++ ;
00057 }
00058 } while(1) ;
00059
00060 fprintf(stderr,"%d lines catenated\n",idone) ;
00061 exit(0) ;
00062 }