static int parse_schema(fb_parser_t *P) { fb_token_t *t, *t0; parse_include(P); t = P->token; for (;;) { if (is_end(t)) { break; } if (P->failed >= FLATCC_MAX_ERRORS) { return -1; } t0 = t; parse_schema_decl(P); t = P->token; if (t == t0) { if (P->failed) { return -1; } error_tok(P, t, "extra tokens in input"); return -1; } } revert_names(&P->schema.attributes); revert_symbols(&P->schema.symbols); return 0; }
char * parse_expression(char *s, struct lacy_env *env) { int t = next_token(&s); switch (t) { case FOR: tree_push(FOR, NULL); s = parse_foreach(s, env); break; case DONE: tree_push(DONE, NULL); break; case INCLUDE: tree_push(INCLUDE, NULL); s = parse_include(s, env); break; default: fatal("excepted for\n"); } t = next_token(&s); switch (t) { case EXP_END: break; default: fatal("excepted expression end\n"); } return s; }
void Parser::compute_next() { if( !_alex.has_next() ) { _next = nullptr; return; } switch( _alex.peek().id ) { case Token::INCLUDE: _next = parse_include( _alex ); return; case Token::CATEGORY: _next = parse_category( _alex ); return; case Token::F: case Token::FX: case Token::FY: case Token::XF: case Token::YF: case Token::XFX: case Token::YFX: case Token::XFY: _next = parse_operator( _alex ); return; default: throw parse_error( "Expected include, category or operator", _alex.peek() ); } }
static void att_read_type_rsp(struct bt_conn *conn, uint8_t err, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_discover_params *params = user_data; uint16_t handle; BT_DBG("err 0x%02x", err); if (err) { goto done; } if (params->type == BT_GATT_DISCOVER_INCLUDE) { handle = parse_include(conn, pdu, params, length); } else { handle = parse_characteristic(conn, pdu, params, length); } if (!handle) { goto done; } /* Continue from the last handle */ params->start_handle = handle; if (params->start_handle < UINT16_MAX) { params->start_handle++; } /* Stop if over the requested range */ if (params->start_handle >= params->end_handle) { goto done; } /* Continue to the next range */ if (!bt_gatt_discover(conn, params)) { return; } done: params->func(conn, NULL, params); }
int assemble(struct _asm_context *asm_context) { char token[TOKENLEN]; int token_type; while(1) { token_type = tokens_get(asm_context, token, TOKENLEN); #ifdef DEBUG printf("%d: <%d> %s\n", asm_context->line, token_type, token); #endif if (token_type == TOKEN_EOF) break; if (token_type == TOKEN_EOL) { if (asm_context->macros.stack_ptr == 0) { asm_context->line++; } } else if (token_type == TOKEN_LABEL) { int param_count_temp; if (macros_lookup(&asm_context->macros, token, ¶m_count_temp) != NULL) { print_already_defined(asm_context, token); return -1; } if (symbols_append(&asm_context->symbols, token, asm_context->address / asm_context->bytes_per_address) == -1) { return -1; } } else if (token_type == TOKEN_POUND || IS_TOKEN(token,'.')) { token_type = tokens_get(asm_context, token, TOKENLEN); #ifdef DEBUG printf("%d: <%d> %s\n", asm_context->line, token_type, token); #endif if (token_type == TOKEN_EOF) break; if (strcasecmp(token, "define") == 0) { if (macros_parse(asm_context, IS_DEFINE) != 0) return -1; } else if (strcasecmp(token, "ifdef") == 0) { parse_ifdef(asm_context, 0); } else if (strcasecmp(token, "ifndef") == 0) { parse_ifdef(asm_context, 1); } else if (strcasecmp(token, "if") == 0) { parse_if(asm_context); } else if (strcasecmp(token, "endif") == 0) { if (asm_context->ifdef_count < 1) { printf("Error: unmatched .endif at %s:%d\n", asm_context->filename, asm_context->ifdef_count); return -1; } return 0; } else if (strcasecmp(token, "else") == 0) { if (asm_context->ifdef_count < 1) { printf("Error: unmatched .else at %s:%d\n", asm_context->filename, asm_context->ifdef_count); return -1; } return 2; } else if (strcasecmp(token, "include") == 0) { if (parse_include(asm_context) != 0) return -1; } else if (strcasecmp(token, "binfile") == 0) { if (parse_binfile(asm_context) != 0) return -1; } else if (strcasecmp(token, "code") == 0) { asm_context->segment = SEGMENT_CODE; } else if (strcasecmp(token, "bss") == 0) { asm_context->segment = SEGMENT_BSS; } else if (strcasecmp(token, "msp430_cpu4") == 0) { asm_context->msp430_cpu4 = 1; } else if (strcasecmp(token, "macro") == 0) { if (macros_parse(asm_context, IS_MACRO) != 0) return -1; } else if (strcasecmp(token, "pragma") == 0) { if (parse_pragma(asm_context) != 0) return -1; } else if (strcasecmp(token, "device") == 0) { if (parse_device(asm_context) != 0) return -1; } else if (strcasecmp(token, "set") == 0) { if (parse_set(asm_context) != 0) return -1; } else if (strcasecmp(token, "export") == 0) { if (parse_export(asm_context) != 0) return -1; } else if (strcasecmp(token, "equ") == 0 || strcasecmp(token, "def")==0) { if (parse_equ(asm_context) != 0) return -1; } else { int ret = check_for_directive(asm_context, token); if (ret == 2) break; if (ret == -1) return -1; if (ret != 1) { printf("Error: Unknown directive '%s' at %s:%d.\n", token, asm_context->filename, asm_context->line); return -1; } } } else if (token_type == TOKEN_STRING) { int ret = check_for_directive(asm_context, token); if (ret == 2) break; if (ret == -1) return -1; if (ret != 1) { int start_address = asm_context->address; char token2[TOKENLEN]; int token_type2; token_type2 = tokens_get(asm_context, token2, TOKENLEN); if (strcasecmp(token2, "equ") == 0) { //token_type2 = tokens_get(asm_context, token2, TOKENLEN); int ptr = 0; int ch = '\n'; while(1) { ch = tokens_get_char(asm_context); if (ch == EOF || ch == '\n') break; if (ch == '*' && ptr > 0 && token2[ptr-1] == '/') { macros_strip_comment(asm_context); ptr--; continue; } token2[ptr++] = ch; if (ptr == TOKENLEN-1) { printf("Internal Error: token overflow at %s:%d.\n", __FILE__, __LINE__); return -1; } } token2[ptr] = 0; tokens_unget_char(asm_context, ch); macros_strip(token2); macros_append(asm_context, token, token2, 0); } else { tokens_push(asm_context, token2, token_type2); ret = asm_context->parse_instruction(asm_context, token); if (asm_context->pass == 2 && asm_context->list != NULL && asm_context->include_count == 0) { asm_context->list_output(asm_context, start_address); fprintf(asm_context->list, "\n"); } if (ret < 0) return -1; if (asm_context->macros.stack_ptr == 0) { asm_context->line++; } asm_context->instruction_count++; if (asm_context->address > start_address) { asm_context->code_count += (asm_context->address - start_address); } } } } else { print_error_unexp(token, asm_context); return -1; } } if (asm_context->error == 1) { return -1; } return 0; }
/* Parse the rcfile, once it has been opened successfully at rcstream, * and close it afterwards. If syntax_only is TRUE, only allow the file * to contain color syntax commands: syntax, color, and icolor. */ void parse_rcfile(FILE *rcstream #ifdef ENABLE_COLOR , bool syntax_only #endif ) { char *buf = NULL; ssize_t len; size_t n; while ((len = getline(&buf, &n, rcstream)) > 0) { char *ptr, *keyword, *option; int set = 0; size_t i; /* Ignore the newline. */ if (buf[len - 1] == '\n') buf[len - 1] = '\0'; lineno++; ptr = buf; while (isblank(*ptr)) ptr++; /* If we have a blank line or a comment, skip to the next * line. */ if (*ptr == '\0' || *ptr == '#') continue; /* Otherwise, skip to the next space. */ keyword = ptr; ptr = parse_next_word(ptr); /* Try to parse the keyword. */ if (strcasecmp(keyword, "set") == 0) { #ifdef ENABLE_COLOR if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else #endif set = 1; } else if (strcasecmp(keyword, "unset") == 0) { #ifdef ENABLE_COLOR if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else #endif set = -1; } #ifdef ENABLE_COLOR else if (strcasecmp(keyword, "include") == 0) { if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else parse_include(ptr); } else if (strcasecmp(keyword, "syntax") == 0) { if (endsyntax != NULL && endcolor == NULL) rcfile_error(N_("Syntax \"%s\" has no color commands"), endsyntax->desc); parse_syntax(ptr); } else if (strcasecmp(keyword, "header") == 0) parse_headers(ptr); else if (strcasecmp(keyword, "color") == 0) parse_colors(ptr, FALSE); else if (strcasecmp(keyword, "icolor") == 0) parse_colors(ptr, TRUE); else if (strcasecmp(keyword, "bind") == 0) parse_keybinding(ptr); #endif /* ENABLE_COLOR */ else rcfile_error(N_("Command \"%s\" not understood"), keyword); if (set == 0) continue; if (*ptr == '\0') { rcfile_error(N_("Missing flag")); continue; } option = ptr; ptr = parse_next_word(ptr); for (i = 0; rcopts[i].name != NULL; i++) { if (strcasecmp(option, rcopts[i].name) == 0) { #ifdef DEBUG fprintf(stderr, "parse_rcfile(): name = \"%s\"\n", rcopts[i].name); #endif if (set == 1) { if (rcopts[i].flag != 0) /* This option has a flag, so it doesn't take an * argument. */ SET(rcopts[i].flag); else { /* This option doesn't have a flag, so it takes * an argument. */ if (*ptr == '\0') { rcfile_error( N_("Option \"%s\" requires an argument"), rcopts[i].name); break; } option = ptr; if (*option == '"') option++; ptr = parse_argument(ptr); option = mallocstrcpy(NULL, option); #ifdef DEBUG fprintf(stderr, "option = \"%s\"\n", option); #endif /* Make sure option is a valid multibyte * string. */ if (!is_valid_mbstring(option)) { rcfile_error( N_("Option is not a valid multibyte string")); break; } #ifndef DISABLE_OPERATINGDIR if (strcasecmp(rcopts[i].name, "operatingdir") == 0) operating_dir = option; else #endif #ifndef DISABLE_WRAPJUSTIFY if (strcasecmp(rcopts[i].name, "fill") == 0) { if (!parse_num(option, &wrap_at)) { rcfile_error( N_("Requested fill size \"%s\" is invalid"), option); wrap_at = -CHARS_FROM_EOL; } else free(option); } else #endif #ifndef NANO_TINY if (strcasecmp(rcopts[i].name, "matchbrackets") == 0) { matchbrackets = option; if (has_blank_mbchars(matchbrackets)) { rcfile_error( N_("Non-blank characters required")); free(matchbrackets); matchbrackets = NULL; } } else if (strcasecmp(rcopts[i].name, "whitespace") == 0) { whitespace = option; if (mbstrlen(whitespace) != 2 || strlenpt(whitespace) != 2) { rcfile_error( N_("Two single-column characters required")); free(whitespace); whitespace = NULL; } else { whitespace_len[0] = parse_mbchar(whitespace, NULL, NULL); whitespace_len[1] = parse_mbchar(whitespace + whitespace_len[0], NULL, NULL); } } else #endif #ifndef DISABLE_JUSTIFY if (strcasecmp(rcopts[i].name, "punct") == 0) { punct = option; if (has_blank_mbchars(punct)) { rcfile_error( N_("Non-blank characters required")); free(punct); punct = NULL; } } else if (strcasecmp(rcopts[i].name, "brackets") == 0) { brackets = option; if (has_blank_mbchars(brackets)) { rcfile_error( N_("Non-blank characters required")); free(brackets); brackets = NULL; } } else if (strcasecmp(rcopts[i].name, "quotestr") == 0) quotestr = option; else #endif #ifndef NANO_TINY if (strcasecmp(rcopts[i].name, "backupdir") == 0) backup_dir = option; else #endif #ifndef DISABLE_SPELLER if (strcasecmp(rcopts[i].name, "speller") == 0) alt_speller = option; else #endif if (strcasecmp(rcopts[i].name, "tabsize") == 0) { if (!parse_num(option, &tabsize) || tabsize <= 0) { rcfile_error( N_("Requested tab size \"%s\" is invalid"), option); tabsize = -1; } else free(option); } else assert(FALSE); } #ifdef DEBUG fprintf(stderr, "flag = %ld\n", rcopts[i].flag); #endif } else if (rcopts[i].flag != 0) UNSET(rcopts[i].flag); else rcfile_error(N_("Cannot unset flag \"%s\""), rcopts[i].name); break; } } if (rcopts[i].name == NULL) rcfile_error(N_("Unknown flag \"%s\""), option); } #ifdef ENABLE_COLOR if (endsyntax != NULL && endcolor == NULL) rcfile_error(N_("Syntax \"%s\" has no color commands"), endsyntax->desc); #endif free(buf); fclose(rcstream); lineno = 0; check_vitals_mapped(); return; }
bool parser::parse(const char * filename) { fake * fk = m_fk; if (!filename) { FKERR("parse filename is empty"); seterror(fk, efk_parse_file_fail, "", 0, "", "parse filename is empty"); return false; } FKLOG("parse %p %s", fk, filename); m_parse_dep++; // 检查深度 if (m_parse_dep >= m_fk->cfg.include_deps) { FKERR("parse %s file too deep %d", filename, m_parse_dep); seterror(fk, efk_parse_file_fail, filename, 0, "", "parse %s file too deep %d", filename, m_parse_dep); return false; } // 检查当前文件是否在解析中 if (is_parsing(filename)) { FKERR("parse open %s fail", fk, filename); seterror(fk, efk_parse_file_fail, filename, 0, "", "already parsing %s file...include list \n%s", filename, get_parsing_file_list()); return false; } // 加入 m_parsing_file_list.push_back(filename); // 清空错误 fk->clearerr(); // 输入源文件 FKLOG("parse inputfile %p %s", fk, filename); myflexer mf(fk); mf.clear(); bool b = mf.inputfile(filename); if (!b) { FKERR("parse open %s fail", fk, filename); return false; } // 进行语法解析 int ret = yyparse((void *)&mf); if (ret != 0) { FKERR("parse yyparse %s fail ret %d", fk, filename, ret); seterror(fk, efk_parse_file_fail, filename, mf.get_error_line(), "", "parse %s file fail for reason : %s", filename, mf.get_error()); return false; } FKLOG("parse yyparse %p %s OK", fk, filename); // 解析前置文件 for (int i = 0; i < (int)mf.get_include_list().size(); i++) { String & name = mf.get_include_list()[i]; if (!parse_include(filename, name)) { FKERR("%s parse_include %s fail", filename, name.c_str()); return false; } } // 编译 FKLOG("parse compile %p %s", fk, filename); compiler mc(fk, &mf); mc.clear(); b = mc.compile(); if (!b) { FKERR("parse %s compile %s fail", fk, filename); return false; } // jit fk->as.clear(); assembler & as = fk->as; b = as.compile(&fk->bin); if (!b) { FKERR("fkparse %s jit %s fail", fk, filename); return false; } // 弹出 assert(m_parsing_file_list.back() == (String)filename); m_parsing_file_list.pop_back(); FKLOG("parse %p %s OK", fk, filename); return true; }
bool parser::parsestr(const char * str) { fake * fk = m_fk; FKLOG("parsestr %p %s", fk, str); // 清空错误 fk->clearerr(); // 输入 myflexer mf(fk); mf.clear(); bool b = mf.inputstr(str); if (!b) { FKERR("parse inputstr %s fail", fk, str); return false; } // 进行语法解析 int ret = yyparse((void *)&mf); if (ret != 0) { FKERR("parse yyparse %s fail ret %d", fk, str, ret); seterror(fk, efk_parse_file_fail, "", mf.get_error_line(), "", "parse string fail for reason : %s", mf.get_error()); return false; } FKLOG("parse yyparse %p %s OK", fk, str); // 解析前置文件 for (int i = 0; i < (int)mf.get_include_list().size(); i++) { String & name = mf.get_include_list()[i]; if (!parse_include("", name)) { FKERR("%s parse_include %s fail", "", name.c_str()); return false; } } // 编译 FKLOG("parse compile %p %s", fk, str); compiler mc(fk, &mf); mc.clear(); b = mc.compile(); if (!b) { FKERR("parse %s compile %s fail", fk, str); return false; } // jit 先放弃 fk->as.clear(); assembler & as = fk->as; b = as.compile(&fk->bin); if (!b) { FKERR("parse %s jit %s fail", fk, str); return false; } FKLOG("parse %p %s OK", fk, str); return true; }
static int32_t snmptool_parse_options(struct snmp_toolinfo *snmptoolctx, int argc, char **argv) { int32_t count, optnum = 0; int ch; const char *opts; switch (program) { case BSNMPWALK: opts = "dhnKA:b:C:I:i:l:M:N:o:P:p:r:s:t:U:v:"; break; case BSNMPGET: opts = "aDdehnKA:b:C:I:i:l:M:N:o:P:p:r:s:t:U:v:"; break; case BSNMPSET: opts = "adehnKA:b:C:I:i:l:o:P:r:s:t:U:v:"; break; default: return (-1); } while ((ch = getopt(argc, argv, opts)) != EOF) { switch (ch) { case 'A': count = parse_authentication(snmptoolctx, optarg); break; case 'a': count = parse_skip_access(snmptoolctx); break; case 'b': count = parse_buflen(optarg); break; case 'D': count = parse_discovery(snmptoolctx); break; case 'd': count = parse_debug(); break; case 'e': count = parse_errors(snmptoolctx); break; case 'h': usage(); return (-2); case 'C': count = parse_context(snmptoolctx, optarg); break; case 'I': count = parse_include(snmptoolctx, optarg); break; case 'i': count = parse_file(snmptoolctx, optarg); break; case 'K': count = parse_local_key(snmptoolctx); break; case 'l': count = parse_local_path(optarg); break; case 'M': count = parse_max_repetitions(snmptoolctx, optarg); break; case 'N': count = parse_non_repeaters(snmptoolctx, optarg); break; case 'n': count = parse_num_oids(snmptoolctx); break; case 'o': count = parse_output(snmptoolctx, optarg); break; case 'P': count = parse_privacy(snmptoolctx, optarg); break; case 'p': count = parse_pdu_type(snmptoolctx, optarg); break; case 'r': count = parse_retry(optarg); break; case 's': count = parse_server(optarg); break; case 't': count = parse_timeout(optarg); break; case 'U': count = parse_user_security(snmptoolctx, optarg); break; case 'v': count = parse_version(optarg); break; case '?': default: usage(); return (-1); } if (count < 0) return (-1); optnum += count; } return (optnum); }
/* Parse the rcfile, once it has been opened successfully at rcstream, * and close it afterwards. If syntax_only is TRUE, only allow the file * to contain color syntax commands: syntax, color, and icolor. */ void parse_rcfile(FILE *rcstream #ifndef DISABLE_COLOR , bool syntax_only #endif ) { char *buf = NULL; ssize_t len; size_t n = 0; #ifndef DISABLE_COLOR syntaxtype *end_syn_save = NULL; #endif while ((len = getline(&buf, &n, rcstream)) > 0) { char *ptr, *keyword, *option; int set = 0; size_t i; /* Ignore the newline. */ if (buf[len - 1] == '\n') buf[len - 1] = '\0'; lineno++; ptr = buf; while (isblank(*ptr)) ptr++; /* If we have a blank line or a comment, skip to the next * line. */ if (*ptr == '\0' || *ptr == '#') continue; /* Otherwise, skip to the next space. */ keyword = ptr; ptr = parse_next_word(ptr); #ifndef DISABLE_COLOR /* Handle extending first... */ if (strcasecmp(keyword, "extendsyntax") == 0) { char *syntaxname = ptr; syntaxtype *ts = NULL; ptr = parse_next_word(ptr); for (ts = syntaxes; ts != NULL; ts = ts->next) if (!strcmp(ts->desc, syntaxname)) break; if (ts == NULL) { rcfile_error(N_("Could not find syntax \"%s\" to extend"), syntaxname); continue; } else { end_syn_save = endsyntax; endsyntax = ts; keyword = ptr; ptr = parse_next_word(ptr); } } #endif /* Try to parse the keyword. */ if (strcasecmp(keyword, "set") == 0) { #ifndef DISABLE_COLOR if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else #endif set = 1; } else if (strcasecmp(keyword, "unset") == 0) { #ifndef DISABLE_COLOR if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else #endif set = -1; } #ifndef DISABLE_COLOR else if (strcasecmp(keyword, "include") == 0) { if (syntax_only) rcfile_error( N_("Command \"%s\" not allowed in included file"), keyword); else parse_include(ptr); } else if (strcasecmp(keyword, "syntax") == 0) { if (endsyntax != NULL && endcolor == NULL) rcfile_error(N_("Syntax \"%s\" has no color commands"), endsyntax->desc); parse_syntax(ptr); } else if (strcasecmp(keyword, "magic") == 0) #ifdef HAVE_LIBMAGIC parse_magic_exp(ptr); #else ; #endif else if (strcasecmp(keyword, "header") == 0) parse_header_exp(ptr); else if (strcasecmp(keyword, "color") == 0) parse_colors(ptr, FALSE); else if (strcasecmp(keyword, "icolor") == 0) parse_colors(ptr, TRUE); else if (strcasecmp(keyword, "linter") == 0) parse_linter(ptr); else if (strcasecmp(keyword, "formatter") == 0) #ifndef DISABLE_SPELLER parse_formatter(ptr); #else ; #endif #endif /* !DISABLE_COLOR */ else if (strcasecmp(keyword, "bind") == 0)
/* * Parse data from a file into a policy language. */ int rlm_policy_parse(rbtree_t *policies, const char *filename) { FILE *fp; policy_lex_t token; policy_lex_file_t mylexer, *lexer = NULL; char buffer[32]; fp = fopen(filename, "r"); if (!fp) { fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno)); return 0; } lexer = &mylexer; memset(lexer, 0, sizeof(*lexer)); lexer->filename = filename; lexer->fp = fp; lexer->token = POLICY_LEX_BAD; lexer->parse = NULL; /* initial input */ lexer->policies = policies; do { int reserved; token = policy_lex_file(lexer, 0, buffer, sizeof(buffer)); switch (token) { case POLICY_LEX_BARE_WORD: reserved = fr_str2int(policy_reserved_words, buffer, POLICY_RESERVED_UNKNOWN); switch (reserved) { case POLICY_RESERVED_POLICY: if (!parse_named_policy(lexer)) { return 0; } break; case POLICY_RESERVED_INCLUDE: if (!parse_include(lexer)) { return 0; } break; case POLICY_RESERVED_DEBUG: if (!parse_debug(lexer)) { return 0; } break; default: fprintf(stderr, "%s[%d]: Unexpected word \"%s\"\n", lexer->filename, lexer->lineno, buffer); return 0; break; } /* switch over reserved words */ case POLICY_LEX_EOF: break; default: fprintf(stderr, "%s[%d]: Illegal input\n", lexer->filename, lexer->lineno); return 0; } } while (token != POLICY_LEX_EOF); if (((lexer->debug & POLICY_DEBUG_PRINT_POLICY) != 0) && fr_log_fp) { fprintf(fr_log_fp, "# rlm_policy \n"); } debug_tokens("--------------------------------------------------\n"); return 1; }
static int parse_one_file(config_t *config, const char *filename, char **section) { _cleanup_(fclosep) FILE *fp = NULL; _cleanup_free_ char *line = NULL; size_t n = 0; int in_options = 0; if(*section) { in_options = strcmp(*section, "options") == 0; } fp = fopen(filename, "r"); if(fp == NULL) { return -errno; } for(;;) { ssize_t len; errno = 0; len = getline(&line, &n, fp); if(len < 0) { if(errno != 0) { return -errno; } /* EOF */ break; } len = strtrim(line); if(len == 0 || line[0] == '#') { continue; } if(is_section(line, len)) { free(*section); *section = strndup(&line[1], len - 2); if(*section == NULL) { return -ENOMEM; } in_options = strcmp(*section, "options") == 0; if(!in_options) { int r; r = config_add_repo(config, *section); if(r < 0) { return r; } } continue; } if(in_options && memchr(line, '=', len)) { char *val = line; strsep(&val, "="); strtrim(line); strtrim(val); if(strcmp(line, "Include") == 0) { int k; k = parse_include(config, val, section); if(k < 0) { return k; } } else if(strcmp(line, "DBPath") == 0) { config->dbpath = strdup(val); if(config->dbpath == NULL) { return -ENOMEM; } } else if(strcmp(line, "RootDir") == 0) { config->dbroot = strdup(val); if(config->dbpath == NULL) { return -ENOMEM; } } } } return 0; }
std::string load_shader_impl(ShaderInitializationParams& params, const std::vector<std::string>& data, const std::string& tag, LoadContext& load_context) { std::string actual_data; enum { state_not_found, state_found, state_incorrect_found }; int state = state_not_found; for (size_t i = 0; i < data.size(); ++i) { const std::string& s = utils::trim_copy(data[i]); if (s.find(include_tag) != std::string::npos) { ++load_context.level; actual_data += parse_include(params, s, tag, load_context); --load_context.level; continue; } if (s.find(defs_tag) != std::string::npos) continue; if (s.find(sampler_tag) != std::string::npos) { actual_data += parse_sampler(params, s); continue; } if (s.find(uniform_tag) != std::string::npos) { actual_data += parse_uniform(params, s); continue; } if (s.find(image_tag) != std::string::npos) { actual_data += parse_image(params, s); continue; } if (s.find(var_tag) != std::string::npos) { actual_data += parse_variable(params, s); continue; } if (s.find(version_tag) != std::string::npos) { actual_data += parse_version(params, s); continue; } if (s == tag) state = state_found; else { for (size_t j = 0; j < 4; ++j) { if (s == tags[j]) { if (state == state_found) return actual_data; else state = state_incorrect_found; break; } } if (state != state_incorrect_found) actual_data += (s + "\n"); } } if (state == state_found) load_context.tag_found = true; if (!load_context.tag_found && load_context.level == 0) actual_data.clear(); return actual_data; }
/* * Extracts given chains from a policy file. */ static int openpam_parse_chain(pam_handle_t *pamh, const char *service, pam_facility_t facility, const char *filename, openpam_style_t style) { pam_chain_t *this, **next; pam_facility_t fclt; pam_control_t ctlf; char *line0, *line, *str, *name; char *option, **optv; int len, lineno, ret; FILE *f; if ((f = fopen(filename, "r")) == NULL) { openpam_log(errno == ENOENT ? PAM_LOG_DEBUG : PAM_LOG_NOTICE, "%s: %m", filename); return (PAM_SUCCESS); } if (openpam_check_desc_owner_perms(filename, fileno(f)) != 0) { fclose(f); return (PAM_SYSTEM_ERR); } this = NULL; name = NULL; lineno = 0; while ((line0 = line = openpam_readline(f, &lineno, NULL)) != NULL) { /* get service name if necessary */ if (style == pam_conf_style) { if ((len = parse_service_name(&line, &str)) == 0) { openpam_log(PAM_LOG_NOTICE, "%s(%d): invalid service name (ignored)", filename, lineno); FREE(line0); continue; } if (strlcmp(service, str, len) != 0) { FREE(line0); continue; } } /* get facility name */ if ((fclt = parse_facility_name(&line)) == (pam_facility_t)-1) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid facility", filename, lineno); goto fail; } if (facility != fclt && facility != PAM_FACILITY_ANY) { FREE(line0); continue; } /* check for "include" */ if (parse_include(&line)) { if ((len = parse_service_name(&line, &str)) == 0) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid filename", filename, lineno); goto fail; } if ((name = strndup(str, len)) == NULL) goto syserr; if (parse_eol(&line) != 0) { openpam_log(PAM_LOG_ERROR, "%s(%d): garbage at end of line", filename, lineno); goto fail; } ret = openpam_load_chain(pamh, name, fclt); FREE(name); if (ret != PAM_SUCCESS) goto fail; FREE(line0); continue; } /* get control flag */ if ((ctlf = parse_control_flag(&line)) == (pam_control_t)-1) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid control flag", filename, lineno); goto fail; } /* get module name */ if ((len = parse_filename(&line, &str)) == 0) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid module name", filename, lineno); goto fail; } if ((name = strndup(str, len)) == NULL) goto syserr; /* allocate new entry */ if ((this = calloc(1, sizeof *this)) == NULL) goto syserr; this->flag = ctlf; /* get module options */ if ((this->optv = malloc(sizeof *optv)) == NULL) goto syserr; this->optc = 0; while ((option = parse_option(&line)) != NULL) { optv = realloc(this->optv, (this->optc + 2) * sizeof *optv); if (optv == NULL) goto syserr; this->optv = optv; this->optv[this->optc++] = option; } this->optv[this->optc] = NULL; if (*line != '\0') { openpam_log(PAM_LOG_ERROR, "%s(%d): syntax error in module options", filename, lineno); goto fail; } /* load module */ this->module = openpam_load_module(name); FREE(name); if (this->module == NULL) goto fail; /* hook it up */ for (next = &pamh->chains[fclt]; *next != NULL; next = &(*next)->next) /* nothing */ ; *next = this; this = NULL; /* next please... */ FREE(line0); } if (!feof(f)) goto syserr; fclose(f); return (PAM_SUCCESS); syserr: openpam_log(PAM_LOG_ERROR, "%s: %m", filename); fail: if (this && this->optc) { while (this->optc--) FREE(this->optv[this->optc]); FREE(this->optv); } FREE(this); FREE(line0); FREE(name); fclose(f); return (PAM_SYSTEM_ERR); }