* as/link/lklib.c, as/link/lksdcclib.c, as/link/lklibr.h,
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 2 Jan 2009 20:40:13 +0000 (20:40 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 2 Jan 2009 20:40:13 +0000 (20:40 +0000)
  as/link/getline.[ch], as/link/lkrel.[ch]: added,
  made support for differnet library formats more flexible,
  preparation for support of ar format
* as/link/lklibr.c, as/link/z80/Makefile.in,
  as/link/z80/linkgbz80.dsp, as/link/z80/linkz80.dsp,
  as/link/hc08/link_hc08.dsp, as/link/hc08/Makefile.in,
  as/link/mcs51/aslink.dsp, as/link/mcs51/Makefile.in,
  as/link/hc08/lkelf.c, as/link/aslink.h:
  made support for differnet library formats more flexible,
  preparation for support of ar format

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5319 4a8a32a2-be11-0410-ad9d-d568d2c75423

18 files changed:
ChangeLog
as/link/aslink.h
as/link/getline.c [new file with mode: 0644]
as/link/getline.h [new file with mode: 0644]
as/link/hc08/Makefile.in
as/link/hc08/link_hc08.dsp
as/link/hc08/lkelf.c
as/link/lklib.c [new file with mode: 0644]
as/link/lklibr.c
as/link/lklibr.h [new file with mode: 0644]
as/link/lkrel.c [new file with mode: 0644]
as/link/lkrel.h [new file with mode: 0644]
as/link/lksdcclib.c [new file with mode: 0644]
as/link/mcs51/Makefile.in
as/link/mcs51/aslink.dsp
as/link/z80/Makefile.in
as/link/z80/linkgbz80.dsp
as/link/z80/linkz80.dsp

index 8d719087c5a460ef460b6e1852c4e112b5dcdfc1..6a734bfe940622039abbe1e67d20381fcacd27ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-01-02 Borut Razem <borut.razem AT siol.net>
+
+       * as/link/lklib.c, as/link/lksdcclib.c, as/link/lklibr.h,
+         as/link/getline.[ch], as/link/lkrel.[ch]: added,
+         made support for differnet library formats more flexible,
+         preparation for support of ar format
+       * as/link/lklibr.c, as/link/z80/Makefile.in,
+         as/link/z80/linkgbz80.dsp, as/link/z80/linkz80.dsp,
+         as/link/hc08/link_hc08.dsp, as/link/hc08/Makefile.in,
+         as/link/mcs51/aslink.dsp, as/link/mcs51/Makefile.in,
+         as/link/hc08/lkelf.c, as/link/aslink.h:
+         made support for differnet library formats more flexible,
+         preparation for support of ar format
+
 2009-01-01 Borut Razem <borut.razem AT siol.net>
 
        * as/link/asxxxx_config.h.in:
index 3fc0c7528afea950d5e5f8f140ea75e10cc93fc3..4f21df913777f7cdee9dc17ba934bf428ab3bf1d 100644 (file)
@@ -22,8 +22,6 @@
  * Extensions: P. Felber
  */
 
-#include "asxxxx_config.h"
-
 #define VERSION "V01.75 + NoICE + SDCC Feb 1999"
 
 /*
@@ -487,7 +485,8 @@ struct lbfile {
         char            *libspc;
         char            *relfil;
         char            *filspc;
-        long            offset; /*>=0 if rel file is embedded in a lib file at this offset*/
+        long            offset;
+        unsigned int    type;
 };
 
 /*
diff --git a/as/link/getline.c b/as/link/getline.c
new file mode 100644 (file)
index 0000000..ba208ee
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+  getline.c - read a line from file into a buffer
+  version 1.0.0, April 25th, 2008
+
+  Copyright (c) 2008 Borut Razem
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+  Borut Razem
+  borut.razem@siol.net
+*/
+
+#include "getline.h"
+
+/*******************************************************************************
+
+                                getline
+
+getline() reads in at most one less than size characters from stream and stores
+them into the buffer pointed to by s. Reading stops after an EOF or a newline.
+The newline character is not stored into the buffer. A '\0' is stored after the
+last character in the buffer. All the characters between size and the newline or
+EOF are skipped.
+
+getline() return s on success, and NULL on error or when end of file occurs
+while no characters have been read.
+
+*******************************************************************************/
+
+char *
+getline (char *s, int size, FILE * stream)
+{
+  static char eof_f = 0;
+  int c = '\0';
+  char *s_o;
+  char prev_c;
+
+  if (eof_f)
+    {
+      eof_f = 0;
+      return NULL;
+    }
+
+  s_o = s;
+  --size;                       /* for null terminator */
+  while (size > 0)
+    {
+      prev_c = c;
+      if ((c = getc (stream)) == '\n' || c == EOF)
+        break;
+
+      if (prev_c == '\r')
+        {
+          *s++ = prev_c;
+          if (--size <= 0)
+            break;
+        }
+
+      if (c != '\r')
+        {
+          *s++ = c;
+          --size;
+        }
+    }
+  *s = '\0';
+
+  while (c != '\n' && c != EOF)
+    c = getc (stream);
+
+  if (c == EOF)
+    {
+      if (s == s_o)
+        return NULL;
+
+      eof_f = 1;
+    }
+
+  return s_o;
+}
diff --git a/as/link/getline.h b/as/link/getline.h
new file mode 100644 (file)
index 0000000..3877461
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+  getline.h - read a line from file into a buffer
+  version 1.0.0, Aprile 25th, 2008
+
+  Copyright (c) 2008 Borut Razem
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+  Borut Razem
+  borut.razem@siol.net
+*/
+
+
+#ifndef __GETLINE_H
+#define __GETLINE_H
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+  char *getline (char *s, int size, FILE * stream);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif                          /* __GETLINE_H */
index 53af6c4d976a60fcce44f49349d22e55d1057b3a..d2398537a22b521de994ff805006139354d72bcd 100644 (file)
@@ -33,8 +33,8 @@ EXEEXT          = @EXEEXT@
 
 VPATH           = @srcdir@
 
-CPPFLAGS        = @CPPFLAGS@ -I.. -I$(srcdir)/.. -I$(top_builddir)
-CFLAGS          = @CFLAGS@ -Wall -DUNIX -I.. -I$(srcdir)/.. -I$(top_builddir)
+CPPFLAGS        = @CPPFLAGS@ -I.. -I$(srcdir)/..
+CFLAGS          = @CFLAGS@ -Wall -DUNIX -I.. -I$(srcdir)/..
 M_OR_MM         = @M_OR_MM@
 LDFLAGS         = @LDFLAGS@
 
@@ -46,9 +46,9 @@ LKLIB = $(srcdir)/..
 
 ASXXLIBSRC = strcmpi.c
 
-LKLIBSRC = lkaomf51.c lkdata.c lkeval.c \
-           lkhead.c lklex.c lklibr.c lklist.c \
-           lknoice.c lkstore.c lksym.c
+LKLIBSRC = getline.c lkaomf51.c lkdata.c lkeval.c \
+           lkhead.c lklex.c lklib.c lklibr.c lklist.c \
+           lknoice.c lkrel.c lksdcclib.c lkstore.c lksym.c
 
 SRC = lkmain.c lkarea.c lkihx.c \
       lkrloc.c lks19.c lkelf.c lkmem.c
index c077dcbbbf45c900195b2b30e4ea9c7248cbf43a..7a2359ac60bd5fe74902363bacb552187bb96c4f 100644 (file)
@@ -42,7 +42,7 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O2 /I ".." /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
 # ADD BASE RSC /l 0x409 /d "NDEBUG"\r
 # ADD RSC /l 0x409 /d "NDEBUG"\r
 BSC32=bscmake.exe\r
@@ -66,7 +66,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c\r
 # ADD BASE RSC /l 0x409 /d "_DEBUG"\r
 # ADD RSC /l 0x409 /d "_DEBUG"\r
 BSC32=bscmake.exe\r
@@ -87,6 +87,10 @@ LINK32=link.exe
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
 # Begin Source File\r
 \r
+SOURCE=..\getline.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lkaomf51.c\r
 # End Source File\r
 # Begin Source File\r
@@ -119,6 +123,10 @@ SOURCE=..\lklex.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lklib.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lklibr.c\r
 # End Source File\r
 # Begin Source File\r
@@ -139,6 +147,10 @@ SOURCE=..\lknoice.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkrel.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\lkrloc.c\r
 # End Source File\r
 # Begin Source File\r
@@ -147,6 +159,10 @@ SOURCE=.\lks19.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lksdcclib.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lkstore.c\r
 # End Source File\r
 # Begin Source File\r
@@ -167,7 +183,19 @@ SOURCE=..\aslink.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=..\..\..\sdcc_vc.h\r
+SOURCE=..\asxxxx_config.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\getline.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lklibr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lkrel.h\r
 # End Source File\r
 # End Group\r
 # End Target\r
index 503bef2b008ad10ed3097b70e0249400ca95b954..827ef48c57047cc86942132851a39aad461cfcea 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <asxxxx_config.h>
+
 #include "aslink.h"
 
 static int execStartMSB;
