Esempio n. 1
0
ULONG CTobCompiler::GetSizeFromType(CHAR Type)
{
    ULONG Length;
    switch(CHAR_UPPER(Type))
    {
        case 'B': Length = 1;  break;
        case 'S': Length = 2;  break;
        case 'T': Length = 3;  break;
        case 'Q':
        case 'I': Length = 4;  break;
        case 'F': Length = -4; break;
        case 'D': Length = -8; break;
        default:  Length = -1;  break;
    }

    return Length;
}
Esempio n. 2
0
VOID ACLStr::MakeUpper(VOID)
{
	CHAR_UPPER(_string, _length);
}	//	MakeUpper
Esempio n. 3
0
CTobCompiler::EToken CTobCompiler::GetString(CByteArray& bin)
{
    CByteArray temp;
    int c, d, e;
    for(;;)
    {
        if ((c = fgetc(m_fsrc)) < 0) break;
        if (c == '\n') ++m_line;
        else if (ms_tokentable[c] == 3)
        {
            m_err.Format("found invalid char 0x%02X in src file at %p", c, ftell(m_fsrc)-1);
            return ERR_NORMAL;
        }
        else if (c < ' ') continue;
        else if (c == '\'' || c == '"')
        {
            if ((d = fgetc(m_fsrc)) > 0)
            {
                if (d == ':')
                {
                    if ((d = fgetc(m_fsrc)) < 0) break;
                    e = GetSizeFromType(d);
                    if (e == -1)
                    {
                        m_err.Format("unknown type '%c' after ':'", d);
                        return ERR_NORMAL;
                    }

                    d = temp.GetSize();
                    for(int i = 0; i < e; ++i)
                        bin.Add(((BYTE*)&d)[i]);
                }
                else if (fseek(m_fsrc, -1, SEEK_CUR))
                {
                    m_err.Format("can not seek src file at %p", ftell(m_fsrc));
                    return ERR_SEVERE;
                }
            }
            bin.Append(temp);
            if (c == '"')
                bin.Add(0);

            if (m_Option.bIgnoreCase)
                strlwr((LPSTR)bin.GetData());
            return SYM_STR;
        }
        else if (c == '\\')
        {
            if ((c = fgetc(m_fsrc)) < 0) break;
            switch(CHAR_UPPER(c))
            {
                case 'N': c = '\n';   break;
                case 'R': c = '\r';   break;
                case 'T': c = '\t';   break;
                case '0': c = '\0';   break;
                case '1': c = '\x01'; break;
                case '2': c = '\x02'; break;
                case '3': c = '\x03'; break;
                case '4': c = '\x04'; break;
                case '5': c = '\x05'; break;
                case '6': c = '\x06'; break;
                case '7': c = '\x07'; break;
                case '8': c = '\x08'; break;
                case '9': c = '\x09'; break;
                case 'A': c = '\x0a'; break;
                case 'B': c = '\x0b'; break;
                case 'C': c = '\x0c'; break;
                case 'D': c = '\x0d'; break;
                case 'E': c = '\x0e'; break;
                case 'F': c = '\x0f'; break;
                case 'X':
                {
                    if ((c = fgetc(m_fsrc)) < 0) goto end_;
                    BYTE b0 = ms_hextable[c];
                    if (b0 == 16)
                    {
                        m_err.Format("bad hex char 0x%02X after '\\x'", b0);
                        return ERR_NORMAL;
                    }
                    if ((c = fgetc(m_fsrc)) < 0) goto end_;
                    BYTE b1 = ms_hextable[c];
                    if (b1 == 16)
                    {
                        m_err.Format("bad hex char 0x%02X after '\\x'", b1);
                        return ERR_NORMAL;
                    }
                    temp.Add((BYTE)((b0<<4) + b1));
                }
            }
        }
        if (c >= 0x81)
        {
            if ((d = fgetc(m_fsrc)) < 0) break;
            if (d < 0x40)
            {
                if (fseek(m_fsrc, -1, SEEK_CUR))
                {
                    m_err.Format("can not seek src file at %p", ftell(m_fsrc));
                    return ERR_SEVERE;
                }
                m_err.Format("found half wide char at %p", ftell(m_fsrc)-1);
                return ERR_NORMAL;
            }
            temp.Add((BYTE)c);
            temp.Add((BYTE)d);
        }
        else
        {
            temp.Add((BYTE)c);
        }
    }
end_:
    if (!feof(m_fsrc))
        m_err.Format("can not read src file at %p", ftell(m_fsrc));
    else
        m_err = "bad string at the end of src file";
    return ERR_SEVERE;
}
Esempio n. 4
0
CTobCompiler::EToken CTobCompiler::GetNumber(CString& str)
{
    BOOL dot = FALSE, ex = FALSE, number = FALSE, hex = FALSE;
    str.Empty();
    for(;;)
    {
        int c = fgetc(m_fsrc);
        if (c == EOF)
        {
            if (!feof(m_fsrc))
            {
                m_err.Format("can not read src file at %p", ftell(m_fsrc));
                return ERR_SEVERE;
            }
            if (str.IsEmpty())
                return ERR_EOF;

            c = (BYTE)str[str.GetLength() - 1];
            if (!number || (ms_tokentable[c] != TOKEN_OTHER && !IN_RANGE('A', c, 'Z')))
            {
                m_err = "found bad number";
                return ERR_NORMAL;
            }
            return (dot || ex) ? SYM_FLOAT : SYM_INT;
        }

        c = CHAR_UPPER(c);
begin_: if (c == '.')
        {
            if (dot)
            {
                m_err = "found more '.' in number";
                return ERR_NORMAL;
            }
            if (ex)
            {
                m_err = "found '.' after 'e/E' in number";
            }
            dot = TRUE;
        }
        else if (!hex && c == 'E')
        {
            if (ex)
            {
                m_err = "found more 'e/E' in number";
            }
            c = fgetc(m_fsrc);
            if (c < 0)
            {
                if (!feof(m_fsrc))
                {
                    m_err.Format("can not read src file at %p", ftell(m_fsrc));
                    return ERR_SEVERE;
                }
                else
                {
                    m_err = "found bad number at the end of src file";
                    return ERR_NORMAL;
                }
            }
            if (c != '+' && c != '-')
                goto begin_;
        }
        else
        {
            switch(ms_tokentable[c])
            {
                case TOKEN_NOT_ID:
                    if (c > ' ' && fseek(m_fsrc, -1, SEEK_CUR))
                    {
                        m_err.Format("can not seek src file at %p", ftell(m_fsrc));
                        return ERR_SEVERE;
                    }

                    c = (BYTE)str[str.GetLength() - 1];
                    if (!number || (ms_tokentable[c] != TOKEN_OTHER && !IN_RANGE('A', c, 'Z')))
//                    if (!number || ms_tokentable[(BYTE)str[str.GetLength()-1]] != 2)
                    {
                        m_err = "found bad number";
                        return ERR_NORMAL;
                    }
                    return dot || ex ? SYM_FLOAT : SYM_INT;

                case TOKEN_ID:
                    if (!hex || !IN_RANGE('A', c, 'Z'))
                    {
                        m_err = "found bad number";
                        return ERR_NORMAL;
                    }

                case TOKEN_OTHER:
                    if (!number && !hex)
                    {
                        if (c == '0')
                        {
                            int c2 = fgetc(m_fsrc);
                            c2 = CHAR_UPPER(c2);
                            if (c2 == 'X')
                            {
                                hex = TRUE;
                                str += '0';
                                c = 'x';
                            }
                            else if (fseek(m_fsrc, -1, SEEK_CUR))
                            {
                                m_err.Format("can not seek src file at %p", ftell(m_fsrc));
                                return ERR_SEVERE;
                            }
                        }
                    }

                    number = TRUE;
                    break;

                case TOKEN_INVALID:
                    m_err.Format("found invalid char 0x%02X in src file at %p", c, ftell(m_fsrc)-1);
                    return ERR_NORMAL;
            }
        }
        str += (TCHAR)c;
    }
}