bool EXCELLON_IMAGE::Select_Tool( char*& text )
{
    int tool_id = TCodeNumber( text );

    if( tool_id >= 0 )
    {
        tool_id += FIRST_DCODE;     // Remember: dcodes are >= FIRST_DCODE
        if( tool_id > (TOOLS_MAX_COUNT - 1) )
            tool_id = TOOLS_MAX_COUNT - 1;
        m_Current_Tool = tool_id;
        D_CODE* pt_Dcode = GetDCODE( tool_id , false );
        if( pt_Dcode )
            pt_Dcode->m_InUse = true;
    }
    while( *text )
        text++;

    return tool_id >= 0;
}
bool EXCELLON_IMAGE::Select_Tool( char*& text )
{
    // Select the tool from the command line Tn, with n = 1 ... TOOLS_MAX_COUNT - 1
    // Because some drill file have an embedded TCODE definition (like T1C.008F0S0)
    // in tool selection command, if the tool is not defined in list,
    // and the definition is embedded, it will be entered in list
    char * startline = text;    // the tool id starts here.
    int tool_id = TCodeNumber( text );

    // T0 is legal, but is not a selection tool. it is a special command
    if( tool_id >= 0 )
    {
        int dcode_id = tool_id + FIRST_DCODE;     // Remember: dcodes are >= FIRST_DCODE

        if( dcode_id > (TOOLS_MAX_COUNT - 1) )
            dcode_id = TOOLS_MAX_COUNT - 1;

        m_Current_Tool = dcode_id;
        D_CODE* currDcode = GetDCODE( dcode_id , false );

        if( currDcode == NULL && tool_id > 0 )   // if the definition is embedded, enter it
        {
            text = startline;   // text starts at the beginning of the command
            readToolInformation( text );
            currDcode = GetDCODE( dcode_id , false );
        }

        if( currDcode )
            currDcode->m_InUse = true;
    }

    while( *text )
        text++;

    return tool_id >= 0;
}