summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-01-24 08:23:33 +0000
committerRoland McGrath <roland@gnu.org>1996-01-24 08:23:33 +0000
commita66067befed6a453b75a2a0caac2c50d3a6e9cfb (patch)
tree38e6d6330653a7349cca5ab6541b7164a368e68f
parent0793d3483ae525d659ea13cfd0563e6ea9a0c9ce (diff)
* stdio-common/Makefile (tests): Add scanf[1-9].
* stdio-common/scanf[1-9].c: New files. Bug tests from hjl. Wed Jan 24 03:22:07 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu> * stdio-common/Makefile (tests): Add scanf[1-9]. * stdio-common/scanf[1-9].c: New files. Bug tests from hjl.
-rw-r--r--ChangeLog5
-rw-r--r--stdio-common/Makefile3
-rw-r--r--stdio-common/scanf1.c15
-rw-r--r--stdio-common/scanf2.c24
-rw-r--r--stdio-common/scanf3.c30
-rw-r--r--stdio-common/scanf4.c30
-rw-r--r--stdio-common/scanf5.c20
-rw-r--r--stdio-common/scanf6.c15
-rw-r--r--stdio-common/scanf7.c22
-rw-r--r--stdio-common/scanf8.c15
-rw-r--r--stdio-common/scanf9.c23
11 files changed, 201 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 291b2bf400..0c5af3ed83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jan 24 03:22:07 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
+
+ * stdio-common/Makefile (tests): Add scanf[1-9].
+ * stdio-common/scanf[1-9].c: New files. Bug tests from hjl.
+
Wed Jan 24 04:18:36 1996 Paul Eggert <eggert@twinsun.com>
* strftime.c (strftime):
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 96a2731b35..deb6f92214 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -40,7 +40,8 @@ tests := tst-printf tstscanf test_rdwr test-popen tstgetln test-fseek \
temptest tst-fileno test-fwrite \
xbug errnobug \
bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 \
- tfformat tiformat tstdiomisc
+ tfformat tiformat tstdiomisc \
+ scanf1 scanf2 scanf3 scanf4 scanf5 scanf6 scanf7 scanf8 scanf9
include ../Rules
diff --git a/stdio-common/scanf1.c b/stdio-common/scanf1.c
new file mode 100644
index 0000000000..4a5be880a4
--- /dev/null
+++ b/stdio-common/scanf1.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main()
+{
+ int i,n,r;
+
+ n = i = r = -1;
+ r = sscanf("1234:567", "%d%n", &i, &n);
+ printf("%d %d %d\n", r, n, i);
+ if (r != 1 || i != 1234 || n != 4)
+ abort ();
+ return 0;
+}
diff --git a/stdio-common/scanf2.c b/stdio-common/scanf2.c
new file mode 100644
index 0000000000..06c97c669a
--- /dev/null
+++ b/stdio-common/scanf2.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+main()
+{
+ int point, x, y;
+
+ point = x = y = -1;
+ sscanf("0x10 10", "%x %x", &x, &y);
+ printf("%d %d\n", x, y);
+ if (x != 0x10 || y != 0x10)
+ abort ();
+ point = x = y = -1;
+ sscanf("P012349876", "P%1d%4d%4d", &point, &x, &y);
+ printf("%d %d %d\n", point, x, y);
+ if (point != 0 || x != 1234 || y != 9876)
+ abort ();
+ point = x = y = -1;
+ sscanf("P112349876", "P%1d%4d%4d", &point, &x, &y);
+ printf("%d %d %d\n", point, x, y);
+ if (point != 1 || x != 1234 || y != 9876)
+ abort ();
+ return 0;
+}
diff --git a/stdio-common/scanf3.c b/stdio-common/scanf3.c
new file mode 100644
index 0000000000..1a77522482
--- /dev/null
+++ b/stdio-common/scanf3.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int arc, char *argv)
+{
+ int n, res;
+ unsigned int val;
+ char *s;
+
+ s = "111";
+
+ val = n = -1;
+ res = sscanf(s, "%u %n", &val, &n);
+ printf("Result of sscanf = %d\n", res);
+ printf("Scanned format %%u = %u\n", val);
+ printf("Possibly scanned format %%n = %d\n", n);
+ if (n != 3 || val != 111 || res != 1)
+ abort ();
+
+ val = n = -1;
+ res = sscanf(s, "%u%n", &val, &n);
+ printf("Result of sscanf = %d\n", res);
+ printf("Scanned format %%u = %u\n", val);
+ printf("Possibly scanned format %%n = %d\n", n);
+ if (n != 3 || val != 111 || res != 1)
+ abort ();
+
+ return 0;
+ return 0;
+}
diff --git a/stdio-common/scanf4.c b/stdio-common/scanf4.c
new file mode 100644
index 0000000000..b624b69d98
--- /dev/null
+++ b/stdio-common/scanf4.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+int main(int arc, char *argv)
+{
+ int n, res;
+ unsigned int val;
+
+ FILE *fp = fopen ("/dev/null", "r");
+
+ val = 0;
+ res = fscanf(fp, "%n", &val);
+
+ printf("Result of fscanf %%n = %d\n", res);
+ printf("Scanned format = %d\n", val);
+
+ res = fscanf(fp, "");
+ printf("Result of fscanf \"\" = %d\n", res);
+ if (res != 0)
+ abort ();
+
+ res = fscanf(fp, "BLURB");
+ printf("Result of fscanf \"BLURB\" = %d\n", res);
+ if (res >= 0)
+ abort ();
+
+ fclose (fp);
+
+ return 0;
+ return 0;
+}
diff --git a/stdio-common/scanf5.c b/stdio-common/scanf5.c
new file mode 100644
index 0000000000..b52e853344
--- /dev/null
+++ b/stdio-common/scanf5.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+int
+main()
+{
+ int a, b;
+
+ a = b = -1;
+ sscanf ("12ab", "%dab%n", &a, &b);
+ printf ("%d, %d\n", a, b);
+ if (a != 12 || b != 4)
+ abort ();
+
+ a = b = -1;
+ sscanf ("12ab100", "%dab%n100", &a, &b);
+ printf ("%d, %d\n", a, b);
+ if (a != 12 || b != 4)
+ abort ();
+ return 0;
+}
diff --git a/stdio-common/scanf6.c b/stdio-common/scanf6.c
new file mode 100644
index 0000000000..36055aa82e
--- /dev/null
+++ b/stdio-common/scanf6.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+main ()
+{
+ int n = -1;
+ char c = '!';
+ int ret;
+
+ ret = sscanf ("0x", "%i%c", &n, &c);
+ printf ("ret: %d, n: %d, c: %c\n", ret, n, c);
+ if (ret != 2 || n != 0 || c != 'x')
+ abort ();
+ return 0;
+}
diff --git a/stdio-common/scanf7.c b/stdio-common/scanf7.c
new file mode 100644
index 0000000000..386dac4d06
--- /dev/null
+++ b/stdio-common/scanf7.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+main ()
+{
+ long long int n;
+ int ret;
+
+ n = -1;
+ ret = sscanf ("1000", "%lld", &n);
+ printf ("%%lld: ret: %d, n: %Ld, c: %c\n", ret, n);
+ if (ret != 1 || n != 1000L)
+ abort ();
+
+ n = -2;
+ ret = sscanf ("1000", "%llld", &n);
+ printf ("%%llld: ret: %d, n: %Ld\n", ret, n);
+ if (ret != 0 || n >= 0L)
+ abort ();
+
+ return 0;
+}
diff --git a/stdio-common/scanf8.c b/stdio-common/scanf8.c
new file mode 100644
index 0000000000..316f45df01
--- /dev/null
+++ b/stdio-common/scanf8.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+main ()
+{
+ int ret;
+ char buf [1024] = "Ooops";
+
+ ret = sscanf ("static char Term_bits[] = {", "static char %s = {", buf);
+ printf ("ret: %d, name: %s\n", ret, buf);
+ if (ret != 1 || strcmp (buf, "Term_bits[]") != 0)
+ abort ();
+ return 0;
+}
diff --git a/stdio-common/scanf9.c b/stdio-common/scanf9.c
new file mode 100644
index 0000000000..52bff08e18
--- /dev/null
+++ b/stdio-common/scanf9.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char *argv[]) {
+ int matches;
+ char str[10];
+
+ str[0] = '\0';
+ matches = -9;
+ matches = sscanf("x ]", "%[^] ]", str);
+ printf("Matches = %d, string str = \"%s\".\n", matches, str);
+ printf("str should be \"x\".\n");
+ if (strcmp (str, "x")) abort ();
+ str[0] = '\0';
+ matches = -9;
+ matches = sscanf(" ] x", "%[] ]", str);
+ printf("Matches = %d, string str = \"%s\".\n", matches, str);
+ printf("str should be \" ] \".\n");
+ if (strcmp (str, " ] ")) abort ();
+ exit(0);
+ return 0;
+}