diff --git a/as/link/lklib.c b/as/link/lklib.c
new file mode 100644 (file)
index 0000000..b074351
--- /dev/null
@@ -0,0 +1,239 @@
+/* lklib.c */
+
+/*
+ * (C) Copyright 1989-1995
+ * All Rights Reserved
+ *
+ * Alan R. Baldwin
+ * 721 Berkeley St.
+ * Kent, Ohio  44240
+ *
+ * With contributions for the
+ * object libraries from
+ * Ken Hornstein
+ * kenh@cmf.nrl.navy.mil
+ *
+ */
+
+/*
+ * Extensions: P. Felber
+ */
+
+#include <string.h>
+
+#include "getline.h"
+#include "aslink.h"
+#include "lklibr.h"
+#include "lkrel.h"
+
+static int
+is_lib (FILE * libfp)
+{
+  return 1;
+}
+
+#ifdef INDEXLIB
+/* buildlibraryindex - build an in-memory cache of the symbols contained in
+ *                     the libraries
+ */
+static pmlibraryfile
+buildlibraryindex_lib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This, int type)
+{
+  char relfil[NINPUT];
+
+  while (getline (relfil, sizeof (relfil), libfp) != NULL)
+    {
+      FILE *fp;
+      char str[PATH_MAX];
+
+      if (lbnh->path != NULL)
+        {
+          strcpy (str, lbnh->path);
+#ifdef  OTHERSYSTEM
+          if ((*str != '\0') && (str[strlen (str) - 1] != '/') && (str[strlen (str) - 1] != LKDIRSEP))
+            {
+              strcat (str, LKDIRSEPSTR);
+            }
+#endif
+        }
+      else
+        str[0] = '\0';
+
+      if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
+        {
+          strcat (str, relfil + 1);
+        }
+      else
+        {
+          strcat (str, relfil);
+        }
+
+      if (strchr (relfil, FSEPX) == NULL)
+        {
+          sprintf (&str[strlen (str)], "%c%s", FSEPX, LKOBJEXT);
+        }
+
+      if ((fp = fopen (str, "rb")) != NULL)
+        {
+          /* Opened OK - create a new libraryfile object for it */
+          if (libr == NULL)
+            {
+              libr = This = (pmlibraryfile) new (sizeof (mlibraryfile));
+            }
+          else
+            {
+              This->next = (pmlibraryfile) new (sizeof (mlibraryfile));
+              This = This->next;
+            }
+          This->next = NULL;
+          This->loaded = -1;
+          This->libspc = lbnh->libspc;
+          This->relfil = strdup (relfil);
+          This->filename = strdup (str);
+          This->type = type;
+
+          /* Start a new linked list of symbols for this module: */
+          This->symbols = NULL;
+
+          add_rel_index (fp, -1, This);
+          fclose (fp);
+        }                       /* Closes if object file opened OK */
+      else
+        {
+          fprintf (stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
+        }
+    }                           /* Ends while - processing all in libr */
+
+  return This;
+}
+
+#else
+
+static int
+fndsym_lib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
+{
+  char relfil[NINPUT];
+
+  while (getline (relfil, sizeof (relfil), libfp) != NULL)
+    {
+      char str[PATH_MAX];
+      FILE *fp;
+
+      if (lbnh->path != NULL)
+        {
+          strcpy (str, lbnh->path);
+#ifdef  OTHERSYSTEM
+          if ((*str != '\0') && (str[strlen (str) - 1] != '/') && (str[strlen (str) - 1] != LKDIRSEP))
+            {
+              strcat (str, LKDIRSEPSTR);
+            }
+#endif
+        }
+      else
+        str[0] = '\0';
+
+      if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
+        {
+          strcat (str, relfil + 1);
+        }
+      else
+        {
+          strcat (str, relfil);
+        }
+
+      if (strchr (relfil, FSEPX) == NULL)
+        {
+          sprintf (&str[strlen (str)], "%c%s", FSEPX, LKOBJEXT);
+        }
+
+      if ((fp = fopen (str, "rb")) != NULL)
+        {
+          /* Opened OK - create a new libraryfile object for it */
+          int ret = add_rel_file (name, lbnh, relfil, str, -1, fp, -1, type);
+          fclose (fp);
+          if (ret)
+            {
+              /* if cdb information required & adb file present */
+              if (dflag && dfp)
+                {
+                  FILE *xfp = afile (str, "adb", 0);    //JCF: Nov 30, 2002
+                  if (xfp)
+                    {
+                      SaveLinkedFilePath (str);
+                      copyfile (dfp, xfp);
+                      fclose (xfp);
+                    }
+                }
+              return 1;         /* Found the symbol, so success! */
+            }
+        }                       /* Closes if object file opened OK */
+      else
+        {
+          fprintf (stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
+        }
+    }                           /* Ends while - processing all in libr */
+
+  return 0;                     /* The symbol is not in this library */
+}
+#endif
+
+/*)Function VOID    loadfile_lib(filspc)
+ *
+ *      char    *filspc     library object file specification
+ *
+ *  The function loadfile() links the library object module.
+ *
+ *  local variables:
+ *      FILE    *fp         file handle
+ *      int     i           input line length
+ *      char    str[]       file input line
+ *
+ *  global variables:
+ *      char    *ip         pointer to linker input string
+ *
+ *   functions called:
+ *      int     fclose()    c_library
+ *      char    *getline()  getline.c
+ *      FILE *  fopen()     c_library
+ *      VOID    link_main() lkmain.c
+ *      int     strlen()    c_library
+ *
+ *  side effects:
+ *      If file exists it is linked.
+ */
+
+static VOID
+loadfile_lib (struct lbfile *lbfh)
+{
+  FILE *fp;
+#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 (lbfh->filspc, posix_path);
+  fp = fopen (posix_path, "rb");
+#else
+  fp = fopen (lbfh->filspc, "rb");
+#endif
+
+  if (fp != NULL)
+    {
+      load_rel (fp, -1);
+      fclose (fp);
+    }
+  else
+    {
+      fprintf (stderr, "?ASlink-Error-Opening library '%s'\n", lbfh->filspc);
+      fclose (fp);
+      lkexit (1);
+    }
+}
+
+struct aslib_target aslib_target_lib = {
+  &is_lib,
+#ifdef INDEXLIB
+  &buildlibraryindex_lib,
+#else
+  &fndsym_lib,
+#endif
+  &loadfile_lib,
+};
index 31d2e897aa472176a5facd25e961d6a9cac5204a..c59becceaf0c1d0eb4094e3b52772e99bd2a0766 100644 (file)
  */
 
 #define EQ(A,B) !strcmp((A),(B))
-#define MAXLINE 254 /*when using fgets*/
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <assert.h>
+
 #include "aslink.h"
+#include "lkrel.h"
+#include "lklibr.h"
 
 /*)Module   lklibr.c
  *
  *
  */
 
-#ifdef INDEXLIB
-typedef struct slibrarysymbol mlibrarysymbol;
-typedef struct slibrarysymbol *pmlibrarysymbol;
-
-struct slibrarysymbol {
-    char * name; /*Warning: allocate memory before using*/
-    pmlibrarysymbol next;
-};
-
-typedef struct slibraryfile mlibraryfile;
-typedef struct slibraryfile *pmlibraryfile;
-
-struct slibraryfile {
-    int loaded;
-    char * libspc;
-    char * relfil; /*Warning: allocate memory before using*/
-    char * filename; /*Warning: allocate memory before using*/
-    long offset; //if > 0, the embedded file offset in the library file libspc
-    pmlibrarysymbol symbols;
-    pmlibraryfile next;
-};
+#define NELEM(x) (sizeof (x) / sizeof (*x))
 
+#ifdef INDEXLIB
 /* First entry in the library object symbol cache */
-pmlibraryfile libr=NULL;
+pmlibraryfile libr = NULL;
 
-int buildlibraryindex(void);
+int buildlibraryindex (void);
 void freelibraryindex (void);
 #endif /* INDEXLIB */
 
+struct aslib_target *aslib_targets[] = {
+  &aslib_target_sdcclib,
+  &aslib_target_lib,
+};
+
 /*)Function VOID    addpath()
  *
  *  The function addpath() creates a linked structure containing
@@ -101,24 +90,26 @@ void freelibraryindex (void);
  */
 
 VOID
-addpath(void)
+addpath (void)
 {
-    struct lbpath *lbph, *lbp;
-
-    lbph = (struct lbpath *) new (sizeof(struct lbpath));
-    if (lbphead == NULL) {
-        lbphead = lbph;
-    } else {
-        lbp = lbphead;
-        while (lbp->next)
+  struct lbpath *lbph, *lbp;
+
+  lbph = (struct lbpath *) new (sizeof (struct lbpath));
+  if (lbphead == NULL)
+    {
+      lbphead = lbph;
+    }
+  else
+    {
+      lbp = lbphead;
+      while (lbp->next)
         {
-            lbp = lbp->next;
+          lbp = lbp->next;
         }
-        lbp->next = lbph;
+      lbp->next = lbph;
     }
-    unget(getnb());
-    lbph->path = (char *) new (strlen(ip)+1);
-    strcpy(lbph->path, ip);
+  unget (getnb ());
+  lbph->path = strdup (ip);
 }
 
 /*)Function VOID    addlib()
@@ -149,27 +140,27 @@ addpath(void)
  */
 
 VOID
-addlib(void)
+addlib (void)
 {
-    struct lbpath *lbph;
-    int foundcount=0;
+  struct lbpath *lbph;
+  int foundcount = 0;
 
-    unget(getnb());
+  unget (getnb ());
 
-    if (lbphead == NULL)
+  if (lbphead == NULL)
     {
-        foundcount=addfile(NULL, ip);
+      foundcount = addfile (NULL, ip);
     }
-    else
+  else
     {
-        for (lbph=lbphead; lbph; lbph=lbph->next)
+      for (lbph = lbphead; lbph; lbph = lbph->next)
         {
-            foundcount+=addfile(lbph->path, ip);
+          foundcount += addfile (lbph->path, ip);
         }
     }
-    if(foundcount == 0)
+  if (foundcount == 0)
     {
-        fprintf(stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
+      fprintf (stderr, "?ASlink-Warning-Couldn't find library '%s'\n", ip);
     }
 }
 
@@ -211,110 +202,111 @@ addlib(void)
  *      0: the library was not found
  */
 
-int addfile(char * path, char * libfil)
+int
+addfile (char *path, char *libfil)
 {
-    FILE *fp;
-    char *str;
-    struct lbname *lbnh, *lbn;
+  FILE *fp;
+  char *str;
+  struct lbname *lbnh, *lbn;
 #ifdef  OTHERSYSTEM
-    int libfilinc=0;
+  int libfilinc = 0;
 #endif
 
-    if (path != NULL)
+  if (path != NULL)
     {
-        str = (char *) new (strlen(path) + strlen(libfil) + 6);
-        strcpy(str, path);
+      str = (char *) new (strlen (path) + strlen (libfil) + 6);
+      strcpy (str, path);
 #ifdef  OTHERSYSTEM
-        if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
+      if (strlen (str) && (str[strlen (str) - 1] != '/') && (str[strlen (str) - 1] != LKDIRSEP))
         {
-            strcat(str, LKDIRSEPSTR);
+          strcat (str, LKDIRSEPSTR);
         }
 #endif
     }
-    else
+  else
     {
-        str = (char *) new (strlen(libfil) + 5);
+      str = (char *) new (strlen (libfil) + 5);
     }
 
 #ifdef  OTHERSYSTEM
-    if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
+  if ((libfil[0] == '/') || (libfil[0] == LKDIRSEP))
     {
-        libfil++;
-        libfilinc=1;
+      libfil++;
+      libfilinc = 1;
     }
 #endif
 
-    strcat(str, libfil);
-    if(strchr(libfil, FSEPX) == NULL)
+  strcat (str, libfil);
+  if (strchr (libfil, FSEPX) == NULL)
     {
-        sprintf(&str[strlen(str)], "%clib", FSEPX);
+      sprintf (&str[strlen (str)], "%clib", FSEPX);
     }
 
-    fp=fopen(str, "r");
-    if(fp == NULL)
+  fp = fopen (str, "rb");
+  if (fp == NULL)
     {
-        /*Ok, that didn't work.  Try with the 'libfil' name only*/
+      /*Ok, that didn't work.  Try with the 'libfil' name only */
 #ifdef  OTHERSYSTEM
-        if(libfilinc) libfil--;
+      if (libfilinc)
+        libfil--;
 #endif
-        fp=fopen(libfil, "r");
-        if(fp != NULL)
+      fp = fopen (libfil, "rb");
+      if (fp != NULL)
         {
-            /*Bingo!  'libfil' is the absolute path of the library*/
-            strcpy(str, libfil);
-            path=NULL;/*This way 'libfil' and 'path' will be rebuilt from 'str'*/
+          /*Bingo!  'libfil' is the absolute path of the library */
+          strcpy (str, libfil);
+          path = NULL;          /*This way 'libfil' and 'path' will be rebuilt from 'str' */
         }
     }
 
-    if(path==NULL)
+  if (path == NULL)
     {
-        /*'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'.*/
-        int j;
-        path = (char *) new (strlen(str) + 1);
-        strcpy(path, str);
-        for(j=strlen(path)-1; j>=0; j--)
+      /*'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'. */
+      int j;
+      path = strdup (str);
+      for (j = strlen (path) - 1; j >= 0; j--)
         {
-            if((path[j] == '/') || (path[j] == LKDIRSEP))
+          if ((path[j] == '/') || (path[j] == LKDIRSEP))
             {
-                strcpy(libfil, &path[j+1]);
-                path[j+1]=0;
-                break;
+              strcpy (libfil, &path[j + 1]);
+              path[j + 1] = 0;
+              break;
             }
         }
-        if(j<=0) path[0]=0;
+      if (j <= 0)
+        path[0] = 0;
     }
 
-    if (fp != NULL)
+  if (fp != NULL)
     {
-        fclose(fp);
-        lbnh = (struct lbname *) new (sizeof(struct lbname));
-        if (lbnhead == NULL)
+      fclose (fp);
+      lbnh = (struct lbname *) new (sizeof (struct lbname));
+      if (lbnhead == NULL)
         {
-            lbnhead = lbnh;
+          lbnhead = lbnh;
         }
-        else
+      else
         {
-            lbn = lbnhead;
-            while (lbn->next)
+          lbn = lbnhead;
+          while (lbn->next)
             {
-                lbn = lbn->next;
+              lbn = lbn->next;
             }
-            lbn->next = lbnh;
+          lbn->next = lbnh;
         }
 
-        lbnh->path = path;
-        lbnh->libfil = (char *) new (strlen(libfil) + 1);
-        strcpy(lbnh->libfil, libfil);
-        lbnh->libspc = str;
-        return 1;
+      lbnh->path = path;
+      lbnh->libfil = strdup (libfil);
+      lbnh->libspc = str;
+      return 1;
     }
-    else
+  else
     {
-        free(str);
-        return 0;
+      free (str);
+      return 0;
     }
 }
 
@@ -350,233 +342,46 @@ int addfile(char * path, char * libfil)
  */
 
 VOID
-search(void)
-{
-    register struct sym *sp;
-    register int i, symfnd;
-
-    /*
-     * Look for undefined symbols.  Keep
-     * searching until no more symbols are resolved.
-     */
-    symfnd = 1;
-    while (symfnd) {
-        symfnd = 0;
-        /*
-         * Look through all the symbols
-         */
-        for (i=0; i<NHASH; ++i) {
-            sp = symhash[i];
-            while (sp) {
-                /* If we find an undefined symbol
-                 * (one where S_DEF is not set), then
-                 * try looking for it.  If we find it
-                 * in any of the libraries then
-                 * increment symfnd.  This will force
-                 * another pass of symbol searching and
-                 * make sure that back references work.
-                 */
-                if ((sp->s_type & S_DEF) == 0) {
-                    if (fndsym(sp->s_id)) {
-                        symfnd++;
-                    }
-                }
-                sp = sp->s_sp;
-            }
-        }
-    }
-}
-
-/*Load a .rel file embedded in a sdcclib file*/
-void LoadRel(char * libfname, FILE * libfp, char * ModName)
+search (void)
 {
-    char str[NINPUT+2];
-    int state=0;
-
-    while (fgets(str, NINPUT, libfp) != NULL)
+  register struct sym *sp;
+  register int i, symfnd;
+
+  /*
+   * Look for undefined symbols.  Keep
+   * searching until no more symbols are resolved.
+   */
+  symfnd = 1;
+  while (symfnd)
     {
-        str[NINPUT+1] = '\0';
-        chop_crlf(str);
-        switch(state)
+      symfnd = 0;
+      /*
+       * Look through all the symbols
+       */
+      for (i = 0; i < NHASH; ++i)
         {
-            case 0:
-                if(EQ(str, "<FILE>"))
-                {
-                    fgets(str, NINPUT, libfp);
-                    str[NINPUT+1] = '\0';
-                    chop_crlf(str);
-                    if(EQ(str, ModName)) state=1;
-                    else
-                    {
-                        fprintf(stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n",
-                            libfname, ModName);
-                        lkexit(1);
-                    }
-                }
-            break;
-            case 1:
-                if(EQ(str, "<REL>")) state=2;
-            break;
-            case 2:
-                if(EQ(str, "</REL>")) return;
-                ip = str;
-                link_main();
-            break;
-        }
-    }
-}
-
-/*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
+          sp = symhash[i];
+          while (sp)
+            {
+              /* If we find an undefined symbol
+               * (one where S_DEF is not set), then
+               * try looking for it.  If we find it
+               * in any of the libraries then
+               * increment symfnd.  This will force
+               * another pass of symbol searching and
+               * make sure that back references work.
+               */
+              if ((sp->s_type & S_DEF) == 0)
                 {
-                    /*Check if this is the symbol we are looking for.*/
-                    if (strncmp(SymName, FLine, NCPS)==0)
+                  if (fndsym (sp->s_id))
                     {
-                        /*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);
-
-                        /* if cdb information required & .adb file present */
-                        if (dflag && dfp)
-                        {
-                            if(LoadAdb(libfp))
-                                SaveLinkedFilePath(DirLib);
-                        }
-                        return 1; /*Found the symbol, so success!*/
+                      symfnd++;
                     }
                 }
-            break;
-
-            default:
-                return 0; /*It should never reach this point, but just in case...*/
-            break;
+              sp = sp->s_sp;
+            }
         }
     }
-
-    return 0; /*The symbol is not in this library*/
 }
 
 /*)Function VOID    fndsym(name)
@@ -627,7 +432,6 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
  *
  *   functions called:
  *      int     fclose()    c_library
- *      int     fgets()     c_library
  *      FILE    *fopen()    c_library
  *      VOID    free()      c_library
  *      char    getnb()     lklex.c
@@ -651,602 +455,321 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName)
  */
 
 #ifdef INDEXLIB
