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

📄 clilib.c

📁 sttesttool.rar的标准testtool.rar驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
            ParseTable_p[ParseTableIndex] = (STTST_Parse_t *)memory_allocate(sttst_InitParams.CPUPartition_p, AllocSize);
        }
    }
    return(ParseTable_p[ParseTableIndex]);
}

/*******************************************************************************
Name        : FreeParseTableSlot
Description : free memory slot for print
Parameters  :
Assumptions :
Limitations :
Returns     : nothing
*******************************************************************************/
static void FreeParseTableSlot(void)
{
    if (ParseTableIndex >= PARSE_TABLE_INIT_SIZE )
    {
        memory_deallocate(sttst_InitParams.CPUPartition_p, ParseTable_p[ParseTableIndex]);
    }
    ParseTableIndex--;
}

/* ========================================================================
   indirect print method using variable arg format to invoke formatting
=========================================================================== */
void sttst_Print(const char* const format, ...)
{
    va_list list;
    char *pt, *StringBuffer;

    StringBuffer = NewStringTableSlot(MAX_STTBX_LEN);

    va_start(list, format);
    vsprintf(StringBuffer, format, list);
    va_end(list);
    /*io_write(StringBuffer); */
    STTBX_Print((StringBuffer));
#ifndef UNHOSTED
    if ((LogFile != NULL) && LogOutput)
    {
        if ( LogResults )
        {
            pt = strstr( StringBuffer, "result");
            if ( pt==NULL )
            {
                pt = strstr( StringBuffer, "RESULT");
            }
            if ( pt==NULL )
            {
                pt = strstr( StringBuffer, "Result");
            }
            if ( pt!=NULL )
            {
                fprintf(LogFile, "%s", StringBuffer);
            }
        }
        else
        {
            fprintf(LogFile, "%s", StringBuffer);
        }
    }
#endif
    FreeStringTableSlot();
}

/* ========================================================================
   display memory free blocks
=========================================================================== */
#ifndef ST_OSLINUX /* Linux Porting */

static void partition_heap_infos(partition_t *l, size_t *MaxBlockSize, BOOL DisplayEnabled)
{
#ifdef ST_OS20
#define partition_free_head   u.partition_heap.partition_heap_free_head
#define __next partition_heap_block_next
#define __blocksize partition_heap_block_blocksize

    partition_heap_block_t *i;
    partition_heap_block_t *m;
    size_t size;

    i =  (partition_heap_block_t *) ((partition_heap_block_t *) l->partition_free_head->__next);
    m =  (partition_heap_block_t *) l->partition_free_head;

    *MaxBlockSize = 0;
    TotalFreeSize = 0;

    while(i != m)
    {
        if (DisplayEnabled)
        {
            sttst_Print("Block %x: %d \tNext block : %x %x\n",(int)i,(int)i->__blocksize,(int)i->__next,(int)m);
        }
        size = (size_t)i->__blocksize;
        TotalFreeSize += size;
        if (size > *MaxBlockSize)
        {
            *MaxBlockSize = size;
        }
        i = i->__next;
    }
    sttst_Print("Free blocks size sum %d\n",(int)TotalFreeSize);
#else
    sttst_Print("Free blocks size sum : info not available on OS21/ST40\n");
#endif /* ST40_OS21 */

}

#endif /* ST_OSLINUX */

