wm: teppich

Download patch

ref: 9bd2c2d1765c8a63cdaddfa1590e03a1572659f1
parent: 0db68816a181050ffee307935f9a95884d0d2f8a
author: mkf <mkf@cloud9p.org>
date: Tue Dec 5 16:24:17 EST 2023

scanf: tabs, use cons, make internal functions static

--- a/libc/scanf.c
+++ b/libc/scanf.c
@@ -1,69 +1,66 @@
 #include <u.h>
 #include <libc.h>
-
-#include <vga.h>
-#include <ps2.h>
+#include <cons.h>
 #include <mem.h>
 
-char*
+static char*
 get_char()
 {
-    int i = 0;
-    char *buff = malloc(10), c;
-    while (1 == 1)
-    {
-		c = ps2_getc();
-		vga_putc(c);
-        if (c != '\r')
-        {
-            buff[i] = c;
-            i++;
-        }
-        else break;
-    }
-    return buff; 
+	int i = 0;
+	char *buff = malloc(10), c;
+	while (1 == 1)
+	{
+		c = cons_read(defcons);
+		cons_putc(defcons, c);
+		if (c != '\r')
+		{
+			buff[i] = c;
+			i++;
+		}
+		else break;
+	}
+	return buff; 
 }
 
 int
 scanf(char *str, ...)
 {
-    va_list ap;
-    va_start(ap, str);
+	va_list ap;
+	va_start(ap, str);
 
-    int count = 0;
-    char *buffer, *temp;
+	int count = 0;
+	char *buffer, *temp;
 
-    while (*str != '\0')
-    {
-        if (*str == '%')
-        {
-            buffer = get_char();
-            str++;
-            switch(*str)
-            {
-                case 'c':
-                    *va_arg(ap, char*) = buffer[0];
-                    count++;
-                    break;
-                case 's':
-                    *va_arg(ap, char**) = buffer;
-                    count++;
-                    break;
-                case 'd':
-                    *va_arg(ap, int*) = strtol(buffer, &temp, 10);
-                    count++;
-                    break;
-                case 'x':
-                    *va_arg(ap, int*) = strtol(buffer, &temp, 16);
-                    count++;
-                    break;
-                default:
-                    break;
-            }
-        }
-        str++;
-    }
-    va_end(ap);
-    return count;
+	while (*str != '\0')
+	{
+		if (*str == '%')
+		{
+			buffer = get_char();
+			str++;
+			switch(*str)
+			{
+				case 'c':
+					*va_arg(ap, char*) = buffer[0];
+					count++;
+					break;
+				case 's':
+					*va_arg(ap, char**) = buffer;
+					count++;
+					break;
+				case 'd':
+					*va_arg(ap, int*) = strtol(buffer, &temp, 10);
+					count++;
+					break;
+				case 'x':
+					*va_arg(ap, int*) = strtol(buffer, &temp, 16);
+					count++;
+					break;
+				default:
+					break;
+			}
+		}
+		str++;
+	}
+	va_end(ap);
+	return count;
 }
-