Changeset 2792 for branches


Ignore:
Timestamp:
Aug 27, 2006, 8:31:48 PM (19 years ago)
Author:
bird
Message:

Implemented the new length modifiers for *scanf. Adjusted the length modifier implementation for *printf. Fixes #113.

Location:
branches/libc-0.6/src/emx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/ChangeLog.LIBC

    r2786 r2792  
    552006-08-27: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    66    - libc:
     7        o Implemented the new length modifiers for *scanf. Adjusted the length
     8          modifier implementation for *printf. Fixes #76.
    79        o Fixed problems with fork() and module loading/unloading. Fixes #76.
    810        o Fixed atexit() and on_exit() problem with callbacks in unloaded DLLs. Fixes #103.
  • branches/libc-0.6/src/emx/src/lib/io/_input.c

    r2090 r2792  
    44#include <stdio.h>
    55#include <stdlib.h>
     6#include <stdint.h>
    67#include <stdarg.h>
    78#include <string.h>
     
    1617#define TRUE    1
    1718
     19#define SIZE_HH         (('h' << 8) | 'h')
     20#define SIZE_LL         (('l' << 8) | 'l')
     21
     22
    1823/* This structure holds the local variables of _input() which are
    1924   passed to the functions called by _input(). */
     
    2833  int collected;                /* Number of characters collected */
    2934  size_t more_size;             /* Size of the above */
    30   char size;                    /* Size (0, 'h', 'l' or 'L') */
     35  int size;                     /* Size (0, 'h', SIZE_HH, 'l', SIZE_LL, 'L', 'j', 'z', 'Z', 't' or 'q') */
    3136  char width_given;             /* A field width has been given */
    3237  unsigned char ungetc_count;   /* stream's _ungetc_count prior to get0() */
     
    192197
    193198
     199static void inp_wchar (ilocal *v, wchar_t *dst)
     200{
     201/** @todo implement sscanf(, "%lc", pwsz). */
     202  int c, ok;
     203//  mbstate_t mbs;
     204
     205  if (v->status == END_OF_FILE)
     206    {
     207      v->status = INPUT_FAILURE;
     208      return;
     209    }
     210  if (!v->width_given)
     211    v->width = 1;
     212  ok = FALSE;
     213//  mbsinit(&mbs);
     214  while ((c = get (v)) != EOF)
     215    {
     216      ok = TRUE;
     217      if (dst != NULL)
     218        *dst++ = (unsigned char)c;
     219    }
     220  if (!ok)
     221    v->status = INPUT_FAILURE;
     222  else if (dst != NULL)
     223    ++v->count;
     224}
     225
     226
    194227static void inp_str (ilocal *v, unsigned char *dst)
    195228{
     
    197230
    198231  c = skip (v);
    199   if (v->status != OK) return;
     232  if (v->status != OK)
     233    return;
    200234  while (c != EOF && !isspace (c))
    201235    {
     
    211245  make_unread (v, c);
    212246}
     247
     248
     249static void inp_wstr (ilocal *v, wchar_t *dst)
     250{
     251  int c;
     252/** @todo implement sscanf(, "%ls", pwsz). */
     253//  mbstate_t mbs;
     254
     255  c = skip (v);
     256  if (v->status != OK)
     257    return;
     258
     259//  mbsinit(&mbs);
     260  while (c != EOF && !isspace (c))
     261    {
     262      if (dst != NULL)
     263        *dst++ = (unsigned char)c;
     264      c = get (v);
     265    }
     266  if (dst != NULL)
     267    {
     268      *dst = 0;
     269      ++v->count;
     270    }
     271  make_unread (v, c);
     272}
     273
    213274
    214275
     
    372433      switch (v->size)
    373434        {
    374         case 'L':
    375           *(long long *)dst = n;
    376           break;
    377435        case 'h':
    378436          *(short *)dst = n;
     437          break;
     438        case SIZE_HH:
     439          *(signed char *)dst = n;
     440          break;
     441        case 'l':
     442          *(long *)dst = n;
     443          break;
     444        case SIZE_LL:
     445        case 'L':                       /* GNU */
     446        case 'q':                       /* bsd */
     447          *(long long *)dst = n;
     448          break;
     449        case 'j':
     450          *(intmax_t *)dst = n;
     451          break;
     452        case 'z':
     453        case 'Z':
     454          *(size_t *)dst = n;
     455          break;
     456        case 't':
     457          *(ptrdiff_t *)dst = n;
    379458          break;
    380459        default:
     
    659738                v->width_given = TRUE;
    660739            }
    661           if (*format == 'h' || *format == 'l' || *format == 'L')
    662             v->size = *format++;
     740          if (   *format == 'h' || *format == 'l' || *format == 'L'
     741              || *format == 'j' || *format == 'z' || *format == 't'
     742              || *format == 'q' || *format == 'Z' )
     743            {
     744              v->size = *format++;
     745              if (v->size == 'l' && *format == 'l')
     746                {
     747                  v->size = SIZE_LL; ++format;
     748                }
     749              else if (v->size == 'h' && *format == 'h')
     750                {
     751                  v->size = SIZE_HH; ++format;
     752                }
     753            }
    663754          f = *format;
    664755          switch (f)
    665756            {
    666             case 'c':
    667               if (assign)
    668                 dst = va_arg (arg_ptr, char *);
    669               inp_char (v, dst);
    670               break;
    671 
    672757            case '[':
    673758              if (assign)
     
    676761              break;
    677762
     763            case 'c':
     764              if (v->size != 'l' && v->size != 'L')
     765                {
     766                  if (assign)
     767                    dst = va_arg (arg_ptr, char *);
     768                  inp_char (v, dst);
     769                  break;
     770                }
     771              /* fall thru */
     772            case 'C':
     773              if (assign)
     774                dst = va_arg (arg_ptr, wchar_t *);
     775              inp_wchar (v, dst);
     776              break;
     777
    678778            case 's':
    679               if (assign)
    680                 dst = va_arg (arg_ptr, char *);
    681               inp_str (v, dst);
    682               break;
     779              if (v->size != 'l' && v->size == 'L')
     780                {
     781                  if (assign)
     782                    dst = va_arg (arg_ptr, char *);
     783                  inp_str (v, dst);
     784                  break;
     785                }
     786              /* fall thru */
     787            case 'S':
     788                if (assign)
     789                  dst = va_arg (arg_ptr, wchar_t *);
     790                inp_wstr (v, dst);
     791                break;
    683792
    684793            case 'f':
     
    713822                switch (v->size)
    714823                  {
    715                   case 'L':
    716                     dst = va_arg (arg_ptr, long long *);
     824                  case SIZE_HH:
     825                    dst = va_arg (arg_ptr, char *);
    717826                    break;
    718827                  case 'h':
    719828                    dst = va_arg (arg_ptr, short *);
     829                    break;
     830                  case 'l':
     831                    dst = va_arg (arg_ptr, long *);
     832                    break;
     833                  case SIZE_LL:
     834                  case 'L':
     835                  case 'q':
     836                    dst = va_arg (arg_ptr, long long *);
     837                    break;
     838                  case 'j':
     839                    dst = va_arg (arg_ptr, uintmax_t *);
     840                    break;
     841                  case 'z':
     842                  case 'Z':
     843                    dst = va_arg (arg_ptr, size_t *);
     844                    break;
     845                  case 't':
     846                    dst = va_arg (arg_ptr, ptrdiff_t *);
    720847                    break;
    721848                  default:
     
    730857                switch (v->size)
    731858                  {
    732                   case 'L':
    733                     *(va_arg (arg_ptr, long long *)) = v->chars;
     859                  case SIZE_HH:
     860                    *(va_arg (arg_ptr, signed char *)) = v->chars;
    734861                    break;
    735862                  case 'h':
    736863                    *(va_arg (arg_ptr, short *)) = v->chars;
     864                    break;
     865                  case 'l':
     866                    *(va_arg (arg_ptr, long *)) = v->chars;
     867                    break;
     868                  case SIZE_LL:
     869                  case 'L':
     870                  case 'q':
     871                    *(va_arg (arg_ptr, long long *)) = v->chars;
     872                    break;
     873                  case 'z':
     874                  case 'Z':
     875                    *(va_arg (arg_ptr, size_t *)) = v->chars;
     876                    break;
     877                  case 't':
     878                    *(va_arg (arg_ptr, ptrdiff_t *)) = v->chars;
    737879                    break;
    738880                  default:
  • branches/libc-0.6/src/emx/src/lib/io/_output.c

    r2160 r2792  
    55#include <stdlib.h>
    66#include <stdarg.h>
     7#include <stdint.h>
    78#include <string.h>
    89#include <math.h>
     
    2122#define SIZE_HH         (('h' << 8) | 'h')
    2223#define SIZE_LL         (('l' << 8) | 'l')
     24
     25/* ASSUMES that there are no odd integer sizes (like char being 7 bit or similar weirdnesses). */
     26
     27#define IS_SIZE_64BIT(size) (   (sizeof(long long) == sizeof(uint64_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \
     28                             || (sizeof(size_t)    == sizeof(uint64_t) && ((size) == 'z' || (size) == 'z')) \
     29                             || (sizeof(uintmax_t) == sizeof(uint64_t) && (size) == 'j') \
     30                             || (sizeof(ptrdiff_t) == sizeof(uint64_t) && (size) == 't') \
     31                             || (sizeof(int)       == sizeof(uint64_t) && (size) == 0) \
     32                             || (sizeof(short)     == sizeof(uint64_t) && (size) == 'h') \
     33                             || (sizeof(char)      == sizeof(uint64_t) && (size) == SIZE_HH) \
     34                            )
     35
     36#define IS_SIZE_32BIT(size) (   (sizeof(long long) == sizeof(uint32_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \
     37                             || (sizeof(size_t)    == sizeof(uint32_t) && ((size) == 'z' || (size) == 'z')) \
     38                             || (sizeof(uintmax_t) == sizeof(uint32_t) && (size) == 'j') \
     39                             || (sizeof(ptrdiff_t) == sizeof(uint32_t) && (size) == 't') \
     40                             || (sizeof(int)       == sizeof(uint32_t) && (size) == 0) \
     41                             || (sizeof(short)     == sizeof(uint32_t) && (size) == 'h') \
     42                             || (sizeof(char)      == sizeof(uint32_t) && (size) == SIZE_HH) \
     43                            )
     44
     45#define IS_SIZE_LE_32BIT(size) (   (sizeof(long long) <= sizeof(uint32_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \
     46                                || (sizeof(size_t)    <= sizeof(uint32_t) && ((size) == 'z' || (size) == 'z')) \
     47                                || (sizeof(uintmax_t) <= sizeof(uint32_t) && (size) == 'j') \
     48                                || (sizeof(ptrdiff_t) <= sizeof(uint32_t) && (size) == 't') \
     49                                || (sizeof(int)       <= sizeof(uint32_t) && (size) == 0) \
     50                                || (sizeof(short)     <= sizeof(uint32_t) && (size) == 'h') \
     51                                || (sizeof(char)      <= sizeof(uint32_t) && (size) == SIZE_HH) \
     52                               )
     53
     54#define IS_SIZE_16BIT(size) (   (sizeof(long long) == sizeof(uint16_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \
     55                             || (sizeof(size_t)    == sizeof(uint16_t) && ((size) == 'z' || (size) == 'z')) \
     56                             || (sizeof(uintmax_t) == sizeof(uint16_t) && (size) == 'j') \
     57                             || (sizeof(ptrdiff_t) == sizeof(uint16_t) && (size) == 't') \
     58                             || (sizeof(int)       == sizeof(uint16_t) && (size) == 0) \
     59                             || (sizeof(short)     == sizeof(uint16_t) && (size) == 'h') \
     60                             || (sizeof(char)      == sizeof(uint16_t) && (size) == SIZE_HH) \
     61                            )
     62
     63#define IS_SIZE_8BIT(size)  (   (sizeof(long long) == sizeof(uint8_t) && ((size) == 'L' || (size) == SIZE_LL || (size) == 'q')) \
     64                             || (sizeof(size_t)    == sizeof(uint8_t) && ((size) == 'z' || (size) == 'z')) \
     65                             || (sizeof(uintmax_t) == sizeof(uint8_t) && (size) == 'j') \
     66                             || (sizeof(ptrdiff_t) == sizeof(uint8_t) && (size) == 't') \
     67                             || (sizeof(int)       == sizeof(uint8_t) && (size) == 0) \
     68                             || (sizeof(short)     == sizeof(uint8_t) && (size) == 'h') \
     69                             || (sizeof(char)      == sizeof(uint8_t) && (size) == SIZE_HH) \
     70                            )
     71
    2372
    2473#define DEFAULT_PREC    6
     
    369418
    370419
    371 static int cvt_hex_32 (olocal *v, unsigned n, char x)
     420static int cvt_hex_32 (olocal *v, uint32_t n, char x)
    372421{
    373422  char buf[9];
     
    378427
    379428
    380 static int cvt_hex_64 (olocal *v, unsigned long long n, char x)
     429static int cvt_hex_64 (olocal *v, uint64_t n, char x)
    381430{
    382431  char buf[17];
     
    401450
    402451
    403 static int cvt_oct_32 (olocal *v, unsigned n)
     452static int cvt_oct_32 (olocal *v, uint32_t n)
    404453{
    405454  char buf[12];
     
    410459
    411460
    412 static int cvt_oct_64 (olocal *v, unsigned long long n)
     461static int cvt_oct_64 (olocal *v, uint64_t n)
    413462{
    414463  char buf[23];
     
    419468
    420469
    421 static int cvt_dec_32 (olocal *v, unsigned n, int is_signed, int is_neg)
     470static int cvt_dec_32 (olocal *v, uint32_t n, int is_signed, int is_neg)
    422471{
    423472  char buf[11];
     
    428477
    429478
    430 static int cvt_dec_64 (olocal *v, unsigned long long n, int is_signed,
    431                        int is_neg)
     479static int cvt_dec_64 (olocal *v, uint64_t n, int is_signed, int is_neg)
    432480{
    433481  char buf[21];
     
    905953                size = SIZE_HH; ++format;
    906954              }
    907             else if (size == 'q' || size == 'j')
    908                 size = SIZE_LL;
    909             else if (size == 'z' || size == 'Z' || size == 't')
    910                 size = 'l';
    911955          }
    912956
     
    919963
    920964          case 'n':
    921             if (size == SIZE_LL || size == 'L')
    922               {
    923                 long long *ptr = va_arg (arg_ptr, long long *);
     965            if (IS_SIZE_64BIT(size))
     966              {
     967                int64_t *ptr = va_arg (arg_ptr, int64_t *);
    924968                *ptr = v.count;
    925969              }
    926             else if (size == 'h')
    927               {
    928                 short *ptr = va_arg (arg_ptr, short *);
     970            else if (IS_SIZE_16BIT(size))
     971              {
     972                int16_t *ptr = va_arg (arg_ptr, int16_t *);
    929973                *ptr = v.count;
    930974              }
    931             else if (size == SIZE_HH)
    932               {
    933                 char *ptr = va_arg (arg_ptr, char *);
     975            else if (IS_SIZE_8BIT(size))
     976              {
     977                int8_t *ptr = va_arg (arg_ptr, int8_t *);
    934978                *ptr = v.count;
    935979              }
    936             else
    937               {
    938                 int *ptr = va_arg (arg_ptr, int *);
     980            else /* 32-bit */
     981              {
     982                int32_t *ptr = va_arg (arg_ptr, int32_t *);
    939983                *ptr = v.count;
    940984              }
     
    9751019          case 'd':
    9761020          case 'i':
    977             if (size == SIZE_LL || size == 'L')
    978               {
    979                 long long n = va_arg (arg_ptr, long long);
     1021            if (IS_SIZE_64BIT(size))
     1022              {
     1023                int64_t n = va_arg (arg_ptr, int64_t);
    9801024                if (n < 0)
    9811025                  CHECK (cvt_dec_64 (&v, -n, TRUE, TRUE));
     
    9851029            else
    9861030              {
    987                 int n = va_arg (arg_ptr, int);
     1031                int32_t n = va_arg (arg_ptr, int32_t);
    9881032                if (size == 'h')
    9891033                  n = (short)n;
     
    9981042
    9991043          case 'u':
    1000             if (size == SIZE_LL || size == 'L')
    1001               CHECK (cvt_dec_64 (&v, va_arg (arg_ptr, unsigned long long),
    1002                                  FALSE, FALSE));
     1044            if (IS_SIZE_64BIT (size))
     1045              CHECK (cvt_dec_64 (&v, va_arg (arg_ptr, uint64_t), FALSE, FALSE));
    10031046            else
    10041047              {
    1005                 unsigned n = va_arg (arg_ptr, unsigned);
     1048                uint32_t n = va_arg (arg_ptr, uint32_t);
    10061049                if (size == 'h')
    10071050                  n = (unsigned short)n;
     
    10141057          case 'p':
    10151058            v.hash = TRUE;
    1016             CHECK (cvt_hex_32 (&v, va_arg (arg_ptr, unsigned), 'x'));
     1059            if (sizeof(uintptr_t) == sizeof(uint64_t))
     1060                CHECK (cvt_hex_64 (&v, va_arg (arg_ptr, uintptr_t), 'x'));
     1061            else
     1062                CHECK (cvt_hex_32 (&v, va_arg (arg_ptr, uintptr_t), 'x'));
    10171063            break;
    10181064
    10191065          case 'x':
    10201066          case 'X':
    1021             if (size == SIZE_LL || size == 'L')
    1022               CHECK (cvt_hex_64 (&v, va_arg (arg_ptr, unsigned long long),
     1067            if (IS_SIZE_64BIT (size))
     1068              CHECK (cvt_hex_64 (&v, va_arg (arg_ptr, uint64_t),
    10231069                                 *format));
    10241070            else
    10251071              {
    1026                 unsigned n = va_arg (arg_ptr, unsigned);
     1072                uint32_t n = va_arg (arg_ptr, uint32_t);
    10271073                if (size == 'h')
    10281074                  n = (unsigned short)n;
     
    10341080
    10351081          case 'o':
    1036             if (size == SIZE_LL || size == 'L')
    1037               CHECK (cvt_oct_64 (&v, va_arg (arg_ptr, unsigned long long)));
     1082            if (IS_SIZE_64BIT (size))
     1083              CHECK (cvt_oct_64 (&v, va_arg (arg_ptr, uint64_t)));
    10381084            else
    10391085              {
    1040                 unsigned n = va_arg (arg_ptr, unsigned);
     1086                uint32_t n = va_arg (arg_ptr, uint32_t);
    10411087                if (size == 'h')
    10421088                  n = (unsigned short)n;
Note: See TracChangeset for help on using the changeset viewer.