void gml_index( gml_tag gtag ) { gtag = gtag; if( ProcFlags.doc_sect_nxt == doc_sect_egdoc ) { xx_line_err( err_eof_expected, tok_start ); return; } if( ProcFlags.doc_sect_nxt == doc_sect_index ) {// duplicate :INDEX tag scan_start = scan_stop; // ignore this call return; // wgml4 OS/2 crashes with page fault } if( !((ProcFlags.doc_sect == doc_sect_backm) || (ProcFlags.doc_sect_nxt == doc_sect_backm)) ) { xx_line_err( err_doc_sec_expected_1, tok_start ); return; } if( !GlobalFlags.index ) { // index option not active g_err( wng_index_opt ); // give hint to activate index scan_start = scan_stop; return; } gml_doc_xxx( doc_sect_index ); gen_index(); // output the formatted index }
bool lay_init_su( const char *p, su *in_su ) { bool cvterr = true; const char *pa = NULL; // start of value text char *ps = NULL; // destination for value text char sign; size_t len; su *s; s = in_su; pa = p; ps = s->su_txt; *ps = '\0'; while( *p && (*p == ' ' ) ) { // just in case p++; } while( *p && (*p != ' ' ) ) { p++; } len = p - pa; if( (len + 1) > MAX_SU_CHAR ) { // won't fit xx_line_err( err_inv_att_val, val_start ); scan_start = scan_stop; return( cvterr ); } memcpy( ps, pa, len ); ps[len] = '\0'; s->su_u = SU_undefined; if( *ps == '+' ) { // not allowed with tags xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } else if( *ps == '-' ) { // not relative, just negative sign = *ps; if( *(ps + 1) == '+' || *(ps + 1) == '-' ) { // only one sign is allowed xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } } else { sign = '+'; } if( !*ps ) { // value end reached, not valid xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } s->su_relative = false; // no relative positioning with tags if( su_layout_special( in_su ) ) { cvterr = false; } else { cvterr = internal_to_su( in_su, true, pa ); } return( cvterr ); }
extern void gml_titlep( const gmltag * entry ) { if( ProcFlags.doc_sect_nxt == doc_sect_egdoc ) { xx_line_err( err_eof_expected, tok_start ); return; } if( !ProcFlags.frontm_seen ) { xx_line_err( err_doc_sec_expected_1, tok_start ); return; } scr_process_break(); gml_doc_xxx( doc_sect_titlep ); add_symvar( &global_dict, "$stitle", "", no_subscript, 0 );// set nullstring add_symvar( &global_dict, "$title", "", no_subscript, 0 );// set nullstring rs_loc = titlep_tag; if( input_cbs->fmflags & II_file ) { // save line number titlep_lineno = input_cbs->s.f->lineno; } else if( input_cbs->fmflags & II_tag_mac ) { titlep_lineno = input_cbs->s.m->lineno; } else { titlep_lineno = 0; // not clear what to do here } save_indent = g_indent; save_indentr = g_indentr; g_indent = 0; g_indentr = 0; set_h_start(); }
extern void gml_index( const gmltag * entry ) { if( ProcFlags.doc_sect_nxt == doc_sect_egdoc ) { xx_line_err( err_eof_expected, tok_start ); return; } if( ProcFlags.doc_sect_nxt == doc_sect_index ) {// duplicate :INDEX tag scan_start = scan_stop + 1; // ignore this call return; // wgml4 OS/2 crashes with page fault } if( !((ProcFlags.doc_sect == doc_sect_backm) || (ProcFlags.doc_sect_nxt == doc_sect_backm)) ) { xx_line_err( err_doc_sec_expected_1, tok_start ); return; } if( !GlobalFlags.index ) { // index option not active return; } scr_process_break(); gml_doc_xxx( doc_sect_index ); /* When gen_index() is finalized, the resets may need to be moved */ g_indent = 0; g_indentr = 0; set_h_start(); /// I suspect start_doc_sect() will be needed here! gen_index(); // output the formatted index }
void gml_titlep( gml_tag gtag ) { gtag = gtag; if( ProcFlags.doc_sect_nxt == doc_sect_egdoc ) { xx_line_err( err_eof_expected, tok_start ); return; } if( !ProcFlags.frontm_seen ) { xx_line_err( err_doc_sec_expected_1, tok_start ); return; } gml_doc_xxx( doc_sect_titlep ); g_spacing_ln = layout_work.titlep.spacing; add_symvar( &global_dict, "$stitle", "", no_subscript, 0 );// set nullstring add_symvar( &global_dict, "$title", "", no_subscript, 0 );// set nullstring rs_loc = titlep_tag; if( input_cbs->fmflags & II_file ) { // save line number titlep_lineno = input_cbs->s.f->lineno; } else if( input_cbs->fmflags & II_tag_mac ) { titlep_lineno = input_cbs->s.m->lineno; } else { titlep_lineno = 0; // not clear what to do here } }
extern void gml_abstract( const gmltag * entry ) { if( ProcFlags.doc_sect_nxt == doc_sect_egdoc ) { xx_line_err( err_eof_expected, tok_start ); return; } if( !ProcFlags.frontm_seen ) { xx_line_err( err_doc_sec_expected_1, tok_start ); return; } if( blank_lines > 0 ) { set_skip_vars( NULL, NULL, NULL, 0, 0 ); // set g_blank_lines } scr_process_break(); gml_doc_xxx( doc_sect_abstract ); g_cur_left = g_page_left; g_cur_h_start = g_page_left; if( layout_work.hx.hx_sect[hds_abstract].header ) { start_doc_sect(); // a header is enough } g_indent = 0; g_indentr = 0; set_h_start(); }
bool att_val_to_su( su * in_su, bool pos ) { bool cvterr = true; char * ps = NULL; // destination for value text char sign; su * s; s = in_su; ps = s->su_txt; *ps = '\0'; if( (val_len + 1) > MAX_SU_CHAR ) { // won't fit xx_line_err( err_inv_att_val, val_start ); scan_start = scan_stop; return( cvterr ); } memcpy( ps, val_start, val_len ); ps[val_len] = '\0'; s->su_u = SU_undefined; if( *ps == '+' ) { // not allowed with tags xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } else if( *ps == '-' ) { // not relative, just negative if( pos ) { // value must be positive xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } sign = *ps; if( *(ps + 1) == '+' || *(ps + 1) == '-' ) { // only one sign is allowed xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } } else { sign = '+'; } if( !*ps ) { // value end reached, not valid xx_line_err( err_inv_att_val, ps ); scan_start = scan_stop; return( cvterr ); } s->su_relative = false; // no relative positioning with tags if( su_layout_special( in_su ) ) { cvterr = false; } else { cvterr = internal_to_su( in_su, true, val_start ); } return( cvterr ); }
void scr_cw( void ) { char * pa; char * p; int len; 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 > 2 ) { xx_line_err( err_inv_cw_sep, pa ); return; } else if( len > 0 ) { // 1 char or 2 hex characters CW_sep_char = parse_char( pa, len ); } else { CW_sep_char = '\0'; } add_to_sysdir( "$cw", CW_sep_char ); scan_restart = pa + len; return; }
void gml_preface( gml_tag gtag ) { gtag = gtag; if( ProcFlags.doc_sect_nxt == doc_sect_egdoc ) { xx_line_err( err_eof_expected, tok_start ); return; } if( !ProcFlags.frontm_seen ) { xx_line_err( err_doc_sec_expected_1, tok_start ); return; } if( g_blank_lines_ln > 0 ) { set_skip_vars( NULL, NULL, NULL, 0, 0 ); // set g_blank_lines } scr_process_break(); gml_doc_xxx( doc_sect_preface ); g_spacing_ln = layout_work.preface.spacing; }
bool cw_val_to_su( char * * scanp, su * in_su ) { bool cvterr = true; char * p = NULL; // source of value text char * pa = NULL; // start of value text char * ps = NULL; // destination for value text char sign; size_t len; su * s; s = in_su; p = *scanp;; pa = p; ps = s->su_txt; *ps = '\0'; while( *p && (*p == ' ' ) ) { // just in case p++; } while( *p && (*p != ' ' ) ) { p++; } len = p - pa; *scanp = p; // report back value of p if( (len + 1) > MAX_SU_CHAR ) { xx_line_err( err_inv_cw_op_val, val_start ); scan_start = scan_stop; return( cvterr ); } memcpy( ps, pa, len ); ps[len] = '\0'; s->su_u = SU_undefined; if( *ps == '+' || *ps == '-' ) { sign = *ps; s->su_relative = true; // value is added / subtracted from old value } else { sign = '+'; s->su_relative = false; // value replaces old value } if( su_expression( in_su ) ) { cvterr = false; } else { cvterr = internal_to_su( in_su, false, pa ); } return( cvterr ); }
char * get_att_value( char * p ) { char quote; ProcFlags.tag_end_found = false; quote_char = '\0'; val_start = NULL; val_len = 0; while( *p == ' ' ) { // over WS to '=' p++; } if( *p == '=' ) { p++; while( *p == ' ' ) { // over WS to value p++; } } else { if( *p == '.' ) { ProcFlags.tag_end_found = true; } xx_line_err( err_eq_missing, p ); scan_start = scan_stop; return( p ); } if( (*p == '\0') || (*p == '.') ) { // value is missing if( *p == '.' ) { ProcFlags.tag_end_found = true; } xx_line_err( err_att_val_missing, p ); scan_start = scan_stop; return( p ); } if( *p == '"' || *p == '\'' ) { quote = *p; quote_char = *p; ++p; val_start = p; while( *p ) { if( *p == quote ) { if( *(p + 1) != quote ) { break; } { // this should almost never be used char * q; char * r; q = p; r = p + 1; while( *r ) { *q = *r; q++; r++; } } } ++p; } val_len = p - val_start; // up to (not including) final quote if( *p != quote ) { // terminating quote not found xx_line_err( err_att_val_open, val_start - 1 ); scan_start = scan_stop; return( p ); } ++p; // over final quote } else { val_start = p; while( *p && *p != ' ' && *p != '.' ) { ++p; } val_len = p - val_start; } if( *p == '.' ) { ProcFlags.tag_end_found = true; } return( p ); }
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 }
void gml_docnum( const gmltag * entry ) { char * p; doc_element * cur_el; text_line * p_line; int8_t d_spacing; font_number font_save; int32_t rc; symsub * docnumval; if( !((ProcFlags.doc_sect == doc_sect_titlep) || (ProcFlags.doc_sect_nxt == doc_sect_titlep)) ) { g_err( err_tag_wrong_sect, entry->tagname, ":TITLEP section" ); err_count++; show_include_stack(); } if( ProcFlags.docnum_tag_seen ) { // only one DOCNUM tag allowed xx_line_err( err_2nd_docnum, buff2 ); } ProcFlags.docnum_tag_seen = true; p = scan_start; if( *p && *p == '.' ) p++; // over . to docnum while( *p == ' ' ) { // over WS to attribute p++; } rc = find_symvar( &sys_dict, "$docnum", no_subscript, &docnumval ); if( *p ) { // docnum specified strcpy_s( docnumval->value, 60, p ); } else { *(docnumval->value) = 0; } start_doc_sect(); // if not already done p_line = alloc_text_line(); p_line->line_height = wgml_fonts[layout_work.docnum.font].line_height; prep_docnum_line( p_line, docnumval->value ); d_spacing = layout_work.titlep.spacing; font_save = g_curr_font; g_curr_font = layout_work.docnum.font; /************************************************************/ /* pre_skip is treated as pre_top_skip because it is */ /* always used at the top of the page, despite the docs */ /************************************************************/ set_skip_vars( NULL, &layout_work.docnum.pre_skip, NULL, d_spacing, g_curr_font ); cur_el = alloc_doc_el( el_text ); cur_el->blank_lines = g_blank_lines; g_blank_lines = 0; cur_el->depth = p_line->line_height + g_spacing; cur_el->subs_skip = g_subs_skip; cur_el->top_skip = g_top_skip; cur_el->element.text.overprint = ProcFlags.overprint; ProcFlags.overprint = false; cur_el->element.text.spacing = g_spacing; cur_el->element.text.first = p_line; ProcFlags.skips_valid = false; p_line = NULL; insert_col_main( cur_el ); g_curr_font = font_save; scan_start = scan_stop + 1; }
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 }
void scr_tb( void ) { bool relative; char * p; char * pa; char * pb; char quote; condcode cc; getnum_block t_pos; int i; int len; p = scan_start; while( *p && (*p != ' ') ) { // over tb p++; } while( *p && (*p == ' ') ) { // first token p++; } pa = p; while( *p && (*p != ' ') ) { // token end p++; } len = p - pa; if( (len > 0) && !memicmp( pa , "set", len ) ) { while( *p && (*p == ' ') ) { // tab char p++; } pa = p; while( *p && (*p != ' ') ) { // end tab char p++; } len = p - pa; if( len == 0 ) { tab_char = 0x09; // reset to default value } else if( len == 1 ) { tab_char = *pa; // set to specified char } else { xx_line_err( err_tab_char, pa ); } add_to_sysdir( "$tb", tab_char ); add_to_sysdir( "$tab", tab_char ); while( *p && (*p == ' ') ) { // end of line p++; } pa = p; while( *p && (*p != ' ') ) { // end of line p++; } len = p - pa; // should be "0" if( len != 0 ) { xx_line_err( err_tab_char, pa ); } } else { user_tabs.current = 0; // clear user_tabs p = pa; // reset to start of first tab while( *p ) { // tab stop start if( user_tabs.current == user_tabs.length) { user_tabs.length += TAB_COUNT; // add space for new tab stops user_tabs.tabs = mem_realloc( user_tabs.tabs, user_tabs.length * sizeof( tab_stop ) ); } i = user_tabs.current; // initialize (not done elsewhere) user_tabs.tabs[i].column = 0; user_tabs.tabs[i].fill_char = ' '; user_tabs.tabs[i].alignment = al_left; quote = ' '; pa = p; // Parse fill chars/strings if( (*p != '+') && !isdigit(*p) ) { // potential fill char if( (*p == '\'') || (*p == '"') || (*p == '/') ) { quote = *p; // initial quote found p++; // should be fill char if( !*p || (*p == ' ') || (*p == '+') || isdigit(*p) ) { // ' " or / only before tab stop position xx_line_err( err_right_delim, pa ); continue; } } user_tabs.tabs[i].fill_char = *p; pb = p; // save position if not fill char p++; // should be end delimiter if( !*p ) { // 'c "c or /c only xx_line_err( err_right_delim, pa ); continue; } /* fill strings are not allowed -- yet */ if( ((quote == ' ') && (*p == '/')) || ((quote != ' ') && (*p == quote)) ) { p++; // final quote found } else { if( quote != ' ' ) {// quoted value started while( *p ) { // find final quote if( *p == quote ) { break; } p++; } if( *p == quote ) { // found: fill string xx_line_err( err_tab_fill_string, pa ); user_tabs.tabs[i].fill_char = ' '; } else if( *p ) { // not found: format error xx_line_err( err_right_delim, pa ); user_tabs.tabs[i].fill_char = ' '; } } else { // format error xx_line_err( err_inv_text_before_tab, pa ); user_tabs.tabs[i].fill_char = ' '; p = pb; // restore position: not fill char } } } // Parse the tab stop position while( *p && (*p == ' ') ) { p++; } pa = p; // tab position start t_pos.ignore_blanks = false; t_pos.argstart = p; while( *p && (*p != ' ') ) { // tab position end plus 1 p++; } if( *p && (p > pa) ) { // as needed by getnum p--; // *p is last character of tab stop } while( (p != pa) && !isdigit( *p ) ) { // back up over alignment p--; } pb = p + 1; t_pos.argstop = p; cc = getnum( &t_pos ); p = pb; // alignment start if( t_pos.num_sign == ' ' ) { relative = false; } else { if( t_pos.num_sign == '+' ) { relative = true; } else { xx_line_err( err_inv_tab_stop, pa ); } } if( cc == notnum ) { xx_line_err( err_inv_text_before_tab, pa ); } else { if( t_pos.result <= 0 ) { if( relative ) { xx_line_err( err_tab_stop_order, pa ); } else { xx_line_err( err_inv_tab_stop, pa ); } } else { if( relative && ( i > 0) ) { t_pos.result *= tab_col; user_tabs.tabs[i].column = user_tabs.tabs[i-1].column + t_pos.result; } else { t_pos.result --; t_pos.result *= tab_col; user_tabs.tabs[i].column = t_pos.result; } } if( !relative && (i > 0) ) { if( user_tabs.tabs[i].column <= user_tabs.tabs[i-1].column ) { xx_line_err( err_tab_stop_order, pa ); } } user_tabs.current++; } // Parse the alignment user_tabs.tabs[i].alignment = al_left; if( *p && (*p != ' ') ) { // space ends tab stop /* alignment characters are not allowed -- yet */ pa = p; // potential alignment start if( (*p == 'c') || (*p == 'C') ) { user_tabs.tabs[i].alignment = al_center; p++; } else if( (*p == 'l') || (*p == 'L') ) { user_tabs.tabs[i].alignment = al_left; p++; } else if( (*p == 'r') || (*p == 'R') ) { user_tabs.tabs[i].alignment = al_right; p++; } else if( *p == '\'' ) { // possible alignment character p++; if( !*p || (*p != ' ') ) { // not end of tab stop if( !*p ) { // ' only xx_line_err( err_right_delim, pa ); } p++; if( !*p ) { // 'c only xx_line_err( err_right_delim, pa ); } else if( *p == '\'' ) { // definite alignment character xx_line_err( err_tab_align_char, pa ); } else { // 'cc with or without more text xx_line_err( err_right_delim, pa ); } } else { // something else xx_line_err( err_inv_text_after_tab, pa ); } p++; } else { // something else xx_line_err( err_inv_text_after_tab, pa ); p++; } } if( *p != ' ' ) { while( *p && (*p != ' ') ) { // find end of tab stop p++; } } while( *p && (*p == ' ') ) { // find next tab position p++; } } } scan_restart = scan_stop + 1; return; }
void gml_date( gml_tag gtag ) { char * p; doc_element * cur_el; text_line * p_line; spacing_line spacing_ln; font_number font_save; if( !((ProcFlags.doc_sect == doc_sect_titlep) || (ProcFlags.doc_sect_nxt == doc_sect_titlep)) ) { g_err( err_tag_wrong_sect, gml_tagname( gtag ), ":TITLEP section" ); err_count++; show_include_stack(); } if( ProcFlags.date_tag_seen ) { // only one DATE tag allowed xx_line_err( err_2nd_date, buff2 ); } ProcFlags.date_tag_seen = true; p = scan_start; if( *p && *p == '.' ) p++; // over . to docnum while( *p == ' ' ) { // over WS to attribute p++; } if( *p ) { // date specified add_symvar( &global_dict, "date", p, no_subscript, 0 ); } start_doc_sect(); // if not already done p_line = alloc_text_line(); p_line->line_height = wgml_fonts[layout_work.docnum.font].line_height; prep_date_line( p_line, p ); spacing_ln = layout_work.titlep.spacing; font_save = g_curr_font; g_curr_font = layout_work.date.font; /************************************************************/ /* pre_skip is treated as pre_top_skip because it is */ /* always used at the top of the page, despite the docs */ /************************************************************/ set_skip_vars( NULL, &layout_work.date.pre_skip, NULL, spacing_ln, g_curr_font ); cur_el = alloc_doc_el( el_text ); cur_el->depth = p_line->line_height + g_spacing; cur_el->subs_skip = g_subs_skip; cur_el->top_skip = g_top_skip; cur_el->element.text.overprint = ProcFlags.overprint; ProcFlags.overprint = false; cur_el->element.text.spacing = g_spacing; cur_el->element.text.first = p_line; ProcFlags.skips_valid = false; p_line = NULL; insert_col_main( cur_el ); g_curr_font = font_save; scan_start = scan_stop; }
bool att_val_to_SU( su * converted, bool pos ) { bool converterror = true; bool is_cp = false; char * p = NULL; // source of value text char * pd = NULL; // ptr to decimal point char * pd1 = NULL; // ptr to 0.1 decimal char * pdn = NULL; // ptr to last digit +1 char * ps = NULL; // destination for value text char * pu = NULL; // ptr to trailing unit char sign; char unit[4]; int i; ldiv_t div; long k; long wh; long wd; su * s; if( (val_len + 1) > MAX_SU_CHAR ) { // won't fit xx_line_err( err_inv_att_val, val_start ); scan_start = scan_stop + 1; return( converterror ); } unit[3] = '\0'; unit[2] = '\0'; unit[1] = '\0'; unit[0] = '\0'; s = converted; p = val_start; ps = s->su_txt; *ps = '\0'; wd = 0; wh = 0; s->su_u = SU_undefined; if( *p == '+' ) { // not allowed with tags xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } else if( *p == '-' ) { // not relative, just negative if( pos ) { // value must be positive xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } sign = *p; *ps++ = *p++; if( *p == '+' || *p == '-' ) { // only one sign is allowed xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } } else { sign = '+'; } if( (p - val_start) >= val_len ) { // value end reached, not valid xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } s->su_relative = false; // no relative positioning with tags /***********************************************************************/ /* Special for layout :BANREGION */ /***********************************************************************/ if( isalpha( *p ) ) { converterror = su_layout_special( &p, converted ); if( !converterror ) { return( converterror ); // layout special ok } } for( i = 0; i < 4; i++ ) { // max four digits in whole part if( (*p >= '0') && (*p <= '9') ) { wh = (10 * wh) + (*p - '0'); *ps++ = *p++; } else { break; } if( (p - val_start) > val_len ) { // value end reached break; } } if( (*p >= '0') && (*p <= '9') ) { // too many digits in whole part xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } if( ((p - val_start) < val_len) && *p == '.' ) { // check for decimal point pd = p; *ps++ = *p++; pd1 = p; // remember start of decimals for( i = 0; i < 2; i++ ) { // max two digits in decimals if( (*p >= '0') && (*p <= '9') ) { wd = 10 * wd + *p - '0'; *ps++ = *p++; } else { break; } if( (p - val_start) > val_len ) { // value end reached break; } } pdn = p; if( pd1 == p ) { // no decimals pd1 = NULL; pdn = NULL; } if( (*p >= '0') && (*p <= '9') ) { // too many digits in decimals xx_line_err( err_inv_att_val, pdn ); scan_start = scan_stop + 1; return( converterror ); } } k = 0; pu = p; for( i = 0; i < 2; i++ ) { // max two characters in unit if( *p && isalpha( *p ) ) { unit[k++] = tolower( *p ); // save Unit *ps++ = *p++; } else { break; } if( (p - val_start) > val_len ) { // value end reached break; } } if( *p && isalpha( *p ) ) { // too many characters in unit xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } /***********************************************************************/ /* check for valid unit */ /***********************************************************************/ if( unit[1] == '\0' ) { // single letter unit switch( unit[0] ) { case 'i' : s->su_u = SU_inch; break; case 'm' : s->su_u = SU_ems; if( pd != NULL ) { // no decimals with "M" xx_line_err( err_inv_att_val, pd ); scan_start = scan_stop + 1; return( converterror ); } break; case 'c' : s->su_u = SU_cicero; is_cp = true; break; case 'p' : s->su_u = SU_pica; is_cp = true; break; case '\0' : // no unit is characters or lines s->su_u = SU_chars_lines; break; default: xx_line_err( err_inv_att_val, pu ); scan_start = scan_stop + 1; return( converterror ); break; } } else { // two letter unit if( unit[1] == 'm' ) { // cm, mm ? if( unit[0] == 'c' ) { s->su_u = SU_cm; } else if( unit[0] == 'm' ) { s->su_u = SU_mm; } else { // invalid unit xx_line_err( err_inv_att_val, pu ); scan_start = scan_stop + 1; return( converterror ); } } else if( unit[0] == 'd' ) { // dv ? if( unit[1] == 'v' ) { s->su_u = SU_dv; } } else { // invalid unit xx_line_err( err_inv_att_val, pu ); scan_start = scan_stop + 1; return( converterror ); } } if( is_cp ) { // "C" and "P" can be followed by max four digits for( i = 0; i < 4; i++ ) { if( (*p >= '0') && (*p <= '9') ) { wd = (10 * wd) + (*p - '0'); *ps++ = *p++; } if( (p - val_start) > val_len ) { // value end reached break; } } } if( (*p >= '0') && (*p <= '9') ) { // too many digits after "C" or "P" xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } *ps = '\0'; if( (p - val_start) < val_len ) { // value continues on: it shouldn't xx_line_err( err_inv_att_val, p ); scan_start = scan_stop + 1; return( converterror ); } s->su_whole = wh; s->su_dec = wd; if( k == 0 ) { // no trailing unit pu = NULL; } if( pd != NULL ) { // dec point found if( pu == NULL ) { // need trailing unit xx_line_err( err_inv_att_val, pd ); scan_start = scan_stop + 1; return( converterror ); } } s->su_inch = 0; s->su_mm = 0; k = 1; if( pd1 != NULL ) { if( pdn - pd1 == 1 ) { k = 10; // only 0.1 digit } } switch( s->su_u ) { // the relative units are only stored, not converted case SU_chars_lines : case SU_ems : case SU_dv : break; case SU_inch : // inch, cm, mm valid with decimals s->su_mm = (wh * 100L + wd * k) * 2540L; s->su_inch = (wh * 100L + wd * k) * 100L; break; case SU_cm : s->su_mm = (wh * 100L + wd * k) * 1000L; s->su_inch = s->su_mm * 10L / 254L; break; case SU_mm : s->su_mm = (wh * 100L + wd * k) * 100L; s->su_inch = s->su_mm * 10L / 254L; break; case SU_cicero : // cicero if( wd > 11 ) { div = ldiv( wd, 12L); wh += div.quot; wd = div.rem; } s->su_inch = wh * 10000L / 6L + wd * 10000L / 72L; s->su_inch = (int64_t)s->su_inch * 10656L / 10000L; s->su_mm = s->su_inch * 254L / 10L; break; case SU_pica : // pica if( wd > 11 ) { div = ldiv( wd, 12L); wh += div.quot; wd = div.rem; } s->su_inch = wh * 10000L / 6L + wd * 10000L / 72L; s->su_inch = (int64_t)s->su_inch * 9978L / 10000L; s->su_mm = s->su_inch * 254L / 10L; break; default: break; } if( sign == '-' ) { s->su_inch = -s->su_inch; s->su_mm = -s->su_mm; s->su_whole = -s->su_whole; } converterror = false; return( converterror ); }