www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/05/29/15:55:35

Date: Wed, 29 May 2002 20:49:26 +0100
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.2.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: Patches for building with gcc 3.1 - *scanf() chunk
Message-Id: <E17D9M9-0000RD-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Please find below a patch for building with gcc 3.1. This converts
_doscan*() to using va_list. This seems to work fine with programs
in the test suite.

The example usage of _doscan() in doscan.txh needs rewriting.
Until I've done that, this patch is just for other people
to look at and/or test.

The patch may apply with some fuzz in stdio.h, because I've chopped
out a couple of declarations for fseeko(), ftello() from
my CVS check-out.

Bye, Rich =]

Index: src/libc/ansi/stdio/doscan.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doscan.c,v
retrieving revision 1.10
diff -p -u -3 -r1.10 doscan.c
--- src/libc/ansi/stdio/doscan.c	2001/06/09 20:33:22	1.10
+++ src/libc/ansi/stdio/doscan.c	2002/05/26 17:27:25
@@ -1,7 +1,9 @@
+/* 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 */
 /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -18,7 +20,7 @@
 #define	INT	0
 #define	FLOAT	1
 
-static int _innum(int **ptr, int type, int len, int size, FILE *iop, 
+static int _innum(int *ptr, int type, int len, int size, FILE *iop, 
                   int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), 
                   int *eofptr);
 static int _instr(char *ptr, int type, int len, FILE *iop, 
@@ -40,18 +42,18 @@ static char _sctab[256] = {
 static int nchars = 0;
 
 int 
-_doscan(FILE *iop, const char *fmt, void **argp)
+_doscan(FILE *iop, const char *fmt, va_list argp)
 {
   return(_doscan_low(iop, fgetc, ungetc, fmt, argp));
 }
 
 int
 _doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
-            const char *fmt, void **argp)
+            const char *fmt, va_list argp)
 {
   register int ch;
   int nmatch, len, ch1;
-  int **ptr, fileended, size;
+  int *ptr, fileended, size;
 
   nchars = 0;
   nmatch = 0;
@@ -64,7 +66,7 @@ _doscan_low(FILE *iop, int (*scan_getc)(
       goto def;
     ptr = 0;
     if (ch != '*')
-      ptr = (int **)argp++;
+      ptr = va_arg(argp, int *);
     else
       ch = *fmt++;
     len = 0;
@@ -122,13 +124,13 @@ _doscan_low(FILE *iop, int (*scan_getc)(
       if (!ptr)
         break;
       if (size==LONG)
-	**(long**)ptr = nchars;
+	*(long*)ptr = nchars;
       else if (size==SHORT)
-        **(short**)ptr = nchars;
+        *(short*)ptr = nchars;
       else if (size==LONGDOUBLE)
-        **(long long**)ptr = nchars;
+        *(long long*)ptr = nchars;
       else
-        **(int**)ptr = nchars;
+        *(int*)ptr = nchars;
       break;
     }
       
@@ -176,7 +178,7 @@ _doscan_low(FILE *iop, int (*scan_getc)(
 }
 
 static int
-_innum(int **ptr, int type, int len, int size, FILE *iop,
+_innum(int *ptr, int type, int len, int size, FILE *iop,
        int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr)
 {
   register char *np;
@@ -187,7 +189,7 @@ _innum(int **ptr, int type, int len, int
   int cpos;
 
   if (type=='c' || type=='s' || type=='[')
-    return(_instr(ptr? *(char **)ptr: (char *)NULL, type, len,
+    return(_instr(ptr? (char *)ptr: (char *)NULL, type, len,
 		  iop, scan_getc, scan_ungetc, eofptr));
   lcval = 0;
   ndigit = 0;
@@ -281,31 +283,31 @@ _innum(int **ptr, int type, int len, int
 
   case (FLOAT<<4) | SHORT:
   case (FLOAT<<4) | REGULAR:
-    **(float **)ptr = atof(numbuf);
+    *(float *)ptr = atof(numbuf);
     break;
 
   case (FLOAT<<4) | LONG:
-    **(double **)ptr = atof(numbuf);
+    *(double *)ptr = atof(numbuf);
     break;
 
   case (FLOAT<<4) | LONGDOUBLE:
-    **(long double **)ptr = _atold(numbuf);
+    *(long double *)ptr = _atold(numbuf);
     break;
 
   case (INT<<4) | SHORT:
-    **(short **)ptr = (short)lcval;
+    *(short *)ptr = (short)lcval;
     break;
 
   case (INT<<4) | REGULAR:
-    **(int **)ptr = (int)lcval;
+    *(int *)ptr = (int)lcval;
     break;
 
   case (INT<<4) | LONG:
-    **(long **)ptr = (long)lcval;
+    *(long *)ptr = (long)lcval;
     break;
 
   case (INT<<4) | LONGDOUBLE:
-    **(long long **)ptr = lcval;
+    *(long long *)ptr = lcval;
     break;
   }
   return(1);
Index: src/libc/ansi/stdio/doscan.txh
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doscan.txh,v
retrieving revision 1.3
diff -p -u -3 -r1.3 doscan.txh
--- src/libc/ansi/stdio/doscan.txh	1999/06/20 08:53:39	1.3
+++ src/libc/ansi/stdio/doscan.txh	2002/05/26 17:27:25
@@ -2,9 +2,10 @@
 @subheading Syntax
 
 @example
+#include <stdarg.h>
 #include <stdio.h>
 
-int _doscan(FILE *file, const char *format, void **ptrs_to_args);
+int _doscan(FILE *file, const char *format, va_list argp);
 @end example
 
 @subheading Description
@@ -27,6 +28,9 @@ error. 
 @subheading Example
 
 @example
+TODO: This example is bogus now!
+TODO: Rewrite this example!
+
 int x, y;
 int *args[2];
 args[0] = &x;
Index: include/stdio.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/stdio.h,v
retrieving revision 1.6
diff -p -u -3 -r1.6 stdio.h
--- include/stdio.h	2001/06/19 19:10:15	1.6
+++ include/stdio.h	2002/05/26 17:27:31
@@ -135,8 +142,8 @@ extern FILE __dj_stdprn, __dj_stdaux;
 
 void	_djstat_describe_lossage(FILE *_to_where);
 int	_doprnt(const char *_fmt, va_list _args, FILE *_f);
-int	_doscan(FILE *_f, const char *_fmt, void **_argp);
-int	_doscan_low(FILE *, int (*)(FILE *_get), int (*_unget)(int, FILE *), const char *_fmt, void **_argp);
+int	_doscan(FILE *_f, const char *_fmt, va_list _args);
+int	_doscan_low(FILE *, int (*)(FILE *_get), int (*_unget)(int, FILE *), const char *_fmt, va_list _args);
 int	fpurge(FILE *_f);
 int	getw(FILE *_f);
 char *	mktemp(char *_template);
Index: src/libc/ansi/stdio/sprintf.c
Index: src/libc/pc_hw/co80/conio.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/pc_hw/co80/conio.c,v
retrieving revision 1.7
diff -p -u -3 -r1.7 conio.c
--- src/libc/pc_hw/co80/conio.c	2001/06/30 13:14:27	1.7
+++ src/libc/pc_hw/co80/conio.c	2002/05/26 17:28:20
@@ -1,3 +1,4 @@
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
@@ -722,8 +723,14 @@ cgets(char *string)
 int
 cscanf(const char *fmt, ...)
 {
-  return(_doscan_low(NULL, _scan_getche, _scan_ungetch, 
-		     fmt, (void **) unconst( ((&fmt)+1), char ** )));
+  va_list args;
+  int ret;
+
+  va_start(args, fmt);
+  ret = _doscan_low(NULL, _scan_getche, _scan_ungetch, fmt, args);
+  va_end(args);
+
+  return(ret);
 }
 
 int

- Raw text -


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