On Tue, Feb 29, 2000 at 06:18:20PM +0100, Lars Gullik Bj&resh;nnes wrote:
> Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:
> I have changed some of that in layout.C now. Since we usually parse
> layout files pretty seldom I have changed the lyxlex tables to be
> dynamic.
> 
> I have also changed to of the code that annoyed Dekel the most. and
> thus now some of the code has run-time checking instead of compile
> time...
> 
>       Lgb

I can't understand what you've written above.
I'm still not satisfied with the (new) code.
Consider the code of LyXTextClass::readOutputType:

| void LyXTextClass::readOutputType(LyXLex & lexrc)
| {
|         keyword_item outputTypeTags[] = {
|                 { "docbook", DOCBOOK },
|                 { "latex", LATEX },
|                 { "linuxdoc", LINUXDOC },
|                 { "literate", LITERATE }
| };

Why isn't outputTypeTags declared static?

|         pushpophelper pph(lexrc, outputTypeTags, LITERATE);

It is not a good idea to use the tag LITERATE because someone might change
enum OutputType by adding a new tag after LITERATE, but he may forget to 
change the line above.

A better idea is to use sizeof(outputTypeTags)/sizeof(keyword_item),
(another option is to add a line "OutputType_LAST = LITERATE" to 
enum OutputType, and then use OutputType_LAST instead of LITERATE)

|         int le = lexrc.lex();
|         switch(le) {
|         case LyXLex::LEX_UNDEF:
|                 lexrc.printError("Unknown output type `$$Token'");
|                 return;
|         case LATEX:
|         case LINUXDOC:
|         case DOCBOOK:
|         case LITERATE:
|                 outputType_ = static_cast<OutputType>(le);
|                 break;
|         default:
|                 lyxerr << "Unhandled value " << le
|                        << " in LyXTextClass::readOutputType." << endl;
| 
|                 break;
|         }

The code here isn't very pretty.
The value of 'le' can be either an error code from LyXLex::lex() namely
either LyXLex::LEX_UNDEF, LEX_FEOF or LEX_DATA,
and otherwise, it is either LATEX,LINUXDOC,DOCBOOK or LITERATE
so the code can be as follows:

        switch(le) {
        case LyXLex::LEX_UNDEF:
                lexrc.printError("Unknown output type `$$Token'");
                return;
        case LyXLex::LEX_FEOF:
        case LyXLex::LEX_DATA:
                lyxerr << "Unhandled value " << le
                       << " in LyXTextClass::readOutputType." << endl;
        default:
                 outputType_ = static_cast<OutputType>(le);
        }

Reply via email to