From 333b605b2afd472b823aeda0adf0e8b1ea9843c0 Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Mon, 27 May 2019 02:41:51 +0100 Subject: initial commit from asl-1.41r8.tar.gz --- a2k.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 a2k.c (limited to 'a2k.c') diff --git a/a2k.c b/a2k.c new file mode 100644 index 0000000..43685f9 --- /dev/null +++ b/a2k.c @@ -0,0 +1,193 @@ +#include +#include +#include +#include + +/*** valid sym. character */ + +int readline(file,dest) +FILE *file; +char *dest; +{ + char *run=dest; + int zeichen='a'; + + while ((!feof(file))&&(zeichen!=EOF)&&(zeichen!='\n')) + { + zeichen=fgetc(file); + if ((zeichen!=EOF)&&(zeichen!='\n')) *(run++)=zeichen; + } + *run='\0'; + return 0; +} + +int isblankline(line) +char *line; +{ + for (; *line!='\0'; line++) if (!isspace(*line)) return 0; + return 1; +} + +int linestartswidth(line,needle) +char *line; +char *needle; +{ + while (isspace(*line)) line++; + return (strncmp(line,needle,strlen(needle))==0); +} + +#define BUFFERSIZE 10 + +int main(argc, argv) +int argc; +char **argv; +{ + FILE *inpfile,*outfile; + char lines[BUFFERSIZE][500],*p; + char orig[1000],dest[1000],params[1000],single[1000],save; + int BufferFill,start,z,flag; + + if (argc!=3) + { + fprintf(stderr,"usage: %s \n",argv[0]); + exit(1); + } + + if (strcmp(argv[1],"-")==0) inpfile=stdin; + else inpfile=fopen(argv[1],"r"); + if (inpfile==NULL) + { + perror(argv[1]); return 2; + } + + if (strcmp(argv[2],"-")==0) outfile=stdout; + else outfile=fopen(argv[2],"w"); + if (outfile==NULL) + { + perror(argv[2]); return 2; + } + + BufferFill=0; + while (!feof(inpfile)) + { + if (BUFFERSIZE==BufferFill) + { + fprintf(outfile,"%s\n",lines[0]); + for (z=0; z=0; start--) + if (isblankline(lines[start])) break; + else if (*lines[start]=='#') break; + else if (strncmp(lines[start],"/*",2)==0) break; + else if (strcmp(lines[start]+strlen(lines[start])-2,"*/")==0) break; + start++; + + /* found: assemble source lines into a single line */ + + for (z=start,*orig='\0'; z<=BufferFill-2; z++) + { + p=lines[z]; while (isspace(*p)) p++; strcat(orig,p); + if (z!=BufferFill-2) strcat(orig," "); + } + + /* cut function name+prefixes: parameter list starts at first '(' */ + + p=strchr(orig,'('); *p='\0'; + sprintf(dest,"\t%s",orig); strcat(dest,"("); strcpy(orig,p+1); + + /* cut trailing ')' */ + + for (p=orig+strlen(orig)-1; *p!=')'; p--); *p='\0'; + + /* loop through parameters: discard 'void' entries */ + + *params=0; flag=0; + while (*orig!='\0') + { + p=strchr(orig,','); + if (p==NULL) + { + strcpy(single,orig); *orig='\0'; + } + else + { + *p='\0'; strcpy(single,orig); strcpy(orig,p+1); + } + for (p=single; isspace(*p); p++); strcpy(single,p); + for (p=single+strlen(single)-1; isspace(*p); p--); p[1]='\0'; + if (strncmp(single,"const ",6)==0) strcpy(single,single+6); + if (strcmp(single,"void")!=0) + { + strcat(params,single); strcat(params,";\n"); + for (p=single+strlen(single)-1; (isalnum(*p))||(*p=='_'); p--); + if (flag) strcat(dest,","); strcat(dest,p+1); flag=1; + } + } + + /* close function head */ + + strcat(dest,")"); + + /* flush contents berore header from buffer */ + + for (z=0; z