/xbmc/visualizations/Goom/goom2k4-0/gtk-gui-devel/intl/explodename.c

http://github.com/xbmc/xbmc · C · 188 lines · 125 code · 32 blank · 31 comment · 98 complexity · 930994e607ac485929753d7caddcb584 MD5 · raw file

  1. /* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
  2. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #ifdef HAVE_CONFIG_H
  15. # include <config.h>
  16. #endif
  17. #if defined STDC_HEADERS || defined _LIBC
  18. # include <stdlib.h>
  19. #endif
  20. #if defined HAVE_STRING_H || defined _LIBC
  21. # include <string.h>
  22. #else
  23. # include <strings.h>
  24. #endif
  25. #include <sys/types.h>
  26. #include "loadinfo.h"
  27. /* On some strange systems still no definition of NULL is found. Sigh! */
  28. #ifndef NULL
  29. # if defined __STDC__ && __STDC__
  30. # define NULL ((void *) 0)
  31. # else
  32. # define NULL 0
  33. # endif
  34. #endif
  35. /* @@ end of prolog @@ */
  36. int
  37. _nl_explode_name (name, language, modifier, territory, codeset,
  38. normalized_codeset, special, sponsor, revision)
  39. char *name;
  40. const char **language;
  41. const char **modifier;
  42. const char **territory;
  43. const char **codeset;
  44. const char **normalized_codeset;
  45. const char **special;
  46. const char **sponsor;
  47. const char **revision;
  48. {
  49. enum { undecided, xpg, cen } syntax;
  50. char *cp;
  51. int mask;
  52. *modifier = NULL;
  53. *territory = NULL;
  54. *codeset = NULL;
  55. *normalized_codeset = NULL;
  56. *special = NULL;
  57. *sponsor = NULL;
  58. *revision = NULL;
  59. /* Now we determine the single parts of the locale name. First
  60. look for the language. Termination symbols are `_' and `@' if
  61. we use XPG4 style, and `_', `+', and `,' if we use CEN syntax. */
  62. mask = 0;
  63. syntax = undecided;
  64. *language = cp = name;
  65. while (cp[0] != '\0' && cp[0] != '_' && cp[0] != '@'
  66. && cp[0] != '+' && cp[0] != ',')
  67. ++cp;
  68. if (*language == cp)
  69. /* This does not make sense: language has to be specified. Use
  70. this entry as it is without exploding. Perhaps it is an alias. */
  71. cp = strchr (*language, '\0');
  72. else if (cp[0] == '_')
  73. {
  74. /* Next is the territory. */
  75. cp[0] = '\0';
  76. *territory = ++cp;
  77. while (cp[0] != '\0' && cp[0] != '.' && cp[0] != '@'
  78. && cp[0] != '+' && cp[0] != ',' && cp[0] != '_')
  79. ++cp;
  80. mask |= TERRITORY;
  81. if (cp[0] == '.')
  82. {
  83. /* Next is the codeset. */
  84. syntax = xpg;
  85. cp[0] = '\0';
  86. *codeset = ++cp;
  87. while (cp[0] != '\0' && cp[0] != '@')
  88. ++cp;
  89. mask |= XPG_CODESET;
  90. if (*codeset != cp && (*codeset)[0] != '\0')
  91. {
  92. *normalized_codeset = _nl_normalize_codeset (*codeset,
  93. cp - *codeset);
  94. if (strcmp (*codeset, *normalized_codeset) == 0)
  95. free ((char *) *normalized_codeset);
  96. else
  97. mask |= XPG_NORM_CODESET;
  98. }
  99. }
  100. }
  101. if (cp[0] == '@' || (syntax != xpg && cp[0] == '+'))
  102. {
  103. /* Next is the modifier. */
  104. syntax = cp[0] == '@' ? xpg : cen;
  105. cp[0] = '\0';
  106. *modifier = ++cp;
  107. while (syntax == cen && cp[0] != '\0' && cp[0] != '+'
  108. && cp[0] != ',' && cp[0] != '_')
  109. ++cp;
  110. mask |= XPG_MODIFIER | CEN_AUDIENCE;
  111. }
  112. if (syntax != xpg && (cp[0] == '+' || cp[0] == ',' || cp[0] == '_'))
  113. {
  114. syntax = cen;
  115. if (cp[0] == '+')
  116. {
  117. /* Next is special application (CEN syntax). */
  118. cp[0] = '\0';
  119. *special = ++cp;
  120. while (cp[0] != '\0' && cp[0] != ',' && cp[0] != '_')
  121. ++cp;
  122. mask |= CEN_SPECIAL;
  123. }
  124. if (cp[0] == ',')
  125. {
  126. /* Next is sponsor (CEN syntax). */
  127. cp[0] = '\0';
  128. *sponsor = ++cp;
  129. while (cp[0] != '\0' && cp[0] != '_')
  130. ++cp;
  131. mask |= CEN_SPONSOR;
  132. }
  133. if (cp[0] == '_')
  134. {
  135. /* Next is revision (CEN syntax). */
  136. cp[0] = '\0';
  137. *revision = ++cp;
  138. mask |= CEN_REVISION;
  139. }
  140. }
  141. /* For CEN syntax values it might be important to have the
  142. separator character in the file name, not for XPG syntax. */
  143. if (syntax == xpg)
  144. {
  145. if (*territory != NULL && (*territory)[0] == '\0')
  146. mask &= ~TERRITORY;
  147. if (*codeset != NULL && (*codeset)[0] == '\0')
  148. mask &= ~XPG_CODESET;
  149. if (*modifier != NULL && (*modifier)[0] == '\0')
  150. mask &= ~XPG_MODIFIER;
  151. }
  152. return mask;
  153. }