]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Cleanup po_scan entry point.
authorBruno Haible <bruno@clisp.org>
Tue, 22 Apr 2003 10:49:59 +0000 (10:49 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:23 +0000 (12:10 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/po.c
gettext-tools/src/po.h

index fd9ba943072206fcc12ef0d1da99666071764978..1f9f149932c33a32d007b5e644277c6892ebe6ee 100644 (file)
@@ -1,3 +1,10 @@
+2003-04-13  Bruno Haible  <bruno@clisp.org>
+
+       * po.h (po_scan_start, po_scan_end): New declarations.
+       * po.c: Reorder functions.
+       (po_scan_start, po_scan_end): New functions.
+       (po_scan, po_scan_file): Use them.
+
 2003-04-12  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.vms: New variables ABIFLAGS, DEFS. Avoid rules with no
index 20caa306be6e76625fa9ac4657efe0260eb2f567..1d2f4e3a9039d00fc7d589b7c48a026a77d2e348 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-1996, 1998, 2000-2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1996, 1998, 2000-2003 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -76,8 +76,7 @@ po_parse_debrief (po_ty *pop)
 
 
 void
-po_scan (po_ty *pop, FILE *fp,
-        const char *real_filename, const char *logical_filename)
+po_scan_start (po_ty *pop)
 {
   /* The parse will call the po_callback_... functions (see below)
      when the various directive are recognised.  The callback_arg
@@ -85,32 +84,39 @@ po_scan (po_ty *pop, FILE *fp,
      have the relevant method invoked.  */
   callback_arg = pop;
 
+  po_parse_brief (pop);
+}
+
+void
+po_scan_end (po_ty *pop)
+{
+  po_parse_debrief (pop);
+  callback_arg = NULL;
+}
+
+
+void
+po_scan (po_ty *pop, FILE *fp,
+        const char *real_filename, const char *logical_filename)
+{
   /* Parse the stream's content.  */
   lex_start (fp, real_filename, logical_filename);
-  po_parse_brief (pop);
+  po_scan_start (pop);
   po_gram_parse ();
-  po_parse_debrief (pop);
+  po_scan_end (pop);
   lex_end ();
-  callback_arg = NULL;
 }
 
 
 void
 po_scan_file (po_ty *pop, const char *filename)
 {
-  /* The parse will call the po_callback_... functions (see below)
-     when the various directive are recognised.  The callback_arg
-     variable is used to tell these functions which instance is to
-     have the relevant method invoked.  */
-  callback_arg = pop;
-
   /* Open the file and parse it.  */
   lex_open (filename);
-  po_parse_brief (pop);
+  po_scan_start (pop);
   po_gram_parse ();
-  po_parse_debrief (pop);
+  po_scan_end (pop);
   lex_close ();
-  callback_arg = NULL;
 }
 
 
@@ -122,6 +128,8 @@ po_directive_domain (po_ty *pop, char *name)
 }
 
 
+/* This function is called by po_gram_lex() whenever a domain directive
+   has been seen.  */
 void
 po_callback_domain (char *name)
 {
@@ -145,6 +153,8 @@ po_directive_message (po_ty *pop,
 }
 
 
+/* This function is called by po_gram_lex() whenever a message has been
+   seen.  */
 void
 po_callback_message (char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
                     char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
@@ -161,14 +171,6 @@ po_callback_message (char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
 }
 
 
-static void
-po_comment_special (po_ty *pop, const char *s)
-{
-  if (pop->method->comment_special != NULL)
-    pop->method->comment_special (pop, s);
-}
-
-
 static void
 po_comment (po_ty *pop, const char *s)
 {
@@ -185,48 +187,6 @@ po_comment_dot (po_ty *pop, const char *s)
 }
 
 
-/* This function is called by po_gram_lex() whenever a comment is
-   seen.  It analyzes the comment to see what sort it is, and then
-   dispatces it to the appropriate method.  */
-void
-po_callback_comment (const char *s)
-{
-  /* assert(callback_arg); */
-  if (*s == '.')
-    po_comment_dot (callback_arg, s + 1);
-  else if (*s == ':')
-    {
-      /* Parse the file location string.  If the parse succeeds, the
-        appropriate callback will be invoked.  If the parse fails,
-        the po_hash function will return non-zero - so pretend it was
-        a normal comment.  */
-      if (po_hash (s + 1) == 0)
-       /* Do nothing, it is a GNU-style file pos line.  */ ;
-      else
-       po_comment (callback_arg, s + 1);
-    }
-  else if (*s == ',' || *s == '!')
-    {
-      /* Get all entries in the special comment line.  */
-      po_comment_special (callback_arg, s + 1);
-    }
-  else
-    {
-      /* It looks like a plain vanilla comment, but Solaris-style file
-        position lines do, too.  Rather than parse the lot, only look
-        at lines that could start with "# File..." This minimizes
-        memory leaks on failed parses.  If the parse succeeds, the
-        appropriate callback will be invoked.  */
-      if (s[0] == ' ' && (s[1] == 'F' || s[1] == 'f') && s[2] == 'i'
-         && s[3] == 'l' && s[4] == 'e' && s[5] == ':'
-         && po_hash (s) == 0)
-       /* Do nothing, it is a Sun-style file pos line.  */ ;
-      else
-       po_comment (callback_arg, s);
-    }
-}
-
-
 static void
 po_comment_filepos (po_ty *pop, const char *name, size_t line)
 {
@@ -235,6 +195,7 @@ po_comment_filepos (po_ty *pop, const char *name, size_t line)
 }
 
 
+/* This function is called by po_hash(), once for each filename.  */
 void
 po_callback_comment_filepos (const char *name, size_t line)
 {
@@ -243,6 +204,14 @@ po_callback_comment_filepos (const char *name, size_t line)
 }
 
 
+static void
+po_comment_special (po_ty *pop, const char *s)
+{
+  if (pop->method->comment_special != NULL)
+    pop->method->comment_special (pop, s);
+}
+
+
 /* Parse a special comment and put the result in *fuzzyp, formatp, *wrapp.  */
 void
 po_parse_comment_special (const char *s,
@@ -338,3 +307,46 @@ po_parse_comment_special (const char *s,
        }
     }
 }
+
+
+/* This function is called by po_gram_lex() whenever a comment is
+   seen.  It analyzes the comment to see what sort it is, and then
+   dispatches it to the appropriate method: po_comment, po_comment_dot,
+   po_comment_filepos (via po_hash), or po_comment_special.  */
+void
+po_callback_comment (const char *s)
+{
+  /* assert(callback_arg); */
+  if (*s == '.')
+    po_comment_dot (callback_arg, s + 1);
+  else if (*s == ':')
+    {
+      /* Parse the file location string.  If the parse succeeds, the
+        appropriate callback will be invoked.  If the parse fails,
+        the po_hash function will return non-zero - so pretend it was
+        a normal comment.  */
+      if (po_hash (s + 1) == 0)
+       /* Do nothing, it is a GNU-style file pos line.  */ ;
+      else
+       po_comment (callback_arg, s + 1);
+    }
+  else if (*s == ',' || *s == '!')
+    {
+      /* Get all entries in the special comment line.  */
+      po_comment_special (callback_arg, s + 1);
+    }
+  else
+    {
+      /* It looks like a plain vanilla comment, but Solaris-style file
+        position lines do, too.  Rather than parse the lot, only look
+        at lines that could start with "# File..." This minimizes
+        memory leaks on failed parses.  If the parse succeeds, the
+        appropriate callback will be invoked.  */
+      if (s[0] == ' ' && (s[1] == 'F' || s[1] == 'f') && s[2] == 'i'
+         && s[3] == 'l' && s[4] == 'e' && s[5] == ':'
+         && po_hash (s) == 0)
+       /* Do nothing, it is a Sun-style file pos line.  */ ;
+      else
+       po_comment (callback_arg, s);
+    }
+}
index a088ff01aa13a749f36a1a1daf21d01705e304b6..e741e7a8573c009f7f27fdf44b0762951e02fb23 100644 (file)
@@ -1,5 +1,5 @@
 /* GNU gettext - internationalization aids
-   Copyright (C) 1995-1996, 1998, 2000-2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1996, 1998, 2000-2003 Free Software Foundation, Inc.
 
    This file was written by Peter Miller <millerp@canb.auug.org.au>
 
@@ -122,6 +122,12 @@ struct po_ty
    constructor.  */
 extern po_ty *po_alloc (po_method_ty *jtable);
 
+/* Prepare for use of po_method_ty methods.  */
+extern void po_scan_start (po_ty *pop);
+
+/* Terminate the use of po_method_ty methods.  */
+extern void po_scan_end (po_ty *pop);
+
 /* Read a PO file from a stream, and dispatch to the various po_method_ty
    methods.  */
 extern void po_scan (po_ty *pop, FILE *fp, const char *real_filename,