Imported Upstream version 7.9
[platform/upstream/gdb.git] / bfd / doc / chew.c
index f949e1f..af7c01b 100644 (file)
@@ -1,7 +1,5 @@
 /* chew
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001,
-   2002, 2003, 2005, 2007, 2009, 2012
-   Free Software Foundation, Inc.
+   Copyright (C) 1990-2015 Free Software Foundation, Inc.
    Contributed by steve chamberlain @cygnus
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -267,6 +265,19 @@ skip_white_and_stars (src, idx)
   return idx;
 }
 
+static unsigned int
+skip_past_newline_1 (ptr, idx)
+     string_type *ptr;
+     unsigned int idx;
+{
+  while (at (ptr, idx)
+        && at (ptr, idx) != '\n')
+    idx++;
+  if (at (ptr, idx) == '\n')
+    return idx + 1;
+  return idx;
+}
+
 /***********************************************************************/
 
 string_type stack[STACK];
@@ -476,8 +487,10 @@ remove_noncomments (src, dst)
 static void
 print_stack_level ()
 {
-  fprintf (stderr, "current string stack depth = %ld, ", tos - stack);
-  fprintf (stderr, "current integer stack depth = %ld\n", isp - istack);
+  fprintf (stderr, "current string stack depth = %ld, ",
+          (long) (tos - stack));
+  fprintf (stderr, "current integer stack depth = %ld\n",
+          (long) (isp - istack));
   pc++;
 }
 
@@ -603,10 +616,12 @@ outputdots ()
 
   while (at (tos, idx))
     {
-      if (at (tos, idx) == '\n' && at (tos, idx + 1) == '.')
+      /* Every iteration begins at the start of a line.  */
+      if (at (tos, idx) == '.')
        {
          char c;
-         idx += 2;
+
+         idx++;
 
          while ((c = at (tos, idx)) && c != '\n')
            {
@@ -626,11 +641,13 @@ outputdots ()
                  idx++;
                }
            }
+         if (c == '\n')
+           idx++;
          catchar (&out, '\n');
        }
       else
        {
-         idx++;
+         idx = skip_past_newline_1 (tos, idx);
        }
     }
 
@@ -1095,10 +1112,7 @@ icatstr ()
 static void
 skip_past_newline ()
 {
-  while (at (ptr, idx)
-        && at (ptr, idx) != '\n')
-    idx++;
-  idx++;
+  idx = skip_past_newline_1 (ptr, idx);
   pc++;
 }
 
@@ -1256,7 +1270,7 @@ perform ()
                fprintf (stderr, "warning, %s is not recognised\n", next);
              skip_past_newline ();
            }
-
+         free (next);
        }
       else
        skip_past_newline ();
@@ -1564,7 +1578,7 @@ main (ac, av)
   if (tos != stack)
     {
       fprintf (stderr, "finishing with current stack level %ld\n",
-              tos - stack);
+              (long) (tos - stack));
       return 1;
     }
   return 0;