* src/regression/init0.c: new test for initialized arrays of function
[fw/sdcc] / src / pic / device.c
index fc35b7e16c0542123fbcb96dd9aede463c1685f1..442292ef93d80d92e4b90e8cd8f75685e618837f 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;
 
@@ -166,11 +158,10 @@ static void register_map(int num_words, char word[SPLIT_WORDS_MAX][PIC14_STRING_
                r->end_address = parse_config_value(word[pcount]);
                r->alias = parse_config_value(word[1]);
                r->bank = (r->start_address >> 7) & 3;
+               // add memRange to device entry for future lookup (sharebanks)
+               r->next = rangeRAM;
+               rangeRAM = r;
        }
-       
-       // add memRange to device entry for future lookup (sharebanks)
-       r->next = rangeRAM;
-       rangeRAM = r;
 }
 
 
@@ -202,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;
@@ -233,64 +224,78 @@ 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';
        while (fgets(pic_buf, sizeof(pic_buf)-1, pic_file) != NULL && !done) {
+               unsigned llen;
+               llen = strlen (pic_buf);
                
                /* remove trailing spaces */
-               while (isspace(pic_buf[strlen(pic_buf)-1]))
-                       pic_buf[strlen(pic_buf)-1] = '\0';
+               while (llen && isspace(pic_buf[llen-1])) {
+                       pic_buf[llen-1] = '\0';
+                       llen--;
+               }
                
                /* remove leading spaces */
                for (pic_buf_pos = pic_buf; isspace(*pic_buf_pos); pic_buf_pos++)