summaryrefslogtreecommitdiff
path: root/libc/stdio
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-12-20 19:26:35 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-12-20 19:26:35 +0000
commitc9d66e44af5c93a1ea5487fd9bff78274be65850 (patch)
tree975bb662b51ac91f8d1434553b936784b175a802 /libc/stdio
parentbd6e7b0208c9652717bec30abff2d8dc12eaaca7 (diff)
The big thing is locale dependent collation support.
Also added outdigit support and (legacy) YESSTR/NOSTR support.
Diffstat (limited to 'libc/stdio')
-rw-r--r--libc/stdio/printf.c19
-rw-r--r--libc/stdio/stdio.c37
2 files changed, 47 insertions, 9 deletions
diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c
index 273bf3621..945d3c38d 100644
--- a/libc/stdio/printf.c
+++ b/libc/stdio/printf.c
@@ -2331,11 +2331,16 @@ static int _do_one_spec(FILE * __restrict stream,
}
if (ppfs->conv_num <= CONV_i) { /* pointer or (un)signed int */
alphacase = __UIM_LOWER;
- if (((base = spec_base[(int)(ppfs->conv_num - CONV_p)]) == 10)
- && (PRINT_INFO_FLAG_VAL(&(ppfs->info),group))
- ) {
- alphacase = __UIM_GROUP;
+#ifndef __LOCALE_C_ONLY
+ if ((base = spec_base[(int)(ppfs->conv_num - CONV_p)]) == 10) {
+ if (PRINT_INFO_FLAG_VAL(&(ppfs->info),group)) {
+ alphacase = __UIM_GROUP;
+ }
+ if (PRINT_INFO_FLAG_VAL(&(ppfs->info),i18n)) {
+ alphacase |= 0x80;
+ }
}
+#endif /* __LOCALE_C_ONLY */
if (ppfs->conv_num <= CONV_u) { /* pointer or unsigned int */
if (ppfs->conv_num == CONV_X) {
alphacase = __UIM_UPPER;
@@ -2350,6 +2355,9 @@ static int _do_one_spec(FILE * __restrict stream,
if (ppfs->info.prec < 0) { /* Ignore '0' flag if prec specified. */
padchar = ppfs->info.pad;
}
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning if using outdigits and/or grouping, how should we interpret precision?
+#endif
s = _uintmaxtostr(buf + sizeof(buf) - 1,
(uintmax_t)
_load_inttype(*argtype & __PA_INTMASK,
@@ -2557,6 +2565,9 @@ static int _do_one_spec(FILE * __restrict stream,
return -1;
}
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning if using outdigits and/or grouping, how should we pad?
+#endif
{
size_t t;
diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c
index cf72a5ccc..e39cf5205 100644
--- a/libc/stdio/stdio.c
+++ b/libc/stdio/stdio.c
@@ -319,11 +319,11 @@ int putw(int w, FILE *stream)
UNLOCKED(int,fileno,(register FILE *stream),(stream))
{
#ifdef __STDIO_GLIBC_CUSTOM_STREAMS
- return ( ((stream->cookie == &(stream->filedes)) && (stream->filedes >= 0))
+ return ( (stream && (stream->cookie == &(stream->filedes)) && (stream->filedes >= 0))
? stream->filedes
: (__set_errno(EBADF), -1) );
#else /* __STDIO_GLIBC_CUSTOM_STREAMS */
- return (stream->filedes >= 0) ? stream->filedes : (__set_errno(EBADF), -1);
+ return ((stream && stream->filedes >= 0)) ? stream->filedes : (__set_errno(EBADF), -1);
#endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
}
@@ -3331,7 +3331,7 @@ char *_uintmaxtostr(register char * __restrict bufend, uintmax_t uval,
unsigned int H, L, high, low, rh;
#endif
#ifndef __LOCALE_C_ONLY
- int grouping;
+ int grouping, outdigit;
size_t gslen; /* This does not need to be initialized. */
const char *g; /* This does not need to be initialized. */
#endif /* __LOCALE_C_ONLY */
@@ -3350,6 +3350,11 @@ char *_uintmaxtostr(register char * __restrict bufend, uintmax_t uval,
#ifndef __LOCALE_C_ONLY
grouping = -1;
+ outdigit = 0x80 & alphacase;
+ alphacase ^= outdigit;
+#ifdef __UCLIBC_MJN3_ONLY_
+#warning implement outdigit... need digit lengths! (put it in locale struct)
+#endif
if (alphacase == __UIM_GROUP) {
assert(base == 10);
if (*(g = CUR_LOCALE.grouping)
@@ -3391,7 +3396,18 @@ char *_uintmaxtostr(register char * __restrict bufend, uintmax_t uval,
digit = uval % base;
uval /= base;
- *--bufend = ( (digit < 10) ? digit + '0' : digit + alphacase );
+#ifndef __LOCALE_C_ONLY
+ if (outdigit) {
+ outdigit = CUR_LOCALE.outdigit_length[digit];
+ do {
+ *--bufend = (&CUR_LOCALE.outdigit0_mb)[digit][--outdigit];
+ } while (outdigit);
+ outdigit = 1;
+ } else
+#endif
+ {
+ *--bufend = ( (digit < 10) ? digit + '0' : digit + alphacase );
+ }
} while (uval);
#else /* ************************************************** */
@@ -3437,7 +3453,18 @@ char *_uintmaxtostr(register char * __restrict bufend, uintmax_t uval,
low = (low / base) + (H * rh) + (digit / base);
digit %= base;
- *--bufend = ( (digit < 10) ? digit + '0' : digit + alphacase );
+#ifndef __LOCALE_C_ONLY
+ if (outdigit) {
+ outdigit = CUR_LOCALE.outdigit_length[digit];
+ do {
+ *--bufend = (&CUR_LOCALE.outdigit0_mb)[digit][--outdigit];
+ } while (outdigit);
+ outdigit = 1;
+ } else
+#endif
+ {
+ *--bufend = ( (digit < 10) ? digit + '0' : digit + alphacase );
+ }
} while (low | high);
#endif /******************************************************/