From 4ca6f60788560b8929c8acda13a4335f8e8f7b91 Mon Sep 17 00:00:00 2001 From: tehKaiN Date: Wed, 7 Apr 2021 17:44:28 +0200 Subject: [PATCH 1/2] made formatting a bit more consistent --- fd2inline.c | 426 ++++++++++++++++++++++++++-------------------------- 1 file changed, 212 insertions(+), 214 deletions(-) diff --git a/fd2inline.c b/fd2inline.c index 0a3995b..42c0920 100644 --- a/fd2inline.c +++ b/fd2inline.c @@ -199,7 +199,7 @@ RegStr(regs reg) } -static INLINE +static INLINE /****************************************************************************** * StrNRBrk @@ -264,7 +264,7 @@ MatchGlob( char* glob, char* str ) return 0; } break; - + case '*': if( *glob == 0 ) { @@ -302,7 +302,7 @@ SkipWSAndComments( const char* ptr ) { while (*ptr && (*ptr==' ' || *ptr=='\t')) ptr++; - if (ptr[0] == '/' && ptr[1] == '*' ) + if (ptr[0] == '/' && ptr[1] == '*' ) { ptr+=2; while (ptr[0] && ! (ptr[-2] == '*' && ptr[-1] == '/') ) @@ -1178,8 +1178,8 @@ fD_parsefd(fdDef* obj, char** comment_ptr, fdFile* infile) if (!NewString(&buf, infile->line)) { - fprintf(stderr, "No mem for line %lu\n", infile->lineno); - fF_SetError(infile, real_error); + fprintf(stderr, "No mem for line %lu\n", infile->lineno); + fF_SetError(infile, real_error); } bpoint=buf; /* so -Wall keeps quiet */ @@ -1187,197 +1187,195 @@ fD_parsefd(fdDef* obj, char** comment_ptr, fdFile* infile) while (parsing!=ready && fF_GetError(infile)==false) { - switch (parsing) - { - case name: - switch (buf[0]) - { - case '#': - if (strncmp("##base", buf, 6)==0) - { - bnext=buf+6; - while (*bnext==' ' || *bnext=='\t' || *bnext=='_') - bnext++; - strcpy(BaseName, bnext); - BaseName[strlen(BaseName)-1]='\0'; - } - else - if (strncmp("##bias", buf, 6)==0) - { - if (!sscanf(buf+6, "%ld", &infile->offset)) - { - fprintf(stderr, "Illegal ##bias in line %lu: %s\n", - infile->lineno, infile->line); - fF_SetError(infile, real_error); - break; /* avoid nodef */ - } - else - { - if (fF_GetOffset(infile)>0) - fF_SetOffset(infile, -fF_GetOffset(infile)); - DBP(fprintf(stderr, "set offset to %ld\n", - fF_GetOffset(infile))); - } - } - else - { - if (strncmp("##private", buf, 9)==0) - fF_SetFlags(infile, fF_GetFlags(infile) | - FD_PRIVATE); - else if (strncmp("##public", buf, 8)==0) - fF_SetFlags(infile, fF_GetFlags(infile) & - ~FD_PRIVATE); - } - /* try again somewhere else */ - fF_SetError(infile, nodef); - break; - - case '*': - { - size_t olen = *comment_ptr ? strlen(*comment_ptr) : 0; - size_t clen = strlen(buf) + 1 + olen; - - *comment_ptr = realloc(*comment_ptr, clen); - - if (olen ==0) { - **comment_ptr = 0; - } - - strcat(*comment_ptr, buf); - DBP(fprintf(stderr, "Comments: %s", *comment_ptr)); - - /* try again somewhere else */ - fF_SetError(infile, nodef); - break; - } - - default: - /* assume a regular line here */ - fD_SetPrivate( obj, - (fF_GetFlags(infile) & FD_PRIVATE) != 0); - parsing=name; /* switch (parsing) */ - for (index=0; buf[index] && buf[index]!='('; index++); - - if (!buf[index]) - { - /* oops, no fd ? */ - fprintf(stderr, "Not an fd, line %lu: %s\n", - infile->lineno, buf /* infile->line */); - fF_SetError(infile, nodef); - } /* maybe next time */ - else - { - buf[index]=0; - - fD_NewName(obj, buf); - fD_SetOffset(obj, fF_GetOffset(infile)); - - bpoint=buf+index+1; - parsing=params; /* continue the loop */ - } - } - break; - - case params: - { - char *bptmp; /* needed for fD_NewParam */ - - /* look for parameters now */ - - for (bnext = bpoint; *bnext && *bnext!=',' && *bnext!=')'; - bnext++); - - if (*bnext) - { - bptmp=bpoint; - - if (*bnext == ')') - { - if (bnext[1] != '(') - { - fprintf(stderr, "Registers expected in line %lu: %s\n", - infile->lineno, infile->line); - fF_SetError(infile, nodef); - } - else - { - parsing=regs; - bpoint=bnext+2; - } - } - else - bpoint = bnext+1; - - /* terminate string and advance to next item */ - - *bnext='\0'; - if (*bptmp) - fD_NewParam(obj, fD_ParamNum(obj), bptmp); - } - else - { - fF_SetError(infile, nodef); - fprintf(stderr, "Param expected in line %lu: %s\n", - infile->lineno, infile->line); - } - break; /* switch parsing */ - } - - case regs: - /* look for parameters now */ - - for (bnext=bpoint; *bnext && *bnext!='/' && *bnext!=',' && - *bnext!=')'; bnext++); - - if (*bnext) - { - if (')'==*bnext) - { - /* wow, we've finished */ - fF_SetOffset(infile, fF_GetOffset(infile)-FUNCTION_GAP); - parsing=ready; - } - *bnext = '\0'; - - bpoint[0]=tolower(bpoint[0]); - - if ((bpoint[0]=='d' || bpoint[0]=='a') && bpoint[1]>='0' && - bpoint[1]<='8' && bnext==bpoint+2) - fD_NewReg(obj, fD_RegNum(obj), - bpoint[1]-'0'+(bpoint[0]=='a'? 8 : 0)); - else - if (bnext!=bpoint) - { - if (!strcasecmp(bpoint, "base")) - { - fD_SetBase(obj,1); - } - else if (!strcasecmp(bpoint, "sysv")) - { - fD_SetCFunction(obj,1); - } - else - { - /* it is when our function is void */ - fprintf(stderr, "Illegal register %s in line %ld\n", - bpoint, infile->lineno); - fF_SetError(infile, nodef); - } - } - bpoint = bnext+1; - } - else - { - fF_SetError(infile, nodef); - fprintf(stderr, "Reg expected in line %lu\n", - infile->lineno); - } - break; /* switch parsing */ - - case ready: - fprintf(stderr, "Internal error, use another compiler.\n"); - break; - } + switch (parsing) + { + case name: + switch (buf[0]) + { + case '#': + if (strncmp("##base", buf, 6)==0) + { + bnext=buf+6; + while (*bnext==' ' || *bnext=='\t' || *bnext=='_') + bnext++; + strcpy(BaseName, bnext); + BaseName[strlen(BaseName)-1]='\0'; + } + else + if (strncmp("##bias", buf, 6)==0) + { + if (!sscanf(buf+6, "%ld", &infile->offset)) + { + fprintf(stderr, "Illegal ##bias in line %lu: %s\n", + infile->lineno, infile->line); + fF_SetError(infile, real_error); + break; /* avoid nodef */ + } + else + { + if (fF_GetOffset(infile)>0) + fF_SetOffset(infile, -fF_GetOffset(infile)); + DBP(fprintf(stderr, "set offset to %ld\n", + fF_GetOffset(infile))); + } + } + else + { + if (strncmp("##private", buf, 9)==0) + fF_SetFlags(infile, fF_GetFlags(infile) | + FD_PRIVATE); + else if (strncmp("##public", buf, 8)==0) + fF_SetFlags(infile, fF_GetFlags(infile) & + ~FD_PRIVATE); + } + /* try again somewhere else */ + fF_SetError(infile, nodef); + break; + + case '*': + { + size_t olen = *comment_ptr ? strlen(*comment_ptr) : 0; + size_t clen = strlen(buf) + 1 + olen; + + *comment_ptr = realloc(*comment_ptr, clen); + + if (olen ==0) { + **comment_ptr = 0; + } + + strcat(*comment_ptr, buf); + DBP(fprintf(stderr, "Comments: %s", *comment_ptr)); + + /* try again somewhere else */ + fF_SetError(infile, nodef); + } + break; + + default: + /* assume a regular line here */ + fD_SetPrivate( obj, + (fF_GetFlags(infile) & FD_PRIVATE) != 0); + parsing=name; /* switch (parsing) */ + for (index=0; buf[index] && buf[index]!='('; index++); + + if (!buf[index]) + { + /* oops, no fd ? */ + fprintf(stderr, "Not an fd, line %lu: %s\n", + infile->lineno, buf /* infile->line */); + fF_SetError(infile, nodef); + } /* maybe next time */ + else + { + buf[index]=0; + + fD_NewName(obj, buf); + fD_SetOffset(obj, fF_GetOffset(infile)); + + bpoint=buf+index+1; + parsing=params; /* continue the loop */ + } + } + break; + + case params: + { + char *bptmp; /* needed for fD_NewParam */ + + /* look for parameters now */ + for (bnext = bpoint; *bnext && *bnext!=',' && *bnext!=')'; + bnext++); + + if (*bnext) + { + bptmp=bpoint; + + if (*bnext == ')') + { + if (bnext[1] != '(') + { + fprintf(stderr, "Registers expected in line %lu: %s\n", + infile->lineno, infile->line); + fF_SetError(infile, nodef); + } + else + { + parsing=regs; + bpoint=bnext+2; + } + } + else + bpoint = bnext+1; + + /* terminate string and advance to next item */ + + *bnext='\0'; + if (*bptmp) + fD_NewParam(obj, fD_ParamNum(obj), bptmp); + } + else + { + fF_SetError(infile, nodef); + fprintf(stderr, "Param expected in line %lu: %s\n", + infile->lineno, infile->line); + } + } + break; /* switch parsing */ + + case regs: + /* look for parameters now */ + for (bnext=bpoint; *bnext && *bnext!='/' && *bnext!=',' && + *bnext!=')'; bnext++); + + if (*bnext) + { + if (')'==*bnext) + { + /* wow, we've finished */ + fF_SetOffset(infile, fF_GetOffset(infile)-FUNCTION_GAP); + parsing=ready; + } + *bnext = '\0'; + + bpoint[0]=tolower(bpoint[0]); + + if ((bpoint[0]=='d' || bpoint[0]=='a') && bpoint[1]>='0' && + bpoint[1]<='8' && bnext==bpoint+2) + fD_NewReg(obj, fD_RegNum(obj), + bpoint[1]-'0'+(bpoint[0]=='a'? 8 : 0)); + else + if (bnext!=bpoint) + { + if (!strcasecmp(bpoint, "base")) + { + fD_SetBase(obj,1); + } + else if (!strcasecmp(bpoint, "sysv")) + { + fD_SetCFunction(obj,1); + } + else + { + /* it is when our function is void */ + fprintf(stderr, "Illegal register %s in line %ld\n", + bpoint, infile->lineno); + fF_SetError(infile, nodef); + } + } + bpoint = bnext+1; + } + else + { + fF_SetError(infile, nodef); + fprintf(stderr, "Reg expected in line %lu\n", + infile->lineno); + } + break; /* switch parsing */ + + case ready: + fprintf(stderr, "Internal error, use another compiler.\n"); + break; + } } free(buf); @@ -1543,7 +1541,7 @@ getvarargsfunction(const fdDef * obj) { unsigned int count; const char *name = fD_GetName(obj); - + for (count=0; count0) { for (count=d0; count0) { for (count=d0; count0) { for (count=d0; count\n"); - + free(buffer); } - + fclose(clib); } From 9c3c0507e3b89c203b5383f9a0133d11aef0c002 Mon Sep 17 00:00:00 2001 From: KaiN Date: Fri, 16 Apr 2021 17:17:43 +0200 Subject: [PATCH 2/2] fixed getting library name for identify.library, cybergraphics.library --- fd2inline.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/fd2inline.c b/fd2inline.c index 42c0920..daaee62 100644 --- a/fd2inline.c +++ b/fd2inline.c @@ -57,7 +57,10 @@ typedef enum { false, nodef, real_error } Error; static int Quiet = 0; -static char BaseName[64], BaseNamU[64], BaseNamL[64], BaseNamC[64]; +static char BaseName[64]; +static char BaseNamU[64]; // library base name, all chars are uppercase +static char BaseNamL[64]; // library base name as read from .fd +static char BaseNamC[64]; // library base name, first char is uppercase static char Buffer[512]; static const char *LibExcTable[]= @@ -1193,9 +1196,9 @@ fD_parsefd(fdDef* obj, char** comment_ptr, fdFile* infile) switch (buf[0]) { case '#': - if (strncmp("##base", buf, 6)==0) + if (strncmp("##base", buf, strlen("##base"))==0) { - bnext=buf+6; + bnext=buf + strlen("##base"); while (*bnext==' ' || *bnext=='\t' || *bnext=='_') bnext++; strcpy(BaseName, bnext); @@ -2198,24 +2201,37 @@ main(int argc, char** argv) fF_dtor(myfile); if (strlen(fdfilename)>7 && - !strcmp(fdfilename+strlen(fdfilename)-7, "_lib.fd")) + !strcmp(fdfilename+strlen(fdfilename)-7, "_lib.fd")) { - char *str=fdfilename+strlen(fdfilename)-8; + // Extract .library name directly from .fd file name + // e.g. muimaster_lib.fd -> extracts "muimaster" + char *str=fdfilename+strlen(fdfilename) - strlen("_lib.fd"); while (str!=fdfilename && str[-1]!='/' && str[-1]!=':') - str--; -//lcs strncpy(BaseNamL, str, strlen(str)-7); - strncpy(BaseNamU, str, strlen(str)-7); + str--; + strncpy(BaseNamU, str, strlen(str) - strlen("_lib.fd")); BaseNamU[strlen(str)-7]='\0'; strcpy(BaseNamL, BaseNamU); strcpy(BaseNamC, BaseNamU); } else { - strcpy(BaseNamU, BaseName); - if (strlen(BaseNamU)>4 && strcmp(BaseNamU+strlen(BaseNamU)-4, "Base")==0) - BaseNamU[strlen(BaseNamU)-4]='\0'; + // Extract .library name directly from .fd file name + // e.g. identify.fd -> extracts "identify" + char *str = fdfilename + strlen(fdfilename) - strlen(".fd"); + while (str!=fdfilename && str[-1]!='/' && str[-1]!=':') + str--; + strncpy(BaseNamU, str, strlen(str) - strlen(".fd")); + BaseNamU[strlen(str) - strlen(".fd")]='\0'; strcpy(BaseNamL, BaseNamU); strcpy(BaseNamC, BaseNamU); + + // Use library name from from inside .fd (line "==base") + // e.g. "##base _CyberGfxBase" -> uses "CyberGfx" - this is wrong + // strcpy(BaseNamU, BaseName); + // if (strlen(BaseNamU)>4 && strcmp(BaseNamU+strlen(BaseNamU)-4, "Base")==0) + // BaseNamU[strlen(BaseNamU)-4]='\0'; + // strcpy(BaseNamL, BaseNamU); + // strcpy(BaseNamC, BaseNamU); } StrUpr(BaseNamU); BaseNamC[0]=toupper(BaseNamC[0]);