removed obsolete and buggy ARRAYINIT
[fw/sdcc] / src / SDCCmain.c
index ab0e117c1c64652aae9551ba3f30b1b18674f94d..83d4db79b205508ced2878780294407ca668215f 100644 (file)
@@ -49,7 +49,6 @@ char *fullSrcFileName;                /* full name for the source file; */
                                /* can be NULL while c1mode or linking without compiling */
 char *fullDstFileName;         /* full name for the output file; */
                                /* only given by -o, otherwise NULL */
-size_t fullDstFileNameLen;     /* size of previous string. */
 char *dstFileName;             /* destination file name without extension */
 char *dstPath = "";            /* path for the output files; */
                                /* "" is equivalent with cwd */
@@ -120,6 +119,7 @@ char buffer[PATH_MAX * 2];
 #define OPTION_CODE_SIZE       "--code-size"
 #define OPTION_NO_CCODE_IN_ASM "--no-c-code-in-asm"
 #define OPTION_ICODE_IN_ASM    "--i-code-in-asm"
+#define OPTION_PRINT_SEARCH_DIRS "--print-search-dirs"
 
 static const OPTION
 optionsTable[] = {
@@ -206,6 +206,7 @@ optionsTable[] = {
     { 0,    OPTION_NO_XINIT_OPT,    &options.noXinitOpt, "don't memcpy initialized xram from code"},
     { 0,    OPTION_NO_CCODE_IN_ASM, &options.noCcodeInAsm, "don't include c-code as comments in the asm file"},
     { 0,    OPTION_ICODE_IN_ASM,    &options.iCodeInAsm, "include i-code as comments in the asm file"},
+    { 0,    OPTION_PRINT_SEARCH_DIRS, &options.printSearchDirs, "display the directories in the compiler's search path"},
     /* End of options */
     { 0,    NULL }
 };
@@ -273,6 +274,9 @@ static PORT *_ports[] =
 #if !OPT_DISABLE_XA51
   &xa51_port,
 #endif
+#if !OPT_DISABLE_DS400
+  &ds400_port, 
+#endif 
 };
 
 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
@@ -385,13 +389,13 @@ printVersionInfo ()
 #ifdef __CYGWIN__
           " (CYGWIN)\n"
 #elif defined __MINGW32__
-          " (MINGW32) \n"
+          " (MINGW32)\n"
 #elif defined __DJGPP__
-          " (DJGPP) \n"
+          " (DJGPP)\n"
 #elif defined(_MSC_VER)
-          " (MSVC) \n"
+          " (MSVC)\n"
 #elif defined(__BORLANDC__)
-          " (BORLANDC) \n"
+          " (BORLANDC)\n"
 #else
           " (UNIX) \n"
 #endif
