- invoke fix-info-dir via /sbin/postshell where possible to avoid extra /bin/sh dep
[packages/conflib.git] / conflib-locale.patch
1 diff -ur conflib-0.4.5-/src/cl_assign.c conflib-0.4.5/src/cl_assign.c
2 --- conflib-0.4.5-/src/cl_assign.c      Fri Oct  9 19:03:57 1998
3 +++ conflib-0.4.5/src/cl_assign.c       Sat Oct 20 21:45:42 2001
4 @@ -93,6 +93,45 @@
5                         "Value %s doesn't match %s %s.",
6                         val,what,var->rangeexp);
7  }
8 +
9 +static int
10 +cl_in_current_locale(const char *varname)
11 +{
12 +       static const char *locale = NULL;
13 +       static int locale_len = 0;
14 +       static int locale_first_len = 0;
15 +       char *p;
16 +
17 +       if (locale == NULL) {
18 +               const char *lp;
19 +               
20 +               if ((locale = getenv("LC_MESSAGES")) == NULL &&
21 +                   (locale = getenv("LC_ALL")) == NULL &&
22 +                   (locale = getenv("LANG")) == NULL)
23 +                       locale = "C";
24 +               locale_len = strlen(locale);
25 +               for (lp = locale; *lp; lp++, locale_first_len++)
26 +                       if (*lp == '_')
27 +                               break;
28 +       }
29 +
30 +       p = strchr(varname, '(');
31 +       if (p == NULL)
32 +               return 1;       /* yes */
33 +       p++;
34 +       if (strcmp(p, "POSIX)") == 0 ||
35 +           strcmp(p, "C)") == 0)
36 +               return 1;       /* yes */
37 +       if (strncmp(p, locale, locale_first_len) == 0 &&
38 +           p[locale_first_len] == ')' &&
39 +           p[locale_first_len+1] == 0)
40 +               return 2;       /* yes, better */
41 +       if (strncmp(p, locale, locale_len) == 0 &&
42 +           p[locale_len] == ')' &&
43 +           p[locale_len+1] == 0)
44 +               return 3;       /* yes, even better */
45 +       return 0;
46 +}
47         
48  int 
49  cl_assign(cl_file_t *conf, cl_var_t *KonfTab,
50 @@ -102,6 +141,7 @@
51         const cl_enum_t *enump;
52         int override=0;
53         int append=0;
54 +       char *nameptr = NULL;
55         if (0==strncmp(varname,"override ",9)) {
56                 varname+=9;
57                 override=1;
58 @@ -111,6 +151,15 @@
59                 append=1;
60         }
61  
62 +       if ((conf->mode&' ') == 0 && strchr(varname, ')')) {
63 +               if (cl_in_current_locale(varname) == 0)
64 +                       return 0;
65 +               nameptr = strdup(varname);
66 +               *strchr(nameptr, '(') = 0;
67 +               varname = nameptr;
68 +               override = 1;
69 +       }
70 +       
71         for(Vp=KonfTab;Vp->varname;Vp++)
72         {
73                 char c1=tolower(*varname);
74 @@ -125,7 +174,7 @@
75                         {
76                                 Vp=cl_unalias(conf,KonfTab,Vp);
77                                 if (!Vp)
78 -                                       return 1;
79 +                                       goto return_1;
80                         }
81                         if (Vp->flags & CL_WARNING) {
82                                 cl_warning(CL_WARN(conf,Vp),"variable %s should not be used",
83 @@ -139,7 +188,7 @@
84                                         if (cl_fnmatch(Vp->rangeexp,value)!=0)
85                                         {
86                                                 cl_as_dontmatch(conf,Vp,"wildcard", value);
87 -                                               return 0;
88 +                                               goto return_0;
89                                         }
90                                 }
91                                 else 
92 @@ -151,12 +200,12 @@
93                                                 cl_warning(CL_ERR(conf,Vp),
94                                                         "cannot compile regular expression %s",
95                                                         Vp->rangeexp);
96 -                                               return -1;
97 +                                               goto return_m1;
98                                         }
99                                         if (regexec(&exp,value,0,NULL,0)!=0)
100                                         {
101                                                 cl_as_dontmatch(conf,Vp,"regular expression", value);
102 -                                               return 0;
103 +                                               goto return_0;
104                                         }
105  #else
106                                         /* ### was hier zur├╝ckliefern? */
107 @@ -170,7 +219,7 @@
108                                 {
109                                         cl_warning(CL_ERR(conf,Vp),
110                                                 "CL_ENUM nullpointer dereference!");
111 -                                       return 1;
112 +                                       goto return_1;
113                                 }
114                                 Vp->flags |= CL_MAY_SAVE;
115                                 for (enump=(const cl_enum_t *) Vp->secdata; enump->magic; enump++)
116 @@ -178,13 +227,13 @@
117                                         if (!strcasecmp(enump->magic,value))
118                                         {
119                                                 *(long*)Vp->adr = enump->value;
120 -                                               return 0;
121 +                                               goto return_0;
122                                         }
123                                 }
124                                 cl_warning(CL_WARN(conf,Vp),
125                                         "unknown value %s for enumeration",value);
126                                 *(long*)Vp->adr = (long) 0;
127 -                               return 0; /* ### is this good? */
128 +                               goto return_0; /* ### is this good? */
129                                 break;
130                         case CL_BITFIELD:
131                                 {
132 @@ -192,7 +241,7 @@
133                                         if (!Vp->secdata) {
134                                                 cl_warning(CL_ERR(conf,Vp),
135                                                         "CL_BITFIELD nullpointer dereference!");
136 -                                               return 1;
137 +                                               goto return_1;
138                                         }
139                                         Vp->flags |= CL_MAY_SAVE;
140                                         if (override)
141 @@ -234,7 +283,7 @@
142                                                 }
143                                                 p=q;
144                                         }
145 -                                       return 0;
146 +                                       goto return_0;
147                                         break;
148                                 }
149                         case CL_STRING: /* Stringvariable */
150 @@ -243,7 +292,7 @@
151                                         size_t l2=strlen(value);
152                                         char *s=malloc(l1+l2+2);
153                                         if (!s)
154 -                                               return -1;
155 +                                               goto return_m1;
156                                         Vp->flags |= CL_MAY_SAVE;
157                                         memcpy(s,*(char **)Vp->adr,l1);
158                                         s[l1]=' ';
159 @@ -252,14 +301,14 @@
160                                                 free (*(char **)Vp->adr);
161                                         *(char **)Vp->adr=s;
162                                         Vp->flags|=CL_MALLOCED;
163 -                                       return 0;
164 +                                       goto return_0;
165                                 }
166                                 if (0==cl_dup_to(Vp,value))
167                                 {
168                                         Vp->flags |= CL_MAY_SAVE;
169 -                                       return 0;
170 +                                       goto return_0;
171                                 }
172 -                               return -1;
173 +                               goto return_m1;
174                         case CL_DIRNAME:        /* Stringvariable */
175                                 {
176                                         size_t l;
177 @@ -267,7 +316,7 @@
178                                         l=strlen(value);
179                                         buf=malloc(l+2);
180                                         if (!buf)
181 -                                               return -1;
182 +                                               goto return_m1;
183                                         memcpy(buf,value,l+1);
184                                         if (buf[l-1]!='/') {
185                                                 buf[l]='/';
186 @@ -278,7 +327,7 @@
187                                                 size_t l1=strlen(*(char **)Vp->adr);
188                                                 char *s=malloc(l1+l+1);
189                                                 if (!s)
190 -                                                       return -1;
191 +                                                       goto return_m1;
192                                                 Vp->flags |= CL_MAY_SAVE;
193                                                 memcpy(s,*(char **)Vp->adr,l1);
194                                                 memcpy(s+l1,buf,l+1);
195 @@ -287,23 +336,23 @@
196                                                 *(char **)Vp->adr=s;
197                                                 free(buf);
198                                                 Vp->flags|=CL_MALLOCED;
199 -                                               return 0;
200 +                                               goto return_0;
201                                         }
202                                         if (0==cl_dup_to(Vp,buf))
203                                         {
204                                                 Vp->flags |= CL_MAY_SAVE;
205                                                 free(buf);
206 -                                               return 0;
207 +                                               goto return_0;
208                                         }
209                                         free(buf);
210                                 }
211 -                               return -1;
212 +                               goto return_m1;
213                         case CL_CHAR:
214                                 if (value[1]!='\0')
215                                         cl_warning(CL_WARN(conf,Vp),"char desired, got string %s", value);
216                                 Vp->flags |= CL_MAY_SAVE;
217                                 *(char *)Vp->adr = *value;
218 -                               return 0;
219 +                               goto return_0;
220                         case CL_NUM:
221                                 Vp->flags |= CL_MAY_SAVE;
222                                 {
223 @@ -314,7 +363,7 @@
224                                                 *(long*)Vp->adr = strtol(value,NULL,0);
225                                         }
226                                 }
227 -                               return 0;
228 +                               goto return_0;
229                         case CL_NUMSHORT:
230                                 Vp->flags |= CL_MAY_SAVE;
231                                 {
232 @@ -334,11 +383,11 @@
233                                         }
234                                         *(short*)Vp->adr = (int) lo;
235                                 }
236 -                               return 0;
237 +                               goto return_0;
238                         case CL_BOOLEAN:
239                                 Vp->flags |= CL_MAY_SAVE;
240                                 *(int *)Vp->adr=cl_convert2bool(value);
241 -                               return 0;
242 +                               goto return_0;
243                         case CL_ARRAY:  /* Stringarray */
244                                 {
245                                         register int Cnt;
246 @@ -354,10 +403,10 @@
247                                         else
248                                         {
249                                                 cl_warning(CL_WARN(conf,Vp),"Array %s is full",Vp->varname);
250 -                                               return -1;
251 +                                               goto return_m1;
252                                         }
253                                         Vp->flags |= CL_MAY_SAVE;
254 -                                       return 0;
255 +                                       goto return_0;
256                                 }
257                                 break;
258                         case CL_ALIAS:
259 @@ -421,11 +470,11 @@
260                                                 Vp->flags|=CL_MALLOCED;
261                                         } /* while sep */
262                                         Vp->flags |= CL_MAY_SAVE;
263 -                                       return 0;
264 +                                       goto return_0;
265                                 }
266                                 break;
267                         } /* switch */
268 -                       return 0;
269 +                       goto return_0;
270                 }
271         } /* for */
272  
273 @@ -445,17 +494,17 @@
274                                 {
275                                         cl_warning(CL_ERR(conf,Vp),"out of memory");
276                                         dieser->inhalt=old;
277 -                                       return -1;
278 +                                       goto return_m1;
279                                 }
280                                 free(old);
281 -                               return 0;
282 +                               goto return_0;
283                         }
284                 }
285                 dieser=malloc(sizeof(cl_ulist_t));
286                 if (!dieser)
287                 {
288                         cl_warning(CL_ERR(conf,Vp),"out of memory");
289 -                       return 0;
290 +                       goto return_0;
291                 }
292                 dieser->varname=strdup(varname);
293                 dieser->inhalt=strdup(value);
294 @@ -465,7 +514,7 @@
295                         free(dieser->inhalt);
296                         free(dieser);
297                         cl_warning(CL_ERR(conf,Vp),"out of memory");
298 -                       return -1;
299 +                       goto return_m1;
300                 }
301                 dieser->next=NULL;
302                 if (!last)
303 @@ -473,12 +522,22 @@
304                 else
305                         last->next=dieser;
306                         
307 -               return 0;
308 +               goto return_0;
309         }
310         
311         if (conf->report_unknown)
312                 cl_warning(CL_WARN(conf,Vp),
313                         "unknown variable '%s'",varname);
314 +return_0:
315 +       free(nameptr);
316         return 0;
317 +       
318 +return_1:
319 +       free(nameptr);
320 +       return 1;
321 +
322 +return_m1:
323 +       free(nameptr);
324 +       return -1;
325  }
326  
327 diff -ur conflib-0.4.5-/src/cl_openconf.c conflib-0.4.5/src/cl_openconf.c
328 --- conflib-0.4.5-/src/cl_openconf.c    Fri Oct  9 19:03:57 1998
329 +++ conflib-0.4.5/src/cl_openconf.c     Sat Oct 20 21:16:56 2001
330 @@ -94,6 +94,13 @@
331  cl_openconf (const char *fname, const char *mode)
332  {
333         cl_file_t *c;
334 +       int localized = 0;
335 +       
336 +       if (*mode == 'l') {
337 +               localized++;
338 +               mode++;
339 +       }
340 +       
341         if (*mode != 'r' && *mode != 'w') {
342                 errno=EINVAL;
343                 return NULL;
344 @@ -152,6 +159,9 @@
345                 errno=ENOMEM;
346                 return NULL;
347         }
348 +
349 +       if (localized)
350 +               c->mode &= ~' ';
351  
352         return c;
353  }
354 diff -ur conflib-0.4.5-/src/cl_putstanza.c conflib-0.4.5/src/cl_putstanza.c
355 --- conflib-0.4.5-/src/cl_putstanza.c   Fri Oct  9 19:03:57 1998
356 +++ conflib-0.4.5/src/cl_putstanza.c    Sat Oct 20 21:16:24 2001
357 @@ -166,7 +166,7 @@
358         char indent[256]="\t"; /* default to use if we don't read any line */
359         char *backupfname;
360  
361 -       if (conf->mode!='w')
362 +       if ((conf->mode|' ')!='w')
363         {
364                 cl_warning(CL_ERR(conf,NULL),
365                         "file is readonly");
This page took 0.102108 seconds and 3 git commands to generate.