The structure is also clear, yesterday's blog has been roughly said, not much explanation.
RTFSC :)
#include
TypedEf struct command_struct {int COMARGC; Char * Command; char * comargv [10];
INT COM_INSIDE (CHAR *); int search (char *, char *, char *);
INT main (int Argc, char ** argv) {INT flag; int 1, c; int m, n; int * status; char cwd [255]; int exeflag; char Tempcom [10]; char full_pathname [64] = "/ home / yg / c_test / 0921"; char pathname [64]; char scanargv [10] [10] = {}; command_struct com; (1) {if ((int) getcwd (cwd, 64) == -1) Printf ("get cwd error"); Printf ("% s>", cwd); / * begin init command_struct * / for (m = 0; m ) {for (n = 0; N <10; n ) {scanargv [m] [n] = 0;}} i = 0; while ((c = getchar ())! = '/ N') {IF (c! = ') {Scanargv [ I] [0] = C; Scanf ("% s", scanargv [i ] 1);} else {scanf ("% s", scanargv [i ]);}} com.comargc = i-1; COM .command = scanargv [0]; i = 0; while (i <10) {com.comargv [i] = scanargv [i]; i ;} / * end init command_struct * / if (com.command == "/ N ") Continue; IF ((strcmp (com.command," quit ") == 0) || (strcmp (com.command," exit ") == 0)) EXIT (1); if ((Flag = COM_INSIDE (Com.command)) == - 1) EXIT (1); ELSE IF FLAG == 1) Continue; Else IF (flag == 0) {struct (tempcom, com.command); if ((exeflag = search (full_pathname, tempcom, pathname) == 0) Printf ("Bad Command OR File Name / N "); else {ix (fork () == 0) {i = 0; while (i <= com.comargc) {Argv [i] = com.comargv [i]; i ;} if (Execve (Pathname, Argv, 0) == - 1) {Printf ("Error IS% S / N", STRERROR (Errno));
}}}}}}}}}}}}}}}}}}}} Int COM_INSIDE (CHAR * Command) {if (Command == NULL) Return -1; if (! (! (!)))) {Printf ("ok / n"); return 1;} IF (! (StrCMP ("0.0.0.1/n")) {printf ("0.0.0.1/n"); returnit 1;} return 0;}
INT Search (char * full_pathname) {INT flag; int i; char pathname [64] = {}; Dir * DIRP; Struct Dirent * Direntp; Strcpy (Pathname, PATH); i = 0 WHILE (Pathname [i]! = 0) {i ;} if (pathname [i-1]! = 47) {strat (pathname, "/");} if ((DIRP = OpenDir (PATH))) { While ((DirentP = ReadDir (Dirp))! = null) {if (Strcmp-> D_Name, Name) == 0) {FLAG = 1; Break;} else flag = 0;} Closedir (DIRP); IF (FLAG) {strat (pathname, name); strcpy (full_pathname, pathname); Return 1;} else return 0;} else {return 0;}}}