/** * @brief Parse a line in control file. */ bool ReaderParam(Reader *rd, const char *keyword, char *target) { /* * result */ if (CompareKeyword(keyword, "INFILE") || CompareKeyword(keyword, "INPUT")) { ASSERT_ONCE(rd->infile == NULL); rd->infile = pstrdup(target); } else if (CompareKeyword(keyword, "LOGFILE")) { ASSERT_ONCE(rd->logfile == NULL); rd->logfile = pstrdup(target); } else if (CompareKeyword(keyword, "PARSE_BADFILE")) { ASSERT_ONCE(rd->parse_badfile == NULL); rd->parse_badfile = pstrdup(target); } else if (CompareKeyword(keyword, "PARSE_ERRORS") || CompareKeyword(keyword, "MAX_ERR_CNT")) { ASSERT_ONCE(rd->max_parse_errors < -1); rd->max_parse_errors = ParseInt64(target, -1); if (rd->max_parse_errors == -1) rd->max_parse_errors = INT64_MAX; } else if (CompareKeyword(keyword, "LOAD") || CompareKeyword(keyword, "LIMIT")) { ASSERT_ONCE(rd->limit == INT64_MAX); rd->limit = ParseInt64(target, 0); } else if (CompareKeyword(keyword, "CHECK_CONSTRAINTS")) { rd->checker.check_constraints = ParseBoolean(target); } else if (CompareKeyword(keyword, "ENCODING")) { ASSERT_ONCE(rd->checker.encoding < 0); rd->checker.encoding = pg_valid_client_encoding(target); if (rd->checker.encoding < 0) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid encoding for parameter \"ENCODING\": \"%s\"", target))); } else if (rd->parser == NULL || !ParserParam(rd->parser, keyword, target)) return false; return true; }
static void ParseOptions(Datum options, Reader **rd, Writer **wt, time_t tm) { List *defs; List *rest_defs = NIL; ListCell *cell; DefElem *opt; char *keyword; char *value; char *type = NULL; char *writer = NULL; bool multi_process = false; Assert(*rd == NULL); Assert(*wt == NULL); /* parse for each option */ defs = untransformRelOptions(options); foreach (cell, defs) { opt = lfirst(cell); if (opt->arg == NULL) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("option \"%s\" has no value", opt->defname))); keyword = opt->defname; value = strVal(opt->arg); if (CompareKeyword(keyword, "TYPE")) { ASSERT_ONCE(type == NULL); type = value; } else if (CompareKeyword(keyword, "WRITER") || CompareKeyword(keyword, "LOADER")) { ASSERT_ONCE(writer == NULL); writer = value; } else if (CompareKeyword(keyword, "MULTI_PROCESS")) { multi_process = ParseBoolean(value); } else { rest_defs = lappend(rest_defs, opt); continue; } }
/** * @brief Parse a line in control file. */ bool WriterParam(Writer *self, const char *keyword, char *value) { if (CompareKeyword(keyword, "VERBOSE")) { self->verbose = ParseBoolean(value); } else if (!self->param(self, keyword, value)) return false; return true; }
TSqlKeyword TSqlLexer::Keyword(const TSqlToken& aToken) // // non-member function: Return the keyword value // { if (aToken==ESqlIdentifier) { TInt r=KSqlKeywordCount; TInt l=0; while (r>l) { TInt m=(l+r)>>1; TInt k=CompareKeyword(m,aToken.Literal()); if (k>0) r=m; else if (k<0) l=m+1; else return TSqlKeyword(m); // keyword } }
static bool BufferedWriterParam(BufferedWriter *self, const char *keyword, char *value) { if (CompareKeyword(keyword, "TABLE") || CompareKeyword(keyword, "OUTPUT")) { ASSERT_ONCE(self->base.output == NULL); self->base.relid = RangeVarGetRelid(makeRangeVarFromNameList( stringToQualifiedNameList(value)), NoLock, false); self->base.output = get_relation_name(self->base.relid); } else if (CompareKeyword(keyword, "DUPLICATE_BADFILE")) { ASSERT_ONCE(self->base.dup_badfile == NULL); self->base.dup_badfile = pstrdup(value); } else if (CompareKeyword(keyword, "DUPLICATE_ERRORS")) { ASSERT_ONCE(self->base.max_dup_errors < -1); self->base.max_dup_errors = ParseInt64(value, -1); if (self->base.max_dup_errors == -1) self->base.max_dup_errors = INT64_MAX; } else if (CompareKeyword(keyword, "ON_DUPLICATE_KEEP")) { const ON_DUPLICATE values[] = { ON_DUPLICATE_KEEP_NEW, ON_DUPLICATE_KEEP_OLD }; self->base.on_duplicate = values[choice(keyword, value, ON_DUPLICATE_NAMES, lengthof(values))]; } else if (CompareKeyword(keyword, "TRUNCATE")) { self->base.truncate = ParseBoolean(value); } else return false; /* unknown parameter */ return true; }
static bool BinaryParserParam(BinaryParser *self, const char *keyword, char *value) { if (CompareKeyword(keyword, "COL")) { BinaryParam(&self->fields, &self->nfield, value, self->preserve_blanks, false); if (self->fields[self->nfield - 1].character) self->fields[self->nfield - 1].str = palloc(self->fields[self->nfield - 1].len * MAX_CONVERSION_GROWTH + 1); } else if (CompareKeyword(keyword, "PRESERVE_BLANKS")) { self->preserve_blanks = ParseBoolean(value); } else if (CompareKeyword(keyword, "STRIDE")) { ASSERT_ONCE(self->rec_len == 0); self->rec_len = ParseInt32(value, 1); } else if (CompareKeyword(keyword, "SKIP") || CompareKeyword(keyword, "OFFSET")) { ASSERT_ONCE(self->offset < 0); self->offset = ParseInt64(value, 0); } else if (CompareKeyword(keyword, "FILTER")) { ASSERT_ONCE(!self->filter.funcstr); self->filter.funcstr = pstrdup(value); } else return false; /* unknown parameter */ return true; }
void HangStruct::ScanState(const char *code, const char *state) { if (code != 0) { for (int n = 0; code[n] != NULLC; n++) { if (state[n] == Normal) { int c = code[n]; if (isName(c) && (n == 0 || !isName(code[n-1]))) { int findWord = LookupKeyword(code + n); do_aggreg = False; if (findWord >= 0) { indent = 0; until_parn = 1; n += strlen(pIndentWords[findWord].name) - 1; if (pIndentWords[findWord].code == oneLine) stmt_level++; else stmt_level = 0; } else { if (CompareKeyword(code+n, "enum")) until_curl = 1; if (parn_level == 0) until_parn = 0; indent = 1; while (isName(code[n])) n++; n--; } } else if (!isspace(code[n])) { if (do_aggreg && code[n] != L_CURL) do_aggreg = False; switch (code[n]) { case '=': if (parn_level == 0) do_aggreg = True; break; case L_CURL: curl_level++; indent = 0; stmt_level = 0; until_parn = 0; if (do_aggreg) in_aggreg = curl_level; break; case R_CURL: curl_level--; indent = 0; stmt_level = 0; until_curl = 0; break; case ':': // "::" means something different entirely if (code[n+1] == ':') { n++; } else { indent = 0; stmt_level = 0; until_parn = 0; } break; case SEMICOLON: if (parn_level == 0) { indent = 0; stmt_level = 0; until_parn = 0; until_curl = 0; if (in_aggreg > curl_level) in_aggreg = 0; } break; case L_PAREN: parn_level++; indent = 1; break; case R_PAREN: parn_level--; if (until_parn && !parn_level) indent = 0; else indent = 1; break; case ESCAPE: break; default: indent = 1; break; } } } } } }