/* ECP: FILEname=fig13_25.c */ /* 1*/ /* Fill The Structure Referenced By Buf */ /* 2*/ int /* 3*/ Parse( char *TheLine, FullCommand *Buf ) /* 4*/ { /* 5*/ int CommandNum = 0, Token; /* 6*/ char Str[ MaxLineLen ]; /* 7*/ int NumStr = 0; /* # Of Strings In Current Command */ /* 8*/ Buf->NumPipes = Buf->Background = 0; /* 9*/ strcpy( Buf->InFile, "" ); /*10*/ strcpy( Buf->OutFile, "" ); /*11*/ for( ; TheLine = GetToken( TheLine, Str, &Token ); ) /*12*/ switch( Token ) /*13*/ { /*14*/ default: /*15*/ case Error: /*16*/ printf( "Syntax error\n" ); /*17*/ return -1; /*18*/ case From: /*19*/ strcpy( Buf->InFile, Str ); /*20*/ break; /*21*/ case To: /*22*/ strcpy( Buf->OutFile, Str ); /*23*/ break; /*24*/ case Amper: /*25*/ Buf->Background++; /*26*/ break; /*27*/ case Pipe: /*28*/ Buf->NumPipes++; /*29*/ case Eoln: /*30*/ Buf->Commands[ CommandNum++ ][ NumStr ] = NULL; /*31*/ NumStr = 0; /*32*/ break; /*33*/ case Word: /*34*/ Buf->Commands[ CommandNum ][ NumStr++ ] = /*35*/ Strdup( Str ); /* Note: This Is A Memory Leak */ /*36*/ break; /*37*/ } /*38*/ return 0; /*39*/ }