From 8081375fb2a5fdeaecce9da588fd02929819f45e Mon Sep 17 00:00:00 2001 From: jesusc Date: Thu, 3 Jul 2003 19:21:27 +0000 Subject: [PATCH] properly handle extensions in function afile git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2720 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 +++++- as/mcs51/lkmain.c | 51 +++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 56c7b917..85f4789f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2003-07-03 Jesus Calvino-Fraga + + * as/mcs51/lkmain.c: properly handle extensions in function afile. + 2003-07-02 Borut Razem * src/port.h, src/SDCCmain.c, src/pic/glue.h, src/pic/main.c, @@ -21,7 +25,7 @@ 2003-06-20 Jesus Calvino-Fraga - * as/mcs51/aomf51.c: Make sure the size of the last procedure is correct. + * as/mcs51/lkaomf51.c: Make sure the size of the last procedure is correct. 2003-06-19 Borut Razem diff --git a/as/mcs51/lkmain.c b/as/mcs51/lkmain.c index 8ea5fde7..cc695c9b 100644 --- a/as/mcs51/lkmain.c +++ b/as/mcs51/lkmain.c @@ -1076,12 +1076,8 @@ setgbl() * the assembler on an open error. * * local variables: - * int c character value * char fb[] constructed file specification string * FILE * fp filehandle for opened file - * char * p1 pointer to filespec string fn - * char * p2 pointer to filespec string fb - * char * p3 pointer to filetype string ft * * global variables: * int lkerr error flag @@ -1099,36 +1095,35 @@ afile(fn, ft, wf) char *fn; char *ft; { - register char *p1, *p2, *p3; - register int c; FILE *fp; char fb[PATH_MAX]; char *omode = (wf ? (wf == 2 ? "a" : "w") : "r"); + int i; - p1 = fn; - p2 = fb; - p3 = ft; - while ((c = *p1++) != 0 && c != FSEPX) { - if (p2 < &fb[PATH_MAX-4]) - *p2++ = c; - } - *p2++ = FSEPX; - if (*p3 == 0) { - if (c == FSEPX) { - p3 = p1; - } else { - p3 = "rel"; - } + /*Look backward the name path and get rid of the extension, if any*/ + i=strlen(fn); + for(; (fn[i]!='.')&&(fn[i]!='\\')&&(fn[i]!='/')&&(i>=0); i--); + if( (fn[i]=='.') && strcmp(ft, "lnk") ) + { + strncpy(fb, fn, i); + fb[i]=0; } - while ((c = *p3++) != 0) { - if (p2 < &fb[PATH_MAX-1]) - *p2++ = c; + else + { + strcpy(fb, fn); } - *p2++ = 0; - if ((fp = fopen(fb, omode)) == NULL) { - if (strcmp(ft,"adb")) { - fprintf(stderr, "%s: cannot %s.\n", fb, wf?"create":"open"); - lkerr++; + + /*Add the extension*/ + strcat(fb, "."); + strcat(fb, strlen(ft)?ft:"rel"); + + fp = fopen(fb, omode); + if (fp==NULL) + { + if (strcmp(ft,"adb"))/*Do not complaint for optional adb files*/ + { + fprintf(stderr, "%s: cannot %s.\n", fb, wf?"create":"open"); + lkerr++; } } return (fp); -- 2.30.2