Beispiel #1
0
void Chooser::AddCommands(text begin, text label)
// ----------------------------------------------------------------------------
//   Add chooser commands from the symbols table
// ----------------------------------------------------------------------------
{
    // Add all the commands that begin with the prefix in the current context
    XL::name_set names, infix, prefix, postfix;
    XL::MAIN->ListNames(begin, names, infix, prefix, postfix);
    
    // Loop over all rewrites that match
    uint first = begin.length();
    for (XL::name_set::iterator n = names.begin(); n != names.end(); n++)
    {
        text symname = *n;
        text caption = "";
        kstring data = symname.data();
        uint c, maxc = symname.length();
        for (c = first; c < maxc; c = Utf8Next(data, c))
        {
            wchar_t wc;
            char wcbuf[MB_LEN_MAX];
            if (mbtowc(&wc, data + c, maxc - c) > 0)
            {
                if (wc == '_')
                    wc = ' ';
                else if (c == first && label.length() > 0)
                    wc = towupper(wc);
            }
            int sz = wctomb(wcbuf, wc);
            if (sz > 0)
                caption.insert(caption.end(), wcbuf, wcbuf + sz);
        }
        
        // Create a closure from the resulting commands to remember context
        Tree *command = new XL::Name(symname);
        caption = widget->xlTr(NULL, caption);
        AddItem(label + caption, command);
    }
}
Beispiel #2
0
Datei: unit.cpp Projekt: c3d/elfe
bool CompiledUnit::ValidCName(Tree *tree, text &label)
// ----------------------------------------------------------------------------
//   Check if the name is valid for C
// ----------------------------------------------------------------------------
{
    uint len = 0;

    if (Name *name = tree->AsName())
    {
        label = name->value;
        len = label.length();
    }
    else if (Text *text = tree->AsText())
    {
        label = text->value;
        len = label.length();
    }

    if (len == 0)
    {
        Ooops("No valid C name in $1", tree);
        return false;
    }

    // We will NOT call functions beginning with _ (internal functions)
    for (uint i = 0; i < len; i++)
    {
        char c = label[i];
        if (!isalpha(c) && c != '_' && !(i && isdigit(c)))
        {
            Ooops("C name $1 contains invalid characters", tree);
            return false;
        }
    }
    return true;
}