Exemplo n.º 1
0
char    *scr_single_func_e( char * in, char * end, char * * result )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;

    end   = end;

    pchar = scan_sym( in + 3 + (*(in + 3) == '&'), &symvar_entry, &var_ind );

    if( symvar_entry.flags & local_var ) {  // lookup var in dict
        rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                            var_ind, &symsubval );
    } else {
        rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                          &symsubval );
    }
    if( rc == 2 ) {
        **result = '1';                 // exists
    } else {
        **result = '0';                 // does not exist
    }
    *result  += 1;
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Exemplo n.º 2
0
static char * subst_1var( char * pout, char * pvar, size_t len )
{
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    char            *   pchar;

    ProcFlags.suppress_msg = true;
    scan_err = false;

    pchar = scan_sym( pvar, &symvar_entry, &var_ind );
    ProcFlags.suppress_msg = false;
    if( !scan_err ) {
        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                              var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            pchar = symsubval->value;
            while( *pchar ) {
                *pout++ = *pchar++;
            }
        }
    }
    *pout = '\0';
    return( pout );
}
Exemplo n.º 3
0
char    *scr_single_func_w( char * in, char * end, char * * result )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    int                 len;
    uint32_t            width;

    if( *(in + 3) == '&' ) {            // symbol name
        pchar = scan_sym( in + 4, &symvar_entry, &var_ind );

        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            width = cop_text_width( symsubval->value, strlen( symsubval->value ), g_curr_font);
        } else {

        /*******************************************************************/
        /* for undefined variable calc length of name, & and perhaps *     */
        /*******************************************************************/
            width = cop_text_width( symvar_entry.name, strlen( symvar_entry.name ), g_curr_font )
                    + wgml_fonts[g_curr_font].width_table['&'];

            if( symvar_entry.flags & local_var ) {  // add width of *
                width += wgml_fonts[g_curr_font].width_table['*'];
            }
        }
    } else {                            // string
        pchar = in + 3;
        len = 0;
        while( !((*pchar == ' ') || (*pchar == '.') || (pchar == end)) ) {
            len++;
            pchar++;
        }
        width = cop_text_width( in + 3, len, g_curr_font );
    }
    len = width;
    width = (width * CPI + g_resh / 2) / g_resh;
    sprintf( *result, "%d", width );
#if 0                                   // perhaps as debug output
    sprintf( *result + strlen( *result ), " %d", len );
