static struct test *read_tests(void) { char *fname; FILE *fp; char line[BUFSIZ]; struct test *result = NULL, *t = NULL; int lc = 0; bool append_cmd = true; if (asprintf(&fname, "%s/tests/run.tests", abs_top_srcdir) < 0) die("asprintf fname"); if ((fp = fopen(fname, "r")) == NULL) die("fopen run.tests"); while (fgets(line, BUFSIZ, fp) != NULL) { lc += 1; char *s = skipws(line); if (*s == '#' || *s == '\0') continue; if (*s == ':') s += 1; char *eos = s + strlen(s) - 2; if (eos >= s && *eos == ':') { *eos++ = '\n'; *eos = '\0'; } if (looking_at(s, KW_TEST)) { if (ALLOC(t) < 0) die_oom(); list_append(result, t); append_cmd = true; s = token(s + strlen(KW_TEST), &(t->name)); s = inttok(s, &t->result); s = errtok(s, &t->errcode); } else if (looking_at(s, KW_PRINTS)) { s = skipws(s + strlen(KW_PRINTS)); t->out_present = looking_at(s, KW_SOMETHING); append_cmd = false; } else if (looking_at(s, KW_USE)) { if (t->module !=NULL) die("Can use at most one module in a test"); s = token(s + strlen(KW_USE), &(t->module)); } else { char **buf = append_cmd ? &(t->cmd) : &(t->out); if (*buf == NULL) { *buf = strdup(s); if (*buf == NULL) die_oom(); } else { if (REALLOC_N(*buf, strlen(*buf) + strlen(s) + 1) < 0) die_oom(); strcat(*buf, s); } } if (t->out != NULL) t->out_present = true; } return result; }
void netlist_parser::netdev_device(const pstring &dev_type) { pstring devname; netlist_device_t *dev; int cnt; skipws(); devname = getname2(',', ')'); dev = m_setup.factory().new_device_by_name(dev_type, m_setup); m_setup.register_dev(dev, devname); NL_VERBOSE_OUT(("Parser: IC: %s\n", devname.cstr())); cnt = 0; while (getc() != ')') { skipws(); pstring output_name = getname2(',', ')'); pstring alias = pstring::sprintf("%s.[%d]", devname.cstr(), cnt); NL_VERBOSE_OUT(("Parser: ID: %s %s\n", output_name.cstr(), alias.cstr())); m_setup.register_link(alias, output_name); skipws(); cnt++; } /* if (cnt != dev->m_terminals.count() && !dev->variable_input_count()) fatalerror("netlist: input count mismatch for %s - expected %d found %d\n", devname.cstr(), dev->m_terminals.count(), cnt); if (dev->variable_input_count()) { NL_VERBOSE_OUT(("variable inputs %s: %d\n", dev->name().cstr(), cnt)); } */ }
TInt DWinsKeyboard::DefineAlias(const char* aValue) // // The character string terminates in a ';' or a '\0' // { //get the alias name const char* beg = skipws(aValue); const char* end = skiptok(beg); TPtrC8 alias((const TUint8*)beg, end-beg); //get the real name beg = skipws(end); end = skiptok(beg); TPtrC8 name((const TUint8*)beg, end-beg); //prevent an alias being made of an alias if (iAliasedKeys[name] != NULL) return KErrArgument; // ensure this is valid name TInt r = GetEPOCKeyCode(name); if (r == KErrNotFound) return r; //now we need to record the alias name and the real key name return iAliasedKeys.Add(alias, name); }
void netlist_parser::netdev_device(const pstring &dev_type, const pstring &default_param, bool isString) { netlist_device_t *dev; skipws(); pstring devname = getname2(',', ')'); pstring defparam = devname + "." + default_param; dev = m_setup.factory().new_device_by_name(dev_type, m_setup); m_setup.register_dev(dev, devname); NL_VERBOSE_OUT(("Parser: IC: %s\n", devname.cstr())); if (getc() != ')') { // have a default param skipws(); if (isString) { pstring val = getname(')'); ungetc(); NL_VERBOSE_OUT(("Parser: Default param: %s %s\n", defparam.cstr(), val.cstr())); m_setup.register_param(defparam, val); } else { double val = eval_param(); NL_VERBOSE_OUT(("Parser: Default param: %s %f\n", defparam.cstr(), val)); m_setup.register_param(defparam, val); } } check_char(')'); }
pstring netlist_parser::getstring() { skipws(); check_char('"'); pstring ret = getname2_ext('"', 0, NULL); check_char('"'); skipws(); return ret; }
void netlist_parser::net_alias() { pstring alias; pstring out; skipws(); alias = getname(','); skipws(); out = getname(')'); NL_VERBOSE_OUT(("Parser: Alias: %s %s\n", alias.cstr(), out.cstr())); m_setup.register_alias(alias, out); }
void netlist_parser::net_c() { pstring t1; pstring t2; skipws(); t1 = getname(','); skipws(); t2 = getname(')'); NL_VERBOSE_OUT(("Parser: Connect: %s %s\n", t1.cstr(), t2.cstr())); m_setup.register_link(t1 , t2); }
static int parsepair(Parser *p, JSON *parent, JSON **kprev, JSON **vprev) { must(*p->s == '"'); must(parsestring(p, parent, kprev)); skipws(p); must(consume(p, ":")); skipws(p); must(parsevalue(p, parent, vprev)); return 1; }
void netlist_parser::netdev_param() { pstring param; double val; skipws(); param = getname(','); skipws(); val = eval_param(); NL_VERBOSE_OUT(("Parser: Param: %s %f\n", param.cstr(), val)); m_setup.register_param(param, val); check_char(')'); }
void record_enum::parse(proto_info &, cursor &c) { pimpl->name = get_to_sep(c, ' ', enum_body_open_char, enum_type_separator); // if enum has specified underlying type skipws(c); if ( curch(c) == enum_type_separator ) { check_next(c, enum_type_separator); cursor c1 = c; const std::string type = get_to_sep(c, ' ', enum_body_open_char); pimpl->type = type_id_by_name(type); if ( pimpl->type == type_id::type_unknown ) YARMI_THROW( "enum underlying type error: '%s' in %s" ,type ,c1.format() ); } check_next(c, enum_body_open_char); for ( ;; ) { skipws(c); // if enum don't have any members char cc = curch(c); if ( cc == enum_body_close_char ) { check_next(c, enum_body_close_char); check_next(c, enum_body_close_dotcomma_char); return; } const std::string n = get_to_sep(c, ',', ' ', enum_assign_char, enum_body_close_char); skipws(c); cc = curch(c); // without init value if ( cc == ',' ) { nextch(c); pimpl->elems.push_back({n, ""}); // with init value } else if ( cc == enum_assign_char ) { nextch(c); const std::string v = get_to_sep(c, ' ', ',', enum_body_close_char); pimpl->elems.push_back({n, v}); // error } else { YARMI_THROW( "syntax error: '%c' in %s" ,cc ,c.format() ); } } }
void netlist_parser::netdev_device(const pstring &dev_type) { pstring devname; net_device_t_base_factory *f = m_setup.factory().factory_by_name(dev_type, m_setup); netlist_device_t *dev; nl_util::pstring_list termlist = f->term_param_list(); pstring def_param = f->def_param(); int cnt; skipws(); devname = getname2(',', ')'); dev = f->Create(); m_setup.register_dev(dev, devname); NL_VERBOSE_OUT(("Parser: IC: %s\n", devname.cstr())); if (def_param != "") { pstring paramfq = devname + "." + def_param; NL_VERBOSE_OUT(("Defparam: %s\n", def_param.cstr())); check_char(','); skipws(); if (peekc() == '"') { pstring val = getstring(); m_setup.register_param(paramfq, val); } else { double val = eval_param(); m_setup.register_param(paramfq, val); } if (termlist.count() > 0) check_char(','); } cnt = 0; while (getc() != ')' && cnt < termlist.count()) { skipws(); pstring output_name = getname2(',', ')'); m_setup.register_link(devname + "." + termlist[cnt], output_name); skipws(); cnt++; } if (cnt != termlist.count()) fatalerror("netlist: input count mismatch for %s - expected %d found %d\n", devname.cstr(), termlist.count(), cnt); }
void netlist_parser::netdev_netlist_start() { // don't do much skipws(); /*pstring dummyname = */ getname(')'); //check_char(')'); }
void netlist_parser::parse(const char *buf) { m_px = buf; m_line_ptr = buf; m_line = 1; while (!eof()) { pstring n; skipws(); if (eof()) break; n = getname('('); NL_VERBOSE_OUT(("Parser: Device: %s\n", n.cstr())); if (n == "NET_ALIAS") net_alias(); else if (n == "NET_C") net_c(); else if (n == "NETDEV_PARAM") netdev_param(); else if ((n == "NET_MODEL")) net_model(); else if (n == "NETLIST_START") netdev_netlist_start(); else if (n == "NETLIST_END") netdev_netlist_end(); else netdev_device(n); } }
PROC join(int count) { bool ok; int lp, first; if (lend < bufmax) { /* are we in the buffer? */ disp = lend; /* start redraw here */ newc = lend; do { /* join until.. */ first = lend; lp = skipws(1+first); ok = delete_to_undo(&undo, 1+first, lp-(1+first)); if (ok) { ok = move_to_undo(&undo, first, 1); core[first] = ' '; /* spaces between lines */ } count--; lend = fseekeol(first); } while (ok && count > 0); endY = MAGICNUMBER; newend = lend; if (!ok) error(); } else error(); }
PROC scroll(bool down) { int i; if (count <= 0) count = dofscroll; strput(CURoff); if (down) { curr = min(bufmax-1, nextline(TRUE, curr, count)); i = min(bufmax-1, nextline(TRUE, pend, count)); if (i > pend) scrollforward(i); } else { curr = bseekeol(max(0,nextline(FALSE, curr, count))); i = bseekeol(max(0,nextline(FALSE, ptop, count))); if (i < ptop) if (canUPSCROLL) scrollback(i); else { ptop = i; setend(); redisplay(TRUE); } } strput(CURon); setpos(skipws(curr)); /* initialize new position - first nonwhite */ yp = setY(curr); mvcur(yp, xp); /* go there */ }
void tech_fix(dbref player, void *data, char *buffer) { MECH *mech = data; int n = atoi(buffer); int low, high; int isds; skipws(buffer); TECHCOMMANDC; if (unit_is_fixable(mech)) make_damage_table(mech); else make_scrap_table(mech); DOCHECK(!damage_last && MechType(mech) == CLASS_MECH, "The 'mech is in pristine condition!"); DOCHECK(!damage_last, "It's in pristine condition!"); if (sscanf(buffer, "%d-%d", &low, &high) == 2) { DOCHECK(low < 1 || low > damage_last, "Invalid low #!"); DOCHECK(high < 1 || high > damage_last, "Invalid high #!"); for (n = low; n <= high; n++) fix_entry(player, mech, n); return; } DOCHECK(n < 1 || n > damage_last, "Invalid #!"); fix_entry(player, mech, n); }
void netlist_parser::parse(const char *buf) { m_px = buf; while (!eof()) { pstring n; skipws(); if (eof()) break; n = getname('('); NL_VERBOSE_OUT(("Parser: Device: %s\n", n.cstr())); if (n == "NET_ALIAS") net_alias(); else if (n == "NET_C") net_c(); else if (n == "NETDEV_PARAM") netdev_param(); else if (n == "NETDEV_R") netdev_device(n, "R"); else if (n == "NETDEV_C") netdev_device(n, "C"); else if (n == "NETDEV_POT") netdev_device(n, "R"); else if (n == "NETDEV_D") netdev_device(n, "model", true); else if ((n == "NETDEV_TTL_CONST") || (n == "NETDEV_ANALOG_CONST")) netdev_const(n); else netdev_device(n); } }
static bool parse_headers(Iterator& it, Request& request) { bool res = true; while (res) { std::string key; std::string value; res = consumeUntil(it, key, ": \r"); if (key.empty()) { return res; } skipws(it); res = res && expect(it, ":"); while (match(it, ' ')) { } res = res && consumeUntil(it, value, "\r"); if (res) { request.headers.emplace_back(std::move(key), std::move(value)); } res = res && expect(it, HTTP_DELIMITER); } return false; }
static bool parse_uri(Iterator& it, Request& request) { skipws(it); consumeUntil(it, request.uri, "? "); if (match(it, '?')) { do { std::string key; std::string value; bool res = consumeUntil(it, key, "&= "); if (match(it, '=')) { res = res && consumeUntil(it, value, "& "); key = UTILS::url_decode(key); value = UTILS::url_decode(value); request.query_params.emplace_back(std::move(key), std::move(value)); } else { request.query_params.emplace_back(std::move(key), ""); } if (!res) { return res; } } while (match(it, '&')); } return it != EOS; }
static bool parse_http_version(Iterator& it, Request& request) { skipws(it); bool res = expect(it, "HTTP/"); std::string major, minor; res = res && consumeUntil(it, major, "."); res = res && expect(it, "."); res = res && consumeUntil(it, minor, "\r"); if (res) { try { request.major = std::stoi(major); request.minor = std::stoi(minor); } catch (std::exception const& ex) { LOG(parser_logger, error) << "Cannot parse Major/Minor: " << ex.what(); return false; } } return res; }
bool readrecord() { if(!skip('#')) return false; // Read data base name if(!readidentifier()) { error(ErrorExpectedIdentifier); return true; } skipws(); const bsreq* fields = 0; auto pd = bsdata::find(buffer); if(pd) fields = pd->fields; else warning(ErrorNotFoundBase1p, buffer); // Read key value parent_object = value_object; if(iskey(p)) readvalue(fields, true); else if(pd) value_object = pd->add(); else value_object = 0; readfields(value_object, fields); parent_type = fields; return true; }
bool readsubrecord() { auto index = 0; auto last_field = 0; while(skip("##")) { // Read data base name if(!readidentifier()) { error(ErrorExpectedIdentifier); return true; } skipws(); auto parent_field = parent_type->find(buffer); if(!parent_field) { error(ErrorNotFoundMember1pInBase2p, buffer, ""); return true; } if(parent_field->count <= 1 // Only array may be defined as ## || parent_field->reference // No reference allowed || parent_field->isenum // Enumeratior must be initialized in row || parent_field->type->issimple()) { // No Simple type error(ErrorExpectedArrayField); } readfields((void*)parent_field->ptr(parent_object, index), parent_field->type); index++; } // If aref or adat save count return false; }
bool skip(char sym) { if(*p != sym) return false; p++; skipws(); return true; }
/* * Split a string into 2 whitespace separated fields returned in "key" and * "value". If more than 2 fields are found, they are cut off by zero * terminating "key" and "value" inside the string. If "value" is not found, * *value is set to NULL. If "key" is not found, *key is set to NULL. * If something is found, both *key and *value become pointers inside the * string s. * * Return values: * - 0 if neither "key" nor "value" is found * - 1 if only "key" is found * - 2 if both "key" and "value" are found */ int get_two_ws_separated_fields(char **key, char **value, char *s) { int i; *key = NULL; *value = NULL; i = skipws(s, 0); /* Skip initial whitespace */ if (i < 0) return 0; /* We got nothing */ *key = s + i; i = skip_and_terminate_word(s, i); if (i < 0) return 1; /* We got a "key", but not a "value" */ *value = s + i; skip_and_terminate_word(s, i); return 2; /* We got both a "key" and a "value" */ }
int tok_get(void) { int num; if (next != -1) { int tok = next; next = -1; return tok; } pre = cur; if (skipws()) return TOK_EOF; if (buf[cur] == '"') { mem_cut(&str, 0); while (buf[cur] == '"') { readstr(&str); if (skipws()) return TOK_EOF; } return TOK_STR; } if (isdigit(buf[cur]) || buf[cur] == '\'') { readnum(); return TOK_NUM; } if (id_char(buf[cur])) { char *s = name; int i; while (cur < len && id_char(buf[cur])) *s++ = buf[cur++]; *s = '\0'; for (i = 0; i < LEN(kwds); i++) if (!strcmp(kwds[i].name, name)) return kwds[i].id; return TOK_NAME; } if (cur + 3 <= len && (num = get_tok3(TOK3(buf + cur)))) { cur += 3; return num; } if ((num = get_tok3(TOK2(buf + cur)))) { cur += 2; return num; } if (strchr(";,{}()[]<>*&!=+-/%?:|^~.", buf[cur])) return buf[cur++]; return -1; }
void netlist_parser::netdev_const(const pstring &dev_name) { pstring name; netlist_device_t *dev; pstring paramfq; double val; skipws(); name = getname(','); dev = m_setup.factory().new_device_by_name(dev_name, m_setup); m_setup.register_dev(dev, name); skipws(); val = eval_param(); paramfq = name + ".CONST"; NL_VERBOSE_OUT(("Parser: Const: %s %f\n", name.cstr(), val)); check_char(')'); m_setup.register_param(paramfq, val); }
bool iskey(const char* p) { if((p[0] >= 'a' && p[0] <= 'z') || (p[0] >= 'A' && p[0] <= 'Z')) { while(*p && ((*p >= '0' && *p <= '9') || *p == '_' || ischa(*p))) p++; p = skipws(p); return p[0] != '('; } return true; }
void netlist_parser::check_char(char ctocheck) { skipws(); char c = getc(); if ( c == ctocheck) { return; } error("expected '%c' found '%c'\n", ctocheck, c); }
void netlist_parser::check_char(char ctocheck) { skipws(); char c = getc(); if ( c == ctocheck) { return; } m_setup.netlist().xfatalerror("Parser: expected '%c' found '%c'\n", ctocheck, c); }
// Scans src and writes pointers to the lexical bounds of JSON values // to elements of part. // // Returns the total number of values in src, regardless of npart. // If src is not well-formed JSON, returns 0. int jsonparse(char *src, JSON *part, int npart) { Parser p = {}; p.s = src; p.j = part; p.nj = npart; skipws(&p); must(parsetext(&p)); skipws(&p); must(*p.s == '\0'); if (part) { if (p.n < npart) { npart = p.n; } for (int i = 0; i < npart; i++) { part[i].len = part[i].end - part[i].src; } } return p.n; }