-
-int fndsym( char *name )
+int
+fndsym (char *name)
 {
-    struct lbfile *lbfh, *lbf;
-    pmlibraryfile ThisLibr;
-    pmlibrarysymbol ThisSym = NULL;
+  struct lbfile *lbfh, *lbf;
+  pmlibraryfile ThisLibr;
+  pmlibrarysymbol ThisSym = NULL;
 
-    pmlibraryfile FirstFound;
-    int numfound=0;
+  pmlibraryfile FirstFound;
+  int numfound = 0;
 
-    /* Build the index if this is the first call to fndsym */
-    if (libr==NULL) buildlibraryindex();
+  /* Build the index if this is the first call to fndsym */
+  if (libr == NULL)
+    buildlibraryindex ();
 
-    /* Iterate through all library object files */
-    ThisLibr = libr;
-    FirstFound = libr; /*So gcc stops whining*/
-    while (ThisLibr)
+  /* Iterate through all library object files */
+  ThisLibr = libr;
+  FirstFound = libr;            /*So gcc stops whining */
+  while (ThisLibr)
     {
-        /* Iterate through all symbols in an object file */
-        ThisSym = ThisLibr->symbols;
+      /* Iterate through all symbols in an object file */
+      ThisSym = ThisLibr->symbols;
 
-        while (ThisSym)
+      while (ThisSym)
         {
-            if (!strcmp(ThisSym->name, name))
+          if (!strcmp (ThisSym->name, name))
             {
-                if ((!ThisLibr->loaded) && (numfound==0))
+              if ((!ThisLibr->loaded) && (numfound == 0))
                 {
-                    /* Object file is not loaded - add it to the list */
-                    lbfh = (struct lbfile *) new (sizeof(struct lbfile));
-                    if (lbfhead == NULL)
+                  /* Object file is not loaded - add it to the list */
+                  lbfh = (struct lbfile *) new (sizeof (struct lbfile));
+                  if (lbfhead == NULL)
                     {
-                        lbfhead = lbfh;
+                      lbfhead = lbfh;
                     }
-                    else
+                  else
                     {
-                        lbf = lbfhead;
-                        while (lbf->next)
-                        {
-                            lbf = lbf->next;
-                        }
-                        lbf->next = lbfh;
-                    }
-                    lbfh->libspc = ThisLibr->libspc;
-                    lbfh->filspc = ThisLibr->filename;
-                    lbfh->relfil = (char *) new (strlen(ThisLibr->relfil) + 1);
-                    strcpy(lbfh->relfil, ThisLibr->relfil);
-                    lbfh->offset = ThisLibr->offset;
-                    if(lbfh->offset>0)
-                    { /*For an embedded object file in a library*/
-                        void loadfile_SdccLib(char * libspc, char * module, long offset);
-                        loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
-                    }
-                    else
-                    { /*For a stand alone object file*/
-                        /* if cdb information required & adb file present */
-                        if (dflag && dfp)
+                      lbf = lbfhead;
+                      while (lbf->next)
                         {
-                            FILE *xfp = afile(lbfh->filspc, "adb",0);
-                            if (xfp)
-                            {
-                                SaveLinkedFilePath(lbfh->filspc);
-                                copyfile(dfp, xfp);
-                                fclose(xfp);
-                            }
+                          lbf = lbf->next;
                         }
-                        loadfile(lbfh->filspc);
+                      lbf->next = lbfh;
                     }
-                    ThisLibr->loaded=1;
+                  lbfh->libspc = ThisLibr->libspc;
+                  lbfh->filspc = ThisLibr->filename;
+                  lbfh->relfil = strdup (ThisLibr->relfil);
+                  lbfh->offset = ThisLibr->offset;
+                  lbfh->type = ThisLibr->type;
+
+                  (*aslib_targets[lbfh->type]->loadfile) (lbfh);
+
+                  ThisLibr->loaded = 1;
                 }
 
-                if(numfound==0)
+              if (numfound == 0)
                 {
-                    numfound++;
-                    FirstFound=ThisLibr;
+                  numfound++;
+                  FirstFound = ThisLibr;
                 }
-                else
+              else
                 {
-                    char absPath1[PATH_MAX];
-                    char absPath2[PATH_MAX];
+                  char absPath1[PATH_MAX];
+                  char absPath2[PATH_MAX];
 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
-                    int j;
-
-                    _fullpath(absPath1, FirstFound->libspc, PATH_MAX);
-                    _fullpath(absPath2, ThisLibr->libspc, PATH_MAX);
-                    for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]);
-                    for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]);
+                  int j;
+
+                  _fullpath (absPath1, FirstFound->libspc, PATH_MAX);
+                  _fullpath (absPath2, ThisLibr->libspc, PATH_MAX);
+                  for (j = 0; absPath1[j] != 0; j++)
+                    absPath1[j] = tolower ((unsigned char) absPath1[j]);
+                  for (j = 0; absPath2[j] != 0; j++)
+                    absPath2[j] = tolower ((unsigned char) absPath2[j]);
 #else
-                    realpath(FirstFound->libspc, absPath1);
-                    realpath(ThisLibr->libspc, absPath2);
+                  realpath (FirstFound->libspc, absPath1);
+                  realpath (ThisLibr->libspc, absPath2);
 #endif
-                    if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) )
+                  if (!(EQ (absPath1, absPath2) && EQ (FirstFound->relfil, ThisLibr->relfil)))
                     {
-                        if(numfound==1)
+                      if (numfound == 1)
                         {
-                            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);
+                          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);
                         }
