void windowbox_parse (char *tline, FILE * fd, char **unused1, int *unused2) { FilePtrAndData fpd ; ConfigDef *ConfigReader ; FreeStorageElem *Storage = NULL, *more_stuff = NULL; ASWindowBox **aswbox_list = &(ASDefaultScr->Feel.window_boxes); unsigned int *count = &(ASDefaultScr->Feel.window_boxes_num); ASWindowBox *new_box ; ConfigData cd ; fpd.fp = fd ; fpd.data = safemalloc( 12+1+strlen(tline)+1+1 ) ; sprintf( fpd.data, "WindowBox %s\n", tline ); LOCAL_DEBUG_OUT( "fd(%p)->tline(\"%s\")->fpd.data(\"%s\")", fd, tline, fpd.data ); cd.fileptranddata = &fpd ; ConfigReader = InitConfigReader ((char*)get_application_name(), &WindowBoxSyntax, CDT_FilePtrAndData, cd, NULL); free( fpd.data ); if (!ConfigReader) return ; PrintConfigReader (ConfigReader); ParseConfig (ConfigReader, &Storage); /* getting rid of all the crap first */ StorageCleanUp (&Storage, &more_stuff, CF_DISABLED_OPTION); DestroyFreeStorage (&more_stuff); if( (new_box = ProcessWindowBoxOptions (Storage)) != NULL ) { int i = *count ; ++(*count) ; *aswbox_list = realloc( *aswbox_list, sizeof(ASWindowBox)*(i+1)); (*aswbox_list)[i] = *new_box ; free( new_box ); } DestroyConfig (ConfigReader); DestroyFreeStorage (&Storage); }
//! 读取配置文件并覆写 bool CLogerManager::Config(std::string cfgPath) { if (!m_configFile.empty()) { std::cout << "log4z configure error: too many too call Config. the old config file="<< m_configFile << ", the new config file=" << cfgPath << std::endl; return false; } m_configFile = cfgPath; std::map<std::string, LoggerInfo> loggerMap; ParseConfig(cfgPath, loggerMap); for (std::map<std::string, LoggerInfo>::iterator iter = loggerMap.begin(); iter != loggerMap.end(); ++iter) { CreateLogger(iter->second._name, iter->second._path, iter->second._level, iter->second._display, iter->second._monthdir, iter->second._limitsize); } return true; }
/*---------------------------------------------------------------------- | NPT_LogManager::ParseConfigSource +---------------------------------------------------------------------*/ NPT_Result NPT_LogManager::ParseConfigSource(NPT_String& source) { if (source.StartsWith("file:")) { /* file source */ ParseConfigFile(source.GetChars()+5); } else if (source.StartsWith("plist:")) { /* property list source */ ParseConfig(source.GetChars()+6, source.GetLength()-6); } else if (source.StartsWith("http:port=")) { /* http configurator */ unsigned int port = 0; NPT_Result result = NPT_ParseInteger(source.GetChars()+10, port, true); if (NPT_FAILED(result)) return result; new NPT_HttpLoggerConfigurator(port); } else { return NPT_ERROR_INVALID_SYNTAX; } return NPT_SUCCESS; }
bool CLogerManager::UpdateConfig() { if (m_configFile.empty()) { return false; } std::map<std::string, LoggerInfo> loggerMap; ParseConfig(m_configFile, loggerMap); for (std::map<std::string, LoggerInfo>::iterator iter = loggerMap.begin(); iter != loggerMap.end(); ++iter) { LoggerId id = FindLogger(iter->first); if (id != LOG4Z_INVALID_LOGGER_ID) { SetLoggerDisplay(id, iter->second._display); SetLoggerLevel(id, iter->second._level); SetLoggerMonthdir(id, iter->second._monthdir); SetLoggerLimitSize(id, iter->second._limitsize); } } return true; }
int init_suite1(void) { int k=4; // char *output = "out.txt", *input = "in.txt", *query = "query.txt"; //char output[512]; char input[512]; int confNums[5]; //char query[512]; //FILE* queryFile; //FILE* outputFile; //size_t lineSize=0; //size_t lineLen=0; //LSH* lsh; if((config=fopen("./inputFiles/cluster_5.conf","r"))==NULL) { perror("File specified could not be opened(inp)\n"); exit(-1); } char secBuff1[256]; char secBuff2[256]; //printf("input %s, output %s, query %s, k = %d, L = %d\n",input, output, query, k, L); memset(secBuff1,'\0',sizeof(secBuff1)); memset(secBuff2,'\0',sizeof(secBuff2)); if((inputFile=fopen("./inputFiles/Ex2_Datasets/DataHamming_5_1000x64.csv","r"))==NULL) { perror("File specified could not be opened(inp)\n"); exit(-1); } specifyDataset(inputFile); ParseConfig(config,confNums); parseData(inputFile, confNums[0]); return 0; }
bool CCommonParm::AnalizeParameters(int argc, char *argv[]) { try { NLastGetopt::TOpts opts = MakeTomitaParserOpts(); NLastGetopt::TOptsParseResult r(&opts, argc, argv); if (r.Has(OPT_BINARY_DIR)) m_args[OPT_BINARY_DIR] = r.Get(OPT_BINARY_DIR); if (r.GetFreeArgCount() > 0) { m_strConfig = r.GetFreeArgs()[0]; ParseConfig(m_strConfig); } else return false; return true; } catch (yexception& e) { m_strError += e.what(); return false; } catch (...) { m_strError += "Unknown error in \"CParmBase::AnalizeParameters\""; return false; } }
/** * Function name CInsertResource::Execute * Description * @return void * @exception * @see */ BOOL CInsertResource::Execute() { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); Init(); SetFileName(); BOOL bRes = !DoesFileExist(m_sFileName, TRUE); if(bRes) { GenResource(m_ResourceText); COperation::WriteFile(m_ResourceText); ParseConfig(); GenImportText(m_ImportText); InsertResourceImport(); CString ConfigText = m_ConfigText.c_str(); WriteFile(ConfigText); InformProjectManager(); } m_ConfigText.empty(); m_ResourceText.Empty(); m_ImportText.Empty(); m_aVarList.RemoveAll(); return bRes; }
bool CCVar::HandleCommand(CMessage *pMsg) { if(!pMsg->sCmd.Compare("cvar.list")) { g_cMainCtrl.m_cIRC.SendMsg(pMsg->bSilent, pMsg->bNotice, "-[ cvar list ]-", pMsg->sReplyTo.Str()); list<cvar*>::iterator ic; int iCount=0; for(ic=m_lCvars.begin(); ic!=m_lCvars.end(); ++ic) { iCount++; g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "%d. / \"%s\" / \"%s\" / \"%s\"", \ iCount, (*ic)->sName.CStr(), (*ic)->sValue.CStr(), (*ic)->sDescription.CStr()); Sleep(1500); } return true; } else if(!pMsg->sCmd.Compare("cvar.get")) { cvar *pTemp=FindCvarByName(pMsg->sChatString.Token(1, " "), true); if(pTemp) return g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "%s == \"%s\"", pTemp->sName.CStr(), pTemp->sValue.CStr()); else return false; } else if(!pMsg->sCmd.Compare("cvar.set")) { cvar *pTemp=FindCvarByName(pMsg->sChatString.Token(1, " "), true); if(pTemp) { CString sOldStr(pTemp->sValue); SetCVar(pTemp, pMsg->sChatString.Token(2, " ", true)); g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "%s = \"%s\" (was \"%s\")", pTemp->sName.CStr(), pTemp->sValue.CStr(), sOldStr.CStr()); return true; } else return false; } else if(!pMsg->sCmd.Compare("cvar.loadconfig")) { if(ParseConfig(CString(""))) return g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "Successfully loaded config..."); else { g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "Unable to load config..."); return false; } } else if(!pMsg->sCmd.Compare("cvar.saveconfig")) { if(SaveConfig(CString(""))) return g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "Successfully saved config..."); else { g_cMainCtrl.m_cIRC.SendFormat(pMsg->bSilent, pMsg->bNotice, pMsg->sReplyTo.Str(), "Unable to save config..."); return false; } } return false; }
static boolean config_handler(TinyWebServer& web_server) { web_server.send_error_code(200); web_server.end_headers(); const char* length_str = web_server.get_header_value("Content-Length"); int length = atoi(length_str); uint32_t start_time = millis(); StringParse buf; EthernetClient client = web_server.get_client(); while (buf.length() < length && client.connected() && (millis() - start_time < 30000)) { if (!client.available()) continue; buf += client.readString(); } ParseConfig(buf); IP_Config.SaveConfig(); main_page(client, F("<font color='green'>IP Config saved</font>")); return true; }
bool CCVar::ParseConfig(const char *szFilename) { return ParseConfig(CString(szFilename)); }
int main(int argc, char *argv[]) { int x; extern DMC dns_message_handle; progname = xstrdup(strrchr(argv[0], '/') ? strchr(argv[0], '/') + 1 : argv[0]); if (NULL == progname) return 1; srandom(time(NULL)); openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); while ((x = getopt(argc, argv, "pd")) != -1) { switch (x) { case 'p': promisc_flag = 0; break; case 'd': debug_flag = 1; break; default: usage(); break; } } argc -= optind; argv += optind; if (argc != 1) usage(); dns_message_init(); ParseConfig(argv[0]); cip_net_indexer_init(); if (!debug_flag) daemonize(); write_pid_file(); /* * I'm using fork() in this loop, (a) out of laziness, and (b) * because I'm worried we might drop packets. Making sure each * child collector runs for a small amount of time (60 secodns) * means I can be lazy about memory management (leaks). To * minimize the chance for dropped packets, I'd like to spawn * a new collector as soon as (or even before) the current * collector exits. */ if (!debug_flag) { syslog(LOG_INFO, "Sleeping for %d seconds", 60 - (int) (time(NULL) % 60)); sleep(60 - (time(NULL) % 60)); } syslog(LOG_INFO, "Running"); for (;;) { pid_t cpid = fork(); if (0 == cpid) { Pcap_run(dns_message_handle, ip_message_handle); if (0 == fork()) { dns_message_report(); ip_message_report(); } _exit(0); } else { int cstatus = 0; syslog(LOG_DEBUG, "waiting for child pid %d", (int) cpid); while (waitpid(cpid, &cstatus, 0) < 0) (void) 0; if (WIFSIGNALED(cstatus)) syslog(LOG_NOTICE, "child exited with signal %d, status %d", WTERMSIG(cstatus), WEXITSTATUS(cstatus)); } if (debug_flag) break; } Pcap_close(); return 0; }
int main(int argc, char *argv[]) { int x; extern DMC dns_message_handle; int result; struct timeval break_start = {0,0}; progname = xstrdup(strrchr(argv[0], '/') ? strchr(argv[0], '/') + 1 : argv[0]); if (NULL == progname) return 1; srandom(time(NULL)); openlog(progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); while ((x = getopt(argc, argv, "fpd")) != -1) { switch (x) { case 'f': nodaemon_flag = 1; break; case 'p': promisc_flag = 0; break; case 'd': debug_flag++; nodaemon_flag = 1; break; default: usage(); break; } } argc -= optind; argv += optind; if (argc != 1) usage(); dns_message_init(); ParseConfig(argv[0]); cip_net_indexer_init(); if (!nodaemon_flag) daemonize(); write_pid_file(); if (!debug_flag) { syslog(LOG_INFO, "Sleeping for %d seconds", 60 - (int) (time(NULL) % 60)); sleep(60 - (time(NULL) % 60)); } syslog(LOG_INFO, "%s", "Running"); do { useArena(); /* Initialize a memory arena for data collection. */ if (debug_flag && break_start.tv_sec > 0) { struct timeval now; gettimeofday(&now, NULL); syslog(LOG_INFO, "inter-run processing delay: %ld ms", (now.tv_usec - break_start.tv_usec) / 1000 + 1000 * (now.tv_sec - break_start.tv_sec)); } #if HAVE_LIBNCAP result = Ncap_run(dns_message_handle, ip_message_handle); #else result = Pcap_run(dns_message_handle, ip_message_handle); #endif if (debug_flag) gettimeofday(&break_start, NULL); if (0 == fork()) { dump_reports(); _exit(0); } /* Parent quickly frees and clears its copy of the data so it can resume processing packets. */ freeArena(); dns_message_clear_arrays(); ip_message_clear_arrays(); { /* Reap children. (Most recent probably has not exited yet, but * older ones should have.) */ int cstatus = 0; pid_t pid; while ((pid = waitpid(0, &cstatus, WNOHANG)) > 0) { if (WIFSIGNALED(cstatus)) syslog(LOG_NOTICE, "child %d exited with signal %d", pid, WTERMSIG(cstatus)); if (WIFEXITED(cstatus) && WEXITSTATUS(cstatus) != 0) syslog(LOG_NOTICE, "child %d exited with status %d", pid, WEXITSTATUS(cstatus)); } } } while (result > 0 && debug_flag == 0); #if HAVE_LIBNCAP Ncap_close(); #else Pcap_close(); #endif return 0; }
/****************************************************************************** Main - Setup the XConnection,request the window list and loop forever Based on main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ int main(int argc, char **argv) { char *temp, *s; /* Save the program name for error messages and config parsing */ temp = argv[0]; s=strrchr(argv[0], '/'); if (s != NULL) temp = s + 1; /* Setup my name */ Module = safemalloc(strlen(temp)+2); strcpy(Module,"*"); strcat(Module, temp); Clength = strlen(Module); /* Open the console for messages */ OpenConsole(); if((argc != 6)&&(argc != 7)) { fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, VERSION); ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module, VERSION); exit(1); } if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; Fvwm_fd[0] = atoi(argv[1]); Fvwm_fd[1] = atoi(argv[2]); signal (SIGPIPE, DeadPipe); /* Parse the config file */ ParseConfig(); /* Setup the XConnection */ StartMeUp(); XSetErrorHandler((XErrorHandler) ErrorHandler); InitPictureCMap(dpy, Root); InitArray(&buttons,0,0,win_width, fontheight+6); InitList(&windows); fd_width = GetFdWidth(); /* Request a list of all windows, * wait for ConfigureWindow packets */ SendFvwmPipe("Send_WindowList",0); /* SetMessageMask(Fvwm_fd,M_ADD_WINDOW|M_CONFIGURE_WINDOW| M_DESTROY_WINDOW| M_WINDOW_NAME|M_ICON_NAME|M_DEICONIFY|M_ICONIFY|M_END_WINDOWLIST| M_NEW_DESK| M_NEW_PAGE);*/ /* Recieve all messages from Fvwm */ EndLessLoop(); return 0; }
LevelDBEngineFactory::LevelDBEngineFactory(const Properties& props) { ParseConfig(props, m_cfg); }
WharfConfig *ParseWharfOptions (const char *filename, char *myname) { ConfigData cd; ConfigDef *ConfigReader; WharfConfig *config = CreateWharfConfig (); FreeStorageElem *Storage = NULL, *pCurr; ConfigItem item; TermDef *folder_term = func2fterm (F_Folder, False); cd.filename = filename; ConfigReader = InitConfigReader (myname, &WharfSyntax, CDT_Filename, cd, NULL /*WharfSpecialFunc */ ); if (!ConfigReader) return config; folder_term->sub_syntax = &WharfSyntax; item.memory = NULL; PrintConfigReader (ConfigReader); ParseConfig (ConfigReader, &Storage); /* getting rid of all the crap first */ StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION); config->balloon_conf = Process_balloonOptions (Storage, NULL, BALLOON_ID_START); config->style_defs = free_storage2MyStyleDefinitionsList (Storage); for (pCurr = Storage; pCurr; pCurr = pCurr->next) { if (pCurr->term == NULL) continue; if (ReadFlagItem (&(config->set_flags), &(config->flags), pCurr, WharfFlags)) { continue; } if (!ReadConfigItem (&item, pCurr)) continue; switch (pCurr->term->id) { case WHARF_Wharf_ID: item.ok_to_free = 1; ParseWharfFolder (&pCurr, &(config->root_folder)); break; case WHARF_Geometry_ID: set_flags (config->set_flags, WHARF_GEOMETRY); config->geometry = item.data.geometry; break; case WHARF_Rows_ID: set_flags (config->set_flags, WHARF_ROWS); config->rows = item.data.integer; break; case WHARF_Columns_ID: set_flags (config->set_flags, WHARF_COLUMNS); clear_flags (config->set_flags, WHARF_ROWS); config->columns = item.data.integer; break; case WHARF_WithdrawStyle_ID: set_flags (config->set_flags, WHARF_WITHDRAW_STYLE); config->withdraw_style = item.data.integer; break; case WHARF_ForceSize_ID: set_flags (config->set_flags, WHARF_FORCE_SIZE); config->force_size = item.data.geometry; /* errorneous value check */ if (!(config->force_size.flags & WidthValue)) config->force_size.width = 64; if (!(config->force_size.flags & HeightValue)) config->force_size.height = 64; config->force_size.flags = WidthValue | HeightValue; break; case WHARF_TextureType_ID: set_flags (config->set_flags, WHARF_TEXTURE_TYPE); config->texture_type = item.data.integer; break; case WHARF_BgColor_ID: set_string_value (&(config->bg_color), item.data.string, &(config->set_flags), WHARF_BG_COLOR); break; case WHARF_TextureColor_ID: set_string_value (&(config->texture_color), item.data.string, &(config->set_flags), WHARF_TEXTURE_COLOR); break; case WHARF_Pixmap_ID: set_string_value (&(config->pixmap), item.data.string, &(config->set_flags), WHARF_PIXMAP); break; case WHARF_AnimateStepsMain_ID: set_flags (config->set_flags, WHARF_ANIMATE_STEPS_MAIN); config->animate_steps_main = item.data.integer; break; case WHARF_AnimateSteps_ID: set_flags (config->set_flags, WHARF_ANIMATE_STEPS); config->animate_steps = item.data.integer; break; case WHARF_AnimateDelay_ID: set_flags (config->set_flags, WHARF_ANIMATE_DELAY); config->animate_delay = item.data.integer; break; case WHARF_Sound_ID: if (pCurr->sub == NULL) { if (pCurr->argc > 0) { register char *sound = mystrdup (pCurr->argv[pCurr->argc - 1]); set_string_value (&(config->sounds[WHEV_PUSH]), sound, &(config->set_flags), WHARF_SOUND); } } else if (pCurr->sub->argc > 0) { register char *sound = mystrdup (pCurr->sub->argv[0]); set_string_value (& (config-> sounds[WHEV_Id2Code (pCurr->sub->term->id)]), sound, &(config->set_flags), WHARF_SOUND); } item.ok_to_free = 1; break; ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item, LabelLocation); ASCF_HANDLE_ALIGN_KEYWORD_CASE (WHARF, config, pCurr, AlignContents); ASCF_HANDLE_BEVEL_KEYWORD_CASE (WHARF, config, pCurr, Bevel); ASCF_HANDLE_SUBSYNTAX_KEYWORD_CASE (WHARF, config, pCurr, ShowHints, BalloonContents); ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item, CompositionMethod); ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item, FolderOffset); ASCF_HANDLE_INTEGER_KEYWORD_CASE (WHARF, config, item, OrthogonalFolderOffset); default: if (pCurr->term->type != TT_FLAG) item.ok_to_free = 1; } } if (get_flags (config->set_flags, WHARF_Bevel)) clear_flags (config->flags, WHARF_NO_BORDER); ReadConfigItem (&item, NULL); SHOW_CHECKPOINT; DestroyConfig (ConfigReader); SHOW_CHECKPOINT; DestroyFreeStorage (&Storage); SHOW_CHECKPOINT; return config; }
int main(int argc, char *argv[]) { int c, fd, omask, maxfds; fd_set rset; /* * Close any open file descriptors. * Temporarily leave stdin & stdout open for `-d', * and stderr open for any pre-syslog error messages. */ { int i, nfds = getdtablesize(); for (i = 0; i < nfds; i++) if (i != fileno(stdin) && i != fileno(stdout) && i != fileno(stderr)) (void) close(i); } /* * Parse any arguments. */ while ((c = getopt(argc, argv, "adi:")) != -1) switch(c) { case 'a': BootAny++; break; case 'd': DebugFlg++; break; case 'i': IntfName = optarg; break; default: usage(); } for (; optind < argc; optind++) { if (ConfigFile == NULL) ConfigFile = argv[optind]; else { warnx("too many config files (`%s' ignored)", argv[optind]); } } if (ConfigFile == NULL) /* use default config file */ ConfigFile = DfltConfig; if (DebugFlg) { DbgFp = stdout; /* output to stdout */ (void) signal(SIGUSR1, SIG_IGN); /* dont muck w/DbgFp */ (void) signal(SIGUSR2, SIG_IGN); (void) fclose(stderr); /* finished with it */ } else { if (daemon(0, 0)) err(1, "can't detach from terminal"); (void) signal(SIGUSR1, DebugOn); (void) signal(SIGUSR2, DebugOff); } openlog("rbootd", LOG_PID, LOG_DAEMON); /* * If no interface was specified, get one now. * * This is convoluted because we want to get the default interface * name for the syslog("restarted") message. If BpfGetIntfName() * runs into an error, it will return a syslog-able error message * (in `errmsg') which will be displayed here. */ if (IntfName == NULL) { char *errmsg; if ((IntfName = BpfGetIntfName(&errmsg)) == NULL) { /* Backslash to avoid trigraph '??)'. */ syslog(LOG_NOTICE, "restarted (?\?)"); /* BpfGetIntfName() returns safe names, using %m */ syslog(LOG_ERR, "%s", errmsg); Exit(0); } } syslog(LOG_NOTICE, "restarted (%s)", IntfName); (void) signal(SIGHUP, ReConfig); (void) signal(SIGINT, Exit); (void) signal(SIGTERM, Exit); /* * Grab our host name and pid. */ if (gethostname(MyHost, MAXHOSTNAMELEN - 1) < 0) { syslog(LOG_ERR, "gethostname: %m"); Exit(0); } MyHost[MAXHOSTNAMELEN - 1] = '\0'; MyPid = getpid(); /* * Write proc's pid to a file. */ { FILE *fp; if ((fp = fopen(PidFile, "w")) != NULL) { (void) fprintf(fp, "%d\n", (int) MyPid); (void) fclose(fp); } else { syslog(LOG_WARNING, "fopen: failed (%s)", PidFile); } } /* * All boot files are relative to the boot directory, we might * as well chdir() there to make life easier. */ if (chdir(BootDir) < 0) { syslog(LOG_ERR, "chdir: %m (%s)", BootDir); Exit(0); } /* * Initial configuration. */ omask = sigblock(sigmask(SIGHUP)); /* prevent reconfig's */ if (GetBootFiles() == 0) /* get list of boot files */ Exit(0); if (ParseConfig() == 0) /* parse config file */ Exit(0); /* * Open and initialize a BPF device for the appropriate interface. * If an error is encountered, a message is displayed and Exit() * is called. */ fd = BpfOpen(); (void) sigsetmask(omask); /* allow reconfig's */ /* * Main loop: receive a packet, determine where it came from, * and if we service this host, call routine to handle request. */ maxfds = fd + 1; FD_ZERO(&rset); FD_SET(fd, &rset); for (;;) { struct timeval timeout; fd_set r; int nsel; r = rset; if (RmpConns == NULL) { /* timeout isn't necessary */ nsel = select(maxfds, &r, NULL, NULL, NULL); } else { timeout.tv_sec = RMP_TIMEOUT; timeout.tv_usec = 0; nsel = select(maxfds, &r, NULL, NULL, &timeout); } if (nsel < 0) { if (errno == EINTR) continue; syslog(LOG_ERR, "select: %m"); Exit(0); } else if (nsel == 0) { /* timeout */ DoTimeout(); /* clear stale conns */ continue; } if (FD_ISSET(fd, &r)) { RMPCONN rconn; CLIENT *client, *FindClient(); int doread = 1; while (BpfRead(&rconn, doread)) { doread = 0; if (DbgFp != NULL) /* display packet */ DispPkt(&rconn,DIR_RCVD); omask = sigblock(sigmask(SIGHUP)); /* * If we do not restrict service, set the * client to NULL (ProcessPacket() handles * this). Otherwise, check that we can * service this host; if not, log a message * and ignore the packet. */ if (BootAny) { client = NULL; } else if ((client=FindClient(&rconn))==NULL) { syslog(LOG_INFO, "%s: boot packet ignored", EnetStr(&rconn)); (void) sigsetmask(omask); continue; } ProcessPacket(&rconn,client); (void) sigsetmask(omask); } } } }
void ParseConfig( const char * cfg ) { ParseConfig( string( cfg ) ); }
LMDBEngineFactory::LMDBEngineFactory(const Properties& props) : m_env(NULL), m_env_opened(false) { ParseConfig(props, m_cfg); }
int main(int argc, char* argv[]) { FILE* Log1; FILE* Log2; FILE* Opt; unsigned long StartFrame; frame CurrentFrame1; frame CurrentFrame2; unsigned long OldFrameNumber; bool HoldLog1; bool HoldLog2; HoldLog1=HoldLog2=FALSE; NoDifferences=TRUE; RememberedVars.Count=0; if(argc!=5) { fprintf(stderr, "Requires 4 arguments\n"); exit(1); } StartFrame=strtol(argv[1], NULL, 0); Log1=fopen(argv[2], "r"); if(!Log1) { fprintf(stderr, "Could not open file '%s'\n", argv[1]); exit(1); } Log2=fopen(argv[3], "r"); if(!Log2) { fprintf(stderr, "Could not open file '%s'\n", argv[2]); exit(1); } Opt=fopen(argv[4], "r"); if(!Opt) { fprintf(stderr, "Could not open options file '%s'\n", argv[3]); exit(1); } ParseConfig(Opt); fclose(Opt); if(StartFrame!=0) { fprintf(stderr, "Skipping initial frames...\n", StartFrame); ForwardToFrame(StartFrame-1, Log1, Log2); } fprintf(stderr, "Comparing logs at frame %d...\n", StartFrame); while(!feof(Log1) && !feof(Log2)) { int i; if(!HoldLog1) ParseFrame(Log1, &CurrentFrame1); else HoldLog1=FALSE; if(!HoldLog2) ParseFrame(Log2, &CurrentFrame2); else HoldLog2=FALSE; if(CurrentFrame1.Number==CurrentFrame2.Number) { if(!CompareFrames(&CurrentFrame1, &CurrentFrame2)) { int i; fprintf(stderr, "At previous frame (%d):\n", OldFrameNumber); for(i=0; i<RememberedVars.Count; i++) { fprintf(stderr, "\t%-10s <%s>\n", RememberedVars.Elements[i].Name, RememberedVars.Elements[i].Value); } exit(0); } } else { if(CurrentFrame1.Number>CurrentFrame2.Number) { fprintf(stderr, "Frame number %ld does not appear in log 1\n", CurrentFrame2.Number); HoldLog1=TRUE; } else { fprintf(stderr, "Frame number %ld does not appear in log 2\n", CurrentFrame1.Number); HoldLog2=TRUE; } } OldFrameNumber=CurrentFrame1.Number; for(i=0; i<RememberedVars.Count; i++) { strcpy(RememberedVars.Elements[i].Value, GetVariable(&CurrentFrame1, RememberedVars.Elements[i].Name)); } } fprintf(stderr, "Logs match\n"); exit(0); }
int SDLVisualTest_ParseHarnessArgs(char** argv, SDLVisualTest_HarnessState* state) { int i; SDLTest_Log("Parsing commandline arguments.."); if(!argv) { SDLTest_LogError("argv is NULL"); return 0; } if(!state) { SDLTest_LogError("state is NULL"); return 0; } /* initialize the state object */ state->sutargs[0] = '\0'; state->sutapp[0] = '\0'; state->output_dir[0] = '\0'; state->verify_dir[0] = '\0'; state->timeout = DEFAULT_SUT_TIMEOUT; SDL_memset(&state->sut_config, 0, sizeof(SDLVisualTest_SUTConfig)); SDL_memset(&state->action_queue, 0, sizeof(SDLVisualTest_ActionQueue)); state->variator_type = SDL_VARIATOR_RANDOM; state->num_variations = -1; state->no_launch = SDL_FALSE; /* parse config file if passed */ for(i = 0; argv[i]; i++) { if(StrCaseCmpIgnoreHyphen("config", argv[i]) == 0) { if(!argv[i + 1]) { SDLTest_Log("Arguments parsing error: invalid argument for config."); return 0; } if(!ParseConfig(argv[i + 1], state)) { SDLTest_LogError("ParseConfig() failed"); return 0; } } } /* parse the arguments */ for(i = 0; argv[i];) { int consumed = ParseArg(argv, i, state); if(consumed == -1 || consumed == 0) { SDLTest_LogError("ParseArg() failed"); return 0; } i += consumed; } if(state->variator_type == SDL_VARIATOR_RANDOM && state->num_variations == -1) state->num_variations = 1; /* check to see if required options have been passed */ if(!state->sutapp[0]) { SDLTest_LogError("sutapp must be passed."); return 0; } if(!state->sutargs[0] && !state->sut_config.options) { SDLTest_LogError("Either sutargs or parameter-config must be passed."); return 0; } if(!state->output_dir[0]) { SDL_strlcpy(state->output_dir, "./output", MAX_PATH_LEN); } if(!state->verify_dir[0]) { SDL_strlcpy(state->verify_dir, "./verify", MAX_PATH_LEN); } return 1; }
/****************************************************************************** Main - Setup the XConnection,request the window list and loop forever Based on main() from FvwmIdent: Copyright 1994, Robert Nation and Nobutaka Suzuki. ******************************************************************************/ int main(int argc, char **argv) { char *temp, *s; #ifdef HAVE_SIGACTION struct sigaction sigact; #endif /* Save the program name for error messages and config parsing */ temp = argv[0]; s=strrchr(argv[0], '/'); if (s != NULL) temp = s + 1; /* Setup my name */ Module = safemalloc(strlen(temp)+2); strcpy(Module,"*"); strcat(Module, temp); Clength = strlen(Module); /* Open the console for messages */ OpenConsole(); if((argc != 6)&&(argc != 7)) { fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module, VERSION); ConsoleMessage("%s Version %s should only be executed by fvwm!\n",Module, VERSION); exit(1); } if ((argc==7)&&(!strcasecmp(argv[6],"Transient"))) Transient=1; Fvwm_fd[0] = atoi(argv[1]); Fvwm_fd[1] = atoi(argv[2]); #ifdef HAVE_SIGACTION #ifdef SA_INTERRUPT sigact.sa_flags = SA_INTERRUPT; #else sigact.sa_flags = 0; #endif sigemptyset(&sigact.sa_mask); sigact.sa_handler = TerminateHandler; sigaction(SIGPIPE, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); #else signal(SIGPIPE, TerminateHandler); signal(SIGTERM, TerminateHandler); #ifdef HAVE_SIGINTERRUPT siginterrupt(SIGPIPE, True); siginterrupt(SIGTERM, True); #endif #endif /* Parse the config file */ ParseConfig(); /* Setup the XConnection */ StartMeUp(); XSetErrorHandler(ErrorHandler); InitPictureCMap(dpy, Root); InitArray(&buttons,0,0,win_width, fontheight+6); InitList(&windows); fd_width = GetFdWidth(); /* Request a list of all windows, * wait for ConfigureWindow packets */ SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME | M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME | M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST | M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME | #ifdef MINI_ICONS M_MINI_ICON | #endif M_STRING); SendFvwmPipe("Send_WindowList",0); /* Recieve all messages from Fvwm */ atexit(ShutMeDown); MainEventLoop(); return 0; }
//----------------------------------------------------------------------------- // Configuration changing function. // // First change to the new config and back again to determine if the driver // can handle the config. // If not, return error. // // Then query the host for its capability to use the config: // Format out: // "@CONFIG:<baud rate code>:<#data bits>:<#stop bits>:<parity on/off>!" // Format in: // OK/ER // // On ER, return error. // // On OK, change to the new configuration. Resynchronize with the host: // Target waits for host to send S(ync) // [host will delay at least .1 secs after changing baud rate so the // line has time to settle.] // // When receiving S(ync), target replies OK to the host which then // acknowledges with D(one). // // Host can also send R(esync) which means it didn't receieve the OK. If // so the target resends its S(ync) message. // // If the synchronization has not succeeded within 1 second // (configurable in the protocol), both host and target will revert to // the previous configuration and attempt to synchronize again. If // this fails, this call will hang and the host will consider the test // a failure. // // To Do: // Host&protocol currently only supports: // - no/even parity void CeCosTestSerialFilter::CMD_ChangeConfig(CeCosSerial &pSer, char* cfg_str) { ser_cfg_t new_cfg, old_cfg; ParseConfig(cfg_str, &new_cfg); // Return without changing the config if it's not valid. if (!VerifyConfig(pSer, &new_cfg)) { TargetASCIIWrite(pSer, "ER"); return; } // Tell target we're ready to go, wait 1/10 sec, and then change // the config. TargetASCIIWrite(pSer, "OK"); CeCosThreadUtils::Sleep(100); SetConfig(pSer, &new_cfg, &old_cfg); int loops; for (loops = 0; loops < 3; loops++) { unsigned int len, read; unsigned char buffer[2]; int delay_mticks = 0; // millisecond-ticks. 10 of these per target tick // Start by sending a Sync. TargetASCIIWrite(pSer, "S"); for(;;) { // Did target reply? len = 2; read = 0; buffer[0] = 0; buffer[1] = 0; if (!pSer.Read((void*) buffer, len, read)) { throw "CMD_ChangeConfig: serial read failure"; } if (read) { // If only one char read, try to get the next one. if (1 == read) { unsigned int read2 = 0; len = 1; if (!pSer.Read((void*) &buffer[1], len, read2)) { throw "CMD_ChangeConfig: serial read failure"; } read += read2; } if (m_bOptSerDebug) PrintHex(buffer, read); if ('O' == buffer[0] && 'K' == buffer[1]) { // success! TargetASCIIWrite(pSer, "D"); Trace("Config change succeeded.\n"); return; } else { // Garbage, ask target to resend its OK message. TargetASCIIWrite(pSer, "R"); } } else { // Resend Sync message. TargetASCIIWrite(pSer, "S"); } CeCosThreadUtils::Sleep(1); delay_mticks++; // Timeout. if (100 == delay_mticks/10) break; } SetConfig(pSer, &old_cfg, NULL); } // Abort the test. Log("FAIL:<target timed out>\n"); Trace("**** Timed out while changing config\n"); static const char kill_msg[] = "$X00#b8"; filter_abort_t* msg = new filter_abort_t(); msg->data_len = strlen(kill_msg); msg->data_ptr = (const unsigned char *)kill_msg; throw msg; }
int main(int argc, char **argv) { char *temp, *s; commands = (CommandChain*)safemalloc(sizeof(CommandChain)); commands->first = commands->last = NULL; /* Save the program name for error messages and config parsing */ temp = argv[0]; s = strrchr(argv[0], '/'); if (s != NULL) { temp = s + 1; } Module = temp; configPrefix = CatString2("*", Module); if ((argc != 6) && (argc != 7)) { fprintf(stderr, "%s Version %s should only be executed by fvwm!\n", Module, VERSION); exit(1); } fvwm_fd[0] = atoi(argv[1]); fvwm_fd[1] = atoi(argv[2]); /* Grab the X display information now. */ dpy = XOpenDisplay(displayName); if (!dpy) { fprintf(stderr, "%s: unable to open display '%s'\n", Module, XDisplayName (displayName)); exit (2); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); MyDisplayHeight = DisplayHeight(dpy, screen); MyDisplayWidth = DisplayWidth(dpy, screen); XSetErrorHandler(ErrorHandler); flib_init_graphics(dpy); XA_XSETROOT_ID = XInternAtom(dpy, "_XSETROOT_ID", False); XA_ESETROOT_PMAP_ID = XInternAtom(dpy, "ESETROOT_PMAP_ID", False); XA_XROOTPMAP_ID = XInternAtom(dpy, "_XROOTPMAP_ID", False); signal (SIGPIPE, DeadPipe); /* Parse the config file */ ParseConfig(); SetMessageMask(fvwm_fd, M_NEW_PAGE | M_NEW_DESK | M_CONFIG_INFO | M_END_CONFIG_INFO | M_SENDCONFIG); /* ** we really only want the current desk/page, and window list sends it */ SendInfo(fvwm_fd, "Send_WindowList", 0); /* tell fvwm we're running */ SendFinishedStartupNotification(fvwm_fd); /* Recieve all messages from fvwm */ EndLessLoop(); /* Should never get here! */ return 1; }
SoundConfig * ParseSoundOptions (const char *filename, char *myname) { ConfigData cd ; ConfigDef *SoundConfigReader; SoundConfig *config = CreateSoundConfig (); FreeStorageElem *Storage = NULL, *pCurr; ConfigItem item; cd.filename = filename ; SoundConfigReader = InitConfigReader (myname, &SoundSyntax, CDT_Filename, cd, NULL); if (!SoundConfigReader) return config; item.memory = NULL; PrintConfigReader (SoundConfigReader); ParseConfig (SoundConfigReader, &Storage); /* getting rid of all the crap first */ StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION); for (pCurr = Storage; pCurr; pCurr = pCurr->next) { if (pCurr->term == NULL) continue; { if (!ReadConfigItem (&item, pCurr)) continue; switch (pCurr->term->id) { case SOUND_SOUND_ID: if( pCurr->sub ) { if( pCurr->sub->term && pCurr->sub->argv ) if( pCurr->sub->term->id >= EVENT_ID_START && pCurr->sub->term->id < EVENT_ID_END ) set_string( &(config->sounds[pCurr->sub->term->id-EVENT_ID_START]), mystrdup( pCurr->sub->argv[0] )); } break; case SOUND_PCMDEVICE_ID: //set_string( &(config->pcmdevice), item.data.string ); config->pcmdevice = item.data.string; break; case SOUND_PATH_ID: config->path = item.data.string; break; case SOUND_DEBUG_ID: config->debug = (int)item.data.integer; break; /* case SOUND_DELAY_ID: set_flags( config->set_flags, SOUND_SET_DELAY ); config->delay = (int)item.data.integer; break; */ /* case SOUND_RPLAY_HOST_ID: set_string_value( &(config->rplay_host), item.data.string, &(config->set_flags), SOUND_SET_RPLAY_HOST ); break; case SOUND_RPLAY_PRI_ID: set_flags( config->set_flags, SOUND_SET_RPLAY_PRIORITY ); config->rplay_priority = (int)item.data.integer; break; case SOUND_RPLAY_VOL_ID: set_flags( config->set_flags, SOUND_SET_RPLAY_VOLUME ); config->rplay_volume = (int)item.data.integer; break; */ default: item.ok_to_free = 1; } } } ReadConfigItem (&item, NULL); DestroyConfig (SoundConfigReader); DestroyFreeStorage (&Storage); return config; }
//================================================================================================= // Przygotuj parametry do konwersji //================================================================================================= bool ConvertToQmsh(std::string& filename) { ConversionData cs; cs.gopt = GO_ONE; cs.export_phy = export_phy; uint xpos = filename.find_last_of('.'); if(xpos != string::npos) { if(filename.substr(xpos) == ".cfg") { try { ParseConfig(cs, filename); } catch(Error& er) { string msg; er.GetMessage_(&msg); printf("File '%s' is not configuration file!\n%s\n", filename.c_str(), msg.c_str()); } } } if(cs.gopt == GO_ONE) { cs.group_file = group_file; cs.gopt = gopt; cs.input = filename; } if(output_file.empty()) { string::size_type pos = cs.input.find_last_of('.'); if(pos == string::npos) { if(cs.export_phy) cs.output = cs.input + ".phy"; else cs.output = cs.input + ".qmsh"; } else cs.output = cs.input.substr(0, pos); } else cs.output = output_file; if(cs.gopt == GO_CREATE && group_file.empty()) { string::size_type pos = cs.input.find_first_of('.'); if(pos == string::npos) cs.group_file = cs.input + ".cfg"; else cs.group_file = cs.input.substr(0, pos) + ".cfg"; } cs.force_output = force_output; try { Convert(cs); printf("Ok.\n"); return true; } catch(const Error &e) { string Msg; e.GetMessage_(&Msg, " "); printf("B³¹d: %s\n", Msg.c_str()); return false; } }
FeelConfig * ParseFeelOptions (const char *filename, char *myname) { ConfigData cd ; ConfigDef *ConfigReader; FeelConfig *config = CreateFeelConfig (); FreeStorageElem *Storage = NULL, *pCurr; ConfigItem item; cd.filename = filename ; ConfigReader = InitConfigReader (myname, &FeelSyntax, CDT_Filename, cd, BindingSpecialFunc); if (!ConfigReader) return config; item.memory = NULL; PrintConfigReader (ConfigReader); ParseConfig (ConfigReader, &Storage); /* getting rid of all the crap first */ StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION); for (pCurr = Storage; pCurr; pCurr = pCurr->next) { if (pCurr->term == NULL) continue; if (ReadFlagItem (NULL, &(config->feel->flags), pCurr, FeelFlagsXref)) continue; if (!ReadConfigItem (&item, pCurr)) continue; switch (pCurr->term->id) { case FEEL_ClickTime_ID : config->feel->ClickTime = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_ClickTime); break ; case FEEL_OpaqueMove_ID : config->feel->OpaqueMove = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_OpaqueMove); break ; case FEEL_OpaqueResize_ID : config->feel->OpaqueResize = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_OpaqueResize); break ; case FEEL_AutoRaise_ID : config->feel->AutoRaiseDelay = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_AutoRaise); break ; case FEEL_AutoReverse_ID : config->feel->AutoReverse = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_AutoReverse); break ; case FEEL_ShadeAnimationSteps_ID : config->feel->ShadeAnimationSteps = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_ShadeAnimationSteps); break ; case FEEL_XorValue_ID : config->feel->XorValue = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_XorValue); break ; case FEEL_Xzap_ID : config->feel->Xzap = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_Xzap); break ; case FEEL_Yzap_ID : config->feel->Yzap = item.data.integer; set_flags (config->feel->set_val_flags, FEEL_Yzap); break ; case FEEL_Cursor_ID : /* TT_INTEGER */ /* TODO: backport from as-devel : */ /*if ( item.index > 0 && item.index < MAX_CURSORS) config->feel->standard_cursors[item.index] = item.data.integer ; */ break ; case FEEL_CustomCursor_ID : /* TT_BUTTON */ /* TODO: backport from as-devel : */ /* if ( item.index > 0 && item.index < MAX_CURSORS) { if( config->feel->custom_cursors[item.index] ) destroy_ascursor( &(config->feel->custom_cursors[item.index])); config->feel->custom_cursors[item.index] = item.data.cursor ; } */ break ; case FEEL_ClickToRaise_ID : /* TT_BITLIST */ config->feel->RaiseButtons = item.data.integer ; set_flags (config->feel->set_val_flags, FEEL_ClickToRaise); set_flags (config->feel->set_flags, ClickToRaise); set_flags (config->feel->flags, ClickToRaise); break ; case FEEL_EdgeScroll_ID : /* TT_INTARRAY*/ item.ok_to_free = 1; if( item.data.int_array.size > 0 ) { config->feel->EdgeScrollX = item.data.int_array.array[0]; if( item.data.int_array.size > 1 ) config->feel->EdgeScrollY = item.data.int_array.array[1]; set_flags (config->feel->set_val_flags, FEEL_EdgeScroll ); } break ; case FEEL_EdgeResistance_ID : /* TT_INTARRAY*/ item.ok_to_free = 1; if( item.data.int_array.size > 0 ) { config->feel->EdgeResistanceScroll = item.data.int_array.array[0]; if( item.data.int_array.size > 1 ) config->feel->EdgeResistanceMove = item.data.int_array.array[1]; set_flags (config->feel->set_val_flags, FEEL_EdgeResistance ); } break ; case FEEL_Popup_ID : /* TODO: backport from as-devel : */ /* FreeStorage2MenuData( pCurr, &item, config->feel->Popups ); */ break ; case FEEL_Function_ID : FreeStorage2ComplexFunction( pCurr, &item, config->feel->ComplexFunctions ); break ; case FEEL_Mouse_ID : if( item.data.binding.sym ) if( isdigit( (int)item.data.binding.sym[0] ) && pCurr->sub ) { int button_num = item.data.binding.sym[0] - '0' ; if( button_num >= 0 && button_num <= MAX_MOUSE_BUTTONS && pCurr->sub->term->type == TT_FUNCTION ) { ConfigItem func_item ; func_item.memory = NULL ; if( ReadConfigItem( &func_item, pCurr->sub ) ) { MouseButton *tmp = safecalloc( 1, sizeof(MouseButton) ); tmp->Button = button_num ; tmp->Modifier = item.data.binding.mods ; tmp->Context = item.data.binding.context ; tmp->fdata = func_item.data.function ; func_item.data.function = NULL ; tmp->NextButton = config->feel->MouseButtonRoot ; config->feel->MouseButtonRoot = tmp ; } if( func_item.data.function ) { func_item.ok_to_free = 1; ReadConfigItem( &func_item, NULL ); } } } item.ok_to_free = 1; break ; case FEEL_Key_ID : ParseKeyBinding( &item, pCurr->sub, &(config->feel->FuncKeyRoot) ); break ; default: item.ok_to_free = 1; } } ReadConfigItem (&item, NULL); DestroyConfig (ConfigReader); DestroyFreeStorage (&Storage); return config; }
int main(int argc, char *argv[]){ char inputFile[256], outputFile[256], confFile[256]; int inputFlag = 0, outputFlag = 0, confFlag = 0; FILE* input=NULL; FILE* output=NULL; FILE* config=NULL; srand(time(NULL)); int confNums[5]; int r = 365; int choice; while (1) { static struct option long_options[] = { /* Use flags like so: {"verbose", no_argument, &verbose_flag, 'V'}*/ /* Argument styles: no_argument, required_argument, optional_argument */ {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"inputFile", required_argument, 0, 'i'}, {"conf", required_argument, 0, 'c'}, {"output", required_argument, 0, 'o'}, {"rSize", required_argument, 0, 'r'}, {"default", no_argument, 0, 'd'}, {0,0,0,0} }; int option_index = 0; /* Argument parameters: no_argument: " " required_argument: ":" optional_argument: "::" */ choice = getopt_long( argc, argv, "vhi:c:o:r:d", long_options, &option_index); if (choice == -1) break; switch( choice ) { case 'v': printf("beta version\n"); break; case 'h': printf("ussage <executable> –d <inputFile file> –c <configuration file> -o <output file> -I <init fun> -A <assign fun> -U <update fun> --complete\n"); break; case 'd': strcpy(inputFile, "./inputFiles/bio_small_input.dat"); strcpy(outputFile, "./inputFiles/conform.dat"); strcpy(confFile,"./inputFiles/cluster_5.conf" ); inputFlag = 1; outputFlag = 1; confFlag = 1; break; case 'i': strcpy(inputFile, optarg); inputFlag = 1; break; case 'c': strcpy(confFile, optarg); confFlag = 1; break; case 'o': strcpy(outputFile, optarg); outputFlag = 1; break; case 'r': r = atoi(optarg);; break; case '?': /* getopt_long will have already printed an error */ break; default: /* Not sure how to get here... */ return EXIT_FAILURE; } } /* Deal with non-option arguments here */ if ( optind < argc ) { while ( optind < argc ) { } } if ( !inputFlag ) { printf("Give me an input file\n"); scanf("%s", inputFile); } if ( !confFlag ) { printf("Give me an conf file\n"); scanf("%s", confFile); } if ( !outputFlag ) { printf("Give me an output file\n"); scanf("%s", outputFile); } printf("inputFile %s, output %s, confingure %s,r = %d \n",inputFile, outputFile, confFile, r ); if((input=fopen(inputFile,"r")) == NULL){ perror(inputFile); exit(-1); } if((output=fopen(outputFile,"w")) == NULL){ perror(outputFile); exit(-1); } if((config=fopen(confFile,"r")) == NULL){ perror(confFile); exit(-1); } //ReadDataMolecule(NULL, input); SpecifyDatasetMolConf("molecule"); ParseConfig(config,confNums); parseData(input, r); void (*init)() = KMedoidPlusPlusInit; double (*assigment)() = PamAssign; int (*update)() = ClaransUpdate; int kCluster = 19; //int j = 0; int j = 0; init(kCluster); FirstAssignment(); assigment(confNums[1],confNums[2]); j = 0; while(update(assigment,confNums)){ fprintf(output,"Update loop #%d\n",j); printf("Update loop #%d\n",j); j++; } PrintClusters(output); double silhouette=Silhouette(output); fprintf(output, "%d\n%f\n",kCluster,silhouette ); PrintConform(output); data.destroyInput(); DestroyData(); printf("Silhouette: %f\n",silhouette); fclose(input); fclose(output); fclose(config); return 0; }
// Main entry point // Main::Main(CkArgMsg *msg) { // Display title CkPrintf("Simulation Tool for Asynchrnous Cortical Streams (stacs)\n"); // Command line arguments std::string configfile; if (msg->argc < 2) { configfile = "config.yml"; // default } else { configfile = msg->argv[1]; } delete msg; // Parsing config if (ParseConfig(configfile)) { CkPrintf("Error loading config...\n"); CkExit(); } // Charm information real_t netpe = (real_t)npnet/CkNumPes(); if (netpe < 1) { netpe = 1; } // Display configuration information CkPrintf("Loaded config from %s\n" " Data Files (npdat): %" PRIidx "\n" " Network Parts (npnet): %" PRIidx "\n" " Processing Elements: %d\n" " Network Parts per PE: %.2g\n" " Total Simulation Time (tmax): %" PRItick "\n" " Simulation Time Step (tstep): %" PRItick "\n" " Checkpoint Interval (tcheck): %" PRItick "\n", configfile.c_str(), npdat, npnet, CkNumPes(), netpe, tmax, tstep, tcheck); // Read vertex distribution CkPrintf("Initializing simulation\n"); if (ReadDist()) { CkPrintf("Error loading distribution...\n"); CkExit(); } // Read model information if (ReadModel()) { CkPrintf("Error loading models...\n"); CkExit(); } // Setup Charm++ variables mainProxy = thisProxy; mCastGrpId = CProxy_CkMulticastMgr::ckNew(); // Initialize coordination cinit = 0; ninit = 0; #ifdef STACS_WITH_YARP // Initialize YARP yarp.init(); #endif // Setup chare arrays CkCallback *cb = new CkCallback(CkReductionTarget(Main, InitSim), mainProxy); // netdata ++ninit; mDist *mdist = BuildDist(); netdata = CProxy_NetData::ckNew(mdist, npdat); netdata.ckSetReductionClient(cb); // network ++ninit; mModel *mmodel = BuildModel(); network = CProxy_Network::ckNew(mmodel, npnet); network.ckSetReductionClient(cb); #ifdef STACS_WITH_YARP // streamrpc ++ninit; mVtxDist *mvtxdist = BuildVtxDist(); streamrpc = CProxy_StreamRPC::ckNew(mvtxdist); #endif }
/** The main entry point. */ int main(int argc, char *argv[]) { char *temp; int x; enum { ACTION_RUN, ACTION_RESTART, ACTION_EXIT, ACTION_RELOAD, ACTION_PARSE } action; StartDebug(); /* Get the name of the user's local configuration file. */ temp = getenv("HOME"); if(temp) { const size_t temp_len = strlen(temp); const size_t config_len = sizeof(CONFIG_FILE); configPath = Allocate(temp_len + config_len); memcpy(configPath, temp, temp_len); memcpy(&configPath[temp_len], CONFIG_FILE, config_len); } else { configPath = CopyString(CONFIG_FILE); } /* Parse command line options. */ action = ACTION_RUN; for(x = 1; x < argc; x++) { if(!strcmp(argv[x], "-v")) { DisplayAbout(); DoExit(0); } else if(!strcmp(argv[x], "-h")) { DisplayHelp(); DoExit(0); } else if(!strcmp(argv[x], "-p")) { action = ACTION_PARSE; } else if(!strcmp(argv[x], "-restart")) { action = ACTION_RESTART; } else if(!strcmp(argv[x], "-exit")) { action = ACTION_EXIT; } else if(!strcmp(argv[x], "-reload")) { action = ACTION_RELOAD; } else if(!strcmp(argv[x], "-display") && x + 1 < argc) { displayString = argv[++x]; } else if(!strcmp(argv[x], "-f") && x + 1 < argc) { Release(configPath); configPath = CopyString(argv[++x]); } else { printf("unrecognized option: %s\n", argv[x]); DisplayHelp(); DoExit(1); } } switch(action) { case ACTION_PARSE: Initialize(); ParseConfig(configPath); DoExit(0); case ACTION_RESTART: SendRestart(); DoExit(0); case ACTION_EXIT: SendExit(); DoExit(0); case ACTION_RELOAD: SendReload(); DoExit(0); default: break; } #if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) setlocale(LC_ALL, ""); #endif #ifdef HAVE_GETTEXT bindtextdomain("jwm", LOCALEDIR); textdomain("jwm"); #endif /* The main loop. */ StartupConnection(); do { isRestarting = shouldRestart; shouldExit = 0; shouldRestart = 0; shouldReload = 0; /* Prepare JWM components. */ Initialize(); /* Parse the configuration file. */ ParseConfig(configPath); /* Start up the JWM components. */ Startup(); /* The main event loop. */ EventLoop(); /* Shutdown JWM components. */ Shutdown(); /* Perform any extra cleanup. */ Destroy(); } while(shouldRestart); ShutdownConnection(); /* If we have a command to execute on shutdown, run it now. */ if(exitCommand) { execl(SHELL_NAME, SHELL_NAME, "-c", exitCommand, NULL); Warning(_("exec failed: (%s) %s"), SHELL_NAME, exitCommand); DoExit(1); } else { DoExit(0); } /* Control shoud never get here. */ return -1; }
WiredTigerEngineFactory::WiredTigerEngineFactory(const Properties& props) { ParseConfig(props, m_cfg); }