[Commit] nickle file.5c, NONE, 1.1 Makefile.am, 1.36, 1.37 builtin.5c, 1.3, 1.4 printf.5c, 1.6, 1.7 scanf.5c, 1.16, 1.17

Bart Massey commit at keithp.com
Sun Oct 12 23:48:59 PDT 2003


Committed by: bart

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv2611

Modified Files:
	Makefile.am builtin.5c printf.5c scanf.5c 
Added Files:
	file.5c 
Log Message:
Cleaned up File namespace substantially.
In particular, added file.5c to hold non printf/scanf File code.



--- NEW FILE: file.5c ---
(This appears to be a binary file; contents omitted.)

Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/nickle/Makefile.am,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- Makefile.am	21 Jul 2003 22:22:10 -0000	1.36
+++ Makefile.am	13 Oct 2003 05:48:57 -0000	1.37
@@ -6,8 +6,10 @@
 
 SUBDIRS = builtin bench test
 
-NICKLEFILES = builtin.5c math.5c scanf.5c mutex.5c arc4.5c prng.5c command.5c abort.5c \
-        printf.5c history.5c ctype.5c string.5c socket.5c
+NICKLEFILES = builtin.5c math.5c scanf.5c mutex.5c \
+	arc4.5c prng.5c command.5c abort.5c \
+        printf.5c history.5c ctype.5c string.5c socket.5c \
+	file.5c
 EXAMPLES = examples/circle.5c examples/comb.5c examples/kaiser.5c \
 	examples/miller-rabin.5c examples/numbers.5c examples/prime.5c \
 	examples/qbrating.5c examples/roman.5c examples/rsa-demo.5c \

Index: builtin.5c
===================================================================
RCS file: /local/src/CVS/nickle/builtin.5c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- builtin.5c	11 Jun 2003 05:01:55 -0000	1.3
+++ builtin.5c	13 Oct 2003 05:48:57 -0000	1.4
@@ -79,16 +79,20 @@
 # Load the prerequisites for the extra commands.
 library "string.5c";
 library "ctype.5c";
+library "file.5c";
 library "printf.5c";
 library "history.5c";
+
 # Now load the extra commands.
 library "command.5c";
+
 # Note that some libraries extend namespaces, and
 # thus aren't autoload/autoimport candidates.
 library "math.5c";
 import Math;
 library "scanf.5c";
 library "socket.5c"
+
 # Now autoload/autoimport the bonus stuff
 autoimport Abort;
 autoload Mutex;

Index: printf.5c
===================================================================
RCS file: /local/src/CVS/nickle/printf.5c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- printf.5c	17 Jun 2003 03:53:14 -0000	1.6
+++ printf.5c	13 Oct 2003 05:48:57 -0000	1.7
@@ -6,11 +6,6 @@
  */
 
 extend namespace File {
-    /*
-     * Include existing public File members
-     */
-    public import File;
-    
     int default_output_precision = -1;
     int infinite_output_precision = -2;
 
@@ -203,11 +198,6 @@
 	vfprintf (stdout, format, args);
     }
 
-    public void printf (string format, poly args...)
-    {
-	vprintf (format, args);
-    }
-    
     public string vsprintf (string format, poly[*] args)
     {
 	file	f = File::string_write ();
@@ -215,17 +205,19 @@
 	return File::string_string (f);
     }
 
-    public string sprintf (string format, poly args...)
-    {
-	return vsprintf (format, args);
-    }
+    public namespace PrintfGlobals {
 
-    public void putchar (int c)
-    {
-	putc (c, stdout);
+	public void printf (string format, poly args...)
+	{
+	    vprintf (format, args);
+	}
+
+	public string sprintf (string format, poly args...)
+	{
+	    return vsprintf (format, args);
+	}
     }
+
+    public import PrintfGlobals;
 }
-    
-void (string format, poly args...) printf = File::printf;
-string (string format, poly args...) sprintf = File::sprintf;
-void (int c) putchar = File::putchar;
+public import File::PrintfGlobals;

Index: scanf.5c
===================================================================
RCS file: /local/src/CVS/nickle/scanf.5c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- scanf.5c	11 Jun 2003 05:01:55 -0000	1.16
+++ scanf.5c	13 Oct 2003 05:48:57 -0000	1.17
@@ -2,28 +2,14 @@
  * Scanf code.  Extend File namespace with reading code
  */
 extend namespace File {
-    /*
-     * vfscanf
-     */
     public int vfscanf (file f, string format, (*poly)[*] args)
     {
-	bool iswhite (int c)
-	{
-	    switch (c) {
-	    case ' ':
-	    case '\t':
-	    case '\n':
-		return true;
-	    }
-	    return false;
-	}
-
 	/* Skip whitespace */
 	void whitespace ()
 	{
 	    int c;
 
-	    while (iswhite (c = File::getc (f)))
+	    while (Ctype::isspace (c = File::getc (f)))
 		;
 	    File::ungetc (c, f);
 	}
@@ -116,7 +102,7 @@
 
 	    whitespace();
 	    s = "";
-	    while (!iswhite (c = File::getc(f)) && !File::end(f))
+	    while (Ctype::isprint (c = File::getc(f)) && !File::end(f))
 		s = s + String::new(c);
 	    File::ungetc (c, f);
 	    return s;
@@ -195,55 +181,18 @@
         return n;
     }
 
-    public string fgets (file f)
+    public int scanf (string format, *poly args...)
     {
-	string	s;
-	int	c;
-
-	s = "";
-	for (;;)
-	{
-	    c = getc (f);
-	    switch (c) {
-	    case '\n':
-	    case -1:
-		return s;
-	    default:
-		s = s + String::new (c);
-	    }
-	}
+	return File::vfscanf (stdin, format, args);
     }
 
-    public namespace FileGlobals {
-
-	public int scanf (string format, *poly args...)
-	{
-	    return File::vfscanf (stdin, format, args);
-	}
-
+    public namespace ScanfGlobals {
 	public int vscanf (string format, (*poly)[*] args)
 	{
 	    return File::vfscanf (stdin, format, args);
-	}    
-
-	public string gets ()
-	{
-	    return File::fgets (stdin);
 	}
-
-	public int getchar ()
-	{
-	    return File::getc (stdin);
-	}
-
-	public void ungetchar (int ch)
-	{
-	    File::ungetc (ch, stdin);
-	}
-
     }
 
-    public import FileGlobals;
+    public import ScanfGlobals;
 }
-
-import File::FileGlobals;
+import File::ScanfGlobals;




More information about the Commit mailing list