void LayoutParser::parseLayout() { static const QStringList typeValues(QString::fromLatin1("general,url,email,number,phonenumber,common").split(',')); static const QStringList orientationValues(QString::fromLatin1("landscape,portrait").split(',')); const QXmlStreamAttributes attributes(m_xml.attributes()); const TagLayout::LayoutType type(enumValue("type", typeValues, TagLayout::General)); const TagLayout::LayoutOrientation orientation(enumValue("orientation", orientationValues, TagLayout::Landscape)); const bool uniform_font_size(boolValue(attributes.value(QLatin1String("uniform-font-size")), false)); TagLayoutPtr new_layout(TagLayoutPtr(new TagLayout(type, orientation, uniform_font_size))); m_keyboard->appendLayout(new_layout); bool found_section(false); while (m_xml.readNextStartElement()) { const QStringRef name(m_xml.name()); if (name == QLatin1String("section")) { found_section = true; parseSection(new_layout); } else { error(QString::fromLatin1("Expected '<section>', but got '<%1>'.").arg(name.toString())); } } if (not found_section) { error(QString::fromLatin1("Expected '<section>'.")); } }
std::vector<Section> Config::getSectionList() { int count = getNumValues("project"); std::vector<Section> ret; for(int i = 0; i < count; i++){ std::string filename = getValueStr("project", i); try { std::ifstream in(filename.c_str()); std::string line; while(getline(in, line).good()){ Section sec; if(parseSection(line, sec)){ sec.source = filename; ret.push_back(sec); } } in.close(); } catch (std::ifstream::failure ex){ LOG("could not load file: " << filename, LOG_VERBOSE); } } return ret; }
bool Config::parse(const char* filePath) { std::ifstream file; file.open(filePath); if(!file) { Log(LOG_TYPE::ERROR) << "Can't open config file '" << filePath << "'"; return false; } std::string line; int lineNb = 0; while(std::getline(file, line)) { lineNb++; //find section if(isSection(line)) { if(!parseSection(line, file, lineNb)) { return false; } } //skip comments & empty lines else if(!isComment(line) && !isEmpty(line)) { //otherwise flag line Log(LOG_TYPE::ERROR) << "Config: invalid line at '" << lineNb << "' : " << line; return false; } } file.close(); _parsed = true; _filePath = filePath; return true; }
void parseMeta(MFILE *mfout, const char *toparse) { char *tagend=strchr(toparse, ' '); int taglen=tagend-toparse; fprintf(stderr, "Parsing: %s\n", toparse); if(!strcmp(toparse, "/*")){ commdepth++; return; } if(!strcmp(toparse, "*/")){ commdepth--; if(commdepth<0) pexit("comment to deep - to many '*/' found - exiting\n", ""); return; } if(commdepth>0) return; if(taglen<0) pexit("tag wrong - ' ' expected - exiting\n", toparse); if(!strncasecmp(toparse, "section", strlen("section"))) return parseSection(mfout, tagend+1); if(!strncasecmp(toparse, "param", strlen("param"))) return (void)parseParam(mfout, secakt->list, tagend+1, false); if(!strncasecmp(toparse, "slink", strlen("slink"))) return parseSLink(mfout, tagend+1); }
void GSParser::sstaParser() { u32 size = read<u32>() - 2, readBytes = 0; std::string state = readStringFromTable(); std::cout << "Found state section: " << state << "\n"; while(readBytes != size) { readBytes += parseSection(); } std::cout << "End of state section!\n"; }
void GSParser::parse() { mapParsers(); fileSize = read<u32>(false); while(!reachedEndOfFile()) { parseSection(); } std::cout << "Done!\n"; }
bool DbcParser::parse(CanDb &candb, DbcTokenList &tokens) { _dbcVersion.clear(); _nsEntries.clear(); _buEntries.clear(); while (!tokens.isEmpty()) { if (!parseSection(candb, tokens)) { return false; } } return true; }
static void parseSection (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { FB2Mark *mark; mark = getLink(cur, fb); cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) { parseTitle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"section")) { parseSection(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"poem")) { parsePoem(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"cite")) { parseCite(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) { parseEpigraph(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"p")) { parseP(doc, cur, 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"subtitle")) { int start = fb->utf8_current_index; parseP(doc, cur, 0, fb); addMark(start, fb->utf8_current_index, BOOKMARK_TYPE, NULL, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"empty-line")) { bufferAppend("\n", 1, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) { parseImage(doc, cur, fb); } cur = cur->next; } if (mark) mark->link_end = fb->text_current_index; return; }
bool ProjectParserMixin::parseProjectStatement(const ProjectParseContextSPtr& context, const CommentSPtr& comment) { TokenizerPtr& tokenizer = context->tokenizer; TokenPtr core; if (tokenizer->check(Token::TYPE_IDENTIFIER, "core")) { core = tokenizer->current(); tokenizer->shift(); skipComments(context); } if (tokenizer->check(Token::TYPE_IDENTIFIER, "section")) { SectionSPtr section = parseSection(context, comment); if (section) { context->mProject << section; } } else if (tokenizer->check(Token::TYPE_IDENTIFIER, "package")) { if (!core) { *context <<= errorMessage(context, Message::p_unknownStatment) << Message::Context("package") << Message::Options("core"); } PackageSPtr package = parsePackage(context); if (!core || !package) return false; core.reset(); context->mProject->set_corePackage(package); } else { *context <<= errorMessage(context, Message::p_unknownStatment) << Message::Context("top") << Message::Options("section"); tokenizer->shift(); } return true; }
SpellbookInfo Spellbooks::parseSpellbook(pugi::xml_node& node) { SpellbookInfo curInfo; checkAttribute(node, "offset"); checkAttribute(node, "name"); checkAttribute(node, "gump"); curInfo.packetOffset_ = node.attribute("offset").as_uint(); curInfo.name_ = node.attribute("name").value(); curInfo.gumpName_ = node.attribute("gump").value(); pugi::xml_node sectionIter = node.first_child(); while (sectionIter) { SpellbookSectionInfo curSection = parseSection(sectionIter); for (unsigned int i = 0; i < 8; ++i) { curSection.spells_[i].spellId_ += curInfo.packetOffset_; } curInfo.sections_[curSection.byteIndex_] = curSection; sectionIter = sectionIter.next_sibling(); } return curInfo; }
static void parseBody (xmlDocPtr doc, xmlNodePtr cur, FB2Content *fb) { xmlChar *prop; prop = xmlGetProp(cur, (const xmlChar *)"name"); if (prop) { int start = fb->utf8_current_index; bufferAppend("\n\n", 2, fb); bufferAppend(prop, xmlStrlen(prop), fb); bufferAppend("\n\n", 2, fb); addMark(start, fb->utf8_current_index, BOOKMARK_TYPE, NULL, fb); xmlFree(prop); } cur = cur->children; while (cur != NULL) { if (!xmlStrcmp(cur->name, (const xmlChar *)"section")) { parseSection(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"title")) { parseTitle(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"image")) { parseImage(doc, cur, fb); } else if (!xmlStrcmp(cur->name, (const xmlChar *)"epigraph")) { parseEpigraph(doc, cur, fb); } cur = cur->next; } return; }
int parseResReq(char *resReq, struct resVal *resVal, struct lsInfo *lsInfo, int options) { static char fname[] = "parseResReq()"; int cc; struct sections reqSect; if (logclass & (LC_TRACE | LC_SCHED)) ls_syslog(LOG_DEBUG3, "%s: resReq=%s", fname, resReq); initResVal(resVal); ALLOC_STRING(resVal->selectStr, resVal->selectStrSize, MAX(3*strlen(resReq) + 1, MAXLINELEN + MAXLSFNAMELEN)); if ((cc = parseSection(resReq, &reqSect)) != PARSE_OK) return cc; if ((cc = setDefaults(resVal, lsInfo, options)) < 0) return cc; if (options & PR_SELECT) { if (options & PR_XOR) { if ((cc = parseSelect(reqSect.select, resVal, lsInfo, TRUE, options)) != PARSE_OK) return cc; } else { if ((cc = parseSelect(reqSect.select, resVal, lsInfo, FALSE, options)) != PARSE_OK) return cc; } } if (options & PR_ORDER) { if ((cc = parseOrder(reqSect.order, resVal, lsInfo)) != PARSE_OK) return cc; } if (options & PR_RUSAGE) { if ((cc = parseUsage(reqSect.rusage, resVal, lsInfo)) != PARSE_OK) return cc; } if (options & PR_FILTER) { if ((cc = parseFilter(reqSect.filter, resVal, lsInfo)) != PARSE_OK) return cc; } if (options & PR_SPAN) { if ((cc = parseSpan(reqSect.span, resVal)) != PARSE_OK) return cc; } return(PARSE_OK); }
/* process this command */ static int ProcessCmd(char *cmd, char **args, int narg, int node, int tty) { char tbuf[SZ_LINE]; Finfo finfo, tfinfo; #if HAVE_CFITSIO int xlims[2], ylims[2], bin, got, hdutype, hdunum, ncard; int status=0, tstatus=0; int dims[2]; double cens[2]; char extname[FLEN_CARD]; char *cols[2] = {"X", "Y"}; char *ofile="stdout"; char *section=NULL; char *filter=NULL; char *slice=NULL; char *cardstr=NULL; void *tcens=NULL; fitsfile *ifptr, *ofptr, *tfptr; #endif switch(*cmd){ case 'f': if( !strcmp(cmd, "fitsFile") ){ if( narg ){ if( !(tfinfo=FinfoLookup(args[0])) ){ fprintf(stderr, NOIMAGE, args[0]); return 1; } } else if( !(tfinfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } if( tfinfo->fitsfile ){ if( node ) fprintf(stdout, "fitsFile\r"); fprintf(stdout, "%s %s\n", tfinfo->fname, tfinfo->fitsfile); fflush(stdout); } return 0; } break; break; case 'i': if( !strcmp(cmd, "image") ){ if( !narg ){ fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } /* new image */ if( !(finfo = FinfoNew(args[0])) ){ return 1; } /* make it current */ FinfoSetCurrent(finfo); if( node ) fprintf(stdout, "image\r"); /* return the FITS file name, if possible */ fprintf(stdout, "%s %s\n", finfo->fname, finfo->fitsfile ? finfo->fitsfile : "?"); fflush(stdout); return 0; } else if( !strcmp(cmd, "image_") ){ if( !narg ){ fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } /* new image */ if( !(finfo = FinfoNew(args[0])) ){ return 1; } /* make it current */ FinfoSetCurrent(finfo); /* no output! */ return 0; } else if( !strcmp(cmd, "imsection") ){ #if HAVE_CFITSIO if( !(finfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } if( narg < 2 ){ fprintf(stderr, WRONGARGS2, cmd, 2); return 1; } ifptr = openFITSFile(finfo->fitsfile, READONLY, EXTLIST, &hdutype, &status); if( status ){ fprintf(stderr, "ERROR: can't open FITS file '%s'\n", finfo->fitsfile); return 1; } /* process args */ ofile = args[0]; section = args[1]; if( narg >= 3 && args[2] ){ filter = args[2]; } if( narg >= 4 && args[3] ){ slice = args[3]; } if( !section || !(got = parseSection(ifptr, hdutype, section, xlims, ylims, dims, cens, &bin)) ){ fprintf(stderr, "ERROR: can't parse section for '%s' [%s]\n", finfo->fitsfile, (args && args[0]) ? args[0] : "NONE"); return 1; } /* output image */ fits_create_file(&ofptr, ofile, &status); if( status ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't open output FITS file to section '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } switch(hdutype){ case IMAGE_HDU: /* image: let cfitsio make a section */ if( copyImageSection(ifptr, ofptr, dims, cens, bin, slice, &status) ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't copy image section for '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } break; default: /* table: let jsfitsio create an image section by binning the table */ tfptr = filterTableToImage(ifptr, filter, cols, dims, cens, 1, &status); if( status ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't create image from table for '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } fits_read_key(tfptr, TSTRING, "CTYPE1", tbuf, NULL, &status); if( status == 0 ){ if( strstr(tbuf, "--HPX") || strstr(tbuf, "--hpx") ){ tcens = cens; } } status = 0; /* copy section to new image */ if( copyImageSection(tfptr, ofptr, dims, tcens, bin, NULL, &status) ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't copy image section for '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } tstatus = 0; closeFITSFile(tfptr, &tstatus); break; } if( status ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't create section FITS file for '%s' [%s]\n", finfo->fitsfile, tbuf); closeFITSFile(ofptr, &status); return 1; } // return a json object with info about original data fprintf(stdout, "{\"file\":\"%s\"", finfo->fitsfile); fprintf(stdout, ",\"type\":%d", hdutype); ffghdn(ifptr, &hdunum); fprintf(stdout, ",\"extnum\":%d", hdunum-1); tstatus=0; ffgky(ifptr, TSTRING, "EXTNAME", extname, NULL, &tstatus); if( !tstatus ){ fprintf(stdout, ",\"extname\":\"%s\"", extname); } fprintf(stdout, ",\"hdus\":"); _listhdu(finfo->fitsfile, NULL); tstatus=0; getHeaderToString(ifptr, &cardstr, &ncard, &tstatus); if( cardstr ){ fprintf(stdout, ",\"ncard\":%d",ncard); fprintf(stdout, ",\"cardstr\":\"%s\"",cardstr); free(cardstr); } fprintf(stdout, "}\n"); fflush(stdout); tstatus=0; closeFITSFile(ifptr, &tstatus); tstatus=0; closeFITSFile(ofptr, &tstatus); return 0; #else fprintf(stderr, "ERROR: for section support, build js9helper with cfitsio\n"); return 1; #endif } else if( !strcmp(cmd, "info") ){ if( tty ){ if( !(finfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } /* make sure we have a wcs */ fprintf(stdout, "fname:\t%s\n", finfo->fname); fprintf(stdout, "fits:\t%s\n", finfo->fitsfile?finfo->fitsfile:"N/A"); fflush(stdout); } return 0; } break; case 'l': /* list all images */ if( !strcmp(cmd, "list") ){ FinfoList(stdout); return 0; #if HAVE_CFITSIO } else if( !strcmp(cmd, "listhdus") ){ if( !(finfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } _listhdu(finfo->fitsfile, NULL); fflush(stdout); return 0; #endif } break; case 's': if( !strcmp(cmd, "setDataPath") ){ if( narg ){ setenv("JS9_DATAPATH", args[0], 1); if( node ) fprintf(stdout, "setDataPath\r"); fprintf(stdout, "%s\n", getenv("JS9_DATAPATH")); fflush(stdout); } else { fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } return 0; } break; case 'u': if( !strcmp(cmd, "unimage") ){ if( !narg ){ fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } /* close this image */ FinfoFree(args[0]); return 0; } break; case '#': case '\0': return 0; default: break; } /* if we reached here, we did not recognize the command */ fprintf(stderr, "ERROR: unknown command '%s'\n", cmd); /* return the news */ return 2; }
std::string parseKeyValue(std::stringstream& stream, std::unique_ptr<DataIO::Node>& node, const std::string& key) { // Read the assignment symbol from the stream and remove the whitespace behind it char chr; stream.read(&chr, 1); REMOVE_WHITESPACE_AND_COMMENTS(true) // Check for subsection as value if (stream.peek() == '{') return parseSection(stream, node, key); // Read the value std::string line = trim(readLine(stream)); if (!line.empty()) { // Remove the ';' if it is there if (stream.peek() == ';') stream.read(&chr, 1); // Create a value node to store the value auto valueNode = std::make_unique<DataIO::ValueNode>(); valueNode->value = line; // It might be a list node if ((line.size() >= 2) && (line[0] == '[') && (line.back() == ']')) { valueNode->listNode = true; if (line.size() >= 3) { valueNode->valueList.push_back(""); std::size_t i = 1; while (i < line.size()-1) { if (line[i] == ',') { i++; valueNode->valueList.back() = trim(valueNode->valueList.back()); valueNode->valueList.push_back(""); } else if (line[i] == '"') { valueNode->valueList.back().insert(valueNode->valueList.back().getSize(), line[i]); i++; bool backslash = false; while (i < line.size()-1) { valueNode->valueList.back().insert(valueNode->valueList.back().getSize(), line[i]); if (line[i] == '"' && !backslash) { i++; break; } if (line[i] == '\\' && !backslash) backslash = true; else backslash = false; i++; } } else { valueNode->valueList.back().insert(valueNode->valueList.back().getSize(), line[i]); i++; } } valueNode->valueList.back() = trim(valueNode->valueList.back()); } } node->propertyValuePairs[toLower(key)] = std::move(valueNode); return ""; } else { if (stream.peek() == EOF) return "Found EOF while trying to read a value."; else { chr = stream.peek(); if (chr == '=') return "Found '=' while trying to read a value."; else if (chr == '{') return "Found '{' while trying to read a value."; else return "Found empty value."; } } }
/* process this command */ static int ProcessCmd(char *cmd, char **args, int node, int tty) { int ip=0; char tbuf[SZ_LINE]; Finfo finfo, tfinfo; #if HAVE_CFITSIO int x0, x1, y0, y1, bin; int xcolnum, ycolnum, hdunum, hdutype; int status=0, status2=0; int dims[2]; double cens[2]; char *cols[2] = {"X", "Y"}; char *ofile=NULL; char *omode=NULL; fitsfile *ifptr, *ofptr, *tfptr; #endif switch(*cmd){ case 'f': if( !strcmp(cmd, "fitsFile") ){ if( args && word(args[0], tbuf, &ip) ){ if( !(tfinfo=FinfoLookup(tbuf)) ){ fprintf(stderr, NOIMAGE, tbuf); return 1; } } else if( !(tfinfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } if( tfinfo->fitsfile ){ if( node ) fprintf(stdout, "fitsFile\r"); fprintf(stdout, "%s %s\n", tfinfo->fname, tfinfo->fitsfile); fflush(stdout); } return 0; } break; break; case 'i': if( !strcmp(cmd, "image") ){ if( !args || !word(args[0], tbuf, &ip) ){ fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } /* new image */ if( !(finfo = FinfoNew(tbuf)) ){ fprintf(stderr, NONEW, cmd); return 1; } /* make it current */ FinfoSetCurrent(finfo); if( node ) fprintf(stdout, "image\r"); /* return the FITS file name, if possible */ fprintf(stdout, "%s %s\n", finfo->fname, finfo->fitsfile ? finfo->fitsfile : "?"); fflush(stdout); return 0; } else if( !strcmp(cmd, "image_") ){ if( !args || !word(args[0], tbuf, &ip) ){ fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } /* new image */ if( !(finfo = FinfoNew(tbuf)) ){ fprintf(stderr, NONEW, cmd); return 1; } /* make it current */ FinfoSetCurrent(finfo); /* no output! */ return 0; } else if( !strcmp(cmd, "imsection") ){ #if HAVE_CFITSIO if( !(finfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } ifptr = openFITSFile(finfo->fitsfile, EXTLIST, &hdutype, &status); if( status ){ fprintf(stderr, "ERROR: can't open FITS file '%s'\n", finfo->fitsfile); return 1; } if( !args || !parseSection(args[0], &x0, &x1, &y0, &y1, &bin) ){ fprintf(stderr, "ERROR: can't parse section for '%s' [%s]\n", finfo->fitsfile, (args && args[1]) ? args[1] : "NONE"); return 1; } if( args[1] ){ omode = args[1]; } else { omode = "native"; } ofile = "stdout"; // create image if ifile is an image or omode is not native if( (hdutype == IMAGE_HDU) || strcmp(omode, "native") ){ fits_create_file(&ofptr, ofile, &status); if( status ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't open output FITS file to section '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } switch(hdutype){ case IMAGE_HDU: if( bin != 1 ){ fprintf(stderr, "ERROR: imsection of an image must use bin 1 for '%s'\n", finfo->fitsfile); return 1; } snprintf(tbuf, SZ_LINE-1, "%d:%d,%d:%d", x0, x1, y0, y1); fits_copy_image_section(ifptr, ofptr, tbuf, &status); break; default: dims[0] = x1 - x0 + 1; dims[1] = y1 - y0 + 1; cens[0] = (x0 + x1) / 2; cens[1] = (y0 + y1) / 2; tfptr = filterTableToImage(ifptr, NULL, cols, dims, cens, bin, &status); if( status ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't create image from table for '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } fits_copy_image_section(tfptr, ofptr, "*,*", &status); closeFITSFile(tfptr, &status2); break; } if( status ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't write section FITS file for '%s' [%s]\n", finfo->fitsfile, tbuf); closeFITSFile(ofptr, &status); return 1; } closeFITSFile(ofptr, &status); } else { // extract (native) table snprintf(tbuf, SZ_LINE-1, "x >= %d && x <= %d && y >= %d && y <= %d", x0, x1, y0, y1); // ffselect_table(&ifptr, ofile, tbuf, &status); // copied from cfileio.c/ffselect_table() /* create new empty file to hold copy of the image */ if (ffinit(&ofptr, ofile, &status) > 0) { fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't init section file for '%s' [%s]\n", finfo->fitsfile, tbuf); return 1; } /* save current HDU number in input file */ fits_get_hdu_num(ifptr, &hdunum); /* copy the primary array */ fits_movabs_hdu(ifptr, 1, NULL, &status); if( fits_copy_hdu(ifptr, ofptr, 0, &status) > 0){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't copy primary for section file '%s' [%s]\n", finfo->fitsfile, tbuf); fits_close_file(ofptr, &status); return 1; } /* back to current hdu */ fits_movabs_hdu(ifptr, hdunum, NULL, &status); /* copy all the header keywords from the input to output file */ if (fits_copy_header(ifptr, ofptr, &status) > 0){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't copy header for section file '%s' [%s]\n", finfo->fitsfile, tbuf); fits_close_file(ofptr, &status); return 1; } /* set number of rows = 0 */ /* warning: start of cfitsio black magic */ fits_modify_key_lng(ofptr, "NAXIS2", 0, NULL, &status); (ofptr->Fptr)->numrows = 0; (ofptr->Fptr)->origrows = 0; /* force the header to be scanned */ if (ffrdef(ofptr, &status) > 0){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't rdef for section file '%s' [%s]\n", finfo->fitsfile, tbuf); fits_close_file(ofptr, &status); return 1; } /* warning: end of cfitsio black magic */ /* select filtered rows and write to output file */ if (fits_select_rows(ifptr, ofptr, tbuf, &status) > 0){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't select rows for section file '%s' [%s]\n", finfo->fitsfile, tbuf); fits_close_file(ofptr, &status); return 1; } /* update params for this section */ if( (fits_get_colnum(ofptr, CASEINSEN, "X", &xcolnum, &status) > 0) || (fits_get_colnum(ofptr, CASEINSEN, "Y", &ycolnum, &status) > 0) ){ fits_get_errstatus(status, tbuf); fprintf(stderr, "ERROR: can't find X,Y cols for section file '%s' [%s]\n", finfo->fitsfile, tbuf); fits_close_file(ofptr, &status); return 1; } /* we can ignore errors here */ status = 0; snprintf(tbuf, SZ_LINE-1, "TALEN%d", xcolnum); fits_modify_key_lng(ofptr, tbuf, x1-x0, NULL, &status); status = 0; snprintf(tbuf, SZ_LINE-1, "TALEN%d", ycolnum); fits_modify_key_lng(ofptr, tbuf, y1-y0, NULL, &status); status = 0; snprintf(tbuf, SZ_LINE-1, "TLMIN%d", xcolnum); fits_modify_key_flt(ofptr, tbuf, x0, 6, NULL, &status); status = 0; snprintf(tbuf, SZ_LINE-1, "TLMAX%d", xcolnum); fits_modify_key_flt(ofptr, tbuf, x1, 6, NULL, &status); status = 0; snprintf(tbuf, SZ_LINE-1, "TLMIN%d", ycolnum); fits_modify_key_flt(ofptr, tbuf, y0, 6, NULL, &status); status = 0; snprintf(tbuf, SZ_LINE-1, "TLMAX%d", ycolnum); fits_modify_key_flt(ofptr, tbuf, y1, 6, NULL, &status); /* close the output file */ status = 0; fits_close_file(ofptr, &status); } closeFITSFile(ifptr, &status); return 0; #else fprintf(stderr, "ERROR: for section support, build js9helper with cfitsio\n"); return 1; #endif } else if( !strcmp(cmd, "info") ){ if( tty ){ if( !(finfo=FinfoGetCurrent()) ){ fprintf(stderr, NOFINFO, cmd); return 1; } /* make sure we have a wcs */ fprintf(stdout, "fname:\t%s\n", finfo->fname); fprintf(stdout, "fits:\t%s\n", finfo->fitsfile?finfo->fitsfile:"N/A"); fflush(stdout); } return 0; } break; case 'l': /* list all images */ if( !strcmp(cmd, "list") ){ FinfoList(stdout); return 0; } break; case 's': if( !strcmp(cmd, "setDataPath") ){ if( args && word(args[0], tbuf, &ip) ){ setenv("JS9_DATAPATH", tbuf, 1); if( node ) fprintf(stdout, "setDataPath\r"); fprintf(stdout, "%s\n", getenv("JS9_DATAPATH")); fflush(stdout); } else { fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } return 0; } break; case 'u': if( !strcmp(cmd, "unimage") ){ if( !args || !word(args[0], tbuf, &ip) ){ fprintf(stderr, WRONGARGS, cmd, 1, 0); return 1; } /* close this image */ FinfoFree(tbuf); return 0; } break; case '#': case '\0': return 0; default: break; } /* if we reached here, we did not recognize the command */ fprintf(stderr, "ERROR: unknown command '%s'\n", cmd); /* return the news */ return 2; }
bool Calendar::parseFile( const std::string &fname ) { HANDLE calFile = CreateFile( fname.c_str(), GENERIC_READ, FILE_SHARE_READ, 0, // security OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, 0 ); // template handle if ( calFile == INVALID_HANDLE_VALUE ) { return false; } bool fileComplete = false; std::string buffer; while ( !fileComplete ) { char rdbuffer[ 4096 + 1 ]; DWORD chRead = 0; DWORD chToRead = 4096; bool ReadOK = ReadFile ( calFile, rdbuffer, chToRead, &chRead, 0 ); if ( ReadOK ) { if ( chRead > 0 ) { rdbuffer[ chRead ] = '\0'; buffer += rdbuffer; } else { fileComplete = true; } } else { fileComplete = true; } } CloseHandle( calFile ); std::string buffer2; size_t dtdPos = buffer.find( "<!DOCTYPE" ); if ( dtdPos != std::string::npos ) { buffer2 = buffer.substr( 0, dtdPos ); size_t dtdEndPos = buffer.find( "]>" ); if ( dtdEndPos == std::string::npos ) { return false; } buffer2 += buffer.substr( dtdEndPos + 2, buffer.size() - dtdEndPos - 2 ); } TiXmlBase::SetCondenseWhiteSpace( false ); TiXmlDocument xdoc; const char *loaded = xdoc.Parse( buffer2.c_str() ); if ( !loaded ) { return false; } TiXmlElement *tix = xdoc.RootElement(); if ( !tix || !checkElementName( tix, "calendar" ) ) { return false; } for ( TiXmlElement * e = tix->FirstChildElement(); e; e = e->NextSiblingElement() ) { if ( checkElementName( e, "mult_type" ) ) { if ( !parseMultType( e ) ) { return false; } } else if ( checkElementName( e, "special_rule" ) ) { if ( !parseSpecialRule( e ) ) { return false; } } else if ( checkElementName( e, "section" ) ) { if ( !parseSection( e ) ) { return false; } } else if ( checkElementName( e, "band" ) ) { if ( !parseBand( e ) ) { return false; } } else if ( checkElementName( e, "contest_series" ) ) { if ( !parseContestSeries( e ) ) { return false; } } else if ( checkElementName( e, "contest" ) ) { if ( !parseContest( e ) ) { return false; } } else if ( checkElementName( e, "version" ) ) { version = e->GetText(); } else { std::string eval = e->Value(); continue; } } // Now we have the raw info; we need to go through it and // generate all the individual contest details for logger/adjsql setYear( calendarYear ); for ( std::map<std::string, Contest>::iterator i = contests.begin(); i != contests.end(); i++ ) { int instance = 1; // should be used to add contest sequence when name ends with a # // but we need to have them sorted in dtg order for that to work. instance; // take out the warning that it isn't used // For each contest iterate the time list and the band list for ( std::vector<TimeList>::iterator tl = ( *i ).second.timeList.begin(); tl != ( *i ).second.timeList.end(); tl++ ) { for ( std::vector<MonthList>::iterator ml = ( *tl ).monthList.begin(); ml != ( *tl ).monthList.end(); ml++ ) { for ( std::vector<CalendarBandList>::iterator bl = ( *i ).second.bandList.begin(); bl != ( *i ).second.bandList.end(); bl++ ) { // startDate needs to incorporate the week and day // day 6 week 1 means "first Saturday of the month" // and day 2 week 1 means "first Tuesday of the month". // week 2 day 2 would mean "2nd Tuesday of the month". // day 6+1 is Sunday after Saturday // XMAS cumulatives also have <start_date_list>, but they appear to be the only ones // Is it best to generate a table of 365(6) days, and assign each one month/week/day // And we may need month pointers, so we cna then count days from each // Somewhere, we need to evaluate the year... for now, we preset it int sm = getMonth( ( *ml ).month ); if ( sm == 0 ) { continue; } if ( ( *tl ).startDateList.size() ) { // need to iterate the start dates for ( unsigned int j = 0; j < ( *tl ).startDateList.size(); j++ ) { int istartDate = atoi( ( *tl ).startDateList[ j ].date.c_str() ); if ( istartDate == 0 ) { continue; } IndividualContest ic; std::string desc = trim( ( *i ).second.description ); std::string sdesc = trim( ( *i ).second.shortDescription ); /* // This needs changing once the contests are sorted // as e.g. 70MHz cumulatives are defined in two groups if (desc[desc.size() - 1] == '#') { desc += makeStr(instance++); } */ ic.description = desc; ic.shortDescription = sdesc; ic.bands = ( *bl ).name; try { ic.start = TDateTime( curYear, sm, istartDate ); ic.start += atoi( ( *tl ).startTime.c_str() ) / 2400.0; ic.duration = ( *tl ).duration; ic.finish = ic.start + atof( ic.duration.c_str() ) / 24; std::string timeType = ( *tl ).timeType; if ( timeType == "local" ) { ic.start = localToUTC( ic.start ); ic.finish = localToUTC( ic.finish ); } } catch ( Exception & e ) { ShowMessage( "Exception " + e.Message + " from " + ic.description.c_str() ); } ic.ppKmScoring = ( ( *i ).second.scoring == Contest::perkms ); for ( unsigned int j = 0; j < ( *i ).second.sectionList.size(); j++ ) { std::string n = ( *i ).second.sectionList[ j ].name; if ( !sections[ n ].overall ) { ic.sections += n; ic.sections += ","; } } ic.sections = ic.sections.substr( 0, ic.sections.size() - 1 ); // lose any trailing comma ic.mults = ( *i ).second.mult; for ( unsigned int j = 0; j < ( *i ).second.specialRulesList.size(); j++ ) { ic.specialRules += ( *i ).second.specialRulesList[ j ].name + " "; } ic.power = ( *i ).second.power; ic.reg1band = bands[ ic.bands ].reg1band.c_str(); calendar.push_back( ic ); } } else { // NB - band list overrides time list! // Logic here won't cope with a full calendar, but is OK for VHFCC std::string startWeek; std::string startDay; std::string startTime; std::string timeType; std::string duration; ContestBand &blst = bands[ ( *bl ).name ]; if ( blst.timeList.size() ) { TimeList & b = blst.timeList[ 0 ]; startWeek = b.startWeek; startDay = b.startDay; startTime = b.startTime; duration = b.duration; timeType = b.timeType; } else { startWeek = ( *tl ).startWeek; startDay = ( *tl ).startDay; startTime = ( *tl ).startTime; duration = ( *tl ).duration; timeType = ( *tl ).timeType; } int istartWeek = atoi( startWeek.c_str() ); if ( istartWeek == 0 ) { continue; } int istartDay; if ( startDay == "6+1" ) { istartDay = 6; } else { istartDay = atoi( startDay.c_str() ); if ( istartDay == 0 ) { continue; } } // std::string bstartWeek = (*bl).startWeek; // or iterate its timeList int istartDate = getDate( sm, istartDay, istartWeek ); if ( istartDate == 0 ) { continue; } if ( startDay == "6+1" ) { istartDate++; istartDay++; } IndividualContest ic; std::string desc = trim( ( *i ).second.description ); /* // This needs changing once the contests are sorted // as e.g. 70MHz cumulatives are defined in two groups if (desc[desc.size() - 1] == '#') { desc += makeStr(instance++); } */ ic.description = desc; ic.bands = ( *bl ).name; try { ic.start = TDateTime( curYear, sm, istartDate ); ic.start += atoi( startTime.c_str() ) / 2400.0; ic.duration = duration; ic.finish = ic.start + atof( ic.duration.c_str() ) / 24; if ( timeType == "local" ) { ic.start = localToUTC( ic.start ); ic.finish = localToUTC( ic.finish ); } } catch ( Exception & e ) { ShowMessage( "Exception " + e.Message + " from " + ic.description.c_str() ); } ic.ppKmScoring = ( ( *i ).second.scoring == Contest::perkms ); for ( unsigned int j = 0; j < ( *i ).second.sectionList.size(); j++ ) { std::string n = ( *i ).second.sectionList[ j ].name; if ( !sections[ n ].overall ) { ic.sections += n; ic.sections += ","; } } ic.sections = ic.sections.substr( 0, ic.sections.size() - 1 ); // lose any trailing comma ic.mults = ( *i ).second.mult; for ( unsigned int j = 0; j < ( *i ).second.specialRulesList.size(); j++ ) { ic.specialRules += ( *i ).second.specialRulesList[ j ].name + " "; } ic.power = ( *i ).second.power; ic.reg1band = bands[ ic.bands ].reg1band.c_str(); calendar.push_back( ic ); } } } } } std::sort( calendar.begin(), calendar.end() ); return true; }
bool Config::loadConfig(std::string filename, std::string section, int depth, std::string lastFilename) { if(depth > 255){ LOG("Are you perhaps including two project files from eachother, or is a build configuration directly or indirectly inheriting itself?", LOG_INFO); ThrowEx(ConfigException, "Too many includes or too deep build configuration inheritance (255)."); } std::ifstream in(filename.c_str()); std::istringstream parse; std::string get; int i = 0, lineCount = 0, itemsInsertedCount = 0; bool goodItem = false; ConfigItem item; std::string parsingSection = "default"; if(!in.good()) return false; LOG("Loading project file " << filename, filename != lastFilename ? LOG_VERBOSE : LOG_DEBUG); while( in.good() ){ i=0; item.key = ""; goodItem = false; item.value.clear(); std::getline(in, get); lineCount++; Section sec; // if parseSection parsed a section line, continue with next line if(parseSection(get, sec)){ parsingSection = sec.name; if(sec.name == section && sec.inherits != "") loadConfig(filename, sec.inherits, depth + 1, filename); continue; } // only load data in the currently active section if(parsingSection != section) continue; parse.str(get); while( parse >> get ){ if(get.length() > 0 && get.at(0) == '#') break; if(get.length() > 0 && get.at(0) == '"'){ bool missingQuote = true; bool done = false; get = get.substr(1, get.length()); if(get.at(get.length() - 1) == '"'){ get = get.substr(0, get.length() - 1); done = true; } while(!done && parse.good()){ char c; if((c = parse.get()) == '"'){ missingQuote = false; break; }else{ get.push_back(c); } } AssertEx(!(!done && missingQuote), ConfigException, "Unterminated quotation (\") @ " << filename << ":" << lineCount); } if(i == 0){ item.key = get; }else{ item.value.push_back(get); goodItem = true; } i++; } if(goodItem){ itemsInsertedCount++; for(int x=0; x < (int)item.value.size(); x++){ // overwrite previous value if * is prepended bool overwrite = item.key.at(0) == '*'; item.key = item.key.substr(overwrite ? 1 : 0); AssertEx(!(!setAddValue(overwrite ? C_SET : C_ADD, item.key, item.value.at(x), VAR_PROJECT) && configItems.count(item.key) != 0), ConfigException, "Syntax error in project file @ " << filename << ":" << lineCount); } if(item.key == "include"){ for(std::vector<std::string>::iterator it = item.value.begin(); it != item.value.end(); it++){ AssertEx(loadConfig(*it, "default", depth + 1, filename), ConfigException, "Could not include file: " << *it << " @ " << filename << ":" << lineCount); } } } parse.clear(); } AssertEx(itemsInsertedCount > 0, ConfigException, "Empty configuration for: " << section << " in file: " << filename); return true; }
void LLQueryResponder::queryResult(const char *buf, size_t len) { const char *pos = buf; int qdcount = DNS_HEADER_QDCOUNT(pos); int ancount = DNS_HEADER_ANCOUNT(pos); int nscount = DNS_HEADER_NSCOUNT(pos); int arcount = DNS_HEADER_ARCOUNT(pos); int ret; if (qdcount == 0 || ancount + nscount + arcount == 0) { ret = ARES_ENODATA; goto bail; } pos += NS_HFIXEDSZ; for (int i = 0; i < qdcount; i++) { std::string ignore; size_t enclen; ret = LLAres::expandName(pos, buf, len, i == 0 ? mQuery : ignore, enclen); if (ret != ARES_SUCCESS) { goto bail; } pos += enclen; if (i == 0) { int t = DNS_QUESTION_TYPE(pos); switch (t) { case RES_A: case RES_NS: case RES_CNAME: case RES_PTR: case RES_AAAA: case RES_SRV: mType = (LLResType) t; break; default: LL_INFOS() << "Cannot grok query type " << t << LL_ENDL; ret = ARES_EBADQUERY; goto bail; } } pos += NS_QFIXEDSZ; if (pos > buf + len) { ret = ARES_EBADRESP; goto bail; } } ret = parseSection(buf, len, ancount, pos, mAnswers); if (ret != ARES_SUCCESS) { goto bail; } ret = parseSection(buf, len, nscount, pos, mAuthorities); if (ret != ARES_SUCCESS) { goto bail; } ret = parseSection(buf, len, arcount, pos, mAdditional); bail: mResult = ret; if (mResult == ARES_SUCCESS) { querySuccess(); } else { queryError(mResult); } }
// Ignore semicolon behind closing brace REMOVE_WHITESPACE_AND_COMMENTS(false) if (stream.peek() == ';') stream.read(&chr, 1); REMOVE_WHITESPACE_AND_COMMENTS(false) return ""; } else if (stream.peek() != '{') return "Expected property or nested section name, found '" + std::string(1, stream.peek()) + "' instead."; } REMOVE_WHITESPACE_AND_COMMENTS(true) if (stream.peek() == '{') { std::string error = parseSection(stream, sectionNode, word); if (!error.empty()) return error; } else if (stream.peek() == '=') { std::string error = parseKeyValue(stream, sectionNode, word); if (!error.empty()) return error; } else return "Expected '{' or '=', found '" + std::string(1, stream.peek()) + "' instead."; } return "Found EOF while reading section."; }