* support/cpp/libcpp/files.c: SDCPP synchronized with GCC CPP release version 4.3.2
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 30 Aug 2008 21:02:34 +0000 (21:02 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 30 Aug 2008 21:02:34 +0000 (21:02 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5223 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
support/cpp/libcpp/files.c

index 8c5b03581cdc4bb38a1c29e314d93f7807d5e398..c3a9771bff3627782e4b97453b73b4d5945c70e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-08-30 Borut Razem <borut.razem AT siol.net>
+
+       * support/cpp/libcpp/files.c: SDCPP synchronized with GCC CPP
+         release version 4.3.2
+
 2008-08-24 Raphael Neider <rneider AT web.de>
 
        * device/lib/pic16/configure, device/lib/pic16/configure.ac:
index 8be675b2939e2aeb2efe47fa9d0d4a27c7e33171..469a73af0c7529e59e7d4b10c73c739d6c68fd76 100644 (file)
@@ -602,7 +602,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
          type.  Use INTTYPE_MAXIMUM unconditionally to ensure this
          does not bite us.  */
 #ifndef __BORLANDC__
-      if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t))
+         if (file->st.st_size > INTTYPE_MAXIMUM (ssize_t))
         {
           cpp_error (pfile, CPP_DL_ERROR, "%s is too large", file->path);
           return false;
@@ -1229,12 +1229,19 @@ cpp_change_file (cpp_reader *pfile, enum lc_reason reason,
   _cpp_do_file_change (pfile, reason, new_name, 1, 0);
 }
 
+struct report_missing_guard_data
+{
+  const char **paths;
+  size_t count;
+};
+
 /* Callback function for htab_traverse.  */
 static int
-report_missing_guard (void **slot, void *b)
+report_missing_guard (void **slot, void *d)
 {
   struct file_hash_entry *entry = (struct file_hash_entry *) *slot;
-  int *bannerp = (int *) b;
+  struct report_missing_guard_data *data
+    = (struct report_missing_guard_data *) d;
 
   /* Skip directories.  */
   if (entry->start_dir != NULL)
@@ -1244,19 +1251,25 @@ report_missing_guard (void **slot, void *b)
       /* We don't want MI guard advice for the main file.  */
       if (file->cmacro == NULL && file->stack_count == 1 && !file->main_file)
         {
-          if (*bannerp == 0)
+          if (data->paths == NULL)
             {
-              fputs (_("Multiple include guards may be useful for:\n"),
-                     stderr);
-              *bannerp = 1;
+              data->paths = XCNEWVEC (const char *, data->count);
+              data->count = 0;
             }
 
-          fputs (entry->u.file->path, stderr);
-          putc ('\n', stderr);
+          data->paths[data->count++] = file->path;
         }
     }
 
-  return 0;
+  /* Keep traversing the hash table.  */
+  return 1;
+}
+
+/* Comparison function for qsort.  */
+static int
+report_missing_guard_cmp (const void *p1, const void *p2)
+{
+  return strcmp (*(const char *const *) p1, *(const char *const *) p2);
 }
 
 /* Report on all files that might benefit from a multiple include guard.
@@ -1264,9 +1277,29 @@ report_missing_guard (void **slot, void *b)
 void
 _cpp_report_missing_guards (cpp_reader *pfile)
 {
-  int banner = 0;
+  struct report_missing_guard_data data;
+
+  data.paths = NULL;
+  data.count = htab_elements (pfile->file_hash);
+  htab_traverse (pfile->file_hash, report_missing_guard, &data);
 
-  htab_traverse (pfile->file_hash, report_missing_guard, &banner);
+  if (data.paths != NULL)
+    {
+      size_t i;
+
+      /* Sort the paths to avoid outputting them in hash table
+         order.  */
+      qsort (data.paths, data.count, sizeof (const char *),
+             report_missing_guard_cmp);
+      fputs (_("Multiple include guards may be useful for:\n"),
+             stderr);
+      for (i = 0; i < data.count; i++)
+        {
+          fputs (data.paths[i], stderr);
+          putc ('\n', stderr);
+        }
+      free (data.paths);
+    }
 }
 
 /* Locate HEADER, and determine whether it is newer than the current