const void *exec_internal_broam( const char *arg, const struct cfgmenu *menu_root, const struct cfgmenu **p_menu, const struct cfgmenu**p_item) { const void *v = NULL; *p_item = find_cfg_item(arg, menu_root, p_menu); if (NULL == *p_item) return v; v = (*p_item)->pvalue; if (v) { // scan for a possible argument to the command while (!IS_SPC(*arg)) ++arg; skip_spc(&arg); // now set the appropriate variable if (is_fixed_string(v)) { strcpy((char *)v, arg); } else if (is_string_item(v)) { strcpy((char *)v, arg); } else if (get_int_item(v)) { if (*arg) *(int*)v = atoi(arg); } else { set_bool((bool*)v, arg); } // write to blackbox.rc or extensions.rc (automatic) Settings_WriteRCSetting(v); } return v; }
int nexttoken(const char **p_out, const char **p_in, const char *delims) { const char *s, *a, *e; char c, q; int delim_spc; delim_spc = NULL == delims || strchr(delims, ' '); for (a = e = s = *p_in, q = 0; 0 != (c = *s);) { ++s; if (0==q) { if ('\"'==c || '\''==c) q = c; else if (IS_SPC(c)) { if (e == a) { a = e = s; continue; } if (delim_spc) break; } if (delims && strchr(delims, c)) break; } else if (c==q) { q=0; } e = s; } while (e > a && IS_SPC(e[-1])) --e; skip_spc(&s); *p_out = a, *p_in = s; return (int)(e - a); }
char *varname(char *s,char *fn) { char *t; int len; t=s=skip_spc(s); if (!isvarchr(*s)) return 0; while (isvarchr(*t)||isdig(*t)) t++; mkstr(s,t,fn); return t; }
const char *get_special_command(const char **p_path, char *buffer, int size) { const char *in, *a, *b; a = strstr(in = *p_path, ">>"); if (NULL == a) return NULL; b = a + 2; skip_spc(&b); while (a > in && IS_SPC(a[-1])) --a; *p_path = extract_string(buffer, in, imin((int)(a-in), size-1)); return b; }
u_char takearg(char *tedname, int lno, char *ss, char **ostr, char **next) { static char ooo[64]; char *tt, *env; char *aa; ss=skip_spc(ss); *next=tt=ss; if (!*ss) return 0; if (isdig(*tt)) { while (isdig(*tt)) tt++; mkstr(ss,*next=tt,*ostr=ooo); return 1; } else if (*tt=='"') { *ostr=parse_Cstr(tedname, lno, tt,next); return 2; } return 0; }
LoadTedrc(char *tedname, int depth, int kdefmapno) { FILE *fp; char ss[8192],ibuf[2048],*tt,*uu,*vv,*ww,*xx; int len,i,j,lno; int hdef[128]; extern int X_inited; KEYDEF *kdef=kdefmap[kdefmapno]; int kdefno=kdefno_m[kdefmapno]; if ((fp=init_tedrc_fname(tedname, depth))==NULL) return 1; if (kdefno && !depth) { for(j=0;j<kdefno;j++) free(kdef[j].cmd); if (!kdefmapno) free_lang(); free(kdef); kdefmap[kdefmapno]=NULL; if (kdefmapno) { free(mode_str_m[kdefmapno]); mode_str_m[kdefmapno]=NULL; } kdef=NULL; } #if 0 printf("-- %d %d %s\n",depth, kdefmapno, ftedrc); #endif if (kdef==NULL) { MAX_KEY_DEF=280; if ((kdef=mmalloc(sizeof(KEYDEF)*MAX_KEY_DEF,"LoadTedrc"))==NULL) exit(1); kdefmap[kdefmapno]=kdef; kdefno_m[kdefmapno]=kdefno=0; } if (!depth) qsort(kmap,kname_no,sizeof(KEYMAP),qcmpxk); tedrcfname=tedname; lno=0; while (!feof(fp)) { int next_l; ss[0]=0; next_l=0; for(;;) { lno++; len=mfgets(ibuf,sizeof(ibuf),fp); if (!len) { next_l=1; break; } if (ibuf[len-1]=='\n') ibuf[--len]=0; if (!len) { next_l=1; break; } while (len && (ibuf[len-1]==' '||ibuf[len-1]==9)) len--; if (!len) { next_l=1; break; } if (ibuf[len-1]=='\\') { ibuf[len-1]=0; strcat(ss,ibuf); } else { strcat(ss,ibuf); break; } } if (next_l) continue; tt=skip_spc(ss); uu=to_spc(tt); vv=skip_spc(uu); *uu=0; if (tt[0]=='#') continue; if (!strcmp(tt,"d")) { ww=to_spc(vv); if (!(*vv)) lper(tedname,lno,"argument expected"); kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode); if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno) free(kdef[i].cmd); xx=skip_spc(ww); kdef[i].cmd=strdup(parse_Cstr(tedname, lno,xx,&uu)); kdef[i].type=0; if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno); continue; } else if (!strcmp(tt,"f")) { ww=to_spc(vv); if (!(*vv)) lper(tedname,lno,"argument expected"); kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode); if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno) free(kdef[i].cmd); xx=skip_spc(ww); if (parse_stmt(tedname, lno,xx,&kdef[i].cmd,&kdef[i].type)) { if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno); } continue; } if (kdefmapno) lper(tedname,lno,"%s for LoadKeyDefInto can accept 'f' and 'd' command only", tedname); if (!strcmp(tt,"s")) { ww=to_spc(vv); xx=skip_spc(ww); *ww=0; for(i=0;i<sizeof(locolor)/sizeof(locolor[0]);i++) if (!strcmp(vv,locolor[i].cname)) break; if (i==sizeof(locolor)/sizeof(locolor[0])) lper(tedname,lno,"Unknown Def color %s",vv); ww=to_spc(xx); *ww=0; strcpy(locolor[i].caddr,xx); } else if (!strcmp(tt,"set")) { ww=to_spc(vv); xx=skip_spc(ww); tt=to_spc(xx); if (!(*ww)) lper(tedname,lno,"argument expected"); *ww=0; for(i=0;i<sizeof(sets)/sizeof(sets[0]);i++) if (!strcmp(sets[i].sname,vv)) break; if (i==sizeof(sets)/sizeof(sets[0])) lper2(tedname,lno,"Unknown set %s",vv); else { *tt=0; *(sets[i].saddr)=atoi(xx); } } else if (!strcmp(tt,"lang") && !depth) { extern char DirectCommentChars[]; int keywcnt=3,LangIdx,ColIdx,AllocN=32,kwidx, MaxKeywordLen=0; char *ff; KW *kw; if (depth) p_err("cannot define 'lang' in include %s", tedname); tt=parse_Cstr(tedname, lno,vv,&uu); i=strlen(tt)+2; if ((vv=mmalloc(i,"LoadTedrc"))==NULL) exit(1); if ((kw=mmalloc(AllocN*sizeof(KW),"LoadTedrc 2"))==NULL) exit(1); LangExt[LangN]=strcat(strcpy(vv,tt)," "); kw[0].coloridx=ColorCnt; strcpy(pc_color[ColorCnt].fg_str,getstr(uu,&vv)); strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu)); uu=skip_spc(uu); DirectCommentChars[LangN]=*uu; kw[1].coloridx=ColorCnt; strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv)); strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu)); kw[2].coloridx=ColorCnt; strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv)); strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu)); for(;;) { if (!*uu) break; strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv)); strcpy(pc_color[ColorCnt].bg_str,getstr(vv,&uu)); uu=skip_spc(uu); ww=tt=parse_Cstr(tedname, lno,uu,&vv); uu=vv; xx=tt+strlen(tt); for(;;) { char *pstr; tt=to_spc(ww); vv=skip_spc(tt); *(tt)=0; if (pstr=strchr(ww,'(')) { kw[keywcnt].arg=strdup(pstr); *pstr=0; } else kw[keywcnt].arg=0; kw[keywcnt].keyword=strdup(ww); if (strlen(ww) > MaxKeywordLen) MaxKeywordLen=strlen(ww); kw[keywcnt].coloridx=ColorCnt; #if 0 printf("%d %d %d %s\n",LangN,keywcnt, ColorCnt, kw[keywcnt].keyword); #endif keywcnt++; if (keywcnt+3>=AllocN) { AllocN+=32; if ((kw=mrealloc(kw,AllocN*sizeof(KW),"LoadTedrc 3"))==NULL) exit(1); } ww=vv; if (ww==xx) break; } ColorCnt++; } qsort(kw+3,keywcnt-3,sizeof(KW), kwcmp); LangKw[LangN]=kw; LangMaxKeywordLen[LangN]=MaxKeywordLen; LangKwN[LangN++]=keywcnt; if (LangN>=MaxLang) { error("Too many languages defined"); error("Remove unused language in tedrc or modify ted.h and recompile"); exit(1); } } else if (!strcmp(tt,"include")) { if (depth > 10) { error("include too many level ??"); continue; } ww=to_spc(vv); xx=skip_spc(ww); if (!(*vv)) lper(tedname,lno,"argument expected"); *ww=0; LoadTedrc(vv,depth+1,kdefmapno); tedrcfname=tedname; } else if (!strcmp(tt,"filebrowser")) { ww=to_spc(vv); xx=skip_spc(ww); if (!(*vv)) lper(tedname,lno,"argument expected"); init_reg_exp(vv); } else if (!strcmp(tt,"fontlist")) { ww=to_spc(vv); xx=skip_spc(ww); if (!(*vv)) lper(tedname,lno,"argument expected"); setFontList(vv); } else if (!strcmp(tt,"LoadKeyDefInto")) { int no; char mstr[16], *p; tt=parse_Cstr(tedname, lno,vv,&uu); if (!(*tt)) lper(tedname,lno,"file name expected"); ww=skip_spc(uu); if (!*ww) lper(tedname,lno,"Bind number expected"); no=*ww-'0'; if (no<=0 || no>=4) lper(tedname,lno,"Bind number must be less than 4 and greater than 0"); if ((p=strchr(tt,'.'))==NULL) { mode_str_m[no]=" "; } else { p++; if (! *p) mode_str_m[no]=strdup(" "); else mode_str_m[no]=strdup(p); } LoadTedrc(tt,0,no); } } fclose(fp); if (!depth) { kdefno=kdefno_m[kdefmapno]; qsort(kdef,kdefno,sizeof(kdef[0]),qcmp); bzero(hdef,sizeof(hdef)); bzero(kdefhash[kdefmapno],128*sizeof(int)); for(i=0;i<kdefno;i++) { j=KEYHASH(kdef[i].kcode[0]); if (hdef[j]) continue; hdef[j]=1; kdefhash[kdefmapno][j]=i; } kdefhash[kdefmapno][127]=kdefno; for(i=126;i>=0;i--) if (!hdef[i]) kdefhash[kdefmapno][i]=kdefhash[kdefmapno][i+1]; ReLoadTed=1; if (X_inited) alloc_pc_colors(); } return 0; }
parse_stmt(char *tedname, int lno, char *ss,char **cmd, u_char *count) { char fn[32], *arg,*tt; char tbuf[1024]; u_short funidx[64],fuid; int typ,cmlen=0,fncnt=0,argtyp,ii; while (*ss) { if (!(ss=varname(ss,fn))) lper(tedname,lno,"func name expected"); for(fuid=0;fuid<funcno;fuid++) if (!strcmp(fn,func[fuid].funname)) break; if (fuid==funcno) { lper2(tedname,lno,"func %s is not defined",fn); return 0; } ss=skip_spc(ss); if (*ss!='(') lper(tedname,lno,"( expected"); ss++; funidx[fncnt++]=cmlen; argtyp=func[fuid].argtype; tbuf[cmlen++]=fuid; switch (argtyp) { case 0: case 4: case 5: case 6: typ=takearg(tedname, lno, ss,&arg,&tt); if (typ!=0) lper(tedname,lno,"No arg is expected"); break; case 1: typ=takearg(tedname, lno, ss,&arg,&tt); if (typ!=1) lper(tedname, lno, tedname,lno,"integer is expected"); tbuf[cmlen++]=atoi(arg); break; case 2: typ=takearg(tedname, lno, ss,&arg,&tt); if (typ!=2) lper(tedname,lno,"String is expected"); strcpy(&tbuf[cmlen],arg); cmlen+=strlen(arg)+1; break; case 3: /* (string,string) */ typ=takearg(tedname, lno,ss,&arg,&tt); if (typ!=2) lper(tedname,lno,"String is expected"); strcpy(&tbuf[cmlen],arg); cmlen+=strlen(arg)+1; tt=skip_spc(tt); if (*tt!=',') lper(tedname,lno,", is expected"); tt++; typ=takearg(tedname, lno,tt,&arg,&tt); if (typ!=2) lper(tedname,lno,"String is expected"); strcpy(&tbuf[cmlen],arg); cmlen+=strlen(arg)+1; break; case 7: /* (string,string,string) */ typ=takearg(tedname, lno,ss,&arg,&tt); if (typ!=2) lper(tedname,lno,"String is expected"); strcpy(&tbuf[cmlen],arg); cmlen+=strlen(arg)+1; tt=skip_spc(tt); if (*tt!=',') lper(tedname,lno,", is expected"); tt++; typ=takearg(tedname, lno,tt,&arg,&tt); if (typ!=2) lper(tedname,lno,"String is expected"); strcpy(&tbuf[cmlen],arg); cmlen+=strlen(arg)+1; tt=skip_spc(tt); if (*tt!=',') lper(tedname,lno,", is expected"); tt++; typ=takearg(tedname, lno,tt,&arg,&tt); if (typ!=2) lper(tedname,lno,"String is expected"); strcpy(&tbuf[cmlen],arg); cmlen+=strlen(arg)+1; break; case 8: /* int int */ typ=takearg(tedname, lno, ss,&arg,&tt); if (typ!=1) lper(tedname, lno, tedname,lno,"integer is expected"); ii=atoi(arg); memcpy(&tbuf[cmlen],&ii,sizeof(int)); cmlen+=sizeof(int); tt=skip_spc(tt); if (*tt!=',') lper(tedname,lno,", is expected"); tt++; ss=skip_spc(tt); typ=takearg(tedname, lno, ss,&arg,&tt); if (typ!=1) lper(tedname, lno, tedname,lno,"integer is expected"); ii=atoi(arg); memcpy(&tbuf[cmlen],&ii,sizeof(int)); cmlen+=sizeof(int); } ss=skip_spc(tt); if (*ss!=')') lper(tedname,lno," ) expected"); ss++; ss=skip_spc(ss); if (*ss==';') ss++; } if ((*cmd=(char *)malloc(cmlen))==NULL) lper(tedname,lno,"malloc err"); *count=fncnt; memcpy(*cmd,tbuf,cmlen); return 1; }