+2007-11-10 Maarten Brock <sourceforge.brock AT dse.nl>
+
+ * as/hc08/asmain.c,
+ * as/z80/asmain.c: cosmetic changes
+ * as/hc08/alloc.h,
+ * as/mcs51/alloc.h,
+ * as/z80/alloc.h: removed
+ * as/hc08/assym.c,
+ * as/mcs51/assym.c: replaced alloc.h with stdlib.h
+ * as/link/aslink.h: added LKDIRSEP and, LKDIRSEPSTR
+ * as/link/hc08/Makefile.in,
+ * as/link/mcs51/Makefile.in,
+ * as/link/z80/Makefile.in: added -DUNIX to CFLAGS
+ * as/link/lklex.c,
+ * as/link/mcs51/lkarea.c,
+ * as/link/mcs51/lkmain.c: cosmetic changes
+ * as/link/hc08/lklibr.c,
+ * as/link/z80/lklibr.c,
+ * as/link/mcs51/lklibr.c: used LKDIRSEP, LKDIRSEPSTR and LKOBJEXT,
+ used cygwin_conv_to_full_posix_path,
+ added warnings, cosmetic changes, brought more in sync
+ changed old K&R into ANSI function declarations
+ * as/link/z80/lklibr.c (loadAdb): added
+ * as/link/z80/lkmain.c: removed -- option from usage text
+
2007-11-03 Maarten Brock <sourceforge.brock AT dse.nl>
* src/mcs51/gen.c (outBitC): optimized for no result
+++ /dev/null
-/* alloc.h */
-/* DECUS C */
-
-#include <stdlib.h>
*/
default:
machine(mp);
- /* if cdb information the generate the line info */
+ /* if cdb information then generate the line info */
if (cflag && (pass == 1))
DefineCDB_Line();
* 721 Berkeley St.
* Kent, Ohio 44240
*
- * 28-Oct-97 JLH:
+ * 28-Oct-97 JLH:
* - lookup: Use StoreString for sym construction
* - change symeq() to do length-independent string compare
* - change hash() to do length-independent hash calculation
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
-#if defined(_MSC_VER)
-#include <malloc.h>
-#else
-#include <alloc.h>
-#endif
+#include <stdlib.h>
#include "asm.h"
/*)Module assym.c
* side effects:
* none
*/
-
+
int
hash(p)
register char *p;
$(STACK) = 2000
*/
+#if defined decus
/* DECUS C void definition */
/* File/extension seperator */
-#ifdef decus
-#define VOID char
-#define FSEPX '.'
-#endif
+#define VOID char
+#define FSEPX '.'
+#elif defined PDOS
/* PDOS C void definition */
/* File/extension seperator */
-#ifdef PDOS
-#define VOID char
-#define FSEPX ':'
-#endif
+#define VOID char
+#define FSEPX ':'
+
+#elif defined UNIX
+/* UNIX void definition */
+/* File/extension seperator */
-/* Default void definition */
+#define VOID void
+#define FSEPX '.'
+#define LKDIRSEP '/'
+#define LKDIRSEPSTR "/"
+#define OTHERSYSTEM
+
+#else
+/* DOS/WINDOWS void definition */
/* File/extension seperator */
-#ifndef VOID
-#define VOID void
-#define FSEPX '.'
+#define VOID void
+#define FSEPX '.'
+#define LKDIRSEP '\\'
+#define LKDIRSEPSTR "\\"
#define OTHERSYSTEM
+
#endif
/*
VPATH = @srcdir@
CPPFLAGS = @CPPFLAGS@ -I$(srcdir)/..
-CFLAGS = @CFLAGS@ -Wall
+CFLAGS = @CFLAGS@ -Wall -DUNIX
M_OR_MM = @M_OR_MM@
LDFLAGS = @LDFLAGS@
*/
VOID
-addpath()
+addpath(void)
{
struct lbpath *lbph, *lbp;
} else {
lbp = lbphead;
while (lbp->next)
+ {
lbp = lbp->next;
+ }
lbp->next = lbph;
}
unget(getnb());
*/
VOID
-addlib()
+addlib(void)
{
struct lbpath *lbph;
int foundcount=0;
if (path != NULL)
{
str = (char *) new (strlen(path) + strlen(libfil) + 6);
- strcpy(str,path);
+ strcpy(str, path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
- strcat(str,"/");
+ strcat(str, LKDIRSEPSTR);
}
#endif
}
}
#ifdef OTHERSYSTEM
- if ((libfil[0] == '/') || (libfil[0] == '\\'))
+ if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
{
libfil++;
libfilinc=1;
if(path==NULL)
{
- /*'path' can not be null since it is needed to find the '.rel' files associated with
+ /*'path' can not be null since it is needed to find the object files associated with
the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
That way putting 'path' and 'libfil' together will result into the original filepath
as contained in 'str'.*/
strcpy(path, str);
for(j=strlen(path)-1; j>=0; j--)
{
- if((path[j] == '/') || (path[j] == '\\'))
+ if((path[j] == '/') || (path[j] == LKDIRSEP))
{
strcpy(libfil, &path[j+1]);
path[j+1]=0;
{
lbn = lbnhead;
while (lbn->next)
+ {
lbn = lbn->next;
+ }
lbn->next = lbnh;
}
lbnh->path = path;
lbnh->libfil = (char *) new (strlen(libfil) + 1);
- strcpy(lbnh->libfil,libfil);
+ strcpy(lbnh->libfil, libfil);
lbnh->libspc = str;
return 1;
}
*/
VOID
-search()
+search(void)
{
register struct sym *sp;
- register int i,symfnd;
+ register int i, symfnd;
/*
* Look for undefined symbols. Keep
}
/*Load a .rel file embedded in a sdcclib file*/
-void LoadRel(FILE * libfp, char * ModName)
+void LoadRel(char * libfname, FILE * libfp, char * ModName)
{
char str[NINPUT+2];
int state=0;
if(EQ(str, ModName)) state=1;
else
{
- fprintf(stderr, "?ASlink-Error-Bad offset in library file str=%s, Modname=%s\n",
- str, ModName);
+ fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
+ libfname, ModName);
lkexit(1);
}
}
}
}
-/*Load an .adb file embedded in a sdcclib file. If there is
+/*Load an .adb file embedded in a sdcclib file. If there is
something between <ADB> and </ADB> returns 1, otherwise returns 0.
-This way the aomf51 will not have uselless empty modules. */
+This way the aomf51 will not have useless empty modules. */
int LoadAdb(FILE * libfp)
{
return ToReturn;
}
-/*Check for a symbol in a SDCC library. If found, add the embedded .rel and
+/*Check for a symbol in a SDCC library. If found, add the embedded .rel and
.adb files from the library. The library must be created with the SDCC
librarian 'sdcclib' since the linking process depends on the correct file offsets
embedded in the library file.*/
/*As in the original library format, it is assumed that the .rel
files reside in the same directory as the lib files.*/
strcat(DirLib, ModName);
- sprintf(&DirLib[strlen(DirLib)], "%crel", FSEPX);
+ sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
/*If this module has been loaded already don't load it again.*/
lbf = lbfhead;
{
lbf = lbfhead;
while (lbf->next)
- lbf = lbf->next;
+ {
+ lbf = lbf->next;
+ }
lbf->next = lbfh;
}
/*Jump to where the .rel begins and load it.*/
fseek(libfp, lbfh->offset, SEEK_SET);
- LoadRel(libfp, ModName);
+ LoadRel(PathLib, libfp, ModName);
/* if cdb information required & .adb file present */
if (dflag && dfp)
*/
int
-fndsym(name)
-char *name;
+fndsym(char *name)
{
FILE *libfp, *fp;
struct lbname *lbnh;
{
if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
{
- fprintf(stderr, "ASlink-Error-Cannot open library file %s\n",
+ fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
lbnh->libspc);
lkexit(1);
}
str = (char *) new (strlen(path)+strlen(relfil)+6);
strcpy(str,path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
- strcat(str,"/");
+ strcat(str, LKDIRSEPSTR);
}
#endif
}
str = (char *) new (strlen(relfil) + 5);
}
+ /*See if this is a library with embedded files*/
if(strcmp(relfil, "<SDCCLIB>")==0)
{
result=SdccLib(lbnh->libspc, libfp, str, name);
- fclose(libfp);
if(result) return(1); /*Found the symbol*/
free(str);
/*The symbol is not in the current library,
}
/*From here down is the support for libraries in the original format*/
- if (relfil[0] == '\\')
+ if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
{
- strcat(str,relfil+1);
+ strcat(str, relfil+1);
}
else
{
- strcat(str,relfil);
+ strcat(str, relfil);
}
if(strchr(relfil, FSEPX) == NULL)
{
- sprintf(&str[strlen(str)], "%crel", FSEPX);
+ sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
}
if ((fp = fopen(str, "r")) != NULL)
{
-
/*
* Read in the object file. Look for lines that
* begin with "S" and end with "D". These are
/*
* Skip everything that's not a symbol record.
*/
- if (buf[0] != 'S') continue;
+ if (buf[0] != 'S')
+ continue;
/*
- * When a 'T line' is found terminate file scan.
- * All 'S line's preceed 'T line's in .REL files.
- */
- if (buf[0] == 'T') break;
+ * When a 'T line' is found terminate file scan.
+ * All 'S line's preceed 'T line's in .REL files.
+ */
+ if (buf[0] == 'T')
+ break;
sscanf(buf, "S %s %c", symname, &c);
/*
- * If we find a symbol definition for the
- * symbol we're looking for, load in the
- * file and add it to lbfhead so it gets
- * loaded on pass number 2.
- */
+ * If we find a symbol definition for the
+ * symbol we're looking for, load in the
+ * file and add it to lbfhead so it gets
+ * loaded on pass number 2.
+ */
if (strncmp(symname, name, NCPS) == 0 && c == 'D')
{
lbfh = (struct lbfile *) new (sizeof(struct lbfile));
{
lbf = lbfhead;
while (lbf->next)
- lbf = lbf->next;
+ {
+ lbf = lbf->next;
+ }
lbf->next = lbfh;
}
loadfile(str);
return (1);
}
- }
+ } /* Closes while - read object file */
fclose(fp);
+ } /* Closes if object file opened OK */
+ else
+ {
+ fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
}
free(str);
- }
+ } /* Ends while - processing all in libr */
fclose(libfp);
- }
+ } /* Ends good open of libr file */
return(0);
}
{
FILE *fp;
- if ((fp = fopen(libspc,"r")) != NULL)
+#ifdef __CYGWIN__
+ char posix_path[PATH_MAX];
+ void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
+ cygwin_conv_to_full_posix_path(libspc, posix_path);
+ fp = fopen(posix_path, "r");
+#else
+ fp = fopen(libspc,"r");
+#endif
+
+ if (fp != NULL)
{
fseek(fp, offset, SEEK_SET);
- LoadRel(fp, module);
+ LoadRel(libspc, fp, module);
fclose(fp);
}
+ else
+ {
+ fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
+ lkexit(1);
+ }
}
/*)Function VOID library()
*/
VOID
-library()
+library(void)
{
struct lbfile *lbfh;
* char str[] file input line
*
* global variables:
- * char *ip pointer to linker input string
+ * char *ip pointer to linker input string
*
* functions called:
* int fclose() c_library
*/
VOID
-loadfile(filspc)
-char *filspc;
+loadfile(char *filspc)
{
FILE *fp;
char str[NINPUT+2];
- if ((fp = fopen(filspc,"r")) != NULL) {
- while (fgets(str, NINPUT, fp) != NULL) {
+#ifdef __CYGWIN__
+ char posix_path[PATH_MAX];
+ void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
+ cygwin_conv_to_full_posix_path(filspc, posix_path);
+ fp = fopen(posix_path, "r");
+#else
+ fp = fopen(filspc,"r");
+#endif
+
+ if (fp != NULL)
+ {
+ while (fgets(str, NINPUT, fp) != NULL)
+ {
str[NINPUT+1] = '\0';
chop_crlf(str);
ip = str;
}
fclose(fp);
}
+ else
+ {
+ fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);
+ lkexit(1);
+ }
}
} else
if (ftype == F_REL) {
sfp = afile(fid, LKOBJEXT, 0);
- /* if a .cdb file exists then copy it over */
+ /* if a .adb file exists then copy it over */
if (dflag && sfp && dfp && pass == 0) {
FILE *xfp = afile(fid,"adb",0); //JCF: Nov 30, 2002
if (xfp) {
VPATH = @srcdir@
CPPFLAGS = @CPPFLAGS@ -I.. -I$(srcdir)/..
-CFLAGS = @CFLAGS@ -Wall -DINDEXLIB
+CFLAGS = @CFLAGS@ -Wall -DINDEXLIB -DUNIX
M_OR_MM = @M_OR_MM@
LDFLAGS = @LDFLAGS@
{
taxp->a_addr = j-k+1;
for(j=taxp->a_addr; (j<(int)(taxp->a_addr+taxp->a_size)) && (j<0x30); j++)
- idatamap[j]=fchar;
+ idatamap[j]=fchar;
}
else /*Couldn't find a chunk big enough: report the problem.*/
{
#include <ctype.h>
#include "aslink.h"
-/*)Module lklibr.c
+/*)Module lklibr.c
*
* The module lklibr.c contains the functions which
* (1) specify the path(s) to library files [.LIB]
/* First entry in the library object symbol cache */
pmlibraryfile libr=NULL;
-int buildlibraryindex();
+int buildlibraryindex(void);
void freelibraryindex (void);
#endif /* INDEXLIB */
*/
VOID
-addpath()
+addpath(void)
{
struct lbpath *lbph, *lbp;
} else {
lbp = lbphead;
while (lbp->next)
+ {
lbp = lbp->next;
+ }
lbp->next = lbph;
}
unget(getnb());
*/
VOID
-addlib()
+addlib(void)
{
struct lbpath *lbph;
int foundcount=0;
if (path != NULL)
{
str = (char *) new (strlen(path) + strlen(libfil) + 6);
- strcpy(str,path);
+ strcpy(str, path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
- strcat(str,"/");
+ strcat(str, LKDIRSEPSTR);
}
#endif
}
}
#ifdef OTHERSYSTEM
- if ((libfil[0] == '/') || (libfil[0] == '\\'))
+ if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
{
libfil++;
libfilinc=1;
if(fp != NULL)
{
/*Bingo! 'libfil' is the absolute path of the library*/
- strcpy(str, libfil);
+ strcpy(str, libfil);
path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
}
}
if(path==NULL)
{
- /*'path' can not be null since it is needed to find the '.rel' files associated with
+ /*'path' can not be null since it is needed to find the object files associated with
the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
That way putting 'path' and 'libfil' together will result into the original filepath
as contained in 'str'.*/
strcpy(path, str);
for(j=strlen(path)-1; j>=0; j--)
{
- if((path[j] == '/') || (path[j] == '\\'))
+ if((path[j] == '/') || (path[j] == LKDIRSEP))
{
strcpy(libfil, &path[j+1]);
path[j+1]=0;
{
lbn = lbnhead;
while (lbn->next)
+ {
lbn = lbn->next;
+ }
lbn->next = lbnh;
}
lbnh->path = path;
lbnh->libfil = (char *) new (strlen(libfil) + 1);
- strcpy(lbnh->libfil,libfil);
+ strcpy(lbnh->libfil, libfil);
lbnh->libspc = str;
return 1;
}
*/
VOID
-search()
+search(void)
{
register struct sym *sp;
- register int i,symfnd;
+ register int i, symfnd;
/*
* Look for undefined symbols. Keep
if(EQ(str, ModName)) state=1;
else
{
- fprintf(stderr, "?Aslink-Error-Bad offset in library file %s(%s)\n",
+ fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
libfname, ModName);
lkexit(1);
}
}
}
-/*Load an .adb file embedded in a sdcclib file. If there is
+/*Load an .adb file embedded in a sdcclib file. If there is
something between <ADB> and </ADB> returns 1, otherwise returns 0.
-This way the aomf51 will not have uselless empty modules. */
+This way the aomf51 will not have useless empty modules. */
int LoadAdb(FILE * libfp)
{
return ToReturn;
}
-/*Check for a symbol in a SDCC library. If found, add the embedded .rel and
+/*Check for a symbol in a SDCC library. If found, add the embedded .rel and
.adb files from the library. The library must be created with the SDCC
librarian 'sdcclib' since the linking process depends on the correct file offsets
embedded in the library file.*/
/*As in the original library format, it is assumed that the .rel
files reside in the same directory as the lib files.*/
strcat(DirLib, ModName);
- sprintf(&DirLib[strlen(DirLib)], "%crel", FSEPX);
+ sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
/*If this module has been loaded already don't load it again.*/
lbf = lbfhead;
{
lbf = lbfhead;
while (lbf->next)
- lbf = lbf->next;
+ {
+ lbf = lbf->next;
+ }
lbf->next = lbfh;
}
{
lbf = lbfhead;
while (lbf->next)
- lbf = lbf->next;
+ {
+ lbf = lbf->next;
+ }
lbf->next = lbfh;
}
lbfh->libspc = ThisLibr->libspc;
{
if(numfound==1)
{
- fprintf(stderr, "?Aslink-Warning-Definition of public symbol '%s'"
+ fprintf(stderr, "?ASlink-Warning-Definition of public symbol '%s'"
" found more than once:\n", name);
fprintf(stderr, " Library: '%s', Module: '%s'\n",
FirstFound->libspc, FirstFound->relfil);
This->relfil=(char *)new(strlen(ModName)+1);
strcpy(This->relfil, ModName);
- sprintf(buff, "%s%s%crel", DirLib, ModName, FSEPX);
+ sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
This->filename=(char *)new(strlen(buff)+1);
strcpy(This->filename, buff);
/*
* Search through every library in the linked list "lbnhead".
*/
-
for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
{
if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
{
- fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n",
+ fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
lbnh->libspc);
lkexit(1);
}
{
strcpy(str, path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
- strcat(str,"/");
+ strcat(str, LKDIRSEPSTR);
}
#endif
}
/*From here down, build the index for the original library format*/
- if (relfil[0] == '\\')
+ if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
{
- strcat(str,relfil+1);
+ strcat(str, relfil+1);
}
else
{
- strcat(str,relfil);
+ strcat(str, relfil);
}
if(strchr(relfil, FSEPX) == NULL)
{
- sprintf(&str[strlen(str)], "%crel", FSEPX);
+ sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
}
if ((fp = fopen(str, "r")) != NULL)
strcpy(This->filename, str);
/*Start a new linked list of symbols for this module:*/
- This->symbols=ThisSym=NULL;
+ This->symbols = ThisSym = NULL;
/*
* Read in the object file. Look for lines that
} /* Closes if object file opened OK */
else
{
- fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str);
+ fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
}
} /* Ends while - processing all in libr */
fclose(libfp);
#else /* INDEXLIB */
int
-fndsym(name)
-char *name;
+fndsym(char *name)
{
FILE *libfp, *fp;
struct lbname *lbnh;
{
if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
{
- fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n",
+ fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
lbnh->libspc);
lkexit(1);
}
str = (char *) new (strlen(path)+strlen(relfil)+6);
strcpy(str,path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
- strcat(str,"/");
+ strcat(str, LKDIRSEPSTR);
}
#endif
}
str = (char *) new (strlen(relfil) + 5);
}
+ /*See if this is a library with embedded files*/
if(strcmp(relfil, "<SDCCLIB>")==0)
{
result=SdccLib(lbnh->libspc, libfp, str, name);
}
/*From here down is the support for libraries in the original format*/
- if (relfil[0] == '\\')
+ if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
{
- strcat(str,relfil+1);
+ strcat(str, relfil+1);
}
else
{
- strcat(str,relfil);
+ strcat(str, relfil);
}
if(strchr(relfil, FSEPX) == NULL)
{
- sprintf(&str[strlen(str)], "%crel", FSEPX);
+ sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
}
if ((fp = fopen(str, "r")) != NULL)
{
-
/*
* Read in the object file. Look for lines that
* begin with "S" and end with "D". These are
/*
* Skip everything that's not a symbol record.
*/
- if (buf[0] != 'S') continue;
+ if (buf[0] != 'S')
+ continue;
/*
- * When a 'T line' is found terminate file scan.
- * All 'S line's preceed 'T line's in .REL files.
- */
- if (buf[0] == 'T') break;
+ * When a 'T line' is found terminate file scan.
+ * All 'S line's preceed 'T line's in .REL files.
+ */
+ if (buf[0] == 'T')
+ break;
sscanf(buf, "S %s %c", symname, &c);
/*
- * If we find a symbol definition for the
- * symbol we're looking for, load in the
- * file and add it to lbfhead so it gets
- * loaded on pass number 2.
- */
+ * If we find a symbol definition for the
+ * symbol we're looking for, load in the
+ * file and add it to lbfhead so it gets
+ * loaded on pass number 2.
+ */
if (strncmp(symname, name, NCPS) == 0 && c == 'D')
{
lbfh = (struct lbfile *) new (sizeof(struct lbfile));
{
lbf = lbfhead;
while (lbf->next)
- lbf = lbf->next;
+ {
+ lbf = lbf->next;
+ }
lbf->next = lbfh;
}
loadfile(str);
return (1);
}
- }
+ } /* Closes while - read object file */
fclose(fp);
+ } /* Closes if object file opened OK */
+ else
+ {
+ fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
}
free(str);
- }
+ } /* Ends while - processing all in libr */
fclose(libfp);
- }
+ } /* Ends good open of libr file */
return(0);
}
-#endif /*INDEXLIB*/
+#endif /* INDEXLIB */
void loadfile_SdccLib(char * libspc, char * module, long offset)
{
FILE *fp;
- if ((fp = fopen(libspc,"r")) != NULL)
+#ifdef __CYGWIN__
+ char posix_path[PATH_MAX];
+ void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
+ cygwin_conv_to_full_posix_path(libspc, posix_path);
+ fp = fopen(posix_path, "r");
+#else
+ fp = fopen(libspc,"r");
+#endif
+
+ if (fp != NULL)
{
fseek(fp, offset, SEEK_SET);
LoadRel(libspc, fp, module);
fclose(fp);
}
+ else
+ {
+ fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", libspc);
+ lkexit(1);
+ }
}
/*)Function VOID library()
*/
VOID
-library()
+library(void)
{
struct lbfile *lbfh;
* char str[] file input line
*
* global variables:
- * char *ip pointer to linker input string
+ * char *ip pointer to linker input string
*
* functions called:
* int fclose() c_library
*/
VOID
-loadfile(filspc)
-char *filspc;
+loadfile(char *filspc)
{
FILE *fp;
char str[NINPUT+2];
- if ((fp = fopen(filspc,"r")) != NULL) {
- while (fgets(str, NINPUT, fp) != NULL) {
+#ifdef __CYGWIN__
+ char posix_path[PATH_MAX];
+ void cygwin_conv_to_full_posix_path(char * win_path, char * posix_path);
+ cygwin_conv_to_full_posix_path(filspc, posix_path);
+ fp = fopen(posix_path, "r");
+#else
+ fp = fopen(filspc,"r");
+#endif
+
+ if (fp != NULL)
+ {
+ while (fgets(str, NINPUT, fp) != NULL)
+ {
str[NINPUT+1] = '\0';
chop_crlf(str);
ip = str;
}
fclose(fp);
}
+ else
+ {
+ fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);
+ lkexit(1);
+ }
}
break;
if (pflag && sfp != stdin)
fprintf(stdout, "%s\n", ip);
- if (*ip == '\0' || parse())
+ if (*ip == '\0' || parse())
break;
}
SaveLinkedFilePath(linkp->f_idp); //Must be the first one...
dfp = afile(linkp->f_idp,"cdb",1); //JCF: Nov 30, 2002
if (dfp == NULL)
- lkexit(1);
+ lkexit(1);
}
for (pass=0; pass<2; ++pass) {
BINS = $(BUILDDIR)link$(EXT)$(EXEEXT)
CPPFLAGS+= -I.. -I$(srcdir)/..
-CFLAGS += $(CPPFLAGS) $(OPTS) -DINDEXLIB -DMLH_MAP -DUNIX -DSDK
+CFLAGS += $(CPPFLAGS) $(OPTS) -DINDEXLIB -DMLH_MAP -DSDK
CFLAGS += -funsigned-char -DUNIX
CFLAGS += -I$(top_builddir)/as/$(PORT) -I$(SLIB)
#include <ctype.h>
#include "aslink.h"
-#ifdef OTHERSYSTEM
-#ifdef SDK
-#ifdef UNIX
- #define LKDIRSEP '/'
- #define LKDIRSEPSTR "/"
-#else /* UNIX */
- #define LKDIRSEP '\\'
- #define LKDIRSEPSTR "\\"
-#endif /* UNIX */
-#else /* SDK */
- #define LKDIRSEP '\\'
- #define LKDIRSEPSTR "\\"
-#endif /* SDK */
-#endif
-
/*)Module lklibr.c
*
* The module lklibr.c contains the functions which
/* First entry in the library object symbol cache */
pmlibraryfile libr=NULL;
-int buildlibraryindex();
+int buildlibraryindex(void);
void freelibraryindex (void);
#endif /* INDEXLIB */
*/
VOID
-addpath()
+addpath(void)
{
struct lbpath *lbph, *lbp;
} else {
lbp = lbphead;
while (lbp->next)
+ {
lbp = lbp->next;
+ }
lbp->next = lbph;
}
unget(getnb());
*/
VOID
-addlib()
+addlib(void)
{
struct lbpath *lbph;
int foundcount=0;
FILE *fp;
char *str;
struct lbname *lbnh, *lbn;
+#ifdef OTHERSYSTEM
int libfilinc=0;
+#endif
if (path != NULL)
{
str = (char *) new (strlen(path) + strlen(libfil) + 6);
strcpy(str, path);
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+#ifdef OTHERSYSTEM
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
strcat(str, LKDIRSEPSTR);
}
+#endif
}
else
{
str = (char *) new (strlen(libfil) + 5);
}
- if ((libfil[0] == '/') || (libfil[0] == '\\'))
+#ifdef OTHERSYSTEM
+ if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
{
libfil++;
libfilinc=1;
}
+#endif
strcat(str, libfil);
-
if(strchr(libfil, FSEPX) == NULL)
{
sprintf(&str[strlen(str)], "%clib", FSEPX);
if(fp == NULL)
{
/*Ok, that didn't work. Try with the 'libfil' name only*/
+#ifdef OTHERSYSTEM
if(libfilinc) libfil--;
+#endif
fp=fopen(libfil, "r");
if(fp != NULL)
{
if(path==NULL)
{
- /*'path' can not be null since it is needed to find the .rel/.o files associated with
+ /*'path' can not be null since it is needed to find the object files associated with
the library. So, get 'path' from 'str' and then chop it off and recreate 'libfil'.
That way putting 'path' and 'libfil' together will result into the original filepath
as contained in 'str'.*/
strcpy(path, str);
for(j=strlen(path)-1; j>=0; j--)
{
- if((path[j] == '/') || (path[j] == '\\'))
+ if((path[j] == '/') || (path[j] == LKDIRSEP))
{
strcpy(libfil, &path[j+1]);
path[j+1]=0;
{
lbn = lbnhead;
while (lbn->next)
+ {
lbn = lbn->next;
+ }
lbn->next = lbnh;
}
*/
VOID
-search()
+search(void)
{
register struct sym *sp;
register int i, symfnd;
}
}
+/*Load an .adb file embedded in a sdcclib file. If there is
+something between <ADB> and </ADB> returns 1, otherwise returns 0.
+This way the aomf51 will not have useless empty modules. */
+
+int LoadAdb(FILE * libfp)
+{
+ char str[MAXLINE+1];
+ int state=0;
+ int ToReturn=0;
+
+ while (fgets(str, MAXLINE, libfp) != NULL)
+ {
+ str[NINPUT+1] = '\0';
+ chop_crlf(str);
+ switch(state)
+ {
+ case 0:
+ if(EQ(str, "<ADB>")) state=1;
+ break;
+ case 1:
+ if(EQ(str, "</ADB>")) return ToReturn;
+ fprintf(dfp, "%s\n", str);
+ ToReturn=1;
+ break;
+ }
+ }
+ return ToReturn;
+}
+
+/*Check for a symbol in a SDCC library. If found, add the embedded .rel and
+.adb files from the library. The library must be created with the SDCC
+librarian 'sdcclib' since the linking process depends on the correct file offsets
+embedded in the library file.*/
+
+int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
+{
+ struct lbfile *lbfh, *lbf;
+ char ModName[NCPS]="";
+ char FLine[MAXLINE+1];
+ int state=0;
+ long IndexOffset=0, FileOffset;
+
+ while(!feof(libfp))
+ {
+ FLine[0]=0;
+ fgets(FLine, MAXLINE, libfp);
+ chop_crlf(FLine);
+
+ switch(state)
+ {
+ case 0:
+ if(EQ(FLine, "<INDEX>"))
+ {
+ /*The next line has the size of the index*/
+ FLine[0]=0;
+ fgets(FLine, MAXLINE, libfp);
+ chop_crlf(FLine);
+ IndexOffset=atol(FLine);
+ state=1;
+ }
+ break;
+ case 1:
+ if(EQ(FLine, "<MODULE>"))
+ {
+ /*The next line has the name of the module and the offset
+ of the corresponding embedded file in the library*/
+ FLine[0]=0;
+ fgets(FLine, MAXLINE, libfp);
+ chop_crlf(FLine);
+ sscanf(FLine, "%s %ld", ModName, &FileOffset);
+ state=2;
+ }
+ else if(EQ(FLine, "</INDEX>"))
+ {
+ /*Reached the end of the index. The symbol is not in this library.*/
+ return 0;
+ }
+ break;
+ case 2:
+ if(EQ(FLine, "</MODULE>"))
+ {
+ /*The symbol is not in this module, try the next one*/
+ state=1;
+ }
+ else
+ {
+ /*Check if this is the symbol we are looking for.*/
+ if (strncmp(SymName, FLine, NCPS)==0)
+ {
+ /*The symbol is in this module.*/
+
+ /*As in the original library format, it is assumed that the .rel
+ files reside in the same directory as the lib files.*/
+ strcat(DirLib, ModName);
+ sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
+
+ /*If this module has been loaded already don't load it again.*/
+ lbf = lbfhead;
+ while (lbf)
+ {
+ if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
+ lbf=lbf->next;
+ }
+
+ /*Add the embedded file to the list of files to be loaded in
+ the second pass. That is performed latter by the function
+ library() below.*/
+ lbfh = (struct lbfile *) new (sizeof(struct lbfile));
+ if (lbfhead == NULL)
+ {
+ lbfhead = lbfh;
+ }
+ else
+ {
+ lbf = lbfhead;
+ while (lbf->next)
+ {
+ lbf = lbf->next;
+ }
+ lbf->next = lbfh;
+ }
+
+ lbfh->libspc = PathLib;
+ lbfh->filspc = DirLib;
+ lbfh->relfil = (char *) new (strlen(ModName) + 1);
+ strcpy(lbfh->relfil, ModName);
+ /*Library embedded file, so lbfh->offset must be >=0*/
+ lbfh->offset = IndexOffset+FileOffset;
+
+ /*Jump to where the .rel begins and load it.*/
+ fseek(libfp, lbfh->offset, SEEK_SET);
+ LoadRel(PathLib, libfp, ModName);
+
+ return 1; /*Found the symbol, so success!*/
+ }
+ }
+ break;
+
+ default:
+ return 0; /*It should never reach this point, but just in case...*/
+ break;
+ }
+ }
+
+ return 0; /*The symbol is not in this library*/
+}
+
/*)Function VOID fndsym(name)
*
* char *name symbol name to find
* file structure
*
* functions called:
- * int fclose() c_library
- * int fgets() c_library
+ * int fclose() c_library
+ * int fgets() c_library
* FILE *fopen() c_library
* VOID free() c_library
* char getnb() lklex.c
* VOID loadfile() lklibr.c
* VOID * new() lksym.c
* char * sprintf() c_library
- * int sscanf() c_library
+ * int sscanf() c_library
* char * strcat() c_library
* char * strchr() c_library
* char * strcpy() c_library
- * int strlen() c_library
- * int strncmp() c_library
+ * int strlen() c_library
+ * int strncmp() c_library
* VOID unget() lklex.c
*
* side effects:
{
lbf = lbfhead;
while (lbf->next)
- lbf = lbf->next;
+ {
+ lbf = lbf->next;
+ }
lbf->next = lbfh;
}
lbfh->libspc = ThisLibr->libspc;
{
if(numfound==1)
{
- fprintf(stderr, "?Aslink-Warning-Definition of public symbol '%s'"
+ fprintf(stderr, "?ASlink-Warning-Definition of public symbol '%s'"
" found more than once:\n", name);
fprintf(stderr, " Library: '%s', Module: '%s'\n",
FirstFound->libspc, FirstFound->relfil);
/* buildlibraryindex - build an in-memory cache of the symbols contained in
- * the libraries
+ * the libraries
*/
int buildlibraryindex(void)
{
{
if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
{
- fprintf(stderr, "?Aslink-Error-Cannot open library file %s\n",
+ fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
lbnh->libspc);
lkexit(1);
}
{
strcpy(str, path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
strcat(str, LKDIRSEPSTR);
}
/*From here down, build the index for the original library format*/
- if ((relfil[0] == '/') || (relfil[0] == '\\'))
+ if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
{
strcat(str, relfil+1);
}
} /* Closes if object file opened OK */
else
{
- fprintf(stderr, "?Aslink-Warning-Cannot open library module %s\n", str);
+ fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
}
} /* Ends while - processing all in libr */
fclose(libfp);
#else /* INDEXLIB */
-
-/*Check for a symbol in a SDCC library. If found, add the embedded .rel.
-The library must be created with the SDCC librarian 'sdcclib' since the
-linking process depends on the correct file offsets embedded in the library
-file.*/
-
-int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
-{
- struct lbfile *lbfh, *lbf;
- char ModName[NCPS]="";
- char FLine[MAXLINE+1];
- int state=0;
- long IndexOffset=0, FileOffset;
-
- while(!feof(libfp))
- {
- FLine[0]=0;
- fgets(FLine, MAXLINE, libfp);
- chop_crlf(FLine);
-
- switch(state)
- {
- case 0:
- if(EQ(FLine, "<INDEX>"))
- {
- /*The next line has the size of the index*/
- FLine[0]=0;
- fgets(FLine, MAXLINE, libfp);
- chop_crlf(FLine);
- IndexOffset=atol(FLine);
- state=1;
- }
- break;
- case 1:
- if(EQ(FLine, "<MODULE>"))
- {
- /*The next line has the name of the module and the offset
- of the corresponding embedded file in the library*/
- FLine[0]=0;
- fgets(FLine, MAXLINE, libfp);
- chop_crlf(FLine);
- sscanf(FLine, "%s %ld", ModName, &FileOffset);
- state=2;
- }
- else if(EQ(FLine, "</INDEX>"))
- {
- /*Reached the end of the index. The symbol is not in this library.*/
- return 0;
- }
- break;
- case 2:
- if(EQ(FLine, "</MODULE>"))
- {
- /*The symbol is not in this module, try the next one*/
- state=1;
- }
- else
- {
- /*Check if this is the symbol we are looking for.*/
- if (strncmp(SymName, FLine, NCPS)==0)
- {
- /*The symbol is in this module.*/
-
- /*As in the original library format, it is assumed that the .rel
- files reside in the same directory as the lib files.*/
- strcat(DirLib, ModName);
- sprintf(&DirLib[strlen(DirLib)], "%c%s", FSEPX, LKOBJEXT);
-
- /*If this module has been loaded already don't load it again.*/
- lbf = lbfhead;
- while (lbf)
- {
- if(EQ(DirLib, lbf->filspc)) return 1;/*Already loaded*/
- lbf=lbf->next;
- }
-
- /*Add the embedded file to the list of files to be loaded in
- the second pass. That is performed latter by the function
- library() below.*/
- lbfh = (struct lbfile *) new (sizeof(struct lbfile));
- if (lbfhead == NULL)
- {
- lbfhead = lbfh;
- }
- else
- {
- lbf = lbfhead;
- while (lbf->next)
- lbf = lbf->next;
- lbf->next = lbfh;
- }
-
- lbfh->libspc = PathLib;
- lbfh->filspc = DirLib;
- lbfh->relfil = (char *) new (strlen(ModName) + 1);
- strcpy(lbfh->relfil, ModName);
- /*Library embedded file, so lbfh->offset must be >=0*/
- lbfh->offset = IndexOffset+FileOffset;
-
- /*Jump to where the .rel begins and load it.*/
- fseek(libfp, lbfh->offset, SEEK_SET);
- LoadRel(PathLib, libfp, ModName);
-
- return 1; /*Found the symbol, so success!*/
- }
- }
- break;
-
- default:
- return 0; /*It should never reach this point, but just in case...*/
- break;
- }
- }
-
- return 0; /*The symbol is not in this library*/
-}
-
-/*)Function VOID fndsym(name)
- *
- * char *name symbol name to find
- *
- * The function fndsym() searches through all combinations of the
- * library path specifications (input by the -k option) and the
- * library file specifications (input by the -l option) that
- * lead to an existing file.
- *
- * The file specicifation may be formed in one of two ways:
- *
- * (1) If the library file contained an absolute
- * path/file specification then this becomes filspc.
- * (i.e. C:\...)
- *
- * (2) If the library file contains a relative path/file
- * specification then the concatenation of the path
- * and this file specification becomes filspc.
- * (i.e. \...)
- *
- * The structure lbfile is created for the first library
- * object file which contains the definition for the
- * specified undefined symbol.
- *
- * If the library file [.LIB] contains file specifications for
- * non existant files, no errors are returned.
- *
- * local variables:
- * char buf[] [.REL] file input line
- * char c [.REL] file input character
- * FILE *fp file handle for object file
- * lbfile *lbf temporary pointer
- * lbfile *lbfh pointer to lbfile structure
- * FILE *libfp file handle for library file
- * lbname *lbnh pointer to lbname structure
- * char *path file specification path
- * char relfil[] [.REL] file specification
- * char *str combined path and file specification
- * char symname[] [.REL] file symbol string
- *
- * global variables:
- * lbname *lbnhead The pointer to the first
- * name structure
- * lbfile *lbfhead The pointer to the first
- * file structure
- *
- * functions called:
- * int fclose() c_library
- * int fgets() c_library
- * FILE *fopen() c_library
- * VOID free() c_library
- * char getnb() lklex.c
- * VOID lkexit() lkmain.c
- * VOID loadfile() lklibr.c
- * VOID * new() lksym.c
- * char * sprintf() c_library
- * int sscanf() c_library
- * char * strcat() c_library
- * char * strchr() c_library
- * char * strcpy() c_library
- * int strlen() c_library
- * int strncmp() c_library
- * VOID unget() lklex.c
- *
- * side effects:
- * If the symbol is found then a new lbfile structure
- * is created and added to the linked list of lbfile
- * structures. The file containing the found symbol
- * is linked.
- */
-
int
-fndsym(name)
-char *name;
+fndsym(char *name)
{
FILE *libfp, *fp;
struct lbname *lbnh;
str = (char *) new (strlen(path)+strlen(relfil)+6);
strcpy(str,path);
#ifdef OTHERSYSTEM
- if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != '\\'))
+ if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
{
-#ifdef SDK
-#ifdef UNIX
- strcat(str,"/");
-#else /* UNIX */
- strcat(str,"\\");
-#endif /* UNIX */
-#else /* SDK */
- strcat(str,"\\");
-#endif /* SDK */
+ strcat(str, LKDIRSEPSTR);
}
#endif
}
}
/*From here down is the support for libraries in the original format*/
- if ((relfil[0] == '/') || (relfil[0] == '\\'))
+ if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
{
strcat(str, relfil+1);
}
while (fgets(buf, NINPUT, fp) != NULL)
{
buf[NINPUT+1] = '\0';
- chop_crlf(buf);
+ chop_crlf(buf);
/*
* Skip everything that's not a symbol record.
*/
{
lbf = lbfhead;
while (lbf->next)
+ {
lbf = lbf->next;
+ }
lbf->next = lbfh;
}
loadfile(str);
return (1);
}
- }
+ } /* Closes while - read object file */
fclose(fp);
+ } /* Closes if object file opened OK */
+ else
+ {
+ fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
}
free(str);
- }
+ } /* Ends while - processing all in libr */
fclose(libfp);
- }
+ } /* Ends good open of libr file */
return(0);
}
*/
VOID
-library()
+library(void)
{
struct lbfile *lbfh;
*/
VOID
-loadfile(filspc)
-char *filspc;
+loadfile(char *filspc)
{
FILE *fp;
char str[NINPUT+2];
"\n",
#endif
"Startup:",
-#ifdef SDK
- " -- [Commands] Non-interactive command line input",
-#endif /* SDK */
" -c Command line input",
" -f file[LNK] File input",
" -p Prompt and echo of file[LNK] to stdout (default)",
+++ /dev/null
-/* alloc.h */
-/* DECUS C */
-
-#include <stdlib.h>
* 721 Berkeley St.
* Kent, Ohio 44240
*
- * 28-Oct-97 JLH:
+ * 28-Oct-97 JLH:
* - lookup: Use StoreString for sym construction
* - change symeq() to do length-independent string compare
* - change hash() to do length-independent hash calculation
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
-#if defined(_MSC_VER)
-#include <malloc.h>
-#else
-#include <alloc.h>
-#endif
+#include <stdlib.h>
#include "asm.h"
/*)Module assym.c
* side effects:
* none
*/
-
+
int
hash(p)
register char *p;
+++ /dev/null
-/* alloc.h */
-/* DECUS C */
-
-#ifndef SDK
-//extern char *alloc();
-//extern char *malloc();
-//extern char *calloc();
-//extern char *realloc();
-#endif
-
goto loop;
}
/*
- * If the first character is a letter then assume a lable,
+ * If the first character is a letter then assume a label,
* symbol, assembler directive, or assembler mnemonic is
* being processed.
*/
} else {
qerr();
}
- }
+ }
getid(id, c);
c = getnb();
/*