This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

intl patches (26)



msgfmt also needs to check the plural formula, so that 1. core dumps at run
time through formulas like "plural= 1 + (1/n)" can be caught, 2. the nplurals
value can be checked against the formula. To this effect, it is very useful
if msgfmt can reuse the plural form evaluation code from libintl. Here is
a patch that moves the plural_eval function to a separate file.


2001-09-22  Bruno Haible  <bruno@clisp.org>

	* intl/plural-eval.c: New file, extracted from dcigettext.c.
	* intl/plural-exp.h (PLURAL_EVAL): New declaration.
	* intl/dcigettext.c (plural_eval): Remove function, moved to
	intl/plural-eval.c.
	(plural_lookup): Call PLURAL_EVAL instead of plural_eval.
	* intl/Makefile (routines): Add plural-eval.

--- glibc-20011110/intl/plural-eval.c.bak	Tue Nov 20 01:09:29 2001
+++ glibc-20011110/intl/plural-eval.c	Tue Nov 20 01:07:59 2001
@@ -0,0 +1,103 @@
+/* Plural expression evaluation.
+   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "plural-exp.h"
+
+unsigned long int
+internal_function
+PLURAL_EVAL (pexp, n)
+     struct expression *pexp;
+     unsigned long int n;
+{
+  switch (pexp->nargs)
+    {
+    case 0:
+      switch (pexp->operation)
+	{
+	case var:
+	  return n;
+	case num:
+	  return pexp->val.num;
+	default:
+	  break;
+	}
+      /* NOTREACHED */
+      break;
+    case 1:
+      {
+	/* pexp->operation must be lnot.  */
+	unsigned long int arg = PLURAL_EVAL (pexp->val.args[0], n);
+	return ! arg;
+      }
+    case 2:
+      {
+	unsigned long int leftarg = PLURAL_EVAL (pexp->val.args[0], n);
+	if (pexp->operation == lor)
+	  return leftarg || PLURAL_EVAL (pexp->val.args[1], n);
+	else if (pexp->operation == land)
+	  return leftarg && PLURAL_EVAL (pexp->val.args[1], n);
+	else
+	  {
+	    unsigned long int rightarg = PLURAL_EVAL (pexp->val.args[1], n);
+
+	    switch (pexp->operation)
+	      {
+	      case mult:
+		return leftarg * rightarg;
+	      case divide:
+		return leftarg / rightarg;
+	      case module:
+		return leftarg % rightarg;
+	      case plus:
+		return leftarg + rightarg;
+	      case minus:
+		return leftarg - rightarg;
+	      case less_than:
+		return leftarg < rightarg;
+	      case greater_than:
+		return leftarg > rightarg;
+	      case less_or_equal:
+		return leftarg <= rightarg;
+	      case greater_or_equal:
+		return leftarg >= rightarg;
+	      case equal:
+		return leftarg == rightarg;
+	      case not_equal:
+		return leftarg != rightarg;
+	      default:
+		break;
+	      }
+	  }
+	/* NOTREACHED */
+	break;
+      }
+    case 3:
+      {
+	/* pexp->operation must be qmop.  */
+	unsigned long int boolarg = PLURAL_EVAL (pexp->val.args[0], n);
+	return PLURAL_EVAL (pexp->val.args[boolarg ? 1 : 2], n);
+      }
+    }
+  /* NOTREACHED */
+  return 0;
+}
--- glibc-20011110/intl/plural-exp.h.bak	Wed Nov 21 12:35:53 2001
+++ glibc-20011110/intl/plural-exp.h	Tue Nov 20 01:37:34 2001
@@ -94,16 +94,19 @@
 # define PLURAL_PARSE __gettextparse
 # define GERMANIC_PLURAL __gettext_germanic_plural
 # define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
+# define PLURAL_EVAL __gettext_plural_eval
 #elif defined (IN_LIBINTL)
 # define FREE_EXPRESSION gettext_free_exp__
 # define PLURAL_PARSE gettextparse__
 # define GERMANIC_PLURAL gettext_germanic_plural__
 # define EXTRACT_PLURAL_EXPRESSION gettext_extract_plural__
+# define PLURAL_EVAL gettext_plural_eval__
 #else
 # define FREE_EXPRESSION free_plural_expression
 # define PLURAL_PARSE parse_plural_expression
 # define GERMANIC_PLURAL germanic_plural
 # define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
+# define PLURAL_EVAL plural_eval
 #endif
 
 extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