@@ -642,20 +646,20 @@ _setModel (int model, const char *sz)
 static char *
 getStringArg(const char *szStart, char **argv, int *pi, int argc)
 {
-  if (argv[*pi][strlen(szStart)]) 
+  if (argv[*pi][strlen(szStart)])
     {
       return &argv[*pi][strlen(szStart)];
     }
-  else 
+  else
     {
       ++(*pi);
-      if (*pi >= argc) 
+      if (*pi >= argc)
         {
           werror (E_ARGUMENT_MISSING, szStart);
           /* Die here rather than checking for errors later. */
           exit(-1);
         }
-      else 
+      else
         {
           return argv[*pi];
         }
@@ -663,7 +667,7 @@ getStringArg(const char *szStart, char **argv, int *pi, int argc)
 }
 
 /** Gets the integer argument to this option using the same rules as
-    getStringArg. 
+    getStringArg.
 */
 static int
 getIntArg(const char *szStart, char **argv, int *pi, int argc)
@@ -1060,7 +1064,6 @@ parseCmdLine (int argc, char **argv)
                 else
                   {
                     fullDstFileName = Safe_strdup (buffer);
-                   fullDstFileNameLen = strlen(fullDstFileName) + 1;
 
                     /* get rid of the "."-extension */
 
@@ -1259,7 +1262,7 @@ parseCmdLine (int argc, char **argv)
   /* if debug option is set then open the cdbFile */
   if (options.debug && fullSrcFileName)
     {
-      SNPRINTF (scratchFileName, sizeof(scratchFileName), 
+      SNPRINTF (scratchFileName, sizeof(scratchFileName),
                "%s.adb", dstFileName); //JCF: Nov 30, 2002
       if(debugFile->openFile(scratchFileName))
        debugFile->writeModule(moduleName);
@@ -1280,7 +1283,7 @@ linkEdit (char **envp)
   int i, system_ret;
 
   /* first we need to create the <filename>.lnk file */
-  SNPRINTF (scratchFileName, sizeof(scratchFileName), 
+  SNPRINTF (scratchFileName, sizeof(scratchFileName),
            "%s.lnk", dstFileName);
   if (!(lnkfile = fopen (scratchFileName, "w")))
     {
@@ -1357,7 +1360,21 @@ linkEdit (char **envp)
          break;
        case MODEL_FLAT24:
          /* c = "flat24"; */
-         c = "ds390";
+           if (TARGET_IS_DS390)
+           {
+               c = "ds390";
+           }
+           else if (TARGET_IS_DS400)
+           {
+               c = "ds400";
+           }
+           else
+           {
+               fprintf(stderr, 
+                       "Add support for your FLAT24 target in %s @ line %d\n",
+                       __FILE__, __LINE__);
+               exit(-1);
+           }
          break;
        case MODEL_PAGE0:
          c = "xa51";
@@ -1373,7 +1390,21 @@ linkEdit (char **envp)
 #if !OPT_DISABLE_DS390
       if (options.model == MODEL_FLAT24)
        {
-         fprintf (lnkfile, "-l %s\n", STD_DS390_LIB);
+           if (TARGET_IS_DS390)
+           {
+               fprintf (lnkfile, "-l %s\n", STD_DS390_LIB);
+           }
+           else if (TARGET_IS_DS400)
+           {
+               fprintf (lnkfile, "-l %s\n", STD_DS400_LIB);
+           }
+           else
+           {
+               fprintf(stderr, 
+                       "Add support for your FLAT24 target in %s @ line %d\n",
+                       __FILE__, __LINE__);
+               exit(-1);
+           }
        }
 #endif
 
@@ -1459,43 +1490,36 @@ linkEdit (char **envp)
       else
         {
           strncpyz (scratchFileName, relFiles[0], sizeof(scratchFileName));
-          /* strip "rel" extension */
+          /* strip ".rel" extension */
           p = strrchr (scratchFileName, '.');
          if (p)
            {
-               p++;
-               *p = 0;
+             *p = 0;
            }
-           
         }
       strncatz (scratchFileName,
-               options.out_fmt ? "S19" : "ihx",
+               options.out_fmt ? ".S19" : ".ihx",
                sizeof(scratchFileName));
       rename (scratchFileName, fullDstFileName);
 
-      q = strrchr (fullDstFileName, '.');
-      if (q)
-        {
-          /* point after the '.' of the extension */
-          q++;
-        }
-      else
+      strncpyz (buffer, fullDstFileName, sizeof(buffer));
+      q = strrchr (buffer, '.');
+      if (!q)
         {
           /* no extension: append new extensions */
-         /* Don't we want to append a period here ? */
-          q = strlen (fullDstFileName) + fullDstFileName;
+          q = strlen (buffer) + buffer;
         }
-               
-      *p = 0;  
-      strncatz (scratchFileName, "map", sizeof(scratchFileName));
+
+      *p = 0;
+      strncatz (scratchFileName, ".map", sizeof(scratchFileName));
       *q = 0;
-      strncatz(fullDstFileName, "map", fullDstFileNameLen);
-      rename (scratchFileName, fullDstFileName);
-      *p = 0;  
-      strncatz (scratchFileName, "mem", sizeof(scratchFileName));
+      strncatz(buffer, ".map", sizeof(buffer));
+      rename (scratchFileName, buffer);
+      *p = 0;
+      strncatz (scratchFileName, ".mem", sizeof(scratchFileName));
       *q = 0;
-      strncatz(fullDstFileName, "mem", fullDstFileNameLen);    
-      rename (scratchFileName, fullDstFileName);
+      strncatz(buffer, ".mem", sizeof(buffer));
+      rename (scratchFileName, buffer);
     }
   if (system_ret)
     {
@@ -1665,7 +1689,7 @@ setBinPaths(const char *argv0)
    */
 
   /* do it in reverse mode, so that addSetHead() can be used
-     instaed of slower addSet() */
+     instead of slower addSet() */
 
   if ((p = getBinPath(argv0)) != NULL)
     addSetHead(&binPathSet, Safe_strdup(p));
@@ -1674,6 +1698,16 @@ setBinPaths(const char *argv0)
     SNPRINTF(buf, sizeof buf, "%s" PREFIX2BIN_DIR, p);
     addSetHead(&binPathSet, Safe_strdup(buf));
   }
+
+  if (options.printSearchDirs) {
+    printf("programs: ");
+    if (NULL != (p = (char *)setFirstItem(binPathSet))) {
+      printf("%s", p);
+      while (NULL != (p = (char *)setNextItem(binPathSet)))
+        printf(":%s", p);
+    }
+    putchar('\n');
+  }
 }
 
 /* Set system include path */
@@ -1697,6 +1731,9 @@ setIncludePath(const char *datadir)
     p = buf;
   }
 
+  if (options.printSearchDirs)
+    printf("includedir: %s\n", p);
+
   setMainValue ("includedir", p);
 }
 
@@ -1721,6 +1758,9 @@ setLibPath(const char *datadir)
     p = buf;
   }
 
+  if (options.printSearchDirs)
+    printf("libdir: %s\n", p);
+
   setMainValue ("libdir", p);
 }
 
