www.pudn.com > SimpleShell.zip > myshell.c
#include#include "myshell.h" #define MAX_COM 100 #define MAX_ARG 256 main(int commingArgc, char *commingArgv[]) { char command[MAX_COM]; char commandForCheck[MAX_COM]; char bCommand[MAX_COM]; int i; int outSignIndex; int inSignIndex; int pIndex; char *bToken; char *bArg[MAX_ARG]; int bArgv; char source[MAX_COM]; char desti[MAX_COM]; char dDesti[MAX_COM]; int cError; char curDic[MAX]; int background; char *pwdForCh; FILE *fp; getcwd(curDic, MAX); pwdForCh = (char *)malloc( 6 + strlen(curDic) + 2); strcat(pwdForCh, "SHELL="); strcat(pwdForCh, curDic); putenv(pwdForCh); while(1) { cError = FALSE; outSignIndex = -1; inSignIndex = -1; pIndex = -1; for(i=0; i ", curDic); fgets(command, MAX_COM, stdin); strcpy(commandForCheck, command); for(i = 0; i < MAX_COM; i++) { if(commandForCheck[i] == '>') { outSignIndex = i; break; } } for(i = 0; i < MAX_COM; i++) { if(commandForCheck[i] == '<') { inSignIndex = i; break; } } if( outSignIndex == -1 && inSignIndex == -1) { excuteCommand(command, desti, dDesti, source); continue; } else if ( outSignIndex > inSignIndex && (inSignIndex>=0) ) { pIndex = inSignIndex; } else if ( inSignIndex > outSignIndex && (outSignIndex>=0) ) { pIndex = outSignIndex; } else if ( inSignIndex < 0 ) { pIndex = outSignIndex; } else if ( outSignIndex < 0 ) { pIndex = inSignIndex; } for(i=pIndex; i ") ) { if ( desti[0] == (char)NULL && dDesti[0] == (char)NULL) { strcpy(desti, bArg[++i]); } else { cError = TRUE; break; } } else if( !strcmp(bArg[i],">>") ) { if ((dDesti[0] == (char)NULL) && (desti[0] == (char)NULL)) { strcpy(dDesti, bArg[++i]); } else { cError = TRUE; break; } } else if( !strcmp(bArg[i],"<") ) { if(source[0] == (char)NULL) { strcpy(source, bArg[++i]); } else { cError = TRUE; break; } } } } if( !strcmp(source, ">") | !strcmp(source, ">>") | !strcmp(source, "<") ) { cError = TRUE; } else if ( !strcmp(desti, ">") | !strcmp(desti, ">>") | !strcmp(desti, "<") ) { cError = TRUE; } else if ( !strcmp(desti, ">") | !strcmp(desti, ">>") | !strcmp(desti, "<") ) { cError = TRUE; } if(cError) { printf(FIND_ERROR_MSG); continue; } else { excuteCommand(command,desti,dDesti, source); } } } }