Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Console.inl
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_CONSOLE_INL)
#define TGS_COMMON_CONSOLE_INL
#pragma once


/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions and Private Data */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgCN_Find_Command_In_Hash --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_STg2_CN_Command_Common tgCN_Find_Command_In_Hash( CPC_TgCHAR pszCmd, C_TgUINTXX uiHash )
{
    P_STg2_CN_Command_Common            psIter_Cmd;
    TgSINT32                            iHash_Index;

    iHash_Index = uiHash % KTgCN_MAX_COMMAND_HASH_SET;
    TgERROR_INDEX( iHash_Index, g_apsCN_Command_Hash_Set );

    psIter_Cmd = g_apsCN_Command_Hash_Set[iHash_Index];
    while (nullptr != psIter_Cmd)
    {
        if (0 == tgSZ_Compare_NoCase( pszCmd, psIter_Cmd->m_pzName ))
        {
            return (psIter_Cmd);
        };

        psIter_Cmd = psIter_Cmd->m_psNext_Hash;
    };

    return (nullptr);
}


/* ---- tgCN_Calc_Command_Lexical_Index --------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgSINT32 tgCN_Calc_Command_Lexical_Index( CPC_TgCHAR pszCmd )
{
    TgSINT32                            iLexical_Index;

    iLexical_Index = tgCM_CLP_S32( 1 + (TgSINT32)tgCHAR_To_Lower( pszCmd[0] ) - 'a', 0, 27 );
    iLexical_Index *= 29;
    if (0 == pszCmd[1])
    {
        iLexical_Index += 28;
    }
    else
    {
        iLexical_Index += tgCM_CLP_S32( 1 + (TgSINT32)tgCHAR_To_Lower( pszCmd[1] ) - 'a', 0, 27 );
    };
    iLexical_Index *= 29;
    if ((0 == pszCmd[1]) || (0 == pszCmd[2]))
    {
        iLexical_Index += 28;
    }
    else
    {
        iLexical_Index += tgCM_CLP_S32( 1 + (TgSINT32)tgCHAR_To_Lower( pszCmd[2] ) - 'a', 0, 27 );
    };

    return (iLexical_Index);
}


/* ---- tgCN_Is_Command_Function ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCN_Is_Command_Function( CPCU_STg2_CN_Command_Common psCmd )
{
    return (psCmd->m_uiType >= ETgCN_COMMAND__FCN_START && psCmd->m_uiType < ETgCN_COMMAND__FCN_END ? TgTRUE : TgFALSE);
}


/* ---- tgCN_Is_Command_Variable ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCN_Is_Command_Variable( CPCU_STg2_CN_Command_Common psCmd )
{
    return (psCmd->m_uiType >= ETgCN_COMMAND__VAR_START && psCmd->m_uiType < ETgCN_COMMAND__VAR_END ? TgTRUE : TgFALSE);
}


/* ====================================================================================================================================================================== */
#endif