static int l_L(Void) { int ch, rv, sawdot; if(f__lcount>0) return(0); f__lcount = 1; f__ltype=0; GETC(ch); if(isdigit(ch)) { rd_count(ch); if(GETC(ch)!='*') { if(!f__cf || !feof(f__cf)) { errfl(f__elist->cierr,112,"no star"); } else { err(f__elist->cierr,(EOF),"lread"); } } GETC(ch); } sawdot = 0; if(ch == '.') { sawdot = 1; GETC(ch); } switch(ch) { case 't': case 'T': if (nml_read && Lfinish(ch, sawdot, &rv)) return rv; f__lx=1; break; case 'f': case 'F': if (nml_read && Lfinish(ch, sawdot, &rv)) return rv; f__lx=0; break; default: if(isblnk(ch) || issep(ch) || ch==EOF) { (void) Ungetc(ch,f__cf); return(0); } if (nml_read > 1) { Ungetc(ch,f__cf); f__lquit = 2; return 0; } errfl(f__elist->cierr,112,"logical"); } f__ltype=TYLONG; while(!issep(GETC(ch)) && ch!=EOF); Ungetc(ch, f__cf); return(0); }
void removeSpaces(char *s) { int start, end, i, ind; for(start=0; s[start] != '\0' && issep(s[start]); start++); for(end=strlen(s)-1; end>0 && issep(s[end]); end--); ind = 0; for(i=start; i<=end; i++) s[ind++] = s[i]; s[end+1] = '\0'; }
char * findblank(char *p, int flags) { int instring; instring = 0; while (*p) { if (*p == '\\') { if (flags & PARSE_REDUCE) { memmove(p, p + 1, strlen(p)); if (!*p) break; } else p++; } else if (*p == '"') { memmove(p, p + 1, strlen(p)); instring = !instring; continue; } else if (!instring && (issep(*p) || (*p == '#' && !(flags & PARSE_NOHASH)))) return p; p++; } return instring ? NULL : p; }
int main (int argc, char **argv) { int np; char buf[BUFSZ*PARSZ], **para, *p, *sep; sf_init(argc, argv); if ((sep=sf_getstring("sep"))==NULL) sep=""; /* cmd separater */ para = (char **)sf_alloc(PARSZ, sizeof(char*)); *para = (char *)sf_alloc(PARSZ*BUFSZ, sizeof(char)); for(np=1;np<PARSZ; np++) para[np] = para[np-1] + BUFSZ; vp_init(); p=buf; while(1) { *p=fgetc(stdin); if(issep(*p, sep)) { p = cmdline(buf, p, para); }else if(*p==EOF) { p = cmdline(buf, p, para); break; }else p++; } free(*para); free(para); return 0; }
static char * strip(char *line) { int len; len = strlen(line); while (len && (line[len-1] == '\n' || line[len-1] == '\r' || issep(line[len-1]))) line[--len] = '\0'; while (issep(*line)) line++; if (*line == '#') *line = '\0'; return line; }
int skip_separator(const char *buf, int i, int len) { if (i >= len) return -1; if (issep(buf[i])) i++; else return -1; while (i < len) { if (issep(buf[i])) i++; else break; } return i; }
/********************************************************** * Delete SPACE and TAB from begin and end of the str. * Also delete \r\n at the end of the str. * Final check is the comment line. **********************************************************/ char* trim(char *string) { int len; char * str= string; len = strlen(str); while( len && (str[len-1] == '\n' || str[len-1] == '\r' || issep (str[len-1]) ) ) str[--len] = '\0'; while( issep (*str) ) str++; if (*str == '#') *str = '\0'; return str; }
/*get the fossilInts from comments*/ TypeFossilIntTab getFossilInt(char *str) { int i, ind = 0, sizeBufFossil = INC_FOSSIL_ITEM; char tmp[MAX_NAME_SIZE+1]; TypeFossilIntTab tab; tab.size = 0; if(str == NULL || strlen(str) < 5) { tab.fossilInt = NULL; return tab; } else tab.fossilInt = (TypeTimeInterval*) malloc(sizeBufFossil*sizeof(TypeTimeInterval)); i = 4; while(str[i] != '\0') { for(; str[i] != '\0' && (str[i-4]!=':' || str[i-3]!='F' || str[i-2]!='O' || str[i-1]!='S' || str[i]!='='); i++); if(str[i]=='=') i++; if(str[i] != '\0') { for(; str[i] != '\0' && issep(str[i]); i++); ind = 0; for(; str[i] != '\0' && !issep(str[i]) && ind<MAX_NAME_SIZE; i++) tmp[ind++] = str[i]; tmp[ind++] = '\0'; if(tab.size>=sizeBufFossil) { sizeBufFossil += INC_FOSSIL_ITEM; tab.fossilInt = (TypeTimeInterval*) realloc((void*) tab.fossilInt, sizeBufFossil*sizeof(TypeTimeInterval)); } tab.fossilInt[tab.size++] = toFossilInt(tmp); } } if(tab.size>0) { tab.fossilInt = (TypeTimeInterval*) realloc((void*) tab.fossilInt, tab.size*sizeof(TypeTimeInterval)); for(i=0; i<tab.size; i++) if(tab.fossilInt[i].inf>tab.fossilInt[i].sup) { double tmp = tab.fossilInt[i].inf; tab.fossilInt[i].inf = tab.fossilInt[i].sup; tab.fossilInt[i].sup = tmp; } qsort(tab.fossilInt, tab.size, sizeof(TypeTimeInterval), compareFossilInt); } else { free((void*) tab.fossilInt); tab.fossilInt = NULL; } return tab; }
long Cx_PluginLoader::LoadPluginFiles(const wchar_t* path, const wchar_t* files, HMODULE instance, bool enableDelayLoading) { wchar_t filename[MAX_PATH]; m_instance = instance; MakeFullPath(filename, instance, path); const size_t len0 = wcslen(filename); wchar_t* nameend = filename + len0; std::vector<std::wstring> filenames; size_t i, j; for (i = 0; files[i] != 0; ) { while (issep(files[i])) { i++; } for (j = i; files[j] != 0 && !issep(files[j]); j++) { } if (j > i) { wcsncpy_s(nameend, MAX_PATH - len0, files + i, MAX_PATH - len0 < j - i ? MAX_PATH - len0 : j - i); nameend[j - i] = 0; ReplaceSlashes(filename); if (wcschr(nameend, L'.') == NULL) wcscat_s(filename, MAX_PATH, L".plugin" PLNEXT); filenames.push_back(filename); } i = j; } return InLoadPlugins(filenames, enableDelayLoading); }
static int DecodeCtrlCommand(char *line, char *arg) { const char *end; if (!strncasecmp(line, "include", 7) && issep(line[7])) { end = InterpretArg(line+8, arg); if (*end && *end != '#') log_Printf(LogWARN, "usage: !include filename\n"); else return CTRL_INCLUDE; } return CTRL_UNKNOWN; }
int tfs_getfld (const TFSCAN *tfs, FILE *file, char *buf, int len, int *read) { /* --- read a table field */ int c; /* character read */ int d; /* delimiter type */ char *p; /* to traverse the buffer */ assert(tfs && file && buf && (len >= 0)); p = buf; *p = '\0'; /* clear read buffer */ do { /* --- skip leading blanks */ c = getc(file); /* get next character */ if (c == EOF) return (ferror(file)) ? -1 : TFS_EOF; } while (isblank(c)); /* while character is blank */ if (issep(c)) { /* check for field/record separator */ if (read) *read = 0; /* clear number of characters read */ return (isfldsep(c)) ? TFS_FLD : TFS_REC; } /* return delimiter type */ while (1) { /* --- read value */ if (len >= 0) { /* if buffer is not full, */ len--; *p++ = (char)c; } /* store character in buffer */ c = getc(file); /* get next character */ if (issep(c)) { d = (isfldsep(c)) ? TFS_FLD : TFS_REC; break; } if (c == EOF) { d = (ferror(file)) ? -1 : TFS_EOF; break; } } /* while character is no separator */ while (isblank(*--p)); /* --- remove trailing blanks */ *++p = '\0'; /* terminate string in buffer */ if (read) *read = (int)(p -buf); /* store number of characters read */ if (d != TFS_FLD) return d; /* if not at field separator, abort */ while (isblank(c)) { /* --- skip trailing blanks */ c = getc(file); /* get next character */ if (c == EOF) return (ferror(file)) ? -1 : TFS_EOF; } /* check for end of file */ if (isrecsep(c)) return TFS_REC; /* check for record separator */ if (!isfldsep(c)) ungetc(c, file); /* put back character */ return TFS_FLD; /* return delimiter type */ } /* tfs_getfld() */
Lfinish(int ch, int dot, int *rvp) #endif { char *s, *se; static char what[] = "namelist input"; s = nmLbuf + 2; se = nmLbuf + sizeof(nmLbuf) - 1; *s++ = ch; while(!issep(GETC(ch)) && ch!=EOF) { if (s >= se) { nmLbuf_ovfl: return *rvp = err__fl(f__elist->cierr,131,what); } *s++ = ch; if (ch != '=') continue; if (dot) return *rvp = err__fl(f__elist->cierr,112,what); got_eq: *s = 0; nmL_getc_save = l_getc; l_getc = nmL_getc; nmL_ungetc_save = l_ungetc; l_ungetc = nmL_ungetc; nmLbuf[1] = *(nmL_next = nmLbuf) = ','; *rvp = f__lcount = 0; return 1; } if (dot) goto done; for(;;) { if (s >= se) goto nmLbuf_ovfl; *s++ = ch; if (!isblnk(ch)) break; if (GETC(ch) == EOF) goto done; } if (ch == '=') goto got_eq; done: Ungetc(ch, f__cf); return 0; }
static int DecodeCtrlCommand(char *line, char *arg, size_t argsiz) { const char *end; if (!strncasecmp(line, "include", 7) && issep(line[7])) { end = InterpretArg(line+8, arg, argsiz); if (end == NULL) { log_Printf(LogWARN, "Failed to expand command '%s': too long for the " "destination buffer\n", line); return CTRL_UNKNOWN; } if (*end && *end != '#') log_Printf(LogWARN, "usage: !include filename\n"); else return CTRL_INCLUDE; } return CTRL_UNKNOWN; }
char skipSep(FILE *f, char c) { while(c != EOF && issep(c)) { c = getc(f); } return c; }
/* * Move string from ``from'' to ``to'', interpreting ``~'' and $.... * Returns NULL if string expansion failed due to lack of buffer space. */ const char * InterpretArg(const char *from, char *to, size_t tosiz) { char *ptr, *startto, *endto; struct passwd *pwd; int len, instring; const char *env; instring = 0; startto = to; endto = to + tosiz - 1; while(issep(*from)) from++; while (*from != '\0') { if (to >= endto) return NULL; switch (*from) { case '"': instring = !instring; *to++ = *from++; break; case '\\': switch (*++from) { case '$': case '~': break; /* Swallow the escapes */ default: *to++ = '\\'; /* Pass the escapes on, maybe skipping \# */ break; } if (to >= endto) return NULL; *to++ = *from++; break; case '$': if (from[1] == '$') { *to = '\0'; /* For an empty var name below */ from += 2; } else if (from[1] == '{') { ptr = strchr(from+2, '}'); if (ptr) { len = ptr - from - 2; if (endto - to < len ) return NULL; if (len) { strncpy(to, from+2, len); to[len] = '\0'; from = ptr+1; } else { *to++ = *from++; continue; } } else { *to++ = *from++; continue; } } else { ptr = to; for (from++; (isalnum(*from) || *from == '_') && ptr < endto; from++) *ptr++ = *from; *ptr = '\0'; } if (to >= endto) return NULL; if (*to == '\0') *to++ = '$'; else if ((env = getenv(to)) != NULL) { if (endto - to < strlen(env)) return NULL; strncpy(to, env, endto - to); *endto = '\0'; to += strlen(to); } break; case '~': ptr = strchr(++from, '/'); len = ptr ? ptr - from : strlen(from); if (len == 0) pwd = getpwuid(ID0realuid()); else { if (endto - to < len) return NULL; strncpy(to, from, len); to[len] = '\0'; pwd = getpwnam(to); } if (to >= endto) return NULL; if (pwd == NULL) *to++ = '~'; else { if (endto - to < strlen(pwd->pw_dir)) return NULL; strncpy(to, pwd->pw_dir, endto - to); *endto = '\0'; to += strlen(to); from += len; } endpwent(); break; default: *to++ = *from++; break; } } while (to > startto) { to--; if (!issep(*to)) { to++; break; } } *to = '\0'; return from; }
static int ReadSystem(struct bundle *bundle, const char *name, const char *file, struct prompt *prompt, struct datalink *cx, int how) { FILE *fp; char *cp; int n, len; char line[LINE_LEN]; char filename[PATH_MAX]; int linenum; int argc; char *argv[MAXARGS]; int allowcmd; int indent; char arg[LINE_LEN]; struct prompt *op; if (*file == '/') snprintf(filename, sizeof filename, "%s", file); else snprintf(filename, sizeof filename, "%s/%s", PPP_CONFDIR, file); fp = ID0fopen(filename, "r"); if (fp == NULL) { log_Printf(LogDEBUG, "ReadSystem: Can't open %s.\n", filename); return -2; } log_Printf(LogDEBUG, "ReadSystem: Checking %s (%s).\n", name, filename); linenum = 0; while ((n = xgets(line, sizeof line, fp))) { linenum += n; if (issep(*line)) continue; cp = strip(line); switch (*cp) { case '\0': /* empty/comment */ break; case '!': switch (DecodeCtrlCommand(cp+1, arg, LINE_LEN)) { case CTRL_INCLUDE: log_Printf(LogCOMMAND, "%s: Including \"%s\"\n", filename, arg); n = ReadSystem(bundle, name, arg, prompt, cx, how); log_Printf(LogCOMMAND, "%s: Done include of \"%s\"\n", filename, arg); if (!n) { fclose(fp); return 0; /* got it */ } break; default: log_Printf(LogWARN, "%s: %s: Invalid command\n", filename, cp); break; } break; default: if ((cp = GetLabel(cp, filename, linenum)) == NULL) continue; if (strcmp(cp, name) == 0) { /* We're in business */ if (how == SYSTEM_EXISTS) { fclose(fp); return 0; } while ((n = xgets(line, sizeof line, fp))) { linenum += n; indent = issep(*line); cp = strip(line); if (*cp == '\0') /* empty / comment */ continue; if (!indent) { /* start of next section */ if (*cp != '!' && how == SYSTEM_EXEC) cp = GetLabel(cp, filename, linenum); break; } len = strlen(cp); if ((argc = command_Expand_Interpret(cp, len, argv, cp - line)) < 0) log_Printf(LogWARN, "%s: %d: Syntax error\n", filename, linenum); else { allowcmd = argc > 0 && !strcasecmp(argv[0], "allow"); if ((how != SYSTEM_EXEC && allowcmd) || (how == SYSTEM_EXEC && !allowcmd)) { /* * Disable any context so that warnings are given to everyone, * including syslog. */ op = log_PromptContext; log_PromptContext = NULL; command_Run(bundle, argc, (char const *const *)argv, prompt, name, cx); log_PromptContext = op; } } } fclose(fp); /* everything read - get out */ return 0; } break; } } fclose(fp); return -1; }
/*read partition in Line format*/ TypePartition readPartitionLine(FILE *f, char***name) { char c; TypePartition part; int sizeBufItem = INC_SIZE_ITEM_BUF, index; TypeLexiTree *dict; dict = newLexiTree(); part.sizeAtom = 0; part.sizeItem = 0; part.atom = (int*) malloc(sizeBufItem*sizeof(int)); for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f)); while(c != EOF) { char tmp[MAX_NAME_SIZE+1]; int i; while(c != EOF && !isline(c)) { if(c == '\'' || c == '"') { c = fgetc(f); for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) { tmp[i] = c; c = fgetc(f); } if(c == '\'' || c == '"') c = fgetc(f); else exitProg(ErrorReading, "Missing closing \" or '..."); } else { for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) { tmp[i] = c; c = fgetc(f); } } if(i == MAX_NAME_SIZE) exitProg(ErrorExec, "Name too much long..."); if(i>0) { tmp[i++] = '\0'; //printf("%s\n", tmp); if(findWordLexi(tmp, dict) >= 0) { printf("Duplicate identifier %s(%d)\n", tmp, findWordLexi(tmp, dict)); fprintLexiTree(stdout, dict); exit(1); } index = addWordLexiTree(tmp, dict); if(index>part.sizeItem) part.sizeItem = index; if(index>=sizeBufItem) { sizeBufItem += INC_SIZE_ITEM_BUF; part.atom = (int*) realloc((void*)part.atom, sizeBufItem*sizeof(int)); } part.atom[index] = part.sizeAtom; } for(; c != EOF && issep(c); c = fgetc(f)); } part.sizeAtom++; for(; c != EOF && issepline(c); c = fgetc(f)); } part.sizeItem++; part.atom = (int*) realloc((void*)part.atom, part.sizeItem*sizeof(int)); *name = (char**) malloc(part.sizeItem*sizeof(char*)); fillLexiTree(*name, dict); freeLexiTree(dict); return part; }
/*read partition in Line Number format*/ TypePartition readPartitionNumber(FILE *f) { char c; TypePartition part; int sizeBufItem = INC_SIZE_ITEM_BUF, index; TypeLexiTree *dict; dict = newLexiTree(); part.sizeAtom = 0; part.sizeItem = 0; part.atom = (int*) malloc(sizeBufItem*sizeof(int)); for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f)); while(c != EOF) { char tmp[MAX_NAME_SIZE+1]; int i; while(c != EOF && !isline(c)) { if(c == '\'' || c == '"') { c = fgetc(f); for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) { tmp[i] = c; c = fgetc(f); } if(c == '\'' || c == '"') c = fgetc(f); else exitProg(ErrorReading, "Missing closing \" or '..."); } else { for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issep(c); i++) { tmp[i] = c; c = fgetc(f); } } if(i == MAX_NAME_SIZE) exitProg(ErrorExec, "Name too much long..."); if(i>0) { tmp[i++] = '\0'; index = atoi(tmp); if(index>part.sizeItem) part.sizeItem = index; if(index>=sizeBufItem) { sizeBufItem += INC_SIZE_ITEM_BUF; part.atom = (int*) realloc((void*)part.atom, sizeBufItem*sizeof(int)); } for(; c != EOF && issep(c); c = fgetc(f)); if(c == '\'' || c == '"') { c = fgetc(f); for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) { tmp[i] = c; c = fgetc(f); } if(c == '\'' || c == '"') c = fgetc(f); else exitProg(ErrorReading, "Missing closing \" or '..."); } else { for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) { tmp[i] = c; c = fgetc(f); } } if(i == MAX_NAME_SIZE) exitProg(ErrorExec, "Name too much long..."); if(i>0) { tmp[i++] = '\0'; part.atom[index] = atoi(tmp); if(part.atom[index]>=part.sizeAtom) part.sizeAtom = part.atom[index]+1; } } for(; c != EOF && issep(c); c = fgetc(f)); } for(; c != EOF && issepline(c); c = fgetc(f)); } part.sizeItem++; part.atom = (int*) realloc((void*)part.atom, part.sizeItem*sizeof(int)); return part; }
int ts_next (TABSCAN *tsc, FILE *file, char *buf, int len) { /* --- read the next table field */ int c, d; /* character read, delimiter type */ char *p; /* to traverse the buffer */ assert(tsc && (!buf || (len >= 0))); /* check function argumens */ /* --- initialize --- */ if (!buf) { /* if no buffer given, use internal */ buf = tsc->buf; len = TS_SIZE; } p = buf; *p = '\0'; /* clear the read buffer and */ tsc->cnt = 0; /* the number of characters read */ GETC(c, TS_EOF, file); /* get the first character */ /* --- skip comment records --- */ if (tsc->delim != TS_FLD) { /* if at the start of a record */ while (iscomment(c)) { /* while the record is a comment */ tsc->reccnt++; /* count the record to be read */ while (!isrecsep(c)) /* while not at end of record, */ GETC(c, TS_EOF, file); /* get the next character */ GETC(c, TS_EOF, file); /* get the first character */ } /* after the comment record */ } /* (comment records are skipped) */ /* --- skip leading blanks --- */ while (isblank(c)) /* while character is blank, */ GETC(c, TS_REC, file); /* get the next character */ if (issep(c)) { /* check for field/record separator */ tsc->last = c; /* store the last character read */ if (isfldsep(c)) return tsc->delim = TS_FLD; tsc->reccnt++; return tsc->delim = TS_REC; } /* if at end of record, count reocrd */ /* Note that after at least one valid character was read, even */ /* if it is a blank, the end of file/input is translated into a */ /* record separator. -1 is returned only if no character could */ /* be read before the end of file/input is encountered. */ /* --- read the field --- */ while (1) { /* field read loop */ if (len > 0) { /* if the buffer is not full, */ len--; *p++ = (char)c; } /* store the character in the buffer */ c = getc(file); /* get the next character */ if (issep(c)) { d = (isfldsep(c)) ? TS_FLD : TS_REC; break; } if (c == EOF) { d = (ferror(file)) ? TS_ERR : TS_REC; break; } } /* while character is no separator */ tsc->last = c; /* store the last character read */ /* --- remove trailing blanks --- */ while (isblank(*--p)); /* while character is blank */ *++p = '\0'; /* terminate string in buffer */ tsc->cnt = (int)(p -buf); /* store number of characters read */ /* --- check for a null value --- */ while (--p >= buf) /* check for only null value chars. */ if (!isnull((unsigned char)*p)) break; if (p < buf) { /* clear buffer if null value */ buf[0] = '\0'; tsc->cnt = 0; } /* --- check for end of line --- */ if (d != TS_FLD) { /* if not at a field separator */ if (d == TS_REC) tsc->reccnt++; return tsc->delim = d; /* if at end of record, count record, */ } /* and then abort the function */ /* --- skip trailing blanks --- */ while (isblank(c)) { /* while character is blank, */ tsc->last = c; /* note the last character */ GETC(c, TS_REC, file); /* and get the next character */ } if (isrecsep(c)) { /* check for a record separator */ tsc->reccnt++; tsc->last = c; return tsc->delim = TS_REC; } if (isfldsep(c)) /* note the field separator or */ tsc->last = c; /* put back last character (may be */ else ungetc(c, file); /* necessary if blank = field sep.) */ return tsc->delim = TS_FLD; /* return the delimiter type */ } /* ts_next() */
static int l_CHAR(Void) { int ch,size,i; static char rafail[] = "realloc failure"; char quote,*p; if(f__lcount>0) return(0); f__ltype=0; if(f__lchar!=NULL) free(f__lchar); size=BUFSIZE; p=f__lchar = (char *)malloc((unsigned int)size); if(f__lchar == NULL) errfl(f__elist->cierr,113,"no space"); GETC(ch); if(isdigit(ch)) { /* allow Fortran 8x-style unquoted string... */ /* either find a repetition count or the string */ f__lcount = ch - '0'; *p++ = ch; for(i = 1;;) { switch(GETC(ch)) { case '*': if (f__lcount == 0) { f__lcount = 1; #ifndef F8X_NML_ELIDE_QUOTES if (nml_read) goto no_quote; #endif goto noquote; } p = f__lchar; goto have_lcount; case ',': case ' ': case '\t': case '\n': case '/': Ungetc(ch,f__cf); /* no break */ case EOF: f__lcount = 1; f__ltype = TYCHAR; return *p = 0; } if (!isdigit(ch)) { f__lcount = 1; #ifndef F8X_NML_ELIDE_QUOTES if (nml_read) { no_quote: errfl(f__elist->cierr,112, "undelimited character string"); } #endif goto noquote; } *p++ = ch; f__lcount = 10*f__lcount + ch - '0'; if (++i == size) { f__lchar = (char *)realloc(f__lchar, (unsigned int)(size += BUFSIZE)); if(f__lchar == NULL) errfl(f__elist->cierr,113,rafail); p = f__lchar + i; } } } else (void) Ungetc(ch,f__cf); have_lcount: if(GETC(ch)=='\'' || ch=='"') quote=ch; else if(isblnk(ch) || (issep(ch) && ch != '\n') || ch==EOF) { Ungetc(ch,f__cf); return 0; } #ifndef F8X_NML_ELIDE_QUOTES else if (nml_read > 1) { Ungetc(ch,f__cf); f__lquit = 2; return 0; } #endif else { /* Fortran 8x-style unquoted string */ *p++ = ch; for(i = 1;;) { switch(GETC(ch)) { case ',': case ' ': case '\t': case '\n': case '/': Ungetc(ch,f__cf); /* no break */ case EOF: f__ltype = TYCHAR; return *p = 0; } noquote: *p++ = ch; if (++i == size) { f__lchar = (char *)realloc(f__lchar, (unsigned int)(size += BUFSIZE)); if(f__lchar == NULL) errfl(f__elist->cierr,113,rafail); p = f__lchar + i; } } } f__ltype=TYCHAR; for(i=0;;) { while(GETC(ch)!=quote && ch!='\n' && ch!=EOF && ++i<size) *p++ = ch; if(i==size) { newone: f__lchar= (char *)realloc(f__lchar, (unsigned int)(size += BUFSIZE)); if(f__lchar == NULL) errfl(f__elist->cierr,113,rafail); p=f__lchar+i-1; *p++ = ch; } else if(ch==EOF) return(EOF); else if(ch=='\n') { if(*(p-1) != '\\') continue; i--; p--; if(++i<size) *p++ = ch; else goto newone; } else if(GETC(ch)==quote) { if(++i<size) *p++ = ch; else goto newone; } else { (void) Ungetc(ch,f__cf); *p = 0; return(0); } } }
TypeNameFossilIntTab *readFossilIntTab(FILE *f) { int sizeBuf; char c; TypeNameFossilIntTab *res; res = (TypeNameFossilIntTab *) malloc(sizeof(TypeNameFossilIntTab)); sizeBuf = INC_FOSSIL_ITEM; res->name = (char**) malloc(sizeBuf*sizeof(char*)); res->fossilIntTab = (TypeFossilIntTab*) malloc(sizeBuf*sizeof(TypeFossilIntTab)); res->size = 0; do { char *tmp; int i; tmp = (char*) malloc((MAX_NAME_SIZE+1)*sizeof(char)); for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f)); if(c == '\'' || c == '"') { c = fgetc(f); for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) { tmp[i] = c; c = fgetc(f); } if(c == '\'' || c == '"') c = fgetc(f); } else { for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issep(c); i++) { tmp[i] = c; c = fgetc(f); } } if(i == MAX_NAME_SIZE) exitProg(ErrorExec, "Name too much long..."); tmp[i++] = '\0'; if(i>1) { char bof[MAX_NAME_SIZE+1]; int sizeFossilIntBuf = INC_FOSSIL_ITEM; if(res->size >= sizeBuf) { sizeBuf += INC_FOSSIL_ITEM; res->name = (char**) realloc((void*) res->name, sizeBuf*sizeof(char*)); res->fossilIntTab = (TypeFossilIntTab*) realloc((void*) res->fossilIntTab, sizeBuf*sizeof(TypeFossilIntTab)); } res->name[res->size] = (char *) realloc((void*) tmp, i*sizeof(char)); fixSpace(res->name[res->size]); res->fossilIntTab[res->size].size = 0; res->fossilIntTab[res->size].fossilInt = (TypeTimeInterval*) malloc(sizeFossilIntBuf*sizeof(TypeTimeInterval)); for(; c != EOF && issep(c); c = fgetc(f)); while(c != EOF && !isline(c)) { for(i=0; c != EOF && !issepline(c) && i<MAX_NAME_SIZE; i++) { bof[i] = c; c = fgetc(f); } bof[i++] = '\0'; if(res->fossilIntTab[res->size].size>=sizeFossilIntBuf) { sizeFossilIntBuf += INC_FOSSIL_ITEM; res->fossilIntTab[res->size].fossilInt = (TypeTimeInterval*) realloc((void*) res->fossilIntTab[res->size].fossilInt, sizeFossilIntBuf*sizeof(TypeTimeInterval)); } res->fossilIntTab[res->size].fossilInt[res->fossilIntTab[res->size].size++] = toFossilInt(bof); DEBUG( printf("\"%s\"\t%s\t", tmp, bof); fprintFossilInt(stdout, res->fossilIntTab[res->size].fossilInt[res->fossilIntTab[res->size].size-1]); printf("\n"); ) for(; c != EOF && issep(c); c = fgetc(f)); } res->size++; } else
int trd_read (TABREAD *trd) { /* --- read the next table field */ int c, d; /* character read, delimiter type */ char *p, *e; /* to traverse the field */ /* --- initialize --- */ assert(trd && trd->file); /* check the function arguments */ trd->pos = (trd->delim == TRD_FLD) ? trd->pos+1 : 1; trd->field[trd->len = 0] = 0; /* clear the current field */ GETC(trd, c, TRD_EOF); /* get the first character */ /* --- skip comment records --- */ if (trd->delim != TRD_FLD) { /* if at the start of a record */ while (iscomment(c)) { /* while the record is a comment */ while (!isrecsep(c)) /* while not at end of record, */ GETC(trd, c, TRD_EOF); /* get the next character */ trd->rec++; /* count the comment record */ GETC(trd, c, TRD_EOF); /* get the first character */ } /* after the comment record */ } /* (comment records are skipped) */ /* --- skip leading blanks --- */ while (isblank(c)) /* while the character is blank, */ GETC(trd, c, TRD_REC); /* get the next character */ if (issep(c)) { /* check for field/record separator */ trd->last = c; /* store the last character read */ if (isfldsep(c)) return trd->delim = TRD_FLD; trd->rec++; return trd->delim = TRD_REC; } /* if at end of record, count record */ /* Note that after at least one valid character was read, even */ /* if it is a blank, the end of file/input is translated into a */ /* record separator. EOF is returned only if no character could */ /* be read before the end of file/input is encountered. */ /* --- read the field --- */ p = trd->field; e = p +TRD_MAXLEN; while (1) { /* field read loop */ if (p < e) *p++ = (char)c; /* append the last character */ c = trd_getc(trd); /* and get the next character */ if (c < 0) { d = (c <= TRD_ERR) ? TRD_ERR : TRD_REC; break; } if (issep(c)) { d = (isfldsep(c)) ? TRD_FLD : TRD_REC; break; } } /* while character is no separator */ trd->last = c; /* store the last character read */ /* --- remove trailing blanks --- */ while (isblank(*--p)); /* skip blank characters at the end */ *++p = '\0'; /* and terminate the current field */ trd->len = (size_t)(p -trd->field); /* store number of characters */ /* --- check for a null value --- */ while (--p >= trd->field) /* check for only null value chars. */ if (!isnull((unsigned char)*p)) break; if (p < trd->field) /* clear field if null value */ trd->field[trd->len = 0] = 0; /* --- check for end of line --- */ if (d != TRD_FLD) { /* if not at a field separator */ if (d == TRD_REC) trd->rec++; return trd->delim = d; /* if at end of record, count record, */ } /* and then abort the function */ /* --- skip trailing blanks --- */ while (isblank(c)) { /* while character is blank, */ trd->last = c; /* note the last character */ GETC(trd, c, TRD_REC); /* and get the next character */ } if (isrecsep(c)) { /* check for a record separator */ trd->last = c; trd->rec++; return trd->delim = TRD_REC; } if (isfldsep(c)) /* note the field separator or */ trd->last = c; /* put back last character (may be */ else trd_ungetc(trd, c); /* necessary if blank = field sep.) */ return trd->delim = TRD_FLD; /* return the delimiter type */ } /* trd_read() */
int issepX(char c) { return c == ',' || issep(c); }
TypeOntologyInfo *readOntologyInfo(FILE *f) { char c, first[MAX_NAME_SIZE+1], last[MAX_NAME_SIZE+1], id[MAX_NAME_SIZE+1], name[MAX_NAME_SIZE+1]; int sizeBuffer, indexG, indexA, indexL, n, m, i, j; TypeOntologyInfo *info; info = (TypeOntologyInfo*) malloc(sizeof(TypeOntologyInfo)); sizeBuffer = BASIC_INC_BUFFER_L; info->id = (char**) malloc(sizeBuffer*sizeof(char*)); info->name = (char**) malloc(sizeBuffer*sizeof(char*)); info->size = 0; for(c=getc(f); c!=EOF && issepline(c); c = fgetc(f)); do { for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) { first[i] = c; c = fgetc(f); } first[i] = '\0'; for(; c!=EOF && isline(c); c = fgetc(f)); for(; c!=EOF && issepline(c); c = fgetc(f)); //printf("first %s\n", first); } while(strcmp(first, "[Term]") != 0); while(c != EOF) { id[0] = '\0'; name[0] = '\0'; do { for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) { first[i] = c; c = fgetc(f); } first[i] = '\0'; if(strcmp(first, "id:") == 0) { for(; c!=EOF && issep(c); c = fgetc(f)); for(i=0; i<MAX_NAME_SIZE && c !=EOF && !isline(c); i++) { id[i] = c; c = fgetc(f); } id[i] = '\0'; } if(strcmp(first, "name:") == 0) { for(; c!=EOF && issep(c); c = fgetc(f)); for(i=0; i<MAX_NAME_SIZE && c !=EOF && !isline(c); i++) { name[i] = c; c = fgetc(f); } name[i] = '\0'; } for(; c!=EOF && !isline(c); c = fgetc(f)); for(; c!=EOF && issepline(c); c = fgetc(f)); } while(c != EOF && strcmp(first, "[Term]") != 0); if(id[0] != '\0' && name[0] != '\0') { if(info->size >= sizeBuffer) { sizeBuffer += BASIC_INC_BUFFER_L; info->id = (char**) realloc(info->id, sizeBuffer*sizeof(char*)); info->name = (char**) realloc(info->name, sizeBuffer*sizeof(char*)); } info->id[info->size] = strdup(id); info->name[info->size] = strdup(name); info->size++; } } info->id = (char**) realloc(info->id, info->size*sizeof(char*)); info->name = (char**) realloc(info->name, info->size*sizeof(char*)); return info; }