]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Some code simplification.
authorBruno Haible <bruno@clisp.org>
Tue, 27 Nov 2001 13:14:29 +0000 (13:14 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 21:26:48 +0000 (23:26 +0200)
src/ChangeLog
src/x-c.c

index 67e3634f9b534a6e5e4fe93f7e11fb0f738536a7..ec3d761379c3617764e9e115f025ad4f11e9e126 100644 (file)
@@ -1,3 +1,9 @@
+2001-11-25  Bruno Haible  <bruno@clisp.org>
+
+       * x-c.c (comment_start, comment_add, comment_line_end): New inline
+       functions.
+       (phase4_getc): Use them.
+
 2001-11-25  Bruno Haible  <bruno@clisp.org>
 
        * msginit.c (no_translator): New variable.
index 6b762116c8a2bbfdf6529de67af3add6537218fd..cc32b0ddfe9bc9d9ca972447e27583b2e79177d0 100644 (file)
--- a/src/x-c.c
+++ b/src/x-c.c
@@ -165,6 +165,9 @@ static int phase2_getc PARAMS ((void));
 static void phase2_ungetc PARAMS ((int c));
 static int phase3_getc PARAMS ((void));
 static void phase3_ungetc PARAMS ((int c));
+static inline void comment_start PARAMS ((void));
+static inline void comment_add PARAMS ((int c));
+static inline void comment_line_end PARAMS ((size_t chars_to_remove));
 static int phase4_getc PARAMS ((void));
 static void phase4_ungetc PARAMS ((int c));
 static int phase7_getc PARAMS ((void));
@@ -365,6 +368,48 @@ phase3_ungetc (c)
 }
 
 
+/* Accumulating comments.  */
+
+static char *buffer;
+static size_t bufmax;
+size_t buflen;
+
+static inline void
+comment_start ()
+{
+  buflen = 0;
+}
+
+static inline void
+comment_add (c)
+     int c;
+{
+  if (buflen >= bufmax)
+    {
+      bufmax += 100;
+      buffer = xrealloc (buffer, bufmax);
+    }
+  buffer[buflen++] = c;
+}
+
+static inline void
+comment_line_end (chars_to_remove)
+     size_t chars_to_remove;
+{
+  buflen -= chars_to_remove;
+  while (buflen >= 1
+        && (buffer[buflen - 1] == ' ' || buffer[buflen - 1] == '\t'))
+    --buflen;
+  if (chars_to_remove == 0 && buflen >= bufmax)
+    {
+      bufmax += 100;
+      buffer = xrealloc (buffer, bufmax);
+    }
+  buffer[buflen] = '\0';
+  xgettext_comment_add (buffer);
+}
+
+
 /* 4. Replace each comment that is not inside a character constant or
    string literal with a space character.  We need to remember the
    comment for later, because it may be attached to a keyword string.
@@ -373,9 +418,6 @@ phase3_ungetc (c)
 static int
 phase4_getc ()
 {
-  static char *buffer;
-  static size_t bufmax;
-  size_t buflen;
   int c;
   bool last_was_star;
 
@@ -391,7 +433,7 @@ phase4_getc ()
 
     case '*':
       /* C comment.  */
-      buflen = 0;
+      comment_start ();
       last_was_star = false;
       while (1)
        {
@@ -399,24 +441,13 @@ phase4_getc ()
          if (c == EOF)
            break;
          /* We skip all leading white space, but not EOLs.  */
-         if (buflen == 0 && isspace (c) && c != '\n')
-           continue;
-         if (buflen >= bufmax)
-           {
-             bufmax += 100;
-             buffer = xrealloc (buffer, bufmax);
-           }
-         buffer[buflen++] = c;
+         if (!(buflen == 0 && (c == ' ' || c == '\t')))
+           comment_add (c);
          switch (c)
            {
            case '\n':
-             --buflen;
-             while (buflen >= 1 && (buffer[buflen - 1] == ' '
-                                    || buffer[buflen - 1] == '\t'))
-               --buflen;
-             buffer[buflen] = 0;
-             xgettext_comment_add (buffer);
-             buflen = 0;
+             comment_line_end (1);
+             comment_start ();
              last_was_star = false;
              continue;
 
@@ -427,12 +458,7 @@ phase4_getc ()
            case '/':
              if (last_was_star)
                {
-                 buflen -= 2;
-                 while (buflen >= 1 && (buffer[buflen - 1] == ' '
-                                        || buffer[buflen - 1] == '\t'))
-                   --buflen;
-                 buffer[buflen] = 0;
-                 xgettext_comment_add (buffer);
+                 comment_line_end (2);
                  break;
                }
              /* FALLTHROUGH */
@@ -448,26 +474,15 @@ phase4_getc ()
 
     case '/':
       /* C++ or ISO C 99 comment.  */
-      buflen = 0;
+      comment_start ();
       while (1)
        {
          c = phase3_getc ();
          if (c == '\n' || c == EOF)
            break;
-         if (buflen >= bufmax)
-           {
-             bufmax += 100;
-             buffer = xrealloc (buffer, bufmax);
-           }
-         buffer[buflen++] = c;
-       }
-      if (buflen >= bufmax)
-       {
-         bufmax += 100;
-         buffer = xrealloc (buffer, bufmax);
+         comment_add (c);
        }
-      buffer[buflen] = 0;
-      xgettext_comment_add (buffer);
+      comment_line_end (0);
       last_comment_line = newline_count;
       return '\n';
     }