void executeApplication(char *path, char *directory, char **argv) { int pid; zzz(); XFlush(XtDisplay(toplevel)); if (chdir(directory)) { wakeUp(); sysError("Can't chdir:"); } else if ((pid = fork()) == -1) { wakeUp(); sysError("Can't fork:"); } else { if (!pid) { if (resources.echo_actions) { char **arg; fprintf(stderr, "[%s] %s", directory, path); for (arg = argv+1; *arg; arg++) echoarg(*arg); fprintf(stderr, "\n"); } /* Make sure that child processes don't lock up xfm with keyboard input. This is certainly a kludge and if you know of any better way to do this, please let me know. -ag */ freopen("/dev/null", "r", stdin); execvp(path, argv); perror("Exec failed"); exit(1); } else { sleep(1); wakeUp(); } } }
int main(int argc, char** argv) { char sh[200]; strcpy(sh,"SHELL="); strcat(sh,getenv("PWD")); putenv(sh); if(argc==2) { //printf("file readin"); if(freopen(argv[1],"r",stdin)==NULL){ fprintf(stdout,"Failure to open"); } } //char* comm; char str[200]; char* commands[NUMBER_OF_COMMANDS]={"clr","dir","environ","quit","echo","cd","pause","help"}; while(1) { //initializing redirection values in_=0; out_=0; app_=0; dont_wait=0; //sets next arguement to auto wait. fprintf(stdout,"%s==>",getenv("PWD")); fflush(stdout); //start reading function //get string and note that it has a newline character at the end of the string. if(fgets(str,200,stdin)==NULL) { fclose(stdin); } //end reading function strcpy(masterstr,str); //malloc buffer size int argcount=0; char* buffer =NULL; buffer=strtok(str," \n\t"); char** argarray=(char**) malloc(sizeof(str)); while(buffer!=NULL) { if(strcmp(buffer,"&")==0) { fprintf(stdout,"%s",buffer); dont_wait=1; } else if(strcmp(buffer,"<")==0) { fprintf(stdout,"%s",buffer); fprintf(stdin,"Input changed"); buffer=strtok(NULL," \n\t"); if(buffer!=NULL) { strcpy(in,buffer); in_=1; } } else if(strcmp(buffer,">")==0) { fprintf(stdout,"%s",buffer); fprintf(stdin,"Output changed"); buffer=strtok(NULL," \n\t"); if(buffer!=NULL) { strcpy(out,buffer); out_=1; } } else if(strcmp(buffer,">>")==0) { fprintf(stdout,"%s",buffer); fprintf(stdin,"append Out changed"); buffer=strtok(NULL," \n\t"); if(buffer!=NULL) { strcpy(app,buffer); app_=1; } } else { argarray[argcount]=(char*) malloc(sizeof(buffer)); //allocate space for each argument strcpy(argarray[argcount++],buffer); //take next value from command string } buffer=strtok(NULL," \n\t"); } //start command parse int l; if(argarray[0]!=NULL) { for(l=0;l<NUMBER_OF_COMMANDS;l++) { //remove to test string comparison //fprintf(stdout,"%s:%s\n",arguments,commands[l]); if(strcmp(argarray[0],commands[l])==0) { break; } } //argarray[argcount++]=(char*) malloc (sizeof(str)); //argarray[argcount++]='\0'; //remove to test the value of l //fprintf(stdout,"HELLO? %d",l); switch(l) { case(0):clr(argarray);break; case(1):dir(argarray,argcount);break; case(2):envi();break; case(3):return 0;break; case(4):echoarg(argarray,argcount);break; case(5):cd(argarray,argcount);break; case(6):sleeptime();break; case(7):help();break; default:other(argarray);break; } } } }