* sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 28 Jan 2007 18:10:42 +0000 (18:10 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 28 Jan 2007 18:10:42 +0000 (18:10 +0000)
  on WIN32
* src/SDCCdwarf2.c, src/SDCCglobl.h, src/SDCCmain.c, src/SDCCutil.c,
  src/SDCCutil.h, src/avr/gen.c, src/ds390/gen.c, src/hc08/gen.c,
  src/mcs51/gen.c, src/pic/device.c, src/pic/gen.c, src/pic/pcode.c,
  src/pic/pcodepeep.c, src/pic/ralloc.c, src/pic16/device.h,
  src/pic16/gen.c, src/pic16/main.c, src/pic16/pcode.c,
  src/pic16/pcodepeep.c, src/pic16/ralloc.c, src/xa51/gen.c,
  src/z80/gen.c, support/Util/MySystem.c:
  accept slash and backslash as directory separator on WIN32 and
  Cygwin ports

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

25 files changed:
ChangeLog
sim/ucsim/cmd.src/cmdutil.cc
src/SDCCdwarf2.c
src/SDCCglobl.h
src/SDCCmain.c
src/SDCCutil.c
src/SDCCutil.h
src/avr/gen.c
src/ds390/gen.c
src/hc08/gen.c
src/mcs51/gen.c
src/pic/device.c
src/pic/gen.c
src/pic/pcode.c
src/pic/pcodepeep.c
src/pic/ralloc.c
src/pic16/device.h
src/pic16/gen.c
src/pic16/main.c
src/pic16/pcode.c
src/pic16/pcodepeep.c
src/pic16/ralloc.c
src/xa51/gen.c
src/z80/gen.c
support/Util/MySystem.c

index 9d23a187e174ad38c138a49a9f03253b749ac406..9c5b95775bc5e40696472cb23ea0c3a862af9d3a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-01-28 Borut Razem <borut.razem AT siol.net>
+
+       * sim/ucsim/cmd.src/cmdutil.cc: NUL device is detected as CG_FILE type
+         on WIN32
+       * src/SDCCdwarf2.c, src/SDCCglobl.h, src/SDCCmain.c, src/SDCCutil.c,
+         src/SDCCutil.h, src/avr/gen.c, src/ds390/gen.c, src/hc08/gen.c,
+         src/mcs51/gen.c, src/pic/device.c, src/pic/gen.c, src/pic/pcode.c,
+         src/pic/pcodepeep.c, src/pic/ralloc.c, src/pic16/device.h,
+         src/pic16/gen.c, src/pic16/main.c, src/pic16/pcode.c,
+         src/pic16/pcodepeep.c, src/pic16/ralloc.c, src/xa51/gen.c,
+         src/z80/gen.c, support/Util/MySystem.c:
+         accept slash and backslash as directory separator on WIN32 and
+         Cygwin ports
+
 2007-01-28 Raphael Neider <rneider AT web.de>
 
        * src/pic16/devices.inc,
index 067a3afcd53df6ec693528643b2cb653a67d2358..955c51e87d155f5ff04ea19ce68a68684420c036 100644 (file)
@@ -152,12 +152,25 @@ get_handle_type(HANDLE handle)
     {
     case FILE_TYPE_CHAR:
       {
-              DWORD err;
+        DWORD err;
 
         if (!ClearCommError(handle, &err, NULL))
-          { 
-            if (ERROR_INVALID_HANDLE == GetLastError())
-              return CH_CONSOLE;
+          {
+            switch (GetLastError())
+              {
+              case ERROR_INVALID_HANDLE:
+                return CH_CONSOLE;
+
+              case ERROR_INVALID_FUNCTION:
+                /*
+                 * In case of NUL device return type CH_FILE.
+                 * Is this the correct way to test it?
+                 */
+                return CH_FILE;
+
+              default:
+                assert(false);
+              }
           }
       }
       return CH_SERIAL;
@@ -218,13 +231,12 @@ input_avail(HANDLE handle, e_handle_type type)
           !GetNumberOfConsoleInputEvents(handle, &NumPending) ||
           NumPending == 0 ||
           NULL == (pIRBuf = (PINPUT_RECORD)_alloca(NumPending * sizeof(INPUT_RECORD))))
-          return FALSE;
+          return false;
 
         if (PeekConsoleInput(handle, pIRBuf, NumPending, &NumPeeked) &&
           NumPeeked != 0L &&
           NumPeeked <= NumPending)
           {
-
             /*
              * Scan all of the peeked events to determine if any is a key event
              * which should be recognized.
index f02f379533a28eb54fe4c4e246301062eb4f9bdb..0e1d1c325a698d79d6851b9ae5b38fb96af92892 100644 (file)
@@ -1575,7 +1575,7 @@ dwFindFileIndex (char * filename)
       if (!strncmp (includeDir, filename, strlen (includeDir))
           && strlen (filename) > strlen (includeDir))
         {
-         if (*(filename+strlen (includeDir)) == DIR_SEPARATOR_CHAR)
+         if (IS_DIR_SEPARATOR(filename[strlen (includeDir)]))
            break;
        }
     }
index 11761f6de805ba140a4964afc652777b0d5ea9c0..61eac7b01b81940f6f866432e4d325587d7d3137 100644 (file)
 
 #define UNIX_DIR_SEPARATOR_CHAR    '/'
 
+#if defined(__BORLANDC__) || defined(_MSC_VER)
+#define STRCASECMP stricmp
+#define STRNCASECMP strnicmp
+#else
+#define STRCASECMP strcasecmp
+#define STRNCASECMP strncasecmp
+#endif
+
+#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__)
+
+#ifndef HAVE_DOS_BASED_FILE_SYSTEM
+#define HAVE_DOS_BASED_FILE_SYSTEM 1
+#endif
+
+#define IS_DIR_SEPARATOR(c)     ((c) == DIR_SEPARATOR_CHAR || (c) == UNIX_DIR_SEPARATOR_CHAR)
+/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
+   only semi-absolute.  This is because the users of IS_ABSOLUTE_PATH
+   want to know whether to prepend the current working directory to
+   a file name, which should not be done with a name like d:foo.  */
+#define IS_ABSOLUTE_PATH(f)     (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':')))
+#define FILENAME_CMP(s1, s2)    STRCASECMP(s1, s2)
+
+#else  /* not DOSish */
+
+#define IS_DIR_SEPARATOR(c)     ((c) == DIR_SEPARATOR_CHAR)
+#define IS_ABSOLUTE_PATH(f)     (IS_DIR_SEPARATOR((f)[0]))
+#define FILENAME_CMP(s1, s2)    strcmp(s1, s2)
+
+#endif /* not DOSish */
+
 #ifdef WIN32
 # define NATIVE_WIN32          1
 # ifndef __MINGW32__
index da935a7aba8ec63c4e95191de277ee21c781e96a..e6c867f804fde3906a10072f31901d5854ed04b5 100644 (file)
@@ -88,7 +88,8 @@ set *libDirsSet = NULL;         /* list of lib search directories */
 int ds390_jammed = 0;
 #endif
 
-/* Globally accessible scratch buffer for file names. */
+/* Globally accessible scratch buffer for file names.
+   TODO: replace them with local buffers */
 char scratchFileName[PATH_MAX];
 char buffer[PATH_MAX * 2];
 
@@ -545,15 +546,15 @@ setParseWithComma (set **dest, const char *src)
   p = src;
   while (src < end)
     {
-      dbuf_init(&dbuf, 16);
+      dbuf_init (&dbuf, 16);
 
       while (p < end && ',' != *p)
         ++p;
-      dbuf_append(&dbuf, src, p - src);
+      dbuf_append (&dbuf, src, p - src);
 
       /* null terminate the buffer */
-      dbuf_c_str(&dbuf);
-      addSet(dest, dbuf_detach(&dbuf));
+      dbuf_c_str (&dbuf);
+      addSet(dest, dbuf_detach (&dbuf));
 
       src = ++p;
     }
@@ -605,29 +606,42 @@ setDefaultOptions (void)
 static void
 processFile (char *s)
 {
-  char *fext = NULL;
+  const char *extp;
+  struct dbuf_s ext;
+  struct dbuf_s path;
 
-  /* get the file extension */
-  fext = s + strlen (s);
-  while ((fext != s) && *fext != '.')
-    fext--;
+  dbuf_init (&ext, 128);
+  dbuf_init (&path, 128);
 
-  /* now if no '.' then we don't know what the file type is
+  /* get the file extension.
+     If no '.' then we don't know what the file type is
      so give a warning and return */
-  if (fext == s)
+  if (!dbuf_splitFile (s, &path, &ext))
     {
       werror (W_UNKNOWN_FEXT, s);
+
+      dbuf_destroy (&ext);
+      dbuf_destroy (&path);
+
       return;
     }
 
   /* otherwise depending on the file type */
-  if (strcmp (fext, ".c") == 0 || strcmp (fext, ".C") == 0)
+  extp = dbuf_c_str (&ext);
+  if (extp[1] == '\0' && (extp[0] == 'c' || extp[0] == 'C'))
     {
+      unsigned char *p;
+
+      dbuf_destroy (&ext);
+
       /* source file name : not if we already have a
          source file */
       if (fullSrcFileName)
         {
           werror (W_TOO_MANY_SRC, s);
+
+          dbuf_destroy (&path);
+
           return;
         }
 
@@ -636,71 +650,55 @@ processFile (char *s)
       if (!(srcFile = fopen (fullSrcFileName, "r")))
         {
           werror (E_FILE_OPEN_ERR, s);
-          exit (1);
-        }
-
-      /* copy the file name into the buffer */
-      strncpyz (buffer, s, sizeof(buffer));
 
-      /* get rid of the "."-extension */
+          dbuf_destroy (&path);
 
-      /* is there a dot at all? */
-      if (strrchr (buffer, '.') &&
-          /* is the dot in the filename, not in the path? */
-          (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.')))
-        {
-          *strrchr (buffer, '.') = '\0';
+          exit (1);
         }
 
       /* get rid of any path information
          for the module name; */
-      fext = buffer + strlen (buffer);
-#if NATIVE_WIN32
-      /* do this by going backwards till we
-         get '\' or ':' or start of buffer */
-      while (fext != buffer &&
-             *(fext - 1) != DIR_SEPARATOR_CHAR &&
-             *(fext - 1) != ':')
-        {
-          fext--;
-        }
-#else
-      /* do this by going backwards till we
-         get '/' or start of buffer */
-      while (fext != buffer &&
-             *(fext - 1) != DIR_SEPARATOR_CHAR)
-        {
-          fext--;
-        }
-#endif
-      moduleNameBase = Safe_strdup ( fext );
-      moduleName = Safe_strdup ( fext );
+      dbuf_init (&ext, 128);
+
+      dbuf_splitPath (dbuf_c_str (&path), NULL, &ext);
+      dbuf_destroy (&path);
 
-      for (fext = moduleName; *fext; fext++)
-        if (!isalnum ((unsigned char)*fext))
-          *fext = '_';
+      moduleNameBase = Safe_strdup (dbuf_c_str (&ext));
+      moduleName = dbuf_detach (&ext);
+
+      for (p = moduleName; *p; ++p)
+        if (!isalnum(*p))
+          *p = '_';
       return;
     }
 
   /* if the extention is type .rel or .r or .REL or .R
      additional object file will be passed to the linker */
-  if (strcmp (fext, ".r") == 0 || strcmp (fext, ".rel") == 0 ||
-      strcmp (fext, ".R") == 0 || strcmp (fext, ".REL") == 0 ||
-      strcmp (fext, port->linker.rel_ext) == 0)
+  if ((extp[1] == '\0' && (extp[0] == 'r' || extp[0] == 'R')) ||
+      strcmp (extp, "rel") == 0 || strcmp (extp, "REL") == 0 ||
+      strcmp (extp, port->linker.rel_ext) == 0)
     {
-      addSet(&relFilesSet, Safe_strdup(s));
+      dbuf_destroy (&ext);
+      dbuf_destroy (&path);
+
+      addSet (&relFilesSet, Safe_strdup (s));
       return;
     }
 
   /* if .lib or .LIB */
-  if (strcmp (fext, ".lib") == 0 || strcmp (fext, ".LIB") == 0)
+  if (strcmp (extp, "lib") == 0 || strcmp (extp, ".LIB") == 0)
     {
-      addSet(&libFilesSet, Safe_strdup(s));
+      dbuf_destroy (&ext);
+      dbuf_destroy (&path);
+
+      addSet (&libFilesSet, Safe_strdup (s));
       return;
     }
 
-  werror (W_UNKNOWN_FEXT, s);
+  dbuf_destroy (&ext);
+  dbuf_destroy (&path);
 
+  werror (W_UNKNOWN_FEXT, s);
 }
 
 static void
@@ -729,7 +727,7 @@ getStringArg(const char *szStart, char **argv, int *pi, int argc)
         {
           werror (E_ARGUMENT_MISSING, szStart);
           /* Die here rather than checking for errors later. */
-          exit(EXIT_FAILURE);
+          exit (EXIT_FAILURE);
         }
       else
         {
@@ -759,42 +757,43 @@ verifyShortOption(const char *opt)
 static bool
 tryHandleUnsupportedOpt(char **argv, int *pi)
 {
-    if (argv[*pi][0] == '-')
-        {
-            const char *longOpt = "";
-            char shortOpt = -1;
-            int i;
+  if (argv[*pi][0] == '-')
+    {
+      const char *longOpt = "";
+      char shortOpt = -1;
+      int i;
 
-            if (argv[*pi][1] == '-')
-                {
-                    /* Long option. */
-                    longOpt = argv[*pi];
-                }
-            else
-                {
-                    shortOpt = argv[*pi][1];
-                }
-            for (i = 0; i < LENGTH(unsupportedOptTable); i++)
-                {
-                    if (unsupportedOptTable[i].shortOpt == shortOpt ||
-                        (longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt))) {
-                        /* Found an unsupported opt. */
-                        char buffer[100];
-                        SNPRINTF(buffer, sizeof(buffer),
-                                 "%s%c%c",
-                                 longOpt ? longOpt : "",
-                                 shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' ');
-                        werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message);
-                        return 1;
-                    }
-                }
-            /* Didn't find in the table */
-            return 0;
+      if (argv[*pi][1] == '-')
+        {
+          /* Long option. */
+          longOpt = argv[*pi];
         }
-    else
+      else
         {
-            /* Not an option, so can't be unsupported :) */
-            return 0;
+          shortOpt = argv[*pi][1];
+        }
+      for (i = 0; i < LENGTH(unsupportedOptTable); i++)
+        {
+          if (unsupportedOptTable[i].shortOpt == shortOpt ||
+              (longOpt && unsupportedOptTable[i].longOpt && !strcmp(unsupportedOptTable[i].longOpt, longOpt)))
+            {
+              /* Found an unsupported opt. */
+              char buffer[100];
+              SNPRINTF(buffer, sizeof(buffer),
+                "%s%c%c",
+                longOpt ? longOpt : "",
+                shortOpt ? '-' : ' ', shortOpt ? shortOpt : ' ');
+              werror (W_UNSUPP_OPTION, buffer, unsupportedOptTable[i].message);
+              return 1;
+            }
+        }
+      /* Didn't find in the table */
+      return 0;
+    }
+  else
+    {
+      /* Not an option, so can't be unsupported :) */
+      return 0;
     }
 }
 
@@ -1153,9 +1152,9 @@ parseCmdLine (int argc, char **argv)
             {
               struct dbuf_s segname;
 
-              dbuf_init(&segname, 16);
-              dbuf_printf(&segname, "%-8s(CODE)", getStringArg(OPTION_CODE_SEG, argv, &i, argc));
-              options.code_seg = dbuf_detach(&segname);
+              dbuf_init (&segname, 16);
+              dbuf_printf (&segname, "%-8s(CODE)", getStringArg (OPTION_CODE_SEG, argv, &i, argc));
+              options.code_seg = dbuf_detach (&segname);
               continue;
             }
 
@@ -1163,9 +1162,9 @@ parseCmdLine (int argc, char **argv)
             {
               struct dbuf_s segname;
 
-              dbuf_init(&segname, 16);
-              dbuf_printf(&segname, "%-8s(CODE)", getStringArg(OPTION_CONST_SEG, argv, &i, argc));
-              options.const_seg = dbuf_detach(&segname);
+              dbuf_init (&segname, 16);
+              dbuf_printf (&segname, "%-8s(CODE)", getStringArg (OPTION_CONST_SEG, argv, &i, argc));
+              options.const_seg = dbuf_detach (&segname);
               continue;
             }
 
@@ -1217,41 +1216,40 @@ parseCmdLine (int argc, char **argv)
 
             case 'o':
               {
-                char *p;
+                char *outName = getStringArg("-o", argv, &i, argc);
+                size_t len = strlen(outName);
 
-                /* copy the file name into the buffer */
-                strncpyz(buffer, getStringArg("-o", argv, &i, argc),
-                         sizeof(buffer));
                 /* point to last character */
-                p = buffer + strlen (buffer) - 1;
-                if (*p == DIR_SEPARATOR_CHAR)
+                if (IS_DIR_SEPARATOR(outName[len - 1]))
                   {
                     /* only output path specified */
-                    dstPath = Safe_strdup (buffer);
+                    dstPath = Safe_malloc(len);
+                    memcpy(dstPath, outName, len - 1);
+                    dstPath[len - 1] = '\0';
                     fullDstFileName = NULL;
                   }
                 else
                   {
-                    fullDstFileName = Safe_strdup (buffer);
+                    struct dbuf_s path;
 
-                    /* get rid of the "."-extension */
+                    dbuf_init (&path, 128);
+                    fullDstFileName = Safe_strdup (outName);
 
-                    /* is there a dot at all? */
-                    if (strrchr (buffer, '.') &&
-                        /* is the dot in the filename, not in the path? */
-                        (strrchr (buffer, DIR_SEPARATOR_CHAR) < strrchr (buffer, '.')))
-                      *strrchr (buffer, '.') = '\0';
+                    /* get rid of the "."-extension */
+                    dbuf_splitFile (outName, &path, NULL);
 
-                    dstFileName = Safe_strdup (buffer);
+                    dbuf_c_str (&path);
+                    dstFileName = dbuf_detach (&path);
 
+                    dbuf_init (&path, 128);
                     /* strip module name to get path */
-                    p = strrchr (buffer, DIR_SEPARATOR_CHAR);
-                    if (p)
+                    if (dbuf_splitPath (dstFileName, &path, NULL))
                       {
-                        /* path with trailing / */
-                        p[1] = '\0';
-                        dstPath = Safe_strdup (buffer);
+                        dbuf_c_str (&path);
+                        dstPath = dbuf_detach (&path);
                       }
+                    else
+                      dbuf_destroy (&path);
                   }
                 break;
               }
@@ -1402,35 +1400,41 @@ parseCmdLine (int argc, char **argv)
       /* use the modulename from the C-source */
       if (fullSrcFileName)
         {
-          size_t bufSize = strlen (dstPath) + strlen (moduleNameBase) + 1;
+          struct dbuf_s path;
 
-          dstFileName = Safe_alloc (bufSize);
-          strncpyz (dstFileName, dstPath, bufSize);
-          strncatz (dstFileName, moduleNameBase, bufSize);
+          if (*dstPath != '\0')
+            {
+              dbuf_makePath (&path, dstPath, moduleNameBase);
+              dbuf_c_str (&path);
+              dstFileName = dbuf_detach (&path);
+            }
+          else
+            dstFileName = Safe_strdup(moduleNameBase);
         }
       /* use the modulename from the first object file */
       else if ((s = peekSet(relFilesSet)) != NULL)
         {
-          char *objectName;
-          size_t bufSize;
+          struct dbuf_s file;
+
+          dbuf_init(&file, 128);
+
+          dbuf_splitPath (s, NULL, &file);
 
-          strncpyz (buffer, s, sizeof(buffer));
-          /* remove extension (it must be .rel) */
-          *strrchr (buffer, '.') = '\0';
-          /* remove path */
-          objectName = strrchr (buffer, DIR_SEPARATOR_CHAR);
-          if (objectName)
+          if (*dstPath != '\0')
             {
-              ++objectName;
+              struct dbuf_s path;
+
+              dbuf_init(&path, 128);
+              dbuf_makePath (&path, dstPath, dbuf_c_str (&file));
+              dbuf_destroy (&file);
+              dbuf_c_str (&path);
+              dstFileName = dbuf_detach (&path);
             }
           else
             {
-              objectName = buffer;
+              dbuf_c_str (&file);
+              dstFileName = dbuf_detach (&file);
             }
-          bufSize = strlen (dstPath) + strlen (objectName) + 1;
-          dstFileName = Safe_alloc (bufSize);
-          strncpyz (dstFileName, dstPath, bufSize);
-          strncatz (dstFileName, objectName, bufSize);
         }
       /* else no module given: help text is displayed */
     }
@@ -1651,7 +1655,7 @@ linkEdit (char **envp)
                       fprintf(stderr,
                         "Add support for your FLAT24 target in %s @ line %d\n",
                         __FILE__, __LINE__);
-                      exit(EXIT_FAILURE);
+                      exit (EXIT_FAILURE);
                     }
                   break;
                 case MODEL_PAGE0:
@@ -1699,7 +1703,7 @@ linkEdit (char **envp)
                   fprintf(stderr,
                     "Add support for your FLAT24 target in %s @ line %d\n",
                     __FILE__, __LINE__);
-                  exit(EXIT_FAILURE);
+                  exit (EXIT_FAILURE);
                 }
               }
 #endif
@@ -1863,12 +1867,6 @@ linkEdit (char **envp)
 
   system_ret = my_system (buffer);
 
-#ifdef _WIN32
-  #define STRCMP stricmp
-#else
-  #define STRCMP strcmp
-#endif
-
   /* TODO: most linker don't have a -o parameter */
   /* -o option overrides default name? */
   if (fullDstFileName)
@@ -1897,7 +1895,7 @@ linkEdit (char **envp)
       strncatz (scratchFileName,
         options.out_fmt ? ".S19" : ".ihx",
         sizeof(scratchFileName));
-      if (STRCMP (fullDstFileName, scratchFileName))
+      if (FILENAME_CMP (fullDstFileName, scratchFileName))
         remove (fullDstFileName);
       rename (scratchFileName, fullDstFileName);
 
@@ -1913,14 +1911,14 @@ linkEdit (char **envp)
       strncatz (scratchFileName, ".map", sizeof(scratchFileName));
       *q = 0;
       strncatz(buffer, ".map", sizeof(buffer));
-      if (STRCMP (scratchFileName, buffer))
+      if (FILENAME_CMP (scratchFileName, buffer))
         remove (buffer);
       rename (scratchFileName, buffer);
       *p = 0;
       strncatz (scratchFileName, ".mem", sizeof(scratchFileName));
       *q = 0;
       strncatz(buffer, ".mem", sizeof(buffer));
-      if (STRCMP (scratchFileName, buffer))
+      if (FILENAME_CMP (scratchFileName, buffer))
         remove (buffer);
       rename (scratchFileName, buffer);
       if (options.debug)
@@ -1929,13 +1927,13 @@ linkEdit (char **envp)
           strncatz (scratchFileName, ".cdb", sizeof(scratchFileName));
           *q = 0;
           strncatz(buffer, ".cdb", sizeof(buffer));
-          if (STRCMP (scratchFileName, buffer))
+          if (FILENAME_CMP (scratchFileName, buffer))
             remove (buffer);
           rename (scratchFileName, buffer);
           /* and the OMF file without extension: */
           *p = 0;
           *q = 0;
-          if (STRCMP (scratchFileName, buffer))
+          if (FILENAME_CMP (scratchFileName, buffer))
             remove (buffer);
           rename (scratchFileName, buffer);
         }
