wm: teppich

Download patch

ref: 723dcdf945237c6fa70e4f964cfce71d963ec90f
parent: a3d9c8a50f2bd94224725e329b1d2482a7b0718d
author: mkf <mkf@cloud9p.org>
date: Thu Nov 23 10:58:17 EST 2023

fix '☺' bug, fmt scanf.

--- a/libc/scanf.c
+++ b/libc/scanf.c
@@ -1,58 +1,64 @@
-
 #include <u.h>
 #include <libc.h>
 
-int scanf (char * str, ...)
+#include <vga.h>
+#include <ps2.h>
+
+int scanf(char *str, ...)
 {
-    va_list vl;
-    int i = 0, j=0, ret = 0;
-    char buff[100] = {0}, tmp[20], c;
-    char *out_loc;
-    while(c != '\0') 
-    {
-        c = ps2_getc();
- 	    buff[i] = c;
- 	    i++;
- 	}
- 	va_start( vl, str );
- 	i = 0;
- 	while (str && str[i])
- 	{
- 	    if (str[i] == '%') 
- 	    {
- 	       i++;
- 	       switch (str[i]) 
- 	       {
- 	           case 'c': 
- 	           {
-	 	           *(char *)va_arg( vl, char* ) = buff[j];
-	 	           j++;
-	 	           ret ++;
-	 	           break;
- 	           }
- 	           case 'd': 
- 	           {
-	 	           *(int *)va_arg( vl, int* ) =strtol(&buff[j], &out_loc, 10);
-	 	           j+=out_loc -&buff[j];
-	 	           ret++;
-	 	           break;
- 	            }
- 	            case 'x': 
- 	            {
-	 	           *(int *)va_arg( vl, int* ) =strtol(&buff[j], &out_loc, 16);
-	 	           j+=out_loc -&buff[j];
-	 	           ret++;
-	 	           break;
- 	            }
- 	        }
- 	    } 
- 	    else 
- 	    {
- 	        buff[j] =str[i];
-            j++;
-        }
-        i++;
-    }
-    va_end(vl);
-    return ret;
+	va_list vl;
+	int i = 0, j=0, ret = 0;
+	char buff[100] = {0}, tmp[20], c;
+	char *out_loc;
+
+
+	while(c != '\r') 
+	{
+		c = ps2_getc();
+		vga_putc(c);
+		buff[i] = c;
+		i++;
+	}
+	
+	va_start( vl, str );
+	i = 0;
+	while (str && str[i])
+	{
+		if(str[i] == '%') 
+		{
+			i++;
+			switch (str[i]) 
+			{
+				case 'c': 
+				{
+					*(char*)va_arg(vl, char*) = buff[j];
+					j++;
+					ret++;
+					break;
+				}
+				case 'd': 
+				{
+					*(int*)va_arg( vl, int* ) = strtol(&buff[j], &out_loc, 10);
+					j+=out_loc -&buff[j];
+					ret++;
+					break;
+				}
+				case 'x': 
+				{
+					*(int *)va_arg( vl, int* ) = strtol(&buff[j], &out_loc, 16);
+					j += out_loc -&buff[j];
+					ret++;
+					break;
+				}
+			}
+		} 
+		else 
+		{
+			buff[j] =str[i];
+            		j++;
+        	}
+		i++;
+	}
+	va_end(vl);
+	return ret;
 }