/* ========================================================================
   indirect statistics about memory usage (FQ Jan 99)
=========================================================================== */
static void cli_statistics(BOOL DisplayEnabled)
{
/*    void *mem_pt; previous code*/
#ifndef ST_OSLINUX
    size_t mem_size;
#endif
    symtab_t* sym_pt;
    int  loop_cpt=0;
    int  mac_cpt=0;
    int  com_cpt=0;
    int  str_cpt=0;
    int  nb_cpt=0;
    char *StringBuffer;

    /* Get free memory */
/* previous code */
/*    mem_size=800500;*/
/*    do*/
/*    {*/
/*        mem_size -= 500;*/
/*        mem_pt = memory_allocate((partition_t *)sttst_InitParams.CPUPartition_p, (size_t)mem_size);*/
/*    }*/
/*    while ( mem_pt == NULL );*/
/*    memory_deallocate( sttst_InitParams.CPUPartition_p, mem_pt);*/

#ifndef ST_OSLINUX
    /* new code for free memory calculation CL Aug 2001 */

    partition_heap_infos(sttst_InitParams.CPUPartition_p, &mem_size, DisplayEnabled);
    /* end of new code for free memory calculation CL Aug 2001 */
#endif

    /* Symbols counting */
    while ( loop_cpt < SymbolCount )
    {
        sym_pt = Symtab_p[loop_cpt];
        if ( sym_pt->type == CLI_MAC_SYMBOL ) mac_cpt++;
        if ( sym_pt->type == CLI_COM_SYMBOL ) com_cpt++;
        if ( sym_pt->type == CLI_STR_SYMBOL ) str_cpt++;
        if ( sym_pt->type == CLI_INT_SYMBOL ) nb_cpt++;
        if ( sym_pt->type == CLI_FLT_SYMBOL ) nb_cpt++;
        loop_cpt++;
    }

    StringBuffer = NewStringTableSlot(CLI_MAX_LINE_LENGTH);

    /* Memory informations */
#ifdef ST_OSLINUX
    sprintf(StringBuffer, "max free memory block size  = N/A on Linux\n");
#else
    sprintf(StringBuffer, "max free memory block size  = %d bytes\n",mem_size);
#endif
    STTBX_Print((StringBuffer));
    sprintf( StringBuffer,
        "declared symbols  = %d (%d commands + %d macros + %d strings + %d numbers)\n",
        (com_cpt+mac_cpt+str_cpt+nb_cpt), com_cpt, mac_cpt, str_cpt, nb_cpt);
    STTBX_Print((StringBuffer));
    sprintf(StringBuffer, "allocated symbols = %d / %d \n",SymbolCount, MaxSymbolCount);
    STTBX_Print((StringBuffer));
    sprintf(StringBuffer,
        "Buffer management : max simultaneous reached...\n\t...String = %d\n\t...Token  = %d\n\t...Parse  = %d\n",
        MaxSimultaneousStringReached, MaxSimultaneousTokenReached, MaxSimultaneousParseReached);
    STTBX_Print((StringBuffer));
    FreeStringTableSlot();
}

/* ========================================================================
   statistics about memory usage
=========================================================================== */
static BOOL cli_stat(STTST_Parse_t *Parse_p, char *result_sym_p)
{
    BOOL IsBad;
    BOOL DisplayEnabled;
    S32 Enable;

    TotalFreeSize =0;
    IsBad = STTST_GetInteger(Parse_p, FALSE, &Enable);
    if (IsBad)
    {
        STTST_TagCurrentLine(Parse_p, "expected base address");
    }
    else
    {
        DisplayEnabled = Enable;
        cli_statistics(DisplayEnabled);
        IsBad = STTST_AssignInteger(result_sym_p, TotalFreeSize, FALSE);
    }
    return(IsBad);
}

