errorfile(void) { extern char *tpnam; FILE *fp; ERF *ep; char buf[90],asmb[100]; if(errmsg != NULL) clrerr(); if((fp= fopen(tpnam,"r")) == NULL) return(NG); ep= NULL; while(fgets(buf,90,fp) != NULL) { ep= mgeterr(ep); if(errmsg == NULL) errmsg= ep; crcut(buf); if(lng == ASM) sprintf(asmb,"%s %s",editfile[edfile].filename,buf); else strcpy(asmb,buf); ep->buffer= memgets(asmb); } if(lng != ASM) { if(strstr(errmsg->buffer,editfile[edfile].filename) == NULL) { msg("Illegal errfile <illegal filename>\a"); errbuf= NULL; return(NG); } else errbuf= errmsg->fwd; } else errbuf= errmsg; return(nexterr()); }
int markcut(void) { unsigned char *p, buf[BUFSIZ]; SCRN *op,*lp; int ox, i; extern refr_flg; markcpy(); ox = curposx; lp = markcp; if(lp == line) { for(i = 0;i < mark.posx;++i) buf[i] = lp->buffer[i]; while(lp->buffer[ox]) buf[i++] = lp->buffer[ox++]; buf[i] = '\0'; curposx = mark.posx; update(buf, 0); } else if(lp->num < line->num) { lp->buffer[mark.posx] = '\0'; p = &line->buffer[curposx]; sprintf(buf, "%s%s", lp->buffer, p); line->rev = lp->rev; lp->rev->fwd = line; while(lp != line) { free(lp->buffer); op = lp; lp = lp->fwd; free(op); } free(line->buffer); line->buffer = memgets(buf); curposx = mark.posx; curposy = disset(5); refr_flg = last = OFF; } return(NG); }
othset(struct KEY *kp,char *buf,char *p) { int s,i; unsigned col; s= NG; for(i= 0;i < 3;++i) { if(!stricmp(cc[i],buf)) { copl[i]= memgets(p); return(OK); } } if(!strnicmp(buf,"tabset",6)) { buf += 6; if(*buf < '0' && *buf > '7') return(NG); s= *buf - '0'; if((tabtbl[s]= atoi(p)) == 0) return(NG); return(OK); } else if(!stricmp(buf,"backup")) { if(!strnicmp(p,"on",2) && *(p + 2) <= ' ') back_flg = ON; else if(!strnicmp(p,"off",3) && *(p + 3) <= ' ') back_flg = OFF; else return(NG); return(OK); } else if(!stricmp(buf,"line")) { if((lastdisplay= atoi(p)) < 20) { fprintf(stderr,"Like wow, man. No lines or columns!\n"); exit(1); } return(OK); } else if(!stricmp(buf,"col")) { if((displaylen = atoi(p)) < 40) { fprintf(stderr,"Like wow, man. No columns!\n"); exit(1); } return(OK); } else if(!stricmp(buf,"highdisplay")) { if(!strnicmp(p,"on",2) && *(p + 2) <= ' ') beut_flg = ON; else if(!strnicmp(p,"off",3) && *(p + 3) <= ' ') beut_flg = OFF; else return(NG); return(OK); } #ifdef TEXT98 else if(!stricmp(buf,"bcolor")) { col = atoi(p); if(col > 7 || col == 0) return(NG); rev_col = (col << 5) + 5; return(OK); } else if(!stricmp(buf,"fcolor")) { col = atoi(p); if(col > 7 || col == 0) return(NG); nor_col = (col << 5) + 1; return(OK); } #endif return(NG); }
tool(void) { char buf[BUFSIZ],*p; unsigned short div2(char *,char **); struct KEY kk,*kp; size_t cnt; FILE *fp; int i,sts; keyptr = key; ininame = "keys.ini"; if((fp= fopen(ininame,"r")) == NULL) { /* Curent directory */ if((p= getenv("KEYS")) != NULL) { fp= fopen(p,"r"); /* Env val directory */ } } if(fp == NULL) { #ifndef UNIX _searchenv(ininame,"PATH",buf); #else sprintf(buf,"/usr/local/etc/%s", ininame); #endif if((fp= fopen(buf,"r")) == NULL) return(NG); /* PATH directory */ } if((keyptr = (struct KEY *)calloc(KEYDEFMAX,sizeof(struct KEY))) == NULL) abort(); cnt= 0; while(fgets(buf,BUFSIZ,fp) != NULL) { crcut(buf); if(buf[0] == ';' || buf[0] == '*' || buf[0] == '#') continue; if((kk.code = div2(buf,&p)) == 0xffff) { keyptr = key; break; } kk.keyword = buf; kp = lfind(&kk, key, &key_count,sizeof(struct KEY),cpkey); if(kp == NULL) { if(othset(&kk,buf,p) == NG) { ndprintf("Keyword not found [%s]!\n",buf); if(ynchk("Continue ?") != YES) { #if (defined TEXT98) popscrn(); #elif (defined UNIX) ttclose(); #else batch("///",NULL); #endif exit(1); } } continue; } kk.func = kp->func; kk.helpmsg = kp->helpmsg; if(key_count < KEYDEFMAX) { if(cnt) kp = lfind(&kk, keyptr, &cnt,sizeof(struct KEY), codekey); else kp= NULL; if(kp == NULL) { kk.keyword= memgets(buf); lsearch(&kk, keyptr, &cnt, sizeof(struct KEY), codekey); } } } key_count= cnt; fclose(fp); }
/* Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped), and comments starting with ';' (semicolon). Section is "" if name=value pair parsed before any section heading. name:value pairs are also supported as a concession to Python's ConfigParser. For each name=value pair parsed, call handler function with given user pointer as well as section, name, and value (data only valid for duration of handler call). Handler should return nonzero on success, zero on error. Returns 0 on success, line number of first error on parse error (doesn't stop on first error). */ static int ini_parse(char *filestart, size_t filelen, int (*handler)(void *, char *, char *, char *), void *user) { /* Uses a fair bit of stack (use heap instead if you need to) */ char line[MAX_LINE]; char section[MAX_SECTION] = ""; char prev_name[MAX_NAME] = ""; char *curmem = filestart; char *start; char *end; char *name; char *value; size_t memleft = filelen; int lineno = 0; int error = 0; /* Scan through file line by line */ while (memgets(line, sizeof(line), &curmem, &memleft) != NULL) { lineno++; start = lskip(rstrip(line)); if (*start == ';' || *start == '#') { /* * Per Python ConfigParser, allow '#' comments at start * of line */ } #if CONFIG_INI_ALLOW_MULTILINE else if (*prev_name && *start && start > line) { /* * Non-blank line with leading whitespace, treat as * continuation of previous name's value (as per Python * ConfigParser). */ if (!handler(user, section, prev_name, start) && !error) error = lineno; } #endif else if (*start == '[') { /* A "[section]" line */ end = find_char_or_comment(start + 1, ']'); if (*end == ']') { *end = '\0'; strncpy0(section, start + 1, sizeof(section)); *prev_name = '\0'; } else if (!error) { /* No ']' found on section line */ error = lineno; } } else if (*start && *start != ';') { /* Not a comment, must be a name[=:]value pair */ end = find_char_or_comment(start, '='); if (*end != '=') end = find_char_or_comment(start, ':'); if (*end == '=' || *end == ':') { *end = '\0'; name = rstrip(start); value = lskip(end + 1); end = find_char_or_comment(value, '\0'); if (*end == ';') *end = '\0'; rstrip(value); /* Strip double-quotes */ if (value[0] == '"' && value[strlen(value)-1] == '"') { value[strlen(value)-1] = '\0'; value += 1; } /* * Valid name[=:]value pair found, call handler */ strncpy0(prev_name, name, sizeof(prev_name)); if (!handler(user, section, name, value) && !error) error = lineno; } else if (!error) /* No '=' or ':' found on name[=:]value line */ error = lineno; } } return error; }