diff --git a/programs/develop/ktcc/trunk/libc/include/ctype.h b/programs/develop/ktcc/trunk/libc/include/ctype.h index af84cfb694..4c0362c67a 100644 --- a/programs/develop/ktcc/trunk/libc/include/ctype.h +++ b/programs/develop/ktcc/trunk/libc/include/ctype.h @@ -16,19 +16,19 @@ #define __UPPER 512 #define __XDIGIT 1024 -extern char __is[128]; +extern unsigned short __is[128]; -#define isalnum(c)(__is[c] & __ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */ -#define isalpha(c)(__is[c] & __ALPHA ) /* 'a'-'z', 'A'-'Z' */ -#define iscntrl(c)(__is[c] & __CNTRL ) /* 0-31, 127 */ -#define isdigit(c)(__is[c] & __DIGIT ) /* '0'-'9' */ -#define isgraph(c)(__is[c] & __GRAPH ) /* '!'-'~' */ -#define islower(c)(__is[c] & __LOWER ) /* 'a'-'z' */ -#define isprint(c)(__is[c] & __PRINT ) /* ' '-'~' */ -#define ispunct(c)(__is[c] & __PUNCT ) /* !alnum && !cntrl && !space */ -#define isspace(c)(__is[c] & __BLANK ) /* HT, LF, VT, FF, CR, ' ' */ -#define isupper(c)(__is[c] & __UPPER ) /* 'A'-'Z' */ -#define isxdigit(c)(__is[c] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */ +#define isalnum(c)(__is[c+1] & __ALNUM ) /* 'a'-'z', 'A'-'Z', '0'-'9' */ +#define isalpha(c)(__is[c+1] & __ALPHA ) /* 'a'-'z', 'A'-'Z' */ +#define iscntrl(c)(__is[c+1] & __CNTRL ) /* 0-31, 127 */ +#define isdigit(c)(__is[c+1] & __DIGIT ) /* '0'-'9' */ +#define isgraph(c)(__is[c+1] & __GRAPH ) /* '!'-'~' */ +#define islower(c)(__is[c+1] & __LOWER ) /* 'a'-'z' */ +#define isprint(c)(__is[c+1] & __PRINT ) /* ' '-'~' */ +#define ispunct(c)(__is[c+1] & __PUNCT ) /* !alnum && !cntrl && !space */ +#define isspace(c)(__is[c+1] & __BLANK ) /* HT, LF, VT, FF, CR, ' ' */ +#define isupper(c)(__is[c+1] & __UPPER ) /* 'A'-'Z' */ +#define isxdigit(c)(__is[c+1] & __XDIGIT) /* '0'-'9', 'a'-'f', 'A'-'F' */ #define isascii(c) (!((c)&(~0x7f))) #define toascii(c) ((c)&0x7f) diff --git a/programs/develop/ktcc/trunk/libc/include/stdio.h b/programs/develop/ktcc/trunk/libc/include/stdio.h index 2a73ec7ac0..62923dceae 100644 --- a/programs/develop/ktcc/trunk/libc/include/stdio.h +++ b/programs/develop/ktcc/trunk/libc/include/stdio.h @@ -71,5 +71,12 @@ char * gets (char * str); typedef int (*virtual_getc)(void *sp, const void *obj); typedef void (*virtual_ungetc)(void *sp, int c, const void *obj); int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc); +int vscanf ( const char * format, va_list arg ); +int scanf ( const char * format, ...); +int vsscanf ( const char * s, const char * format, va_list arg ); +int sscanf ( const char * s, const char * format, ...); +int vfscanf ( FILE * stream, const char * format, va_list arg ); + + #endif diff --git a/programs/develop/ktcc/trunk/libc/stdio/format_scan.c b/programs/develop/ktcc/trunk/libc/stdio/format_scan.c index 57134cf3e5..d1abb2d9fd 100644 --- a/programs/develop/ktcc/trunk/libc/stdio/format_scan.c +++ b/programs/develop/ktcc/trunk/libc/stdio/format_scan.c @@ -18,6 +18,8 @@ todo: #include #include #include +typedef int (*virtual_getc)(void *sp, const void *obj); +typedef void (*virtual_ungetc)(void *sp, int c, const void *obj); enum flags_t { @@ -170,7 +172,9 @@ int try_parse_int(long long *digit, int ch, const void *src, void *save, vir { base = 8; ch = vgetc(save, src); - if (ch == EOF) return EOF; + if (ch == EOF || isspace(ch)) + have_digits++; + else if (ch == 'x' || ch == 'X') { base = 16; @@ -201,6 +205,8 @@ int try_parse_int(long long *digit, int ch, const void *src, void *save, vir ch = vgetc(save, src); if (ch == EOF || isspace(ch)) break; // ok, just finish num } + else if (ch == EOF || isspace(ch)) + break; else { vungetc(save, ch, src); @@ -365,9 +371,9 @@ int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vge arg_str = va_arg(argp, char*); if (fmt1 == 0) length = 1; else length = fmt1; - for (i = 0; i < length; i++) + for (i = 0; i < length;) { - *arg_str++ = ch; + *arg_str++ = ch; i++; ch = vgetc(&save, src); if (ch == EOF) break; } diff --git a/programs/develop/ktcc/trunk/libc/stdio/fscanf.c b/programs/develop/ktcc/trunk/libc/stdio/fscanf.c index 669fef99a5..9ae0ff86f8 100644 --- a/programs/develop/ktcc/trunk/libc/stdio/fscanf.c +++ b/programs/develop/ktcc/trunk/libc/stdio/fscanf.c @@ -6,8 +6,11 @@ int virtual_getc_file(void *sp, const void *obj) // get next chat from file obj, save point is ptr to string char ptr { FILE *f = (FILE *)obj; + int ch = fgetc(f); - return fgetc(f); +//printf("getc '%c'[%d];", ch, ch); + + return ch; } void virtual_ungetc_file(void *sp, int c, const void *obj) diff --git a/programs/develop/ktcc/trunk/libc/stdio/ungetc.c b/programs/develop/ktcc/trunk/libc/stdio/ungetc.c new file mode 100644 index 0000000000..5bfe0ea7be --- /dev/null +++ b/programs/develop/ktcc/trunk/libc/stdio/ungetc.c @@ -0,0 +1,16 @@ +#include +// non standard realization - no support for virtually change char +int ungetc(int c,FILE* file) +{ + dword res; + + if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0)) return EOF; + + if (file->filepos>file->filesize || file->filepos==0) + { + return EOF; + } + file->filepos--; + + return c; +} \ No newline at end of file diff --git a/programs/develop/ktcc/trunk/libc/string/is.c b/programs/develop/ktcc/trunk/libc/string/is.c index 19265ec0d1..8abb9f0dca 100644 --- a/programs/develop/ktcc/trunk/libc/string/is.c +++ b/programs/develop/ktcc/trunk/libc/string/is.c @@ -1,5 +1,6 @@ -#include "ctype.h" -char __is[128] = { +#include +unsigned short __is[129] = { + 0, /* EOF */ 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004,