Mail Archives: djgpp-workers/2005/01/12/02:46:43
On Fri, 07 Jan 2005 17:09:21 -0700, Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca> wrote:
>On Sat, 08 Jan 2005 00:39:28 +0100 (CET), ams AT ludd DOT ltu DOT se wrote:
>
>>According to Brian Inglis:
>>> Appended the changes to setlocal and its version of strftime which will
>>> then be identical to the updated version of libc strftime which I changed.
>>> As these are not under CVS control, I generated diffs between the DJGPP
>>> contrib/liblocal.02 directory and my development directory then edited
>>> the new file path to match the old file path, and hope this works okay.
>>
>>Yes. And I think I've been over those without finding anything. Note:
>>I want the patch to src/libc/ansi/locale/setlocal.txh. Given that
>>neither you or me can find one, perhaps there isn't one. What do I
>>know? Perhaps a completely rewrite of setlocale() won't need and
>>documentation update? (I surely did think it would. Suprise!)
>
>Alexander Aganichev includes an updated setlocal.txh in his distribution
>under: contrib/liblocal.02/src/ansi/locale/setlocal.txh.
>I'll append a diff against cvs/djgpp/src/libc/ansi/locale/setlocal.txh.
>
>>> >The changes to strftime.c and friends are dependand of the setlocale
>>> >patch, right?
>>>
>>> AIUI the only interface is the __dj_date_format and __dj_time_format
>>> global variables which are defaulted in strftime but can be set by
>>> calling setlocale().
>>>
>>> Some of the time test programs call setlocale() and change the TZ
>>> env var to check out handling these variations.
>>
>>Ok. So you mean I should be able to commit the strftime.c and friends
>>changes without any bad side effects, except the test programs might
>>not give the right answers until setlocale() is updated?
>
>Those tests that change the timezone or locale will not be correct
>if their respective packages are not installed.
>
>>> >I want to apply your setlocal patch because my cvs copy has so many
>>> >changes that I'm having problems knowing what is what. But to do that
>>> >I want to have the documentation up-to-date too.
>>> >
>>> >Are you planning to recode setlocal.c so it uses other functions
>>> >instead of stpcpy() and itoa()? If you are, it's counterproductive to
>>> >add those as stubs as they'll disappear again rather quickly; or not
>>> >which can be the real problem.
>>>
>>> On Thu, 30 Dec 2004 09:24:08 +0300 (MSK), in Re: setlocale patch,
>>> Alexander Aganichev said he would review my fixes and incorporate
>>> them, and deal with those other issues.
>>>
>>> If the updated version of strftime is incorporated into libc,
>>> then he can eliminate the version he provided with liblocal.02,
>>> which the appended patch makes identical.
>>
>>Yes. But either I'm missing something or you didn't answer my question.
>>Your fixes didn't affect the status regarding stpcpy() and itoa()
>>because I used your (what I think is more recent) corrected source.
>>
>>As I see it, the version from you is more up-to-date than what we got
>>from Alexander Aganichev (because your's is newer). And that one pulls
>>in the non-ansi functions stpcpy() and itoa().
>
>They don't appear in my patch, so they must be in the original sources.
>
>>> >That change itself is in no great hurry. Actually I'd prefer if that
>>> >change came later as I had to make some minor adjustment to the code I
>>> >got from you to make it compile and I really want to commit that new
>>> >setlocal.c after which you can submit a small patch.
>>>
>>> If he doesn't have time, I can deal with them right now.
>>
>>Deal away. I've not been in contact with Alexander Aganichev
>>specifically, as I'm now with you (because it's you that is most
>>active and I chose to email you). If you think I really should talk
>>directly with Alexander Aganichev I could do so.
>>
>>However as I stated (or tried to anyway), I'd prefer to commit what I
>>got with regards to setlocal.c and what I suspect is wandering the net
>>with regards to setlocal.txh (which I can't find), so I can get a
>>little more sane cvs tree. And then we take care of stpcpy() and
>>itoa(). _If_ we are aiming to take care of stpcpy() and itoa() at
>>all.
>
>I'll do that, and if Alexander Aganichev wants to incorporate
>that into a new release, or handle it better, great.
>
>>> I'll pull my patch summaries and edit those into new patches to wc204.
>>> The setlocale() patch contains only minor bug fixes for resetting
>>> the locale and returning the correct name.
contrib/liblocal.02/src/ansi/locale/setlocal.c additional changes
...
replace itoa() with sprintf() and keep string nul terminated;
replace stpcpy() with strcpy() and ptr adjustments;
change variable j from int to unsigned to avoid warnings
and move to inner scope;
change size calculations to use objects instead of types
Thanks. Take care, Brian Inglis
diff -Bbwiput contrib/liblocal.02/src/ansi/locale/setlocal.c contrib/liblocal.02/src/ansi/locale/setlocal.c
--- contrib/liblocal.02/src/ansi/locale/setlocal.c 2002-07-17 02:16:36.000000000 -0600
+++ contrib/liblocal.02/src/ansi/locale/setlocal.c 2005-01-12 00:03:14.000000000 -0700
@@ -10,6 +10,7 @@
#include <locale.h>
#include <ctype.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <dpmi.h>
#ifdef TEST
@@ -434,7 +435,7 @@ char *
setlocale(int category, const char *locale)
{
int honored = 1;
- int i, j;
+ int i;
if (locale != NULL)
{
@@ -465,15 +466,17 @@ setlocale(int category, const char *loca
if (locale[0] == '\0')
{
const char *env;
- if ((env = getenv ("LANG")) != NULL)
+ if ((env = getenv (cat[i].env)) != NULL)
{
locale = env;
}
- if ((env = getenv (cat[i].env)) != NULL)
+ else
+ if ((env = getenv ("LC_ALL")) != NULL)
{
locale = env;
}
- if ((env = getenv ("LC_ALL")) != NULL)
+ else
+ if ((env = getenv ("LANG")) != NULL)
{
locale = env;
}
@@ -481,11 +484,15 @@ setlocale(int category, const char *loca
if ((stricmp(locale, "C") == 0) || (stricmp(locale, "POSIX") == 0))
{
if (cat[i].reset() == 0)
+ {
honored = 0;
+ continue;
+ }
}
else
{
int CID, CCP;
+ unsigned j;
/* Allocate DOS memory */
if (segment == -1)
@@ -507,7 +514,7 @@ setlocale(int category, const char *loca
if (p == NULL)
p = locale + strlen(locale);
len = p - locale;
- for (j = 0; j < sizeof(loc2id) / sizeof(struct _loc2id); j++)
+ for (j = 0; j < sizeof(loc2id) / sizeof(*loc2id); j++)
if (!strncmp(locale, loc2id[j].loc,
len >= loc2id[j].len ? len : loc2id[j].len))
{
@@ -541,16 +548,16 @@ setlocale(int category, const char *loca
if (*locale == '\0') {
CID = _farpeekw(selector, 3);
CCP = _farpeekw(selector, 5);
- locale = buf;
strcpy(buf, "??_??.");
- for (j = 0; j < sizeof(loc2id) / sizeof(struct _loc2id); j++)
+ for (j = 0; j < sizeof(loc2id) / sizeof(*loc2id); j++)
if (loc2id[j].id == CID)
{
strcpy(buf, loc2id[j].loc);
- buf[loc2id[j].len] = '.';
+ strcpy(buf + loc2id[j].len, ".");
break;
}
- itoa(CCP, &buf[strlen(buf)], 10);
+ sprintf(buf + strlen(buf), "%u", CCP);
+ locale = buf;
}
/* regs.x.bx, regs.x.dx, regs.x.es/di are preserved by DOS */
@@ -559,12 +566,12 @@ setlocale(int category, const char *loca
honored = 0;
continue;
}
+ }
strncpy(lc_current[i], locale, LC_MAXNAMESIZE);
lc_current[i][LC_MAXNAMESIZE - 1] = '\0';
}
}
- }
if (segment != -1)
__dpmi_free_dos_memory(selector);
}
@@ -592,9 +599,9 @@ setlocale(int category, const char *loca
p = lc_buffer;
for (i = 0; i < LC_CATEGORIES; i++)
{
- p = stpcpy(p, lc_current[i]);
+ p = strcpy(p, lc_current[i]) + strlen( lc_current[i] );
if (i != (LC_CATEGORIES - 1))
- p = stpcpy(p, ",");
+ strcpy(p++, ",");
}
return lc_buffer;
}
@@ -604,11 +611,10 @@ setlocale(int category, const char *loca
}
#ifdef TEST
-#include <stdio.h>
unsigned char __dj_collate_table[256];
-char __dj_date_format[10] = "%m/%d/%y";
-char __dj_time_format[16] = "%H:%M:%S";
+extern char __dj_date_format[];
+extern char __dj_time_format[];
int
main(int ac, char *av[])
- Raw text -