1 /* Fake setlocale - platform independent, for testing purposes.
2 Copyright (C) 2001-2002 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 /* Return string representation of locale CATEGORY. */
28 category_to_name (int category
)
36 retval
= "LC_COLLATE";
46 retval
= "LC_MONETARY";
51 retval
= "LC_NUMERIC";
61 retval
= "LC_MESSAGES";
66 retval
= "LC_RESPONSE";
71 /* This might not make sense but is perhaps better than any other
77 /* If you have a better idea for a default value let me know. */
84 /* An implementation of setlocale that always succeeds, but doesn't
85 actually change the behaviour of locale dependent functions.
86 Assumes setenv()/putenv() is not called. */
88 setlocale (int category
, SETLOCALE_CONST
char *locale
)
90 static char C_string
[] = "C";
91 static char *current_locale
= C_string
;
98 static struct list
*facets
= NULL
;
106 copy
= (char *) malloc (strlen (locale
) + 1);
107 strcpy (copy
, locale
);
109 if (category
== LC_ALL
)
111 while ((facetp
= facets
) != NULL
)
113 facets
= facetp
->next
;
114 free (facetp
->current_locale
);
117 if (current_locale
!= C_string
)
118 free (current_locale
);
119 current_locale
= copy
;
123 for (facetp
= facets
; facetp
!= NULL
; facetp
= facetp
->next
)
124 if (category
== facetp
->category
)
126 free (facetp
->current_locale
);
127 facetp
->current_locale
= copy
;
132 facetp
= (struct list
*) malloc (sizeof (struct list
));
133 facetp
->category
= category
;
134 facetp
->current_locale
= copy
;
135 facetp
->next
= facets
;
141 retval
= current_locale
;
142 for (facetp
= facets
; facetp
!= NULL
; facetp
= facetp
->next
)
143 if (category
== facetp
->category
)
145 retval
= facetp
->current_locale
;
149 if (retval
[0] == '\0')
151 retval
= getenv ("LC_ALL");
152 if (retval
== NULL
|| retval
[0] == '\0')
154 retval
= getenv (category_to_name (category
));
155 if (retval
== NULL
|| retval
[0] == '\0')
157 retval
= getenv ("LANG");
158 if (retval
== NULL
|| retval
[0] == '\0')