-                        fprintf(stderr, "   Library: '%s', Module: '%s'\n",
-                                ThisLibr->libspc, ThisLibr->relfil);
-                        numfound++;
+                      fprintf (stderr, "   Library: '%s', Module: '%s'\n", ThisLibr->libspc, ThisLibr->relfil);
+                      numfound++;
                     }
                 }
             }
-            ThisSym=ThisSym->next;  /* Next sym in library */
+          ThisSym = ThisSym->next;      /* Next sym in library */
         }
-        ThisLibr=ThisLibr->next; /* Next library in list */
+      ThisLibr = ThisLibr->next;        /* Next library in list */
     }
-    return numfound;
+  return numfound;
 }
 
-pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * DirLib, pmlibraryfile This)
+struct add_sym_s
 {
-    char ModName[NCPS]="";
-    char FLine[MAXLINE+1];
-    char buff[PATH_MAX];
-    int state=0;
-    long IndexOffset=0, FileOffset;
-    pmlibrarysymbol ThisSym = NULL;
-
-    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;
-
-                    /*Create a new libraryfile object for this module*/
-                    if(libr==NULL)
-                    {
-                        libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
-                    }
-                    else
-                    {
-                        This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
-                        This=This->next;
-                    }
-                    This->next = NULL;
-                    This->loaded=-1;
-                    This->offset=FileOffset+IndexOffset;
-                    This->libspc=PathLib;
+  pmlibraryfile plf;
+  pmlibrarysymbol pls;
+};
 
-                    This->relfil=(char *)new(strlen(ModName)+1);
-                    strcpy(This->relfil, ModName);
+static int
+add_sybmol (const char *sym, void *param)
+{
+  struct add_sym_s *as = (struct add_sym_s *) param;
+  pmlibrarysymbol ps = (pmlibrarysymbol) new (sizeof (mlibrarysymbol));
 
-                    sprintf(buff, "%s%s%c%s", DirLib, ModName, FSEPX, LKOBJEXT);
-                    This->filename=(char *)new(strlen(buff)+1);
-                    strcpy(This->filename, buff);
+  as->plf->loaded = 0;
+  ps->next = NULL;
+  ps->name = strdup (sym);
 
-                    This->symbols=ThisSym=NULL; /*Start a new linked list of symbols*/
-                }
-                else if(EQ(FLine, "</INDEX>"))
-                {
-                    return This; /*Finish, get out of here*/
-                }
-            break;
-            case 2:
-                if(EQ(FLine, "</MODULE>"))
-                {
-                    This->loaded=0;
-                    /*Create the index for the next module*/
-                    state=1;
-                }
-                else
-                {
-                    /*Add the symbols*/
-                    if(ThisSym==NULL) /*First symbol of the current module*/
-                    {
-                        ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
-                    }
-                    else
-                    {
-                        ThisSym->next = (pmlibrarysymbol)new(sizeof(mlibrarysymbol));
-                        ThisSym=ThisSym->next;
-                    }
-                    ThisSym->next=NULL;
-                    ThisSym->name=(char *)new(strlen(FLine)+1);
-                    strcpy(ThisSym->name, FLine);
-                }
-            break;
-
-            default:
-                return This; /*State machine should never reach this point, but just in case...*/
-            break;
-        }
+  if (as->pls == NULL)
+    {
+      as->pls = as->plf->symbols = ps;
+    }
+  else
+    {
+      as->pls->next = ps;
+      as->pls = as->pls->next;
     }
 
-    return This; /*State machine should never reach this point, but just in case...*/
+  return 0;
 }
 
+pmlibrarysymbol
+add_rel_index (FILE * fp, long size, pmlibraryfile This)
+{
+  struct add_sym_s as;
+  as.plf = This;
+  as.pls = This->symbols;
+
+  assert (This->symbols == NULL);
+
+  enum_symbols (fp, size, &add_sybmol, &as);
+
+  return as.pls;
+}
 
 /* buildlibraryindex - build an in-memory cache of the symbols contained in
  *                     the libraries
  */
