int ib_trans_line( /*****************/ section_def *section, int alloc_size ) { char *ptr; char *end; int ch; char *ctx_name; char *ctx_text; char buf[ 100 ]; int indent = 0; int ctr; char *file_name; // check for special pre-processing stuff first ptr = Line_buf; ch = *(unsigned char *)ptr; // We start at a new line... Wrap_Safe = section->section_size; Cursor_X = 0; R_Chars = 0; if( Blank_line && ( ch != CH_LIST_ITEM || Curr_list->compact != LIST_SPACE_COMPACT ) ) { Blank_line = FALSE; } switch( ch ) { // Tabbed-example case CH_TABXMP: if( *skip_blank( ptr + 1 ) == '\0' ) { Tab_xmp = FALSE; } else { read_tabs( ptr + 1 ); Tab_xmp = TRUE; } return( alloc_size ); // Box-mode start case CH_BOX_ON: ctr = 0; // indent properly while( ctr < Curr_indent ) { ctr++; trans_add_char( ' ', section, &alloc_size); } // draw the top line of the box trans_add_char( BOX_CORNER_TOP_LEFT, section, &alloc_size ); for( ctr = 1; ctr <= Right_Margin - Curr_indent - 2; ctr++ ) { trans_add_char( BOX_HBAR, section, &alloc_size ); } trans_add_char( BOX_CORNER_TOP_RIGHT, section, &alloc_size ); trans_add_char_wrap( '\n', section, &alloc_size); Box_Mode = TRUE; return( alloc_size ); case CH_BOX_OFF: ctr = 0; while( ctr < Curr_indent ) { ctr++; trans_add_char( ' ', section, &alloc_size); } trans_add_char( BOX_CORNER_BOTOM_LEFT, section, &alloc_size ); for( ctr = 1; ctr <= Right_Margin - Curr_indent - 2; ctr++ ) { trans_add_char( BOX_HBAR, section, &alloc_size ); } trans_add_char( BOX_CORNER_BOTOM_RIGHT, section, &alloc_size ); Box_Mode = FALSE; trans_add_char_wrap( '\n', section, &alloc_size ); return( alloc_size ); case CH_OLIST_START: new_list( LIST_TYPE_ORDERED ); set_compact( ptr ); Curr_indent += Text_Indent; return( alloc_size ); case CH_LIST_START: case CH_DLIST_START: new_list( ( ch == CH_LIST_START ) ? LIST_TYPE_UNORDERED : LIST_TYPE_DEFN ); set_compact( ptr ); Curr_indent += Text_Indent; if( ch == CH_DLIST_START ) { ptr = skip_blank( ptr + 1 ); if( *ptr != '\0' ) { /* due to a weakness in GML, the definition term must be allowed on the same line as the definition tag. So if its there, continue */ break; } } return( alloc_size ); case CH_DLIST_TERM: Curr_indent -= Text_Indent; break; case CH_SLIST_START: indent = 0; if( Curr_list->type == LIST_TYPE_SIMPLE ) { /* nested simple lists, with no pre-indent. Force an indent */ indent = Text_Indent; } new_list( LIST_TYPE_SIMPLE ); set_compact( ptr ); Curr_indent += indent; return( alloc_size ); case CH_SLIST_END: case CH_OLIST_END: case CH_LIST_END: case CH_DLIST_END: pop_list(); return( alloc_size ); case CH_DLIST_DESC: Curr_indent += Text_Indent; if( *skip_blank( ptr + 1 ) == '\0' ) { /* no description on this line. Ignore it so that no blank line gets generated */ return( alloc_size ); } break; case CH_CTX_KW: ptr = whole_keyword_line( ptr ); if( ptr == NULL ) { return( alloc_size ); } break; } // skip preceding blank lines if( *skip_blank( ptr ) == '\0' && Curr_ctx->empty ) { return( alloc_size ); } // remove '\n' on the end if( Blank_line ) { --section->section_size; } // indent properly if the first char is not white-space if( ch != '\0' && ch != ' ' && ch != '\t') { ctr = ( ch == CH_LIST_ITEM && !Box_Mode && Curr_list->type != LIST_TYPE_SIMPLE ) ? Text_Indent : 0; while( ctr < Curr_indent ) { ctr++; trans_add_char_wrap( ' ', section, &alloc_size); } if( Box_Mode ) { trans_add_char_wrap( BOX_VBAR, section, &alloc_size); trans_add_char_wrap( ' ', section, &alloc_size); } } Blank_line = TRUE; for( ;; ) { ch = *(unsigned char *)ptr; if( ch != '\0' && ( ch != ' ' || ch != '\t' ) ) { Blank_line = FALSE; } if( ch == '\0' ) { // this just shuts off bolding after a def. list term if( Line_postfix == LPOSTFIX_TERM ) { Line_postfix = LPOSTFIX_NONE; trans_add_str( STR_BOLD_OFF, section, &alloc_size ); } trans_add_char_wrap( '\n', section, &alloc_size ); break; } else if( ch == CH_HLINK || ch == CH_DFN || ch == CH_FLINK ) { Curr_ctx->empty = FALSE; if( ch == CH_FLINK ) { file_name = strchr( ptr + 1, ch ); if( file_name == NULL ) { error( ERR_BAD_LINK_DFN, TRUE ); } *file_name = '\0'; } else { file_name = ptr; } ctx_name = strchr( file_name + 1, ch ); if( ctx_name == NULL ) { error( ERR_BAD_LINK_DFN, TRUE ); } *ctx_name = '\0'; ctx_text = strchr( ctx_name + 1, ch ); if( ctx_text == NULL ) { error( ERR_BAD_LINK_DFN, TRUE ); } *ctx_text = '\0'; ctx_text = ctx_name + 1; ctx_name = file_name + 1; file_name = ptr + 1; if( ch != CH_FLINK ) { add_link( ctx_name ); } ptr = ctx_text + strlen( ctx_text ) + 1; // Definition pop-up's are converted to hyper-links in InfoBench trans_add_char( CHR_TEMP_HLINK , section, &alloc_size ); // Add line number to hyperlink so we can give meaningful errors trans_add_str( itoa( Line_num, buf, 10 ), section, &alloc_size ); trans_add_char( CHR_TEMP_HLINK, section, &alloc_size ); // We don't want links to break as IB doesn't like this... to_nobreak( ctx_text ); indent = Curr_indent; if( indent < 0 ) indent = 0; // find out the maximum allowed length for hyper-link text: ctr = Right_Margin - indent - ( ( Hyper_Brace_L == '<' ) ? 2 : 0 ); // if the link name is too long then we warn & truncate it if( strlen( ctx_text ) > ctr ) { warning( "Hyperlink name too long", Line_num ); ctx_text[ ctr ] = '\0'; } /* If hyper-link bracing is on we have to do a kludge to fix * the spacing. The "XX" will make the wrap routine happy. * They're stripped off when it comes time to write the file. */ if( Hyper_Brace_L == '<' ) { trans_add_str_wrap( "XX", section, &alloc_size ); } trans_add_str_wrap( ctx_text, section, &alloc_size ); trans_add_char( CHR_HLINK_BREAK , section, &alloc_size ); trans_add_str( ctx_name, section, &alloc_size ); if( ch == CH_FLINK ) { trans_add_char( CHR_HLINK_BREAK, section, &alloc_size ); trans_add_str( file_name, section, &alloc_size ); } trans_add_char( CHR_TEMP_HLINK , section, &alloc_size ); } else if( ch == CH_LIST_ITEM ) { if( Curr_list->type != LIST_TYPE_SIMPLE ) { if( Curr_list->type == LIST_TYPE_UNORDERED ) { // generate a bullet, correctly spaced for tab size buf[0] = '\0'; for( ctr = 1; ctr <= Text_Indent; ctr++) { strcat( buf, " " ); } buf[ Text_Indent / 2 - 1 ] = CHR_BULLET; } else if( Curr_list->type == LIST_TYPE_ORDERED ) { /* ordered list type */ sprintf( buf, "%*d. ", Text_Indent - 2, Curr_list->number ); ++Curr_list->number; } trans_add_str_wrap( buf, section, &alloc_size ); } Eat_blanks = TRUE; ptr = skip_blank( ptr + 1 ); } else if( ch == CH_DLIST_DESC ) { ptr = skip_blank( ptr + 1 ); } else if( ch == CH_DLIST_TERM ) { /* definition list term */ trans_add_str( STR_BOLD_ON, section, &alloc_size ); Line_postfix = LPOSTFIX_TERM; ptr = skip_blank( ptr + 1 ); Eat_blanks = TRUE; } else if( ch == CH_CTX_KW ) { end = strchr( ptr + 1, CH_CTX_KW ); memcpy( buf, ptr + 1, end - ptr - 1 ); buf[end - ptr - 1] = '\0'; add_ctx_keyword( Curr_ctx, buf ); ptr = end + 1; if( *ptr == ' ' ) { /* kludge fix cuz of GML: GML thinks that keywords are are real words, so it puts a space after them. This should fix that */ ++ptr; } } else if( ch == CH_PAR_RESET ) { // we ignore paragraph resets ++ptr; } else if( ch == CH_BMP ) { // we ignore bitmaps ptr = strchr( ptr + 3, CH_BMP ) + 1; } else if( ch == CH_FONTSTYLE_START ) { ++ptr; end = strchr( ptr, CH_FONTSTYLE_START ); for( ; ptr != end; ++ptr ) { switch( *ptr ) { // bold and italic map to bold case 'b': case 'i': trans_add_str( STR_BOLD_ON, section, &alloc_size ); break; // underline and underscore map to underline case 'u': case 's': trans_add_str( STR_UNDERLINE_ON, section, &alloc_size ); break; } } ++ptr; } else if( ch == CH_FONTSTYLE_END ) { // reset style (bold off, underline off) trans_add_str( Reset_Style, section, &alloc_size ); ++ptr; } else if( ch == CH_FONTTYPE ) { // we basically ignore font type changes ptr = strchr( strchr( ptr + 1 , CH_FONTTYPE ) + 1, CH_FONTTYPE ) + 1; } else { ++ptr; if( !Eat_blanks || ch != ' ' ) { Curr_ctx->empty = FALSE; if( Tab_xmp && ch == Tab_xmp_char ) { tab_align( section, &alloc_size ); ptr = skip_blank( ptr ); } else { trans_add_char_wrap( ch, section, &alloc_size ); } Eat_blanks = FALSE; } } } return( alloc_size ); }
void create() { set_mapfile(RIDARIN+"map"); set_descfile(RIDARIN+"descs"); set_compact(2); ::create(); }