machine_config::machine_config(const machine_config_token *tokens) : m_driver_data_alloc(NULL), m_minimum_quantum(attotime_zero), m_perfect_cpu_quantum(NULL), m_watchdog_vblank_count(0), m_watchdog_time(attotime_zero), m_machine_start(NULL), m_machine_reset(NULL), m_nvram_handler(NULL), m_memcard_handler(NULL), m_video_attributes(0), m_gfxdecodeinfo(NULL), m_total_colors(0), m_default_layout(NULL), m_init_palette(NULL), m_video_start(NULL), m_video_reset(NULL), m_video_eof(NULL), m_video_update(NULL), m_sound_start(NULL), m_sound_reset(NULL), m_parse_level(0) { // parse tokens into the config detokenize(tokens); }
TEST_F(TreeOperatorsTest, PruneLengths3) { vector<string> tokens; vector<string> leaves; tokens.resize(5); string toks[] = {"h", "7", "A", "8", "B"}; copy (toks, toks+5, tokens.begin()); leaves.push_back("A"); pruneTree(tokens, leaves); ASSERT_EQ("B", detokenize(tokens)); }
// make sure branch lenghts are kept for nodes moved “up” in a tree as it is // pruned TEST_F(TreeOperatorsTest, PruneLengths2) { vector<string> tokens; vector<string> leaves; tokens.resize(13); string toks[] = {"h", "7", "A", "8", "h", "9", "h", "11", "B", "12", "C", "10", "D"}; copy (toks, toks+13, tokens.begin()); leaves.push_back("A"); leaves.push_back("D"); pruneTree(tokens, leaves); ASSERT_EQ("h\t11\tB\t12\tC", detokenize(tokens)); }
static void write_server(GQServerList* list, GqServer* server, gpointer user_data) { gpointer* wc_and_cfg = user_data; struct writeconfig* wc = wc_and_cfg[0]; struct gq_config * cfg = wc_and_cfg[1]; /* GString *pw = g_string_new(); */ config_write(wc, "<ldapserver>\n"); wc->indent++; config_write_string(wc, server->name, "name", NULL); config_write_string(wc, server->ldaphost, "ldaphost", NULL); config_write_int(wc, server->ldapport, "ldapport", NULL); config_write_string_ne(wc, server->basedn, "basedn", NULL); config_write_string_ne(wc, server->binddn, "binddn", NULL); if (cfg->config_version == 0) { config_write_string_ne(wc, server->bindpw, "bindpw", NULL); } else if(server->bindpw && *server->bindpw) { gq_keyring_save_server_password(server); } if(server->bindtype != DEFAULT_BINDTYPE) config_write_string_ne(wc, detokenize(token_bindtype, server->bindtype), "bindtype", NULL); config_write_string_ne(wc, server->searchattr, "search-attribute", NULL); if(server->maxentries != DEFAULT_MAXENTRIES) config_write_int(wc, server->maxentries, "maxentries", NULL); if(server->cacheconn != DEFAULT_CACHECONN) config_write_bool(wc, server->cacheconn, "cache-connection", NULL); if(server->enabletls != DEFAULT_ENABLETLS) config_write_bool(wc, server->enabletls, "enable-tls", NULL); if(server->local_cache_timeout != DEFAULT_LOCAL_CACHE_TIMEOUT) config_write_int(wc, server->local_cache_timeout, "local-cache-timeout", NULL); if(server->ask_pw != DEFAULT_ASK_PW) config_write_bool(wc, server->ask_pw, "ask-pw", NULL); if(server->hide_internal != DEFAULT_HIDE_INTERNAL) config_write_bool(wc, server->hide_internal, "hide-internal", NULL); if(server->show_ref != DEFAULT_SHOW_REF) config_write_bool(wc, server->show_ref, "show-ref", NULL); wc->indent--; config_write(wc, "</ldapserver>\n\n"); }
static gboolean save_config_internal(int write_context, struct gq_config *cfg, const char *rcpath) { GList *templatelist, *oclist, *filterlist; GqServer *server; struct gq_template *template; struct gq_filter *filter; struct writeconfig *wc; char *tmprcpath; struct stat sfile; int mode = S_IRUSR|S_IWUSR; GList *I; gboolean ok = FALSE; gpointer wc_and_cfg[2] = { NULL, cfg }; if (cfg->config_version > CURRENT_CONFIG_VERSION) { error_push(write_context, _("Configuration file version too high - saving the configuration is not possible")); return FALSE; } wc = new_writeconfig(); wc_and_cfg[0] = wc; /* write to temp file... */ tmprcpath = g_malloc(strlen(rcpath) + 10); strcpy(tmprcpath, rcpath); strcat(tmprcpath, ".new"); /* check mode of original file. Do not overwrite without write permission. */ if(stat(rcpath, &sfile) == 0) { mode = sfile.st_mode & (S_IRUSR|S_IWUSR); } wc->outfile = fopen(tmprcpath, "w"); if(!wc->outfile) { error_push(write_context, _("Unable to open %1$s for writing:\n%2$s\n"), rcpath, strerror(errno)); g_free(tmprcpath); return FALSE; } fchmod(fileno(wc->outfile), mode); config_write(wc, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"); config_write(wc, "<gq-config>\n\n"); /* global settings */ wc->indent++; if (cfg->config_version > 0) { config_write_int(wc, cfg->config_version, "config-version", NULL); config_write_int(wc, cfg->config_version, "asked-config-version", NULL); config_write_int(wc, cfg->config_version, "last-asked", NULL); } config_write_bool(wc, cfg->confirm_mod, "confirm-mod", NULL); config_write_string(wc, detokenize(token_searchargument, cfg->search_argument), "search-argument", NULL); config_write_bool(wc, cfg->showdn, "show-dn", NULL); config_write_bool(wc, cfg->showoc, "show-oc", NULL); config_write_bool(wc, cfg->show_rdn_only, "show-rdn-only", NULL); config_write_bool(wc, cfg->sort_search, "sort-search-mode", NULL); config_write_bool(wc, cfg->sort_browse, "sort-browse-mode", NULL); config_write_bool(wc, cfg->browse_use_user_friendly, "browse-use-user-friendly", NULL); config_write_bool(wc, cfg->restore_window_sizes, "restore-window-sizes", NULL); config_write_bool(wc, cfg->restore_window_positions, "restore-window-positions", NULL); config_write_bool(wc, cfg->restore_search_history, "restore-search-history", NULL); config_write_bool(wc, cfg->restore_tabs, "restore-tabs", NULL); config_write_bool(wc, cfg->never_leak_credentials, "never-leak-credentials", NULL); config_write_bool(wc, cfg->do_not_use_ldap_conf, "do-not-use-ldap-conf", NULL); config_write_string(wc, detokenize(token_ldifformat, cfg->ldifformat), "ldif-format", NULL); if(strlen(cfg->schemaserver)) config_write_string(wc, cfg->schemaserver, "schema-server", NULL); config_write(wc, "\n"); /* ldapservers */ gq_server_list_foreach(gq_server_list_get(), write_server, wc_and_cfg); /* templates */ templatelist = cfg->templates; while(templatelist) {
int main(int argc, char **argv) { int c; const char *optstring = "vhanof:?"; int linenumbers = 0; bool add_vfcodes = FALSE; char *vfc_filnam = NULL; while (1) { #ifdef __GLIBC__ int option_index = 0; static struct option long_options[] = { {"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'}, {"all", 0, 0, 'a'}, {"linenumbers", 0, 0, 'n'}, {"offsets", 0, 0, 'o'}, {"fcodes", 1, 0, 'f'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, optstring, long_options, &option_index); #else c = getopt(argc, argv, optstring); #endif if (c == -1) break; switch (c) { case 'v': verbose = TRUE; break; case 'a': decode_all = TRUE; break; case 'n': linenumbers |= 1; show_linenumbers = TRUE; break; case 'o': linenumbers |= 2; show_linenumbers = TRUE; show_offsets = TRUE; break; case 'f': add_vfcodes = TRUE; vfc_filnam = optarg; break; case 'h': case '?': print_copyright(TRUE); usage(argv[0]); return 0; default: print_copyright(TRUE); printf("%s: unknown option.\n", argv[0]); usage(argv[0]); return 1; } } if (verbose) print_copyright(FALSE); if (linenumbers > 2) printremark ("Line numbers will be disabled in favour of offsets.\n"); if (optind >= argc) { print_copyright(TRUE); printf("%s: filename missing.\n", argv[0]); usage(argv[0]); return 1; } init_dictionary(); if (add_vfcodes) { if (add_fcodes_from_list(vfc_filnam)) { freeze_dictionary(); } } while (optind < argc) { if (init_stream(argv[optind])) { printf("Could not open file \"%s\".\n", argv[optind]); optind++; continue; } detokenize(); close_stream(); optind++; reset_dictionary(); } printf("\n"); return 0; }
void machine_config::detokenize(const machine_config_token *tokens, const device_config *owner) { device_config *device = NULL; astring tempstring; // increase the parse level m_parse_level++; // loop over tokens until we hit the end UINT32 entrytype = MCONFIG_TOKEN_INVALID; while (entrytype != MCONFIG_TOKEN_END) { device_type devtype; const char *tag; UINT64 data64; UINT32 clock; // unpack the token from the first entry TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8); switch (entrytype) { // end case MCONFIG_TOKEN_END: break; // including case MCONFIG_TOKEN_INCLUDE: detokenize(TOKEN_GET_PTR(tokens, tokenptr), owner); break; // device management case MCONFIG_TOKEN_DEVICE_ADD: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); devtype = TOKEN_GET_PTR(tokens, devtype); tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens)); device = m_devicelist.append(tag, (*devtype)(*this, tag, owner, clock)); break; case MCONFIG_TOKEN_DEVICE_REPLACE: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32); devtype = TOKEN_GET_PTR(tokens, devtype); tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens)); device = m_devicelist.replace(tag, (*devtype)(*this, tag, owner, clock)); break; case MCONFIG_TOKEN_DEVICE_REMOVE: tag = TOKEN_GET_STRING(tokens); m_devicelist.remove(owner->subtag(tempstring, tag)); device = NULL; break; case MCONFIG_TOKEN_DEVICE_MODIFY: tag = TOKEN_GET_STRING(tokens); device = m_devicelist.find(owner->subtag(tempstring, tag)); if (device == NULL) fatalerror("Unable to find device: tag=%s\n", tempstring.cstr()); break; case MCONFIG_TOKEN_DEVICE_CLOCK: case MCONFIG_TOKEN_DEVICE_CONFIG: case MCONFIG_TOKEN_DEVICE_INLINE_DATA16: case MCONFIG_TOKEN_DEVICE_INLINE_DATA32: case MCONFIG_TOKEN_DEVICE_INLINE_DATA64: case MCONFIG_TOKEN_DIEXEC_DISABLE: case MCONFIG_TOKEN_DIEXEC_VBLANK_INT: case MCONFIG_TOKEN_DIEXEC_PERIODIC_INT: case MCONFIG_TOKEN_DIMEMORY_MAP: case MCONFIG_TOKEN_DISOUND_ROUTE: case MCONFIG_TOKEN_DISOUND_RESET: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_2: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_3: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_4: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_5: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_6: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_7: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_8: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_9: case MCONFIG_TOKEN_DEVICE_CONFIG_DATA32: case MCONFIG_TOKEN_DEVICE_CONFIG_DATA64: case MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32: case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE: assert(device != NULL); device->process_token(entrytype, tokens); break; // core parameters case MCONFIG_TOKEN_DRIVER_DATA: m_driver_data_alloc = TOKEN_GET_PTR(tokens, driver_data_alloc); break; case MCONFIG_TOKEN_QUANTUM_TIME: TOKEN_EXTRACT_UINT64(tokens, data64); m_minimum_quantum = UINT64_ATTOTIME_TO_ATTOTIME(data64); break; case MCONFIG_TOKEN_QUANTUM_PERFECT_CPU: m_perfect_cpu_quantum = TOKEN_GET_STRING(tokens); break; case MCONFIG_TOKEN_WATCHDOG_VBLANK: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_watchdog_vblank_count, 24); break; case MCONFIG_TOKEN_WATCHDOG_TIME: TOKEN_EXTRACT_UINT64(tokens, data64); m_watchdog_time = UINT64_ATTOTIME_TO_ATTOTIME(data64); break; // core functions case MCONFIG_TOKEN_MACHINE_START: m_machine_start = TOKEN_GET_PTR(tokens, machine_start); break; case MCONFIG_TOKEN_MACHINE_RESET: m_machine_reset = TOKEN_GET_PTR(tokens, machine_reset); break; case MCONFIG_TOKEN_NVRAM_HANDLER: m_nvram_handler = TOKEN_GET_PTR(tokens, nvram_handler); break; case MCONFIG_TOKEN_MEMCARD_HANDLER: m_memcard_handler = TOKEN_GET_PTR(tokens, memcard_handler); break; // core video parameters case MCONFIG_TOKEN_VIDEO_ATTRIBUTES: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_video_attributes, 24); break; case MCONFIG_TOKEN_GFXDECODE: m_gfxdecodeinfo = TOKEN_GET_PTR(tokens, gfxdecode); break; case MCONFIG_TOKEN_PALETTE_LENGTH: TOKEN_UNGET_UINT32(tokens); TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_total_colors, 24); break; case MCONFIG_TOKEN_DEFAULT_LAYOUT: m_default_layout = TOKEN_GET_STRING(tokens); break; // core video functions case MCONFIG_TOKEN_PALETTE_INIT: m_init_palette = TOKEN_GET_PTR(tokens, palette_init); break; case MCONFIG_TOKEN_VIDEO_START: m_video_start = TOKEN_GET_PTR(tokens, video_start); break; case MCONFIG_TOKEN_VIDEO_RESET: m_video_reset = TOKEN_GET_PTR(tokens, video_reset); break; case MCONFIG_TOKEN_VIDEO_EOF: m_video_eof = TOKEN_GET_PTR(tokens, video_eof); break; case MCONFIG_TOKEN_VIDEO_UPDATE: m_video_update = TOKEN_GET_PTR(tokens, video_update); break; // core sound functions case MCONFIG_TOKEN_SOUND_START: m_sound_start = TOKEN_GET_PTR(tokens, sound_start); break; case MCONFIG_TOKEN_SOUND_RESET: m_sound_reset = TOKEN_GET_PTR(tokens, sound_reset); break; default: fatalerror("Invalid token %d in machine config\n", entrytype); break; } } // if we started at parse level 0 (and are thus at level 1), do post-processing if (m_parse_level == 1) { // process any device-specific machine configurations for (const device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) if (!devconfig->m_config_complete) { tokens = devconfig->machine_config_tokens(); if (tokens != NULL) detokenize(tokens, devconfig); } // then notify all devices that their configuration is complete for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) if (!devconfig->m_config_complete) { devconfig->config_complete(); devconfig->m_config_complete = true; } } // bump down the parse level m_parse_level--; }