/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include #include #include #include #include //#include "common/textconsole.h" #ifdef isdigit #undef isdigit #endif #define isdigit(c) ((c) >= '0' && (c) <= '9') #define TEST 1 // // simple sscanf replacement to match scummvm usage patterns // extern double strtod__(const char *start, char **end); inline void skipArg(const char **in, const char *fmt) { printf("before skip args in = %s and format = %s\n", *in, fmt); while (*fmt != '%') { fmt++; // should skip one char but don't } (*in)++; printf("skipped input string: %s and format: %s\n", *in, fmt); } extern "C" int simple_sscanf(const char *input, const char *format, ...) { va_list ap; int result = 0; const char *next = input; va_start(ap, format); while (*format) { if (*format == '%') { format++; int max = 0; while (isdigit(*format)) { max = (max * 10) + (*format - '0'); format++; } bool err = false; switch (*format++) { case '*': // while (*format != '%') { // format++;} // *(next++); skipArg(&next, format); printf("after skipArg next = %s and format = %s\n", next, format); break; default: printf("Unknown format specifier: \t%s \n", format); err = true; break; } if (err) { break; } else { result++; } } else if (*format++ != *next++) { // match input break; } } va_end(ap); return result; } #if 1 //defined(TEST_SSCANF) int main(int argc, char *argv[]) { char tt[5] = {0}; printf("\nStart test skipping arg\n"); printf("\nCurrent args num: %d\t and arg =", simple_sscanf("abcd", "%*c%c", &tt[0])); printf("%c\n", tt[0]); printf("this is normal sscanf result:"); printf("\nCurrent args num: %d\t and arg =", sscanf("abcd", "%*c%c", &tt[0])); printf("%c\n", tt[0]); return 0; } #endif