static int processConfig(xmlElement *element, xml2lpc_context *ctx) { xmlNode *cur_node = NULL; for (cur_node = element->children; cur_node; cur_node = cur_node->next) { dumpNode(cur_node, ctx); if (cur_node->type == XML_ELEMENT_NODE && strcmp((const char*)cur_node->name, "section") == 0 ) { processSection((xmlElement*)cur_node, ctx); } } return 0; }
static void processConfig_cb(const char *section, struct __processConfigCtx *ctx) { if(ctx->ret == 0) { xmlNode *node = xmlNewChild(ctx->node, NULL, (const xmlChar *)"section", NULL); xmlAttr *name_attr; if(node == NULL) { lpc2xml_log(ctx->ctx, LPC2XML_ERROR, "Can't create \"section\" element"); ctx->ret = -1; return; } name_attr = xmlSetProp(node, (const xmlChar *)"name", (const xmlChar *)section); if(name_attr == NULL) { lpc2xml_log(ctx->ctx, LPC2XML_ERROR, "Can't create name attribute for \"section\" element"); ctx->ret = -1; return; } ctx->ret = processSection(section, node, ctx->ctx); } }
void IniReader::readFile() { std::fstream fh( m_fileName.c_str(), std::ios::in ); CHECK( fh.is_open(), "INI file '%s' does not exist!", m_fileName.c_str() ); char line[128]; std::string currSection = ""; while( !fh.eof() ) { fh.getline( line, sizeof(line) ); std::string str = line; if ( processComment(str) ) continue; else if ( processSection(str, currSection) ) continue; else if ( processDataRow(str, currSection) ) continue; } fh.close(); }
void FileReaderTXT::nextLine(bool strip) { data = false; section = false; string line = ""; while (line.empty() || line[0] == '#') { if (inputFile->eof()) { endOfFile = true; return; } lineNumber++; getline(*inputFile, line); string::size_type invalidCharPos = 0; // CTRL+Z removing while ((invalidCharPos = line.find(char(26), invalidCharPos)) != line.npos) { line.erase(invalidCharPos, 1); } if (!line.empty() && line[line.size() - 1] == '\r') { line.erase(line.size() - 1); } if (strip) { while (!line.empty() && (line[line.size() - 1] == ' ' || line[line.size() - 1] == '\t')) { line.erase(line.size() - 1); } } } if (line[0] == '[') { processSection(line); } else { processDataLine(line); } }