Doxygen Source Code Documentation
ccatt.c File Reference
#include "stdio.h"
#include "string.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Function Documentation
|
convert DTIStudio fiber format data to SUMA segment data Definition at line 4 of file ccatt.c. References argc.
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 ; /* skip this line */ 00049 00050 if( strstr(line2,starter) == line2 ){ /* next line starts OK */ 00051 printf("%s\n",line1) ; /* so write line1 out */ 00052 strcpy(line1,line2) ; /* and move line2 up to be line1 */ 00053 00054 } else { /* next line doesn't start OK */ 00055 strcat(line1,line2) ; /* so tack it onto line1 */ 00056 idone++ ; 00057 } 00058 } while(1) ; 00059 00060 fprintf(stderr,"%d lines catenated\n",idone) ; 00061 exit(0) ; 00062 } |