/* Added by Nick Burch <*****@*****.**> */ int call_pgpk(FILE *log, char *pgppath, char *args[], int start, int end ) { /* Calls PGPK.EXE */ int rc; char *opts; // Get command line from args[] opts = get_cmd_line( log,args,start,end ); sprintf(cmdline, "%s\\pgpk.exe %s", pgppath, opts); rc = system(cmdline); dprintf( log, "Called PGPK.EXE, with RC=%d",rc); return(rc); }
int main(int ac, char **av, char **env) { t_system sys; (void)av; (void)ac; if (signal(SIGINT, &handle_sig) == SIG_ERR) return (EXIT_FAILURE); if (init_sys(&sys, &sys.history, env) == -1) return (EXIT_FAILURE); get_sys(&sys); process_conf_file(&sys); aff_prompt(&sys); get_cmd_line(&sys); unset_termcaps(&sys); free_all(&sys); if (sys.exit.exit == true) return (sys.exit.value); return (EXIT_SUCCESS); }
int main(int ac, char **av) { t_global *global; t_xtree *tree; srandom(time(0) * getpid()); if ((global = malloc(sizeof(*global))) == NULL) return (EXIT_FAILURE); global_thread = global; global->object = NULL; global->param = POSITION; if (!get_cmd_line(ac, av, &(global->info))) return (EXIT_FAILURE); my_putstr("[*] Raytracer: Creation of the tree ..."); if ((tree = xml_parser(global->info.xml)) == NULL) return (my_puterror(" \033[31mFail !\033[00m\n")); my_putstr(" \033[32mDone !\033[00m\n"); if ((main_option(global, tree)) == EXIT_FAILURE) return (EXIT_FAILURE); return (EXIT_SUCCESS); }
int main(int argc, char** argv) { init_config(); int execute_cmd(char* line, bool is_dump) { //if is_dump == true then file cmd // is_dump == false then stdin cmd if(is_dump == true) printf("%s\n", line); sendto(sock, line, strlen(line) + 1, 0,(struct sockaddr*)&lb_addr, sizeof(lb_addr)); cmd_exec(line); printf("> "); fflush(stdout); return 0; } List* fd_list = list_create(NULL); for(int i = 1; i < argc; i++) { int fd = open(argv[i], O_RDONLY); if(fd != -1) { list_add(fd_list, (void*)(int64_t)fd); } } list_add(fd_list, STDIN_FILENO); //fd of stdin void get_cmd_line(int fd) { static char line[MAX_LINE_SIZE] = {0, }; char* head; int seek = 0; static int eod = 0; //end of data while((eod += read(fd, &line[eod], MAX_LINE_SIZE - eod))) { head = line; for(; seek < eod; seek++) { if(line[seek] == '\n') { line[seek] = '\0'; int ret = execute_cmd(head, fd != STDIN_FILENO); if(fd != STDIN_FILENO && ret != 0 && ret != CMD_STATUS_ASYNC_CALL) {//parsing file and return error code printf("stop parsing file\n"); eod = 0; return; } head = &line[seek] + 1; } } if(head == line && eod == MAX_LINE_SIZE){ //not found '\n' and head == 0 printf("Command line is too long %d > %d\n", eod, MAX_LINE_SIZE); eod = 0; return; } else { //not found '\n' and seek != 0 memmove(line, head, eod - (head - line)); eod -= head - line; seek = eod; if(fd == STDIN_FILENO) { return; } else continue; } } if(eod != 0) { line[eod] = '\0'; execute_cmd(&line[0], fd != STDIN_FILENO); } eod = 0; return; } int fd = (int)(int64_t)list_remove_first(fd_list); int retval; char buf[CMD_RESULT_SIZE] = {0, }; fd_set in_put; fd_set temp_in; FD_ZERO(&in_put); FD_SET(sock, &in_put); FD_SET(fd, &in_put); printf(">"); fflush(stdout); while(is_continue) { temp_in = in_put; retval = select(fd > sock ? (fd + 1) : (sock + 1), &temp_in, 0, 0, NULL); if(retval == -1) { printf("selector error\n"); return -1; } else if(retval == 0) { printf("selector timeout\n"); continue; } else { if(FD_ISSET(sock, &temp_in) != 0) { struct sockaddr_in recv_addr; socklen_t recv_addr_size; recvfrom(sock, buf, CMD_RESULT_SIZE - 1, 0, (struct sockaddr*)&recv_addr, &recv_addr_size); printf("%s\n",buf); fflush(stdout); } if(FD_ISSET(fd, &temp_in) != 0) { get_cmd_line(fd); if(fd != STDIN_FILENO) { FD_CLR(fd, &in_put); close(fd); fd = (int)(int64_t)list_remove_first(fd_list); FD_SET(fd, &in_put); } } } } }
RESULT cmd_loop(GameContext* pContext, GameEventContext* pEvent, YESNO force, const char* strAlter) { char prompt[MAX_NAME_LEN + 10]; char cmdline[MAX_CMD_LEN]; const char* argv[MAX_PARAM_NUM]; int argc; char *next, *w; int n; RESULT ret; if(get_game_status(pContext) == Status_None) { snprintf(prompt, sizeof(prompt), "[SGS2010] $ "); } else { snprintf(prompt, sizeof(prompt), "[%s] $ ", CUR_PLAYER(pContext)->name); } while(1) { if (strAlter != NULL) { MSG_OUT("%s\n", strAlter) ; } if(NULL == get_cmd_line(pContext, pEvent, prompt, cmdline, sizeof(cmdline))) { break; } next = cmdline; argc = 0; memset(argv, 0, sizeof(argv)); while( NULL != (w = get_word(next, &next) ) ) { if(argc < (int)COUNT(argv)) { argv[argc++] = w; } } if(*next != 0) { MSG_OUT("error cmd at col %d!\n", (int)(next - cmdline)); } else if(argc > 0) { ret = R_DEF; //if(funper != NULL) //{ // ret = (*funper)(argv, argc, pContext, ud); // if(ret < 0) // return ret; //} if(ret == R_DEF) { for(n= 0; n < CMD_NUM; n++) { if(!strcmp(argv[0], s_cmdDispatch[n].name) || (s_cmdDispatch[n].sort_name && !strcmp(argv[0], s_cmdDispatch[n].sort_name))) { break; } } if(n < CMD_NUM) { ret = (*s_cmdDispatch[n].func)(argv, argc, pContext, pEvent); if(ret == R_CANCEL && force == YES) { MSG_OUT("当前不能取消(放弃)操作!\n"); } else { switch(ret) { case R_SUCC: // success and back to caller case R_BACK: // back to caller no result case R_CANCEL: // cancel current operator and back to caller case R_EXIT: // exit game return ret; default: break; } } } else { MSG_OUT("无效的命令:\'%s\'!\n", argv[0]); } } } } // end of input ??? return R_EXIT; }
RESULT select_loop(GameContext* pContext, GameEventContext* pEvent, const SelOption options[], int optnum, const char* strAlter, int* out_value) { int n; const char* s; const char* p; char buffer[1024]; int buflen; int v; while(1) { if(strAlter) MSG_OUT("%s\n", strAlter); for(n = 0; n < optnum; n++) { buflen = 0; buffer[0] = 0; buflen += sprintf(buffer + buflen, "("); s = options[n].input; if(*s == '\n' || *s == '\0') { buflen += sprintf(buffer + buflen, "%d", options[n].value); if(*s != 0) s++; } else { p = strchr_notnull(s, '\n'); strncpy(buffer + buflen, s, p - s); buflen += (p-s); if(*p == '\0') s = p; else s = p + 1; } while(*s != '\0' && *s != '\n' ) { p = strchr_notnull(s, '\n'); buffer[buflen++] = '/'; strncpy(buffer + buflen, s, p - s); buflen += (p-s); if(*p == 0) break; s = p + 1; } buflen += sprintf(buffer + buflen, ") %s", options[n].text); buffer[buflen] = 0; MSG_OUT(" %s\n", buffer); } if(NULL == get_cmd_line(pContext, pEvent, "[请选择] : ", buffer, sizeof(buffer))) return R_E_FAIL; strtrim(buffer); buflen = strlen(buffer); if(R_SUCC == to_int(buffer, &v)) { for(n = 0; n < optnum; n++) { if((options[n].input[0] == '\0' || options[n].input[0] == '\n') && v == options[n].value) { *out_value = options[n].value; return R_SUCC; } } } for(n = 0; n < optnum; n++) { s = options[n].input; if(*s == '\n') s++; while(*s != '\0' && *s != '\n') { p = strchr_notnull(s, '\n'); if(buflen == (p-s) && !strncasecmp(s, buffer, buflen)) { *out_value = options[n].value; return R_SUCC; } if(*p == 0) break; s = p + 1; } } // 没有找到匹配,看看是不是info 指令 ,是的话,执行info cmd_comm(pContext, pEvent, buffer); } return R_E_FAIL; }
/** * \class ds::EngineSettings */ EngineSettings::EngineSettings() { // Default file names. const std::string DEFAULT_FILENAME("engine.xml"); std::string appFilename = DEFAULT_FILENAME, localFilename, projectPath; std::vector<std::wstring> args; get_cmd_line(args); for (auto it=args.begin(), end=args.end(); it != end; ++it) { std::string key, value; if (!get_key_value(*it, key, value)) continue; if (key == "app_settings") { appFilename = value; if (localFilename.empty()) localFilename = value; } else if (key == "local_settings") { localFilename = value; } else if (key == "local_path") { // The local path and filename need to be parsed here. Poco::Path p(value); const std::string& fn(p.getFileName()); const std::string full(p.toString()); projectPath = full.substr(0, full.length()-(fn.length()+1)); localFilename = fn; } } if (localFilename.empty()) localFilename = DEFAULT_FILENAME; // I have all the argument-supplied paths and filenames. Now I can // start reading my settings files. // APP SETTINGS // Find my app settings/ directory. This will vary based on whether I'm in a dev environment or // in a production, but I will have a settings/ folder either at or above me. const std::string appSettingsPath = ds::Environment::getAppFolder(ds::Environment::SETTINGS()); if (appSettingsPath.empty()) throw std::runtime_error("Missing application settings folder"); Poco::Path appP(appSettingsPath); appP.append(appFilename); readFrom(appP.toString(), false); // LOCAL SETTINGS // The project path is taken from the supplied arguments, if it existed, or else it's // pulled from the settings I just loaded. If neither has it, then I guess no local settings. if (projectPath.empty()) { projectPath = getText("project_path", 0, projectPath); } else { // If it exists, then make sure then any project_path in the settings is the same. No one // should ever use that, but let's be safe. ds::cfg::Settings::Editor ed(*this, Editor::SET_MODE); ed.setText("project_path", projectPath); } if (!projectPath.empty()) { // Set the global project path PROJECT_PATH = projectPath; readFrom(ds::Environment::getLocalSettingsPath(localFilename), true); // Load the configuration settings, which can be used to modify settings even more. // Currently used to provide alternate layout sizes. ds::Environment::loadSettings("configuration.xml", CONFIGURATION_SETTINGS); CONFIGURATION_FOLDER = CONFIGURATION_SETTINGS.getText("folder", 0, ""); // If the folder exists, then apply any changes to the engine file if (!CONFIGURATION_FOLDER.empty()) { const std::string app = ds::Environment::expand("%APP%/settings/%CFG_FOLDER%/" + appFilename); const std::string local = ds::Environment::expand("%LOCAL%/settings/%PP%/%CFG_FOLDER%/" + appFilename); readFrom(app, true); readFrom(local, true); } } }
main(int argc, char **argv) { extern int optind; /* for use of getopt() */ extern char *optarg; /* for use of getopt() */ int ch; /* command-line option letter */ static char *ProgName = "esig2fea"; /* name of this program */ static char *Version = SCCS_VERSION; /* program SCCS version */ static char *Date = SCCS_DATE; /* program SCCS date */ char **field_names = NULL; int num_fields = 0; int alloc_fields = 0; int rflag = NO; /* -r option specified? */ char *rrange; /* arguments of -r option */ long start_rec; /* starting record number */ long end_rec; /* ending record number */ long num_recs; /* number of records to read (0 means all up to end of file) */ long num_read; /* number of records actually read */ char *iname; /* input file name */ FILE *ifile; /* input stream */ FieldList list; /* input field list */ int inord; /* input: field order or type order? */ FieldSpec **ifields; /* input fields in field or type order */ char *subtype = NULL; /* FEA subtype name */ int subtype_code = NONE; /* numeric subtype code */ FieldSpec *fld; /* spec of various special fields */ char *oname; /* output file name */ FILE *ofile; /* output stream */ struct header *ohd; /* output file header */ struct fea_data *orec; /* output record */ int outord = TYPE_ORDER; char *version; /* version from input preamble */ int arch; /* architecture from input preamble */ long pre_size; /* preamble size */ long hdr_size; /* header size (bytes) from preamble */ long rec_size; /* record size from preamble */ double rec_freq; double start_time_offset; double *data; long len, i; struct header *source; /* embedded source-file header */ while ((ch = getopt(argc, argv, "f:r:x:FT:")) != EOF) switch (ch) { case 'f': if (num_fields >= alloc_fields) { size_t size; alloc_fields = num_fields + 1 + num_fields/2; size = (alloc_fields + 1) * sizeof(char *); field_names = (char **) ((field_names == NULL) ? malloc(size) : realloc(field_names, size)); } field_names[num_fields++] = optarg; field_names[num_fields] = NULL; break; case 'r': rflag = YES; rrange = optarg; break; case 'x': debug_level = atoi(optarg); break; case 'F': outord = FIELD_ORDER; break; case 'T': subtype = optarg; break; default: SYNTAX; break; } if (argc - optind > 2) { fprintf(stderr, "%s: too many file names specified.\n", ProgName); SYNTAX; } if (argc - optind < 2) { fprintf(stderr, "%s: too few file names specified.\n", ProgName); SYNTAX; } DebugMsgLevel = debug_level; DebugMsgFunc = DebugPrint; iname = argv[optind++]; list = OpenIn(iname, &version, &arch, &pre_size, &hdr_size, &rec_size, &ifile); REQUIRE(list != NULL, "read header failed"); if (ifile == stdin) iname = "<stdin>"; oname = argv[optind++]; start_rec = 0; end_rec = LONG_MAX; num_recs = 0; /* 0 means continue to end of file */ if (rflag) { lrange_switch(rrange, &start_rec, &end_rec, 0); if (end_rec != LONG_MAX) num_recs = end_rec - start_rec + 1; } REQUIRE(start_rec >= 0, "can't start before beginning of file"); REQUIRE(end_rec >= start_rec, "empty range of records specified"); if (debug_level) fprintf(stderr, "start_rec: %ld. end_rec: %ld. num_recs: %ld.\n", start_rec, end_rec, num_recs); REQUIRE(GetFieldOrdering(list, &inord), "cant get field ordering of input"); switch (inord) { case TYPE_ORDER: if (debug_level) fprintf(stderr, "making type-ordered field array.\n"); ifields = TypeOrder(list); break; case FIELD_ORDER: if (debug_level) fprintf(stderr, "making field-ordered field array.\n"); ifields = FieldOrder(list); break; default: REQUIRE(0, "input order neither TYPE_ORDER nor FIELD_ORDER"); break; } ohd = FieldList_to_fea(list, &orec, field_names, FALSE); REQUIRE(ohd != NULL, "failure converting input field list to header & record struct"); if (subtype != NULL) { subtype_code = lin_search(fea_file_type, subtype); if (subtype_code == -1) fprintf(stderr, "%s: unknown FEA file subtype \"%s\" ignored.\n", ProgName, subtype); else ohd->hd.fea->fea_type = subtype_code; } if (outord == FIELD_ORDER) ohd->hd.fea->field_order = YES; fld = FindField(list, "recordFreq"); if (fld != NULL && fld->occurrence == GLOBAL && fld->data != NULL) { (void) type_convert(1L, (char *) fld->data, ElibTypeToEsps(fld->type), (char *) &rec_freq, FDOUBLE, (void (*)()) NULL); *add_genhd_d("record_freq", NULL, 1, ohd) = rec_freq; } else rec_freq = 1.0; fld = FindField(list, "startTime"); if (fld != NULL && fld->occurrence == GLOBAL && fld->data != NULL && rec_freq != 0) { start_time_offset = start_rec / rec_freq; len = FieldLength(fld); data = (double *) type_convert(len, (char *) fld->data, ElibTypeToEsps(fld->type), (char *) NULL, FDOUBLE, (void (*)()) NULL); if (start_time_offset != 0) { for (i = 0; i < len; i++) data[i] += start_time_offset; } (void) add_genhd_d("start_time", data, len, ohd); } (void) strcpy(ohd->common.prog, ProgName); (void) strcpy(ohd->common.vers, Version); (void) strcpy(ohd->common.progdate, Date); source = FieldList_to_fea(list, NULL, NULL, TRUE); add_source_file(ohd, savestring(iname), source); add_comment(ohd, get_cmd_line(argc, argv)); oname = eopen(ProgName, oname, "w", NONE, NONE, NULL, &ofile); write_header(ohd, ofile); num_read = SkipRecs(ifile, start_rec, RecordSize(list, arch), ifields, arch); if (num_read != start_rec) { fprintf(stderr, "%s: couldn't reach starting record; only %ld skipped.\n", ProgName, num_read); exit(0); } for ( ; num_read <= end_rec && ReadRecord(ifields, arch, ifile); num_read++) { put_fea_rec(orec, ohd, ofile); } if (num_read <= end_rec && num_recs != 0) fprintf(stderr, "esig2fea: only %ld records read.\n", num_read - start_rec); exit(0); /*NOTREACHED*/ }