void ExportTilesets(const std::string & destdir) { //1. Obtain level list const GameScriptData::lvlinf_t & lvlinf = m_gconf.GetGameScriptData().LevelInfo(); //2. Load bg_list.dat stringstream sstrbglist; sstrbglist << utils::TryAppendSlash(m_mapbgdir) <<filetypes::FName_BGListFile; filetypes::lvlbglist_t bglist(filetypes::LoadLevelList( sstrbglist.str() )); cout <<"Loaded " <<filetypes::FName_BGListFile <<"file..\n"; //3. Iterate level list, export each levels matching the index of the name in the BG list for( const pmd2::level_info & lvl : lvlinf ) { if( lvl.mapid < bglist.size() ) { stringstream sstrtsetpath; sstrtsetpath << utils::TryAppendSlash(destdir) <<lvl.name; string tsetpath = sstrtsetpath.str(); cout <<"\rExporting " <<left <<setw(10) <<setfill(' ') <<lvl.name <<".."; utils::DoCreateDirectory(tsetpath); ExportATileset( lvl, bglist[lvl.mapid], tsetpath ); } else { //The map id refers to a map out of bound! stringstream sstrer; sstrer << "GameLevelHandler::ExportTilesets(): Error processing level \"" <<lvl.name <<"\"! Map id " <<lvl.mapid <<" is outside the \"" <<filetypes::FName_BGListFile <<"\" level list file's range!!"; assert(false); throw std::runtime_error(sstrer.str()); } } }
int main(int argc, char*argv[], char*envp[]){ char next_char; int i, fd; copy_envp(envp); char changepath[1024]; head = (struct node *) malloc( sizeof(struct node) ); head->next = NULL; head->val = 0; struct node *ptr = (struct node *)malloc(sizeof(struct node *)); ptr->val=0; ptr->next = NULL; head = current = ptr; /** clears screen for RSI **/ if(fork() == 0) { execvp("clear", argv); exit(1); } else { wait(NULL); } /** Prints prompt for first time **/ strcpy(cwd,""); if (getcwd(cwd, sizeof(cwd)) == NULL){ perror("getcwd() error"); } printf("RSI: %s > ", cwd); fflush(stdout); char word[24] = "\0"; char* args[256]; int m = 0; int child_pid; int h; char command[24]; static char arg_buffer[256] = "\0"; /* while user has not pushed ctrl-d */ while(next_char != EOF){ /* gets next char typed in cmd line, adds to words. */ /* puts the words (arguments) into argv *************/ next_char=getchar(); if(isspace(next_char) == 0){ strncat(word, &next_char, 1); } else{ strcpy(command, word); args[m] = (char *)malloc(sizeof(char) * 100); strcpy(args[m], command); strcpy(word, ""); m++; } /* if the line is done, ...*/ if(next_char == '\n'){ args[m] = (char *)malloc(sizeof(char) * 2); args[m] = NULL; int r = 0; int j = 0; int wpid; /* if statements check if cmd is bg, bglist, or cd. */ /* if not, it executes the command, waits for the child to complete, then prompts again */ if (strcmp(args[0], "cd" ) == 0){ change_directory(args, changepath, envp); } else if(strcmp(args[0], "\0")==0){ printf("\nNo Command Entered.\n"); } else if(strcmp(args[0], "bglist") == 0){ bglist(); } /** if it's a bg process, execute process, add info to list, then continue. **/ else if(strcmp(args[0], "bg") == 0){ for(r = 0; r<m-1; r++){ bzero(args[r], sizeof(args[r])); strcpy(args[r],args[r+1]); } bzero(args[m-1], sizeof(args[m-1])); args[m-1] = NULL; if ((child_pid=fork()) == 0) { h = execvp(args[0], args); printf("errno is %d\n", errno); } else { int c = 1; /* combine separate args to single string for node and future printout at bglist */ for(c=1; c<m-1; c++){ strcat(arg_buffer, args[c]); strcat(arg_buffer, " "); } add_to_list(child_pid, args[0], arg_buffer); bzero(arg_buffer, 256); } } /* execute process, then wait until process has finished to continue */ else { pid_t num; if ((num = fork()) == 0){ h = execvp(args[0], args); printf("errno is %d\n", errno); } else { waitpid(num, NULL, 0); } } m = 0; /* gets cwd and checks for finished processes. If there are, remove them from the list of bg processes. */ strcpy(cwd,""); if (getcwd(cwd, sizeof(cwd)) == NULL){ perror("getcwd() error"); } int status; int pid; /* waitpid() returns a PID on success*/ for(;;){ pid = waitpid(-1, &status, WNOHANG); if(pid <= 0){ break; } printf("[proc %d exited with code %d]\n", pid, WEXITSTATUS(status)); delete_from_list(pid); } /* prints prompt */ printf("\nRSI: %s > ", cwd); fflush(stdout); } } }
int main ( void ) { for (;;) { //pid_t pid; terminate(); char *cmd = readline ("shell>"); const char s[2]= " "; char* args[15]; //char* argsBG[15]; char *token=strtok(cmd,s); int a=0; while(token!=NULL){ if(a==0){ args[a]=token; a++; } else if(a<15){ args[a]=token; //argsBG[a-1]=token; a++; } token=strtok(NULL,s); } pwd(args); if (strcmp(args[0],"pwd") == 0){ fprintf(stdout, "Current working dir: %s\n", cwd); }else if(strcmp(args[0],"cd")==0){ cd(args); }else if(strcmp(args[0],"bgkill")==0){ int WhichKill=atoi(args[1]); //printf("%i",WhichKill); int WhichPid=backGround[WhichKill].pid; if(kill(WhichPid, SIGTERM)==0){ printf("Kill program with pid %i\n",WhichPid); } //}else if(strcmp(args[0],"bg")==0){ //p_num++; //RunBack(argsBG); }else if(strcmp(args[0],"bglist")==0){ bglist(); }else if(strcmp(args[0],"stop")==0){ int WhichKill=atoi(args[1]); if(backGround[WhichKill].StatOrStop==1){ printf("Error, this program is stoped\n"); }else{ backGround[WhichKill].StatOrStop=1; int WhichPid=backGround[WhichKill].pid; if(kill(WhichPid, SIGSTOP)==0){ printf("Stop program with pid %i\n",WhichPid); } } }else if(strcmp(args[0],"start")==0){ int WhichKill=atoi(args[1]); if(backGround[WhichKill].StatOrStop==0){ printf("Error, this program is running\n"); }else{ backGround[WhichKill].StatOrStop=0; int WhichPid=backGround[WhichKill].pid; if(kill(WhichPid, SIGSTOP)==0){ printf("Stop program with pid %i\n",WhichPid); } } }else{ //printf("%s",*args); hmmpid=fork(); if(hmmpid>=0){ if(hmmpid==0){ //execvp(args[0], args); //sleep(3); p_child(args); if(strcmp(args[0],"bg")==0){ bg_child(args); } //p_child(args); }else{ if(strcmp(args[0],"bg")==0){ //waitpid(hmmpid, &status, 0); AddBG(hmmpid); }else{ wait(0); } } free (cmd); }else{ printf("OUTPUT ERROR"); } } //printf ("Got: [%s]\n", cmd); //free (cmd); } }