コード例 #1
0
/* Parse a command line buffer into arguments */
static int
ParseCommandLine(char *cmdline, char **argv)
{
    char *bufp;
    char *lastp = NULL;
    int argc, last_argc;

    argc = last_argc = 0;
    for (bufp = cmdline; *bufp;) {
        /* Skip leading whitespace */
        while (SDL_isspace(*bufp)) {
            ++bufp;
        }
        /* Skip over argument */
        if (*bufp == '"') {
            ++bufp;
            if (*bufp) {
                if (argv) {
                    argv[argc] = bufp;
                }
                ++argc;
            }
            /* Skip over word */
            lastp = bufp;
            while (*bufp && (*bufp != '"' || *lastp == '\\')) {
                lastp = bufp;
                ++bufp;
            }
        } else {
            if (*bufp) {
                if (argv) {
                    argv[argc] = bufp;
                }
                ++argc;
            }
            /* Skip over word */
            while (*bufp && !SDL_isspace(*bufp)) {
                ++bufp;
            }
        }
        if (*bufp) {
            if (argv) {
                *bufp = '\0';
            }
            ++bufp;
        }

        /* Strip out \ from \" sequences */
        if (argv && last_argc != argc) {
            UnEscapeQuotes(argv[last_argc]);
        }
        last_argc = argc;
    }
    if (argv) {
        argv[argc] = NULL;
    }
    return (argc);
}
コード例 #2
0
ファイル: IMG_pnm.c プロジェクト: AlanApter/steamlink-sdk
/* read a non-negative integer from the source. return -1 upon error */
static int ReadNumber(SDL_RWops *src)
{
    int number;
    unsigned char ch;

    /* Initialize return value */
    number = 0;

    /* Skip leading whitespace */
    do {
        if ( ! SDL_RWread(src, &ch, 1, 1) ) {
            return(0);
        }
        /* Eat comments as whitespace */
        if ( ch == '#' ) {  /* Comment is '#' to end of line */
            do {
                if ( ! SDL_RWread(src, &ch, 1, 1) ) {
                    return -1;
                }
            } while ( (ch != '\r') && (ch != '\n') );
        }
    } while ( SDL_isspace(ch) );

    /* Add up the number */
    do {
        number *= 10;
        number += ch-'0';

        if ( !SDL_RWread(src, &ch, 1, 1) ) {
            return -1;
        }
    } while ( SDL_isdigit(ch) );

    return(number);
}
コード例 #3
0
int SDL_sscanf(const char *text, const char *fmt, ...)
{
    va_list ap;
    int retval = 0;

    va_start(ap, fmt);
    while ( *fmt ) {
        if ( *fmt == ' ' ) {
            while ( SDL_isspace((unsigned char) *text) ) {
                ++text;
            }
            ++fmt;
            continue;
        }
        if ( *fmt == '%' ) {
            SDL_bool done = SDL_FALSE;
            long count = 0;
            int radix = 10;
            enum {
                DO_SHORT,
                DO_INT,
                DO_LONG,
                DO_LONGLONG
            } inttype = DO_INT;
            SDL_bool suppress = SDL_FALSE;

            ++fmt;
            if ( *fmt == '%' ) {
                if ( *text == '%' ) {
                    ++text;
                    ++fmt;
                    continue;
                }
                break;
            }
            if ( *fmt == '*' ) {
                suppress = SDL_TRUE;
                ++fmt;
            }
            fmt += SDL_ScanLong(fmt, 10, &count);

            if ( *fmt == 'c' ) {
                if ( ! count ) {
                    count = 1;
                }
                if ( suppress ) {
                    while ( count-- ) {
                        ++text;
                    }
                } else {
                    char *valuep = va_arg(ap, char*);
                    while ( count-- ) {
                        *valuep++ = *text++;
                    }
                    ++retval;
                }
                continue;
            }

            while ( SDL_isspace((unsigned char) *text) ) {
                ++text;
            }

            /* FIXME: implement more of the format specifiers */
            while (!done) {
                switch(*fmt) {
                    case '*':
                        suppress = SDL_TRUE;
                        break;
                    case 'h':
                        if ( inttype > DO_SHORT ) {
                            ++inttype;
                        }
                        break;
                    case 'l':
                        if ( inttype < DO_LONGLONG ) {
                            ++inttype;
                        }
                        break;
                    case 'I':
                        if ( SDL_strncmp(fmt, "I64", 3) == 0 ) {
                            fmt += 2;
                            inttype = DO_LONGLONG;
                        }
                        break;
                    case 'i':
                        {
                            int index = 0;
                            if ( text[index] == '-' ) {
                                ++index;
                            }
                            if ( text[index] == '0' ) {
                                if ( SDL_tolower((unsigned char) text[index+1]) == 'x' ) {
                                    radix = 16;
                                } else {
                                    radix = 8;
                                }
                            }
                        }
                        /* Fall through to %d handling */
                    case 'd':
#ifdef SDL_HAS_64BIT_TYPE
                        if ( inttype == DO_LONGLONG ) {
                            Sint64 value;
                            text += SDL_ScanLongLong(text, radix, &value);
                            if ( ! suppress ) {
                                Sint64 *valuep = va_arg(ap, Sint64*);
                                *valuep = value;
                                ++retval;
                            }
                        }
                        else
#endif /* SDL_HAS_64BIT_TYPE */
                        {
                            long value;
                            text += SDL_ScanLong(text, radix, &value);
                            if ( ! suppress ) {
                                switch (inttype) {
                                    case DO_SHORT:
                                        { short* valuep = va_arg(ap, short*);
                                            *valuep = (short)value;
                                        }
                                        break;
                                    case DO_INT:
                                        { int* valuep = va_arg(ap, int*);
                                            *valuep = (int)value;
                                        }
                                        break;
                                    case DO_LONG:
                                        { long* valuep = va_arg(ap, long*);
                                            *valuep = value;
                                        }
                                        break;
                                    case DO_LONGLONG:
                                        /* Handled above */
                                        break;
                                }
                                ++retval;
                            }
                        }
                        done = SDL_TRUE;
                        break;
                    case 'o':
                        if ( radix == 10 ) {
                            radix = 8;
                        }
                        /* Fall through to unsigned handling */
                    case 'x':
                    case 'X':
                        if ( radix == 10 ) {
                            radix = 16;
                        }
                        /* Fall through to unsigned handling */
                    case 'u':
#ifdef SDL_HAS_64BIT_TYPE
                        if ( inttype == DO_LONGLONG ) {
                            Uint64 value;
                            text += SDL_ScanUnsignedLongLong(text, radix, &value);
                            if ( ! suppress ) {
                                Uint64 *valuep = va_arg(ap, Uint64*);
                                *valuep = value;
                                ++retval;
                            }