wm: teppich

ref: 8d3dbfa11753101bdfdc9fcce43ed5c0756cf0a5
dir: /libc/scanf.c/

View raw version
#include <u.h>
#include <libc.h>

#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 != '\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;
}