@@ -1743,18 +1783,23 @@ setDataPaths(const char *argv0)
     SNPRINTF(buf, sizeof buf, "%s" PREFIX2DATA_DIR, p);
     p = buf;
   }
-  else {
-    if ((p = getBinPath(argv0)) == NULL)
-      p = ".";
-
+  else if ((p = getBinPath(argv0)) != NULL) {
     SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p);
     p = buf;
-
-#ifndef _WIN32  /* *nix paltform */
-    if (!pathExists(p))
-      p = DATADIR; /* last resort */
-#endif
   }
+#ifdef _WIN32
+  else {
+    /* this should never happen... */
+    wassertl(0, "Can't get binary path");
+    p = ".";
+  }
+#else
+  if (!pathExists(p))
+    p = DATADIR; /* last resort */
+#endif
+
+  if (options.printSearchDirs)
+    printf("datadir: %s\n", p);
 
   setIncludePath(p);
   setLibPath(p);
@@ -1874,9 +1919,6 @@ main (int argc, char **argv, char **envp)
   if (port->init)
     port->init ();
 
-  // Create a default exe search path from the path to the sdcc command
-
-
   setDefaultOptions ();
 #ifdef JAMIN_DS390
   if (ds390_jammed) {
@@ -1886,17 +1928,18 @@ main (int argc, char **argv, char **envp)
 #endif
   parseCmdLine (argc, argv);
 
-  /* if no input then printUsage & exit */
-  if (!options.c1mode && !fullSrcFileName && !nrelFiles)
-    {
-      printUsage ();
-      exit (0);
-    }
-
   initValues ();
   setBinPaths(argv[0]);
   setDataPaths(argv[0]);
 
+  /* if no input then printUsage & exit */
+  if (!options.c1mode && !fullSrcFileName && !nrelFiles) {
+    if (!options.printSearchDirs)
+      printUsage();
+
+    exit(0);
+  }
+
   /* initMem() is expensive, but
      initMem() must called before port->finaliseOptions ().
      And the z80 port needs port->finaliseOptions(),