-int buildlibraryindex(void)
+int
+buildlibraryindex (void)
 {
-    FILE *libfp, *fp;
-    struct lbname *lbnh;
-    char relfil[NINPUT+2], str[PATH_MAX], *path;
-    char buf[NINPUT+2], c;
-    char symname[NINPUT+2];
-    pmlibraryfile This=NULL;
-    pmlibrarysymbol ThisSym;
-
-    /*
-     * Search through every library in the linked list "lbnhead".
-     */
-    for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
+  pmlibraryfile This = NULL;
+  struct lbname *lbnh;
+
+  /*
+   * Search through every library in the linked list "lbnhead".
+   */
+  for (lbnh = lbnhead; lbnh; lbnh = lbnh->next)
     {
-        if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
+      FILE *libfp;
+      int i;
+
+      if ((libfp = fopen (lbnh->libspc, "rb")) == NULL)
         {
-            fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
-                lbnh->libspc);
-            lkexit(1);
+          fprintf (stderr, "?ASlink-Error-Cannot open library file %s\n", lbnh->libspc);
+          lkexit (1);
         }
-        path = lbnh->path;
 
-        /*
-         * Read in a line from the library file.
-         * This is the relative file specification
-         * for a .REL file in this library.
-         */
-
-        while (fgets(relfil, NINPUT, libfp) != NULL)
+      for (i = 0; i < NELEM (aslib_targets); ++i)
         {
-            relfil[NINPUT+1] = '\0';
-            chop_crlf(relfil);
-            if (path != NULL)
+          if ((*aslib_targets[i]->is_lib) (libfp))
             {
-                strcpy(str, path);
-#ifdef  OTHERSYSTEM
-                if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
-                {
-                    strcat(str, LKDIRSEPSTR);
-                }
-#endif
+              This = (*aslib_targets[i]->buildlibraryindex) (lbnh, libfp, This, i);
+              break;
             }
-            else
-            {
-                strcpy(str, "");
-            }
-
-            if(strcmp(relfil, "<SDCCLIB>")==0)
-            {
-                /*Get the built in index of this library*/
-                This=buildlibraryindex_SdccLib(lbnh->libspc, libfp, str, This);
-                break; /*get the index for next library*/
-            }
-
-            /*From here down, build the index for the original library format*/
-
-            if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
-            {
-                strcat(str, relfil+1);
-            }
-            else
-            {
-                strcat(str, relfil);
-            }
-
-            if(strchr(relfil, FSEPX) == NULL)
-            {
-                sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
-            }
-
-            if ((fp = fopen(str, "r")) != NULL)
-            {
-                /* Opened OK - create a new libraryfile object for it */
-                if(libr==NULL)
-                {
-                    libr=This=(pmlibraryfile)new( sizeof( mlibraryfile ));
-                }
-                else
-                {
-                    This->next=(pmlibraryfile)new( sizeof( mlibraryfile ));
-                    This=This->next;
-                }
-                This->next = NULL;
-                This->loaded=-1;
-                This->offset=-1; /*We have a stand alone .rel file*/
-                This->libspc = lbnh->libspc;
-
-                This->relfil=(char *)new(strlen(relfil)+1);
-                strcpy(This->relfil, relfil);
-
-                This->filename=(char *)new(strlen(str)+1);
-                strcpy(This->filename, str);
-
-                /*Start a new linked list of symbols for this module:*/
-                This->symbols = ThisSym = NULL;
-
-                /*
-                 * Read in the object file.  Look for lines that
-                 * begin with "S" and end with "D".  These are
-                 * symbol table definitions.  If we find one, see
-                 * if it is our symbol.  Make sure we only read in
-                 * our object file and don't go into the next one.
-                 */
-
-                while (fgets(buf, NINPUT, fp) != NULL)
-                {
-                    buf[NINPUT+1] = '\0';
-                    buf[strlen(buf) - 1] = '\0';
-
-                    /*
-                     * Skip everything that's not a symbol record.
-                     */
-                    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;
+      if (i >= NELEM (aslib_targets))
+        fprintf (stderr, "?ASlink-Error-Unknown library file format %s\n", lbnh->libspc);
 
-                    sscanf(buf, "S %s %c", symname, &c);
+      fclose (libfp);
+    }
 
-                    /* If it's an actual symbol, record it */
-                    if (c == 'D')
-                    {
-                        if(ThisSym==NULL)
-                        {
-                            ThisSym=This->symbols=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
-                        }
-                        else
-                        {
-                            ThisSym->next=(pmlibrarysymbol)new(sizeof(mlibrarysymbol));
-                            ThisSym=ThisSym->next;
-                        }
-                        This->loaded=0;
-                        ThisSym->next=NULL;
-                        ThisSym->name=(char *)new(strlen(symname)+1);
-                        strcpy(ThisSym->name, symname);
-                    }
-                } /* 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);
-            }
-        } /* Ends while - processing all in libr */
-        fclose(libfp);
-    } /* Ends good open of libr file */
-    return 0;
+  return 0;
 }
 
 /*Release all memory allocated for the in-memory library index*/
-void freelibraryindex (void)
+void
+freelibraryindex (void)
 {
-    pmlibraryfile ThisLibr, ThisLibr2Free;
-    pmlibrarysymbol ThisSym, ThisSym2Free;
+  pmlibraryfile ThisLibr, ThisLibr2Free;
+  pmlibrarysymbol ThisSym, ThisSym2Free;
 
-    ThisLibr = libr;
+  ThisLibr = libr;
 
-    while (ThisLibr)
+  while (ThisLibr)
     {
-        ThisSym = ThisLibr->symbols;
+      ThisSym = ThisLibr->symbols;
 
-        while (ThisSym)
+      while (ThisSym)
         {
-            free(ThisSym->name);
-            ThisSym2Free=ThisSym;
-            ThisSym=ThisSym->next;
-            free(ThisSym2Free);
+          free (ThisSym->name);
+          ThisSym2Free = ThisSym;
+          ThisSym = ThisSym->next;
+          free (ThisSym2Free);
         }
-        free(ThisLibr->filename);
-        free(ThisLibr->relfil);
-        ThisLibr2Free=ThisLibr;
-        ThisLibr=ThisLibr->next;
-        free(ThisLibr2Free);
+      free (ThisLibr->filename);
+      free (ThisLibr->relfil);
+      ThisLibr2Free = ThisLibr;
+      ThisLibr = ThisLibr->next;
+      free (ThisLibr2Free);
     }
 
-    libr=NULL;
+  libr = NULL;
 }
 
 #else /* INDEXLIB */
 
-int
-fndsym(char *name)
+struct load_sym_s
+{
+  const char *name;
+  struct lbname *lbnh;
+  const char *relfil;
+  const char *filspc;
+  int offset;
+  int type;
+};
+
+static int
+load_sybmol (const char *sym, void *params)
 {
-    FILE *libfp, *fp;
-    struct lbname *lbnh;
-    struct lbfile *lbfh, *lbf;
-    char relfil[NINPUT+2];
-    char buf[NINPUT+2];
-    char symname[NINPUT];
-    char *path,*str;
-    char c;
-    int result;
-
-    /*
-     * Search through every library in the linked list "lbnhead".
-     */
-
-    for (lbnh=lbnhead; lbnh; lbnh=lbnh->next)
+  struct load_sym_s *ls = (struct load_sym_s *) params;
+
+  if (strcmp (ls->name, sym) == 0)
     {
-        if ((libfp = fopen(lbnh->libspc, "r")) == NULL)
-        {
-            fprintf(stderr, "?ASlink-Error-Cannot open library file %s\n",
-                lbnh->libspc);
-            lkexit(1);
-        }
-        path = lbnh->path;
+      struct lbfile *lbfh, *lbf;
 
-        /*
-         * Read in a line from the library file.
-         * This is the relative file specification
-         * for a .REL file in this library.
-         */
+      lbfh = (struct lbfile *) new (sizeof (struct lbfile));
+      lbfh->libspc = ls->lbnh->libspc;
+      lbfh->relfil = strdup (ls->relfil);
+      lbfh->filspc = strdup (ls->filspc);
+      lbfh->offset = ls->offset;
+      lbfh->type = ls->type;
 
-        while (fgets(relfil, NINPUT, libfp) != NULL)
+      if (lbfhead == NULL)
         {
-            relfil[NINPUT+1] = '\0';
-            chop_crlf(relfil);
-            if (path != NULL)
-            {
-                str = (char *) new (strlen(path)+strlen(relfil)+6);
-                strcpy(str,path);
-#ifdef  OTHERSYSTEM
-                if (strlen(str) && (str[strlen(str)-1] != '/') && (str[strlen(str)-1] != LKDIRSEP))
-                {
-                    strcat(str, LKDIRSEPSTR);
-                }
-#endif
-            }
-            else
+          lbfhead = lbfh;
+        }
+      else
+        {
+          lbf = lbfhead;
+          while (lbf->next)
             {
-                str = (char *) new (strlen(relfil) + 5);
+              lbf = lbf->next;
             }
+          lbf->next = lbfh;
+        }
 
-            /*See if this is a library with embedded files*/
-            if(strcmp(relfil, "<SDCCLIB>")==0)
-            {
-                result=SdccLib(lbnh->libspc, libfp, str, name);
-                if(result) return(1); /*Found the symbol*/
-                free(str);
-                /*The symbol is not in the current library,
-                check the next library in the list*/
-                break;
-            }
+      (*aslib_targets[ls->type]->loadfile) (lbfh);
 
-            /*From here down is the support for libraries in the original format*/
-            if ((relfil[0] == '/') || (relfil[0] == LKDIRSEP))
-            {
-                strcat(str, relfil+1);
-            }
-            else
-            {
-                strcat(str, relfil);
-            }
+      return 1;
+    }
+  else
+    return 0;
+}
 
