#include #include #include #include #undef DEBUG #define iofail() do { perror(pname); exit(EXIT_FAILURE); } while (0) #define iofailn(e) do { errno=(e); perror(pname); exit(EXIT_FAILURE); } while (0) struct sym { struct sym *succ; char *sym,*val; } *symt; char *pname; #define WHITE(c) ((c)==' '||(c)=='\t') static char *getsym(char *s) { struct sym *sm=symt; #ifdef DEBUG fprintf(stderr,"getsym(\"%s\")\n",s); #endif while (sm) { if (!strcmp(sm->sym,s)) { #ifdef DEBUG fputs("getsym() - OK",stderr); #endif return(sm->val); } sm=sm->succ; } #ifdef DEBUG fputs("getsym() - NOT FOUND",stderr); #endif return(NULL); } static void addsym(char *sym,char *val) { size_t syml; struct sym *sm=malloc(sizeof(*sm)+(syml=strlen(sym)+1)+strlen(val)+1); #ifdef DEBUG fprintf(stderr,"addsym(\"%s\",\"%s\")\n",sym,val); #endif if (!sm) iofail(); sm->succ=symt; symt=sm; strcpy(symt->val=strcpy(symt->sym=(char *)sm+sizeof(*sm),sym)+syml,val); #ifdef DEBUG fputs("addsym() end\n",stderr); #endif } static char *strip(char *s) { char *s2; #ifdef DEBUG fprintf(stderr,"strip(\"%s\")\n",s); #endif while (WHITE(*s)) s++; for (s2=s;*s2;s2++); s2--; while (s2>=s&&WHITE(*s2)) s2--; *(s2+1)='\0'; #ifdef DEBUG fprintf(stderr,"strip()==\"%s\"\n",s); #endif return(s); } static char *quote(char **sp) { char *s=*sp,*s2; while (WHITE(*s)) s++; if (*s++!='"') return(NULL); s2=s; while (*s&&*s!='"') s++; if (!*s) return(NULL); *s++='\0'; *sp=s; return(s2); } int eval(char *s,char *buf,int bs) { #ifdef DEBUG fprintf(stderr,"eval(\"%s\")\n",s); #endif for (;;) { while (*s&&*s!='$'&&bs) bs--,*buf++=*s++; if (!bs) return(0); if (!*s) { *buf++='\0'; #ifdef DEBUG fputs("eval() end\n",stderr); #endif return(1); } if (*++s=='(') { char *smn=++s,*sym; while (*s&&*s!=')') s++; if (!*s) return(0); *s++='\0'; if ((sym=getsym(smn))) { while (*sym&&bs) bs--,*buf++=*sym++; if (!bs) return(0); } } else *buf++='$'; } } int main(int argc,char **argv) { char line[512],outt[sizeof(line)],*s; char *c1,*c2,cn1[512],cn2[sizeof(cn1)]; int lins,run=1,cdpos,proc,i; if ((pname=rindex(*argv,'/'))) pname++; else pname=*argv; puts("\ ##############################################################\n\ ### This file was created automatically by gmk2mk utility. ###\n\ ### PLEASE DON'T EDIT THIS FILE, edit GNUmakefile instead. ###\n\ ##############################################################\n"); while (fgets(line,sizeof(line),stdin)) { if (line[(lins=strlen(line))-1]=='\n') line[--lins]='\0'; strcpy(outt,line); cdpos=1; for (i=0;i