/* compiles <str> into a label <lp> */ void make_simple_label(GVC_t * gvc, textlabel_t * lp) { char c, *p, *line, *lineptr, *str = lp->text; unsigned char byte = 0x00; lp->dimen.x = lp->dimen.y = 0.0; if (*str == '\0') return; line = lineptr = NULL; p = str; line = lineptr = N_GNEW(strlen(p) + 1, char); *line = 0; while ((c = *p++)) { byte = (unsigned int) c; /* wingraphviz allows a combination of ascii and big-5. The latter * is a two-byte encoding, with the first byte in 0xA1-0xFE, and * the second in 0x40-0x7e or 0xa1-0xfe. We assume that the input * is well-formed, but check that we don't go past the ending '\0'. */ if ((lp->charset == CHAR_BIG5) && 0xA1 <= byte && byte <= 0xFE) { *lineptr++ = c; c = *p++; *lineptr++ = c; if (!c) /* NB. Protect against unexpected string end here */ break; } else { if (c == '\\') { switch (*p) { case 'n': case 'l': case 'r': *lineptr++ = '\0'; storeline(gvc, lp, line, *p); line = lineptr; break; default: *lineptr++ = *p; } if (*p) p++; /* tcldot can enter real linend characters */ } else if (c == '\n') { *lineptr++ = '\0'; storeline(gvc, lp, line, 'n'); line = lineptr; } else { *lineptr++ = c; } } } if (line != lineptr) { *lineptr++ = '\0'; storeline(gvc, lp, line, 'n'); } lp->space = lp->dimen; }
/* If a label is encountered in parse_record, this function gets called to deal with the remaining record. The following tokens in the record can be either an instruction, a directive or a comment/null. Anything else is an error */ void analyzelabel(char* line, char* token){ char* nexttoken; char* string; char* strptr; struct firsttoken result; #ifdef debug printf("FOUND LABEL >>%s<<\n", token); #endif /* debug */ global = token; // Global string saving the label token string = storeline(line); nexttoken = strtok(line, " \t\r\n"); if(nexttoken != NULL && *nexttoken != ';' && nexttoken[0] != '\r'){ while(!isalnum(*string)){ // Go to first legible char *string++; } //Points to the start of the next token for the analysis functions strptr = storeline(string + strlen(nexttoken)); #ifdef debug printf("TOKEN AFTER LABEL IS >>%s<<\n", nexttoken); printf("SENDING TO ANALYZERS: >>%s<<\n", strptr); #endif /* debug */ result = sort(nexttoken); flag_first_token_label = TRUE; // indicator used for storing in symtbl switch (result.type) { case INST: analyzeinstruction(strptr, result); break; case DIR: analyzedirective(strptr, result); break; default: error_count("ERROR: Invalid token after label:", nexttoken); break; } flag_first_token_label = FALSE; } else{ // Nothing follows the label #ifdef debug printf("SOLO LABEL >>%s<<\n", token); #endif if(!get_entry(token)){ // If label unique, add it with LC add_entry(token, LC, LBLTYPE); } else{ update_entry(token, LC, LBLTYPE); } } global = NULL; //Reset the global label for further usage }
int nofill() { int j; tchar i; if (!pendnf) { over = 0; tbreak(); if (trap) goto rtn; if (nlflg) { ch = nflush = 0; callsp(); return (0); } adsp = adrem = 0; nwd = 10000; } while ((j = (cbits(i = GETCH()))) != '\n') { if (j == ohc) continue; if (j == CONT) { pendnf++; nflush = 0; flushi(); ckul(); return (0); } j = width(i); widthp = j; numtab[HP].val += j; storeline(i, j); } if (ce) { ce--; if ((i = quant(nel / 2, HOR)) > 0) un += i; } if (!nc) storeline((tchar)FILLER, 0); brflg = 2; tbreak(); ckul(); rtn: pendnf = nflush = 0; return (0); }
void parse_record(char* line){ char *token; char *string; char *strptr; unsigned short safeguard = 0; struct firsttoken tokinfo; string = storeline(line); //Store the record for error printing purposes token = strtok(line, " \t\r\n"); // Isolate the token for analysis while(!isalnum(*string)){ // Go to first legible alphanumeric *string++; if(safeguard++ == LINE_LEN){ break; } } strptr = storeline(string + strlen(token)); // Store the record minus the // 1st token for analysis in // subsequent parsers if(token != NULL){ /* Specify 1st token type in record (INST, DIR, LABEL, ERROR) */ tokinfo = sort(token); switch (tokinfo.type) { case INST: analyzeinstruction(strptr, tokinfo); break; case DIR: analyzedirective(strptr, tokinfo); break; case LABEL: analyzelabel(strptr, token); break; case COMMENT: return; break; default: error_count("ERROR: Unclassifiable first token >>%s<< in line", token); break; } token = strtok(NULL, " \t\n"); } #ifdef debug printf("LC after record %d\n", LC); #endif /* debug */ return; }
void endfile( unsigned int *x ) { int count, linenum; storeline( curline ); curline = sentinel->previous; curpage = curline; lineno = findlineno( curline ); if ( pagebreak ) { linenum = findlineno( curpage ); } count = wind.width - 1; while ( ( count != 0 ) && ( curpage->previous != sentinel ) ) { if ( pagebreak ) { if ( ( linenum % lineperpage ) != 0 ) { curpage = curpage->previous; linenum--; } } else { curpage = curpage->previous; } count--; } loadtoline( curline->text ); endline( x ); pagecomplete = NO; }
void top_of_page( void ) { storeline( curline ); while ( curline != curpage ) { curline = curline->previous; lineno--; } loadtoline( curline->text ); }
void scroll_up( void ) { if ( curpage->previous != sentinel ) { /* top of file ? */ storeline( curline ); curpage = curpage->previous; pagecomplete = NO; loadtoline( curline->text ); } }
void goline( unsigned int linetogo ) { storeline( curline ); curline = sentinel->next; lineno = 1; while ( ( lineno != linetogo ) && ( curline->next != sentinel ) ) { curline = curline->next; lineno++; } loadtoline( curline->text ); curpage = curline; pagecomplete = NO; }
void topfile( unsigned int *x ) { storeline( curline ); if ( curpage != sentinel->next ) { curpage = sentinel->next; pagecomplete = NO; } curline = curpage; *x = 0; firstcol = 0; lineno = 1; loadtoline( curline->text ); }
void scroll_down( void ) { if ( curpage->next != sentinel ) { /* end of file ? */ storeline( curline ); if ( curpage != curline ) { curpage = curpage->next; } else { curpage = curpage->next; curline = curpage; lineno++; } pagecomplete = NO; loadtoline( curline->text ); } }
void cursor_up( void ) { if ( curline->previous != sentinel ) { /* top of file ? */ storeline( curline ); lineno--; if ( curpage == curline ) { /* Is top of page ? */ curpage = curpage->previous; /* scroll page up */ curline = curline->previous; /* up one line */ pagecomplete = NO; /* refresh screen */ } else { curline = curline->previous; /* up one line */ } loadtoline( curline->text ); } }
nofill(){ register i, j; if(!pendnf){ over = 0; tbreak(); if(trap)goto rtn; if(nlflg){ ch = nflush = 0; callsp(); return; } adsp = adrem = 0; nwd = 10000; } while((j = ((i = GETCH()) & CMASK)) != '\n'){ if(j == ohc)continue; if(j == CONT){ pendnf++; nflush = 0; flushi(); ckul(); return; } storeline(i,-1); } if(ce){ ce--; if((i=quant(nel/2,HOR)) > 0)un += i; } if(!nc)storeline(FILLER,0); brflg = 2; tbreak(); ckul(); rtn: pendnf = nflush = 0; }
void bottom_of_page( void ) { int count; top_of_page( ); count = wind.width - 1; storeline( curline ); while ( ( curline != sentinel ) && count-- ) { curline = curline->next; lineno++; } if ( curline == sentinel ) { curline = sentinel->previous; lineno--; } loadtoline( curline->text ); }
void replacing( unsigned int *p_xCursorPos, unsigned int *y_CursorPos ) { storeline( curline ); if ( searchreplaceinfo( ) == YES ) { showpageall( ); replaceflag = YES; if ( optionword( ) ) { addblank( ); } if ( optionupper( ) ) { strupr( source ); } if ( !searchreplace( p_xCursorPos, y_CursorPos ) ) { wordnotfound( ); } } }
void page_down( void ) { int count; if ( curpage->next != sentinel ) { /* bottom of file ? */ storeline( curline ); count = wind.width - 1; while ( ( count != 0 ) && ( curline->next != sentinel ) ) { curline = curline->next; curpage = curpage->next; count--; lineno++; } if ( count != 0 ) /* end of file ? */ curpage = curline; pagecomplete = NO; loadtoline( curline->text ); } }
void page_up( void ) { int count; storeline( curline ); if ( curpage->previous != sentinel ) { /* top of file ? */ count = wind.width - 1; while ( ( count > 0 ) && ( curpage->previous != sentinel ) ) { curpage = curpage->previous; curline = curline->previous; lineno--; count--; } pagecomplete = NO; } else { curline = curpage; lineno = 1; } loadtoline( curline->text ); }
void searching( unsigned int *p_xCursorPos, unsigned int *y_CursorPos ) { storeline( curline ); if ( searchonlyinfo( ) == YES ) { showpageall( ); replaceflag = NO; if ( optionword( ) ) { addblank( ); } if ( optionupper( ) ) { strupr( source ); } if ( optionglobal( ) ) { topfile( p_xCursorPos ); showpageall( ); } if ( !searchfwd( p_xCursorPos, y_CursorPos ) ) { wordnotfound( ); } } }
void cursor_down( unsigned y ) { if ( curline->next != sentinel ) { /* end of file ? */ storeline( curline ); lineno++; /* increment lineno */ curline = curline->next; /* down one line */ if ( y == ( wind.width - 1 ) ) { /* bottom of screen ? */ if ( pagebreak && ( ( ( lineno - 1 ) % lineperpage ) == 0 ) ) { curpage = curpage->next; /* skip over page break */ } curpage = curpage->next; /* scroll page down */ pagecomplete = NO; /* refresh screen */ } else { if ( pagebreak && /* page break is displayed at bottom of screen ? */ ( ( ( ( lineno - 1 ) % lineperpage ) == 0 ) && ( y == ( wind.width - 2 ) ) ) ) { curpage = curpage->next; /* skip over page break */ pagecomplete = NO; /* refresh screen */ } } loadtoline( curline->text ); } }
void insertgraph( ) { int i; char graphname[30]; notavailable( ); /* comment this out */ storeline( curline ); blockmsg( 5 ); dispstrhgc( "ãÊèª×èÍá¿éÁÃÙ»ÀÒ¾·Õèµéͧ¡ÒÃÍèÒ¹ :", ( 14 + center_factor ) + 3, 6, REVERSEATTR ); strcpy( graphname, "*.*" ); i = getname( graphname, ( 14 + center_factor ) + 28, 5, 22, REVERSEATTR ); if ( ( i == YES ) && ( graphname[0] != '\0' ) ) { if ( havewild( graphname ) ) { selectfile( graphname ); } curline->graph = readgraph( graphname ); } changeflag = YES; pagecomplete = NO; loadtoline( curline->text ); }
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; }
int main( int argc, char *argv[] ) { /* (x,y) position of edit window. x column, y line -> (0,0) at upper left on screen */ unsigned int xCursorPos = 0; unsigned int yCursorPos = 0; unsigned int curmenu = 0x1100; int i; cwsetup( argc, argv ); writestatus( 0 ); writetab( ); splashscreen( ); /* Main program loop */ do { dispstrhgc( " ", wind.col, 2, NORMALATTR ); i = pulled_down_menu( &curmenu, &xCursorPos, &yCursorPos ); if ( filename[0] != '\0' ) { switch ( i ) { case RETKEY: keymain = menu_to_key( curmenu ); break; case ESCKEY: waitkbd( wind.col + xCursorPos, wind.row + yCursorPos ); /* Show blinking cursor */ keymain = readkbd( ); /* If keypressed Get it */ break; default: keymain = i; break; } while ( keymain != ESCKEY ) { if ( ( keymain & 0xff ) >= 32 ) { keymain = changekey( keymain ); if ( insertmode ) { if ( !insert_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } else { if ( !ovrwrite_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } refreshline( xCursorPos, yCursorPos ); } else { /* Function Key */ switch ( keymain ) { case PGUPKEY: case CNTRL_R: page_up( ); break; case PGDNKEY: case CNTRL_C: page_down( ); break; case UPKEY: case CNTRL_E: cursor_up( ); break; case DNKEY: case CNTRL_X: cursor_down( yCursorPos ); break; case LEKEY: case CNTRL_S: cursor_left( &xCursorPos ); break; case 0x2301: gobeginblk( &xCursorPos ); break; case 0x2401: goendblk( &xCursorPos ); break; case RIKEY: case CNTRL_D: cursor_right( &xCursorPos, yCursorPos ); break; case CNTRL_W: scroll_up( ); break; case CNTRL_Z: scroll_down( ); break; case CHOMEKEY: top_of_page( ); break; case CPGUPKEY: topfile( &xCursorPos ); break; case CENDKEY: bottom_of_page( ); break; case CPGDNKEY: endfile( &xCursorPos ); break; case DELKEY: case CNTRL_G: delete_char( xCursorPos ); refreshline( xCursorPos, yCursorPos ); changeflag = YES; break; case CNTRL_T: delete_word( xCursorPos ); refreshline( xCursorPos, yCursorPos ); changeflag = YES; break; case CNTRL_Y: delete_line( ); changeflag = YES; break; case CNTRL_M: case RETKEY: if ( insertmode == NO ) { returnkey( &xCursorPos, yCursorPos ); } else { ret_with_ins( &xCursorPos, yCursorPos ); changeflag = YES; } break; case BSKEY: case CNTRL_H: backspace( &xCursorPos ); yCursorPos = findrow( ); refreshline( 0, yCursorPos ); changeflag = YES; break; case INSKEY: case CNTRL_V: insertmode = !insertmode; writeinsmode( ); break; case CNTRL_N: insert_ret( &xCursorPos ); break; case F10KEY: thaimode = !thaimode; writelanguage( ); break; case F1KEY: fontused = 0x00; writeattr( ); break; case F2KEY: fontused = fontused | ITALICATTR; writeattr( ); break; case F3KEY: fontused = fontused | ONELINEATTR; fontused = fontused & 0x7f; writeattr( ); break; case F4KEY: fontused = fontused | TWOLINEATTR; fontused = fontused & 0xfe; writeattr( ); break; case F5KEY: fontused = fontused | BOLDATTR; writeattr( ); break; case F6KEY: fontused = fontused | ENLARGEATTR; writeattr( ); break; case F7KEY: fontused = fontused | SUPERATTR; if ( ( fontused & SUBATTR ) == SUBATTR ) { fontused = fontused ^ SUBATTR; } writeattr( ); break; case F8KEY: fontused = fontused | SUBATTR; if ( ( fontused & SUPERATTR ) == SUPERATTR ) { fontused = fontused ^ SUPERATTR; } writeattr( ); break; case F9KEY: manualwrap( &xCursorPos, &yCursorPos ); break; case ALTM: editmacro( ); break; case TABKEY: case CNTRL_I: movetotab( &xCursorPos, yCursorPos ); break; case CNTRL_K: blockcommand( &xCursorPos ); break; case 0x1401: blkcmd( 'p', &xCursorPos ); break; case 0x6101: blkcmd( 'b', &xCursorPos ); break; case 0x6201: blkcmd( 'k', &xCursorPos ); break; case 0x6301: blkcmd( 'c', &xCursorPos ); break; case 0x6401: blkcmd( 'y', &xCursorPos ); break; case 0x6501: blkcmd( 'v', &xCursorPos ); break; case 0x6601: blkcmd( 'r', &xCursorPos ); break; case 0x6701: blkcmd( 'w', &xCursorPos ); break; case 0x6801: blkcmd( 'h', &xCursorPos ); break; case CNTRL_O: onscreen( xCursorPos, yCursorPos ); break; case 0x7101: doonscrn( 'l', xCursorPos, yCursorPos ); break; case 0x7201: doonscrn( 'r', xCursorPos, yCursorPos ); break; case 0x7301: doonscrn( 'i', xCursorPos, yCursorPos ); break; case 0x7401: doonscrn( 'n', xCursorPos, yCursorPos ); break; case 0x7501: doonscrn( 'c', xCursorPos, yCursorPos ); break; case 0x7601: doonscrn( 'p', xCursorPos, yCursorPos ); break; case 0x7701: doonscrn( 'x', xCursorPos, yCursorPos ); break; case CNTRL_Q: quick( &xCursorPos, &yCursorPos ); break; case 0x3501: deltoendline( xCursorPos, yCursorPos ); break; case 0x8111: inscntrl( CNTRL_W, xCursorPos, yCursorPos ); break; case 0x8211: inscntrl( CNTRL_S, xCursorPos, yCursorPos ); break; case 0x8311: inscntrl( CNTRL_R, xCursorPos, yCursorPos ); break; case 0x8411: inscntrl( CNTRL_B, xCursorPos, yCursorPos ); break; case 0x8511: inscntrl( CNTRL_E, xCursorPos, yCursorPos ); break; case 0x8611: inscntrl( CNTRL_T, xCursorPos, yCursorPos ); break; case 0x8711: inscntrl( CNTRL_V, xCursorPos, yCursorPos ); break; case CNTRL_P: printcntrl( xCursorPos, yCursorPos ); break; case HOMEKEY: home( &xCursorPos ); break; case ENDKEY: endline( &xCursorPos ); break; case CLEKEY: case CNTRL_A: backword( &xCursorPos ); break; case CRIKEY: case CNTRL_F: nextword( &xCursorPos, yCursorPos ); break; case CNTRL_L: if ( source[0] != '\0' ) { if ( replaceflag == NO ) { if ( searchfwd( &xCursorPos, &yCursorPos ) == NO ) { wordnotfound( ); } } else { if ( searchreplace( &xCursorPos, &yCursorPos ) == NO ) { wordnotfound( ); } } } break; case CNTRL_B: reform( ); break; case ALTP: gotopage( ); break; case CNTRL_J: case ALTL: gotoline( ); break; case 0x5101: searching( &xCursorPos, &yCursorPos ); break; case 0x5201: replacing( &xCursorPos, &yCursorPos ); break; case 0x8501: loadtoline( curline->text ); refreshline( 0, yCursorPos ); break; case CF1KEY: insertmacro( ¯o[0][0], &xCursorPos, &yCursorPos ); break; case CF2KEY: insertmacro( ¯o[1][0], &xCursorPos, &yCursorPos ); break; case CF3KEY: insertmacro( ¯o[2][0], &xCursorPos, &yCursorPos ); break; case CF4KEY: insertmacro( ¯o[3][0], &xCursorPos, &yCursorPos ); break; case CF5KEY: insertmacro( ¯o[4][0], &xCursorPos, &yCursorPos ); break; case CF6KEY: insertmacro( ¯o[5][0], &xCursorPos, &yCursorPos ); break; case CF7KEY: insertmacro( ¯o[6][0], &xCursorPos, &yCursorPos ); break; case CF8KEY: insertmacro( ¯o[7][0], &xCursorPos, &yCursorPos ); break; case CF9KEY: insertmacro( ¯o[8][0], &xCursorPos, &yCursorPos ); break; case CF10KEY: insertmacro( ¯o[9][0], &xCursorPos, &yCursorPos ); break; case AF2KEY: inscntrl( ITALICCODE, xCursorPos, yCursorPos ); break; case AF3KEY: inscntrl( ONELINECODE, xCursorPos, yCursorPos ); break; case AF4KEY: inscntrl( TWOLINECODE, xCursorPos, yCursorPos ); break; case AF5KEY: inscntrl( BOLDCODE, xCursorPos, yCursorPos ); break; case AF6KEY: inscntrl( ENLARGECODE, xCursorPos, yCursorPos ); break; case AF7KEY: inscntrl( SUPERCODE, xCursorPos, yCursorPos ); break; case AF8KEY: inscntrl( SUBCODE, xCursorPos, yCursorPos ); break; #ifdef WANT_TO_USE_GRAPH case ALTG: insertgraph( ); break; case ALTD: deletegraph( ); break; #endif case ALTX: quitprog = YES; keymain = ESCKEY; break; default: if ( ( alt_char_map( keymain ) ) != -1 ) { keymain = alt_char_map( keymain ); if ( insertmode ) { if ( !insert_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } else { if ( !ovrwrite_char( keymain, &xCursorPos, &yCursorPos ) ) { linetoolong( ); } } refreshline( xCursorPos, yCursorPos ); } break; } /* switch ( keymain ) */ } adjustcol( &xCursorPos ); while ( ( yCursorPos = findrow( ) ) > ( wind.width - 1 ) ) { storeline( curline ); curline = curline->previous; loadtoline( curline->text ); lineno--; } if ( !keypressed( ) ) { if ( !pagecomplete ) { showpage( ); } if ( !keypressed( ) ) { writecolno( firstcol + xCursorPos ); dispstrhgc( " ", wind.col, 2, NORMALATTR ); if ( !keypressed( ) ) { writepageline( ); } } } if ( quitprog != YES ) { waitkbd( wind.col + xCursorPos, wind.row + yCursorPos ); keymain = readkbd( ); dispkey( keymain ); } } /* while */ } else { /* if filename[0] != '\0' */ errorsound( ); } } while ( !quitprog ); if ( changeflag ) { blockmsg( 5 ); dispstrhgc( "ÂѧäÁèä´é¨Ñ´à¡çºá¿éÁ¢éÍÁÙÅ µéͧ¡ÒèѴà¡çºËÃ×ÍäÁè (Y/N)?", ( 16 + center_factor ) + 7, 5, REVERSEATTR ); keymain = 0; while ( ( keymain != 'n' ) && ( keymain != 'N' ) && ( keymain != 'y' ) && ( keymain != 'Y' ) ) { keymain = ebioskey( 0 ) & 0xff; if ( ( keymain == 'y' ) || ( keymain == 'Y' ) ) { writeblk( filename, sentinel->next, 0, sentinel->previous, MAXCOL ); } } } settext( ); return 0; }
int searchfwd( unsigned int *p_xCursorPos, unsigned int *y_CursorPos ) { struct line_node *savepage, *templine; boolean enlargeflag; unsigned int linecount; unsigned int savecol; unsigned int startpos; size_t i; font_attr font = NORMALATTR; char *foundpoint; char *addr; savecol = firstcol; savepage = curpage; storeline( curline ); templine = curpage; linecount = wind.width - 1; while ( templine != curline ) { linecount--; templine = templine->next; } startpos = linearcolumn( curline->text, *p_xCursorPos + firstcol, &font ); foundpoint = NULL; while ( ( foundpoint == NULL ) && ( curline != sentinel ) ) { foundpoint = searchline( curline->text, startpos ); if ( foundpoint != NULL ) { /* found */ while ( ( *y_CursorPos = findrow( ) ) >= wind.width ) { curpage = curpage->next; } *p_xCursorPos = 0; firstcol = 0; addr = curline->text; enlargeflag = NO; while ( addr != foundpoint ) { if ( ( whatlevel( *addr ) == MIDDLE ) && ( *addr >= 32 ) ) { if ( enlargeflag ) { ( *p_xCursorPos )++; } ( *p_xCursorPos )++; } else { if ( *addr == ENLARGECODE ) { enlargeflag = enlargeflag ^ 1; } } addr++; } for ( i = 0; source[i] != '\0'; i++ ) { if ( whatlevel( source[i] ) == MIDDLE ) { if ( enlargeflag ) { ( *p_xCursorPos )++; } ( *p_xCursorPos )++; } } while ( *p_xCursorPos >= wind.length ) { firstcol = firstcol + wind.length; *p_xCursorPos = *p_xCursorPos - wind.length; } } else { if ( linecount > 0 ) { linecount--; curline = curline->next; lineno++; } else { curline = curline->next; lineno++; curpage = curline; linecount = wind.width - 1; } startpos = 0; } } if ( foundpoint == NULL ) { curline = sentinel->previous; curpage = curline; loadtoline( curline->text ); endline( p_xCursorPos ); } loadtoline( curline->text ); if ( savepage != curpage ) { showpageall( ); } else { if ( firstcol != savecol ) { showpageall( ); } } if ( foundpoint != NULL ) { return( YES ); } else { return( NO ); } }
movword(void) { int w; Tchar i, *wp; int savwch, hys; over = 0; wp = wordp; if (!nwd) { while (cbits(*wp++) == ' ') { wch--; wne -= sps; } wp--; } if (wne > nel && !hyoff && hyf && (!nwd || nel > 3 * sps) && (!(hyf & 02) || (findt1() > lss))) hyphen(wp); savwch = wch; hyp = hyptr; nhyp = 0; while (*hyp && *hyp <= wp) hyp++; while (wch) { if (hyoff != 1 && *hyp == wp) { hyp++; if (!wdstart || (wp > wdstart + 1 && wp < wdend && (!(hyf & 04) || wp < wdend - 1) && /* 04 => last 2 */ (!(hyf & 010) || wp > wdstart + 2))) { /* 010 => 1st 2 */ nhyp++; storeline((Tchar)IMP, 0); } } i = *wp++; w = width(i); wne -= w; wch--; storeline(i, w); } if (nel >= 0) { nwd++; return(0); /* line didn't fill up */ } if (TROFF) xbits((Tchar)HYPHEN, 1); hys = width((Tchar)HYPHEN); m1: if (!nhyp) { if (!nwd) goto m3; if (wch == savwch) goto m4; } if (*--linep != IMP) goto m5; if (!(--nhyp)) if (!nwd) goto m2; if (nel < hys) { nc--; goto m1; } m2: if ((i = cbits(*(linep - 1))) != '-' && i != EMDASH) { *linep = (*(linep - 1) & SFMASK) | HYPHEN; w = width(*linep); nel -= w; ne += w; linep++; } m3: nwd++; m4: wordp = wp; return(1); /* line filled up */ m5: nc--; w = width(*linep); ne -= w; nel += w; wne += w; wch++; wp--; goto m1; }
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; }