⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfscanf.cxx

📁 eCos/RedBoot for勤研ARM AnywhereII(4510) 含全部源代码
💻 CXX
📖 第 1 页 / 共 3 页
字号:

        case 'u':
            c = CT_INT;
            ccfn = strtoul;
            base = 10;
            break;

        case 'X':               /* compat   XXX */
        case 'x':
            flags |= PFXOK;     /* enable 0x prefixing */
            c = CT_INT;
            ccfn = strtoul;
            base = 16;
            break;

        case 'E':               /* compat   XXX */
        case 'G':               /* compat   XXX */
/* ANSI says that E,G and X behave the same way as e,g,x */
            /* FALLTHROUGH */
        case 'e':
        case 'f':
        case 'g':
            c = CT_FLOAT;
            break;

        case 's':
            c = CT_STRING;
            break;

        case '[':
            fmt = __sccl (ccltab, fmt);
            flags |= NOSKIP;
            c = CT_CCL;
            break;

        case 'c':
            flags |= NOSKIP;
            c = CT_CHAR;
            break;

        case 'p':               /* pointer format is like hex */
            flags |= POINTER | PFXOK;
            c = CT_INT;
            ccfn = strtoul;
            base = 16;
            break;

        case 'n':
            if (flags & SUPPRESS)       /* ??? */
                continue;
            if (flags & SHORT)
            {
                sp = va_arg (ap, short *);
                *sp = nread;
            }
            else if (flags & LONG)
            {
                lp = va_arg (ap, long *);
                *lp = nread;
            }
            else
            {
                ip = va_arg (ap, int *);
                *ip = nread;
            }
            continue;

            /*
             * Disgusting backwards compatibility hacks.        XXX
             */
        case '\0':              /* compat */
            return EOF;

        default:                /* compat */
            if (isupper (c))
                flags |= LONG;
            c = CT_INT;
            ccfn = (strtoul_t)strtol;
            base = 10;
            break;
        }

        /*
         * We have a conversion that requires input.
         */
        if (BufferEmpty)
            goto input_failure;

        /*
         * Consume leading white space, except for formats that
         * suppress this.
         */
        if ((flags & NOSKIP) == 0)
        {
            while (isspace (*CURR_POS))
            {
                nread++;
                INC_CURR_POS;
                if (SPACE_LEFT == 0)
#ifndef REDHAT_NEC
                    if (REFILL)
#endif
                        goto input_failure;
            }
            /*
             * Note that there is at least one character in the
             * buffer, so conversions that do not set NOSKIP ca
             * no longer result in an input failure.
             */
        }

        /*
         * Do the conversion.
         */
        switch (c)
        {

        case CT_CHAR:
            /* scan arbitrary characters (sets NOSKIP) */
            if (width == 0)
                width = 1;
            if (flags & SUPPRESS)
            {
                size_t sum = 0;

                for (;;)
                {
                    if ((n = SPACE_LEFT) < (signed)width)
                    {
                        sum += n;
                        width -= n;
                        MOVE_CURR_POS(n-1);
                        INC_CURR_POS;
#ifndef REDHAT_NEC
                        if (REFILL)
                        {
#endif
                            if (sum == 0)
                                goto input_failure;
                            break;
#ifndef REDHAT_NEC
                        }
#endif
                    }
                    else
                    {
                        sum += width;
                        MOVE_CURR_POS(width - 1);
                        INC_CURR_POS;
                        break;
                    }
                }
                nread += sum;
            }
            else
            {
                /* Kludge city for the moment */
                char *dest = va_arg (ap, char *);
                int n = width;
                if (SPACE_LEFT == 0)
#ifndef REDHAT_NEC
                    if (REFILL)
#endif
                        goto input_failure;

                while (n && !BufferEmpty)
                {
                    *dest++ = *CURR_POS;
                    INC_CURR_POS;
                    n--;
                    nread++;
                }
                nassigned++;
            }
            break;

        case CT_CCL:
            /* scan a (nonempty) character class (sets NOSKIP) */
            if (width == 0)
                width = ~0;             /* `infinity' */
            /* take only those things in the class */
            if (flags & SUPPRESS)
            {
                n = 0;
                while (ccltab[(int)*CURR_POS])
                {
                    n++, INC_CURR_POS;
                    if (--width == 0)
                        break;
                    if (BufferEmpty)
                    {
                        if (n == 0)
                            goto input_failure;
                        break;
                    }
                }
                if (n == 0)
                    goto match_failure;
            }
            else
            {
                p0 = p = va_arg (ap, char *);
                while (ccltab[(int)*CURR_POS])
                {
                    *p++ = *CURR_POS;
                    INC_CURR_POS;
                    if (--width == 0)
                        break;
                    if (BufferEmpty)
                    {
                        if (p == p0)
                            goto input_failure;
                        break;
                    }
                }
                n = p - p0;
                if (n == 0)
                    goto match_failure;
                *p = 0;
                nassigned++;
            }
            nread += n;
            break;

        case CT_STRING:
            /* like CCL, but zero-length string OK, & no NOSKIP */
            if (width == 0)
                width = ~0;
            if (flags & SUPPRESS)
            {
                n = 0;
                while (!isspace (*CURR_POS))
                {
                    n++, INC_CURR_POS;
                    if (--width == 0)
                        break;
                    if (BufferEmpty)
                        break;
                }
                nread += n;
            }
            else
            {
                p0 = p = va_arg (ap, char *);
                while (!isspace (*CURR_POS))
                {
                    *p++ = *CURR_POS;
                    INC_CURR_POS;
                    if (--width == 0)
                        break;
                    if (BufferEmpty)
                        break;
                }
                *p = 0;
                nread += p - p0;
                nassigned++;
            }
            continue;

        case CT_INT:
            /* scan an integer as if by strtol/strtoul */
#ifdef hardway
            if (width == 0 || width > sizeof (buf) - 1)
                width = sizeof (buf) - 1;
#else
            /* size_t is unsigned, hence this optimisation */
            if (--width > sizeof (buf) - 2)
                width = sizeof (buf) - 2;
            width++;
#endif
            flags |= SIGNOK | NDIGITS | NZDIGITS;
            for (p = buf; width; width--)
            {
                c = *CURR_POS;
                /*
                 * Switch on the character; `goto ok' if we
                 * accept it as a part of number.
                 */
                switch (c)
                {
                    /*
                     * The digit 0 is always legal, but is special.
                     * For %i conversions, if no digits (zero or nonzero)
                     * have been scanned (only signs), we will have base==0
                     * In that case, we should set it to 8 and enable 0x
                     * prefixing. Also, if we have not scanned zero digits
                     * before this, do not turn off prefixing (someone else
                     * will turn it off if we have scanned any nonzero
                     * digits).
                     */
                case '0':
                    if (base == 0)
                    {
                        base = 8;
                        flags |= PFXOK;
                    }
                    if (flags & NZDIGITS)
                        flags &= ~(SIGNOK | NZDIGITS | NDIGITS);
                    else
                        flags &= ~(SIGNOK | PFXOK | NDIGITS);
                    goto ok;

                    /* 1 through 7 always legal */
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                    base = basefix[base];
                    flags &= ~(SIGNOK | PFXOK | NDIGITS);
                    goto ok;

                    /* digits 8 and 9 ok iff decimal or hex */
                case '8':
                case '9':
                    base = basefix[base];
                    if (base <= 8)
                        break;  /* not legal here */
                    flags &= ~(SIGNOK | PFXOK | NDIGITS);
                    goto ok;

                    /* letters ok iff hex */
                case 'A':
                case 'B':
                case 'C':
                case 'D':
                case 'E':
                case 'F':
                case 'a':
                case 'b':
                case 'c':
                case 'd':
                case 'e':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -