* src/pic/device.c (find_device): search user-specified paths first
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 3 Mar 2008 01:27:36 +0000 (01:27 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 3 Mar 2008 01:27:36 +0000 (01:27 +0000)
  for pic14devices.txt, fixes #1900827

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

ChangeLog
src/pic/device.c

index 75b55f2b8677e853f00659b37cd7030a85827990..b33c1ca3650c7538bdc5b1733d00c4addf903a0d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-03-03 Raphael Neider <rneider AT web.de>
+
+       * src/pic/device.c (find_device): search user-specified paths first
+         for pic14devices.txt, fixes #1900827
+
 2008-03-02 Borut Razem <borut.razem AT siol.net>
 
        * support/scripts/sdcc.nsi: fixed bug in IsNT, LogicLib-isation of
index 528cde2767cc51e0f19956b8942a919cecf64504..442292ef93d80d92e4b90e8cd8f75685e618837f 100644 (file)
@@ -193,8 +193,8 @@ extern set *userIncDirsSet;
 extern set *libDirsSet;
 extern set *libPathsSet;
 
-/* read the file with all the pic14 definitions and pick out the definition for a processor
- * if specified. if pic_name is NULL reads everything */
+/* read the file with all the pic14 definitions and pick out the definition
+ * for a processor if specified. if pic_name is NULL reads everything */
 static PIC_device *find_device(char *pic_name)
 {
        FILE *pic_file;
@@ -224,56 +224,66 @@ static PIC_device *find_device(char *pic_name)
        /* first scan all include directories */
        pic_file = NULL;
        //fprintf( stderr, "%s: searching %s\n", __FUNCTION__, DEVICE_FILE_NAME );
-       for (dir = setFirstItem(includeDirsSet);
+       for (dir = setFirstItem(userIncDirsSet);
                !pic_file && dir;
-               dir = setNextItem(includeDirsSet))
+               dir = setNextItem(userIncDirsSet))
        {
          //fprintf( stderr, "searching1 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
+         SNPRINTF(&filename[0], len, "%s%s", dir,
+           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
          pic_file = fopen( filename, "rt" );
          if (pic_file) break;
        } // for
-       for (dir = setFirstItem(userIncDirsSet);
+
+       for (dir = setFirstItem(includeDirsSet);
                !pic_file && dir;
-               dir = setNextItem(userIncDirsSet))
+               dir = setNextItem(includeDirsSet))
        {
          //fprintf( stderr, "searching2 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
+         SNPRINTF(&filename[0], len, "%s%s", dir,
+           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
          pic_file = fopen( filename, "rt" );
          if (pic_file) break;
        } // for
+
        for (dir = setFirstItem(libDirsSet);
                !pic_file && dir;
                dir = setNextItem(libDirsSet))
        {
          //fprintf( stderr, "searching3 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
+         SNPRINTF(&filename[0], len, "%s%s", dir,
+           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
          pic_file = fopen( filename, "rt" );
          if (pic_file) break;
        } // for
+
        for (dir = setFirstItem(libPathsSet);
                !pic_file && dir;
                dir = setNextItem(libPathsSet))
        {
          //fprintf( stderr, "searching4 %s\n", dir );
-         SNPRINTF(&filename[0], len, "%s%s%s", dir, DIR_SEPARATOR_STRING, DEVICE_FILE_NAME);
+         SNPRINTF(&filename[0], len, "%s%s", dir,
+           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
          pic_file = fopen( filename, "rt" );
          if (pic_file) break;
        } // for
+
        if (!pic_file) {
-         pic_file = fopen(DATADIR LIB_DIR_SUFFIX DIR_SEPARATOR_STRING "pic" DIR_SEPARATOR_STRING DEVICE_FILE_NAME, "rt");
-       }
-       if (pic_file == NULL) {
-               /* this second attempt is used when initially building the libraries */
-               pic_file = fopen(".." DIR_SEPARATOR_STRING ".." DIR_SEPARATOR_STRING ".." DIR_SEPARATOR_STRING ".." 
-                               DIR_SEPARATOR_STRING "src" DIR_SEPARATOR_STRING "pic" DIR_SEPARATOR_STRING 
-                               DEVICE_FILE_NAME, "rt");
-               if (pic_file == NULL) {
-                       fprintf(stderr, "can't find %s\n", DATADIR LIB_DIR_SUFFIX DIR_SEPARATOR_STRING "pic" 
-                                       DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
-                       return NULL;
-               }
-       }
+         SNPRINTF(&filename[0], len, "%s",
+           DATADIR LIB_DIR_SUFFIX
+           DIR_SEPARATOR_STRING "pic"
+           DIR_SEPARATOR_STRING DEVICE_FILE_NAME);
+         pic_file = fopen( filename, "rt" );
+       } // if
+
+        if (pic_file == NULL) {
+            fprintf(stderr, "can't find %s\n", DEVICE_FILE_NAME);
+            return NULL;
+        } // if
+
+       if (options.verbose) {
+           printf ("Using devices from %s.\n", filename);
+       } // if
        
        /* read line by line */
        pic_buf[sizeof(pic_buf)-1] = '\0';