void capitalize(const char *ptr, const char *end, string &result) { int in_small_point_size = 0; for (;;) { const char *start = ptr; if (!get_token(&ptr, end)) break; const token_info *ti = lookup_token(start, ptr); const char *char_end = ptr; int is_lower = ti->is_lower(); if ((is_lower || ti->is_upper()) && get_token(&ptr, end)) { const token_info *ti2 = lookup_token(char_end, ptr); if (!ti2->is_accent()) ptr = char_end; } if (is_lower) { if (!in_small_point_size) { result += "\\s-2"; in_small_point_size = 1; } ti->upper_case(start, char_end, result); result.append(char_end, ptr - char_end); } else { if (in_small_point_size) { result += "\\s+2"; in_small_point_size = 0; } result.append(start, ptr - start); } } if (in_small_point_size) result += "\\s+2"; }
void sortify_words(const char *s, const char *end, const char *sep, string &result) { int non_empty = 0; int need_separator = 0; for (;;) { const char *token_start = s; if (!get_token(&s, end)) break; if ((s - token_start == 1 && (*token_start == ' ' || *token_start == '\n' || (sep && *token_start != '\0' && strchr(sep, *token_start) != 0))) || (s - token_start == 2 && token_start[0] == '\\' && token_start[1] == ' ')) { if (non_empty) need_separator = 1; } else { const token_info *ti = lookup_token(token_start, s); if (ti->sortify_non_empty(token_start, s)) { if (need_separator) { result += ' '; need_separator = 0; } ti->sortify(token_start, s, result); non_empty = 1; } } } }
static svn_error_t *ra_svn_handle_add_file(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *path, *token, *file_token, *copy_path; svn_revnum_t copy_rev; ra_svn_token_entry_t *entry, *file_entry; SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "ccc(?cr)", &path, &token, &file_token, ©_path, ©_rev)); SVN_ERR(lookup_token(ds, token, FALSE, &entry)); ds->file_refs++; path = svn_relpath_canonicalize(path, pool); /* Some operations pass COPY_PATH as a full URL (commits, etc.). Others (replay, e.g.) deliver an fspath. That's ... annoying. */ if (copy_path) { if (svn_path_is_url(copy_path)) copy_path = svn_uri_canonicalize(copy_path, pool); else copy_path = svn_fspath__canonicalize(copy_path, pool); } file_entry = store_token(ds, NULL, file_token, TRUE, ds->file_pool); SVN_CMD_ERR(ds->editor->add_file(path, entry->baton, copy_path, copy_rev, ds->file_pool, &file_entry->baton)); return SVN_NO_ERROR; }
//////////////////////////////////////////////////////////////////// // Function: PPInstance::set_failed // Access: Private // Description: Called when something has gone wrong that prevents // the plugin instance from running. Specifically, this // means it failed to load the core API. //////////////////////////////////////////////////////////////////// void PPInstance:: set_failed() { if (!_failed) { _failed = true; nout << "Plugin failed.\n"; // Look for the "onpluginfail" token. string expression = lookup_token("onpluginfail"); if (!expression.empty()) { // Now attempt to evaluate the expression. COleVariant varResult; CComPtr<IDispatch> pDispatch; CString evalExpression( expression.c_str() ); HRESULT hr = m_parentCtrl.EvalExpression( pDispatch, evalExpression , varResult ); if (FAILED(hr)) { nout << "Unable to eval " << expression << "\n"; } else { nout << "Eval " << expression << "\n"; } } } }
void lowercase(const char *start, const char *end, string &result) { for (;;) { const char *token_start = start; if (!get_token(&start, end)) break; const token_info *ti = lookup_token(token_start, start); ti->lower_case(token_start, start, result); } }
void sortify_word(const char *s, const char *end, string &result) { for (;;) { const char *token_start = s; if (!get_token(&s, end)) break; const token_info *ti = lookup_token(token_start, s); ti->sortify(token_start, s, result); } }
static svn_error_t *ra_svn_handle_change_file_prop(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *token, *name; svn_string_t *value; ra_svn_token_entry_t *entry; SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "cc(?s)", &token, &name, &value)); SVN_ERR(lookup_token(ds, token, TRUE, &entry)); SVN_CMD_ERR(ds->editor->change_file_prop(entry->baton, name, value, pool)); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_delete_entry(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *path, *token; svn_revnum_t rev; ra_svn_token_entry_t *entry; SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "c(?r)c", &path, &rev, &token)); SVN_ERR(lookup_token(ds, token, FALSE, &entry)); path = svn_relpath_canonicalize(path, pool); SVN_CMD_ERR(ds->editor->delete_entry(path, rev, entry->baton, pool)); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_absent_file(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *path; const char *token; ra_svn_token_entry_t *entry; /* Parse parameters and look up the parent directory token. */ SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "cc", &path, &token)); SVN_ERR(lookup_token(ds, token, FALSE, &entry)); /* Call the editor. */ SVN_CMD_ERR(ds->editor->absent_file(path, entry->baton, pool)); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_close_dir(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *token; ra_svn_token_entry_t *entry; /* Parse and look up the directory token. */ SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "c", &token)); SVN_ERR(lookup_token(ds, token, FALSE, &entry)); /* Close the directory and destroy the baton. */ SVN_CMD_ERR(ds->editor->close_directory(entry->baton, pool)); svn_hash_sets(ds->tokens, token, NULL); svn_pool_destroy(entry->pool); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_textdelta_chunk(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *token; ra_svn_token_entry_t *entry; svn_string_t *str; /* Parse arguments and look up the token. */ SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "cs", &token, &str)); SVN_ERR(lookup_token(ds, token, TRUE, &entry)); if (!entry->dstream) return svn_error_create(SVN_ERR_RA_SVN_MALFORMED_DATA, NULL, _("Apply-textdelta not active")); SVN_CMD_ERR(svn_stream_write(entry->dstream, str->data, &str->len)); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_open_file(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *path, *token, *file_token; svn_revnum_t rev; ra_svn_token_entry_t *entry, *file_entry; SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "ccc(?r)", &path, &token, &file_token, &rev)); SVN_ERR(lookup_token(ds, token, FALSE, &entry)); ds->file_refs++; path = svn_relpath_canonicalize(path, pool); file_entry = store_token(ds, NULL, file_token, TRUE, ds->file_pool); SVN_CMD_ERR(ds->editor->open_file(path, entry->baton, rev, ds->file_pool, &file_entry->baton)); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_close_file(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *token; ra_svn_token_entry_t *entry; const char *text_checksum; /* Parse arguments and look up the file token. */ SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "c(?c)", &token, &text_checksum)); SVN_ERR(lookup_token(ds, token, TRUE, &entry)); /* Close the file and destroy the baton. */ SVN_CMD_ERR(ds->editor->close_file(entry->baton, text_checksum, pool)); svn_hash_sets(ds->tokens, token, NULL); if (--ds->file_refs == 0) svn_pool_clear(ds->file_pool); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_open_dir(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *path, *token, *child_token; svn_revnum_t rev; ra_svn_token_entry_t *entry; apr_pool_t *subpool; void *child_baton; SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "ccc(?r)", &path, &token, &child_token, &rev)); SVN_ERR(lookup_token(ds, token, FALSE, &entry)); subpool = svn_pool_create(entry->pool); path = svn_relpath_canonicalize(path, pool); SVN_CMD_ERR(ds->editor->open_directory(path, entry->baton, rev, subpool, &child_baton)); store_token(ds, child_baton, child_token, FALSE, subpool); return SVN_NO_ERROR; }
static svn_error_t *ra_svn_handle_apply_textdelta(svn_ra_svn_conn_t *conn, apr_pool_t *pool, const apr_array_header_t *params, ra_svn_driver_state_t *ds) { const char *token; ra_svn_token_entry_t *entry; svn_txdelta_window_handler_t wh; void *wh_baton; char *base_checksum; /* Parse arguments and look up the token. */ SVN_ERR(svn_ra_svn__parse_tuple(params, pool, "c(?c)", &token, &base_checksum)); SVN_ERR(lookup_token(ds, token, TRUE, &entry)); if (entry->dstream) return svn_error_create(SVN_ERR_RA_SVN_MALFORMED_DATA, NULL, _("Apply-textdelta already active")); entry->pool = svn_pool_create(ds->file_pool); SVN_CMD_ERR(ds->editor->apply_textdelta(entry->baton, base_checksum, entry->pool, &wh, &wh_baton)); entry->dstream = svn_txdelta_parse_svndiff(wh, wh_baton, TRUE, entry->pool); return SVN_NO_ERROR; }
printf("Invalid token: [0x%03x]\n", fcode); sprintf(temp_buf, "Backing up over first byte, which is "); buf_pos = strlen(temp_buf); if (top_byte < 10) { sprintf(&temp_buf[buf_pos], " %02x", top_byte); } else { sprintf(&temp_buf[buf_pos], "0x%02x ( =dec %d)", top_byte, top_byte); } printremark(temp_buf); set_streampos(token_streampos + 1); return; } tname = lookup_token(fcode); printf("%s ", tname); /* The fcode number is interesting * if either * a) the token has no name * or * b) detok is in verbose mode. */ if (strcmp(tname, unnamed) == 0) { printf("[0x%03x] ", fcode); } else { if (verbose) { /* If the token is named, * show its fcode number in * the syntax of a FORTH Comment
static void load_options(struct Configuration *cfg, const struct ConfParse *parse, const struct CF_Child *parent) { struct ConfigurationOptions *options = &cfg->options; size_t i; for (i=0; i<parent->child_count; i++) { struct CF_Child child = confparse_node_getchild(parse, parent, i); struct CF_Token name; struct CF_Token value; name = confparse_node_gettoken(parse, &child, 0); value = confparse_node_gettoken(parse, &child, 1); switch (lookup_token(&name)) { case S_DIRECTORY: if (options->directory) free(options->directory); if (filename_is_absolute(value.name)) { options->directory = filename_combine(value.name, ""); } else { char dir[2048]; if (getcwd(dir, sizeof(dir)) == NULL) { perror("getcwd"); exit(1); } options->directory = filename_combine(dir, value.name); } break; case S_PID_FILE: if (options->pid_file) free(options->pid_file); if (filename_is_absolute(value.name)) { options->pid_file = filename_combine(value.name, ""); if (*options->pid_file && options->pid_file[strlen(options->pid_file)-1] == '/') options->pid_file[strlen(options->pid_file)-1] = '\0'; } else if (options->directory == NULL || strcmp(options->directory, ".") == 0) { char dir[2048]; if (getcwd(dir, sizeof(dir)) == NULL) { perror("getcwd"); exit(1); } options->pid_file = filename_combine(dir, value.name); } else options->pid_file = filename_combine(options->directory, value.name); break; case S_PORT: if (!is_number(&value)) CONF_VALUE_BAD(parse, &value); else { unsigned n = to_number(&value); if (n > 65535) CONF_VALUE_BAD(parse, &value); else cfg->data_plane.port = n; } break; case S_LISTEN_ON: case S_LISTEN_ON_V6: break; case S_TRANSFER_SOURCE: case S_TRANSFER_SOURCE_V6: case S_ALT_TRANSFER_SOURCE: case S_ALT_TRANSFER_SOURCE_V6: break; case S_INTERFACE_INTERVAL: if (!is_number(&value)) CONF_VALUE_BAD(parse, &value); else { unsigned n = to_number(&value); if (n > 40320) CONF_VALUE_BAD(parse, &value); else cfg->data_plane.interface_interval = n; } break; case S_VERSION: switch (lookup_token(&value)) { case S_NONE: if (options->version) free(options->version); options->version = NULL; options->version_length = 0; break; default: if (options->version) free(options->version); options->version = malloc(value.name_length + 1); memcpy(options->version, value.name, value.name_length + 1); options->version_length = value.name_length; break; } break; case S_HOSTNAME: switch (lookup_token(&value)) { case S_NONE: if (options->hostname) free(options->hostname); options->hostname = NULL; break; case S_HOSTNAME: if (options->hostname) free(options->hostname); options->hostname = malloc(130); if (gethostname(options->hostname, 130) != 0) { perror("gethostname()"); free(options->hostname); options->hostname = 0; } break; default: if (options->hostname) free(options->hostname); options->hostname = malloc(value.name_length + 1); memcpy(options->hostname, value.name, value.name_length + 1); break; } break; case S_SERVER_ID: switch (lookup_token(&value)) { case S_NONE: if (options->server_id) free(options->server_id); options->server_id = NULL; options->server_id_length = 0; break; case S_HOSTNAME: if (options->server_id) free(options->server_id); options->server_id = malloc(130); if (gethostname(options->server_id, 130) != 0) { perror("gethostname()"); free(options->server_id); options->server_id = 0; options->server_id_length = 0; } else options->server_id_length = strlen(options->server_id); break; default: if (options->server_id) free(options->server_id); options->server_id = malloc(value.name_length + 1); memcpy(options->server_id, value.name, value.name_length + 1); options->server_id_length = value.name_length; break; } break; case S_ALLOW_NEW_ZONES: switch (lookup_token(&value)) { case S_YES: break; case S_NO: CONF_FEATURE_UNSUPPORTED(parse, &value); break; default: CONF_VALUE_BAD(parse, &value); break; } break; case S_RECURSION: switch (lookup_token(&value)) { case S_YES: CONF_FEATURE_UNSUPPORTED(parse, &value); break; case S_NO: //CONF_RECURSION_UNSUPPORTED(parse, &value); break; default: CONF_VALUE_BAD(parse, &value); break; } break; case S_AUTH_NXDOMAIN: switch (lookup_token(&value)) { case S_YES: CONF_FEATURE_UNSUPPORTED(parse, &value); break; case S_NO: break; default: CONF_VALUE_BAD(parse, &value); break; } break; case S_FORWARDERS: CONF_RECURSION_UNSUPPORTED(parse, &name); break; case S_DNSSEC_VALIDATION: CONF_FEATURE_UNSUPPORTED(parse, &name); break; default: CONF_OPTION_UNKNOWN(parse, &name); break; } } }
/* * The scanner * */ int mcy_lex(void) { static const WCHAR ustr_dot1[] = { '.', '\n', 0 }; static const WCHAR ustr_dot2[] = { '.', '\r', '\n', 0 }; static int isinit = 0; int ch; if(!isinit) { isinit++; set_codepage(WMC_DEFAULT_CODEPAGE); add_token(tok_keyword, ustr_codepages, tCODEPAGE, 0, NULL, 0); add_token(tok_keyword, ustr_facility, tFACILITY, 0, NULL, 1); add_token(tok_keyword, ustr_facilitynames, tFACNAMES, 0, NULL, 1); add_token(tok_keyword, ustr_language, tLANGUAGE, 0, NULL, 1); add_token(tok_keyword, ustr_languagenames, tLANNAMES, 0, NULL, 1); add_token(tok_keyword, ustr_messageid, tMSGID, 0, NULL, 1); add_token(tok_keyword, ustr_messageidtypedef, tTYPEDEF, 0, NULL, 1); add_token(tok_keyword, ustr_outputbase, tBASE, 0, NULL, 1); add_token(tok_keyword, ustr_severity, tSEVERITY, 0, NULL, 1); add_token(tok_keyword, ustr_severitynames, tSEVNAMES, 0, NULL, 1); add_token(tok_keyword, ustr_symbolicname, tSYMNAME, 0, NULL, 1); add_token(tok_severity, ustr_error, 0x03, 0, NULL, 0); add_token(tok_severity, ustr_warning, 0x02, 0, NULL, 0); add_token(tok_severity, ustr_informational, 0x01, 0, NULL, 0); add_token(tok_severity, ustr_success, 0x00, 0, NULL, 0); add_token(tok_facility, ustr_application, 0xFFF, 0, NULL, 0); add_token(tok_facility, ustr_system, 0x0FF, 0, NULL, 0); add_token(tok_language, ustr_english, 0x409, 437, ustr_msg00001, 0); } empty_unichar_stack(); while(1) { if(want_line) { while((ch = get_unichar()) != '\n') { if(ch == EOF) xyyerror("Unexpected EOF\n"); push_unichar(ch); } newline(); push_unichar(ch); push_unichar(0); if(!unistrcmp(ustr_dot1, get_unichar_stack()) || !unistrcmp(ustr_dot2, get_unichar_stack())) { want_line = 0; /* Reset the codepage to our default after each message */ set_codepage(WMC_DEFAULT_CODEPAGE); return tMSGEND; } mcy_lval.str = xunistrdup(get_unichar_stack()); return tLINE; } ch = get_unichar(); if(ch == EOF) return EOF; if(ch == '\n') { newline(); if(want_nl) { want_nl = 0; return tNL; } continue; } if(isisochar(ch)) { if(want_file) { int n = 0; while(n < 8 && isisochar(ch)) { int t = char_table[ch]; if((t & CH_PUNCT) || !(t & CH_SHORTNAME)) break; push_unichar(ch); n++; ch = get_unichar(); } unget_unichar(ch); push_unichar(0); want_file = 0; mcy_lval.str = xunistrdup(get_unichar_stack()); return tFILE; } if(char_table[ch] & CH_IDENT) { token_t *tok; while(isisochar(ch) && (char_table[ch] & (CH_IDENT|CH_NUMBER))) { push_unichar(ch); ch = get_unichar(); } unget_unichar(ch); push_unichar(0); if(!(tok = lookup_token(get_unichar_stack()))) { mcy_lval.str = xunistrdup(get_unichar_stack()); return tIDENT; } switch(tok->type) { case tok_keyword: return tok->token; case tok_language: codepage = tok->codepage; /* Fall through */ case tok_severity: case tok_facility: mcy_lval.tok = tok; return tTOKEN; default: internal_error(__FILE__, __LINE__, "Invalid token type encountered\n"); } } if(isspace(ch)) /* Ignore space */ continue; if(isdigit(ch)) return scan_number(ch); } switch(ch) { case ':': case '=': case '+': case '(': case ')': return ch; case ';': while(ch != '\n' && ch != EOF) { push_unichar(ch); ch = get_unichar(); } newline(); push_unichar(ch); /* Include the newline */ push_unichar(0); mcy_lval.str = xunistrdup(get_unichar_stack()); return tCOMMENT; default: xyyerror("Invalid character '%c' (0x%04x)\n", isisochar(ch) && isprint(ch) ? ch : '.', ch); } } }
void abbreviate_name(const char *ptr, const char *end, string &result) { const char *last_name_end; const char *last_name_start = find_last_name(ptr, end, &last_name_end); int need_period = 0; for (;;) { const char *token_start = ptr; if (!get_token(&ptr, last_name_start)) break; const token_info *ti = lookup_token(token_start, ptr); if (need_period) { if ((ptr - token_start == 1 && *token_start == ' ') || (ptr - token_start == 2 && token_start[0] == '\\' && token_start[1] == ' ')) continue; if (ti->is_upper()) result += period_before_initial; else result += period_before_other; need_period = 0; } result.append(token_start, ptr - token_start); if (ti->is_upper()) { const char *lower_ptr = ptr; int first_token = 1; for (;;) { token_start = ptr; if (!get_token(&ptr, last_name_start)) break; if ((ptr - token_start == 1 && *token_start == ' ') || (ptr - token_start == 2 && token_start[0] == '\\' && token_start[1] == ' ')) break; ti = lookup_token(token_start, ptr); if (ti->is_hyphen()) { const char *ptr1 = ptr; if (get_token(&ptr1, last_name_start)) { ti = lookup_token(ptr, ptr1); if (ti->is_upper()) { result += period_before_hyphen; result.append(token_start, ptr1 - token_start); ptr = ptr1; } } } else if (ti->is_upper()) { // MacDougal -> MacD. result.append(lower_ptr, ptr - lower_ptr); lower_ptr = ptr; first_token = 1; } else if (first_token && ti->is_accent()) { result.append(token_start, ptr - token_start); lower_ptr = ptr; } first_token = 0; } need_period = 1; } } if (need_period) result += period_before_last_name; result.append(last_name_start, end - last_name_start); }
int lex_next(Lex l) { char *p; int len; assert(l != NULL); assert(l->magic == LEX_MAGIC); if (l->gotEOL) { /* deferred line count increment */ l->line++; l->gotEOL = 0; } for (;;) { switch (*l->pos) { case '\0': /* EOF */ l->text[0] = '\0'; return(l->prev = LEX_EOF); break; case ' ': /* ignore whitespace */ case '\t': case '\v': case '\f': l->pos++; break; case '#': /* ignore comments */ do { l->pos++; } while (*l->pos && (*l->pos != '\n') && (*l->pos != '\r')); break; case '\r': /* EOL: CR, LF, CR/LF */ if (*(l->pos+1) == '\n') l->pos++; /* fall-thru... whee! */ case '\n': l->text[0] = *l->pos++; l->text[1] = '\0'; l->gotEOL = 1; /* do not back up;severe tire damage */ return(l->prev = LEX_EOL); case '"': case '\'': for (p=l->pos+1; *p && *p!=*l->pos && *p!='\r' && *p!='\n'; p++){;} if (*p == *l->pos) { /* valid string */ len = MIN(p - l->pos - 1, LEX_MAX_STR - 1); memcpy(l->text, l->pos + 1, len); l->text[len] = '\0'; l->pos = p + 1; return(l->prev = LEX_STR); } else { /* unmatched quote */ l->text[0] = '\0'; l->pos = p; return(l->prev = LEX_ERR); } case '\\': if (*(l->pos+1) == '\n') { /* ignore EOL, continue to next line */ l->pos += 2; l->line++; break; } else if ((*(l->pos+1) == '\r') && (*(l->pos+2) == '\n')) { l->pos += 3; l->line++; break; } /* fall-thru... whee! */ default: if (isalpha((int)*l->pos) || (*l->pos == '_')) { for (p=l->pos+1; *p && (isalnum((int)*p) || *p=='_'); p++) {;} len = MIN(p - l->pos, LEX_MAX_STR - 1); memcpy(l->text, l->pos, len); l->text[len] = '\0'; l->pos = p; return(l->prev = lookup_token(l->text, l->toks, l->numtoks)); } else if (isdigit((int)*l->pos) || (((*l->pos == '-') || (*l->pos == '+')) && isdigit((int)*(l->pos+1)))) { /* integer: [-+]?[0-9]+ */ for (p=l->pos+1; *p && isdigit((int)*p); p++) {;} len = MIN(p - l->pos, LEX_MAX_STR - 1); memcpy(l->text, l->pos, len); l->text[len] = '\0'; l->pos = p; return(l->prev = LEX_INT); } l->text[0] = *l->pos++; /* single-character token */ l->text[1] = '\0'; return(l->prev = l->text[0]); } } }
void conf_load_zone_item( struct Configuration *cfg, const struct ConfParse *parse, const struct CF_Child *parent, struct Cfg_Zone *zone ) { struct CF_Token token = confparse_node_gettoken(parse, parent, 0); struct CF_Token value = confparse_node_gettoken(parse, parent, 1); switch (lookup_token(&token)) { case S_TYPE: if (zone->type != 0) CONF_OPTION_DUPLICATE(parse, &token); switch (lookup_token(&value)) { case S_MASTER: zone->type = CFGZ_MASTER; break; case S_SLAVE: zone->type = CFGZ_SLAVE; break; default: CONF_VALUE_BAD(parse, &value); } break; case S_FILE: if (zone->file != 0) { CONF_OPTION_DUPLICATE(parse, &token); free(zone->file); zone->file = NULL; } if (value.name_length == 0) { CONF_VALUE_BAD(parse, &value); } else { zone->file = filename_combine(cfg->options.directory, value.name); } break; case S_ALLOW_NOTIFY: if (zone->allow_notify) { CONF_OPTION_DUPLICATE(parse, &token); conf_addrmatch_free(zone->allow_notify); zone->allow_notify = NULL; } zone->allow_notify = conf_load_addrlist(cfg, parse, parent, 0, 65536); break; case S_ALLOW_TRANSFER: if (zone->allow_transfer) { CONF_OPTION_DUPLICATE(parse, &token); conf_addrmatch_free(zone->allow_transfer); zone->allow_transfer = NULL; } zone->allow_transfer = conf_load_addrlist(cfg, parse, parent, 0, 65536); break; case S_ALSO_NOTIFY: if (zone->also_notify) { CONF_OPTION_DUPLICATE(parse, &token); conf_addrmatch_free(zone->also_notify); zone->also_notify = NULL; } zone->also_notify = conf_load_addrlist(cfg, parse, parent, 0, 65536); break; default: CONF_OPTION_UNKNOWN(parse, &token); break; } }
//////////////////////////////////////////////////////////////////// // Function: PPInstance::read_contents_file // Access: Private // Description: Attempts to open and read the contents.xml file on // disk. Copies the file to its standard location // on success. Returns true on success, false on // failure. //////////////////////////////////////////////////////////////////// bool PPInstance:: read_contents_file(const string &contents_filename, bool fresh_download) { TiXmlDocument doc(contents_filename.c_str()); if (!doc.LoadFile()) { return false; } bool found_core_package = false; TiXmlElement *xcontents = doc.FirstChildElement("contents"); if (xcontents != NULL) { int max_age = P3D_CONTENTS_DEFAULT_MAX_AGE; xcontents->Attribute("max_age", &max_age); // Get the latest possible expiration time, based on the max_age // indication. Any expiration time later than this is in error. time_t now = time(NULL); _contents_expiration = now + (time_t)max_age; if (fresh_download) { // Update the XML with the new download information. TiXmlElement *xorig = xcontents->FirstChildElement("orig"); while (xorig != NULL) { xcontents->RemoveChild(xorig); xorig = xcontents->FirstChildElement("orig"); } xorig = new TiXmlElement("orig"); xcontents->LinkEndChild(xorig); xorig->SetAttribute("expiration", (int)_contents_expiration); } else { // Read the expiration time from the XML. int expiration = 0; TiXmlElement *xorig = xcontents->FirstChildElement("orig"); if (xorig != NULL) { xorig->Attribute("expiration", &expiration); } _contents_expiration = min(_contents_expiration, (time_t)expiration); } nout << "read contents.xml, max_age = " << max_age << ", expires in " << max(_contents_expiration, now) - now << " s\n"; // Look for the <host> entry; it might point us at a different // download URL, and it might mention some mirrors. find_host(xcontents); // Now look for the core API package. _coreapi_set_ver = ""; TiXmlElement *xpackage = xcontents->FirstChildElement("package"); while (xpackage != NULL) { const char *name = xpackage->Attribute("name"); if (name != NULL && strcmp(name, "coreapi") == 0) { const char *platform = xpackage->Attribute("platform"); if (platform != NULL && strcmp(platform, DTOOL_PLATFORM) == 0) { _coreapi_dll.load_xml(xpackage); const char *set_ver = xpackage->Attribute("set_ver"); if (set_ver != NULL) { _coreapi_set_ver = set_ver; } found_core_package = true; break; } } xpackage = xpackage->NextSiblingElement("package"); } } if (!found_core_package) { // Couldn't find the coreapi package description. nout << "No coreapi package defined in contents file for " << DTOOL_PLATFORM << "\n"; return false; } // Check the coreapi_set_ver token. If it is given, it specifies a // minimum Core API version number we expect to find. If we didn't // find that number, perhaps our contents.xml is out of date. string coreapi_set_ver = lookup_token("coreapi_set_ver"); if (!coreapi_set_ver.empty()) { nout << "Instance asked for Core API set_ver " << coreapi_set_ver << ", we found " << _coreapi_set_ver << "\n"; // But don't bother if we just freshly downloaded it. if (!fresh_download) { if (compare_seq(coreapi_set_ver, _coreapi_set_ver) > 0) { // The requested set_ver value is higher than the one we have on // file; our contents.xml file must be out of date after all. nout << "expiring contents.xml\n"; _contents_expiration = 0; } } } // Success. Now save the file in its proper place. string standard_filename = m_rootDir + "/contents.xml"; mkfile_complete(standard_filename, nout); if (!doc.SaveFile(standard_filename.c_str())) { nout << "Couldn't rewrite " << standard_filename << "\n"; return false; } return true; }
void reference::output(FILE *fp) { fputs(".]-\n", fp); for (int i = 0; i < 256; i++) if (field_index[i] != NULL_FIELD_INDEX && i != annotation_field) { string &f = field[field_index[i]]; if (!csdigit(i)) { int j = reverse_fields.search(i); if (j >= 0) { int n; int len = reverse_fields.length(); if (++j < len && csdigit(reverse_fields[j])) { n = reverse_fields[j] - '0'; for (++j; j < len && csdigit(reverse_fields[j]); j++) // should check for overflow n = n*10 + reverse_fields[j] - '0'; } else n = INT_MAX; reverse_names(f, n); } } int is_multiple = join_fields(f) > 0; if (capitalize_fields.search(i) >= 0) capitalize_field(f); if (memchr(f.contents(), '\n', f.length()) == 0) { fprintf(fp, ".ds [%c ", i); if (f[0] == ' ' || f[0] == '\\' || f[0] == '"') putc('"', fp); put_string(f, fp); putc('\n', fp); } else { fprintf(fp, ".de [%c\n", i); put_string(f, fp); fputs("..\n", fp); } if (i == 'P') { int multiple_pages = 0; const char *s = f.contents(); const char *end = f.contents() + f.length(); for (;;) { const char *token_start = s; if (!get_token(&s, end)) break; const token_info *ti = lookup_token(token_start, s); if (ti->is_hyphen() || ti->is_range_sep()) { multiple_pages = 1; break; } } fprintf(fp, ".nr [P %d\n", multiple_pages); } else if (i == 'E') fprintf(fp, ".nr [E %d\n", is_multiple); } for (const char *p = "TAO"; *p; p++) { int fi = field_index[(unsigned char)*p]; if (fi != NULL_FIELD_INDEX) { string &f = field[fi]; fprintf(fp, ".nr [%c %d\n", *p, is_terminated(f.contents(), f.contents() + f.length())); } } int t = classify(); fprintf(fp, ".][ %d %s\n", t, reference_types[t]); if (annotation_macro.length() > 0 && annotation_field >= 0 && field_index[annotation_field] != NULL_FIELD_INDEX) { putc('.', fp); put_string(annotation_macro, fp); putc('\n', fp); put_string(field[field_index[annotation_field]], fp); } }