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

📄 clilib.c

📁 sttesttool.rar的标准testtool.rar驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
    {
        i = 0;
        while((HexaChars[i] != (char)toupper(token_p[cnt])) && (i < base))
        {
            i++;
        }
        if (token_p[cnt]!=' ') /* skip space (test added for DDTS 6642 - 23 March 01) */
        {
            NbDigit++;
            switch (base)
            {
                case 2 :
                    if ( (i >= 2) || ( NbDigit > 32))
                    {
                        *IsValid_p = FALSE;
                    }
                    break;
                case 8 :
                    if ( (i >= 8) || ( NbDigit > 11))
                    {
                        *IsValid_p = FALSE;
                    }
                    break;
                case 10 :
                    if ( (i >= 10) || (((U32)value >= 429496729) && (i > 5)))
                    {
                        *IsValid_p = FALSE;
                    }
                    break;
                case 16 :
                    if ( (i >= 16) || ( NbDigit > 8))
                    {
                        *IsValid_p = FALSE;
                    }
                    break;
                default :
                    *IsValid_p = FALSE;
                    break;
            }
            if (*IsValid_p)
            {
                value = (value * base) + i;
            }
            else
            {
                value = 0;
            }
        }
        cnt++;
    }
    if (negative && (*IsValid_p))
    {
        value = -value;
    }
    return(value);
}
/* ========================================================================
   returns, if possible, an floating point value. Scanf seems not to
   detect any errors in its input format, and so we have to do a check
   on number validity prior to calling it. This is rather complicated
   to try and reject float expressions, but validate pure float numbers
=========================================================================== */
static BOOL conv_flt(const char * const token_p, double *value_p)
{
    S16  cnt = 0;
    BOOL IsBad = FALSE;
    BOOL seen_dp = FALSE;

    while((token_p[cnt] != '\0') && !IsBad)
    {
        /* check for silly characters */
        if (    (token_p[cnt] != '-') && (token_p[cnt] != '+')
             && (token_p[cnt] != '.')
             && (token_p[cnt] != 'E') && (token_p[cnt] != 'e')
             && ((token_p[cnt] > '9') || (token_p[cnt] < '0')))
        {
            IsBad = TRUE;
        }
        else
        {
            /* check for more than one decimal point */
            if (token_p[cnt] == '.')
            {
                if (seen_dp)
                {
                    IsBad = TRUE;
                }
                else
                {
                    seen_dp = TRUE;
                }
            }
        }
        /* check for sign after decimal point not associated with exponent */
        if (    (!IsBad)
             && (((token_p[cnt] == '+') || (token_p[cnt] == '-')) && seen_dp)
             && ((token_p[cnt-1] != 'E') && (token_p[cnt-1] != 'e')))
        {
            IsBad = TRUE;
        }
        /* check for sign before a decimal point but not at start of token */
        if (    (!IsBad)
             && (((token_p[cnt] == '+') || (token_p[cnt] == '-')) && !seen_dp)
             && (cnt > 0))
        {
            IsBad = TRUE;
        }
        cnt++;
    }
    if (!IsBad)
    {
        if (sscanf(token_p, "%lg", value_p) == 0)
        {
            IsBad = TRUE;
            *value_p = 0;
        }
    }
    return(IsBad);
}
/* ========================================================================
   looks for a symbol type/name within the table. We look from
   most recent to oldest symbol to accomodate scope.
   We also scan for the shortest defined symbol that matches
   the input token - this resolves order dependent declaration problems
=========================================================================== */
static symtab_t *look_for(const char * const token_p, S16 type)
{
    S16     cnt;
    BOOL   found = FALSE;
    symtab_t  *symbol_p;
    symtab_t  *shortest_p;
    S16     short_len;

    short_len = STTST_MAX_TOK_LEN;
    shortest_p = (symtab_t*)NULL;

    /* point to last symbol in the table */
    if (SymbolCount != 0)
    {
        cnt = 1;
        while(cnt <= SymbolCount)
        {
            symbol_p = Symtab_p[SymbolCount - cnt];
            /* protect against deleted symbols */
            if (symbol_p->name_p != NULL)
            {
                /* look for a name match of at least two characters and
                shortest matching definition of search type */
                found = ((is_matched(token_p, symbol_p->name_p, 2) &&
                         ((symbol_p->type & type) > 0)));
                if (found && (symbol_p->name_len < short_len))
                {
                    shortest_p = symbol_p;
                    short_len = symbol_p->name_len;
                }
            }
            cnt++;
        }
    }
    return(shortest_p);
}
/* ========================================================================
   displays current tokeniser string and tags the position of last token.
   An optional message is displayed
=========================================================================== */
/*void tag_current_line(STTST_Parse_t *Parse_p, char *message_p)*/
void STTST_TagCurrentLine(STTST_Parse_t *Parse_p, const char *const message_p)
{
    S16 i;
    char *StringBuffer;

    StringBuffer = NewStringTableSlot(CLI_MAX_LINE_LENGTH);

    /* current line */
    sttst_Print("%s\n", Parse_p->line_p);
    /* tag the position (FQ - Oct 99) */
    for (i=0; i<Parse_p->par_pos && i<CLI_MAX_LINE_LENGTH; i++)
    {
        StringBuffer[i] = CLI_SPACE_CHAR;
    }
    if (Parse_p->par_pos < CLI_MAX_LINE_LENGTH)
    {
        StringBuffer[Parse_p->par_pos] = '^';
    }
    if (Parse_p->par_sta < CLI_MAX_LINE_LENGTH)
    {
        StringBuffer[Parse_p->par_sta] = '^';
    }
    if (Parse_p->par_sta+1 < CLI_MAX_LINE_LENGTH)
    {
        StringBuffer[(Parse_p->par_pos) + 1] = '\0';
    }
    else
    {
        StringBuffer[CLI_MAX_LINE_LENGTH-1] = '\0';
    }
    sttst_Print("%s", StringBuffer);
    /* add message */
    sttst_Print("\n%s\n", message_p);
    FreeStringTableSlot();
}
/* ========================================================================
   included for tokeniser testing
=========================================================================== */
/***void pars_debug(STTST_Parse_t *Parse_p)
{
    STTST_TagCurrentLine(Parse_p, "debug");
    sttst_Print("Tok = \"%s\", delim = %x, toklen = %d \n",
        Parse_p->token,
        Parse_p->tok_del,
        Parse_p->tok_len);
}***/
/* ========================================================================
   start up a new environment
=========================================================================== */
static void init_pars(STTST_Parse_t *Parse_p, const char *const new_line_p)
{
    Parse_p->line_p = (char *)new_line_p;
    Parse_p->par_pos = 0;
    Parse_p->par_sta = 0;
    Parse_p->tok_del = '\0';
    Parse_p->token[0] = '\0';
    Parse_p->tok_len = 0;
}
/* ========================================================================
   implements a tokeniser with a 'soft' approach to end of line conditions
   repeated calls will eventually leave parse position at the null
   terminating the input string.
=========================================================================== */
static S16 get_tok(STTST_Parse_t *Parse_p, const char *const delim_p)
{
    S16 par_sta = Parse_p->par_pos;
    S16 par_pos = par_sta;
    S16 tok_len = 0;
    S16 quotes = 0;

    /* check that we are not already at the end of a line due to
    a previous call (or a null input) - if so return a null token
    End of line now includes finding comment character! */

    if ((Parse_p->line_p[par_pos] == '\0') ||
    (Parse_p->line_p[par_pos] == CLI_COMMENT_CHAR) )
    {
        Parse_p->token[0] = '\0';
        Parse_p->tok_del = '\0';
    }
    else
    {
        /* attempt to find start of a token, nothing special case of first call,
        incrementing past last delimiter and checking for end of line
        on the way */
        if (par_pos != 0)
        {
            par_pos++;
        }
        while (    (    (Parse_p->line_p[par_pos] == CLI_SPACE_CHAR)
                     || (Parse_p->line_p[par_pos] == CLI_TAB_CHAR))
                && (Parse_p->line_p[par_pos] != '\0')
                && (Parse_p->line_p[par_pos] != CLI_COMMENT_CHAR))
        {
            par_pos++;
        }

        /* if we find a delimiter before anything else, return a null token
        also deal with special case of a comment character ending a line */
        if (is_delim(Parse_p->line_p[par_pos], delim_p) ||
            (Parse_p->line_p[par_pos] == CLI_COMMENT_CHAR))
        {
            Parse_p->token[0] = '\0';
            if (Parse_p->line_p[par_pos] != CLI_COMMENT_CHAR)
            {
                Parse_p->tok_del = Parse_p->line_p[par_pos];
            }
            else
            {
                Parse_p->tok_del = '\0';
            }
        }
        else
        {
          /* copy token from line into token string
             until next delimiter found. Note that delimiters found within
             pairs of double quotes will not be considered significant. Quotes
             can be embedded within strings using '\' however. Note also that
             we have to copy the '\' escape char where it is used, it can
             be taken out when the string is evaluated */
            while((!is_delim(Parse_p->line_p[par_pos], delim_p) || (quotes > 0)) &&
                (tok_len < (S16)strlen(Parse_p->line_p)) && (Parse_p->line_p[par_pos] != '\0'))
            {
                Parse_p->token[tok_len] = Parse_p->line_p[par_pos++];
                if ((Parse_p->token[tok_len] =='"') && (tok_len == 0))
                {
                    quotes++;
                }
                if ((Parse_p->token[tok_len] =='"') && (tok_len > 0))
                {
                    if (Parse_p->token[tok_len-1] != CLI_ESCAPE_CHAR)
                    {
                        if (quotes > 0)
                        {
                            quotes--;
                        }
                        else
                        {
                            quotes++;
                        }
                    }
                }
                tok_len++;
            }
            /* if we ran out of token space before copy ended, move up to delimiter */
            while (!is_delim(Parse_p->line_p[par_pos], delim_p))
            {
                par_pos++;
            }
            /* tidy up the rest of the data */
            Parse_p->tok_del = Parse_p->line_p[par_pos];
            Parse_p->token[tok_len] = '\0';
        }
    }
    Parse_p->par_pos = par_pos;
    Parse_p->par_sta = par_sta;
    Parse_p->tok_len = tok_len;
    return(tok_len);
}
/* ========================================================================
   sets up a simple symbol table as an array of elements, ordered by
   declaration, of different types. SymbolCount will index the next free slot
=========================================================================== */
static void init_sym_table(S16 elements)
{
    partition_t *mem_pt;

    SymbolCount = 0;
    MaxSymbolCount = elements; /* based on mimimum size required */
    mem_pt = memory_allocate( sttst_InitParams.CPUPartition_p,
                (size_t)(sizeof(symtab_t*) * MaxSymbolCount) );
    Symtab_p = (symtab_t**) mem_pt;

    if (Symtab_p == NULL)
    {
        STTBX_Print(("symbol table initialization : not enough memory !\n" ));
        MaxSymbolCount = 0;
    }
}

/* ========================================================================
   allocate memory for a buffer where lines to be displayed can be prepared
=========================================================================== */
static void InitDisplayBuffer(void)
{
    DisplayBuffer_p = memory_allocate( sttst_InitParams.CPUPartition_p, DISPLAY_BUFFER_SIZE);
    if (DisplayBuffer_p == NULL)
    {
        STTBX_Print(("Display buffer initialization : not enough memory !\n" ));
    }
}


/* ========================================================================
   allocate memory for line table
=========================================================================== */
static void InitStringTable(void)
{
    U8 i;

    StringTableIndex = -1;
    MaxSimultaneousStringReached = 0;

⌨️ 快捷键说明

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