/* ========================================================================
   indirect 'scanf' function from uart or console
=========================================================================== */
/***int scan (const char * format, void* Variable)
{
    int i;
    char ip_char[CLI_MAX_LINE_LENGTH];

    for ( i=0; i<CLI_MAX_LINE_LENGTH; i++)
    {
        ip_char[i] = 0;
    }
    read_input(ip_char, "?> ");
    sscanf(ip_char, format, Variable);
    return (1);
}***/
/* ========================================================================
 tests the character for equality with a set of delimiter characters
=========================================================================== */
static BOOL is_delim(char character, const char *const delim_p)
{
    S16 delim_count = 0;

    while ((delim_p[delim_count] != '\0') &&
          (character != delim_p[delim_count]))
    {
        delim_count++;
    }
    return ((character == delim_p[delim_count]) ||
           (character == CLI_NL_CHAR) ||
           (character == CLI_CR_CHAR) ||
           (character == '\0'));
}
/* ========================================================================
 tests strings for equality, but not in an exact way. Trailing space is OK
 Comparison will succeed if the tested string matches the definition string
 but is shorter (i.e is an abbreviation). It will not match if the tested
 string is longer or less than minlen chars are present in the tested
 string. Comparison is also case insensitive.
=========================================================================== */
static BOOL is_matched(const char *const tested_p, const char *const definition_p, S16 minlen)
{
  BOOL match = TRUE;
  S16 cnt = 0;

    while (((tested_p[cnt] == definition_p[cnt]) ||
        ((tested_p[cnt] & 0xdf) == (definition_p[cnt] & 0xdf)) ) &&
        (tested_p[cnt] != '\0')                                   &&
        (definition_p[cnt] != '\0'))
    {
        cnt++;
    }

    if ((STTST_RunMode & STTST_NO_ABBREVIATION_MODE) != 0)
    {
        if ( tested_p[cnt] != '\0' || definition_p[cnt] != '\0' )
        {
            /* string lengths are different : it does not match */
            match = FALSE;
        }
    }
    else
    {
    /* if we found the end of the tested string before we found a mis-match
     then strings are matched. If the definition string is shorter than
     minumum length requirements, then match can succeed. */
        if ((tested_p[cnt] != '\0') ||
            ((cnt < minlen) && (definition_p[cnt] != '\0')))
        {
            match = FALSE;
        }
    }
    return(match);
}

/* ========================================================================
   tests a token against a set of control redirection primitives
   and returns an identifier for the construct found
=========================================================================== */
static BOOL is_control(const char * const token_p, S16 *construct_p)
{
    BOOL found = TRUE;

    if (is_matched(token_p, "DEFINE", 2))
    {
        *construct_p = CLI_DEFINE_CONST;
    }
    else if (is_matched(token_p, "IF", 2))
    {
        *construct_p = CLI_IF_CONST;
    }
    else if (is_matched(token_p, "ELIF", 2))
    {
        *construct_p = CLI_ELIF_CONST;
    }
    else if (is_matched(token_p, "ELSE", 2))
    {
        *construct_p = CLI_ELSE_CONST;
    }
    else if (is_matched(token_p, "WHILE", 2))
    {
        *construct_p = CLI_WHILE_CONST;
    }
    else if (is_matched(token_p, "FOR", 2))
    {
        *construct_p = CLI_FOR_CONST;
    }
    else
    {
        found = FALSE;
    }
    return(found);
}
/* ========================================================================
   returns, if possible, an integer value. The default base
   is used for conversion in the absence of other information.
   If a '#' character preceeds the number hex base is assumed
   If a '$' is used as a prefix, then a binary representation is assumed
   If an 'o' or 'O' character is used then octal is assumed.
   Any sign makes the number a decimal representation
=========================================================================== */
static S32 conv_int(const char * token_p, S16 default_base, BOOL *IsValid_p)
{
    S32  value;
    S16  base, cnt, i;
    U8   NbDigit = 0;
    BOOL negative;

    negative = FALSE;
    *IsValid_p = TRUE;
    switch (token_p[0])
    {
        case '#' : /* keep old syntax for backward compatibility */
        case 'h' : /* new syntax (Feb. 2000) */
        case 'H' : /* new syntax (Feb. 2000) */
            base = 16;
            token_p++;
            break;
        case '$' : /* keep old syntax for backward compatibility */
        case 'b' : /* new syntax (Feb. 2000) */
        case 'B' : /* new syntax (Feb. 2000) */
            base = 2;
            token_p++;
            break;
        case 'o' :
        case 'O' :
            base = 8;
            token_p++;
            break;
        case '-' :
            negative = TRUE;
            /* no break */
        case '+' :
            base = 10;
            token_p++;
            break;
        default :
            base = default_base;
            break;
    }
    /* convert by comparison to ordered string array of numeric characters */
    value = 0;
    cnt = 0;
    while((token_p[cnt] != '\0') && (*IsValid_p))

⌨️ 快捷键说明

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