OSDN Git Service

Patch from Dara Hazeghi.
[pf3gnuchains/gcc-fork.git] / gcc / gcov.c
index 276918f..cc15f65 100644 (file)
@@ -417,17 +417,12 @@ print_usage (int error_p)
 static void
 print_version (void)
 {
-  char v[4];
-  unsigned version = GCOV_VERSION;
-  unsigned ix;
-
-  for (ix = 4; ix--; version >>= 8)
-    v[ix] = version;
-  fnotice (stdout, "gcov %.4s (GCC %s)\n", v, version_string);
-  fnotice (stdout, "Copyright (C) 2002 Free Software Foundation, Inc.\n");
+  fnotice (stdout, "gcov (GCC) %s\n", version_string);
+  fnotice (stdout, "Copyright (C) 2003 Free Software Foundation, Inc.\n");
   fnotice (stdout,
-          "This is free software; see the source for copying conditions.  There is NO\n\
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
+          "This is free software; see the source for copying conditions.\n"
+          "There is NO warranty; not even for MERCHANTABILITY or \n"
+          "FITNESS FOR A PARTICULAR PURPOSE.\n\n");
   exit (SUCCESS_EXIT_CODE);
 }
 
@@ -660,10 +655,10 @@ create_file_names (const char *file_name)
     *cptr = 0;
 
   length = strlen (name);
-
-  bbg_file_name = xmalloc (length + strlen (GCOV_GRAPH_SUFFIX) + 1);
+  
+  bbg_file_name = xmalloc (length + strlen (GCOV_NOTE_SUFFIX) + 1);
   strcpy (bbg_file_name, name);
-  strcpy (bbg_file_name + length, GCOV_GRAPH_SUFFIX);
+  strcpy (bbg_file_name + length, GCOV_NOTE_SUFFIX);
 
   da_file_name = xmalloc (length + strlen (GCOV_DATA_SUFFIX) + 1);
   strcpy (da_file_name, name);
@@ -715,7 +710,7 @@ read_graph_file (void)
       return 1;
     }
   bbg_file_time = gcov_time ();
-  if (gcov_read_unsigned () != GCOV_GRAPH_MAGIC)
+  if (!gcov_magic (gcov_read_unsigned (), GCOV_NOTE_MAGIC))
     {
       fnotice (stderr, "%s:not a gcov graph file\n", bbg_file_name);
       gcov_close ();
@@ -726,13 +721,10 @@ read_graph_file (void)
   if (version != GCOV_VERSION)
     {
       char v[4], e[4];
-      unsigned required = GCOV_VERSION;
 
-      for (ix = 4; ix--; required >>= 8, version >>= 8)
-       {
-         v[ix] = version;
-         e[ix] = required;
-       }
+      GCOV_UNSIGNED2STRING (v, version);
+      GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
+
       fnotice (stderr, "%s:version `%.4s', prefer `%.4s'\n",
               bbg_file_name, v, e);
     }
@@ -789,7 +781,7 @@ read_graph_file (void)
                     bbg_file_name, fn->name);
          else
            {
-             unsigned ix, num_blocks = length / 4;
+             unsigned ix, num_blocks = GCOV_TAG_BLOCKS_NUM (length);
              fn->num_blocks = num_blocks;
 
              fn->blocks
@@ -801,7 +793,7 @@ read_graph_file (void)
       else if (fn && tag == GCOV_TAG_ARCS)
        {
          unsigned src = gcov_read_unsigned ();
-         unsigned num_dests = (length - 4) / 8;
+         unsigned num_dests = GCOV_TAG_ARCS_NUM (length);
 
          if (src >= fn->num_blocks || fn->blocks[src].succ)
            goto corrupt;
@@ -860,7 +852,7 @@ read_graph_file (void)
        {
          unsigned blockno = gcov_read_unsigned ();
          unsigned *line_nos
-           = (unsigned *)xcalloc ((length - 4) / 4, sizeof (unsigned));
+           = (unsigned *)xcalloc (length - 1, sizeof (unsigned));
 
          if (blockno >= fn->num_blocks || fn->blocks[blockno].u.line.encoding)
            goto corrupt;
@@ -984,7 +976,7 @@ read_count_file (void)
       fnotice (stderr, "%s:cannot open data file\n", da_file_name);
       return 1;
     }
-  if (gcov_read_unsigned () != GCOV_DATA_MAGIC)
+  if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC))
     {
       fnotice (stderr, "%s:not a gcov data file\n", da_file_name);
     cleanup:;
@@ -995,13 +987,10 @@ read_count_file (void)
   if (version != GCOV_VERSION)
     {
       char v[4], e[4];
-      unsigned desired = GCOV_VERSION;
 
-      for (ix = 4; ix--; desired >>= 8, version >>= 8)
-       {
-         v[ix] = version;
-         e[ix] = desired;
-       }
+      GCOV_UNSIGNED2STRING (v, version);
+      GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
+      
       fnotice (stderr, "%s:version `%.4s', prefer version `%.4s'\n",
               da_file_name, v, e);
     }
@@ -1054,7 +1043,7 @@ read_count_file (void)
        }
       else if (tag == GCOV_TAG_FOR_COUNTER (GCOV_COUNTER_ARCS) && fn)
        {
-         if (length != 8 * fn->num_counts)
+         if (length != GCOV_TAG_COUNTER_LENGTH (fn->num_counts))
            goto mismatch;
 
          if (!fn->counts)