static void handle_section(char *s) { char *name,*attr,*new,*p; uint32_t mem=0; section *sec; if(!(name=parse_name(&s))){ syntax_error(20); /* section name */ return; } if(*s==','){ s=skip(s+1); if(*s!='\"') general_error(6,'\"'); /* quote expected */ if(attr=parse_name(&s)){ if(*s==','){ p=s=skip(s+1); if(*s=='@'||*s=='%'){ /* ELF section type "progbits" or "nobits" */ s++; if(new=parse_identifier(&s)){ if(!strcmp(new,"nobits")){ myfree(new); if(strchr(attr,'u')==NULL){ new=mymalloc(strlen(attr)+2); sprintf(new,"u%s",attr); myfree(attr); attr=new; } }else{ if(strcmp(new,"progbits")) syntax_error(14); /* invalid sectiont type ignored */ myfree(new); } }
void xml_html_parser::parse_entity_decl () { s += 8; skip_space (); bool parameter= test (s, "%"); if (parameter) { s += 1; skip_space (); } string name= parse_name (); if (parameter) name= "%" * name * ";"; else name= "&" * name * ";"; skip_space (); if (test (s, "SYSTEM") || test (s, "PUBLIC")) { // TODO: allow for loading of external entities using wget if (test (s, "SYSTEM")) (void) parse_system (); else (void) parse_public (); skip_space (); if (test (s, "NDATA")) { s += 5; skip_space (); (void) parse_name (); } } else { string val= parse_quoted (); val= expand_entities (val); entities (name) = val; // cout << name << " := " << val << "\n"; } skip_space (); if (test (s, ">")) s += 1; }
int read_fastq(char *fname1, char *fname2, Reads &reads) { std::ifstream f1(fname1),f2(fname2); if (!f1.is_open()) { std::cerr << "ERROR: could not open file " << fname1 << "\n"; exit(-1); } if (!f2.is_open()) { std::cerr << "ERROR: could not open file " << fname2 << "\n"; exit(-1); } std::string p1,p2; Read r1, r2; int count=0,num=0; while(std::getline(f1,p1) && std::getline(f2,p2)) { //std::cout << p1 << "\t\t\t" << p2 << "\n"; if(count==0) { r1.name = parse_name(p1); r2.name = parse_name(p2); } if(count==1) { r1.seq = p1; r2.seq = p2; reads.push_back(r1); reads.push_back(r2); num++; } count+=1; count%=4; } return num; }
string xml_html_parser::transcode (string s2) { s= parse_string (s2); string encoding; if (test (s, "<?")) { s += 2; string target= parse_name (); skip_space (); if (target == "xml") { // since html==true implies we can accept horribly broken HTML, the // presence of an XML prolog is not enough to clear the flag. /* html= false; */ while (s && !test (s, "?>")) { string attname= parse_name (); skip_space (); if (!test (s, "=")) break; s += 1; skip_space (); string val; if (test (s, "\"")) { s += 1; val= parse_until ("\""); skip_space (); } else if (test (s, "'")) { s += 1; val= parse_until ("'"); skip_space (); } if (attname == "encoding") { encoding= upcase_all (val); break; } } } } if (N(encoding) != 0) { // cout << "encoding was specified\n" ; string s3= convert (s2, encoding, "UTF-8"); if (N(s3) == 0) /* conversion from specified charset failed, do nothing (and pray) */ ; else return s3; } else { // cout << "guess encoding\n" ; if (check_encoding (s2, "UTF-8")) /* input encoding seems to be utf-8, do nothing */ ; else { string s3= convert (s2, "ISO-8859-1", "UTF-8"); if (N(s3) != 0) return s3; } } return s2; }
void document_imp::StartElementHandler( const XML_Char* name, const XML_Char** atts) { string element, ns, prefix; parse_name(name, element, ns, prefix); node_ptr n; n.reset(new node(element, ns, prefix)); if (cur.empty()) { cur.push(n); root = cur.top(); } else { cur.top()->add_child(n); cur.push(n); } for (const char** att = atts; *att; att += 2) { if (not att[0] or not att[1]) break; parse_name(att[0], element, ns, prefix); if (not prefix.empty()) element = prefix + ':' + element; attribute_ptr attr(new xml::attribute(element, att[1])); cur.top()->add_attribute(attr); } const string name_prefix("xmlns:"); for (vector<pair<string,string> >::iterator ns = namespaces.begin(); ns != namespaces.end(); ++ns) { string name; if (ns->first.empty()) name = "xmlns"; else name = name_prefix + ns->first; attribute_ptr attr(new xml::attribute(name, ns->second)); cur.top()->add_attribute(attr); } namespaces.clear(); }
bool xml_istream::parse_empty_tag(const string& s, string& open, map<string, string>& attributes) { bool ok = false; open.clear(); attributes.clear(); size_t length = s.length(); size_t k = s.rfind("/>"); assert(s.find('<') == 0 && (k + 2) == length); size_t i = 1; if (parse_name(s, i, open) != false) { ok = true; parse_ws(s, i); while (i < k && ok != false) { string attribute, value; ok = false; if (parse_name(s, i, attribute) != false) { if (parse_eq(s, i) != false) { char ch = s[i]; if (ch == '\'' || ch == '"') { ++i; for (; i < k && s[i] != ch; ++i) { value += s[i]; } if (s[i] == ch) { attributes[attribute] = value; ok = true; } } } } ++i; parse_ws(s, i); } } return ok; }
static void handle_section(char *s) { char *name,*attr; if(!(name=parse_name(&s))) return; if(*s==','){ s=skip(s+1); attr=s; if(*s!='\"') syntax_error(7); else s++; attr=s; while(*s&&*s!='\"') s++; attr=cnvstr(attr,s-attr); s=skip(s+1); }else{ attr=""; if(!strcmp(name,textname)) attr=textattr; if(!strcmp(name,dataname)) attr=dataattr; if(!strcmp(name,sdataname)) attr=sdataattr; if(!strcmp(name,sdata2name)) attr=sdata2attr; if(!strcmp(name,rodataname)) attr=rodataattr; if(!strcmp(name,bssname)) attr=bssattr; if(!strcmp(name,sbssname)) attr=sbssattr; if(!strcmp(name,tocdname)) attr=tocdattr; } new_section(name,attr,1); switch_section(name,attr); eol(s); }
void results_of_competition(){ FILE* f; char str[40]; int results [3]; short int i, max; struct Competitors participant, first, second, third; first.res = -1; second.res = -1; third.res = -1; f = fopen("competition.txt", "r"); while (fgets(str, 40, f) != NULL) { i = parse_name(str, &participant); parse_results(i, str, results); max = -1; for (i = 0; i < 3; ++i){ if (results[i] > max) max = results[i]; } participant.res = max; place_participants(first, third, second, participant); } fclose(f); if (first.res != -1) printf("I место: %s, результат: %d\n", first.name, first.res); if (second.res != -1) printf("II место: %s, результат: %d\n", second.name, second.res); if (third.res != -1) printf("III место: %s, результат: %d\n", third.name, third.res); }
void print_subsys(char* file) { char line[256]; FILE* fp = 0; parse_name(file); fp = fopen(file , "r"); if ( fp != NULL) { while (fgets(line, sizeof(line), fp) != NULL) { if (empty_line(line) == 0) { printf(" "); fputs(line,stdout); } } fclose(fp); } else { printf("Error opening '%s'\n",file); } }
static void GH_verbose(int level, const char *fmt, ...) { static int verbosity=-1; static FILE *output_stream=NULL; static int stream_initialized=0; va_list args; if (verbosity < 0) { verbosity=get_envi("GH_VERBOSE", GH_MSG_LEVEL_DEFAULT); } if (level > verbosity) { return; } if (!stream_initialized) { const char *file=getenv("GH_VERBOSE_FILE"); if (file) { char buf[PATH_MAX]; parse_name(buf, sizeof(buf), file, 0); output_stream=fopen(buf,"a+t"); } if (!output_stream) output_stream=GH_DEFAULT_OUTPUT_STREAM; stream_initialized=1; } fprintf(output_stream,"GH: "); va_start(args, fmt); vfprintf(output_stream, fmt, args); va_end(args); fflush(output_stream); }
/** * Parse name inside of a DNS query or record. * * @param udp_payload entire UDP payload * @param udp_payload_length length of @a udp_payload * @param off pointer to the offset of the name to parse in the udp_payload (to be * incremented by the size of the name) * @return name as 0-terminated C string on success, NULL if the payload is malformed */ char * GNUNET_DNSPARSER_parse_name (const char *udp_payload, size_t udp_payload_length, size_t *off) { return parse_name (udp_payload, udp_payload_length, off, 0); }
void xml_node_t::create_parameter( const std::string& input, std::string::size_type& index ) { // required format: name="value" std::string name_str; if ( ! parse_name( name_str, input, index ) ) return; assert( input[ index ] == '=' ); index++; char quote = input[ index ]; assert( quote == '"' || quote == '\'' ); index++; std::string::size_type start = index; while ( input[ index ] != quote ) { assert( input[ index ] ); index++; } std::string value_str = input.substr( start, index - start ); index++; simplify_xml( value_str ); parameters.push_back( xml_parm_t( name_str, value_str ) ); }
int JSON::parse_array(const char *begin, const char *end, bool withname, std::vector<JSON::Node> *children) { children->clear(); char const *ptr = begin; while (1) { int n; Node node; if (withname) { n = parse_name(ptr, end, &node); if (n > 0) { ptr += n; ptr += scan_space(ptr, end); if (*ptr == ':') { ptr++; } } } n = parse_value(ptr, end, &node); if (node.type != Type::Unknown) { children->push_back(node); } ptr += n; ptr += scan_space(ptr, end); if (ptr < end && *ptr == ',') { ptr++; continue; } return ptr - begin; } }
static blocktype parse_block_type(void) { char new_file_token_str[256]; blocktype block_type; // Parse the file token string as a name. if (!parse_name(file_token_str, new_file_token_str, false)) expected_token("a valid block type"); // Now verify it's a valid block type. if (!stricmp(new_file_token_str, "structural")) block_type = STRUCTURAL_BLOCK; else if (!stricmp(new_file_token_str, "multifaceted sprite")) block_type = MULTIFACETED_SPRITE; else if (!stricmp(new_file_token_str, "angled sprite")) block_type = ANGLED_SPRITE; else if (!stricmp(new_file_token_str, "revolving sprite")) block_type = REVOLVING_SPRITE; else if (!stricmp(new_file_token_str, "facing sprite")) block_type = FACING_SPRITE; else if (!stricmp(new_file_token_str, "player sprite")) block_type = PLAYER_SPRITE; else expected_token("block type 'structural', 'multifaceted sprite', " "'angled sprite', 'revolving sprite', 'facing sprite' or " "'player sprite'"); return(block_type); }
tree xml_html_parser::parse_closing () { s += 2; string name= parse_name (); (void) parse_until (">"); return tuple ("end", name); }
tree xml_html_parser::parse_doctype () { s += 9; tree dt= tuple ("doctype"); skip_space (); dt << parse_name (); skip_space (); if (test (s, "SYSTEM")) dt << parse_system (); else if (test (s, "PUBLIC")) dt << parse_public (); skip_space (); if (test (s, "[")) { s += 1; while (s) { skip_space (); if (test (s, "]")) { s += 1; break; } else if (test (s, "<!ELEMENT")) dt << parse_element (); else if (test (s, "<!ATTLIST")) dt << parse_cdata (); else if (test (s, "<!ENTITY")) parse_entity_decl (); else if (test (s, "<!NOTATION")) a << parse_notation (); else if (test (s, "<?")) dt << parse_pi (); else if (test (s, "<!--")) dt << parse_comment (); else if (s[0] == '&' || s[0] == '%') (void) parse_entity (); else s += 1; } } skip_space (); if (test (s, ">")) s += 1; return dt; }
T FunctionHandlerDDL<T>::operator () (std::vector<std::string> const & args) const { obj_t funcObj = LevelObject::create(); obj_t returnType = LevelObject::create(type_t::type_type(), type_t::type_auto<T>()); funcObj->addObject(name_t::name_return_type, returnType); obj_t argcObj = LevelObject::create(type_t::type_shortint(), int_s_t(args.size())); funcObj->addObject(name_t(key_name_argc()), argcObj); for (size_t index = 0; index < args.size(); ++index) { // TODO: Should make an arg_t for undefined types. obj_t argObj; if (index < _argt.size()) obj_t argObj = LevelObject::create(_argt[index], args[index]); else obj_t argObj = LevelObject::create(type_t::type_string(), string_t(args[index])); name_t argName(parse_name(key_name_arg() + make_string(index))); funcObj->addObject(argName, argObj); } funcObj->addData(_data); obj_t returnValue = funcObj->getObject(name_t::name_return_value); return convert<T, obj_t>(returnValue); }
void reader::implementation::parse_attribute(Attribute& attribute) { parse_name(attribute.name); /*!re2c space* '=' space* { } else { throw_error(); } */ marker = cursor; /*!re2c ["] [^"]* ["] | ['] [^']* ['] { attribute.value = std::string(marker + 1, cursor - 1); return; } else { throw_error(); } */ }
tree xml_html_parser::parse_pi () { s += 2; string name= parse_name (); skip_space (); return tuple ("pi", name, parse_until ("?>")); }
void helper_t<obj_t *>::parse(in_t::ptr_t &ptr, obj_t *&val) { string_t name = parse_name(ptr); obj_t *obj = phantom::obj_find(name); if(!obj) error(ptr, "name not found"); val = obj; }
static void handle_incdir(char *s) { char *name; if (name = parse_name(&s)) new_include_path(name); eol(s); }
static void handle_incbin(char *s) { char *name; if (name = parse_name(&s)) include_binary_file(name,0,0); eol(s); }
static void handle_ident(char *s) { char *name; if(name=parse_name(&s)) setfilename(name); eol(s); }
static void handle_include(char *s) { char *name; if (name = parse_name(&s)) { eol(s); include_source(name); } }
static int parse_line( char* in, M3u_Playlist::entry_t& entry ) { int result = 0; // file entry.file = in; entry.type = ""; in = parse_filename( in, entry ); // track entry.track = -1; entry.decimal_track = 0; in = parse_track( in, entry, &result ); // name entry.name = in; in = parse_name( in ); // time entry.length = -1; in = parse_time( in, &entry.length, &result ); // loop entry.intro = -1; entry.loop = -1; if ( *in == '-' ) { entry.loop = entry.length; in++; } else { in = parse_time_( in, &entry.loop ); if ( entry.loop >= 0 ) { entry.intro = entry.length - entry.loop; if ( *in == '-' ) // trailing '-' means that intro length was specified { in++; entry.intro = entry.loop; entry.loop = entry.length - entry.intro; } } } in = next_field( in, &result ); // fade entry.fade = -1; in = parse_time( in, &entry.fade, &result ); // repeat entry.repeat = -1; in = parse_int( in, &entry.repeat, &result ); return result; }
// Parse a variable declaration in a lambda expression. // // parm-decl ::= identifier ':' expr Tree* parse_parm_decl(Parser& p) { if (Tree* n = parse_name(p)) if (parse::expect(p, colon_tok)) { if (Tree* t = parse_expr(p)) return new Var_tree(n, t); else parse::parse_error(p) << "expected 'expr' after ':'"; } return nullptr; }
// Parse an inititializer. // // init-expr ::= identifier '=' expr Tree* parse_init_expr(Parser& p) { if (Tree* n = parse_name(p)) if (parse::expect(p, equal_tok)) { if (Tree* t = parse_expr(p)) return new Init_tree(n, t); else parse::parse_error(p) << "expected 'expr' after '='"; } return nullptr; }
// Bind a term to a reference // t as id Tree* parse_as(Parser& p, Tree* t1) { if(const Token* t = parse::accept(p, as_tok)) { if(Tree* t2 = parse_name(p)) { return new As_tree(t1, t2); } else parse::parse_error(p) << "expected 'id' after 'as'"; } return nullptr; }
void parse_program_call(){ set_parse_err(programs >= MAX_PROGRAMS,ETOOMANY); parse_name(); ignore_spaces(); argument_number = 1; parse_argument_list(); program_call[programs] .arguments[argument_number] = NULL; }
static int parse_variable(git_config_parser *reader, char **var_name, char **var_value) { const char *value_start = NULL; char *line; int quote_count; bool multiline; git_parse_advance_ws(&reader->ctx); line = git__strndup(reader->ctx.line, reader->ctx.line_len); if (line == NULL) return -1; quote_count = strip_comments(line, 0); /* If there is no value, boolean true is assumed */ *var_value = NULL; if (parse_name(var_name, &value_start, reader, line) < 0) goto on_error; /* * Now, let's try to parse the value */ if (value_start != NULL) { while (git__isspace(value_start[0])) value_start++; if (unescape_line(var_value, &multiline, value_start, 0) < 0) goto on_error; if (multiline) { git_buf multi_value = GIT_BUF_INIT; git_buf_attach(&multi_value, *var_value, 0); if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 || git_buf_oom(&multi_value)) { git_buf_free(&multi_value); goto on_error; } *var_value = git_buf_detach(&multi_value); } } git__free(line); return 0; on_error: git__free(*var_name); git__free(line); return -1; }