#endif
    *result  += strlen( *result );
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Exemplo n.º 4
0
char    *scr_single_func_sS( char * in, char * end, char * * result, char fun )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    char            *   pval;


    **result = function_escape;         // insert function code in buffer
    *result += 1;
    **result = fun;
    *result += 1;

    if( *(in + 3) == '&' ) {            // symbol name
        pchar = scan_sym( in + 4, &symvar_entry, &var_ind );

        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            pval = symsubval->value;    // variable  found
        } else {
            pval =  symvar_entry.name;  // not found use variable name
        }
        while( *pval ) {
            **result = *pval++;
            *result += 1;
        }
    } else {                            // string
        pchar = in + 3;
        while( !((*pchar == ' ') || (*pchar == '.') || (pchar == end)) ) {
            **result = *pchar++;
            *result += 1;
        }
    }
    **result = function_escape;         // insert function code in buffer
    *result += 1;
    **result = fun | 0x01;              // function end
    *result += 1;
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Exemplo n.º 5
0
char    *scr_single_func_l( char * in, char * end, char * * result )
{
    char            *   pchar;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    int                 rc;
    int                 len;

    if( *(in + 3) == '&' ) {            // symbol name
        pchar = scan_sym( in + 4, &symvar_entry, &var_ind );

        if( symvar_entry.flags & local_var ) {  // lookup var in dict
            rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                var_ind, &symsubval );
        } else {
            rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                              &symsubval );
        }
        if( rc == 2 ) {
            sprintf( *result, "%d", strlen( symsubval->value ) );
        } else {
            sprintf( *result, "%d", strlen( symvar_entry.name ) );
        }
    } else {                            // string
        pchar = in + 3;
        len = 0;
        while( !((*pchar == ' ') || (*pchar == '.') || (pchar == end)) ) {
            len++;
            pchar++;
        }
        sprintf( *result, "%d", len );
    }
    *result  += strlen( *result );
    **result = '\0';

    if( *pchar == '.' ) {
        pchar++;                    // skip optional terminating dot
    }
    ProcFlags.substituted = true;       // something changed
    return( pchar );
}
Exemplo n.º 6
0
static  condcode    scr_veclp( parm parms[MAX_FUN_PARMS], size_t parmcount,
                               char * * result, int32_t ressize )
{
    char            *   pneedle;
    char            *   pneedlend;
    char            *   phay;
    char            *   phayend;
    int                 rc;
    int                 index;
    int                 hay_len;
    int                 needle_len;
    char                c;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    symvar          *   psymvar;
    bool                suppress_msg;

    ressize = ressize;
    if( parmcount != 2 ) {
        return( neg );
    }

    pneedle = parms[0].a;
    pneedlend = parms[0].e;

    unquote_if_quoted( &pneedle, &pneedlend );
    needle_len = pneedlend - pneedle + 1;   // needle length

    phay = parms[1].a;
    phayend = parms[1].e;

    unquote_if_quoted( &phay, &phayend );
    hay_len = phayend - phay + 1;       // haystack length

    rc = 0;
    scan_err = false;
    index = 0;

    if( (hay_len > 0) ||                // not null string
        (needle_len > 0) ) {            // needle not null


        suppress_msg = ProcFlags.suppress_msg;
        ProcFlags.suppress_msg = true;
        scan_err = false;
        c = *(phayend + 1);
        *(phayend + 1) = '\0';

        scan_sym( phay, &symvar_entry, &var_ind );

        *(phayend + 1) = c;
        ProcFlags.suppress_msg = suppress_msg;;

        if( !scan_err ) {

            if( symvar_entry.flags & local_var ) {  // lookup var in dict
                rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                    var_ind, &symsubval );
            } else {
                rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                                  &symsubval );
            }
            if( rc > 0 ) {              // variable found
                psymvar = symsubval->base;
                if( psymvar->flags & subscripted ) {
                    c = *(pneedlend + 1);
                    *(pneedlend + 1) = '\0';   // make nul delimited
                    for( symsubval = psymvar->subscripts;
                         symsubval != NULL;
                         symsubval = symsubval->next ) {

                        if( !strcmp( symsubval->value, pneedle ) ) {
                           index = symsubval->subscript;
                           if( vec_pos ) {
                               break;// finished for vec_pos, go for veclastpos
                           }
                        }
                    }
                    *(pneedlend + 1) = c;
                }
            }
        }
    }

    *result += sprintf( *result, "%d", index );

    return( pos );
}
Exemplo n.º 7
0
bool    resolve_symvar_functions( char * buf )
{
    static const char   ampchar = '&';
    inp_line        *   in_wk;
    char            *   workb;
    char            *   pw;
    char            *   pwend;
    char            *   p2;
    char            *   pchar;
    char            *   varstart;
    sub_index           var_ind;
    symvar              symvar_entry;
    symsub          *   symsubval;
    size_t              buf_lg;
    int                 rc;
    bool                functions_found;
    bool                anything_substituted;

    char            *   var_unresolved; // ptr for resume search
    char            *   var_unresolved2;// ptr for resume search

    ProcFlags.substituted = false;
    ProcFlags.unresolved  = false;

    if( NULL == strchr( buf, ampchar ) ) {  // look for & in buffer
        return( false );              // no ampchar found, nothing to resolve
    }

    anything_substituted = false;
    var_unresolved = NULL;
    var_unresolved2 = NULL;
    functions_found = false;

    in_wk = mem_alloc( sizeof( inp_line ) + buf_size );// allocate workbuffer
    in_wk->next = NULL;
    workb = in_wk->value;               // allocate workbuffer

    do {                                // until no more substitutions
        strcpy( workb, buf );   // copy input buffer
        buf_lg = strlen( buf );
        pwend = workb + buf_lg - 1;
        if( var_unresolved == NULL ) {
            pw = workb;
            p2 = buf;
        } else {
            pw = workb + (var_unresolved2 - buf);
            p2 = var_unresolved2;
        }
        varstart = NULL;

        anything_substituted |= ProcFlags.substituted;
        ProcFlags.substituted = false;

        pchar = strchr( workb, ampchar ); // look for & in buffer
        while( pchar != NULL ) {        // & found
            if( *(pchar + 1) == ' ' ) { // not a symbol substition or function
                pchar = strchr( pchar + 1, ampchar );  // look for next & in buffer
                continue;
            }
            while( pw < pchar ) {       // copy all data preceding &
                *p2++ = *pw++;
            }
            buf_lg = strlen( buf );

            if( isalpha( *(pchar + 1) ) && *(pchar + 2) == '\''
                && *(pchar + 3) > ' ' ) {
                                        // not for .if '&*' eq '' .th ...
                                        // only    .if '&x'foo' eq '' .th
                char * * ppval = &p2;

                /***********************************************************/
                /*  Some single letter functions are resolved here:        */
                /*                                                         */
                /*  functions used within the OW doc build system:         */
                /*   &e'  existance of variable 0 or 1                     */
                /*   &l'  length of variable content                       */
                /*        or if undefined variable length of name          */
                /*   &u'  upper                                            */
                /*                                                         */
                /*   &s'  subscript                                        */
                /*   &S'  superscript                                      */
                /*                                                         */
                /*   other single letter functions are not used AFAIK      */
                /*                                                         */
                /***********************************************************/

                if( GlobalFlags.firstpass && input_cbs->fmflags & II_research ) {
                    add_single_func_research( pchar + 1 );
                }

                pw = scr_single_funcs( pchar, pwend, ppval );

                pchar = strchr( pw, ampchar );  // look for next & in buffer

                continue;
            }

            if( *(pchar + 1) == '\'' ) {// perhaps a multi letter function
                char   * pf;
                char * * ppval = &p2;
                int32_t  valsize = buf_size - (p2 - buf);

                pf = pchar + 2;
                while( is_function_char( *pf ) ) {
                    pf++;
                }
                if( *pf == '(' ) {// &'xyz( is start of multi char function

                /***********************************************************/
                /*  Some multi  letter functions are resolved here:        */
                /*                                                         */
                /*  functions used within the OW doc build system:         */
                /*                                                         */
                /*   &'delstr(          &'d2c(              &'index(       */
                /*   &'insert(          &'left(             &'length(      */
                /*   &'lower(           &'min(              &'pos(         */
                /*   &'right(           &'strip(            &'substr(      */
                /*   &'subword(         &'translate(        &'upper(       */
                /*   &'veclastpos(      &'vecpos(           &'word(        */
                /*   &'wordpos(         &'words(                           */
                /*                                                         */
                /*   Others are recognized but not processed               */
                /*   &'c2x(    is used for test output                     */
                /***********************************************************/

                    pw = scr_multi_funcs( pchar, pwend, ppval, valsize );

                    pchar = strchr( pw, ampchar );// look for next & in buffer
                    continue;
                }

                *p2++ = *pw++;          // copy &
                pchar = strchr( pw, ampchar );  // look for next & in buffer
                continue;               // and ignore this &... for now
            }

            /***************************************************************/
            /* & is neither start of single char function                  */
            /*   nor start of multi char function                          */
            /*                                                             */
            /* &  is probably start of a variable                          */
            /***************************************************************/

            varstart = pw;              // remember start of var
            pw++;                       // over &
            ProcFlags.suppress_msg = true;
            scan_err = false;

            pchar = scan_sym( pw, &symvar_entry, &var_ind );
            if( scan_err && *pchar == '(' ) {   // problem with subscript

                if( var_unresolved == NULL ) {
                    ProcFlags.unresolved  = true;
                    var_unresolved = varstart;
                    var_unresolved2 = p2;
                } else {
                    if( var_unresolved != varstart ) {
                        ProcFlags.unresolved  = true;
                    }
                }
                p2 += pchar - varstart;
                pw = pchar;
                pchar = strchr( pw, ampchar );  // look for next & in buffer

                continue;
            }

            ProcFlags.suppress_msg = false;

            if( symvar_entry.flags & local_var ) {  // lookup var in dict
                rc = find_symvar_l( &input_cbs->local_dict, symvar_entry.name,
                                    var_ind, &symsubval );
            } else {
                rc = find_symvar( &global_dict, symvar_entry.name, var_ind,
                                  &symsubval );
            }
            if( rc == 2 ) {             // variable found + resolved
                ProcFlags.substituted = true;
                if( !ProcFlags.CW_sep_ignore &&
                    symsubval->value[0] == CW_sep_char &&
                    symsubval->value[1] != CW_sep_char ) {

                                // split record at control word separator
                                // if variable starts with SINGLE cw separator
                                // and ignore cw separator

                    if( buf != buff2 ) {

                        // splitting input if not outermost buffer ++++ TBD
                        // needed ???
                        g_suicide();
                    }

                    if( *pchar == '.' ) {
                        pchar++;        // skip optional terminating dot
                    }
                    *p2 = '\0';
                    split_input_var( buf, pchar, &symsubval->value[1], true );
                    pw = pwend + 1;     // stop substitution for this record
                    varstart = NULL;

                    break;

                } else {
                    pw = symsubval->value;
                    if( symsubval->value[0] == CW_sep_char &&
                        symsubval->value[1] == CW_sep_char ) {
                        pw++;           // skip 1 CW_sep_char
                    }
                    strcpy( p2, pw );   // copy value
                    p2 += strlen(pw);
                    if( *pchar == '.' ) {
                        pchar++;        // skip optional terminating dot
                    }
                    pw = pchar;
                }
            } else {                    // variable not found
                if( (symvar_entry.flags & local_var )  // local var not found
                    ) {
                    if( (symvar_entry.name[0] == '\0') &&
                        (*pchar == ampchar) ) { // only &* as var name
                                                // followed by another var

                        if( var_unresolved == NULL ) {
                            ProcFlags.unresolved  = true;
                            var_unresolved = varstart;
                            var_unresolved2 = p2;
                        } else {
                            if( var_unresolved != varstart ) {
                                ProcFlags.unresolved  = true;
                            }
                        }
                        pw = varstart;
                        while( pw < pchar ) {   // treat var name as text
                            *p2++ = *pw++;  // and copy
                        }

                        continue;       // pchar points already to next &

                    } else {     // replace not found local var by nullstring
                        ProcFlags.substituted = true;
                        if( *pchar == '.' ) {
                            pchar++;    // skip optional terminating dot
                        }
                        pw = pchar;
                    }
                } else {                // global var not found
                                        // .. or local var outside of macro
                    /*******************************************************/
                    /*  keep trying for constructs such as                 */
                    /*                                                     */
                    /* .se prodgml = "Open Watcom GML"                     */
                    /* .se name = "GML"                                    */
                    /*                                                     */
                    /* My name is &prod&name..!                            */
                    /*                                                     */
                    /*  to become                                          */
                    /*                                                     */
                    /* My name is Open Watcom GML!                         */
                    /*                                                     */
                    /* This does not work for local variables, as these are*/
                    /* replaced by nullstring if not found                 */
                    /* My name is &*prod&*name..!                          */
                    /*  will become                                        */
                    /* My name is !                                        */
                    /*******************************************************/

                    if( var_unresolved == NULL ) {
                        ProcFlags.unresolved  = true;
                        var_unresolved = varstart;
                        var_unresolved2 = p2;
                    } else {
                        if( var_unresolved != varstart ) {
                            ProcFlags.unresolved  = true;
                        }
                    }

                    pw = varstart;
                    if( *pchar == '.' ) {
                        pchar++;        // copy terminating dot, too
                    }
                    while( pw < pchar ) {   // treat var name as text
                        *p2++ = *pw++;  // and copy
                    }
                }
            }
            pchar = strchr( pw, ampchar );  // look for next & in buffer
        }                               // while & found

        while( pw <= pwend) {           // copy remaining input
             *p2++ = *pw++;
        }
        *p2 = 0;                        // terminate string

    } while( ProcFlags.unresolved && ProcFlags.substituted );

    anything_substituted |= ProcFlags.substituted;

    mem_free( in_wk );                  // free workbuffer
    return( anything_substituted );
}