/* ECP: FILEname=fig13_24.c */ /* 1*/ #include /* 2*/ #include /* 3*/ #include /* 4*/ #include /* 5*/ #include /* 6*/ #include /* 7*/ #include /* 8*/ #include /* 9*/ #include /*10*/ /* Simple Shell */ /*11*/ /* A Simple Command Is An Array Of Up To MaxArgc+1 Strings */ /*12*/ /* The Last String Is NULL */ /*13*/ /* This Can Be Used Directly For execvp */ /*14*/ /* Very Limited Error Checking To Keep Code Short */ /*15*/ #define MaxArgc 10 /*16*/ #define MaxPipes 10 /*17*/ #define FileNameLen MaxLineLen /*18*/ #define MaxLineLen 256 /*19*/ typedef char *SimpleCommand[ MaxArgc + 1 ]; /*20*/ typedef struct /*21*/ { /*22*/ char InFile[ FileNameLen ]; /*23*/ char OutFile[ FileNameLen ]; /*24*/ int NumPipes; /*25*/ SimpleCommand Commands[ MaxPipes ]; /*26*/ int Background; /*27*/ } FullCommand; /*28*/ enum { Eoln, Error, From, To, Pipe, Word, Amper }; /*29*/ /* Read A Line, return NULL On EOF */ /*30*/ #define GetLine( S ) ( fgets( S, MaxLineLen, stdin ) ) /*31*/ /* Return Pointer Indicating Where To Begin Next Search */ /*32*/ /* Str Will Be Filled if *Token Is Word, From, Or To */ /*33*/ char *GetToken( char *TheLine, char *Str, int *Token );