-            if(strchr(relfil, FSEPX) == NULL)
-            {
-                sprintf(&str[strlen(str)], "%c%s", FSEPX, LKOBJEXT);
-            }
+int
+add_rel_file (const char *name, struct lbname *lbnh, const char *relfil,
+              const char *filspc, int offset, FILE * fp, long size, int type)
+{
+  struct load_sym_s ls;
+  ls.name = name;
+  ls.lbnh = lbnh;
+  ls.relfil = relfil;
+  ls.filspc = filspc;
+  ls.offset = offset;
+  ls.type = type;
+
+  return enum_symbols (fp, size, &load_sybmol, &ls);
+}
 
-            if ((fp = fopen(str, "r")) != NULL)
-            {
-                /*
-                 * Read in the object file.  Look for lines that
-                 * begin with "S" and end with "D".  These are
-                 * symbol table definitions.  If we find one, see
-                 * if it is our symbol.  Make sure we only read in
-                 * our object file and don't go into the next one.
-                 */
-
-                while (fgets(buf, NINPUT, fp) != NULL)
-                {
-                    buf[NINPUT+1] = '\0';
-                    chop_crlf(buf);
-                    /*
-                     * Skip everything that's not a symbol record.
-                     */
-                    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;
-
-                    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 (strncmp(symname, name, NCPS) == 0 && c == 'D')
-                    {
-                        lbfh = (struct lbfile *) new (sizeof(struct lbfile));
-                        if (lbfhead == NULL)
-                        {
-                            lbfhead = lbfh;
-                        }
-                        else
-                        {
-                            lbf = lbfhead;
-                            while (lbf->next)
-                            {
-                                lbf = lbf->next;
-                            }
-                            lbf->next = lbfh;
-                        }
+int
+fndsym (const char *name)
+{
+  FILE *libfp;
+  struct lbname *lbnh;
+  int i;
+
+  /*
+   * Search through every library in the linked list "lbnhead".
+   */
+  for (lbnh = lbnhead; lbnh; lbnh = lbnh->next)
+    {
+      int ret;
 
-                        lbfh->libspc = lbnh->libspc;
-                        lbfh->filspc = str;
-                        lbfh->relfil = (char *) new (strlen(relfil) + 1);
-                        lbfh->offset = -1; /*Stand alone rel file*/
-                        strcpy(lbfh->relfil,relfil);
-                        fclose(fp);
-                        fclose(libfp);
+      if ((libfp = fopen (lbnh->libspc, "rb")) == NULL)
+        {
+          fprintf (stderr, "?ASlink-Error-Cannot open library file %s\n", lbnh->libspc);
+          lkexit (1);
+        }
 
-                        /* if cdb information required & adb file present */
-                        if (dflag && dfp)
-                        {
-                            FILE *xfp = afile(str,"adb",0); //JCF: Nov 30, 2002
-                            if (xfp)
-                            {
-                                SaveLinkedFilePath(str);
-                                copyfile(dfp,xfp);
-                                fclose(xfp);
-                            }
-                        }
-                        loadfile(str);
-                        return (1);
-                    }
-                } /* Closes while - read object file */
-                fclose(fp);
-            } /* Closes if object file opened OK */
-            else
+      for (i = 0; i < NELEM (aslib_targets); ++i)
+        {
+          if ((*aslib_targets[i]->is_lib) (libfp))
             {
-                fprintf(stderr, "?ASlink-Warning-Cannot open library module %s\n", str);
+              ret = (*aslib_targets[i]->fndsym) (name, lbnh, libfp, i);
+              break;
             }
-            free(str);
-        } /* Ends while - processing all in libr */
-        fclose(libfp);
-    } /* Ends good open of libr file */
-    return(0);
-}
+        }
 
-#endif /* INDEXLIB */
+      if (i >= NELEM (aslib_targets))
+        fprintf (stderr, "?ASlink-Error-Unknown library file format %s\n", lbnh->libspc);
 
-void loadfile_SdccLib(char * libspc, char * module, long offset)
-{
-    FILE *fp;
+      fclose (libfp);
 
-#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 (!ret)
+        break;
 
-    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);
-    }
+    }                           /* Ends good open of libr file */
+  return 0;
 }
+#endif /* INDEXLIB */
 
 /*)Function VOID    library()
  *
@@ -1267,82 +790,14 @@ void loadfile_SdccLib(char * libspc, char * module, long offset)
  */
 
 VOID
-library(void)
+library (void)
 {
-    struct lbfile *lbfh;
-
-    for (lbfh=lbfhead; lbfh; lbfh=lbfh->next)
-    {
-        if(lbfh->offset<0)
-        {
-            /*Stand alone rel file (original lib format)*/
-            loadfile(lbfh->filspc);
-        }
-        else
-        {
-            /*rel file embedded in lib (new lib format)*/
-            loadfile_SdccLib(lbfh->libspc, lbfh->relfil, lbfh->offset);
-        }
-    }
-#ifdef INDEXLIB
-    freelibraryindex();
-#endif
-}
+  struct lbfile *lbfh;
 
-/*)Function VOID    loadfile(filspc)
- *
- *      char    *filspc     library object file specification
- *
- *  The function loadfile() links the library object module.
- *
- *  local variables:
- *      FILE    *fp         file handle
- *      int     i           input line length
- *      char    str[]       file input line
- *
- *  global variables:
- *      char    *ip         pointer to linker input string
- *
- *   functions called:
- *      int     fclose()    c_library
- *      int     fgets()     c_library
- *      FILE *  fopen()     c_library
- *      VOID    link_main() lkmain.c
- *      int     strlen()    c_library
- *
- *  side effects:
- *      If file exists it is linked.
- */
+  for (lbfh = lbfhead; lbfh; lbfh = lbfh->next)
+    (*aslib_targets[lbfh->type]->loadfile) (lbfh);
 
-VOID
-loadfile(char *filspc)
-{
-    FILE *fp;
-    char str[NINPUT+2];
-
-#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");
+#ifdef INDEXLIB
+  freelibraryindex ();
 #endif
-
-    if (fp != NULL)
-    {
-        while (fgets(str, NINPUT, fp) != NULL)
-        {
-            str[NINPUT+1] = '\0';
-            chop_crlf(str);
-            ip = str;
-            link_main();
-        }
-        fclose(fp);
-    }
-    else
-    {
-        fprintf(stderr, "?ASlink-Error-Opening library '%s'\n", filspc);
-        lkexit(1);
-    }
 }
