Back to index

courier  0.68.2
Classes | Defines | Enumerations | Functions
plural-exp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  expression
struct  parse_args
union  expression.val

Defines

#define internal_function
#define attribute_hidden
#define FREE_EXPRESSION   free_plural_expression
#define PLURAL_PARSE   parse_plural_expression
#define GERMANIC_PLURAL   germanic_plural
#define EXTRACT_PLURAL_EXPRESSION   extract_plural_expression

Enumerations

enum  expression_operator {
  var, num, lnot, mult,
  divide, module, plus, minus,
  less_than, greater_than, less_or_equal, greater_or_equal,
  equal, not_equal, land, lor,
  qmop
}

Functions

void FREE_EXPRESSION (struct expression *exp) internal_function
int PLURAL_PARSE (void *arg)
void EXTRACT_PLURAL_EXPRESSION (const char *nullentry, const struct expression **pluralp, unsigned long int *npluralsp) internal_function
unsigned long int plural_eval (const struct expression *pexp, unsigned long int n)

Class Documentation

struct expression

Definition at line 63 of file plural-exp.h.

Class Members
int nargs
enum expression_operator union
expression
val
struct parse_args

Definition at line 76 of file plural-exp.h.

Collaboration diagram for parse_args:
Class Members
const char * cp
struct expression * res
union expression.val

Definition at line 67 of file plural-exp.h.

Class Members
struct expression * args
unsigned long int num

Define Documentation

Definition at line 28 of file plural-exp.h.

#define EXTRACT_PLURAL_EXPRESSION   extract_plural_expression

Definition at line 107 of file plural-exp.h.

#define FREE_EXPRESSION   free_plural_expression

Definition at line 104 of file plural-exp.h.

#define GERMANIC_PLURAL   germanic_plural

Definition at line 106 of file plural-exp.h.

Definition at line 24 of file plural-exp.h.

#define PLURAL_PARSE   parse_plural_expression

Definition at line 105 of file plural-exp.h.


Enumeration Type Documentation

Enumerator:
var 
num 
lnot 
mult 
divide 
module 
plus 
minus 
less_than 
greater_than 
less_or_equal 
greater_or_equal 
equal 
not_equal 
land 
lor 
qmop 

Definition at line 36 of file plural-exp.h.

{
  /* Without arguments:  */
  var,                      /* The variable "n".  */
  num,                      /* Decimal number.  */
  /* Unary operators:  */
  lnot,                            /* Logical NOT.  */
  /* Binary operators:  */
  mult,                            /* Multiplication.  */
  divide,                   /* Division.  */
  module,                   /* Modulo operation.  */
  plus,                            /* Addition.  */
  minus,                    /* Subtraction.  */
  less_than,                /* Comparison.  */
  greater_than,                    /* Comparison.  */
  less_or_equal,            /* Comparison.  */
  greater_or_equal,         /* Comparison.  */
  equal,                    /* Comparison for equality.  */
  not_equal,                /* Comparison for inequality.  */
  land,                            /* Logical AND.  */
  lor,                      /* Logical OR.  */
  /* Ternary operators:  */
  qmop                      /* Question mark operator.  */
};

Function Documentation

void EXTRACT_PLURAL_EXPRESSION ( const char *  nullentry,
const struct expression **  pluralp,
unsigned long int *  npluralsp 
)

Definition at line 99 of file plural-exp.c.

{
  if (nullentry != NULL)
    {
      const char *plural;
      const char *nplurals;

      plural = strstr (nullentry, "plural=");
      nplurals = strstr (nullentry, "nplurals=");
      if (plural == NULL || nplurals == NULL)
       goto no_plural;
      else
       {
         char *endp;
         unsigned long int n;
         struct parse_args args;

         /* First get the number.  */
         nplurals += 9;
         while (*nplurals != '\0' && isspace ((unsigned char) *nplurals))
           ++nplurals;
         if (!(*nplurals >= '0' && *nplurals <= '9'))
           goto no_plural;
#if defined HAVE_STRTOUL || defined _LIBC
         n = strtoul (nplurals, &endp, 10);
#else
         for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++)
           n = n * 10 + (*endp - '0');
#endif
         if (nplurals == endp)
           goto no_plural;
         *npluralsp = n;

         /* Due to the restrictions bison imposes onto the interface of the
            scanner function we have to put the input string and the result
            passed up from the parser into the same structure which address
            is passed down to the parser.  */
         plural += 7;
         args.cp = plural;
         if (PLURAL_PARSE (&args) != 0)
           goto no_plural;
         *pluralp = args.res;
       }
    }
  else
    {
      /* By default we are using the Germanic form: singular form only
         for `one', the plural form otherwise.  Yes, this is also what
         English is using since English is a Germanic language.  */
    no_plural:
      INIT_GERMANIC_PLURAL ();
      *pluralp = &GERMANIC_PLURAL;
      *npluralsp = 2;
    }
}

Here is the call graph for this function:

void FREE_EXPRESSION ( struct expression exp)

Definition at line 1788 of file plural.c.

{
  if (exp == NULL)
    return;

  /* Handle the recursive case.  */
  switch (exp->nargs)
    {
    case 3:
      FREE_EXPRESSION (exp->val.args[2]);
      /* FALLTHROUGH */
    case 2:
      FREE_EXPRESSION (exp->val.args[1]);
      /* FALLTHROUGH */
    case 1:
      FREE_EXPRESSION (exp->val.args[0]);
      /* FALLTHROUGH */
    default:
      break;
    }

  free (exp);
}
unsigned long int plural_eval ( const struct expression pexp,
unsigned long int  n 
)

Definition at line 27 of file eval-plural.h.

{
  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:
#if !INTDIV0_RAISES_SIGFPE
              if (rightarg == 0)
                raise (SIGFPE);
#endif
              return leftarg / rightarg;
             case module:
#if !INTDIV0_RAISES_SIGFPE
              if (rightarg == 0)
                raise (SIGFPE);
#endif
              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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PLURAL_PARSE ( void *  arg)

Here is the caller graph for this function: