static unsigned char *range(unsigned char *seq, int *vv, int *ww) { unsigned char c; int x, v, w; for (x = 0; seq[x] && seq[x] != ' '; ++x) ; /* Skip to a space */ c = seq[x]; seq[x] = 0; /* Zero terminate the string */ v = keyval(seq); /* Get key */ w = v; if (w < 0) return NULL; seq[x] = c; /* Restore the space or 0 */ for (seq += x; *seq == ' '; ++seq) ; /* Skip over spaces */ /* Check for 'TO ' */ if ((seq[0] == 'T' || seq[0] == 't') && (seq[1] == 'O' || seq[1] == 'o') && seq[2] == ' ') { for (seq += 2; *seq == ' '; ++seq) ; /* Skip over spaces */ for (x = 0; seq[x] && seq[x] != ' '; ++x) ; /* Skip to space */ c = seq[x]; seq[x] = 0; /* Zero terminate the string */ w = keyval(seq); /* Get key */ if (w < 0) return NULL; seq[x] = c; /* Restore the space or 0 */ for (seq += x; *seq == ' '; ++seq) ; /* Skip over spaces */ } if (v > w) return NULL; *vv = v; *ww = w; return seq; }
/* ** Check whether key 'k1' is equal to the key in node 'n2'. ** This equality is raw, so there are no metamethods. Floats ** with integer values have been normalized, so integers cannot ** be equal to floats. It is assumed that 'eqshrstr' is simply ** pointer equality, so that short strings are handled in the ** default case. */ static int equalkey (const TValue *k1, const Node *n2) { if (rawtt(k1) != keytt(n2)) /* not the same variants? */ return 0; /* cannot be same key */ switch (ttypetag(k1)) { case LUA_TNIL: return 1; case LUA_TNUMINT: return (ivalue(k1) == keyival(n2)); case LUA_TNUMFLT: return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2))); case LUA_TBOOLEAN: return bvalue(k1) == bvalueraw(keyval(n2)); case LUA_TLIGHTUSERDATA: return pvalue(k1) == pvalueraw(keyval(n2)); case LUA_TLCF: return fvalue(k1) == fvalueraw(keyval(n2)); case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(k1), keystrval(n2)); default: return gcvalue(k1) == gcvalueraw(keyval(n2)); } }
void conf_parser::parse(){ move(); while (look_.type_ != T_EOF){ switch (look_.type_){ case T_KEY: keyval(); break; case T_COMMENT: comment(); break; default: move(); break; } } };
void QgsAuthMethodConfig::loadConfigString( const QString &configstr ) { clearConfigMap(); if ( configstr.isEmpty() ) { return; } QStringList confs( configstr.split( mConfigSep ) ); Q_FOREACH ( const QString& conf, confs ) { if ( conf.contains( mConfigKeySep ) ) { QStringList keyval( conf.split( mConfigKeySep ) ); setConfig( keyval.at( 0 ), keyval.at( 1 ) ); } } if ( configMap().empty() ) { setConfig( QStringLiteral( "oldconfigstyle" ), configstr ); } }
void QgsAuthMethodConfig::loadConfigString( const QString &configstr ) { clearConfigMap(); if ( configstr.isEmpty() ) { return; } const QStringList confs( configstr.split( CONFIG_SEP ) ); for ( const auto &conf : confs ) { if ( conf.contains( CONFIG_KEY_SEP ) ) { QStringList keyval( conf.split( CONFIG_KEY_SEP ) ); setConfig( keyval.at( 0 ), keyval.at( 1 ) ); } } if ( configMap().empty() ) { setConfig( QStringLiteral( "oldconfigstyle" ), configstr ); } }
static void process_input(char *datafile, hydroparam_t * H) { FILE *fd = NULL; char buffer[1024]; char *pval, *pkey; fd = fopen(datafile, "r"); if (fd == NULL) { fprintf(stderr, "Fichier de donnees illisible\n"); exit(1); } while (fgets(buffer, 1024, fd) == buffer) { keyval(buffer, &pkey, &pval); // int parameters if (strcmp(pkey, "nstepmax") == 0) { sscanf(pval, "%ld", &H->nstepmax); continue; } // The total size of the domain is safed in nxdomain and nydomain if (strcmp(pkey, "nx") == 0) { sscanf(pval, "%ld", &H->nxdomain); continue; } if (strcmp(pkey, "ny") == 0) { sscanf(pval, "%ld", &H->nydomain); continue; } if (strcmp(pkey, "boundary_left") == 0) { sscanf(pval, "%ld", &H->boundary_left); continue; } if (strcmp(pkey, "boundary_right") == 0) { sscanf(pval, "%ld", &H->boundary_right); continue; } if (strcmp(pkey, "boundary_up") == 0) { sscanf(pval, "%ld", &H->boundary_up); continue; } if (strcmp(pkey, "boundary_down") == 0) { sscanf(pval, "%ld", &H->boundary_down); continue; } if (strcmp(pkey, "niter_riemann") == 0) { sscanf(pval, "%ld", &H->niter_riemann); continue; } if (strcmp(pkey, "noutput") == 0) { sscanf(pval, "%ld", &H->noutput); continue; } if (strcmp(pkey, "iorder") == 0) { sscanf(pval, "%ld", &H->iorder); continue; } // float parameters if (strcmp(pkey, "slope_type") == 0) { sscanf(pval, "%lf", &H->slope_type); continue; } if (strcmp(pkey, "tend") == 0) { sscanf(pval, "%lf", &H->tend); continue; } if (strcmp(pkey, "dx") == 0) { sscanf(pval, "%lf", &H->dx); continue; } if (strcmp(pkey, "courant_factor") == 0) { sscanf(pval, "%lf", &H->courant_factor); continue; } if (strcmp(pkey, "smallr") == 0) { sscanf(pval, "%lf", &H->smallr); continue; } if (strcmp(pkey, "smallc") == 0) { sscanf(pval, "%lf", &H->smallc); continue; } if (strcmp(pkey, "dtoutput") == 0) { sscanf(pval, "%lf", &H->dtoutput); continue; } // string parameter if (strcmp(pkey, "scheme") == 0) { if (strcmp(pval, "muscl") == 0) { H->scheme = HSCHEME_MUSCL; } else if (strcmp(pval, "plmde") == 0) { H->scheme = HSCHEME_PLMDE; } else if (strcmp(pval, "collela") == 0) { H->scheme = HSCHEME_COLLELA; } else { fprintf(stderr, "Nom de schema <%s> inconnu, devrait etre l'un de [muscl,plmde,collela]\n", pval); exit(1); } continue; } } fclose(fd); // petit resume de la situation printf("+-------------------+\n"); printf("|nx=%-7ld |\n", H->nx); printf("|ny=%-7ld |\n", H->ny); printf("|tend=%-10.3f |\n", H->tend); printf("|nstepmax=%-7ld |\n", H->nstepmax); printf("|noutput=%-7ld |\n", H->noutput); printf("|dtoutput=%-10.3f|\n", H->dtoutput); printf("+-------------------+\n"); //exit(0); }
/* * For each directory entry on the incremental tape, determine which * category it falls into as follows: * KEEP - entries that are to be left alone. * NEW - new entries to be added. * EXTRACT - files that must be updated with new contents. * LINK - new links to be added. * Renames are done at the same time. */ long nodeupdates(char *name, ino_t ino, int type) { struct entry *ep, *np, *ip; long descend = GOOD; int lookuptype = 0; int key = 0; /* key values */ # define ONTAPE 0x1 /* inode is on the tape */ # define INOFND 0x2 /* inode already exists */ # define NAMEFND 0x4 /* name already exists */ # define MODECHG 0x8 /* mode of inode changed */ /* * This routine is called once for each element in the * directory hierarchy, with a full path name. * The "type" value is incorrectly specified as LEAF for * directories that are not on the dump tape. * * Check to see if the file is on the tape. */ if (TSTINO(ino, dumpmap)) key |= ONTAPE; /* * Check to see if the name exists, and if the name is a link. */ np = lookupname(name); if (np != NULL) { key |= NAMEFND; ip = lookupino(np->e_ino); if (ip == NULL) panic("corrupted symbol table\n"); if (ip != np) lookuptype = LINK; } /* * Check to see if the inode exists, and if one of its links * corresponds to the name (if one was found). */ ip = lookupino(ino); if (ip != NULL) { key |= INOFND; for (ep = ip->e_links; ep != NULL; ep = ep->e_links) { if (ep == np) { ip = ep; break; } } } /* * If both a name and an inode are found, but they do not * correspond to the same file, then both the inode that has * been found and the inode corresponding to the name that * has been found need to be renamed. The current pathname * is the new name for the inode that has been found. Since * all files to be deleted have already been removed, the * named file is either a now unneeded link, or it must live * under a new name in this dump level. If it is a link, it * can be removed. If it is not a link, it is given a * temporary name in anticipation that it will be renamed * when it is later found by inode number. */ if (((key & (INOFND|NAMEFND)) == (INOFND|NAMEFND)) && ip != np) { if (lookuptype == LINK) { removeleaf(np); freeentry(np); } else { dprintf(stdout, "name/inode conflict, mktempname %s\n", myname(np)); mktempname(np); } np = NULL; key &= ~NAMEFND; } if ((key & ONTAPE) && (((key & INOFND) && ip->e_type != type) || ((key & NAMEFND) && np->e_type != type))) key |= MODECHG; /* * Decide on the disposition of the file based on its flags. * Note that we have already handled the case in which * a name and inode are found that correspond to different files. * Thus if both NAMEFND and INOFND are set then ip == np. */ switch (key) { /* * A previously existing file has been found. * Mark it as KEEP so that other links to the inode can be * detected, and so that it will not be reclaimed by the search * for unreferenced names. */ case INOFND|NAMEFND: ip->e_flags |= KEEP; dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ip)); break; /* * A file on the tape has a name which is the same as a name * corresponding to a different file in the previous dump. * Since all files to be deleted have already been removed, * this file is either a now unneeded link, or it must live * under a new name in this dump level. If it is a link, it * can simply be removed. If it is not a link, it is given a * temporary name in anticipation that it will be renamed * when it is later found by inode number (see INOFND case * below). The entry is then treated as a new file. */ case ONTAPE|NAMEFND: case ONTAPE|NAMEFND|MODECHG: if (lookuptype == LINK) { removeleaf(np); freeentry(np); } else { mktempname(np); } /* FALLTHROUGH */ /* * A previously non-existent file. * Add it to the file system, and request its extraction. * If it is a directory, create it immediately. * (Since the name is unused there can be no conflict) */ case ONTAPE: ep = addentry(name, ino, type); if (type == NODE) newnode(ep); ep->e_flags |= NEW|KEEP; dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ep)); break; /* * A file with the same inode number, but a different * name has been found. If the other name has not already * been found (indicated by the KEEP flag, see above) then * this must be a new name for the file, and it is renamed. * If the other name has been found then this must be a * link to the file. Hard links to directories are not * permitted, and are either deleted or converted to * symbolic links. Finally, if the file is on the tape, * a request is made to extract it. */ case ONTAPE|INOFND: if (type == LEAF && (ip->e_flags & KEEP) == 0) ip->e_flags |= EXTRACT; /* FALLTHROUGH */ case INOFND: if ((ip->e_flags & KEEP) == 0) { renameit(myname(ip), name); moveentry(ip, name); ip->e_flags |= KEEP; dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ip)); break; } if (ip->e_type == NODE) { descend = FAIL; fprintf(stderr, "deleted hard link %s to directory %s\n", name, myname(ip)); break; } ep = addentry(name, ino, type|LINK); ep->e_flags |= NEW; dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name, flagvalues(ep)); break; /* * A previously known file which is to be updated. If it is a link, * then all names referring to the previous file must be removed * so that the subset of them that remain can be recreated. */ case ONTAPE|INOFND|NAMEFND: if (lookuptype == LINK) { removeleaf(np); freeentry(np); ep = addentry(name, ino, type|LINK); if (type == NODE) newnode(ep); ep->e_flags |= NEW|KEEP; dprintf(stdout, "[%s] %s: %s|LINK\n", keyval(key), name, flagvalues(ep)); break; } if (type == LEAF && lookuptype != LINK) np->e_flags |= EXTRACT; np->e_flags |= KEEP; dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(np)); break; /* * An inode is being reused in a completely different way. * Normally an extract can simply do an "unlink" followed * by a "creat". Here we must do effectively the same * thing. The complications arise because we cannot really * delete a directory since it may still contain files * that we need to rename, so we delete it from the symbol * table, and put it on the list to be deleted eventually. * Conversely if a directory is to be created, it must be * done immediately, rather than waiting until the * extraction phase. */ case ONTAPE|INOFND|MODECHG: case ONTAPE|INOFND|NAMEFND|MODECHG: if (ip->e_flags & KEEP) { badentry(ip, "cannot KEEP and change modes"); break; } if (ip->e_type == LEAF) { /* changing from leaf to node */ for (ip = lookupino(ino); ip != NULL; ip = ip->e_links) { if (ip->e_type != LEAF) badentry(ip, "NODE and LEAF links to same inode"); removeleaf(ip); freeentry(ip); } ip = addentry(name, ino, type); newnode(ip); } else { /* changing from node to leaf */ if ((ip->e_flags & TMPNAME) == 0) mktempname(ip); deleteino(ip->e_ino); ip->e_next = removelist; removelist = ip; ip = addentry(name, ino, type); } ip->e_flags |= NEW|KEEP; dprintf(stdout, "[%s] %s: %s\n", keyval(key), name, flagvalues(ip)); break; /* * A hard link to a directory that has been removed. * Ignore it. */ case NAMEFND: dprintf(stdout, "[%s] %s: Extraneous name\n", keyval(key), name); descend = FAIL; break; /* * If we find a directory entry for a file that is not on * the tape, then we must have found a file that was created * while the dump was in progress. Since we have no contents * for it, we discard the name knowing that it will be on the * next incremental tape. */ case 0: fprintf(stderr, "%s: (inode %ju) not found on tape\n", name, (uintmax_t)ino); break; /* * If any of these arise, something is grievously wrong with * the current state of the symbol table. */ case INOFND|NAMEFND|MODECHG: case NAMEFND|MODECHG: case INOFND|MODECHG: fprintf(stderr, "[%s] %s: inconsistent state\n", keyval(key), name); break; /* * These states "cannot" arise for any state of the symbol table. */ case ONTAPE|MODECHG: case MODECHG: default: panic("[%s] %s: impossible state\n", keyval(key), name); break; } return (descend); }
static int flt_tile_importhdr(flt_tile_t* self, const char* fname) { assert(self); assert(fname); LOGD("debug fname=%s", fname); FILE* f = fopen(fname, "r"); if(f == NULL) { // skip silently return 0; } const char* key; const char* value; char buffer[256]; int ncols = 0; int nrows = 0; double xllcorner = 0.0; double yllcorner = 0.0; double cellsize = 0.0; float nodata = 0.0f; int byteorder = 0; while(fgets(buffer, 256, f)) { if(keyval(buffer, &key, &value) == 0) { // skip silently continue; } if(strcmp(key, "ncols") == 0) { ncols = (int) strtol(value, NULL, 0); } else if(strcmp(key, "nrows") == 0) { nrows = (int) strtol(value, NULL, 0); } else if(strcmp(key, "xllcorner") == 0) { xllcorner = strtod(value, NULL); } else if(strcmp(key, "yllcorner") == 0) { yllcorner = strtod(value, NULL); } else if(strcmp(key, "cellsize") == 0) { cellsize = strtod(value, NULL); } else if(strcmp(key, "NODATA_value") == 0) { nodata = strtof(value, NULL); } else if(strcmp(key, "byteorder") == 0) { if(strcmp(value, "MSBFIRST") == 0) { byteorder = FLT_MSBFIRST; } else if(strcmp(value, "LSBFIRST") == 0) { byteorder = FLT_LSBFIRST; } } else { LOGW("unknown key=%s, value=%s", key, value); } } fclose(f); // verfy required fields if((ncols == 0) || (nrows == 0) || (cellsize == 0.0) || (byteorder == 0)) { LOGE("invalid nrows=%i, ncols=%i, xllcorner=%0.3lf, yllcorner=%0.3lf, cellsize=%0.6lf, byteorder=%i", nrows, ncols, xllcorner, yllcorner, cellsize, byteorder); return 0; } self->latB = yllcorner; self->lonL = xllcorner; self->latT = yllcorner + (double) ncols*cellsize; self->lonR = xllcorner + (double) nrows*cellsize; self->nodata = nodata; self->byteorder = byteorder; self->nrows = nrows; self->ncols = ncols; return 1; }
static int flt_tile_importprj(flt_tile_t* self, const char* fname) { assert(self); assert(fname); LOGD("debug fname=%s", fname); FILE* f = fopen(fname, "r"); if(f == NULL) { // skip silently return 0; } const char* key; const char* value; char buffer[256]; while(fgets(buffer, 256, f)) { if(keyval(buffer, &key, &value) == 0) { // skip silently continue; } if(strcmp(key, "Projection") == 0) { if(strcmp(value, "GEOGRAPHIC") != 0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Datum") == 0) { if(strcmp(value, "NAD83") != 0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Zunits") == 0) { if(strcmp(value, "METERS") != 0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Units") == 0) { if(strcmp(value, "DD") != 0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Spheroid") == 0) { if(strcmp(value, "GRS1980") != 0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Xshift") == 0) { if(strtod(value, NULL) != 0.0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Yshift") == 0) { if(strtod(value, NULL) != 0.0) { LOGW("%s=%s", key, value); } } else if(strcmp(key, "Parameters") == 0) { // skip } else { LOGW("unknown key=%s, value=%s", key, value); } } fclose(f); return 1; }
static void process_input(char *datafile, hydroparam_t * H) { FILE *fd = NULL; char buffer[1024]; char *pval, *pkey; char *realFmt; if (sizeof(real_t) == sizeof(double)) { realFmt = "%lf"; } else { realFmt = "%f"; } fd = fopen(datafile, "r"); if (fd == NULL) { fprintf(stderr, "can't read input file\n"); exit(1); } while (fgets(buffer, 1024, fd) == buffer) { keyval(buffer, &pkey, &pval); // int parameters if (strcmp(pkey, "nstepmax") == 0) { sscanf(pval, "%d", &H->nstepmax); continue; } if (strcmp(pkey, "prt") == 0) { sscanf(pval, "%d", &H->prt); continue; } if (strcmp(pkey, "nx") == 0) { sscanf(pval, "%d", &H->nx); continue; } if (strcmp(pkey, "ny") == 0) { sscanf(pval, "%d", &H->ny); continue; } if (strcmp(pkey, "nxystep") == 0) { sscanf(pval, "%d", &H->nxystep); continue; } if (strcmp(pkey, "boundary_left") == 0) { sscanf(pval, "%d", &H->boundary_left); continue; } if (strcmp(pkey, "boundary_right") == 0) { sscanf(pval, "%d", &H->boundary_right); continue; } if (strcmp(pkey, "boundary_up") == 0) { sscanf(pval, "%d", &H->boundary_up); continue; } if (strcmp(pkey, "boundary_down") == 0) { sscanf(pval, "%d", &H->boundary_down); continue; } if (strcmp(pkey, "niter_riemann") == 0) { sscanf(pval, "%d", &H->niter_riemann); continue; } if (strcmp(pkey, "noutput") == 0) { sscanf(pval, "%d", &H->noutput); continue; } if (strcmp(pkey, "iorder") == 0) { sscanf(pval, "%d", &H->iorder); continue; } // float parameters if (strcmp(pkey, "slope_type") == 0) { sscanf(pval, realFmt, &H->slope_type); continue; } if (strcmp(pkey, "tend") == 0) { sscanf(pval, realFmt, &H->tend); continue; } if (strcmp(pkey, "dx") == 0) { sscanf(pval, realFmt, &H->dx); continue; } if (strcmp(pkey, "courant_factor") == 0) { sscanf(pval, realFmt, &H->courant_factor); continue; } if (strcmp(pkey, "smallr") == 0) { sscanf(pval, realFmt, &H->smallr); continue; } if (strcmp(pkey, "smallc") == 0) { sscanf(pval, realFmt, &H->smallc); continue; } if (strcmp(pkey, "dtoutput") == 0) { sscanf(pval, realFmt, &H->dtoutput); continue; } if (strcmp(pkey, "testcase") == 0) { sscanf(pval, "%d", &H->testCase); continue; } // string parameter if (strcmp(pkey, "scheme") == 0) { if (strcmp(pval, "muscl") == 0) { H->scheme = HSCHEME_MUSCL; } else if (strcmp(pval, "plmde") == 0) { H->scheme = HSCHEME_PLMDE; } else if (strcmp(pval, "collela") == 0) { H->scheme = HSCHEME_COLLELA; } else { fprintf(stderr, "Scheme name <%s> is unknown, should be one of [muscl,plmde,collela]\n", pval); exit(1); } continue; } } // exit(0); }
void Response::add_header(std::string key,std::string val) { std::pair<std::string,std::string> keyval(key,val); headers.push_back(keyval); }