@@ -2131,7 +2129,7 @@ preProcess (char **envp)
 static void
 setBinPaths(const char *argv0)
 {
-  char *p;
+  const char *p;
   char buf[PATH_MAX];
 
   /*
@@ -2146,7 +2144,7 @@ setBinPaths(const char *argv0)
      instead of slower addSet() */
 
   if ((p = getBinPath(argv0)) != NULL)
-    addSetHead(&binPathSet, Safe_strdup(p));
+    addSetHead(&binPathSet, (void *)p);
 
   if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
     SNPRINTF(buf, sizeof buf, "%s" PREFIX2BIN_DIR, p);
@@ -2225,7 +2223,7 @@ setLibPath(void)
 static void
 setDataPaths(const char *argv0)
 {
-  char *p;
+  const char *p;
   char buf[PATH_MAX];
 
   /*
@@ -2243,6 +2241,7 @@ setDataPaths(const char *argv0)
 
   if ((p = getBinPath(argv0)) != NULL) {
     SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p);
+    free((void *)p);
     addSet(&dataDirsSet, Safe_strdup(buf));
   }
 
@@ -2442,7 +2441,7 @@ main (int argc, char **argv, char **envp)
         fatalError = 1;
 
       if (fatalError) {
-        exit (1);
+        exit (EXIT_FAILURE);
       }
 
       if (port->general.do_glue != NULL)
index 048f5f54ce5e5a0a4fce4dbbb7fc16ba87b7ab5e..b5ce4b302c5c097d0dee0d07ca17c27651f63a43 100644 (file)
@@ -120,61 +120,151 @@ joinStrSet(set *list)
   return s;
 }
 
+/** Split the path string to the directory and file name (including extension) components.
+    The directory component doesn't contain trailing directory separator.
+    Returns true if the path contains the directory separator. */
+int
+dbuf_splitPath(const char *path, struct dbuf_s *dir, struct dbuf_s *file)
+{
+  const char *p;
+  int ret;
+  const char *end = &path[strlen(path)];
+
+  for (p = end - 1; p >= path && !IS_DIR_SEPARATOR(*p); --p)
+    ;
+
+  ret = p >= path;
+
+  if (NULL != dir)
+    {
+      int len = p - path;
+
+      if (0 < len)
+        dbuf_append(dir, path, len);
+    }
+
+  if (NULL != file)
+    {
+      int len;
+
+      ++p;
+      len = end - p;
+
+      if (0 < len)
+        dbuf_append(file, p, len);
+    }
+
+  return ret;
+}
+
+/** Split the path string to the file name (including directory) and file extension components.
+    The file name component doesn't contain trailing extension separator.
+    Returns true if the path contains the extension separator. */
+int
+dbuf_splitFile(const char *path, struct dbuf_s *file, struct dbuf_s *ext)
+{
+  const char *p;
+  const char *end = &path[strlen(path)];
+
+  for (p = end - 1; p >= path && !IS_DIR_SEPARATOR(*p) && '.' != *p; --p)
+    ;
+
+  if (p < path || '.' != *p)
+    {
+      dbuf_append_str(file, path);
+
+      return 0;
+    }
+  else
+    {
+      if (NULL != file)
+        {
+          int len = p - path;
+
+          if (0 < len)
+            dbuf_append(file, path, len);
+        }
+
+      if (NULL != ext)
+        {
+          int len;
+
+          ++p;
+          len = end - p;
+
+          if (0 < len)
+            dbuf_append(ext, p, len);
+        }
+
+      return 1;
+    }
+}
+
+/** Combile directory and the file name to a path string using the DIR_SEPARATOR_CHAR.
+ */
+void
+dbuf_makePath(struct dbuf_s *path,const char *dir, const char *file)
+{
+  if (dir != NULL)
+    dbuf_append_str(path, dir);
+  
+  dbuf_append_char(path, DIR_SEPARATOR_CHAR);
+
+  if (file != NULL)
+    dbuf_append_str(path, file);
+}
+
 /** Given a file with path information in the binary files directory,
     returns the directory component. Used for discovery of bin
     directory of SDCC installation. Returns NULL if the path is
     impossible.
 */
 #ifdef _WIN32
-char *
+const char *
 getBinPath(const char *prel)
 {
-  char *p;
-  size_t len;
-  static char path[PATH_MAX];
-    
-  /* try DOS and *nix dir separator on WIN32 */
-  if (NULL != (p = strrchr(prel, DIR_SEPARATOR_CHAR)) ||
-    NULL != (p = strrchr(prel, UNIX_DIR_SEPARATOR_CHAR))) {
-    len = min((sizeof path) - 1, p - prel);
-    strncpy(path, prel, len);
-    path[len] = '\0';
-    return path;
-  }
-  /* not enough info in prel; do it with module name */
-  else if (0 != GetModuleFileName(NULL, path, sizeof path) &&
-    NULL != (p = strrchr(path, DIR_SEPARATOR_CHAR))) {
-    *p = '\0';
-    return path;
-  }
+  struct dbuf_s path;
+  const char *p;
+
+  dbuf_init(&path, 128);
+  dbuf_splitPath(prel, &path, NULL);
+
+  p = dbuf_c_str(&path);
+  if ('\0' != *p)
+    return p;
   else
-    return NULL;
+    {
+      char module[PATH_MAX];
+
+      dbuf_destroy(&path);
+
+      /* not enough info in prel; do it with module name */
+      if (0 != GetModuleFileName(NULL, module, sizeof (module)))
+        {
+          dbuf_init(&path, 128);
+
+          dbuf_splitPath(module, &path, NULL);
+          return dbuf_c_str(&path);
+        }
+      else
+        return NULL;
+    }
 }
 #else
-char *
+const char *
 getBinPath(const char *prel)
 {
-  static char path[PATH_MAX];
+  struct dbuf_s path;
   const char *ret_path;
 
-  if (NULL != (ret_path = findProgramPath(prel))) {
-    char *p;
-    size_t len;
-
-    if (NULL != (p = strrchr(ret_path, DIR_SEPARATOR_CHAR)) &&
-      PATH_MAX > (len = p - ret_path)) {
-      memcpy(path, ret_path, len);
-      path[len] = '\0';
-      free((void *)ret_path);
+  if (NULL != (ret_path = findProgramPath(prel)))
+    {
+      dbuf_splitPath(prel, path, NULL);
 
-      return path;
-    }
-    else {
       free((void *)ret_path);
 
-      return NULL;
+      return dbuf_c_str(path);
     }
-  }
   else
     return NULL;
 }
index 6d5f75f92e529460dc66f3862d754e49639feb5c..aa29272f18f1e9fb17e57a6144d07c96f19f3d3c 100644 (file)
@@ -48,12 +48,26 @@ set *appendStrSet(set *list, const char *pre, const char *post);
 */
 const char *joinStrSet(set *list);
 
+/** Split the path string to the directory and file name (including extension) components.
+    The directory component doesn't contain trailing directory separator.
+    Returns true if the path contains the directory separator. */
+int dbuf_splitPath(const char *path, struct dbuf_s *dir, struct dbuf_s *file);
+
+/** Split the path string to the file name (including directory) and file extension components.
+    The file name component doesn't contain trailing extension separator.
+    Returns true if the path contains the extension separator. */
+int dbuf_splitFile(const char *path, struct dbuf_s *file, struct dbuf_s *ext);
+
+/** Combile directory and the file name to a path string using the DIR_SEPARATOR_CHAR.
+ */
+void dbuf_makePath(struct dbuf_s *path, const char *dir, const char *file);
+
 /** Given a file with path information in the binary files directory,
     returns the directory component. Used for discovery of bin
     directory of SDCC installation. Returns NULL if the path is
     impossible.
 */
-char *getBinPath (const char *prel);
+const char *getBinPath (const char *prel);
 
 /** Returns true if the given path exists.
  */
index 5e78cdd3ae0949d3f23a117ccf52fdaf1d431dea..7c17501518f6b2e52645cd68e34217f0b4197c5f 100644 (file)
@@ -1707,12 +1707,6 @@ resultRemat (iCode * ic)
        return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 /*-----------------------------------------------------------------*/
 /* genFunction - generated code for function entry                 */
 /*-----------------------------------------------------------------*/
index 0c4517c2ba2752e36a0680eb01c8184e3e473dd3..d32a3894a78fac776aeecab4cc8dd74280fe309f 100644 (file)
@@ -3355,12 +3355,6 @@ resultRemat (iCode * ic)
   return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 /*-----------------------------------------------------------------*/
 /* inExcludeList - return 1 if the string is in exclude Reg list   */
 /*-----------------------------------------------------------------*/
index a4911827932f747ec0856bab0dc4f440739efc6c..8c93b380c85b1083471488e31910cd8b5eb77e86 100644 (file)
@@ -2839,12 +2839,6 @@ resultRemat (iCode * ic)
   return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 /*-----------------------------------------------------------------*/
 /* inExcludeList - return 1 if the string is in exclude Reg list   */
 /*-----------------------------------------------------------------*/
index 10487d911da49827652b921269593d2bdfe6d32e..a2841f70701081452a7f27e7ba5da925a466433a 100644 (file)
@@ -3211,12 +3211,6 @@ resultRemat (iCode * ic)
   return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 /*-----------------------------------------------------------------*/
 /* inExcludeList - return 1 if the string is in exclude Reg list   */
 /*-----------------------------------------------------------------*/
index b20b01d5a62a89a52c409e604bf72aa8af849f24..36c0caf0e70a639aae4bf40fece02bf99661c3f4 100644 (file)
 #include "ralloc.h"
 #include "device.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#define STRNCASECMP strnicmp
-#else
-#define STRCASECMP strcasecmp
-#define STRNCASECMP strncasecmp
-#endif
-
 extern int Gstack_base_addr;
 extern int Gstack_size;
 
index 7cf251c42bc1ada681fbb381e1cc67a7167f9a01..c3d8251e538ec7c077f6caed664756723e2d601f 100644 (file)
@@ -2777,12 +2777,6 @@ static int resultRemat (iCode *ic)
        return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 #if 0
 /*-----------------------------------------------------------------*/
 /* inExcludeList - return 1 if the string is in exclude Reg list   */
index 48c1928f5f6d14a719476f405b71ce29d5a20526..1e7b0fa06c4e3c35dc380d5e4476ae883f2f0940 100644 (file)
@@ -33,12 +33,6 @@ pCode *findFunction(char *fname);
 
 static void FixRegisterBanking(pBlock *pb);
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 /****************************************************************/
 /****************************************************************/
 
index bfa0c757ac57c828790bde7a96bfbbfd968c2590..f041796a8831bfe6c60219dff63b8ee535e0a84e 100644 (file)
 #include "pcodeflow.h"
 #include "ralloc.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval);
 pCodeOp *popRegFromString(char *str, int size, int offset);
 
index 4d1ab9349fa58c9c9e91632da3e694f533f31a07..d51dca63908cc3bbd70662d61bd533b44c9ae55c 100644 (file)
 #include "gen.h"
 
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
 #define FENTRY2                        1 ? (void)0 : printf 
-#else
-#define STRCASECMP strcasecmp
-//#define FENTRY2(fmt,...)     do { fprintf (stderr, "%s:%d: called.\n", __FUNCTION__, __LINE__); fprintf (stderr, fmt, ## __VA_ARGS__); } while (0)
-#define FENTRY2                        1 ? (void)0 : printf 
-#endif
 
 /* this should go in SDCCicode.h, but it doesn't. */
 #define IS_REF(op)       (IS_SYMOP(op) && op->operand.symOperand->isref == 1)
index ada8cd6db2ec80f27a281f01be93c1cb9d2da8c6..fd06fc4bd6fca46917da5347d7f894bb3a11b3a8 100644 (file)
 #ifndef  __DEVICE_H__
 #define  __DEVICE_H__
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 #define CONFIGURATION_WORDS    20
 #define IDLOCATION_BYTES       20
 
index 012f409d11d8e7c9a83cf3bd1132d294e766220c..c03145c48b829e10b2cd956c8bf09602c261e20b 100644 (file)
@@ -3598,12 +3598,6 @@ static int resultRemat (iCode *ic)
   return 0;
 }
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 #if 0
 /*-----------------------------------------------------------------*/
 /* inExcludeList - return 1 if the string is in exclude Reg list   */
index ad257088f2155899e153ae70611a18381641d060..ee7b4b4f4fd8848b66367b86cb07602fffaf97fd 100644 (file)
@@ -698,8 +698,6 @@ extern set *userIncDirsSet;
 
 static void _pic16_initPaths(void)
 {
-  char pic16incDir[512];
-  char pic16libDir[512];
   set *pic16incDirsSet=NULL;
   set *pic16libDirsSet=NULL;
   char devlib[512];
@@ -710,13 +708,15 @@ static void _pic16_initPaths(void)
     setMainValue("mcu1", pic16->name[1] );
     addSet(&preArgvSet, Safe_strdup("-D__{mcu1}"));
 
-    sprintf(pic16incDir, "%s%cpic16", INCLUDE_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
-    sprintf(pic16libDir, "%s%cpic16", LIB_DIR_SUFFIX, DIR_SEPARATOR_CHAR);
+    if(!options.nostdinc) {
+      struct dbuf_s pic16incDir;
 
+      dbuf_init(&pic16incDir, 128);
+      dbuf_makePath(&pic16incDir, INCLUDE_DIR_SUFFIX, "pic16");
 
-    if(!options.nostdinc) {
       /* setup pic16 include directory */
-      pic16incDirsSet = appendStrSet(dataDirsSet, NULL, pic16incDir);
+      pic16incDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16incDir));
+      dbuf_destroy(&pic16incDir);
       includeDirsSet = pic16incDirsSet;
 //      mergeSets(&includeDirsSet, pic16incDirsSet);
     }
@@ -725,8 +725,13 @@ static void _pic16_initPaths(void)
     mergeSets(&pic16incDirsSet, userIncDirsSet);
 
     if(!options.nostdlib) {
+      struct dbuf_s pic16libDir;
+
+      dbuf_init(&pic16libDir, 128);
+      dbuf_makePath(&pic16libDir, INCLUDE_DIR_SUFFIX, "pic16");
       /* setup pic16 library directory */
-      pic16libDirsSet = appendStrSet(dataDirsSet, NULL, pic16libDir);
+      pic16libDirsSet = appendStrSet(dataDirsSet, NULL, dbuf_c_str(&pic16libDir));
+      dbuf_destroy(&pic16libDir);
       libDirsSet = pic16libDirsSet;
 //      mergeSets(&libDirsSet, pic16libDirsSet);
     }
index b4fe226ae82d56b2df93b9e1044777e3f22b5360..9cb878feae768e03fe634fe363563249122bfa45 100644 (file)
 extern char *pic16_aopGet (struct asmop *aop, int offset, bool bit16, bool dname);
 
 #if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
 #define inline
-#else
-#define STRCASECMP strcasecmp
 #endif
 
 #define DUMP_DF_GRAPHS 0
index e8814db571536fa57f7633a9eebe49d675030ac9..ec373e3358477a89c119be5c21a0e67899355907 100644 (file)
 #include "pcodeflow.h"
 #include "ralloc.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 pCodeOp *pic16_popCopyGPR2Bit(pCodeOpReg *pc, int bitval);
 
 pCodeOp *pic16_newpCodeOpWild(int id, pCodeWildBlock *pcwb, pCodeOp *subtype);
index 143e92b1b86c1c91ffc6fc710c3a04c4aa2782b3..1319ff89e97ba01cb0ae31a4c2cc8463879e9117 100644 (file)
 #include "gen.h"
 #include "device.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 #ifndef debugf
 #define debugf(frm, rest)       _debugf(__FILE__, __LINE__, frm, rest)
 #endif
index dd6fabb3bb12d2cddbab32f12fa7b5d7c4047a5a..bf86fa619ca685b20ae43a15d41d15e273f5019b 100755 (executable)
 #include "ralloc.h"
 #include "gen.h"
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 extern int allocInfo;
 
 /* this is the down and dirty file with all kinds of
index 08cf5b4cae3c5745927430f3c5ba9f163fcdfd39..dc639d94876a9fd0d809ab94c81c7e40ce7058cf 100644 (file)
 #include <string.h>
 #include <ctype.h>
 
-#if defined(__BORLANDC__) || defined(_MSC_VER)
-#define STRCASECMP stricmp
-#else
-#define STRCASECMP strcasecmp
-#endif
-
 #include "z80.h"
 #include "SDCCglobl.h"
 #include "SDCCpeeph.h"
index b78d99aac17b20736a6e3eda39af189a3cfd3fe8..30e657c571e9757900a1e807947563c691ba8049 100644 (file)
@@ -249,10 +249,7 @@ merge_command(const char *command, const char *params)
 static int
 has_path(const char *path)
 {
-  if (strrchr(path, DIR_SEPARATOR_CHAR) == NULL)
-      return 0;
-
-  return 1;
+  return splitPath(path, NULL, 0, NULL, 0);
 }