Beispiel #1
0
bool        process_tag( gtentry * ge, mac_entry * me )
{
    bool            processed;
    gaentry     *   ga;
    gavalentry  *   gaval;
    char        *   p;
    char        *   p2;
    int             rc;
    char            quote;
    char            longwork[20];
    bool            tag_end_found = false;

    processed = true;
    init_dict( &loc_dict );

    add_defaults_to_dict( ge, &loc_dict );

    /***********************************************************************/
    /*  scan input for attributes and / or tagtext                         */
    /***********************************************************************/

    p = tok_start + ge->namelen + 1;    // over tagname

    if( ge->attribs != NULL ) {     // only process attributes if they exist
        while( *p == ' ' ) {        // not yet end of tag, process attributes

            while( *p == ' ' ) {        // over WS to attribute
                p++;
            }
            if( *p == '.' ) {
                tag_end_found = true;
                break;
            }
            p2 = token_buf;
            while( is_id_char( *p ) ) {
                *p2++ = *p++;
            }
            *p2 = '\0';
            if( p2 != token_buf ) {     // ignore nullstring
                for( ga = ge->attribs; ga != NULL; ga = ga->next ) {// all attrs
                    if( !stricmp( ga->name, token_buf ) ) {
                        ga->attflags |= att_proc_seen; // attribute specified
                        if( ga->attflags & att_auto ) {
                            auto_att_err();
                            break;
                        }

                        if( *p == '=' ) {   // value follows
                            ga->attflags |= att_proc_val;

                            p++;        // over =
                            p2 = token_buf;
                            if( is_quote_char( *p ) ) {
                                quote = *p++;
                                while( *p && *p != quote ) {// quoted value
                                    *p2++ = *p++;
                                }
                                if( *p == quote ) {
                                    p++;// over ending quote
                                }
                            } else {
                                quote = '\0';
                                while( *p && (*p != ' ') && (*p != '.') ) {
                                    *p2++ = *p++;
                                }
                            }
                            *p2 = '\0';
                            if( ga->attflags & att_off ) {// attribute inactive
                                continue;
                            }
                            if( ga->attflags & att_upper ) {// uppercase option
                                strupr( token_buf );
                            }

                            scan_err = check_att_value( ga );

                        } else {// special for range set default2 if no value
                            if( ga->attflags & att_range ) {
                                for( gaval = ga->vals; gaval != NULL;
                                     gaval = gaval->next ) {
                                     if( gaval->valflags & val_range ) {
                                        break;
                                     }
                                }
                                if( gaval != NULL ) {
                                     sprintf( token_buf, "%d",
                                              gaval->a.range[3] );
                                     rc = add_symvar( &loc_dict, ga->name,
                                                      token_buf, no_subscript,
                                                      local_var );
                                }
                            }
                        }
                        break;
                    }
                }
                if( ga == NULL ) {      // attribute Not found
                    char        linestr[MAX_L_AS_STR];

                    processed = false;
                    wng_count++;
                    //***WARNING*** SC--040: 'abd' is not a valid attribute name
                    g_warn( wng_att_name, token_buf );
                    if( input_cbs->fmflags & II_macro ) {
                        ultoa( input_cbs->s.m->lineno, linestr, 10 );
                        g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name );
                    } else {
                        ultoa( input_cbs->s.f->lineno, linestr, 10 );
                        g_info( inf_file_line, linestr, input_cbs->s.f->filename );
                    }
                    show_include_stack();
                }
            }
            /***************************************************************/
            /*  check for tag end .                                        */
            /***************************************************************/
            if( *p == ' ' ) {
                continue;               // not yet at buffer / tag end
            }
#if 0
            /***************************************************************/
            /*  continue scanning for attriutes on next line if not tag end*/
            /*  This does not work for constructs such as                  */
            /*                                                             */
            /*  :hdref refid=diffs                                         */
            /*  .bd to determine if you need to recompile your application.*/
            /*  from docs\doc\gs\intro.gml line 37 f                       */
            /***************************************************************/

            if( *p != '.' ) { //
                if( get_line( true ) ) {
                    p = buff2;
                } else {
                    *p = '\0';
                }
            } else {
                tag_end_found = true;
            }
#else
            if( (*p == '.') || (*p == '\0') ) {
                tag_end_found = true;
            }
#endif
        }

        /*******************************************************************/
        /*  check for missing reqrd attributes                             */
        /*******************************************************************/
        *token_buf = '\0';
        for( ga = ge->attribs; ga != NULL; ga = ga->next ) {// for all attrs
            if( ga->attflags & att_req ) {
                if( !(ga->attflags & att_proc_seen) ) {
                    if( *token_buf != '\0' ) {
                        strcat( token_buf, " '" );
                    } else {
                        strcpy( token_buf, "'" );
                    }
                    strcat( token_buf, ga->name );
                    strcat( token_buf, "' " );
                }
            }
        }
        if( *token_buf != '\0' ) {      // some req attr missing
            char        linestr[MAX_L_AS_STR];

        // the errmsg in wgml 4.0 is wrong, it shows the macroname, not tag.
// ****ERROR**** SC--047: For the tag '@willi', the required attribute(s)
//                       'muss2'
//                       'muss'
//                       have not been specified

            processed = false;
            err_count++;
            g_err( err_att_req, ge->name, token_buf );
            if( input_cbs->fmflags & II_macro ) {
                ultoa( input_cbs->s.m->lineno, linestr, 10 );
                g_info( inf_mac_line, linestr, input_cbs->s.m->mac->name );
            } else {
                ultoa( input_cbs->s.f->lineno, linestr, 10 );
                g_info( inf_file_line, linestr, input_cbs->s.f->filename );
            }
            show_include_stack();
        }

        if( *p == '.' ) {               // does text follow tag end
            if( strlen( p + 1 ) > 0 ) {
                if( ge->tagflags & tag_texterr ) { // no text allowed
                    tag_text_err( ge->name );
                    processed = false;
                }
            } else {
                if( ge->tagflags & tag_textreq ) {  // reqrd text missing
                    tag_text_req_err( ge->name );
                    processed = false;
                }
            }
            strcpy( token_buf, p + 1 );
            rc = add_symvar( &loc_dict, "_", token_buf, no_subscript, local_var );
            p += strlen( token_buf );
        }

        scan_start = p + 1;             // all processed
        /*******************************************************************/
        /*  add standard symbols to dict                                   */
        /*******************************************************************/

        rc = add_symvar( &loc_dict, "_tag", ge->name, no_subscript, local_var );
        ge->usecount++;
        sprintf( longwork, "%d", ge->usecount );
        rc = add_symvar( &loc_dict, "_n", longwork, no_subscript, local_var );


        add_macro_cb_entry( me, ge );   // prepare GML macro as input
        input_cbs->local_dict = loc_dict;
        inc_inc_level();                // start new include level
        if( ge->tagflags & tag_cont ) {   // +++++++++++++++++++ TBD trial
            post_space = 0;
            ProcFlags.ct = true;
        }

        if( input_cbs->fmflags & II_research && GlobalFlags.firstpass ) {
            print_sym_dict( input_cbs->local_dict );
        }
    } else {                            // user-defined tag has no attributes
        if( ge->tagflags & tag_texterr ) {  // no text allowed
            // '.' or CW_sep_char immediately after the tag does not count as text
            if( (*p == '.') || (*p == CW_sep_char ) ) {
                p++;
            }
            while( *p == ' ' ) {        // spaces don't count as text
                p++;
            }
            if( *p ) {                  // text found
                tag_text_err( ge->name );
                processed = false;
                return( processed );
            }
        }
        if( ge->tagflags & tag_textreq ) {  // text is required
            // per wgml 4.0 behavior
            if( *p == CW_sep_char ) {
                processed = false;
                return( processed );
            }
            // '.' immediately after the tag does not count as text
            if( *p == '.' ) {
                p++;
            }
            while( *p == ' ' ) {        // spaces don't count as text
                p++;
            }
            if( !*p ) {                 // no text found
                tag_text_req_err( ge->name );
                processed = false;
                return( processed );
            }
        }
        // per wgml 4.0 behavior
        if( *p == CW_sep_char ) {
            processed = false;
            return( processed );
        }
        // '.' immediately after the tag is not passed to the macro
        if( *p == '.' ) {
            p++;
        }
        strcpy( token_buf, p );
        rc = add_symvar( &loc_dict, "_", token_buf, no_subscript, local_var );
        p += strlen( token_buf );

        scan_start = p + 1;             // all processed
        /*******************************************************************/
        /*  add standard symbols to dict                                   */
        /*******************************************************************/

        rc = add_symvar( &loc_dict, "_tag", ge->name, no_subscript, local_var );
        ge->usecount++;
        sprintf( longwork, "%d", ge->usecount );
        rc = add_symvar( &loc_dict, "_n", longwork, no_subscript, local_var );


        add_macro_cb_entry( me, ge );   // prepare GML macro as input
        input_cbs->local_dict = loc_dict;
        inc_inc_level();                // start new include level
        if( ge->tagflags & tag_cont ) { // +++++++++++++++++++ TBD trial
            post_space = 0;
            ProcFlags.ct = true;
        }

        if( input_cbs->fmflags & II_research && GlobalFlags.firstpass ) {
            print_sym_dict( input_cbs->local_dict );
        }
    }

    return( processed );
}
Beispiel #2
0
static void     scan_script( void )
{
    inputcb     *   cb;
    mac_entry   *   me;
    char        *   p;
    char        *   pt;
    int             toklen;
    int             k;
    bool            cwfound;

    cb = input_cbs;
    p = scan_start + 1;
    scan_restart = scan_start;

    if( (*p == '*') || !strnicmp( p, "cm ", 3 ) ) {
        scan_start = scan_stop + 1;     // .cm  +++ ignore comment up to EOL
        return;                         // .*   +++ ignore comment up to EOL
    }

    if( *p == SCR_char && *(p+1) == SCR_char ) {
            pt = token_buf;
            *pt++ = SCR_char;               // special for ...label
            *pt++ = SCR_char;
            *pt   = '\0';
            me = NULL;
            scan_start = p + 2;
            toklen = 2;
    } else {
        if( *p == '\'' ) {                  // .'
            p++;
            ProcFlags.CW_sep_ignore = 1;
        } else {
            if( CW_sep_char == '\0') {
                ProcFlags.CW_sep_ignore = 1;// No separator char no split
            } else{
                ProcFlags.CW_sep_ignore = 0;
            }
            if( *p == SCR_char ) {          // ..
                p++;
                ProcFlags.macro_ignore = 1;
                me = NULL;
            } else {
                ProcFlags.macro_ignore = 0;
            }
        }
        if( ProcFlags.literal ) {       // no macro or split line if literal
            ProcFlags.CW_sep_ignore = 1;
            ProcFlags.macro_ignore = 1;
        }
        if( !ProcFlags.CW_sep_ignore ) { // scan line for CW_sep_char
            char    *   pchar;

            pchar = search_separator( buff2, CW_sep_char );

            if( pchar != NULL ) {
                if( *(pchar + 1) != '\0' ) {    // only split if more follows
                    split_input( buff2, pchar + 1, false );// ignore CW_sep_char
                }
                *pchar= '\0';               // delete CW_sep_char
                buff2_lg = strlen( buff2 ); // new length of first part
            }
        }

        scan_start = p;

        pt = token_buf;
        while( *p && is_macro_char( *p ) ) {  // end of controlword
           *pt++ = tolower( *p++ );     // copy lowercase to TokenBuf
        }
        *pt = '\0';

        toklen = pt - token_buf;

        if( *p && (*p != ' ') || toklen == 0 ) {// no valid script controlword / macro
//          if( !ProcFlags.literal ) {   // TBD
//             cw_err();
//          }
            scan_start = scan_restart;  // treat as text
            return;
        }

        if( toklen >= MAC_NAME_LENGTH ) {
            *(token_buf + MAC_NAME_LENGTH) = '\0';
        }
        if( !ProcFlags.macro_ignore ) {
            me = find_macro( macro_dict, token_buf );
        } else {
            me = NULL;
        }
    }

    if( me != NULL ) {                  // macro found
        if( GlobalFlags.firstpass && cb->fmflags & II_research ) {
            if( cb->fmflags & II_macro ) {
                printf_research( "L%d    %c%s macro found in macro %s(%d)\n\n",
                                 inc_level, SCR_char, token_buf,
                                 cb->s.m->mac->name, cb->s.m->lineno );
            } else {
                printf_research( "L%d    %c%s macro found in file %s(%d)\n\n",
                                 inc_level, SCR_char, token_buf,
                                 cb->s.f->filename, cb->s.f->lineno );
            }
            add_SCR_tag_research( token_buf );
        }
        add_macro_cb_entry( me, NULL );
        inc_inc_level();
        add_macro_parms( p );
        scan_restart = scan_stop + 1;
    } else {                            // try script controlword
        cwfound = false;
        if( cb->fmflags & II_research && GlobalFlags.firstpass ) {
            if( cb->fmflags & II_macro ) {
                printf_research( "L%d    %c%s CW found in macro %s(%d)\n\n",
                                 inc_level, SCR_char, token_buf,
                                 cb->s.m->mac->name, cb->s.m->lineno );
            } else {
                printf_research( "L%d    %c%s CW found in file %s(%d)\n\n",
                                 inc_level, SCR_char, token_buf,
                                 cb->s.f->filename, cb->s.f->lineno );
            }
            add_SCR_tag_research( token_buf );
        }

        if( toklen == SCR_KW_LENGTH ) {
            for( k = 0; k < SCR_TAGMAX; ++k ) {
                if( !strcmp( scr_tags[k].tagname, token_buf ) ) {
#if 0
                    if( !ProcFlags.fb_document_done &&
                          scr_tags[k].cwflags & cw_o_t ) {

                        /***************************************************/
                        /*  if this is the first cw  which produces output */
                        /* set page geometry and margins from layout       */
                        /***************************************************/
                        do_layout_end_processing();
                    }
#endif
                    if( !ProcFlags.layout && (scr_tags[k].cwflags & cw_o_t) ) {

                        /********************************************************/
                        /* this is the first control word which produces output */
                        /* start the document, the layout is done               */
                        /* start_doc_sect() calls do_layout_end_processing()    */
                        /********************************************************/

                        start_doc_sect();
                    }
                    if( ProcFlags.literal  ) {  // .li active
                        if( !strcmp( token_buf, "li" ) ) {  // .li
                            scan_start = p; // found, process
                            scr_tags[k].tagproc();
                        }
                    } else {
                        scan_start = p; // script controlword found, process
                        if( scr_tags[k].cwflags & cw_break ) {
                            scr_process_break();// output incomplete line, if any
                        }
                        scr_tags[k].tagproc();
                    }
                    cwfound = true;
                    break;
                }
            }
        }
        if( !cwfound ) {
            cw_err();                   // unrecognized control word
        }
    }
    scan_start = scan_restart;
}