static int init_conf(void) { Gra2cairoConf = g_malloc(sizeof(*Gra2cairoConf)); if (Gra2cairoConf == NULL) return 1; Gra2cairoConf->fontmap = nhash_new(); if (Gra2cairoConf->fontmap == NULL) { g_free(Gra2cairoConf); Gra2cairoConf = NULL; return 1; } Gra2cairoConf->fontmap_list_root = NULL; Gra2cairoConf->font_num = 0; if (loadconfig()) { free_fonts(Gra2cairoConf); nhash_free(Gra2cairoConf->fontmap); g_free(Gra2cairoConf); Gra2cairoConf = NULL; return 1; } return 0; }
static void createkey (const char *keyname, const dki_t *list, const zconf_t *conf) { const char *dir = ""; dki_t *dkp; if ( keyname == NULL || *keyname == '\0' ) fatal ("Create key: no keyname!"); dbg_val2 ("createkey: keyname %s, pathflag = %d\n", keyname, pathflag); /* search for already existent key to get the directory name */ if ( pathflag && (dkp = (dki_t *)zkt_search (list, 0, keyname)) != NULL ) { char path[MAX_PATHSIZE+1]; zconf_t localconf; dir = dkp->dname; pathname (path, sizeof (path), dir, LOCALCONF_FILE, NULL); if ( fileexist (path) ) /* load local config file */ { dbg_val ("Load local config file \"%s\"\n", path); memcpy (&localconf, conf, sizeof (zconf_t)); conf = loadconfig (path, &localconf); } } if ( zskflag ) dkp = dki_new (dir, keyname, DKI_ZSK, conf->k_algo, conf->z_bits, conf->z_random, conf->z_life / DAYSEC); else dkp = dki_new (dir, keyname, DKI_KSK, conf->k_algo, conf->k_bits, conf->k_random, conf->k_life / DAYSEC); if ( dkp == NULL ) fatal ("Can't create key %s: %s!\n", keyname, dki_geterrstr ()); /* create a new key always in state published, which means "standby" for ksk */ dki_setstatus (dkp, DKI_PUB); }
main (int argc, char *argv[]) { char *optstr; int val; progname = *argv; config = loadconfig ("", (zconf_t *) NULL); /* load built in defaults */ while ( --argc >= 1 ) { optstr = *++argv; config = loadconfig_fromstr (optstr, config); } val = 1; setconfigpar (config, "-v", &val); val = 2; setconfigpar (config, "verboselog", &val); val = 1; setconfigpar (config, "recursive", &val); val = 1200; setconfigpar (config, "propagation", &val); printconfig ("stdout", config); }
static void daemon_reload () { reload_servers (); reloadactive (); reload_access_conf (); loadconfig (); reload = 0; }
int main(int argc, char *argv[]) { io_openlinkeddatafile(datafile); loadconfig(); initstuff(); mainloop(); saveconfig(); return 0; }
int main(int argc,char **argv){ signal(SIGPIPE,SIG_IGN); if(loadconfig() != 0){ return 0; } signal(SIGINT,sig_int); t_proactor = kn_new_proactor(); if(!init()) return 0; while(!stop) kn_proactor_run(t_proactor,50); return 0; }
static void reload_conf(void) { utype_t *tmp, *next; upslogx(LOG_INFO, "Reloading configuration"); /* sanity check */ if (!check_file(configfile)) { reload_flag = 0; return; } /* flip through ups list, clear retain value */ tmp = firstups; while (tmp) { tmp->retain = 0; tmp = tmp->next; } /* reset paranoia checker */ totalpv = 0; /* reread upsmon.conf */ loadconfig(); /* go through the utype_t struct again */ tmp = firstups; while (tmp) { next = tmp->next; /* !retain means it wasn't in the .conf this time around */ if (tmp->retain == 0) delete_ups(tmp); tmp = next; } /* see if the user just blew off a foot */ if (totalpv < minsupplies) { upslogx(LOG_CRIT, "Fatal error: total power value (%d) less " "than MINSUPPLIES (%d)", totalpv, minsupplies); fatalx(EXIT_FAILURE, "Impossible power configuation, unable to continue"); } /* finally clear the flag */ reload_flag = 0; }
// Loads config from file (key=value pairs) // Fields needed are: // clone_subfolder: the folder in which to clone the repositories. They will // be cloned to <subfolder>/<login>/<repository> // clone_login: the login to git clone with // (git clone <login>@git.epitech.eu) // tests_subfolder: the folder where all the tests are. Tests must have the // following name: <test folder>/<repository> // tests_filename: the file which will launch the tests. It will be piped so // the moulinette can get its output (stdout ONLY). It must be executable // (no interpreter will be used by default) // mail_sendaddr: the mail the moulinette will use. It does not need to be // a valid address (sendmail doesn't check) // mail_sendername: the name the mail will be sent with // ALL fields are MANDATORY // A check is performed so there is no character in the values (double quotes, // spaces ...) which may be a security risk when using system() or sqlite static int load_config(t_mouli *cl, const char *filename) { unsigned int i; cl->cfg = loadconfig(filename); if (!cl->cfg) return (1); // Assign value in the mouli structure for (i = 0 ; i < cl->cfg->nb_entries ; ++i) { if (!strcmp(cl->cfg->entries[i].key, "clone_subfolder")) cl->clone_subfolder = cl->cfg->entries[i].value; else if (!strcmp(cl->cfg->entries[i].key, "clone_login")) cl->clone_login = cl->cfg->entries[i].value; else if (!strcmp(cl->cfg->entries[i].key, "tests_subfolder")) cl->tests_subfolder = cl->cfg->entries[i].value; else if (!strcmp(cl->cfg->entries[i].key, "tests_filename")) cl->tests_filename = cl->cfg->entries[i].value; else if (!strcmp(cl->cfg->entries[i].key, "mail_sendaddr")) cl->mail_sendaddr = cl->cfg->entries[i].value; else if (!strcmp(cl->cfg->entries[i].key, "mail_sendername")) cl->mail_sendername = cl->cfg->entries[i].value; } // Check if all fields are present if (!cl->clone_subfolder || !cl->clone_login || !cl->tests_subfolder || !cl->tests_filename || !cl->mail_sendaddr || !cl->mail_sendername) { fprintf(stderr, "Missing fields in config file\n"); deleteconfig(cl->cfg); return (1); } // Ensure they are all valid if (!IS_VALUE_VALID(cl->clone_subfolder) || !IS_VALUE_VALID(cl->clone_login) || !IS_VALUE_VALID(cl->tests_subfolder) || !IS_VALUE_VALID(cl->tests_filename) || !IS_VALUE_VALID(cl->mail_sendaddr) || !IS_VALUE_VALID(cl->mail_sendername)) { fprintf(stderr, "Invalid value(s)\n"); deleteconfig(cl->cfg); return (1); } return (0); }
void readrc() { struct passwd *pw; struct stat st; char agetrc[1024]; char *tok; if ((pw = getpwuid(getuid())) == NULL) return; snprintf(agetrc, 1020, "%s/.agetrc", pw->pw_dir); if ((stat(agetrc, &st)) == -1) { if (errno == ENOENT) createrc(agetrc); else { fprintf(stderr, "cannot read agetrc file %s: %s. Might be corrupt!\n", agetrc, strerror(errno)); exit(1); } } else loadconfig(agetrc); if (strlen(http_proxyhost) > 0) { if ((tok = strtok(http_proxyhost, ":")) != NULL) { strncpy(http_proxyhost, tok, VALSIZE -1); tok = strtok(NULL, ":"); if(tok != NULL) { http_proxyport = atoi(tok); } else { http_proxyport = 80; } } } #ifdef DEBUG printf("ftpanon: %s\n", ftpanonymoususer); printf("ftpanonpa: %s\n", ftpanonymouspass); printf("ph: %s\n", http_proxyhost); printf("pu: %s\n", http_proxyuser); printf("ppass: %s\n", http_proxypass); printf("pport: %d\n", http_proxyport); printf("pt = %d\n", preferredthread); #endif }
void reloadconfig (int x) { unsigned long ip; unsigned short port; if (conf) { ip = config_getInterface (conf); port = config_getPort (conf); config_dereference (conf); } else { /* Must be invalid */ ip = 0; port = 0; } conf = (config_t *) malloc (sizeof (config_t)); if (!loadconfig (conf, config_filename)) { #ifdef _WIN32_ MessageBox (NULL, "Could not open configuration file.", "Antinat", 48); #else printf ("Could not open configuration file."); #endif free (conf); exit (EXIT_FAILURE); } log_log (NULL, LOG_EVT_SERVERRESTART, 0, conf); if ((config_getPort (conf) != port) || (config_getInterface (conf) != ip)) { if (srv != INVALID_SOCKET) closesocket (srv); srv = INVALID_SOCKET; if (!startServer ((unsigned short) config_getPort (conf), (unsigned int) config_getInterface (conf))) { #ifndef _WIN32_ printf ("Could not listen on interface/port\n"); #else MessageBox (NULL, "Could not listen on interface/port", "Antinat", 16); #endif exit (EXIT_FAILURE); } } #ifndef _WIN32_ signal (x, reloadconfig); #endif }
int main(int argc, char **argv) { int i, cur; tgetopt(argc, argv); if ( toptset('h') ) { printf(usage, argv[0]); exit(0); } if ( toptset('c') ) config_file = toptargs('c'); syslog_open("updategroups", LOG_PID, LOG_NEWS); if ( (master = memmap(sizeof(MASTER))) == NULL ) die("Can't allocate master memory"); if ( (groups = memmap(sizeof(ACTIVE) * MAX_GROUPS)) == NULL ) die("Can't allocate groups memory"); loadconfig(); load_servers(); cur = -1; for (i=master->numservers-2; i>=0; i-- ) if ( (master->lservers[i])->Level != cur ) { cur = (master->lservers[i])->Level; update_server( master->lservers[i] ); } write_active(); write_newsgroups(); memunmap(master, sizeof(MASTER)); memunmap(groups, sizeof(ACTIVE) * MAX_GROUPS); syslog_close(); exit(0); }
main() { ozgetauxsize(); ozclick(0); ozcls(); if(load==1) { loadconfig(); } if(mov==1) { if(watch==1) { movie(); watch=0; } } ozcls(); high=1; prevhigh=0; score=0; shots=25; hits=0; misses=0; acc=0; bullseyes=0; ozquiet(); ozsetfont(FONT_OZ_LARGE); ozputs(0,0,"OZ Clay Pigeons"); ozsetfont(FONT_OZ_NORMAL); ozputs(95,3,"Version 2.0"); ozputs(0,20,"(1) Play OZ Clay Pigeons"); ozputs(0,30,"(2) High Scores"); ozputs(0,40,"(3) Keys"); ozputs(0,50,"(4) Options"); ozputs(0,60,"(5) Quit OZ Clay Pigeons"); ozputs(130,20,"Made with Hi-Tech C;"); ozputs(130,30,"USE AT YOUR OWN RISK!"); ozputs(130,50,"Up/Dn arrows to select"); highlight(); main(); }
void readconfig(char *cfgfile) { loadconfig(cfgfile); if ((strlen(logfile)) <= 0) { fprintf(stderr, "logfile variable doesn't seems defined\n"); exit(-1); } if (strlen(mainlogfile) <= 0) { fprintf(stderr, "mainlogfile variable doesn't seems defined\n"); exit(-1); } if (strlen(adminuser) <= 0) { fprintf(stderr, "adminuser variable doesn't seems defined\n"); exit(-1); } if (strlen(adminpasswd) <= 0) { fprintf(stderr, "adminpasswd variable doesn't seems defined\n"); exit(-1); } if (port == 0) { fprintf(stderr, "listenport variable doesn't seems defined\n"); exit(-1); } if (sesexpiretime == 0) { fprintf(stderr, "sesexpiretime variable doesn't seems defined\n"); exit(-1); } #ifndef WITHOUT_SSL if (strlen(cert_file) <= 0) { fprintf(stderr, "cert_file variable doesn't seems defined\n"); exit(-1); } if (strlen(key_file) <= 0) { fprintf(stderr, "key_file variable doesn't seems defined\n"); exit(-1); } #endif }
/** * Function: main * * The calling convention for this function is: * * wl2ktelnet -c targetcall -t timeoutsecs -e emailaddress -p password HOSTNAME PORT * * The parameters are: * mycall : my call sign, which MUST be set in wl2k.conf * targetcall: callsign for the telnet server (WL2K) * timeoutsecs: timeout in seconds * emailaddress: email address where the retrieved message will be sent via sendmail * password of the telnet host (CMSTelnet) * hostname of the telnet host (server.winlink.org) * port to be used for the telnet host (8772) * */ int main(int argc, char *argv[]) { struct hostent *host; int s; struct sockaddr_in s_in; FILE *fp; char *line; static cfg_t cfg; loadconfig(argc, argv, &cfg); g_mime_init(0); setlinebuf(stdout); if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("socket()"); exit(EXIT_FAILURE); } memset(&s_in, '\0', sizeof(struct sockaddr_in)); #if HAVE_SOCKADDR_IN_SIN_LEN s_in.sin_len = sizeof(struct sockaddr_in); #endif s_in.sin_family = AF_INET; s_in.sin_addr.s_addr = inet_addr(cfg.hostname); if ((int) s_in.sin_addr.s_addr == -1) { host = gethostbyname(cfg.hostname); if (host) { memcpy(&s_in.sin_addr.s_addr, host->h_addr, (unsigned) host->h_length); } else { herror(cfg.hostname); exit(EXIT_FAILURE); } } s_in.sin_port = htons((unsigned short)cfg.hostport); printf("Connecting to %s %d ...\n", cfg.hostname, cfg.hostport); settimeout(cfg.timeoutsecs); if (connect(s, (struct sockaddr *) &s_in, sizeof(struct sockaddr_in)) != 0) { close(s); perror("connect()"); exit(EXIT_FAILURE); } resettimeout(); printf("Connected.\n"); if ((fp = fdopen(s, "r+b")) == NULL) { close(s); perror("fdopen()"); exit(EXIT_FAILURE); } while ((line = wl2kgetline(fp)) != NULL) { printf("%s", line); if (strncmp("Callsign", line, 8) == 0) { fprintf(fp, ".%s\r\n", cfg.mycall); printf(" %s\n", cfg.mycall); break; } putchar('\n'); } if (line == NULL) { fprintf(stderr, "Connection closed by foreign host.\n"); exit(EXIT_FAILURE); } while ((line = wl2kgetline(fp)) != NULL) { printf("%s\n", line); if (strncmp("Password", line, 8) == 0) { fprintf(fp, "%s\r\n", cfg.password); break; } } if (line == NULL) { fprintf(stderr, "Connection closed by foreign host.\n"); exit(EXIT_FAILURE); } wl2kexchange(cfg.mycall, cfg.targetcall, fp, fp, cfg.emailaddr); fclose(fp); g_mime_shutdown(); exit(EXIT_SUCCESS); return 1; }
int main (int argc, char *argv[]) { dki_t *data = NULL; int c; int opt_index; int action; const char *file; const char *defconfname = NULL; char *p; char str[254+1]; zconf_t *config; progname = *argv; if ( (p = strrchr (progname, '/')) ) progname = ++p; view = getnameappendix (progname, "zkt-ls"); defconfname = getdefconfname (view); config = loadconfig ("", (zconf_t *)NULL); /* load built in config */ if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); opterr = 0; opt_index = 0; action = 0; #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 ) #else while ( (c = getopt (argc, argv, short_options)) != -1 ) #endif { switch ( c ) { #if defined(COLOR_MODE) && COLOR_MODE case 'C': /* color mode on; optional with terminal name */ if ( optarg ) term = optarg; else term = getenv ("TERM"); break; #endif case 'M': managedkeyflag = 1; subdomain_before_parent = 0; zskflag = pathflag = 0; action = c; break; case 'T': trustedkeyflag = 1; subdomain_before_parent = 0; zskflag = pathflag = 0; /* fall through */ case 'H': case 'K': case 'Z': action = c; break; case 'a': /* age */ ageflag = !ageflag; break; case 'f': /* key lifetime */ lifetimeflag = !lifetimeflag; break; case 'V': /* view name */ view = optarg; defconfname = getdefconfname (view); if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); setglobalflags (config); break; case 'c': config = loadconfig (optarg, config); setglobalflags (config); checkconfig (config); break; case 'O': /* read option from commandline */ config = loadconfig_fromstr (optarg, config); setglobalflags (config); checkconfig (config); break; case 'd': /* ignore directory arg */ dirflag = 1; break; case 'h': /* print no headline */ headerflag = 0; break; case 'k': /* ksk only */ zskflag = 0; break; case 'L': /* ljust */ ljustflag = !ljustflag; break; case 'l': /* label list */ labellist = prepstrlist (optarg, LISTDELIM); if ( labellist == NULL ) fatal ("Out of memory\n"); break; case 'p': /* print path */ pathflag = 1; break; case 'r': /* switch recursive flag */ recflag = !recflag; break; case 's': /* switch subdomain sorting flag */ subdomain_before_parent = !subdomain_before_parent; break; case 't': /* time */ timeflag = !timeflag; break; case 'e': /* expire time */ exptimeflag = !exptimeflag; break; case 'z': /* zsk only */ kskflag = 0; break; case ':': snprintf (str, sizeof(str), "option \"-%c\" requires an argument.\n", optopt); usage (str, config); break; case '?': if ( isprint (optopt) ) snprintf (str, sizeof(str), "Unknown option \"-%c\".\n", optopt); else snprintf (str, sizeof (str), "Unknown option char \\x%x.\n", optopt); usage (str, config); break; default: abort(); } } if ( kskflag == 0 && zskflag == 0 ) kskflag = zskflag = 1; tc_init (stdout, term); c = optind; do { if ( c >= argc ) /* no args left */ file = config->zonedir; /* use default directory */ else file = argv[c++]; if ( is_directory (file) ) parsedirectory (file, &data, subdomain_before_parent); else parsefile (file, &data, subdomain_before_parent); } while ( c < argc ); /* for all arguments */ switch ( action ) { case 'H': usage ("", config); case 'K': zkt_list_dnskeys (data); break; case 'T': zkt_list_trustedkeys (data); break; case 'M': zkt_list_managedkeys (data); break; default: zkt_list_keys (data); } tc_end (stdout, term); return 0; }
void parseargs(int argc, char * argv[]) { int i; loadconfig(); /* Parse arguments: */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--fullscreen") == 0 || strcmp(argv[i], "-f") == 0) { /* Use full screen: */ use_fullscreen = true; } else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0) { assert(i+1 < argc); joystick_num = atoi(argv[++i]); } else if (strcmp(argv[i], "--joymap") == 0) { assert(i+1 < argc); if (sscanf(argv[++i], "%d:%d:%d:%d:%d", &joystick_keymap.x_axis, &joystick_keymap.y_axis, &joystick_keymap.a_button, &joystick_keymap.b_button, &joystick_keymap.start_button) != 5) { puts("Warning: Invalid or incomplete joymap, should be: 'XAXIS:YAXIS:A:B:START'"); } else { std::cout << "Using new joymap:\n" << " X-Axis: " << joystick_keymap.x_axis << "\n" << " Y-Axis: " << joystick_keymap.y_axis << "\n" << " A-Button: " << joystick_keymap.a_button << "\n" << " B-Button: " << joystick_keymap.b_button << "\n" << " Start-Button: " << joystick_keymap.start_button << std::endl; } } else if (strcmp(argv[i], "--leveleditor") == 0) { launch_leveleditor_mode = true; } else if (strcmp(argv[i], "--datadir") == 0 || strcmp(argv[i], "-d") == 0 ) { assert(i+1 < argc); datadir = argv[++i]; } else if (strcmp(argv[i], "--show-fps") == 0) { /* Use full screen: */ show_fps = true; } else if (strcmp(argv[i], "--opengl") == 0 || strcmp(argv[i], "-gl") == 0) { #ifndef NOOPENGL /* Use OpengGL: */ use_gl = true; #endif } else if (strcmp(argv[i], "--sdl") == 0) { use_gl = false; } else if (strcmp(argv[i], "--usage") == 0) { /* Show usage: */ usage(argv[0], 0); } else if (strcmp(argv[i], "--version") == 0) { /* Show version: */ printf("SuperTux " VERSION "\n"); exit(0); } else if (strcmp(argv[i], "--disable-sound") == 0) { /* Disable the compiled in sound feature */ printf("Sounds disabled \n"); use_sound = false; audio_device = false; } else if (strcmp(argv[i], "--disable-music") == 0) { /* Disable the compiled in sound feature */ printf("Music disabled \n"); use_music = false; } else if (strcmp(argv[i], "--debug-mode") == 0) { /* Enable the debug-mode */ debug_mode = true; } else if (strcmp(argv[i], "--help") == 0) { /* Show help: */ puts("Super Tux " VERSION "\n" " Please see the file \"README.txt\" for more details.\n"); printf("Usage: %s [OPTIONS] FILENAME\n\n", argv[0]); puts("Display Options:\n" " --fullscreen Run in fullscreen mode.\n" " --opengl If opengl support was compiled in, this will enable\n" " the OpenGL mode.\n" " --sdl Use non-opengl renderer\n" "\n" "Sound Options:\n" " --disable-sound If sound support was compiled in, this will\n" " disable sound for this session of the game.\n" " --disable-music Like above, but this will disable music.\n" "\n" "Misc Options:\n" " -j, --joystick NUM Use joystick NUM (default: 0)\n" " --joymap XAXIS:YAXIS:A:B:START\n" " --leveleditor Opens the leveleditor in a file. (Only works when a file is provided.)\n" " Define how joystick buttons and axis should be mapped\n" " -d, --datadir DIR Load Game data from DIR (default: automatic)\n" " --debug-mode Enables the debug-mode, which is useful for developers.\n" " --help Display a help message summarizing command-line\n" " options, license and game controls.\n" " --usage Display a brief message summarizing command-line options.\n" " --version Display the version of SuperTux you're running.\n\n" ); exit(0); } else if (argv[i][0] != '-') { level_startup_file = argv[i]; } else { /* Unknown - complain! */ usage(argv[0], 1); } } }
Swall::Swall(QWidget *parent) : QWidget(parent) { //sndt_key = new QString(""); //sndf_key = new QString(""); // think I don't need playplay due to g_playmode // m_playplay = true; // this does not seem to have the right or any effect. why? /* QMap<QString, QString>::const_iterator ii = cfgmap.constBegin(); while (ii != cfgmap.constEnd()) { qDebug() << ii.key() << ": " << ii.value(); ++ii; } */ QGridLayout *grid = new QGridLayout(this); grid->setSpacing(2); QPushButton *quit = new QPushButton("Quit", this); grid->addWidget(quit, 11,0); connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); QPushButton *savecfg = new QPushButton("Save Config", this); grid->addWidget(savecfg, 11,2); connect(savecfg, SIGNAL(clicked()), this, SLOT(saveconfig())); QPushButton *loadcfg = new QPushButton("Load Config", this); grid->addWidget(loadcfg, 11,3); connect(loadcfg, SIGNAL(clicked()), this, SLOT(loadconfig())); QPushButton *playmode = new QPushButton("Play Mode", this); playmode->setCheckable(1); playmode->setChecked(1); grid->addWidget(playmode, 11,5); connect(playmode, SIGNAL(clicked()), this, SLOT(processplaymode())); QPushButton *editmode = new QPushButton("Edit Mode", this); editmode->setCheckable(1); grid->addWidget(editmode, 11,6); connect(editmode, SIGNAL(clicked()), this, SLOT(processeditmode())); QButtonGroup* buttonGroup = new QButtonGroup(this) ; buttonGroup->addButton(playmode); buttonGroup->addButton(editmode); QPushButton *help = new QPushButton("Help", this); grid->addWidget(help, 11,7); connect(help, SIGNAL(clicked()), this, SLOT(help())); QPushButton *about = new QPushButton("About", this); grid->addWidget(about, 11,8); connect(about, SIGNAL(clicked()), this, SLOT(about())); QPushButton *notes = new QPushButton("Notes", this); grid->addWidget(notes, 11,9); connect(notes, SIGNAL(clicked()), this, SLOT(notes())); QPalette pal; pal.setColor( QPalette::Active, QPalette::Button, "Blue" ); pal.setColor( QPalette::Active, QPalette::ButtonText, "Yellow" ); pal.setColor( QPalette::Inactive, QPalette::Button, "Cyan" ); pal.setColor( QPalette::Inactive, QPalette::ButtonText, "Green" ); // QButtonGroup* gridGroup = new QButtonGroup(this) ; // gridGroup->setExclusive(0); for (int row=0; row<10; row++) { for (int col=0; col<10; col++) { SPushButton *btn = new SPushButton("", this); // qDebug() << "Making SPushButtons for the grid."; btn->setFixedSize(115, 80); btn->setCheckable(1); // btn->setAutoDefault(false); btn->setPalette( pal ); QString sndt_key; QString some_sndt; QString some_butid; // sndt_key = new QString(""); some_sndt.append(QString("Cut::R")); some_sndt.append(QString("%1").arg(row)); some_sndt.append(QString(":C")); some_sndt.append(QString("%1").arg(col)); sndt_key.append(QString("sndt")); sndt_key.append(QString("%1").arg(row)); sndt_key.append(QString("%1").arg(col)); some_butid.append(QString("%1").arg(row)); some_butid.append(QString("%1").arg(col)); some_sndt = cfgmap[sndt_key]; QString sndf_key; QString some_sndf; // sndf_key = new QString(""); some_sndf.append(QString("cut_r")); some_sndf.append(QString("%1").arg(row)); some_sndf.append(QString("_c")); some_sndf.append(QString("%1").arg(col)); some_sndf.append(QString(".mp3")); sndf_key.append(QString("sndf")); sndf_key.append(QString("%1").arg(row)); sndf_key.append(QString("%1").arg(col)); some_sndf = cfgmap[sndf_key]; btn->setSndf(some_sndf); btn->setSndfKey(sndf_key); btn->setSndt(some_sndt); btn->setSndtKey(sndt_key); btn->setButId(some_butid); btn->setProcId("00"); btn->setText(btn->getSndt()); btn->setPlayb(false); btn->setSndLoop(false); connect(btn, SIGNAL(clicked()), btn, SLOT(processButton())); connect(this, SIGNAL(sbutconfig(QString, QString, QString)), btn, SLOT(updateButConfig(QString, QString, QString))); grid->addWidget(btn, row, col); } } setLayout(grid); }
void real_main (int argc, char **argv) { #ifdef USE_SDL SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK #if !defined(NO_SOUND) && !defined(GP2X) | SDL_INIT_AUDIO #endif ); #endif getcwd(launchDir,250); /* PocketUAE prefs */ default_prefs_uae (&currprefs); default_prefs(); #ifdef GP2X gp2x_init(argc, argv); #endif // Set everthing to default and clear HD settings SetDefaultMenuSettings(1); loadconfig (1); if (! graphics_setup ()) { exit (1); } rtarea_init (); hardfile_install(); if (! setup_sound ()) { write_log ("Sound driver unavailable: Sound output disabled\n"); produce_sound = 0; } init_joystick (); int err = gui_init (); if (err == -1) { write_log ("Failed to initialize the GUI\n"); } else if (err == -2) { exit (0); } if (sound_available && produce_sound > 1 && ! init_audio ()) { write_log ("Sound driver unavailable: Sound output disabled\n"); produce_sound = 0; } /* Install resident module to get 8MB chipmem, if requested */ rtarea_setup (); keybuf_init (); /* Must come after init_joystick */ #ifdef USE_AUTOCONFIG expansion_init (); #endif memory_init (); filesys_install (); native2amiga_install (); custom_init (); /* Must come after memory_init */ DISK_init (); m68k_init(0); gui_update (); #ifdef GP2X switch_to_hw_sdl(1); #endif { start_program (); } leave_program (); }
/****************************************************************************** * Function: void main(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: Main program entry point. * * Note: None *****************************************************************************/ void main(void) { //do some startup tasks... InitializeSystem(); //small delay for things to cook up for (b=0;b<1026;b++) { Delay1KTCYx(1); } //start I2C system at 100 Khz speed initi2c(); //board default configuration registers are changed here //make changed to loafconfigfriendly for a more friendly version loadconfig(); // //setup your IO configuration // // NOTE: you should change this 1st before anything else // this allows you to change ports to input, output, or analog // this function is in user.c // loadconfigfriendly(); for (c=0;c<10;c++) { //small delay for things to cook up for (b=0;b<1036;b++) { Delay1KTCYx(10); } } //start the USART module at 57600 buad rate startUsart(200000); //small delay for things to cook up for (b=0;b<1026;b++) { Delay1KTCYx(10); } //test xbee module at given baudrate of 57600 if (testxbee()) { //57600 baud failed so lets test to see if its a new module //start the USART module at 9600 buad rate startUsart(9600); //small delay for things to cook up for (b=0;b<1060;b++) { Delay1KTCYx(1); } //testing xbee at 9600 baudrate if (testxbee()) { //LOOP FOR NO XBEE MODULE FOUND (FAILED AT BOTH BAUDRATES) //xbee module failed at 9600 baud so no module present at either baudrate //new modules come with a 9600 baud rate by default. // //this is the no module operating code in here, put what you want when no module present //can use as a regular controller or PLC. // // NO XBEE MODULE FOUND MAIN LOOP STARTS HERE // mInitializeUSBDriver(); for(c=0;c<60;c++) { for (b=0;b<1060;b++) { Delay1KTCYx(1); USBTasks(); ProcessIO(); } } while(1) { //small delay so dont roast the USB system too much Delay1KTCYx(10); //USB polling tasks optional for (b=0;b<1060;b++) { Delay1KTCYx(1); USBTasks(); ProcessIO(); } // // NO XBEE MODULE FOUND MAIN LOOP ENDS HERE // } //end no xbee found main loop //END LOOP } //found module at 9600 baud rate // //now we will change the baud rate to 57600 in the module to speed things up else { //small delay for things to cook up for (b=0;b<1060;b++) { Delay1KTCYx(20); } //change xbee module to 57600 baud rate changebaudrate(); //start the USART module at 57600 buad rate startUsart(200000); for (c=0;c<30;c++) { //small delay for things to cook up for (b=0;b<3000;b++) { Delay1KTCYx(1); } } //initialize xbee module to the paramters specified in the following function // // NOTE: you need to edit this function to tailor this node's network parameters and such // this function is found in user.c // initxbee(); } } //found xbee module at 57600 baud rate else { //initialize xbee module to the paramters specified in the following function // // NOTE: you need to edit this function to tailor this node's network parameters and such // this function is found in user.c // //small delay for things to cook up for (b=0;b<1026;b++) { Delay1KTCYx(10); } initxbee(); } //configure xbee sleep mode here but it is not written to non volatile memory //since may have problems re-entering command mode later on!! //sleep_config_xbee(); //put xbee to not pin sleep xbee_sleep=0; //put module to not sleep!! (edge triggeered wakeup) //shutoff USB module to save 8 mA current //...uncomment to turn module off // UCONbits.USBEN=0; // UCONbits.SUSPND=1; //uncomment to turn USB on mInitializeUSBDriver(); //end usb turn on for(c=0;c<40;c++) { for (b=0;b<1060;b++) { Delay1KTCYx(1); USBTasks(); ProcessIO(); } } // set processor primary idle mode (not sleep!!) // OSCCONbits.IDLEN=1; //start timer 1 to time periodic functions starttimer(); //start USART receive interrupt PIE1bits.RCIE=1; //MAIN LOOP FOR XBEE MODULE NORMAL // // START MAIN LOOP FOR XBEE MODULE FOUND AT 200 K BAUD AND INTIALIZED TO YOUR PARAMETERS // while(1) { //loop to service USB requests (polling) for (b=0;b<1060;b++) { Delay1KTCYx(1); //service USB tasks USBTasks(); ProcessIO(); } }//end while // // END MAIN LOOP FOR XBEE MODULE FOUND AT 57600 BAUD AND INITIALIZED TO YOUR PARAMETERS // //END LOOP }//end main
int main(int argc,char *argv[]) { int s=0,m,n; FILE *fp; FILE *xmlfp; unsigned char help=0; unsigned char option=0; unsigned char ilf=0; char *pathstr=NULL; char *scstr=NULL; int sctype=0; struct XMLDBbuffer *scbuf=NULL; struct XMLdata *xmldata=NULL; struct XMLDBdata *xmldbdata=NULL; struct XMLDBtree *tree=NULL; char *symbol[]={"\"","\\","<",">","&",0}; char *entity[]={""","'","<",">","&",0}; struct Entitydata *entptr; struct OptionText *ignore=NULL; struct OptionText *remove=NULL; char lbuf[255]; char zero[1]={0}; entptr=EntityMake(); EntityAddEntityStringArray(entptr,entity); EntityAddSymbolStringArray(entptr,symbol); OptionAdd(&opt,"-help",'x',&help); OptionAdd(&opt,"-option",'x',&option); OptionAdd(&opt,"ilf",'x',&ilf); OptionAdd(&opt,"i",'a',&ignore); OptionAdd(&opt,"r",'a',&remove); OptionAdd(&opt,"path",'t',&pathstr); OptionAdd(&opt,"script",'t',&scstr); OptionAdd(&opt,"sctype",'i',&sctype); arg=OptionProcess(1,argc,argv,&opt,NULL); if (help==1) { OptionPrintInfo(stdout,hlpstr); exit(0); } if (option==1) { OptionDump(stdout,&opt); exit(0); } if ((argc-arg)<3) { fprintf(stderr,"xmldoc pwd cfgfile xmldata\n"); exit(-1); } xmlfp=fopen(argv[arg+2],"r"); if (xmlfp==NULL) { fprintf(stderr,"file not found.\n"); exit(-1); } chdir(argv[arg]); fp=fopen(argv[arg+1],"r"); loadconfig(fp,&xmldoc); fclose(fp); if (argc>3) xmldoc.compare.data=argv[arg+3]; else xmldoc.compare.data=NULL; xmldoc.compare.check=cmp; xmldoc.map.iflg=-1; if (pathstr !=NULL) { free(xmldoc.tree.path); xmldoc.tree.path=pathstr; } if (scstr !=NULL) { xmldoc.sc.type=sctype; scbuf=XMLDBMakeBuffer(64); XMLDBAddBuffer(scbuf,scstr,strlen(scstr)); XMLDBFreeBuffer(xmldoc.sc.buf); if (sctype==1) { xmldoc.sc.buf=XMLDBCopyBuffer(scbuf); XMLDBAddBuffer(xmldoc.sc.buf,zero,1); } else xmldoc.sc.buf=EntityDecodeBuffer(entptr,scbuf); XMLDBFreeBuffer(scbuf); } xmldata=XMLMake(); xmldbdata=XMLDBMake(xmldata); tree=XMLDBMakeTree(); XMLDBBuildTree(xmldoc.tree.path,xmldoc.tree.delim,tree); XMLDBSetTree(xmldbdata,tree); /* Set the renderer to XMLrender */ XMLDBSetText(xmldbdata,render,&xmldoc); XMLSetStart(xmldata,XMLDBStart,xmldbdata); XMLSetEnd(xmldata,XMLDBEnd,xmldbdata); XMLSetComment(xmldata,redirect,xmldata); xmldoc.script=ScriptMake(); ScriptSetText(xmldoc.script,mapxml,&xmldoc); XMLdocSetText(xmldoc.doc,stream_output,stdout); if (remove !=NULL) { xmldoc.map.remove.num=remove->num; xmldoc.map.remove.txt=remove->txt; } if (ignore !=NULL) { xmldoc.map.ignore.num=ignore->num; xmldoc.map.ignore.txt=ignore->txt; } while(fgets(lbuf,255,xmlfp) !=NULL) { if (ilf) { m=0; for (n=0;(lbuf[n] !=0) && (n<256);n++) { if (lbuf[n]=='\n') continue; lbuf[m]=lbuf[n]; m++; } lbuf[m]=0; } s=XMLDecode(xmldata,lbuf,strlen(lbuf)); if (s !=0) break; } XMLFree(xmldata); XMLDBFree(xmldbdata); XMLDBFreeTree(tree); ScriptFree(xmldoc.script); fclose(xmlfp); fflush(stdout); return 0; }
/** * Function: main * * The calling convention for this function is: * * wl2kax25 -c targetcall -a ax25port -t timeoutsecs -e emailaddress * * The parameters are: * mycall : my call sign, which MUST be set in wl2k.conf * targetcall: callsign for the RMS * ax25port: name of the ax25 port to use (e.g., sm0) * timeoutsecs: timeout in seconds * emailaddress: email address where the retrieved message will be sent via sendmail * * The targetcall parameter does not support a path yet. */ int main(int argc, char *argv[]) { int s; FILE *fp; unsigned int addrlen = 0; union { struct full_sockaddr_ax25 ax25; struct sockaddr_rose rose; } sockaddr; char *dev; pid_t procID; int sv[2]; int ready; struct pollfd fds[2]; ssize_t len; unsigned char *pbuf; ssize_t byteswritten; static cfg_t cfg; loadconfig(argc, argv, &cfg); g_mime_init(0); setlinebuf(stdout); if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv)) { perror("socketpair"); exit(EXIT_FAILURE); } // Begin AX25 socket code if (ax25_config_load_ports() == 0) fprintf(stderr, "wl2kax25: no AX.25 port data configured\n"); if (cfg.ax25port != NULL) { if ((dev = ax25_config_get_dev(cfg.ax25port)) == NULL) { fprintf(stderr, "wl2kax25: invalid port name - %s\n", cfg.ax25port); return(EXIT_FAILURE); } } if ((s = socket(AF_AX25, SOCK_SEQPACKET, 0)) == -1) { perror("socket"); printf("%d\n", __LINE__); exit(EXIT_FAILURE); } ax25_aton(ax25_config_get_addr(cfg.ax25port), &sockaddr.ax25); ax25_aton(cfg.mycall, &sockaddr.ax25); if (sockaddr.ax25.fsa_ax25.sax25_ndigis == 0) { ax25_aton_entry(ax25_config_get_addr(cfg.ax25port), sockaddr.ax25.fsa_digipeater[0]. ax25_call); sockaddr.ax25.fsa_ax25.sax25_ndigis = 1; } sockaddr.ax25.fsa_ax25.sax25_family = AF_AX25; addrlen = sizeof(struct full_sockaddr_ax25); if (bind(s, (struct sockaddr *) &sockaddr, addrlen) == -1) { perror("bind"); close(s); exit(EXIT_FAILURE); } if (ax25_aton(cfg.targetcall, &sockaddr.ax25) < 0) { close(s); perror("ax25_aton()"); exit(EXIT_FAILURE); } sockaddr.rose.srose_family = AF_AX25; addrlen = sizeof(struct full_sockaddr_ax25); settimeout(cfg.timeoutsecs); if (connect(s, (struct sockaddr *) &sockaddr, addrlen) != 0) { close(s); perror("connect()"); exit(EXIT_FAILURE); } unsettimeout(); printf("Connected to AX.25 stack\n"); fflush(stdout); // End AX25 socket code // Fork a process if ((procID = fork())) { // Parent processing if (-1 == procID) { fprintf(stderr, "fork\n"); exit(EXIT_FAILURE); } close(sv[1]); fds[0].fd = s; fds[0].events = POLLIN; fds[1].fd = sv[0]; fds[1].events = POLLIN; // poll here and feed to the ax25 socket. // Data must be chunked to the appropriate size for (;;) { ready = poll(fds, sizeof(fds)/sizeof(struct pollfd), -1); if (-1 == ready) { if (EINTR == errno) break; close(s); perror("poll"); exit(EXIT_FAILURE); } // Inbound if (fds[0].revents & POLLIN) { len = read(fds[0].fd, axread, sizeof(axread)); if ( len > 0 ) { pbuf = axread; while(len > 0) { byteswritten = write(fds[1].fd, pbuf, MIN(paclen, (size_t)len)); if (byteswritten == 0 || (byteswritten < 0 && errno != EAGAIN)) { fprintf(stderr,"%s error on inbound write: %s)\n", getprogname(), strerror(errno)); break; } pbuf += byteswritten; len -= byteswritten; } } else if (len == 0) { close(s); printf("EOF on ax25 socket, exiting...\n"); exit(EXIT_FAILURE); } } // Outbound if (fds[1].revents & POLLIN) { len = read(fds[1].fd, axwrite, sizeof(axwrite)); if (len > 0 ) { pbuf = axwrite; while(len > 0) { byteswritten = write(fds[0].fd, pbuf, MIN(paclen, (size_t)len)); if (byteswritten == 0 || (byteswritten < 0 && errno != EAGAIN)) { fprintf(stderr,"%s error on outbound write: %s)\n", getprogname(), strerror(errno)); break; } pbuf += byteswritten; len -= byteswritten; } } else if (len == 0) { printf("EOF on child fd, terminating communications loop.\n"); break; } } } printf("Closing ax25 connection\n"); #if 1 { time_t start_time, current_time; bool bax25conn; start_time = time(NULL); /* get current time in seconds */ if ((bax25conn=isax25connected(s)) == TRUE) { printf("Waiting for AX25 peer ... "); while(isax25connected(s)){ current_time = time(NULL); if (difftime(current_time, start_time) > 5) { break; } } if (isax25connected(s)) { printf("timeout\n"); }else { printf("disconnected\n"); } } } #endif g_mime_shutdown(); close(sv[0]); close(s); exit(EXIT_SUCCESS); return 1; } else { // Child processing printf("Child process\n"); close(sv[0]); if ((fp = fdopen(sv[1], "r+b")) == NULL) { close(sv[1]); perror("fdopen()"); _exit(EXIT_FAILURE); } /* set buf size to paclen */ setvbuf(fp, NULL, _IOFBF, paclen); /* * The messages are exchanged in this call * * TODO: The sid sent by the client should contain an NXX, * where NXX represents N followed by two digits of SSID. * This allows the RMS to find the correct registered * user in case the SSID has been changed in the network. */ if(cfg.bVerbose) { printf("Child process calling wl2kexchange()\n"); } settimeout(cfg.timeoutsecs); wl2kexchange(cfg.mycall, cfg.targetcall, fp, fp, cfg.emailaddr); fclose(fp); printf("Child process exiting\n"); _exit(EXIT_SUCCESS); } }
/* This is the daemon's main work - listen for connections and spawn. */ static void run_daemon (void) { pid_t pid; fd_set serverfds; fd_set sslrds; int maxfd; loadconfig (); init_sockets (&serverfds, &sslrds, &maxfd); if (cfg.EnableSSL) ssl_init(); curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if ( !curl ) { syslog(LOG_ERR, "curlGetURL: cant initialize curl!"); return; } if (! test_only) { writepidfile (); if (getuid () == 0) { struct passwd *pwent; if ((pwent = getpwnam (cfg.RunAsUser)) == NULL) die ("Unknown user %s, check configuration", cfg.RunAsUser); if (setuid (pwent->pw_uid)) die ("Cant setuid %s", cfg.RunAsUser); } errno = 0; } daemon_chdir (); load_servers(); loadactive(); loadoverviewfmt(); load_access_conf(); load_statsfile(); // init_cache(); master->serverstart = time (NULL); master->nrforks = 0; #if defined(_SC_NPROCESSORS_ONLN) master->numcores = sysconf(_SC_NPROCESSORS_ONLN); info("Found %d CPU cores", master->numcores); #else info("No CPU core binding support"); #endif if ((master->semid = semlock_init (MASTER_SEMKEY)) == -1) die ("semlock_init: semget failed: %m"); if (test_only) { info ("Startup Test Successfull, Exiting.."); syslog_close (); exit (0); } info ("NNTP Server Starting.."); if (!opt_stay) { syslog_close (); pid = init_daemon (serverfds); syslog_open ("nntpswitchd", LOG_PID, LOG_NEWS); if (pid < 0) die ("Can't fork"); /* 2nd time, with the right pid, as user news */ writepidfile (); } // start the timer process for statistics if ( cfg.StatsFilePeriod > 0 ) timerpid = run_timer_loop(); info("Server running new pid %d uid %d euid %d timerpid %d" , (int)getpid(), (int)getuid(), (int)geteuid(), (int)timerpid); setproctitle("nntpswitchd: waiting for connections"); daemon_select_loop (serverfds, sslrds, maxfd); }
void comain(){ struct config *config = loadconfig(); printf("%s\n",config->flrpath); config_destroy(config); }
int main(int argc, char *argv[]) { char inkey=0, *prgdir, *curdir, *program_name; bool ext, validcfg, quit = false, bkgply = false, batchply = false; unsigned int opt, prgdrive, i; CWindow *focus; #ifdef DEBUG f_log = fopen(DEBUG_FILE,"wt"); #endif std::cout << ADPLAYVERS << ", Copyright (c) 2000 - 2006 Simon Peter <*****@*****.**>" << std::endl << std::endl; // check that no other instance is running { char *adplayenv = getenv("ADPLAY"); if(adplayenv && !strcmp(adplayenv,"S")) { std::cout << "AdPlay already running!" << std::endl; exit(EXIT_FAILURE); } else setenv("ADPLAY","S",1); // flag our instance } // Build program executable name program_name = strrchr(argv[0], '\\') ? strrchr(argv[0], '\\') + 1 : argv[0]; CAdPlug::debug_output("debug.log"); // Redirect AdPlug's debug to file // Build path to default configuration file (in program's directory) SPLITPATH(argv[0],configfile,configfile+2,NULL,NULL); strcat(configfile,CONFIGFILE); loadconfig(configfile,DEFCONFIG); // load default configuration // parse commandline for general options while((opt = getopt(argc,argv))) switch(opt) { case 1: // display help case 2: std::cout << "Usage: " << program_name << " [options]" << std::endl << std::endl; std::cout << "Options can be set with '-' or '/' respectively." << std::endl << std::endl; std::cout << " -?, -h Display commandline help" << std::endl << " -p port Set OPL2 port" << std::endl << " -o Force OPL2 port" << std::endl << " -f file Use alternate configuration file" << std::endl << " -c section Load another configuration section" << std::endl << " -b file Immediate background playback using " << "specified file" << std::endl << " -q files Immediate (batch mode) playback using " << "specified files" << std::endl; showcursor(); exit(EXIT_SUCCESS); case 3: // set OPL2 port opl.setport(atoi(argv[myoptind++])); break; case 4: // force OPL2 port oplforce = true; break; case 7: // background playback bkgply = true; break; case 8: // batch mode playback batchply = true; break; } // Bail out if OPL2 not detected and not force if(!opl.detect() && !oplforce) { std::cout << "No OPL2 detected!" << std::endl; showcursor(); exit(EXIT_FAILURE); } // Hand our database to AdPlug CAdPlug::set_database(&mydb); /*** Background playback mode ***/ if(bkgply) if(!(p = CAdPlug::factory(argv[myoptind],&opl))) { std::cout << "[" << argv[myoptind] << "]: unsupported file type!" << std::endl; exit(EXIT_FAILURE); } else { std::cout << "Background playback... (type EXIT to stop)" << std::endl; #ifdef HAVE_WCC_TIMER_H tmInit(poll_player,0xffff,DEFSTACK); #elif defined HAVE_GCC_TIMER_H timer_init(poll_player); #endif dopoll = true; #ifdef __WATCOMC__ _heapshrink(); #endif system(getenv("COMSPEC")); #ifdef HAVE_WCC_TIMER_H tmClose(); #elif defined HAVE_GCC_TIMER_H timer_deinit(); #endif stop(); exit(EXIT_SUCCESS); } /*** Batch playback mode ***/ if(batchply) { #ifdef HAVE_WCC_TIMER_H tmInit(poll_player,0xffff,DEFSTACK); #elif defined HAVE_GCC_TIMER_H timer_init(poll_player); #endif for(i = myoptind; i < argc; i++) if(!(p = CAdPlug::factory(argv[i],&opl))) { std::cout << "[" << argv[i] << "]: unsupported file type!" << std::endl; #ifdef HAVE_WCC_TIMER_H tmClose(); #elif defined HAVE_GCC_TIMER_H timer_deinit(); #endif exit(EXIT_FAILURE); } else { dopoll = firsttime = true; std::cout << "Playing [" << argv[i] << "] ..." << std::endl; while(firsttime) ; // busy waiting stop(); dopoll = false; } #ifdef HAVE_WCC_TIMER_H tmClose(); #elif defined HAVE_GCC_TIMER_H timer_deinit(); #endif exit(EXIT_SUCCESS); } /*** interactive (GUI) mode ***/ getvideoinfo(&dosvideo); // Save previous video state // register our windows with the window manager wnds.reg(titlebar); wnds.reg(filesel); wnds.reg(songwnd); wnds.reg(instwnd); wnds.reg(volbars); wnds.reg(mastervol); wnds.reg(infownd); // load default GUI layout validcfg = loadcolors(configfile,DEFCONFIG); // reparse commandline for GUI options myoptind = 1; // reset option parser while((opt = getopt(argc,argv))) switch(opt) { case 5: // set config file strcpy(configfile,argv[myoptind++]); if(loadcolors(configfile,DEFCONFIG)) validcfg = true; break; case 6: // load config section loadcolors(configfile,argv[myoptind++]); break; } // bail out if no configfile could be loaded if(!validcfg) { std::cout << "No valid default GUI layout could be loaded!" << std::endl; exit(EXIT_FAILURE); } // init GUI if((tmpfn = TEMPNAM(getenv("TEMP"),"_AP"))) #ifdef __WATCOMC__ mkdir(tmpfn); #else mkdir(tmpfn, S_IWUSR); #endif prgdir = getcwd(NULL, PATH_MAX); _dos_getdrive(&prgdrive); setadplugvideo(); #ifdef HAVE_WCC_TIMER_H tmInit(poll_player,0xffff,DEFSTACK); #elif defined HAVE_GCC_TIMER_H timer_init(poll_player); #endif songwnd.setcaption("Song Info"); volbars.setcaption("VBars"); titlebar.setcaption(ADPLAYVERS); filesel.setcaption("Directory"); mastervol.setcaption("Vol"); filesel.refresh(); mastervol.set(63); display_help(infownd); filesel.setfocus(); reset_windows(); // main loop do { if(p) { // auto-update windows // wait_retrace(); idle_ms(1000/70); refresh_songinfo(songwnd); refresh_volbars(volbars,opl); if(onsongend && !firsttime) { // song ended switch(onsongend) { case 1: // auto-rewind dopoll = false; while(inpoll) ; // critical section... p->rewind(subsong); last_ms = time_ms = 0.0f; dopoll = true; // ...End critical section break; case 2: // stop playback stop(); reset_windows(); break; } } } // Check for keypress and read in, if any if(kbhit()) { if(!(inkey = toupper(getch()))) { ext = true; inkey = toupper(getch()); } else ext = false; focus = CWindow::getfocus(); // cache focused window dbg_printf("main(): Key pressed: %d %s\n", inkey, ext ? "(Ext)" : "(Norm)"); } else inkey = 0; if(ext) // handle all extended keys switch(inkey) { case 15: // [Shift]+[TAB] - Back cycle windows window_cycle(true); break; case 59: // [F1] - display help display_help(infownd); infownd.setfocus(); wnds.update(); break; case 60: // [F2] - change screen layout curdir = getcwd(NULL, PATH_MAX); chdir(prgdir); select_colors(); chdir(curdir); free(curdir); clearscreen(backcol); filesel.refresh(); wnds.update(); break; case 72: // [Up Arrow] - scroll up if(focus == &filesel) { filesel.select_prev(); filesel.update(); } else if(focus == &infownd) { infownd.scroll_up(); infownd.update(); } else if(focus == &instwnd) { instwnd.scroll_up(); instwnd.update(); } break; case 80: // [Down Arrow] - scroll down if(focus == &filesel) { filesel.select_next(); filesel.update(); } else if(focus == &infownd) { infownd.scroll_down(); infownd.update(); } else if(focus == &instwnd) { instwnd.scroll_down(); instwnd.update(); } break; case 75: // [Left Arrow] - previous subsong if(p && subsong) { subsong--; dopoll = false; while(inpoll) ; // critical section... totaltime = p->songlength(subsong); p->rewind(subsong); last_ms = time_ms = 0.0f; dopoll = true; // ...End critical section } break; case 77: // [Right Arrow] - next subsong if(p && subsong < p->getsubsongs()-1) { subsong++; dopoll = false; while(inpoll) ; // critical section... totaltime = p->songlength(subsong); p->rewind(subsong); last_ms = time_ms = 0.0f; dopoll = true; // ...End critical section } break; case 73: // [Page Up] - scroll up half window if(focus == &filesel) { filesel.select_prev(filesel.getsizey() / 2); filesel.update(); } else if(focus == &infownd) { infownd.scroll_up(infownd.getsizey() / 2); infownd.update(); } else if(focus == &instwnd) { instwnd.scroll_up(instwnd.getsizey() / 2); instwnd.update(); } break; case 81: // [Page Down] - scroll down half window if(focus == &filesel) { filesel.select_next(filesel.getsizey() / 2); filesel.update(); } else if(focus == &infownd) { infownd.scroll_down(infownd.getsizey() / 2); infownd.update(); } else if(focus == &instwnd) { instwnd.scroll_down(instwnd.getsizey() / 2); instwnd.update(); } break; case 71: // [Home] - scroll to start if(focus == &filesel) { filesel.setselection(0); filesel.update(); } else if(focus == &infownd) { infownd.scroll_set(0); infownd.update(); } else if(focus == &instwnd) { instwnd.scroll_set(0); instwnd.update(); } break; case 79: // [End] - scroll to end if(focus == &filesel) { filesel.setselection(0xffff); filesel.update(); } else if(focus == &infownd) { infownd.scroll_set(0xffff); infownd.update(); } else if(focus == &instwnd) { instwnd.scroll_set(0xffff); instwnd.update(); } break; } else // handle all normal keys switch(inkey) { case 9: // [TAB] - Cycle through windows window_cycle(); break; case 13: // [Return] - Activate if(focus == &filesel) activate(); break; case 27: // [ESC] - Stop music / Exit to DOS if(p) { stop(); reset_windows(); } else quit = true; break; case ' ': // [Space] - fast forward fast_forward(FF_MSEC); break; case 'M': // refresh song info refresh_songdesc(infownd); break; case 'D': // shell to DOS dosshell(getenv("COMSPEC")); filesel.refresh(); wnds.update(); break; case '+': // [+] - Increase volume adjust_volume(-1); break; case '-': // [-] - Decrease volume adjust_volume(+1); break; } } while(!quit); // deinit #ifdef HAVE_WCC_TIMER_H tmClose(); #elif defined HAVE_GCC_TIMER_H timer_deinit(); #endif stop(); setvideoinfo(&dosvideo); { unsigned int dummy; _dos_setdrive(prgdrive, &dummy); } chdir(prgdir); free(prgdir); if(tmpfn) { rmdir(tmpfn); free(tmpfn); } #ifdef DEBUG dbg_printf("main(): clean shutdown.\n"); fclose(f_log); #endif return EXIT_SUCCESS; }
void init() { loadconfig(); fd = open(device, O_RDONLY); }
int32 startgame() { int32 end; int32 c, mc; int32 bx=192, by=88, h=300; int32 y; int32 upd=1; int32 mx, my; int32 cn=0; int32 ti, ot; t_ik_image *bg; char name[32]; loadconfig(); start_ik_timer(1, 31); while (get_ik_timer(1) < 2 && !must_quit) { ik_eventhandler(); } Play_Sound(WAV_MUS_TITLE, 15, 1, 100, 22050,-1000); while (get_ik_timer(1) < 4 && !must_quit) { ik_eventhandler(); } Play_Sound(WAV_MUS_TITLE, 14, 1, 80, 22050, 1000); if (settings.random_names & 1) strcpy(settings.captname, captnames[rand()%num_captnames]); if (settings.random_names & 2) strcpy(settings.shipname, shipnames[rand()%num_shipnames]); bg = ik_load_pcx("graphics/starback.pcx", NULL); end = 0; ti = get_ik_timer(2); while (!end && !must_quit) { ik_eventhandler(); c = ik_inkey(); mc = ik_mclick(); mx = ik_mouse_x - bx; my = ik_mouse_y - by; ot = ti; ti = get_ik_timer(2); if (ti != ot) { prep_screen(); ik_blit(); } if (c==13 || c==32) end = 2; if ((mc & 1) && mx > 0 && mx < 240) { if (my > h-24 && my < h-8) // buttons { if (mx > 16 && mx < 64) // cancel end = 1; else if (mx > 176 && mx < 224) // ok { end = 2; Play_SoundFX(WAV_DOT); } } else if (my > 32 && my < 40) // captain { if (mx < 216) { cn |= 1; prep_screen(); ik_drawbox(screen, bx+70, by+32, bx+215, by+39, STARMAP_INTERFACE_COLOR*16+3); ik_blit(); strcpy(name, settings.captname); ik_text_input(bx+70, by+32, 14, font_6x8, "", name, STARMAP_INTERFACE_COLOR*16+3, STARMAP_INTERFACE_COLOR); if (strlen(name)>0) strcpy(settings.captname, name); } else { settings.random_names ^= 1; Play_SoundFX(WAV_LOCK,0); } upd = 1;must_quit=0; } else if (my > 40 && my < 48) // ship { if (mx < 216) { cn |= 2; prep_screen(); ik_drawbox(screen, bx+70, by+40, bx+215, by+47, STARMAP_INTERFACE_COLOR*16+3); ik_blit(); strcpy(name, settings.shipname); ik_text_input(bx+70, by+40, 14, font_6x8, "", name, STARMAP_INTERFACE_COLOR*16+3, STARMAP_INTERFACE_COLOR); if (strlen(name)>0) strcpy(settings.shipname, name); } else { settings.random_names ^= 2; Play_SoundFX(WAV_LOCK,0); } upd = 1;must_quit=0; } else if (my > 64 && my < 96) // ship { settings.dif_ship = (mx - 16)/72; Play_SoundFX(WAV_SLIDER,0); upd = 1; } else if (my > 112 && my < 176) // nebula { settings.dif_nebula = (mx - 16)/72; Play_SoundFX(WAV_SLIDER,0); upd = 1; } else if (my > 192 && my < 224) // enemies { settings.dif_enemies = (mx - 16)/72; Play_SoundFX(WAV_SLIDER,0); upd = 1; } else if (my > 232 && my < 240) // easy/hard { c = (mx-40)/32; if (c < 0) c=0; if (c > 4) c=4; settings.dif_nebula = (c+1)/2; settings.dif_enemies = c/2; upd = 1; Play_SoundFX(WAV_SLIDER,0); } else if (my > 256 && my < 264) // enable tutorial { if (mx > 16 && mx < 24) { settings.random_names ^= 4; Play_SoundFX(WAV_LOCK,0); upd = 1; } } } if (upd) { upd = 0; prep_screen(); ik_copybox(bg, screen, 0, 0, 640, 480, 0,0); y = by+16; interface_drawborder(screen, bx, by, bx+240, by+h, 1, STARMAP_INTERFACE_COLOR, "Start new adventure"); ik_print(screen, font_6x8, bx+16, y+=8, 0, textstring[STR_STARTGAME_IDENTIFY]); ik_print(screen, font_6x8, bx+16, y+=8, 0, textstring[STR_STARTGAME_CAPTAIN]); ik_print(screen, font_6x8, bx+70, y, 3, settings.captname); if (!(cn&1)) ik_print(screen, font_4x8, bx+216-strlen(textstring[STR_STARTGAME_RENAME])*4, y, 3, textstring[STR_STARTGAME_RENAME]); ik_dsprite(screen, bx+216, y, spr_IFslider->spr[8+(settings.random_names&1)], 2+((3-3*(settings.random_names&1))<<8)); ik_print(screen, font_6x8, bx+16, y+=8, 0, textstring[STR_STARTGAME_STARSHIP]); ik_print(screen, font_6x8, bx+70, y, 3, settings.shipname); if (!(cn&2)) ik_print(screen, font_4x8, bx+216-strlen(textstring[STR_STARTGAME_RENAME])*4, y, 3, textstring[STR_STARTGAME_RENAME]); ik_dsprite(screen, bx+216, y, spr_IFslider->spr[8+(settings.random_names&2)/2], 2+((3-3*(settings.random_names&2)/2)<<8)); ik_print(screen, font_6x8, bx+16, y+=16, 0, textstring[STR_STARTGAME_LOADOUT], textstring[STR_STARTGAME_LOADOUT1+settings.dif_ship]); y += 8; for (c = 0; c < 3; c++) { ik_dsprite(screen, bx+16+c*72, y, spr_IFdifenemy->spr[c+3], 0); ik_dsprite(screen, bx+16+c*72, y, spr_IFborder->spr[20], 2+(3<<8)*(c==settings.dif_ship)); } ik_print(screen, font_6x8, bx+16, y+=40, 0, textstring[STR_STARTGAME_NEBULA]); y += 8; for (c = 0; c < 3; c++) { ik_dsprite(screen, bx+16+c*72, y, spr_IFdifnebula->spr[c], 0); ik_dsprite(screen, bx+16+c*72, y, spr_IFborder->spr[18], 2+(3<<8)*(c==settings.dif_nebula)); } ik_print(screen, font_6x8, bx+16, y+=72, 0, textstring[STR_STARTGAME_ENEMIES]); y += 8; for (c = 0; c < 3; c++) { ik_dsprite(screen, bx+16+c*72, y, spr_IFdifenemy->spr[c], 0); ik_dsprite(screen, bx+16+c*72, y, spr_IFborder->spr[20], 2+(3<<8)*(c==settings.dif_enemies)); } y+=40; ik_print(screen, font_6x8, bx+16, y, 0, textstring[STR_STARTGAME_EASY]); ik_print(screen, font_6x8, bx+224-6*strlen(textstring[STR_STARTGAME_HARD]), y, 0, textstring[STR_STARTGAME_HARD]); ik_print(screen, font_6x8, bx+16, y+12, 0, textstring[STR_STARTGAME_LOSCORE]); ik_print(screen, font_6x8, bx+224-6*strlen(textstring[STR_STARTGAME_HISCORE]), y+12, 0, textstring[STR_STARTGAME_HISCORE]); interface_drawslider(screen, bx+56, y, 0, 128, 4, settings.dif_enemies+settings.dif_nebula, STARMAP_INTERFACE_COLOR); y+=24; ik_dsprite(screen, bx+12, y-5, spr_IFbutton->spr[(settings.random_names&4)>0], 0); ik_print(screen, font_6x8, bx+32, y, 0, "TUTORIAL MODE"); interface_drawbutton(screen, bx+16, by+h-24, 48, STARMAP_INTERFACE_COLOR, textstring[STR_CANCEL]); interface_drawbutton(screen, bx+240-64, by+h-24, 48, STARMAP_INTERFACE_COLOR, textstring[STR_OK]); ik_blit(); update_palette(); } } interface_cleartuts(); if (must_quit) end = 1; if (settings.opt_mucrontext & 1) { if (end > 1) { bx = 192; by = 72; h = 328; by = 220 - h/2; prep_screen(); ik_copybox(bg, screen, 0, 0, 640, 480, 0,0); y = 3; interface_drawborder(screen, bx, by, bx+256, by+h, 1, STARMAP_INTERFACE_COLOR, textstring[STR_STARTGAME_TITLE1]); y += 1 + interface_textbox(screen, font_6x8, bx+84, by+y*8, 160, 88, 0, textstring[STR_STARTGAME_MUCRON1]); y += 1 + interface_textbox(screen, font_6x8, bx+16, by+y*8, 224, 88, 0, textstring[STR_STARTGAME_MUCRON2]); y += 1 + interface_textbox(screen, font_6x8, bx+16, by+y*8, 224, 88, 0, textstring[STR_STARTGAME_MUCRON3]); y += 1 + interface_textbox(screen, font_6x8, bx+16, by+y*8, 224, 88, 0, textstring[STR_STARTGAME_MUCRON4]); interface_drawbutton(screen, bx+256-64, by+h-24, 48, STARMAP_INTERFACE_COLOR, textstring[STR_OK]); ik_dsprite(screen, bx+16, by+24, spr_SMraces->spr[race_unknown], 0); ik_dsprite(screen, bx+16, by+24, spr_IFborder->spr[18], 2+(STARMAP_INTERFACE_COLOR<<8)); ik_blit(); update_palette(); end = waitclick(bx+256-64, by+h-24, bx+256-16, by+h-8); } if (end > 1) { bx = 192; by = 96; h = 168; by = 220 - h/2; prep_screen(); ik_copybox(bg, screen, 0, 0, 640, 480, 0,0); y = 3; interface_drawborder(screen, bx, by, bx+256, by+h, 1, STARMAP_INTERFACE_COLOR, textstring[STR_STARTGAME_TITLE2]); y += 1 + interface_textbox(screen, font_6x8, bx+84, by+y*8, 160, 88, 0, textstring[STR_STARTGAME_MUCRON5]); y += 1 + interface_textbox(screen, font_6x8, bx+16, by+y*8, 224, 88, 0, textstring[STR_STARTGAME_MUCRON6]); interface_drawbutton(screen, bx+256-64, by+h-24, 48, STARMAP_INTERFACE_COLOR, textstring[STR_OK]); ik_dsprite(screen, bx+16, by+24, spr_IFdifnebula->spr[1], 0); ik_dsprite(screen, bx+16, by+24, hulls[shiptypes[0].hull].sprite, 0); ik_dsprite(screen, bx+16, by+24, spr_IFborder->spr[18], 2+(STARMAP_INTERFACE_COLOR<<8)); ik_blit(); update_palette(); end = waitclick(bx+256-64, by+h-24, bx+256-16, by+h-8); } if (end > 1) { bx = 192; by = 120; h = 112; by = 220 - h/2; prep_screen(); ik_copybox(bg, screen, 0, 0, 640, 480, 0,0); y = 3; interface_drawborder(screen, bx, by, bx+256, by+h, 1, STARMAP_INTERFACE_COLOR, textstring[STR_STARTGAME_TITLE3]); y += 1 + interface_textbox(screen, font_6x8, bx+84, by+y*8, 160, 88, 0, textstring[STR_STARTGAME_MUCRON7]); interface_drawbutton(screen, bx+256-64, by+h-24, 48, STARMAP_INTERFACE_COLOR, textstring[STR_OK]); ik_dsprite(screen, bx+16, by+24, spr_SMraces->spr[RC_PLANET], 4); ik_dsprite(screen, bx+16, by+24, spr_IFborder->spr[18], 2+(STARMAP_INTERFACE_COLOR<<8)); ik_blit(); update_palette(); end = waitclick(bx+256-64, by+h-24, bx+256-16, by+h-8); } } del_image(bg); if (end > 1) { starmap_create(); player_init(); } saveconfig(); return end-1; }
int main (int argc, char *argv[]) { int c; int opt_index; int action; int major; int minor; const char *file; const char *defconfname = NULL; const char *confname = NULL; char *p; char str[254+1]; zconf_t *refconfig = NULL; zconf_t *config; progname = *argv; if ( (p = strrchr (progname, '/')) ) progname = ++p; view = getnameappendix (progname, "zkt-conf"); defconfname = getdefconfname (view); dbg_val0 ("Load built in config \"%s\"\n"); config = loadconfig ("", (zconf_t *)NULL); /* load built in config */ if ( fileexist (defconfname) ) /* load default config file */ { dbg_val ("Load site wide config file \"%s\"\n", defconfname); config = loadconfig (defconfname, config); } if ( config == NULL ) fatal ("Out of memory\n"); confname = defconfname; opterr = 0; opt_index = 0; action = 0; setconfigversion (100); #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 ) #else while ( (c = getopt (argc, argv, short_options)) != -1 ) #endif { switch ( c ) { case 'V': /* view name */ view = optarg; defconfname = getdefconfname (view); if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); confname = defconfname; break; case 'O': /* read option from commandline */ config = loadconfig_fromstr (optarg, config); break; case 'C': switch ( sscanf (optarg, "%d.%d", &major, &minor) ) { case 2: major = major * 100 + minor; case 1: break; default: usage ("illegal release number"); } setconfigversion (major); break; case 'c': if ( *optarg == '\0' ) usage ("empty config file name"); config = loadconfig (optarg, config); if ( *optarg == '-' || strcmp (optarg, "stdin") == 0 ) confname = "stdout"; else confname = optarg; break; case 'd': /* built-in default config */ config = loadconfig ("", config); /* load built-in config */ confname = defconfname; break; case 's': /* side wide config */ /* this is the default **/ break; case 'a': /* set all flag */ allflag = 1; break; case 'l': /* local config file */ refconfig = dupconfig (config); /* duplicate current config */ confname = LOCALCONF_FILE; if ( fileexist (LOCALCONF_FILE) ) /* try to load local config file */ { dbg_val ("Load local config file \"%s\"\n", LOCALCONF_FILE); config = loadconfig (LOCALCONF_FILE, config); } else if ( !writeflag ) usage ("error: no local config file found"); break; case 't': /* test config */ testflag = 1; break; case 'v': /* version */ fprintf (stderr, "%s version %s compiled for BIND version %d\n", progname, ZKT_VERSION, BIND_VERSION); fprintf (stderr, "ZKT %s\n", ZKT_COPYRIGHT); return 0; break; case 'w': /* write back conf file */ writeflag = 1; break; case 'h': /* print help */ usage (""); break; case ':': snprintf (str, sizeof(str), "option \"-%c\" requires an argument.", optopt); usage (str); break; case '?': if ( isprint (optopt) ) snprintf (str, sizeof(str), "Unknown option \"-%c\".", optopt); else snprintf (str, sizeof (str), "Unknown option char \\x%x.", optopt); usage (str); break; default: abort(); } } c = optind; if ( c >= argc ) /* no arguments given on commandline */ { if ( testflag ) { if ( checkconfig (config) ) fprintf (stderr, "All config file parameter seems to be ok\n"); } else { if ( !writeflag ) /* print to stdout */ confname = "stdout"; if ( refconfig ) /* have we seen a local config file ? */ if ( allflag ) printconfig (confname, config); else printconfigdiff (confname, refconfig, config); else printconfig (confname, config); } } else /* command line argument found: use it as name of zone file */ { long minttl; long maxttl; int keydbfound; char *dnskeydb; file = argv[c++]; dnskeydb = config->keyfile; minttl = 0x7FFFFFFF; maxttl = 0; keydbfound = parsezonefile (file, &minttl, &maxttl, dnskeydb); if ( keydbfound < 0 ) error ("can't parse zone file %s\n", file); if ( dnskeydb && !keydbfound ) { if ( writeflag ) { addkeydb (file, dnskeydb); printf ("\"$INCLUDE %s\" directive added to \"%s\"\n", dnskeydb, file); } else printf ("\"$INCLUDE %s\" should be added to \"%s\" (run with option -w)\n", dnskeydb, file); } if ( minttl < (10 * MINSEC) ) fprintf (stderr, "Min_TTL of %s (%ld seconds) is too low to use it in a signed zone (see RFC4641)\n", timeint2str (minttl), minttl); else fprintf (stderr, "Min_TTL:\t%s\t# (%ld seconds)\n", timeint2str (minttl), minttl); fprintf (stdout, "Max_TTL:\t%s\t# (%ld seconds)\n", timeint2str (maxttl), maxttl); if ( writeflag ) { refconfig = dupconfig (config); /* duplicate current config */ confname = LOCALCONF_FILE; if ( fileexist (LOCALCONF_FILE) ) /* try to load local config file */ { dbg_val ("Load local config file \"%s\"\n", LOCALCONF_FILE); config = loadconfig (LOCALCONF_FILE, config); } setconfigpar (config, "Max_TTL", &maxttl); printconfigdiff (confname, refconfig, config); } } return 0; }
int SegmenterManager::init(const char* path, u1 method) { if (method != SEG_METHOD_NGRAM) return -4; //unsupport segmethod. if (m_inited) return 0; //only can be init once. char buf[1024]; memset(buf, 0, sizeof(buf)); if (!path) memcpy(buf, ".", 1); else memcpy(buf, path, strlen(path)); int nLen = (int) strlen(path); //check is end. #ifdef WIN32 if(buf[nLen-1] != '\\') { buf[nLen] = '\\'; nLen++; } #else if (buf[nLen - 1] != '/') { buf[nLen] = '/'; nLen++; } #endif m_method = method; int nRet = 0; if (method == SEG_METHOD_NGRAM) { seg_freelist_.set_size(64); memcpy(&buf[nLen], g_ngram_unigram_dict_name, strlen(g_ngram_unigram_dict_name)); nRet = m_uni.load(buf); if (nRet != 0) { printf("Unigram dictionary load Error\n"); return nRet; } // // memcpy(&buf[nLen],g_token_type_dict_name,strlen(g_token_type_dict_name)); // buf[nLen + strlen(g_token_type_dict_name)] = 0; // LoadTokenTypeFile(buf); //no needs to care kwformat memcpy(&buf[nLen],g_kword_unigram_dict_name,strlen(g_kword_unigram_dict_name)); buf[nLen + strlen(g_kword_unigram_dict_name)] = 0; nRet = m_kw.load(buf); if (nRet != 0 && nRet != -1) { //m_kw not exist or format error. printf("Keyword dictionary load Error\n"); return nRet; } //try to load weight dict memcpy(&buf[nLen],g_wordweight_unigram_dict_name,strlen(g_wordweight_unigram_dict_name)); buf[nLen + strlen(g_wordweight_unigram_dict_name)] = 0; nRet = m_weight.load(buf); if (nRet != 0 && nRet != -1) { //m_kw not exist or format error. printf("Keyword dictionary load Error\n"); return nRet; } memcpy(&buf[nLen],g_synonyms_dict_name,strlen(g_synonyms_dict_name)); buf[nLen + strlen(g_synonyms_dict_name)] = 0; //load g_synonyms_dict_name, we do not care the load in right or not nRet = m_sym.load(buf); if (nRet != 0 && nRet != -1) { printf("Synonyms dictionary format Error\n"); } memcpy(&buf[nLen], g_thesaurus_dict_name, strlen(g_thesaurus_dict_name)); buf[nLen + strlen(g_thesaurus_dict_name)] = 0; //load g_synonyms_dict_name, we do not care the load in right or not nRet = m_thesaurus.load(buf); if (nRet != 0 && nRet != -1) { printf("Thesaurus dictionary format Error\n"); } //read config memcpy(&buf[nLen], g_config_name, strlen(g_config_name)); buf[nLen + strlen(g_config_name)] = 0; loadconfig(buf); nRet = 0; m_inited = 1; return nRet; } return -1; }
void initpc() { char *p; // allegro_init(); get_executable_name(pcempath,511); pclog("executable_name = %s\n", pcempath); p=get_filename(pcempath); *p=0; pclog("path = %s\n", pcempath); fdd_init(); keyboard_init(); mouse_init(); joystick_init(); midi_init(); loadconfig(NULL); pclog("Config loaded\n"); loadfont("mda.rom", 0, cga_fontdat, cga_fontdatm); loadfont("roms/pc1512/40078.ic127", 0, pc1512_fontdat, pc1512_fontdatm); loadfont("roms/pc200/40109.bin", 0, pc200_fontdat, pc200_fontdatm); codegen_init(); cpuspeed2=(AT)?2:1; // cpuspeed2=cpuspeed; atfullspeed=0; device_init(); initvideo(); mem_init(); loadbios(); mem_add_bios(); timer_reset(); sound_reset(); fdc_init(); // #ifdef USE_NETWORKING vlan_reset(); //NETWORK network_card_init(network_card_current); // #endif loaddisc(0,discfns[0]); loaddisc(1,discfns[1]); //loadfont(); loadnvr(); sound_init(); resetide(); #if __unix if (cdrom_drive == -1) cdrom_null_open(cdrom_drive); else #endif ioctl_open(cdrom_drive); pit_reset(); /* if (romset==ROM_AMI386 || romset==ROM_AMI486) */fullspeed(); ali1429_reset(); // CPUID=(is486 && (cpuspeed==7 || cpuspeed>=9)); // pclog("Init - CPUID %i %i\n",CPUID,cpuspeed); shadowbios=0; #if __unix if (cdrom_drive == -1) cdrom_null_reset(); else #endif ioctl_reset(); }
int main(int argc, char *argv[]) { char *cfgfn = NULL, *statfn = NULL; int i; checkdef_t *walk; #ifdef BIG_SECURITY_HOLE drop_root(); #else drop_root_and_removesuid(argv[0]); #endif for (i=1; (i<argc); i++) { if (strcmp(argv[i], "--clock") == 0) { struct timeval tv; struct timezone tz; struct tm *tm; char timestr[50]; gettimeofday(&tv, &tz); printf("epoch: %ld.%06ld\n", (long int)tv.tv_sec, (long int)tv.tv_usec); tm = localtime(&tv.tv_sec); strftime(timestr, sizeof(timestr), "local: %Y-%m-%d %H:%M:%S %Z", tm); printf("%s\n", timestr); tm = gmtime(&tv.tv_sec); strftime(timestr, sizeof(timestr), "UTC: %Y-%m-%d %H:%M:%S %Z", tm); printf("%s\n", timestr); return 0; } else if (i == 1) cfgfn = argv[i]; else if (i == 2) statfn = argv[i]; } if ((cfgfn == NULL) || (statfn == NULL)) return 1; if (loadconfig(cfgfn) != 0) return 1; loadlogstatus(statfn); for (walk = checklist; (walk); walk = walk->next) { char *data; checkdef_t *fwalk; switch (walk->checktype) { case C_LOG: data = logdata(walk->filename, &walk->check.logcheck); fprintf(stdout, "[msgs:%s]\n", walk->filename); fprintf(stdout, "%s\n", data); /* See if there's a special "file:" entry for this logfile */ for (fwalk = checklist; (fwalk && ((fwalk->checktype != C_FILE) || (strcmp(fwalk->filename, walk->filename) != 0))); fwalk = fwalk->next) ; if (fwalk == NULL) { /* No specific file: entry, so make sure the logfile metadata is available */ fprintf(stdout, "[logfile:%s]\n", walk->filename); printfiledata(stdout, walk->filename, 0, 0, 0); } break; case C_FILE: fprintf(stdout, "[file:%s]\n", walk->filename); printfiledata(stdout, walk->filename, walk->check.filecheck.domd5, walk->check.filecheck.dosha1, walk->check.filecheck.dormd160); break; case C_DIR: fprintf(stdout, "[dir:%s]\n", walk->filename); printdirdata(stdout, walk->filename); break; case C_COUNT: fprintf(stdout, "[linecount:%s]\n", walk->filename); printcountdata(stdout, walk); break; case C_NONE: break; } } savelogstatus(statfn); return 0; }