void dispstrhgc( unsigned char *p_string, int p_xPos, int p_yPos, font_attr p_attr ) { while ( ( *p_string != '\0' ) && ( p_xPos < 90 ) ) { if ( *p_string < 32 ) { togglefont( &p_attr, *p_string ); } else { if ( whatlevel( *p_string ) == MIDDLE ) { prchar( *p_string, p_attr, p_xPos, p_yPos ); if ( ( p_attr & ENLARGEATTR ) == ENLARGEATTR ) { p_xPos++; } p_xPos++; } else { if ( ( p_attr & ENLARGEATTR ) == ENLARGEATTR ) { if ( p_xPos >= 2 ) { prchar( *p_string, p_attr, p_xPos - 2, p_yPos ); } } else { if ( p_xPos >= 1 ) { prchar( *p_string, p_attr, p_xPos - 1, p_yPos ); } } } } p_string++; } }
void reform( void ) { struct line_node *templine, *firstline, *freeline; unsigned char *temp1, *temp2, *temp3, *cuthere; unsigned int i, j; font_attr font = 0; char fontcode[9]; storeline( curline ); firstline = curline; templine = firstline; /* start to concatenate all lines to one line only */ temp1 = ( char * ) malloc( 1 ); *temp1 = '\0'; while ( 1 ) { temp2 = ( char * ) malloc( strlen( templine->text ) + 1 ); i = 0; j = 0; while ( templine->text[i] != '\0' ) { if ( templine->text[i] != WRAPBLANK ) { temp2[j] = templine->text[i]; j++; } i++; } temp2[j] = '\0'; temp3 = ( char * ) malloc( strlen( temp1 ) + strlen( temp2 ) + 1 ); strcpy( temp3, temp1 ); strcat( temp3, temp2 ); free( temp1 ); free( temp2 ); if ( templine->wrap == NO ) break; temp1 = temp3; templine = templine->next; } /* now paragraph is in the one line only pointed by temp3 */ /* so we will compress two or more blanks to one blank only */ compress_blank( temp3 ); templine->previous = firstline->previous; ( templine->previous )->next = templine; free( templine->text ); templine->text = temp3; if ( curline == curpage ) { curpage = templine; } curline = templine; while ( firstline != templine ) { freeline = firstline; firstline = firstline->next; free( freeline->text ); if ( freeline->graph != NULL ) { free( freeline->graph ); } free( freeline ); } while ( thaistrlen( curline->text ) > ( rightmar - leftmar + 1 ) ) { i = rightmar - leftmar; /* + 1; */ temp1 = curline->text; while ( ( i != 0 ) && ( *temp1 != '\0' ) ) { for ( temp1++; whatlevel( *temp1 ) != MIDDLE; temp1++ ); i--; } temp3 = temp1; for ( i = 10; ( i != 0 ) && ( *temp3 != '\0' ); i-- ) { temp3++; } cuthere = FINDCUT( curline->text, temp3, temp1 ); cuthere++; font = 0; for ( temp1 = curline->text; temp1 != cuthere; temp1++ ) { if ( *temp1 < 32 ) { togglefont( &font, *temp1 ); } } findstrcode( fontcode, font ); templine = ( struct line_node * ) malloc( sizeof( struct line_node ) ); templine->text = ( char * ) malloc( strlen( fontcode ) + strlen( cuthere ) + 1 ); templine->wrap = NO; templine->graph = NULL; strcpy( templine->text, fontcode ); strcat( templine->text, cuthere ); *cuthere = '\0'; temp3 = ( char * ) malloc( leftmar + strlen( curline->text ) + strlen( fontcode ) ); i = 0; while ( i != ( leftmar - 1 ) ) { temp3[i] = WRAPBLANK; i++; } temp3[i] = '\0'; strcat( temp3, curline->text ); strcat( temp3, fontcode ); free( curline->text ); curline->text = temp3; templine->next = curline->next; ( curline->next )->previous = templine; templine->previous = curline; curline->next = templine; curline->wrap = YES; loadtoline( curline->text ); justify_right( ); storeline( curline ); curline = curline->next; } temp3 = ( char * ) malloc( strlen( curline->text ) + leftmar ); i = 0; while ( i != ( leftmar - 1 ) ) { temp3[i] = WRAPBLANK; i++; } temp3[i] = '\0'; strcat( temp3, curline->text ); free( curline->text ); curline->text = temp3; if ( curline->next != sentinel ) { curline = curline->next; } lineno = findlineno( curline ); loadtoline( curline->text ); while ( findrow( ) > ( wind.width - 1 ) ) { curpage = curpage->next; } changeflag = YES; pagecomplete = NO; blkbegin.lineno = 1; blkend.lineno = 1; blkbegin.column = 0; blkend.column = 0; }
void displine(struct line_node *line,unsigned y,unsigned linenum) { register unsigned x = 0; int count = firstcol; font_attr tempfont, curfont = 0; char *st; st = line->text; y += wind.row; while ((count > 0) && (*st != '\0')) { if (whatlevel(*st) == MIDDLE) { if (*st < 32) { togglefont(&curfont,*st); } else { if ((curfont & ENLARGEATTR) == ENLARGEATTR) { count--; } count--; } } st++; } if ((count < 0) && ((curfont & ENLARGEATTR) == ENLARGEATTR)) { x++; } while ((*st != '\0') && (x < (wind.length - 2))){ if (*st < 32) { togglefont(&curfont,*st); } else { tempfont = curfont; if (haveblock() && inblock(linenum,x + firstcol) && dispblock) { curfont = curfont | REVERSEATTR; } if (whatlevel(*st) != MIDDLE) { if (x > 0) { if ((curfont & ENLARGEATTR) == ENLARGEATTR) { if (x >= 2) { prchar(*st,curfont,wind.col+x-2,y); } } else { prchar(*st,curfont,wind.col+x-1,y); } } } else { if ((*st != ' ') || (curfont != 0)) { if ((curfont & ENLARGEATTR) != ENLARGEATTR) { prchar(*st,curfont,wind.col+x,y); x++; } else { prchar(*st,curfont,wind.col+x,y); x += 2; } } else { /* if it's blank and normal attribute,use prblank to speed up */ prblank(wind.col+x,y); x++; } } curfont = tempfont; } st++; } clrline(wind.col+x,y,wind.col+wind.length-1); if (line->wrap == NO) { prchar('<',0,wind.col + wind.length - 1,y); } if (*st != '\0') { prchar('+',0,wind.col + wind.length - 1,y); } y -= wind.row; /* if (graphbuff[y] != NULL) paintlinegraph(graphbuff[y],y); */ }
void autowrap( unsigned int *x, unsigned int *y ) { unsigned int i, j, already = NO, diff; char *temp1, *temp3, *cuthere, fontcode[9]; font_attr font = 0; struct line_node *templine; storeline( curline ); diff = strlen( workline.middle ) - ( *x + firstcol + 1 ); i = 0; j = 0; while ( curline->text[i] != '\0' ) { if ( curline->text[i] != WRAPBLANK ) { curline->text[j] = curline->text[i]; j++; already = YES; } else { if ( already == NO ) { curline->text[j] = curline->text[i]; j++; } } i++; } curline->text[j] = '\0'; temp1 = curline->text; for ( i = rightmar - 2; ( i > 0 ) && ( *temp1 != '\0' ); i-- ) { temp1++; while ( whatlevel( *temp1 ) != MIDDLE ) { temp1++; } } temp3 = temp1; for ( i = 10; ( i != 0 ) && ( *temp3 != '\0' ); i-- ) { temp3++; } cuthere = FINDCUT( curline->text, temp3, temp1 ); cuthere++; for ( temp1 = curline->text; temp1 != cuthere; temp1++ ) { if ( *temp1 < 32 ) { togglefont( &font, *temp1 ); } } findstrcode( fontcode, font ); templine = ( struct line_node * ) malloc( sizeof( struct line_node ) ); templine->text = ( char * ) malloc( leftmar + strlen( fontcode ) + strlen( cuthere ) ); for ( i = 0; i != ( leftmar - 1 ); i++ ) { templine->text[i] = WRAPBLANK; } templine->text[i] = '\0'; strcat( templine->text, fontcode ); strcat( templine->text, cuthere ); templine->graph = NULL; templine->wrap = ( curline->next )->wrap; *cuthere = '\0'; temp3 = ( char * ) malloc( strlen( curline->text ) + strlen( fontcode ) + 1 ); strcpy( temp3, curline->text ); strcat( temp3, fontcode ); free( curline->text ); curline->text = temp3; templine->next = curline->next; ( curline->next )->previous = templine; templine->previous = curline; curline->next = templine; curline->wrap = YES; loadtoline( curline->text ); justify_right( ); *y = findrow( ); cursor_down( *y ); firstcol = 0; gocol( strlen( workline.middle ) - 1 - diff, x ); pagecomplete = NO; }