@@ -113,6 +116,11 @@
 extern void EXTRACT_PLURAL_EXPRESSION PARAMS ((const char *nullentry,
 					       struct expression **pluralp,
 					       unsigned long int *npluralsp))
+     internal_function;
+
+/* Evaluate the plural expression and return an index value.  */
+extern unsigned long int PLURAL_EVAL PARAMS ((struct expression *pexp,
+					      unsigned long int n))
      internal_function;
 
 #endif /* _PLURAL_EXP_H */
--- glibc-20011110/intl/dcigettext.c.bak	Wed Nov 21 12:35:53 2001
+++ glibc-20011110/intl/dcigettext.c	Tue Nov 20 01:00:00 2001
@@ -266,9 +256,6 @@
 				    const char *translation,
 				    size_t translation_len))
      internal_function;
-static unsigned long int plural_eval PARAMS ((struct expression *pexp,
-					      unsigned long int n))
-     internal_function;
 static const char *category_to_name PARAMS ((int category)) internal_function;
 static const char *guess_category_value PARAMS ((int category,
 						 const char *categoryname))
@@ -935,7 +938,7 @@
   unsigned long int index;
   const char *p;
 
-  index = plural_eval (domaindata->plural, n);
+  index = PLURAL_EVAL (domaindata->plural, n);
   if (index >= domaindata->nplurals)
     /* This should never happen.  It means the plural expression and the
        given maximum value do not match.  */
@@ -963,87 +966,6 @@
 }
 
 
-/* Function to evaluate the plural expression and return an index value.  */
-static unsigned long int
-internal_function
-plural_eval (pexp, n)
-     struct expression *pexp;
-     unsigned long int n;
-{
-  switch (pexp->nargs)
-    {
-    case 0:
-      switch (pexp->operation)
-	{
-	case var:
-	  return n;
-	case num:
-	  return pexp->val.num;
-	default:
-	  break;
-	}
-      /* NOTREACHED */
-      break;
-    case 1:
-      {
-	/* pexp->operation must be lnot.  */
-	unsigned long int arg = plural_eval (pexp->val.args[0], n);
-	return ! arg;
-      }
-    case 2:
-      {
-	unsigned long int leftarg = plural_eval (pexp->val.args[0], n);
-	if (pexp->operation == lor)
-	  return leftarg || plural_eval (pexp->val.args[1], n);
-	else if (pexp->operation == land)
-	  return leftarg && plural_eval (pexp->val.args[1], n);
-	else
-	  {
-	    unsigned long int rightarg = plural_eval (pexp->val.args[1], n);
-
-	    switch (pexp->operation)
-	      {
-	      case mult:
-		return leftarg * rightarg;
-	      case divide:
-		return leftarg / rightarg;
-	      case module:
-		return leftarg % rightarg;
-	      case plus:
-		return leftarg + rightarg;
-	      case minus:
-		return leftarg - rightarg;
-	      case less_than:
-		return leftarg < rightarg;
-	      case greater_than:
-		return leftarg > rightarg;
-	      case less_or_equal:
-		return leftarg <= rightarg;
-	      case greater_or_equal:
-		return leftarg >= rightarg;
-	      case equal:
-		return leftarg == rightarg;
-	      case not_equal:
-		return leftarg != rightarg;
-	      default:
-		break;
-	      }
-	  }
-	/* NOTREACHED */
-	break;
-      }
-    case 3:
-      {
-	/* pexp->operation must be qmop.  */
-	unsigned long int boolarg = plural_eval (pexp->val.args[0], n);
-	return plural_eval (pexp->val.args[boolarg ? 1 : 2], n);
-      }
-    }
-  /* NOTREACHED */
-  return 0;
-}
-
-
 /* Return string representation of locale CATEGORY.  */
 static const char *
 internal_function
--- glibc-20011110/intl/Makefile.bak	Wed Nov 21 12:35:53 2001
+++ glibc-20011110/intl/Makefile	Thu Nov 22 01:08:13 2001
@@ -22,8 +22,8 @@
 headers = libintl.h
 routines = bindtextdom dcgettext dgettext gettext	\
 	   dcigettext dcngettext dngettext ngettext \
 	   finddomain loadmsgcat localealias textdomain	\
-	   l10nflist explodename plural plural-exp
+	   l10nflist explodename plural plural-exp plural-eval
 distribute = gettext.h gettextP.h hash-string.h loadinfo.h locale.alias \
 	     plural.y plural-exp.h po2test.sed tst-gettext.sh tst-translit.sh \
 	     translit.po tst-gettext2.sh tstlang1.po tstlang2.po tstcodeset.po\



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]