You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

explodename.c 4.4KB

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