void RunCmd(commandT** cmd, int n) { int i; int count; total_task = n; //printf("Command name: %s \n",cmd[0]->argv[0]); //printf("Command argument count: %d \n",cmd[0]->argc-1); if (IsAlias((cmd[0]->argv[0]))) { RunAlias((cmd[0])); } else { for ( count=1;count<cmd[0]->argc;count++){ //printf("Argument %d : %s \n",count,cmd[0]->argv[count]); } if(n == 1) RunCmdFork(cmd[0], TRUE); else{ RunCmdPipe(cmd[0], cmd[1]); for(i = 0; i < n; i++) ReleaseCmdT(&cmd[i]); } } }
void BlockFile::ChangeAliasedFile(wxString newFile) { // This method is only called with the DirManager is moving // a file we depend on out of the way, so that a new file // with the same name can be exported. wxASSERT(IsAlias()); mAliasFullPath = newFile; }
wxString BlockFile::GetAliasedFile() { wxASSERT(IsAlias()); return mAliasFullPath; }
//bool secondRun stops the interpreter from recursing more than 1 level into itself void Interpret(char* cmdLine,bool secondRun) { int task = 1; int bg = 0, i,k,j = 0, quotation1 = 0, quotation2 = 0; commandT **command; if(cmdLine[0] == '\0') return; for(i = 0; i < strlen(cmdLine); i++){ if(cmdLine[i] == '\''){ if(quotation2) continue; else if(quotation1){ quotation1 = 0;continue; } else quotation1 = 1; } if(cmdLine[i] == '"'){ if(quotation1) continue; else if(quotation2){ quotation2 = 0;continue; } else quotation2 = 1; } if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){ task ++; } } command = (commandT **) malloc(sizeof(commandT *) * task); i = strlen(cmdLine) - 1; while(i >= 0 && cmdLine[i] == ' ') i--; if(cmdLine[i] == '&'){ if(i == 0) return; bg = 1; cmdLine[i] = '\0'; } quotation1 = quotation2 = 0; task = 0; k = strlen(cmdLine); for(i = 0; i < k; i++, j++){ if(cmdLine[i] == '\''){ if(quotation2) continue; else if(quotation1){ quotation1 = 0;continue; } else quotation1 = 1; } if(cmdLine[i] == '"'){ if(quotation1) continue; else if(quotation2){ quotation2 = 0;continue; } else quotation2 = 1; } if(cmdLine[i] == '|' && quotation1 != 1 && quotation2 != 1){ parser_single(&(cmdLine[i-j]), j, &(command[task]),bg); task++; j = -1; } } parser_single(&(cmdLine[i-j]), j, &(command[task]),bg); // // TILDE EXPANSION // bool changed = FALSE; int idx =0; //look through all the args while(idx < command[0]->argc){ //special case for "unalias x". ie dont expand x if(command[0]->argv[idx][0] == '~'){ char* home = getenv("HOME"); //get the part after the tilde and add it to home strcat(home,(command[0]->argv[idx])+2); command[0]->argv[idx] = home; changed = TRUE; } idx++; } // // ALIAS // //only expand aliases on the first run to stop aliases from recrusively expanding if(!secondRun){ //look for aliases int idx =0; //look through all the args while(idx < command[0]->argc){ //special case for "unalias x". ie dont expand x if(strcmp(command[0]->argv[0],"unalias") != 0) { if(IsAlias(command[0]->argv[idx])){ (command[0]->argv)[idx] = GetAliasCmd(command[0]->argv[idx]); changed = TRUE; //check for tilde expansion } } idx++; } //if we expanded something if(changed){ int newSize = 0;//the new size of the expanded command line //figure out the new size int idx2 =0; while(idx2 < command[0]->argc){ newSize = newSize + strlen(command[0]->argv[idx2]) + 1; idx2++; } //copy all ths args to a new cmdLine string char newCmdLine[newSize + 1]; strcpy (newCmdLine, command[0]->argv[0]); int idx3 =1; while(idx3 < command[0]->argc){ strcat(newCmdLine," ");//add space between args strcat(newCmdLine,command[0]->argv[idx3]); idx3++; } //rerun the interpreter Interpret(newCmdLine,TRUE); } else{ RunCmd(command, task+1); free(command); } }else{ RunCmd(command, task+1); free(command); } }