diff --git a/as/link/lklibr.h b/as/link/lklibr.h
new file mode 100644 (file)
index 0000000..47dafe2
--- /dev/null
@@ -0,0 +1,74 @@
+/* lklibr.h */
+
+/*
+ * (C) Copyright 1989-1995
+ * All Rights Reserved
+ *
+ * Alan R. Baldwin
+ * 721 Berkeley St.
+ * Kent, Ohio  44240
+ *
+ * With contributions for the
+ * object libraries from
+ * Ken Hornstein
+ * kenh@cmf.nrl.navy.mil
+ *
+ */
+
+/*
+ * Extensions: P. Felber
+ */
+
+#ifndef __LKLIBR_H
+#define __LKLIBR_H
+
+#include <stdio.h>
+
+typedef struct slibrarysymbol mlibrarysymbol;
+typedef struct slibrarysymbol *pmlibrarysymbol;
+
+struct slibrarysymbol
+{
+  char *name;                   /*Warning: allocate memory before using */
+  pmlibrarysymbol next;
+};
+
+typedef struct slibraryfile mlibraryfile;
+typedef struct slibraryfile *pmlibraryfile;
+
+struct slibraryfile
+{
+  int loaded;
+  char *libspc;
+  char *relfil;                 /* Warning: allocate memory before using */
+  char *filename;               /* Warning: allocate memory before using */
+  long offset;                  /* The embedded file offset in the library file libspc */
+  unsigned int type;
+  pmlibrarysymbol symbols;
+  pmlibraryfile next;
+};
+
+extern pmlibraryfile libr;
+
+#ifdef INDEXLIB
+pmlibrarysymbol add_rel_index (FILE * fp, long size, pmlibraryfile This);
+#else
+int add_rel_file (const char *name, struct lbname *lbnh, const char *relfil,
+                  const char *filspc, int offset, FILE * fp, long size, int type);
+#endif
+
+struct aslib_target
+{
+  int (*is_lib) (FILE * libfp);
+#ifdef INDEXLIB
+    pmlibraryfile (*buildlibraryindex) (struct lbname * lbnh, FILE * libfp, pmlibraryfile This, int type);
+#else
+  int (*fndsym) (const char *name, struct lbname * lbnh, FILE * libfp, int type);
+#endif
+  void (*loadfile) (struct lbfile * lbfh);
+};
+
+extern struct aslib_target aslib_target_sdcclib;
+extern struct aslib_target aslib_target_lib;
+
+#endif /* __LKLIBR_H */
diff --git a/as/link/lkrel.c b/as/link/lkrel.c
new file mode 100644 (file)
index 0000000..02c1912
--- /dev/null
@@ -0,0 +1,131 @@
+/* lkrel.c */
+
+/*
+ * (C) Copyright 1989-1995
+ * All Rights Reserved
+ *
+ * Alan R. Baldwin
+ * 721 Berkeley St.
+ * Kent, Ohio  44240
+ *
+ * With contributions for the
+ * object libraries from
+ * Ken Hornstein
+ * kenh@cmf.nrl.navy.mil
+ *
+ */
+
+#include <string.h>
+#include <assert.h>
+
+#include "getline.h"
+#include "aslink.h"
+#include "lkrel.h"
+
+int
+is_rel (FILE * libfp)
+{
+  int c;
+  long pos = ftell (libfp);
+  int ret = 0;
+
+  /* [XDQ][HL] */
+  if (((c = getc (libfp)) == 'X' || c == 'D' || c == 'Q') && ((c = getc (libfp)) == 'H' || c == 'L'))
+    {
+      switch (getc (libfp))
+       {
+       case '\r':
+         if (getc (libfp) == '\n')
+           ret = 1;
+         break;
+
+       case '\n':
+         ret = 1;
+       }
+    }
+  else if (c == ';')
+    {
+      char buf[6];
+
+      if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, "!FILE ", 6) == 0)
+       ret = 1;
+    }
+  fseek (libfp, pos, SEEK_SET);
+  return ret;
+}
+
+/* Load a .rel file embedded in a sdcclib file */
+int
+load_rel (FILE * libfp, long size)
+{
+  if (is_rel (libfp))
+    {
+      char str[NINPUT];
+      long end;
+
+      if (size >= 0)
+       end = ftell (libfp) + size;
+      else
+       end = -1;
+
+      while ((end < 0 || ftell (libfp) < end) && getline (str, sizeof (str), libfp) != NULL)
+       {
+         if (0 == strcmp (str, "</REL>"))
+           return 1;
+
+         ip = str;
+         link_main ();
+       }
+
+      return 1;
+    }
+  else
+    return 0;
+}
+
+int
+enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *param), void *param)
+{
+  char buf[NINPUT];
+  long end = (size >= 0) ? ftell (fp) + size : -1;
+
+  assert (func != NULL);
+
+  /*
+   * Read in the object file.  Look for lines that
+   * begin with "S" and end with "D".  These are
+   * symbol table definitions.  If we find one, see
+   * if it is our symbol.  Make sure we only read in
+   * our object file and don't go into the next one.
+   */
+
+  while ((end <= 0 || ftell (fp) < end) && getline (buf, sizeof (buf), fp) != NULL)
+    {
+      char symname[NINPUT];
+      char c;
+
+      /*
+       * 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;
+
+      /*
+       * Skip everything that's not a symbol record.
+       */
+      if (buf[0] != 'S')
+       continue;
+
+      sscanf (buf, "S %s %c", symname, &c);
+
+      /* If it's an actual symbol, record it */
+      if (c == 'D')
+       {
+         if ((*func) (symname, param))
+           return 1;
+       }
+    }
+
+  return 0;
+}
diff --git a/as/link/lkrel.h b/as/link/lkrel.h
new file mode 100644 (file)
index 0000000..68e84c2
--- /dev/null
@@ -0,0 +1,37 @@
+/* lkrel.h */
+
+/*
+ * (C) Copyright 1989-1995
+ * All Rights Reserved
+ *
+ * Alan R. Baldwin
+ * 721 Berkeley St.
+ * Kent, Ohio  44240
+ *
+ * With contributions for the
+ * object libraries from
+ * Ken Hornstein
+ * kenh@cmf.nrl.navy.mil
+ *
+ */
+
+#ifndef __LKREL_H
+#define __LKREL_H
+
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+  int is_rel (FILE * libfp);
+  int load_rel (FILE * libfp, long size);
+  int enum_symbols (FILE * fp, long size, int (*func) (const char *symvoid, void *param), void *param);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif                         /* __LKREL_H */
diff --git a/as/link/lksdcclib.c b/as/link/lksdcclib.c
new file mode 100644 (file)
index 0000000..95f927d
--- /dev/null
@@ -0,0 +1,383 @@
+/* lksdcclib.c */
+
+/*
+ * (C) Copyright 1989-1995
+ * All Rights Reserved
+ *
+ * Alan R. Baldwin
+ * 721 Berkeley St.
+ * Kent, Ohio  44240
+ *
+ * With contributions for the
+ * object libraries from
+ * Ken Hornstein
+ * kenh@cmf.nrl.navy.mil
+ *
+ */
+
+/*
+ * Extensions: P. Felber
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "getline.h"
+#include "aslink.h"
+#include "lklibr.h"
+#include "lkrel.h"
+
+#define EQ(A,B) !strcmp((A),(B))
+#define MAXLINE 254            /*when using getline */
+
+
+static int
+is_sdcclib (FILE * libfp)
+{
+#define SDCCLIB_MAGIC "<SDCCLIB>"
+#define SDCCLIB_MAGIC_LEN (sizeof ("<SDCCLIB>") - 1)
+
+  char buf[SDCCLIB_MAGIC_LEN];
+
+  if (fread (buf, 1, sizeof (buf), libfp) == sizeof (buf) && memcmp (buf, SDCCLIB_MAGIC, SDCCLIB_MAGIC_LEN) == 0)
+    {
+      switch (getc (libfp))
+       {
+       case '\r':
+         if (getc (libfp) == '\n')
+           return 1;
+
+       case '\n':
+         return 1;
+       }
+    }
+  rewind (libfp);
+  return 0;
+}
+
+/* Load a .rel file embedded in a sdcclib file */
+static void
+LoadRel (char *libfname, FILE * libfp, char *ModName)
+{
+  char str[NINPUT];
+  int state = 0;
+
+  while (getline (str, sizeof (str), libfp) != NULL)
+    {
+      switch (state)
+       {
+       case 0:
+         if (EQ (str, "<FILE>"))
+           {
+             getline (str, sizeof (str), libfp);
+             if (EQ (str, ModName))
+               state = 1;
+             else
+               {
+                 fprintf (stderr, "?ASlink-Error-Bad offset in library file %s(%s)\n", libfname, ModName);
+                 lkexit (1);
+               }
+           }
+         break;
+       case 1:
+         if (EQ (str, "<REL>"))
+           state = 2;
+         break;
+       case 2:
+         load_rel (libfp, -1);
+         break;
+       }
+    }
+}
+
+#ifdef INDEXLIB
+static pmlibraryfile
+buildlibraryindex_sdcclib (struct lbname *lbnh, FILE * libfp, pmlibraryfile This, int type)
+{
+  char ModName[NCPS] = "";
+  char FLine[MAXLINE];
+  char buff[PATH_MAX];
+  int state = 0;
+  long IndexOffset = 0, FileOffset;
+  pmlibrarysymbol ThisSym = NULL;
+
+  while (getline (FLine, sizeof (FLine), libfp))
+    {
+      switch (state)
+       {
+       case 0:
+         if (EQ (FLine, "<INDEX>"))
+           {
+             /*The next line has the size of the index */
+             getline (FLine, sizeof (FLine), libfp);
+             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 */
+             getline (FLine, sizeof (FLine), libfp);
+             sscanf (FLine, "%s %ld", ModName, &FileOffset);
+             state = 2;
+
+             /* Create a new libraryfile object for this module */
+             if (libr == NULL)
+               {
+                 libr = This = (pmlibraryfile) new (sizeof (mlibraryfile));
+               }
+             else
+               {
+                 This->next = (pmlibraryfile) new (sizeof (mlibraryfile));
+                 This = This->next;
+               }
+             This->next = NULL;
+             This->loaded = -1;
+             This->offset = FileOffset + IndexOffset;
+             This->libspc = lbnh->libspc;
+             This->relfil = strdup (ModName);
+             sprintf (buff, "%s%s%c%s", lbnh->path, ModName, FSEPX, LKOBJEXT);
+             This->filename = strdup (buff);
+             This->type = type;
+
+             This->symbols = ThisSym = NULL;   /* Start a new linked list of symbols */
+           }
+         else if (EQ (FLine, "</INDEX>"))
+           {
+             return This;      /* Finish, get out of here */
+           }
+         break;
+       case 2:
+         if (EQ (FLine, "</MODULE>"))
+           {
+             This->loaded = 0;
+             /* Create the index for the next module */
+             state = 1;
+           }
+         else
+           {
+             /* Add the symbols */
+             if (ThisSym == NULL)      /* First symbol of the current module */
+               {
+                 ThisSym = This->symbols = (pmlibrarysymbol) new (sizeof (mlibrarysymbol));
+               }
+             else
+               {
+                 ThisSym->next = (pmlibrarysymbol) new (sizeof (mlibrarysymbol));
+                 ThisSym = ThisSym->next;
+               }
+             ThisSym->next = NULL;
+             ThisSym->name = strdup (FLine);
+           }
+         break;
+
+       default:
+         return This;          /* State machine should never reach this point, but just in case... */
+         break;
+       }
+    }
+
+  return This;                 /* State machine should never reach this point, but just in case... */
+}
+
+#else
+
+/* 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. */
+
+static int
+LoadAdb (FILE * libfp)
+{
+  char str[MAXLINE];
+  int state = 0;
+  int ToReturn = 0;
+
+  while (getline (str, sizeof (str), libfp) != NULL)
+    {
+      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. */
+
+static int
+findsym_sdcclib (const char *name, struct lbname *lbnh, FILE * libfp, int type)
+{
+  struct lbfile *lbfh, *lbf;
+  char ModName[NCPS] = "";
+  char FLine[MAXLINE];
+  int state = 0;
+  long IndexOffset = 0, FileOffset;
+
+  while (getline (FLine, sizeof (FLine), libfp))
+    {
+      char str[PATH_MAX];
+
+      if (lbnh->path != NULL)
+       {
+         strcpy (str, lbnh->path);
+#ifdef  OTHERSYSTEM
+         if (*str != '\0' && (str[strlen (str) - 1] != '/') && (str[strlen (str) - 1] != LKDIRSEP))
+           {
+             strcat (str, LKDIRSEPSTR);
+           }
+#endif
+       }
+
+      switch (state)
+       {
+       case 0:
+         if (EQ (FLine, "<INDEX>"))
+           {
+             /* The next line has the size of the index */
+             getline (FLine, sizeof (FLine), libfp);
+             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 */
+             getline (FLine, sizeof (FLine), libfp);
+             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 (name, 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. */
+                 sprintf (&str[strlen (str)], "%s%c%s", ModName, FSEPX, LKOBJEXT);
+
+                 /* If this module has been loaded already don't load it again. */
+                 lbf = lbfhead;
+                 while (lbf)
+                   {
+                     if (EQ (str, 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 = lbnh->libspc;
+                 lbfh->filspc = str;
+                 lbfh->relfil = strdup (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 (lbnh->libspc, libfp, ModName);
+
+                 /* if cdb information required & .adb file present */
+                 if (dflag && dfp)
+                   {
+                     if (LoadAdb (libfp))
+                       SaveLinkedFilePath (str);
+                   }
+                 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 */
+}
+
+#endif
+
+static void
+loadfile_sdcclib (struct lbfile *lbfh)
+{
+  FILE *fp;
+#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 (lbfh->libspc, posix_path);
+  fp = fopen (posix_path, "rb");
+#else
+  fp = fopen (lbfh->libspc, "rb");
+#endif
+
+  if (fp != NULL)
+    {
+      fseek (fp, lbfh->offset, SEEK_SET);
+      LoadRel (lbfh->libspc, fp, lbfh->relfil);
+      fclose (fp);
+    }
+  else
+    {
+      fprintf (stderr, "?ASlink-Error-Opening library '%s'\n", lbfh->libspc);
+      fclose (fp);
+      lkexit (1);
+    }
+}
+
+struct aslib_target aslib_target_sdcclib = {
+  &is_sdcclib,
+#ifdef INDEXLIB
+  &buildlibraryindex_sdcclib,
+#else
+  &findsym_sdcclib,
+#endif
+  &loadfile_sdcclib,
+};
index c061e9f1a3cd37ecc62379cb473635e2fa1eb9b5..1935f360abb9f15224e6c1e38ccc70fbafb151ae 100644 (file)
@@ -33,8 +33,8 @@ EXEEXT          = @EXEEXT@
 
 VPATH           = @srcdir@
 
-CPPFLAGS        = @CPPFLAGS@ -I.. -I$(srcdir)/.. -I$(top_builddir)
-CFLAGS          = @CFLAGS@ -Wall -DINDEXLIB -DUNIX -I.. -I$(srcdir)/.. -I$(top_builddir)
+CPPFLAGS        = @CPPFLAGS@ -I.. -I$(srcdir)/..
+CFLAGS          = @CFLAGS@ -Wall -DINDEXLIB -DUNIX -I.. -I$(srcdir)/..
 M_OR_MM         = @M_OR_MM@
 LDFLAGS         = @LDFLAGS@
 
@@ -46,9 +46,9 @@ LKLIB = $(srcdir)/..
 
 ASXXLIBSRC = strcmpi.c
 
-LKLIBSRC = lkaomf51.c lkdata.c lkeval.c \
-           lkhead.c lklex.c lklibr.c lklist.c \
-           lknoice.c lkstore.c lksym.c
+LKLIBSRC = getline.c lkaomf51.c lkdata.c lkeval.c \
+           lkhead.c lklex.c lklib.c lklibr.c lklist.c \
+           lknoice.c lkrel.c lksdcclib.c lkstore.c lksym.c
 
 SRC = lkmain.c lkarea.c lkihx.c \
       lkrloc.c lks19.c lkmem.c
index 1b1751d83eee3d002d74b5d9e2a8f5fb926fae40..481fc000d910de8160a58e7250c4a787e03bbcbd 100644 (file)
@@ -88,6 +88,10 @@ LINK32=link.exe
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
 # Begin Source File\r
 \r
+SOURCE=..\getline.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lkaomf51.c\r
 # End Source File\r
 # Begin Source File\r
@@ -116,6 +120,10 @@ SOURCE=..\lklex.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lklib.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lklibr.c\r
 # End Source File\r
 # Begin Source File\r
@@ -136,6 +144,10 @@ SOURCE=..\lknoice.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lkrel.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\lkrloc.c\r
 # End Source File\r
 # Begin Source File\r
@@ -144,6 +156,10 @@ SOURCE=.\lks19.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=..\lksdcclib.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lkstore.c\r
 # End Source File\r
 # Begin Source File\r
@@ -162,6 +178,22 @@ SOURCE=..\..\asxxsrc\strcmpi.c
 \r
 SOURCE=..\aslink.h\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\asxxxx_config.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\getline.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lklibr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lkrel.h\r
+# End Source File\r
 # End Group\r
 # End Target\r
 # End Project\r
index 0705970e0a7ef1e53f2754f024505ff61aab98a5..dcb3202680f93331208cdd0fb4f340c314c4abb1 100644 (file)
@@ -13,9 +13,9 @@ ASXXLIBSRC = strcmpi.c
 
 LKLIB = $(srcdir)/..
 
-LKLIBSRC = lkaomf51.c lkdata.c lkeval.c \
-           lkhead.c lklex.c lklibr.c lklist.c \
-           lknoice.c lkstore.c lksym.c
+LKLIBSRC = getline.c lkaomf51.c lkdata.c lkeval.c \
+           lkhead.c lklex.c lklib.c lklibr.c lklist.c \
+           lknoice.c lkrel.c lksdcclib.c lkstore.c lksym.c
 
 SRC = lkmain.c lkarea.c lkihx.c \
       lkrloc.c lks19.c lkgb.c lkgg.c
index dbddecbdc82369944cfddf6fb7e63e8a20ca6dae..3f82f08f40cc08bf580e8899ed3b43bca8093ef4 100644 (file)
@@ -42,7 +42,7 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "SDK" /D "GAMEBOY" /YX /FD /c\r
 # ADD BASE RSC /l 0x409 /d "NDEBUG"\r
 # ADD RSC /l 0x409 /d "NDEBUG"\r
 BSC32=bscmake.exe\r
@@ -67,7 +67,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "SDK" /D "GAMEBOY" /YX /FD /GZ /c\r
 # ADD BASE RSC /l 0x409 /d "_DEBUG"\r
 # ADD RSC /l 0x409 /d "_DEBUG"\r
 BSC32=bscmake.exe\r
@@ -89,88 +89,87 @@ LINK32=link.exe
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
 # Begin Source File\r
 \r
+SOURCE=..\getline.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lkaomf51.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkarea.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkdata.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkeval.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkgb.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkgg.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkhead.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkihx.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lklex.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lklib.c\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lklibr.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lklist.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkmain.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lknoice.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lkrel.c\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkrloc.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lks19.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lksdcclib.c\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkstore.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lksym.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB" /D "GAMEBOY"\r
 # End Source File\r
 # Begin Source File\r
 \r
@@ -184,6 +183,22 @@ SOURCE=..\..\asxxsrc\strcmpi.c
 \r
 SOURCE=..\aslink.h\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\asxxxx_config.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\getline.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lklibr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lkrel.h\r
+# End Source File\r
 # End Group\r
 # Begin Group "Resource Files"\r
 \r
index 4d9e302c08de647fa011f83df75a344b737a276d..499e974cad8eafab03a9c86167d460fb12b6ca10 100644 (file)
@@ -42,7 +42,7 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /W3 /GX /O2 /I ".." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /W3 /GX /O2 /I ".." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "SDK" /YX /FD /c\r
 # ADD BASE RSC /l 0x409 /d "NDEBUG"\r
 # ADD RSC /l 0x409 /d "NDEBUG"\r
 BSC32=bscmake.exe\r
@@ -67,7 +67,7 @@ LINK32=link.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
-# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I ".." /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "INDEXLIB" /D "SDK" /YX /FD /GZ /c\r
 # ADD BASE RSC /l 0x409 /d "_DEBUG"\r
 # ADD RSC /l 0x409 /d "_DEBUG"\r
 BSC32=bscmake.exe\r
@@ -89,88 +89,87 @@ LINK32=link.exe
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
 # Begin Source File\r
 \r
+SOURCE=..\getline.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lkaomf51.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkarea.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkdata.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkeval.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkgb.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkgg.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkhead.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkihx.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lklex.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lklib.c\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lklibr.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lklist.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkmain.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lknoice.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lkrel.c\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lkrloc.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=.\lks19.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lksdcclib.c\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lkstore.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
 SOURCE=..\lksym.c\r
-# ADD CPP /D "SDK" /D "INDEXLIB"\r
 # End Source File\r
 # Begin Source File\r
 \r
@@ -184,6 +183,22 @@ SOURCE=..\..\asxxsrc\strcmpi.c
 \r
 SOURCE=..\aslink.h\r
 # End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\asxxxx_config.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\getline.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lklibr.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\lkrel.h\r
+# End Source File\r
 # End Group\r
 # Begin Group "Resource Files"\r
 \r