| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifdef HAVE_CONFIG_H |
|---|
| 21 | # include <config.h> |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #include <ctype.h> |
|---|
| 25 | #include <stdlib.h> |
|---|
| 26 | #include <string.h> |
|---|
| 27 | |
|---|
| 28 | #include "plural-exp.h" |
|---|
| 29 | |
|---|
| 30 | #if (defined __GNUC__ && !defined __APPLE_CC__) \ |
|---|
| 31 | || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | static const struct expression plvar = |
|---|
| 36 | { |
|---|
| 37 | .nargs = 0, |
|---|
| 38 | .operation = var, |
|---|
| 39 | }; |
|---|
| 40 | static const struct expression plone = |
|---|
| 41 | { |
|---|
| 42 | .nargs = 0, |
|---|
| 43 | .operation = num, |
|---|
| 44 | .val = |
|---|
| 45 | { |
|---|
| 46 | .num = 1 |
|---|
| 47 | } |
|---|
| 48 | }; |
|---|
| 49 | struct expression GERMANIC_PLURAL = |
|---|
| 50 | { |
|---|
| 51 | .nargs = 2, |
|---|
| 52 | .operation = not_equal, |
|---|
| 53 | .val = |
|---|
| 54 | { |
|---|
| 55 | .args = |
|---|
| 56 | { |
|---|
| 57 | [0] = (struct expression *) &plvar, |
|---|
| 58 | [1] = (struct expression *) &plone |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | # define INIT_GERMANIC_PLURAL() |
|---|
| 64 | |
|---|
| 65 | #else |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | static struct expression plvar; |
|---|
| 71 | static struct expression plone; |
|---|
| 72 | struct expression GERMANIC_PLURAL; |
|---|
| 73 | |
|---|
| 74 | static void |
|---|
| 75 | init_germanic_plural () |
|---|
| 76 | { |
|---|
| 77 | if (plone.val.num == 0) |
|---|
| 78 | { |
|---|
| 79 | plvar.nargs = 0; |
|---|
| 80 | plvar.operation = var; |
|---|
| 81 | |
|---|
| 82 | plone.nargs = 0; |
|---|
| 83 | plone.operation = num; |
|---|
| 84 | plone.val.num = 1; |
|---|
| 85 | |
|---|
| 86 | GERMANIC_PLURAL.nargs = 2; |
|---|
| 87 | GERMANIC_PLURAL.operation = not_equal; |
|---|
| 88 | GERMANIC_PLURAL.val.args[0] = &plvar; |
|---|
| 89 | GERMANIC_PLURAL.val.args[1] = &plone; |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | # define INIT_GERMANIC_PLURAL() init_germanic_plural () |
|---|
| 94 | |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | void |
|---|
| 98 | internal_function |
|---|
| 99 | EXTRACT_PLURAL_EXPRESSION (const char *nullentry, struct expression **pluralp, |
|---|
| 100 | unsigned long int *npluralsp) |
|---|
| 101 | { |
|---|
| 102 | if (nullentry != NULL) |
|---|
| 103 | { |
|---|
| 104 | const char *plural; |
|---|
| 105 | const char *nplurals; |
|---|
| 106 | |
|---|
| 107 | plural = strstr (nullentry, "plural="); |
|---|
| 108 | nplurals = strstr (nullentry, "nplurals="); |
|---|
| 109 | if (plural == NULL || nplurals == NULL) |
|---|
| 110 | goto no_plural; |
|---|
| 111 | else |
|---|
| 112 | { |
|---|
| 113 | char *endp; |
|---|
| 114 | unsigned long int n; |
|---|
| 115 | struct parse_args args; |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | nplurals += 9; |
|---|
| 119 | while (*nplurals != '\0' && isspace ((unsigned char) *nplurals)) |
|---|
| 120 | ++nplurals; |
|---|
| 121 | if (!(*nplurals >= '0' && *nplurals <= '9')) |
|---|
| 122 | goto no_plural; |
|---|
| 123 | #if defined HAVE_STRTOUL || defined _LIBC |
|---|
| 124 | n = strtoul (nplurals, &endp, 10); |
|---|
| 125 | #else |
|---|
| 126 | for (endp = nplurals, n = 0; *endp >= '0' && *endp <= '9'; endp++) |
|---|
| 127 | n = n * 10 + (*endp - '0'); |
|---|
| 128 | #endif |
|---|
| 129 | if (nplurals == endp) |
|---|
| 130 | goto no_plural; |
|---|
| 131 | *npluralsp = n; |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | plural += 7; |
|---|
| 138 | args.cp = plural; |
|---|
| 139 | if (PLURAL_PARSE (&args) != 0) |
|---|
| 140 | goto no_plural; |
|---|
| 141 | *pluralp = args.res; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | else |
|---|
| 145 | { |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | no_plural: |
|---|
| 150 | INIT_GERMANIC_PLURAL (); |
|---|
| 151 | *pluralp = &GERMANIC_PLURAL; |
|---|
| 152 | *npluralsp = 2; |
|---|
| 153 | } |
|---|
| 154 | } |
|---|