delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/21/09:06:42

Date: Tue, 21 Jan 2003 14:08:02 +0000
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
Sender: rich AT phekda DOT freeserve DOT co DOT uk
To: djgpp-workers AT delorie DOT com
X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: printf- & scanf-families: j, z, t qualifiers (C99) [PATCH]
Message-Id: <E18az2s-0000sQ-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Below is a patch to add support for the j, z and t conversion qualifiers
to the printf- and scanf-families of functions.

OK to commit?

Thanks, bye, Rich =]

Index: src/libc/ansi/stdio/doprnt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doprnt.c,v
retrieving revision 1.13
diff -p -c -3 -r1.13 doprnt.c
*** src/libc/ansi/stdio/doprnt.c	22 Dec 2002 04:42:28 -0000	1.13
--- src/libc/ansi/stdio/doprnt.c	21 Jan 2003 14:04:23 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
*************** _doprnt(const char *fmt0, va_list argp, 
*** 194,199 ****
--- 195,202 ----
        goto rflag;
      case 'h':
        if (flags&SHORTINT) {
+ 	/* C99 */
+ 	/* for 'hh' - char */
  	flags |= CHARINT;
  	flags &= ~SHORTINT;
        } else {
*************** _doprnt(const char *fmt0, va_list argp, 
*** 205,210 ****
--- 208,222 ----
  	flags |= LONGDBL; /* for 'll' - long long */
        else
  	flags |= LONGINT;
+       goto rflag;
+     case 'j': /* C99 */
+       flags |= LONGDBL; /* long long */
+       goto rflag;
+     case 'z': /* C99 */
+       flags |= LONGINT;
+       goto rflag;
+     case 't': /* C99 */
+       /* t => int, which is the default. */
        goto rflag;
      case 'c':
        *(t = buf) = va_arg(argp, int);
Index: src/libc/ansi/stdio/printf.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/printf.txh,v
retrieving revision 1.6
diff -p -c -3 -r1.6 printf.txh
*** src/libc/ansi/stdio/printf.txh	6 Dec 2002 09:35:51 -0000	1.6
--- src/libc/ansi/stdio/printf.txh	21 Jan 2003 14:04:24 -0000
*************** characters for a string. 
*** 65,74 ****
  
  @item
  
! An optional conversion qualifier, which may be @code{hh} to specify
! @code{char}, @code{h} to specify @code{short} integers, @code{l}
! to specify @code{long} integers, @code{ll} to specify
! @code{long long} integers, or @code{L} to specify @code{long} doubles.
  
  @item
  
--- 65,98 ----
  
  @item
  
! An optional conversion qualifier, which may be:
! 
! @table @code
! @item hh
! to specify @code{char};
! 
! @item h
! to specify @code{short} integers;
! 
! @item j
! to specify @code{intmax_t} or @code{uintmax_t} integers;
! 
! @item l
! to specify doubles or @code{long} integers;
! 
! @item ll
! (two lower-case ell letters) to specify @code{long long} integers;
! to specify @code{long} doubles, although this is non-standard;
! 
! @item L
! to specify @code{long} doubles;
! 
! @item t
! to specify @code{ptrdiff_t};
! 
! @item z
! to specify @code{size_t}.
! @end table
  
  @item
  
*************** The number of characters written.
*** 163,170 ****
  
  @subheading Portability
  
! The @code{D}, @code{O} and @code{U} conversion types are non-standard.
! gcc may generate warnings, if you use them.
  
  @portability ansi, posix
  
--- 187,195 ----
  
  @subheading Portability
  
! @port-note ansi The @code{D}, @code{O} and @code{U} conversion types are non-standard.  gcc may generate warnings, if you use them.
! 
! @port-note ansi-c99 The @code{hh}, @code{j}, @code{t} and @code{z} conversion specifiers first appeared in the ANSI C99 standard.
  
  @portability ansi, posix
  
*************** gcc may generate warnings, if you use th
*** 173,176 ****
  @example
  printf("%-3d %10.2f%% Percent of %s\n", index, per[index], name[index]);
  @end example
- 
--- 198,200 ----
Index: src/libc/ansi/stdio/doscan.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doscan.c,v
retrieving revision 1.12
diff -p -c -3 -r1.12 doscan.c
*** src/libc/ansi/stdio/doscan.c	15 Dec 2002 09:23:30 -0000	1.12
--- src/libc/ansi/stdio/doscan.c	21 Jan 2003 14:04:28 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
*************** _doscan_low(FILE *iop, int (*scan_getc)(
*** 95,105 ****
--- 96,120 ----
        ch = *fmt++;
        if (ch=='h')
        {
+ 	/* C99 */
+ 	/* for 'hh' - char */
  	size = CHAR;
  	ch = *fmt++;
        }
      } else if (ch=='L') {
        size = LONGDOUBLE;
+       ch = *fmt++;
+     } else if (ch=='j') {
+       /* C99 */
+       size = LONGDOUBLE; /* for long long */
+       ch = *fmt++;
+     } else if (ch=='z') {
+       /* C99 */
+       size = LONG;
+       ch = *fmt++;
+     } else if (ch=='t') {
+       /* C99 */
+       size = REGULAR;
        ch = *fmt++;
      } else if (ch=='[')
        fmt = _getccl((const unsigned char *)fmt);
Index: src/libc/ansi/stdio/scanf.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/scanf.txh,v
retrieving revision 1.8
diff -p -c -3 -r1.8 scanf.txh
*** src/libc/ansi/stdio/scanf.txh	16 Dec 2002 21:48:39 -0000	1.8
--- src/libc/ansi/stdio/scanf.txh	21 Jan 2003 14:04:29 -0000
*************** This allows to describe an input field t
*** 29,39 ****
  @item A width specifier, which specifies the maximum number of input
  characters to use in the conversion. 
  
! @item An optional conversion qualifier, which may be @samp{hh}
! to specify @code{char}, @samp{h} to specify @code{short}, @samp{l}
! to specify doubles or long ints, or @samp{L} or @samp{ll}
! (two lower-case ell letters) to specify long doubles and the
! long long type.  If the @samp{h} qualifier appears before a specifier
  that implies conversion to a @code{long} or @code{float} or
  @code{double}, like in @samp{%hD} or @samp{%hf}, it is generally
  ignored.
--- 29,64 ----
  @item A width specifier, which specifies the maximum number of input
  characters to use in the conversion. 
  
! @item An optional conversion qualifier, which may be:
! 
! @table @code
! @item hh
! to specify @code{char};
! 
! @item h
! to specify @code{short} integers;
! 
! @item j
! to specify @code{intmax_t} or @code{uintmax_t} integers;
! 
! @item l
! to specify doubles or @code{long} integers;
! 
! @itemx ll
! (two lower-case ell letters) to specify @code{long long} integers;
! to specify @code{long} doubles, although this is non-standard;
! 
! @item L
! to specify @code{long} doubles;
! 
! @item t
! to specify @code{ptrdiff_t};
! 
! @item z
! to specify @code{size_t}.
! @end table
! 
! If the @samp{h} qualifier appears before a specifier
  that implies conversion to a @code{long} or @code{float} or
  @code{double}, like in @samp{%hD} or @samp{%hf}, it is generally
  ignored.
*************** Convert the input to a signed @code{char
*** 66,71 ****
--- 91,100 ----
  
  Convert the input to a signed @code{short} using 10 as the base.
  
+ @item jd
+ 
+ Convert the input to an @code{intmax_t} using 10 as the base.
+ 
  @item ld
  @itemx D
  
*************** Convert the input to a signed @code{long
*** 77,82 ****
--- 106,119 ----
  
  Convert the input to a signed @code{long long} using 10 as the base.
  
+ @item td
+ 
+ Convert the input to a @code{ptrdiff_t} using 10 as the base.
+ 
+ @item zd
+ 
+ Convert the input to a @code{size_t} using 10 as the base.
+ 
  @item e
  @itemx E
  @itemx f
*************** Like @samp{i}, but stores the result in 
*** 124,129 ****
--- 161,170 ----
  
  Like @samp{i}, but stores the result in a signed @code{short}.
  
+ @item ji
+ 
+ Like @samp{i}, but stores the result in an @code{intmax_t}.
+ 
  @item li
  @itemx I
  
*************** Like @samp{i}, but stores the result in 
*** 135,140 ****
--- 176,189 ----
  
  Like @samp{i}, but stores the result in a signed @code{long long}.
  
+ @item ti
+ 
+ Like @samp{i}, but stores the result in a @code{ptrdiff_t}.
+ 
+ @item zi
+ 
+ Like @samp{i}, but stores the result in a @code{size_t}.
+ 
  @item n
  
  Store the number of characters scanned so far into the @code{int}
*************** Like @samp{n}, but the argument should p
*** 148,153 ****
--- 197,206 ----
  
  Like @samp{n}, but the argument should point to a signed @code{short}.
  
+ @item jn
+ 
+ Like @samp{n}, but the argument should point to an @code{intmax_t}.
+ 
  @item ln
  
  Like @samp{n}, but the argument should point to a signed @code{long}.
*************** Like @samp{n}, but the argument should p
*** 157,162 ****
--- 210,223 ----
  
  Like @samp{n}, but the argument should point to a signed @code{long long}.
  
+ @item tn
+ 
+ Like @samp{n}, but the argument should point to a @code{ptrdiff_t}.
+ 
+ @item zn
+ 
+ Like @samp{n}, but the argument should point to a @code{size_t}.
+ 
  @item o
  
  Convert the input to an unsigned @code{int}, using base 8.
*************** Convert the input to an unsigned @code{c
*** 169,174 ****
--- 230,239 ----
  
  Convert the input to an unsigned @code{short}, using base 8.
  
+ @item jo
+ 
+ Convert the input to an @code{uintmax_t}, using base 8.
+ 
  @item lo
  @itemx O
  
*************** Convert the input to an unsigned @code{l
*** 180,185 ****
--- 245,258 ----
  
  Convert the input to an unsigned @code{long long}, using base 8.
  
+ @item to
+ 
+ Convert the input to a @code{ptrdiff_t}, using base 8.
+ 
+ @item zo
+ 
+ Convert the input to a @code{size_t}, using base 8.
+ 
  @item p
  
  Convert the input to a pointer.  This is like using the @code{x} format. 
*************** Convert the input to an unsigned @code{c
*** 202,207 ****
--- 275,284 ----
  
  Convert the input to an unsigned @code{short} using 10 as the base.
  
+ @item ju
+ 
+ Convert the input to an @code{uintmax_t} using 10 as the base.
+ 
  @item lu
  @itemx U
  
*************** Convert the input to an unsigned @code{l
*** 213,218 ****
--- 290,303 ----
  
  Convert the input to an unsigned @code{long long} using 10 as the base.
  
+ @item tu
+ 
+ Convert the input to a @code{ptrdiff_t} using 10 as the base.
+ 
+ @item zu
+ 
+ Convert the input to a @code{size_t} using 10 as the base.
+ 
  @item x
  @itemx X
  
*************** Convert the input to an unsigned @code{c
*** 228,233 ****
--- 313,323 ----
  
  Convert the input to an unsigned @code{short}, using base 16.
  
+ @item jx
+ @itemx jX
+ 
+ Convert the input to an @code{uintmax_t}, using base 16.
+ 
  @item lx
  @itemx lX
  
*************** Convert the input to an unsigned @code{l
*** 240,245 ****
--- 330,345 ----
  
  Convert the input to an unsigned @code{long long}, using base 16.
  
+ @item tx
+ @itemx tX
+ 
+ Convert the input to a @code{ptrdiff_t}, using base 16.
+ 
+ @item zx
+ @itemx zX
+ 
+ Convert the input to a @code{size_t}, using base 16.
+ 
  @item [@dots{}]
  
  Stores the matched characters in a @code{char} array, followed by a
*************** to be returned.
*** 282,287 ****
--- 382,389 ----
  @subheading Portability
  
  @port-note ansi The conversion specifiers @samp{F}, @samp{D}, @samp{I}, @samp{O}, and @code{U} are DJGPP extensions; they are provided for compatibility with Borland C and other compilers.  The conversion specifiers for the @code{long long} data type are GCC extensions.  The meaning of @samp{[a-c]} as a range of characters is a very popular extension to ANSI (which merely says a dash ``may have a special meaning'' in that context).
+ 
+ @port-note ansi-c99 The @code{hh}, @code{j}, @code{t} and @code{z} conversion specifiers first appeared in the ANSI C99 standard.
  
  @portability ansi, posix
  
Index: src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.133
diff -p -c -3 -r1.133 wc204.txi
*** src/docs/kb/wc204.txi	19 Jan 2003 13:04:31 -0000	1.133
--- src/docs/kb/wc204.txi	21 Jan 2003 14:04:45 -0000
*************** of functions has changed.  Previously @c
*** 798,810 ****
  a @code{long} version of the @code{%x} type conversion.  Now @code{%X}
  is equivalent to the @code{%x} type conversion, as required by C99.
  
! @findex _doprnt AT r{, and }hh AT r{ conversion qualifier}
! @findex printf AT r{, and }hh AT r{ conversion qualifier}
! @findex _doscan AT r{, and }hh AT r{ conversion qualifier}
! @findex scanf AT r{, and }hh AT r{ conversion qualifier}
! The @code{hh} conversion qualifier is now supported by @code{_doprnt},
! @code{_doscan}, the @code{printf} family of functions
! and the @code{scanf} family of functions.
  
  @findex delay AT r{, and Windows 2000 and XP}
  The @code{delay} function now works on Windows 2000 and XP.  However, the
--- 798,811 ----
  a @code{long} version of the @code{%x} type conversion.  Now @code{%X}
  is equivalent to the @code{%x} type conversion, as required by C99.
  
! @findex _doprnt AT r{, and C99 conversion qualifiers}
! @findex printf AT r{, and C99 conversion qualifiers}
! @findex _doscan AT r{, and C99 conversion qualifiers}
! @findex scanf AT r{, and C99 conversion qualifiers}
! The @code{hh}, @code{j}, @code{t} and @code{z} conversion qualifiers
! are now supported by @code{_doprnt}, @code{_doscan},
! the @code{printf} family of functions and the @code{scanf} family
! of functions.
  
  @findex delay AT r{, and Windows 2000 and XP}
  The @code{delay} function now works on Windows 2000 and XP.  However, the
Index: tests/libc/ansi/stdio/printf2.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdio/printf2.c,v
retrieving revision 1.1
diff -p -c -3 -r1.1 printf2.c
*** tests/libc/ansi/stdio/printf2.c	6 Dec 2002 09:37:53 -0000	1.1
--- tests/libc/ansi/stdio/printf2.c	21 Jan 2003 14:04:45 -0000
***************
*** 1,22 ****
  #include <limits.h>
  #include <stdio.h>
  #include <stdlib.h>
  
  int
  main (void)
  {
!   signed char   sc = SCHAR_MAX;
!   unsigned char uc = UCHAR_MAX;
  
    /* Normal operation */
    printf("%hhd %hhi %hhu 0x%hhx 0x%hhX\n",
! 	 sc, sc, uc, uc, uc);
  
    /* Try truncating some ints */
    printf("%hhd %hhi\n", 128, 128);
  
!   printf("%hhd %hhi %hhu 0x%hhx 0x%hhX\n",
! 	 INT_MAX, INT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
  
    return(EXIT_SUCCESS);
  }
--- 1,68 ----
+ /*
+  * printf2.c
+  * Test cases for conversion specifiers new to the ANSI C99 standard.
+  */
+ 
+ #include <inttypes.h>
  #include <limits.h>
+ #include <stdint.h>
  #include <stdio.h>
  #include <stdlib.h>
+ #include <sys/types.h>
  
  int
  main (void)
  {
!   /* --- char --- */
  
    /* Normal operation */
    printf("%hhd %hhi %hhu 0x%hhx 0x%hhX\n",
! 	 SCHAR_MAX, SCHAR_MAX, SCHAR_MAX, SCHAR_MAX, SCHAR_MAX);
! 
!   printf("%hhd %hhi %hhu 0x%hhx 0x%hhX\n",
! 	 UCHAR_MAX, UCHAR_MAX, UCHAR_MAX, UCHAR_MAX, UCHAR_MAX);
  
    /* Try truncating some ints */
    printf("%hhd %hhi\n", 128, 128);
  
!   printf("%hhd %hhi 0%hho %hhu 0x%hhx 0x%hhX\n",
! 	 INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX);
! 
!   printf("%hhd %hhi 0%hho %hhu 0x%hhx 0x%hhX\n",
! 	 UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
! 
!   /* --- *intmax_t --- */
! 
!   printf("%jd %ji 0%jo %ju 0x%jx 0x%jX\n",
! 	 INTMAX_MAX, INTMAX_MAX, INTMAX_MAX,
! 	 INTMAX_MAX, INTMAX_MAX, INTMAX_MAX);
! 
!   printf("%jd %ji 0%jo %ju 0x%jx 0x%jX\n",
! 	 UINTMAX_MAX, UINTMAX_MAX, UINTMAX_MAX,
! 	 UINTMAX_MAX, UINTMAX_MAX, UINTMAX_MAX);
! 
!   /* --- ptrdiff_t --- */
! 
!   printf("%td %ti 0%to %tu 0x%tx 0x%tX\n",
! 	 INT_MAX, INT_MAX, INT_MAX,
! 	 INT_MAX, INT_MAX, INT_MAX);
! 
!   printf("%td %ti 0%to %tu 0x%tx 0x%tX\n",
! 	 UINT_MAX, UINT_MAX, UINT_MAX,
! 	 UINT_MAX, UINT_MAX, UINT_MAX);
! 
!   /* --- size_t --- */
! 
!   size_t  ssize_max = SSIZE_MAX;
!   size_t  size_max  = SIZE_MAX;
! 
!   printf("%zd %zi 0%zo %zu 0x%zx 0x%zX\n",
! 	 ssize_max, ssize_max, ssize_max,
! 	 ssize_max, ssize_max, ssize_max);
! 
!   printf("%zd %zi 0%zo %zu 0x%zx 0x%zX\n",
! 	 size_max, size_max, size_max,
! 	 size_max, size_max, size_max);
  
    return(EXIT_SUCCESS);
  }
Index: tests/libc/ansi/stdio/sscanf2.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdio/sscanf2.c,v
retrieving revision 1.1
diff -p -c -3 -r1.1 sscanf2.c
*** tests/libc/ansi/stdio/sscanf2.c	15 Dec 2002 09:24:44 -0000	1.1
--- tests/libc/ansi/stdio/sscanf2.c	21 Jan 2003 14:04:50 -0000
***************
*** 1,4 ****
--- 1,13 ----
+ /*
+  * sscanf2.c
+  * Test cases for conversion specifiers new to the ANSI C99 standard.
+  */
+ 
  #include <assert.h>
+ #include <inttypes.h>
+ #include <limits.h>
+ #include <stddef.h>
+ #include <stdint.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
*************** typedef struct {
*** 7,22 ****
    const char *str;
    const char *fmt;
    const signed char res;
! } signed_testcase_t;
  
  typedef struct {
    const char *str;
    const char *fmt;
    const unsigned char res;
! } unsigned_testcase_t;
  
! signed_testcase_t s_testcases[] = {
    /* Normal */
    { "127",  "%hhd", 127 },
    { "127",  "%hhi", 127 },
    { "0x7f", "%hhx", 127 },
--- 16,56 ----
    const char *str;
    const char *fmt;
    const signed char res;
! } signed_char_testcase_t;
  
  typedef struct {
    const char *str;
    const char *fmt;
    const unsigned char res;
! } unsigned_char_testcase_t;
! 
! typedef struct {
!   const char *str;
!   const char *fmt;
!   const intmax_t res;
! } intmax_testcase_t;
  
! typedef struct {
!   const char *str;
!   const char *fmt;
!   const uintmax_t res;
! } uintmax_testcase_t;
! 
! typedef struct {
!   const char *str;
!   const char *fmt;
!   const ptrdiff_t res;
! } ptrdiff_testcase_t;
! 
! typedef struct {
!   const char *str;
!   const char *fmt;
!   const size_t res;
! } size_testcase_t;
! 
! signed_char_testcase_t sc_testcases[] = {
    /* Normal */
+   { "127",  "%hhu", 127 },
    { "127",  "%hhd", 127 },
    { "127",  "%hhi", 127 },
    { "0x7f", "%hhx", 127 },
*************** signed_testcase_t s_testcases[] = {
*** 43,56 ****
    { NULL, NULL, 0 }
  };
  
! unsigned_testcase_t u_testcases[] = {
    /* Normal */
!   { "255", "%hhu", 255 },
  
    /* Truncation */
!   { "256",   "%hhu",   0 },
!   { "65535", "%hhu", 255 },
!   { "65536", "%hhu",   0 },
  
    /* Terminator */
    { NULL, NULL, 0 }
--- 77,172 ----
    { NULL, NULL, 0 }
  };
  
! unsigned_char_testcase_t uc_testcases[] = {
    /* Normal */
!   { "255",  "%hhu", 255 },
!   { "0xff", "%hhx", 255 },
!   { "0xFF", "%hhX", 255 },
!   { "377",  "%hho", 255 },
  
    /* Truncation */
!   { "256",     "%hhu",   0 },
!   { "65535",   "%hhu", 255 },
!   { "65536",   "%hhu",   0 },
!   { "0x100",   "%hhx",   0 },
!   { "0xffff",  "%hhx", 255 },
!   { "0x10000", "%hhx",   0 },
!   { "0x100",   "%hhX",   0 },
!   { "0xFFFF",  "%hhX", 255 },
!   { "0x10000", "%hhX",   0 },
!   { "400",     "%hho",   0 },
!   { "177777",  "%hho", 255 },
!   { "2000",    "%hho",   0 },
! 
!   /* Terminator */
!   { NULL, NULL, 0 }
! };
! 
! intmax_testcase_t im_testcases[] = {
!   /* Normal */
!   { "9223372036854775807",   "%ju", INTMAX_MAX },
!   { "9223372036854775807",   "%jd", INTMAX_MAX },
!   { "9223372036854775807",   "%ji", INTMAX_MAX },
!   { "0x7fffffffffffffff",    "%jx", INTMAX_MAX },
!   { "0X7FFFFFFFFFFFFFFF",    "%jX", INTMAX_MAX },
!   { "777777777777777777777", "%jo", INTMAX_MAX },
! 
!   /* Truncation */
!   { "18446744073709551615",   "%jd", -1 },
!   { "18446744073709551615",   "%ji", -1 },
!   { "0xffffffffffffffff",     "%jx", -1 },
!   { "0XFFFFFFFFFFFFFFFF",     "%jX", -1 },
!   { "1777777777777777777777", "%jo", -1 },
! 
!   /* Terminator */
!   { NULL, NULL, 0 }
! };
! 
! uintmax_testcase_t um_testcases[] = {
!   /* Normal */
!   { "18446744073709551615",   "%ju", UINTMAX_MAX },
!   { "0xffffffffffffffff",     "%jx", UINTMAX_MAX },
!   { "0XFFFFFFFFFFFFFFFF",     "%jX", UINTMAX_MAX },
!   { "1777777777777777777777", "%jo", UINTMAX_MAX },
! 
!   /* Terminator */
!   { NULL, NULL, 0 }
! };
! 
! ptrdiff_testcase_t pd_testcases[] = {
!   /* Normal */
!   { "2147483647",  "%tu", INT_MAX },
!   { "2147483647",  "%td", INT_MAX },
!   { "2147483647",  "%ti", INT_MAX },
!   { "0x7fffffff",  "%tx", INT_MAX },
!   { "0X7FFFFFFF",  "%tx", INT_MAX },
!   { "17777777777", "%to", INT_MAX },
! 
!   /* Truncation */
!   { "4294967295",  "%td", -1 },
!   { "4294967295",  "%ti", -1 },
!   { "0xffffffff",  "%tx", -1 },
!   { "0XFFFFFFFF",  "%tX", -1 },
!   { "37777777777", "%to", -1 },
! 
!   /* Terminator */
!   { NULL, NULL, 0 }
! };
! 
! size_testcase_t sz_testcases[] = {
!   { "2147483647",  "%zu", SIZE_MAX },
!   { "2147483647",  "%zd", SIZE_MAX },
!   { "2147483647",  "%zi", SIZE_MAX },
!   { "0x7fffffff",  "%zx", SIZE_MAX },
!   { "0X7FFFFFFF",  "%zx", SIZE_MAX },
!   { "17777777777", "%zo", SIZE_MAX },
! 
!   /* Truncation */
!   { "4294967295",  "%zd", -1 },
!   { "4294967295",  "%zi", -1 },
!   { "0xffffffff",  "%zx", -1 },
!   { "0XFFFFFFFF",  "%zX", -1 },
!   { "37777777777", "%zo", -1 },
  
    /* Terminator */
    { NULL, NULL, 0 }
*************** fail (const int testnum,
*** 61,70 ****
        const char *input,
        const char *fmt,
        const char *reason,
!       const long code)
  {
    fprintf(stderr,
! 	  "FAIL: Test %d: %s %s: %s: %ld\n",
  	  testnum, input, fmt, reason, code);
    exit(EXIT_FAILURE);
  }
--- 177,186 ----
        const char *input,
        const char *fmt,
        const char *reason,
!       const long long code)
  {
    fprintf(stderr,
! 	  "FAIL: Test %d: %s %s: %s: %lld\n",
  	  testnum, input, fmt, reason, code);
    exit(EXIT_FAILURE);
  }
*************** fail (const int testnum,
*** 72,114 ****
  int
  main (void)
  {
!   signed char   s_res;
!   unsigned char u_res;
    int           testnum = 0;
    int           ret;
    int           i;
  
!   /* Signed testcases */
!   for (i = 0; s_testcases[i].str != NULL; i++) {
      testnum++;
!     s_res = 0;
  
!     ret = sscanf(s_testcases[i].str, s_testcases[i].fmt, &s_res);
      if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, s_testcases[i].str, s_testcases[i].fmt,
  	   "sscanf failed", ret);
      }
  
!     if (s_testcases[i].res != s_res) {
!       fail(testnum, s_testcases[i].str, s_testcases[i].fmt,
! 	   "unexpected result", s_res);
      }
    }
  
!   /* Unsigned testcases */
!   for (i = 0; u_testcases[i].str != NULL; i++) {
      testnum++;
!     u_res = 0;
  
!     ret = sscanf(u_testcases[i].str, u_testcases[i].fmt, &u_res);
      if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, u_testcases[i].str, u_testcases[i].fmt,
  	   "sscanf failed", ret);
      }
  
!     if (u_testcases[i].res != u_res) {
!       fail(testnum, u_testcases[i].str, u_testcases[i].fmt,
! 	   "unexpected result", u_res);
      }
    }
  
--- 188,284 ----
  int
  main (void)
  {
!   signed char   sc_res;
!   unsigned char uc_res;
!   intmax_t      im_res;
!   uintmax_t     um_res;
!   ptrdiff_t     pd_res;
    int           testnum = 0;
    int           ret;
    int           i;
  
!   /* Signed char testcases */
!   for (i = 0; sc_testcases[i].str != NULL; i++) {
!     testnum++;
!     sc_res = 0;
! 
!     ret = sscanf(sc_testcases[i].str, sc_testcases[i].fmt, &sc_res);
!     if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, sc_testcases[i].str, sc_testcases[i].fmt,
! 	   "sscanf failed", ret);
!     }
! 
!     if (sc_testcases[i].res != sc_res) {
!       fail(testnum, sc_testcases[i].str, sc_testcases[i].fmt,
! 	   "unexpected result", sc_res);
!     }
!   }
! 
!   /* Unsigned char testcases */
!   for (i = 0; uc_testcases[i].str != NULL; i++) {
!     testnum++;
!     uc_res = 0;
! 
!     ret = sscanf(uc_testcases[i].str, uc_testcases[i].fmt, &uc_res);
!     if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, uc_testcases[i].str, uc_testcases[i].fmt,
! 	   "sscanf failed", ret);
!     }
! 
!     if (uc_testcases[i].res != uc_res) {
!       fail(testnum, uc_testcases[i].str, uc_testcases[i].fmt,
! 	   "unexpected result", uc_res);
!     }
!   }
! 
!   /* intmax_t testcases */
!   for (i = 0; im_testcases[i].str != NULL; i++) {
!     testnum++;
!     im_res = 0;
! 
!     ret = sscanf(im_testcases[i].str, im_testcases[i].fmt, &im_res);
!     if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, im_testcases[i].str, im_testcases[i].fmt,
! 	   "sscanf failed", ret);
!     }
! 
!     if (im_testcases[i].res != im_res) {
!       fail(testnum, im_testcases[i].str, im_testcases[i].fmt,
! 	   "unexpected result", im_res);
!     }
!   }
! 
!   /* uintmax_t testcases */
!   for (i = 0; um_testcases[i].str != NULL; i++) {
      testnum++;
!     um_res = 0;
  
!     ret = sscanf(um_testcases[i].str, um_testcases[i].fmt, &um_res);
      if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, um_testcases[i].str, um_testcases[i].fmt,
  	   "sscanf failed", ret);
      }
  
!     if (um_testcases[i].res != um_res) {
!       fail(testnum, um_testcases[i].str, um_testcases[i].fmt,
! 	   "unexpected result", um_res);
      }
    }
  
!   /* ptrdiff_t testcases */
!   for (i = 0; pd_testcases[i].str != NULL; i++) {
      testnum++;
!     pd_res = 0;
  
!     ret = sscanf(pd_testcases[i].str, pd_testcases[i].fmt, &pd_res);
      if ((ret == EOF) || (ret < 1)) {
!       fail(testnum, pd_testcases[i].str, pd_testcases[i].fmt,
  	   "sscanf failed", ret);
      }
  
!     if (pd_testcases[i].res != pd_res) {
!       fail(testnum, pd_testcases[i].str, pd_testcases[i].fmt,
! 	   "unexpected result", pd_res);
      }
    }
  

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019