Example #1
0
void ob_binclude( binclude_element * in_el )
{
    uint32_t    count;

    if( search_file_in_dirs( in_el->file, "", "", ds_doc_spec ) ) {
        fb_binclude_support( in_el );
        if( fwrite( buffout.text, sizeof( uint8_t ), buffout.current, out_file_fp ) < buffout.current ) {
            xx_simple_err_c( err_write_out_file, out_file );
        }
        buffout.current = 0;

        if( in_el->has_rec_type ) {
            count = fread( buffout.text, sizeof( uint8_t ), buffout.length, try_fp );
            while( count == buffout.length ) {
                buffout.current = count;
                if( fwrite( buffout.text, sizeof( uint8_t ), buffout.current, out_file_fp ) < buffout.current ) {
                    xx_simple_err_c( err_write_out_file, out_file );
                    count = 0;
                    break;
                }
                count = fread( buffout.text, sizeof( uint8_t ), buffout.length, try_fp );
            }
            buffout.current = count;
            if( fwrite( buffout.text, sizeof( uint8_t ), buffout.current, out_file_fp ) < buffout.current ) {
                xx_simple_err_c( err_write_out_file, out_file );
            }
            if( ferror( try_fp ) ) {
                xx_simple_err_cc( err_in_file, "BINCLUDE", try_file_name );
            }
            buffout.current = 0;
        } else {
            count = fread( binc_buff.text, sizeof( uint8_t ), binc_buff.length, try_fp );
            while( count == binc_buff.length ) {
                binc_buff.current = count;
                ob_flush();
                if( fwrite( binc_buff.text, sizeof( uint8_t ), binc_buff.current, out_file_fp )
                        < binc_buff.current ) {
                    xx_simple_err_c( err_write_out_file, out_file );
                    count = 0;
                    break;
                }
                count = fread( binc_buff.text, sizeof( uint8_t ), binc_buff.length, try_fp );
            }
            binc_buff.current = count;
            if( fwrite( binc_buff.text, sizeof( uint8_t ), binc_buff.current, out_file_fp ) < binc_buff.current ) {
                xx_simple_err_c( err_write_out_file, out_file );
            }
            if( in_el->depth > 0 ) {
                ob_flush();
            }
            if( ferror( try_fp ) ) {
                xx_simple_err_cc( err_in_file, "BINCLUDE", try_file_name );
            }
        }
    } else {
        xx_tag_err( err_file_not_found, in_el->file );
    }

    return;
}
Example #2
0
void    gml_binclude( gml_tag gtag )
{
    bool            depth_found             = false;
    bool            file_found              = false;
    bool            has_rec_type            = false;
    bool            reposition;
    bool            reposition_found        = false;
    char            file[FILENAME_MAX];
    char            rt_buff[MAX_FILE_ATTR];
    char        *   p;
    doc_element *   cur_el;
    su              depth_su;
    uint32_t        depth;
    size_t          len;

    if( (ProcFlags.doc_sect < doc_sect_gdoc) ) {
        if( (ProcFlags.doc_sect_nxt < doc_sect_gdoc) ) {
            xx_tag_err( err_tag_before_gdoc, gml_tagname( gtag ) );
            scan_start = scan_stop;
            return;
        }
    }
    len = 0;
    file[0] = '\0';
    rt_buff[0] = '\0';
    p = scan_start;
    for( ;; ) {
        while( *p == ' ' ) {            // over WS to attribute
            p++;
        }
        if( *p == '\0' ) {              // end of line: get new line
            if( !(input_cbs->fmflags & II_eof) ) {
                if( get_line( true ) ) {      // next line for missing attribute
                    process_line();
                    if( (*scan_start == SCR_char) ||    // cw found: end-of-tag
                        (*scan_start == GML_char) ) {   // tag found: end-of-tag
                        ProcFlags.tag_end_found = true;
                        break;
                    } else {
                        p = scan_start; // new line is part of current tag
                        continue;
                    }
                }
            }
        }
        if( !strnicmp( "file", p, 4 ) ) {
            p += 4;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            file_found = true;
            len = val_len;
            if( len >= FILENAME_MAX )
                len = FILENAME_MAX - 1;
            memcpy( file, val_start, len );
            file[len] = '\0';
            split_attr_file( file, rt_buff, MAX_FILE_ATTR );
            if( (rt_buff[0] != '\0') ) {
                has_rec_type = true;
                if( rt_buff[0] != 't' ) {
                    xx_warn( wng_rec_type_binclude );
                }
            }
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "depth", p, 5 ) ) {
            p += 5;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            depth_found = true;
            if( att_val_to_su( &depth_su, true ) ) {
                return;
            }
            depth = conv_vert_unit( &depth_su, g_spacing_ln );
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "reposition", p, 10 ) ) {
            p += 10;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            reposition_found = true;
            if( !strnicmp( "start", val_start, 5 ) ) {
                reposition = true;  // moving following text down by depth
            } else if( !strnicmp( "end", val_start, 3 ) ) {
                reposition = false; // device at proper position after insertion
            } else {
                xx_line_err( err_inv_att_val, val_start );
                scan_start = scan_stop;
                return;
            }
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else {    // no match = end-of-tag in wgml 4.0
            ProcFlags.tag_end_found = true;
            break;
        }
    }
    // detect missing required attributes
    if( !depth_found || !file_found || !reposition_found ) {
        xx_err( err_att_missing );
        scan_start = scan_stop;
        return;
    }

    scr_process_break();                // flush existing text
    start_doc_sect();                   // if not already done

    cur_el = alloc_doc_el(  el_binc );
    if( reposition && depth ) {
        cur_el->depth = depth;          // otherwise, it will be "0"
    }
    if( depth > 0 ) {
        set_skip_vars( NULL, NULL, NULL, 1, g_curr_font );
        cur_el->blank_lines = g_blank_lines;
        g_blank_lines = 0;
        cur_el->subs_skip = g_subs_skip;
        cur_el->top_skip = g_top_skip;
    }
    cur_el->element.binc.depth = depth;
    cur_el->element.binc.cur_left = g_cur_h_start;
    cur_el->element.binc.has_rec_type = has_rec_type;
    ProcFlags.skips_valid = false;
    memcpy( cur_el->element.binc.file, file, len + 1 );
    insert_col_main( cur_el );

    scan_start = scan_stop;         // skip following text
}
Example #3
0
void    gml_graphic( gml_tag gtag )
{
    bool            depth_found             = false;
    bool            file_found              = false;
    char            file[FILENAME_MAX];
    char            rt_buff[MAX_FILE_ATTR];
    char        *   p;
    char        *   pa;
    doc_element *   cur_el;
    su              cur_su;
    uint32_t        depth;
    uint32_t        scale                   = 100;
    // the initial value of width is only correct for one-column pages.
    uint32_t        width                   = g_net_page_width;
    int32_t         xoff                    = 0;
    int32_t         yoff                    = 0;
    size_t          len;

    if( (ProcFlags.doc_sect < doc_sect_gdoc) ) {
        if( (ProcFlags.doc_sect_nxt < doc_sect_gdoc) ) {
            xx_tag_err( err_tag_before_gdoc, gml_tagname( gtag ) );
            scan_start = scan_stop;
            return;
        }
    }
    len = 0;
    file[0] = '\0';
    rt_buff[0] = '\0';
    p = scan_start;
    for( ;; ) {
        while( *p == ' ' ) {            // over WS to attribute
            p++;
        }
        if( *p == '\0' ) {              // end of line: get new line
            if( !(input_cbs->fmflags & II_eof) ) {
                if( get_line( true ) ) {      // next line for missing attribute
                    process_line();
                    if( (*scan_start == SCR_char) ||    // cw found: end-of-tag
                        (*scan_start == GML_char) ) {   // tag found: end-of-tag
                        ProcFlags.tag_end_found = true;
                        break;
                    } else {
                        p = scan_start; // new line is part of current tag
                        continue;
                    }
                }
            }
        }
        if( !strnicmp( "file", p, 4 ) ) {
            p += 4;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            file_found = true;
            len = val_len;
            if( len >= FILENAME_MAX )
                len = FILENAME_MAX - 1;
            memcpy( file, val_start, len );
            file[len] = '\0';
            split_attr_file( file, rt_buff, sizeof( rt_buff ) );
            if( (rt_buff[0] != '\0') ) {
                xx_warn( wng_rec_type_graphic );
            }
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "depth", p, 5 ) ) {
            p += 5;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            depth_found = true;
            pa = val_start;
            if( att_val_to_su( &cur_su, true ) ) {
                return;
            }
            depth = conv_vert_unit( &cur_su, g_spacing_ln );
            if( depth == 0 ) {
                xx_line_err( err_inv_depth_graphic, pa );
                scan_start = scan_stop;
                return;
            }
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "width", p, 5 ) ) {
            p += 5;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            if( !strnicmp( "page", val_start, 4 ) ) {
                // default value is the correct value to use
            } else if( !strnicmp( "column", val_start, 6 ) ) {
                // default value is the correct value to use
            } else {    // value actually specifies the width
                pa = val_start;
                if( att_val_to_su( &cur_su, true ) ) {
                    return;
                }
                width = conv_hor_unit( &cur_su );
                if( width == 0 ) {
                    xx_line_err( err_inv_width_graphic, pa );
                    scan_start = scan_stop;
                    return;
                }
                /* there should be a check somewhere for width > page width */
            }
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "scale", p, 5 ) ) {
            p += 5;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            pa = val_start;
            if( (*pa == '+') || (*pa == '-') ) {  // signs not allowed
                xx_line_err( err_num_too_large, pa );
                scan_start = scan_stop;
                return;
            }
            scale = 0;
            while( (*pa >= '0') && (*pa <= '9') ) { // convert to number
                scale = (10 * scale) + (*pa - '0');
                pa++;
                if( (pa - val_start) > val_len ) {  // value end reached
                    break;
                }
            }
            if( scale > 0x7fffffff ) {              // wgml 4.0 limit
                xx_line_err( err_num_too_large, val_start );
                scan_start = scan_stop;
                return;
            }
            if( (pa - val_start) < val_len ) {      // value continues on
                xx_line_err( err_num_too_large, val_start );
                scan_start = scan_stop;
                return;
            }
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "xoff", p, 4 ) ) {
            p += 4;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            if( att_val_to_su( &cur_su, false ) ) {
                return;
            }
            xoff = conv_hor_unit( &cur_su );
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else if( !strnicmp( "yoff", p, 4 ) ) {
            p += 4;
            p = get_att_value( p );
            if( val_start == NULL ) {
                break;
            }
            if( att_val_to_su( &cur_su, false ) ) {
                return;
            }
            yoff = conv_vert_unit( &cur_su, g_spacing_ln );
            if( ProcFlags.tag_end_found ) {
                break;
            }
        } else {    // no match = end-of-tag in wgml 4.0
            ProcFlags.tag_end_found = true;
            break;
        }
    }
    if( !depth_found || !file_found ) { // detect missing required attributes
        xx_err( err_att_missing );
        scan_start = scan_stop;
        return;
    }

    scr_process_break();                // flush existing text
    start_doc_sect();                   // if not already done

    cur_el = alloc_doc_el( el_graph );
    cur_el->depth = depth;              // always used with GRAPHIC
    if( !ProcFlags.ps_device ) {        // character devices ignore SK & post_skip
        g_skip = 0;
        g_post_skip = 0;
    }
    set_skip_vars( NULL, NULL, NULL, 1, g_curr_font );
    cur_el->blank_lines = g_blank_lines;
    g_blank_lines = 0;
    cur_el->subs_skip = g_subs_skip;
    g_subs_skip = 0;
    cur_el->top_skip = g_top_skip;
    g_top_skip = 0;
    cur_el->element.graph.cur_left = g_cur_h_start;
    cur_el->element.graph.depth = depth;
    cur_el->element.graph.scale = scale;
    cur_el->element.graph.width = width;
    cur_el->element.graph.xoff = xoff;
    cur_el->element.graph.yoff = yoff;
    ProcFlags.skips_valid = false;
    memcpy( cur_el->element.graph.file, file, len + 1 );
    insert_col_main( cur_el );

    if( *p == '.' ) {
        p++;
    }
    scan_start = p;                 // process following text
}
Example #4
0
void ob_graphic( graphic_element * in_el )
{
    char        begindoc[] = "%%BeginDocument: ";
    char        enddoc[] = "%%EndDocument";
    char        graphobj[] = "/graphobj save def /showpage { } def";
    char        restore[] = "graphobj restore";
    size_t      ps_size;
    uint32_t    count;

    if( search_file_in_dirs( in_el->file, "", "", ds_doc_spec ) ) {
        fb_graphic_support( in_el );
        ob_flush();

        ps_size = strlen( graphobj );
        strcpy_s( buffout.text, buffout.length, graphobj );
        buffout.current = ps_size;
        ob_flush();

        memset( buffout.text, buffout.length, '\0' );
        ps_size = sprintf_s( buffout.text, buffout.length,
                  "%d %d %d %d %d %d %d graphhead",
                  in_el->cur_left, in_el->y_address, in_el->width, in_el->depth,
                  in_el->xoff, -1 * (in_el->depth + in_el->yoff), in_el->scale );
        buffout.current = strlen( buffout.text );
        ob_flush();

        ps_size = strlen( begindoc );
        strcpy_s( buffout.text, buffout.length, begindoc );
        buffout.current = ps_size;
        strcpy_s( buffout.text + ps_size, buffout.length - ps_size, in_el->file );
        buffout.current = strlen( buffout.text );
        ob_flush();

        count = fread( buffout.text, sizeof( uint8_t ), buffout.length, try_fp );
        while( count == buffout.length ) {
            buffout.current = count;
            if( fwrite( buffout.text, sizeof( uint8_t ), buffout.current, out_file_fp )
                    < buffout.current ) {
                xx_simple_err_c( err_write_out_file, out_file );
                return;
            }
            count = fread( buffout.text, sizeof( uint8_t ), buffout.length, try_fp );
        }
        buffout.current = count;
        if( fwrite( buffout.text, sizeof( uint8_t ), buffout.current, out_file_fp )
                < buffout.current ) {
            xx_simple_err_c( err_write_out_file, out_file );
            return;
        }
        buffout.current = 0;

        ps_size = strlen( enddoc );
        strcpy_s( buffout.text, buffout.length, enddoc );
        buffout.current = ps_size;
        ob_flush();

        ps_size = strlen( restore );
        strcpy_s( buffout.text, buffout.length, restore );
        buffout.current = ps_size;
        ob_flush();
        if( ferror( try_fp ) ) {
            xx_simple_err_cc( err_in_file, "GRAPHIC", try_file_name );
        }
    } else {
        xx_tag_err( err_file_not_found, in_el->file );
    }

    return;
}