void scr_cp( void ) { char * pa; char * p; int len; getnum_block gn; condcode cc; char cwcurr[4]; cwcurr[0] = SCR_char; cwcurr[1] = 'c'; cwcurr[2] = 'p'; cwcurr[3] = '\0'; p = scan_start; while( *p && *p != ' ' ) { // over cw p++; } while( *p && *p == ' ' ) { // next word start p++; } pa = p; while( *p && *p != ' ' ) { // end of word p++; } len = p - pa; if( len > 0 ) { // no action if no parm gn.argstart = pa; gn.argstop = scan_stop; gn.ignore_blanks = 0; cc = getnum ( &gn ); // try to get numeric value if( cc == notnum ) { xx_opt_err( cwcurr, pa ); scan_restart = scan_stop +1; } else { if( gn.result > 0 ) { // ignore values < 1 if( ((gn.result * wgml_fonts[g_curr_font].line_height) + t_page.cur_depth) > t_page.max_depth ) { last_page_out(); reset_t_page(); } } scan_restart = gn.argstart; } } else { scan_restart = scan_stop +1; } return; }
void scr_pa( void ) { char * pa; char * p; int len; char cwcurr[4]; cwcurr[0] = SCR_char; cwcurr[1] = 'p'; cwcurr[2] = 'a'; cwcurr[3] = '\0'; p = scan_start; while( *p && *p != ' ' ) { // over cw p++; } while( *p && *p == ' ' ) { // next word start p++; } pa = p; while( *p && *p != ' ' ) { // end of word p++; } len = p - pa; switch( len ) { case 7 : if( strnicmp( "NOSTART", pa, 7 ) ) { xx_opt_err( cwcurr, pa ); break; } /* fallthru for NOSTART */ case 0 : last_page_out(); // default action reset_t_page(); break; case 3 : if( !strnicmp( "ODD", pa, 3 ) ) { last_page_out(); reset_t_page(); if( (page & 1) ) { // next page would be even do_page_out(); reset_t_page(); } } else { xx_opt_err( cwcurr, pa ); } break; case 4 : if( !strnicmp( "EVEN", pa, 4 ) ) { last_page_out(); reset_t_page(); if( !(page & 1) ) { // next page would be odd do_page_out(); reset_t_page(); } } else { xx_opt_err( cwcurr, pa ); } break; default: xx_opt_err( cwcurr, pa ); break; } scan_restart = scan_stop +1; return; }
static void gen_toc( void ) { bool levels[7]; // track levels char buffer[11]; char postfix[12]; ffh_entry * curr; int i; int j; uint32_t cur_level; uint32_t indent[7]; uint32_t size; if( hd_list == NULL ) return; // no hd_list, no TOC /* Insert TOC into current section */ last_page_out(); // ensure are on new page g_skip = 0; // ignore remaining skip value set_section_banners( doc_sect_toc ); reset_t_page(); /* Set TOC margins and other values */ g_page_left = g_page_left_org + 2 * conv_hor_unit( &layout_work.toc.left_adjust, g_curr_font ); // matches wgml 4.0 g_page_right = g_page_right_org - conv_hor_unit( &layout_work.toc.right_adjust, g_curr_font ); size = conv_hor_unit( &layout_work.tocpgnum.size, g_curr_font ); // space from fill to right edge figlist_toc_tabs( layout_work.toc.fill_string, size ); /* Initialize levels and indent values */ for( i = 0; i < 7; i++ ) { levels[i] = false; indent[i] = 0; } /* Get converted indent values, which are cumulative */ for( i = 0; i < 7; i++ ) { for( j = i; j < 7; j++ ) { indent[j] += conv_hor_unit( &layout_work.tochx[i].indent, g_curr_font ); } } /* Output TOC */ concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; ProcFlags.keep_left_margin = true; // keep all indents while outputting text curr = hd_list; while( curr != NULL ) { cur_level = curr->number; for( i = 0; i < 7; i++ ) { if( i > cur_level ) { // all lower levels are inactive levels[i] = false; } } if( cur_level < layout_work.toc.toc_levels ) { g_curr_font = layout_work.tochx[cur_level].font; if( levels[cur_level] ) { spacing = layout_work.toc.spacing; set_skip_vars( &layout_work.tochx[cur_level].skip, NULL, NULL, spacing, g_curr_font ); } else { spacing = 1; set_skip_vars( &layout_work.tochx[cur_level].pre_skip, NULL, &layout_work.tochx[cur_level].post_skip, spacing, g_curr_font ); } g_cur_left = g_page_left + indent[cur_level]; g_cur_h_start = g_cur_left; if( curr->prefix != NULL ) { process_text( curr->prefix, g_curr_font ); g_cur_left = t_line->last->x_address + t_line->last->width + wgml_fonts[g_curr_font].spc_width; g_cur_h_start = g_cur_left; ProcFlags.ct = true; // emulate CT post_space = 0; } else { t_line = alloc_text_line(); // capture spacing if no prefix } if( !levels[cur_level] ) { spacing = layout_work.toc.spacing; set_skip_vars( NULL, NULL, NULL, spacing, g_curr_font ); } if( curr->text != NULL ) { g_page_right -= size; if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right -= tab_col; } else { g_page_right -= 3 * tab_col; } ProcFlags.stop_xspc = true; // suppress 2nd space after stop process_text( curr->text, g_curr_font ); if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right += tab_col; } else { g_page_right += 3 * tab_col; } g_page_right += size; } ProcFlags.ct = true; // emulate CT g_curr_font = FONT0; process_text( "$", g_curr_font ); format_num( curr->pageno, &buffer, sizeof( buffer ), curr->style ); strcpy_s( postfix, 12, "$" ); // insert tab characters strcat_s( postfix, 12, buffer ); // append page number g_curr_font = layout_work.tocpgnum.font; process_text( postfix, g_curr_font ); } scr_process_break(); // ensure line break levels[cur_level] = true; // first entry of level done curr = curr->next; } ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; /* Re-establish current section */ last_page_out(); // ensure all pages output set_section_banners( ProcFlags.doc_sect ); reset_t_page(); return; }
void start_doc_sect( void ) { bool first_section; bool header; bool page_r; char * h_text; doc_section ds; hdsrc hds_lvl; int k; page_ej page_e; uint32_t page_c; uint32_t page_s; if( ProcFlags.start_section ) { return; // once is enough } if( !ProcFlags.fb_document_done ) { // the very first section/page do_layout_end_processing(); } scr_process_break(); // commit any prior text first_section = (ProcFlags.doc_sect == doc_sect_none); ProcFlags.start_section = true; ProcFlags.keep_left_margin = false; page_c = layout_work.defaults.columns; ds = ProcFlags.doc_sect_nxt; // new section if( ds == doc_sect_none ) { ds = doc_sect_body; // if text without section start assume body } /***********************************************************************/ /* process special section attributes */ /***********************************************************************/ switch( ds ) { case doc_sect_titlep : page_c = layout_work.titlep.columns; page_e = ej_yes; page_r = false; // no page number reset header = false; // no header string (ABSTRACT, ... ) output init_nest_cb(); nest_cb->p_stack = copy_to_nest_stack(); nest_cb->c_tag = t_TITLEP; nest_cb->p_stack->lineno = titlep_lineno; // correct line number break; case doc_sect_abstract : page_c = layout_work.abstract.columns; page_e = layout_work.abstract.page_eject; page_r = layout_work.abstract.page_reset; page_s = layout_work.hx.hx_sect[hds_abstract].spacing; header = layout_work.hx.hx_sect[hds_abstract].header; if( header ) { h_text = &layout_work.abstract.string; hds_lvl = hds_abstract; } break; case doc_sect_preface : page_c = layout_work.preface.columns; page_e = layout_work.preface.page_eject; page_r = layout_work.preface.page_reset; page_s = layout_work.hx.hx_sect[hds_preface].spacing; header = layout_work.hx.hx_sect[hds_preface].header; if( header ) { h_text = &layout_work.preface.string; hds_lvl = hds_preface; } break; case doc_sect_body : page_c = layout_work.body.columns; page_e = layout_work.body.page_eject; page_r = layout_work.body.page_reset; page_s = layout_work.hx.hx_sect[hds_body].spacing; header = layout_work.hx.hx_sect[hds_body].header; if( header ) { h_text = &layout_work.body.string; hds_lvl = hds_body; } break; case doc_sect_appendix : page_c = layout_work.appendix.columns; page_e = layout_work.appendix.section_eject; page_r = layout_work.appendix.page_reset; page_s = layout_work.hx.hx_sect[hds_appendix].spacing; header = false; // no section header string output, as such if( page_e != ej_no ) { page_e = ej_yes; // "even" and "odd" act like "yes" } for( k = 1; k < hds_appendix; k++ ) { // reset heading levels hd_nums[k].headn = 0; if( hd_nums[k].headnsub != NULL ) { *(hd_nums[k].headnsub->value) = '\0'; } } break; case doc_sect_backm : page_c = layout_work.backm.columns; page_e = layout_work.backm.page_eject; page_r = layout_work.backm.page_reset; page_s = layout_work.hx.hx_sect[hds_backm].spacing; header = layout_work.hx.hx_sect[hds_backm].header; if( header ) { h_text = &layout_work.backm.string; hds_lvl = hds_backm; } break; case doc_sect_index : page_c = layout_work.index.columns; page_e = layout_work.index.page_eject; page_r = layout_work.index.page_reset; page_s = layout_work.hx.hx_sect[hds_index].spacing; header = layout_work.hx.hx_sect[hds_index].header; if( header ) { h_text = &layout_work.index.index_string; hds_lvl = hds_index; } break; case doc_sect_gdoc : case doc_sect_etitlep : case doc_sect_frontm : page_c = layout_work.defaults.columns; page_e = ej_no; // no page eject page_r = false; // no page number reset page_s = layout_work.defaults.spacing; // default spacing header = false; // no section header break; case doc_sect_egdoc : page_c = layout_work.defaults.columns; page_e = ej_yes; page_r = false; // no page number reset page_s = layout_work.defaults.spacing; // default spacing header = false; // no section header break; default: internal_err( __FILE__, __LINE__ ); break; } if( first_section ) { // nothing precedes the first section if( page_e == ej_even ) { do_page_out(); // apage of first page is odd page = 0; // restart page for first text page ProcFlags.page_ejected = true; } set_section_banners( ds ); reset_t_page(); document_new_position(); // first text page ready for content } else if( page_e == ej_no ) { full_page_out(); // ensure are on last page ProcFlags.page_ejected = false; set_section_banners( ds ); reset_bot_ban(); } else { last_page_out(); // ensure last page output ProcFlags.page_ejected = true; // only first section has nothing to output if( page_e == ej_odd ) { if( (page & 1) ) { // first page will be odd do_page_out(); // emit blank page } } else if( page_e == ej_even ) { if( !(page & 1) ) { // first page will be even do_page_out(); // emit blank page } } else if( page_e != ej_yes ) { internal_err( __FILE__, __LINE__ ); } g_skip = 0; // ignore remaining skip value set_section_banners( ds ); reset_t_page(); } ProcFlags.doc_sect = ds; t_page.col_count = page_c; set_cols(); if( page_r ) { page = 0; } spacing = page_s; g_cur_left = g_page_left_org; if( header ) { line_position = pos_center; concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; gen_heading( h_text, NULL, 0, hds_lvl ); g_indent = 0; // reset for section body ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; } g_curr_font = layout_work.defaults.font; g_cur_h_start = g_page_left_org + g_indent; ProcFlags.doc_sect = ds; }
static void gen_figlist( void ) { char buffer[11]; char postfix[12]; ffh_entry * curr; uint32_t size; if( fig_list == NULL ) return; // no fig_list, no FIGLIST /* Insert FIGLIST into current section */ last_page_out(); // ensure are on new page g_skip = 0; // ignore remaining skip value set_section_banners( doc_sect_figlist ); reset_t_page(); /* Set FIGLIST margins and other values */ g_page_left = g_page_left_org + 2 * conv_hor_unit( &layout_work.figlist.left_adjust, g_curr_font ); // matches wgml 4.0 g_page_right = g_page_right_org - conv_hor_unit( &layout_work.figlist.right_adjust, g_curr_font ); size = conv_hor_unit( &layout_work.flpgnum.size, g_curr_font ); // space from fill to right edge figlist_toc_tabs( layout_work.figlist.fill_string, size ); /* Output FIGLIST */ concat_save = ProcFlags.concat; ProcFlags.concat = true; justify_save = ProcFlags.justify; ProcFlags.justify = ju_off; ProcFlags.keep_left_margin = true; // keep all indents while outputting text curr = fig_list; while( curr != NULL ) { if( curr->flags & ffh_figcap ) { // no FIGCAP used, no FIGLIST output g_curr_font = FONT0; // wgml 4.0 uses font 0 if( ProcFlags.page_started ) { // not on first entry spacing = layout_work.figlist.spacing; set_skip_vars( NULL, NULL, NULL, spacing, g_curr_font ); } g_cur_left = g_page_left; g_cur_h_start = g_cur_left; process_text( curr->prefix, g_curr_font ); // caption prefix if( curr->text != NULL ) { g_cur_left = t_line->last->x_address + t_line->last->width + wgml_fonts[g_curr_font].spc_width; g_cur_h_start = g_cur_left; ProcFlags.ct = true; // emulate CT ProcFlags.stop_xspc = true; // suppress 2nd space after stops post_space = 0; g_page_right -= size; if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right -= tab_col; } else { g_page_right -= 3 * tab_col; } if( !ProcFlags.page_started ) { // first entry wrapping spacing = layout_work.figlist.spacing; } set_skip_vars( &layout_work.figlist.skip, NULL, NULL, spacing, g_curr_font ); process_text( curr->text, g_curr_font );// caption text if( ProcFlags.has_aa_block ) { // matches wgml 4.0 g_page_right += tab_col; } else { g_page_right += 3 * tab_col; } g_page_right += size; } ProcFlags.ct = true; // emulate CT g_curr_font = FONT0; process_text( "$", g_curr_font ); format_num( curr->pageno, &buffer, sizeof( buffer ), curr->style ); strcpy_s( postfix, 12, "$" ); // insert tab characters strcat_s( postfix, 12, buffer ); // append page number g_curr_font = layout_work.flpgnum.font; process_text( postfix, g_curr_font ); } scr_process_break(); // ensure line break curr = curr->next; } ProcFlags.concat = concat_save; ProcFlags.justify = justify_save; /* Re-establish current section */ last_page_out(); // ensure all pages output set_section_banners( ProcFlags.doc_sect ); reset_t_page(); return; }