home *** CD-ROM | disk | FTP | other *** search
- /******************************************/
- /********** Präprozessor für TXL **********/
- /******** (c) 1991 by Elmar Warken ********/
- /******************************************/
-
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include "interp.h"
-
- extern char *LinePos;
- extern int Steuer;
- extern char ScanBuffer[ZEILENLAENGE];
-
- typedef struct constvar
- {
- char Bez[20];
- long val;
- struct constvar *next;
- } ConstVar;
-
- ConstVar *FirstConst;
-
- void DelList(void)
- {
- ConstVar *w,*v=FirstConst;
- while (v)
- {
- w=v->next;
- free(v);
- v=w;
- }
- FirstConst=NULL;
- }
-
- int FindConst(char *name, long *val)
- {
- ConstVar *v=FirstConst;
- while (v)
- {
- if (strcmp(v->Bez,name)==0)
- { *val=v->val; return(OK); }
- v=v->next;
- }
- return(FALSE);
- }
-
- void SetConst(char *name, long val)
- {
- ConstVar *v=malloc(sizeof(ConstVar));
-
- strcpy(v->Bez,name);
- v->val=val;
- v->next=FirstConst;
- FirstConst=v;
- }
-
- void ScanLine(char *line, int linenumb)
- {
- char *p;
- long val;
- char cname[20];
-
- /** Leerzeichen am Ende und \n abschneiden **/
-
- for (p=line; *p; p++);
- p--;
- if (*p=='\n') *p=0;
- for (; *p==' '; p--);
- p++; *p=0;
-
- LinePos=line;
- SkipChar();
- Scan();
- if (Steuer==ALPHA)
- {
- if (strcmp(ScanBuffer,"label")==0)
- {
- Scan();
- if (Steuer==ALPHA)
- SetConst(ScanBuffer,linenumb+1);
- } else
- if (strcmp(ScanBuffer,"const")==0)
- {
- Scan();
- if (Steuer==ALPHA)
- {
- strcpy(cname,ScanBuffer);
- Scan();
- if (Steuer==ZIFFER)
- SetConst(cname,atol(ScanBuffer));
- }
- }
- }
- }
-
- void Transform(char *line, int linenumb)
- {
- char *p;
- char newline[100];
- char teil[100];
- long val;
-
- /** Leerzeichen am Ende und \n abschneiden **/
-
- for (p=line; *p; p++);
- p--;
- if (*p=='\n') *p=0;
- for (; *p==' '; p--);
- p++; *p=0;
-
- LinePos=line;
- SkipChar();
-
- ltoa(linenumb,newline,10);
- strcat(newline," ");
- if (!*line)
- strcat(newline,"merke");
- else {
- while (Scan()==SCANOK)
- {
- strcpy(teil,ScanBuffer);
- strcat(teil," ");
- if (Steuer==ALPHA)
- {
- if (FindConst(ScanBuffer,&val))
- {
- ltoa(val,teil,10);
- strcat(teil," ");
- }
- }
- else if (Steuer==STRING)
- {
- strcpy(teil,"\"");
- strcat(teil,ScanBuffer);
- strcat(teil,"\" ");
- }
- strcat(newline,teil);
- }
- }
- strcpy(line,newline);
- }
-
- void TransformFile(char *source, char *dest)
- {
- char line[100];
- FILE *f=fopen(source,"rt");
- FILE *g=fopen(dest,"wt");
-
- int i=0;
- while(!feof(f))
- {
- i++;
- fgets(line,100,f);
- ScanLine(line,i);
- }
- rewind(f);
- i=0;
- while(!feof(f))
- {
- i++;
- if (fgets(line,100,f))
- {
- Transform(line,i);
- fputs(line,g);
- fputs("\n",g);
- }
- }
- fclose(f);
- fclose(g);
- DelList();
- return;
- }
-
- int cdummy(void)
- {
- return(OK);
- }