home *** CD-ROM | disk | FTP | other *** search
- program turbo_text;
-
- const
- keylo = 32;
- keyhi = 126;
- maxindx = 18;
- frametop = 7;
- blankline = { 78 spaces }
- ' ';
-
- type
- text_string = string [ 80 ];
-
- var
- col,row,key,seg,len,tseg,
- lastcol,lside,rside,width,
- lmargin,rmargin,maxline,
- totcol,indx,code,chars,i,
- framebot : integer;
- ch : char;
- value : string [ 2 ];
- line,wrap,topline,botline,
- midline : text_string;
- text : array [ 1..maxindx ] of text_string;
- edit,moveup,movedn : boolean;
-
- label start,
- getval,
- chkval;
-
- procedure bad_entry;
-
- begin
- sound ( 100 );
- delay ( 100 );
- nosound
- end;
-
- procedure update;
-
- begin
- gotoxy(10,4); write(col - lside:2);
- gotoxy(19,4); write(row - frametop + 1:2);
- gotoxy(28,4); write(chars:4);
- end;
-
- procedure make_frame;
-
- begin
- for i := 1 to totcol do begin
- midline := midline + #196;
- end;
- topline := #218 + midline + #191;
- botline := #192 + midline + #217;
- clrscr;
- gotoxy(lside,frametop - 1); write(topline);
- for i := 0 to maxline do begin
- text [ i ] := '';
- gotoxy(lside,frametop + i); write( #179 );
- gotoxy(rside,frametop + i); write( #179 );
- end;
- text [ i ] := '';
- gotoxy(lside,framebot); write(botline);
- gotoxy(1,2); write( 'TurboText - Version 2.0' );
- gotoxy(5,4); write( 'Col: Line: Char: ' );
- update;
- write(^g);
- end;
-
- procedure check_eol;
-
- begin
- if ( pos(#174,line) = 0 ) and ( length(line) < rmargin ) then
- line := line + #174;
- end;
-
- procedure move_cursor;
-
- begin
- check_eol;
- text [ indx ] := line;
- if moveup then begin
- indx := indx - 1;
- row := row - 1; update;
- moveup := false;
- end
- else begin
- indx := indx + 1;
- row := row + 1; update;
- movedn := false;
- end;
- line := text [ indx ];
- col := lmargin; tseg := 1; update;
- if length(line) = 0 then lastcol := lmargin
- else
- lastcol := length(line) + 1;
- end;
-
- procedure editor;
-
- begin
- read(kbd,ch); key := ord(ch);
- case key of
- 72 : begin { cursor up }
- if row = frametop then begin
- bad_entry;
- exit;
- end;
- moveup := true;
- move_cursor;
- exit;
- end;
- 75 : begin { cursor left }
- if col = lmargin then begin
- bad_entry;
- exit;
- end;
- edit := true;
- tseg := tseg - 1;
- lastcol := lmargin + length(line);
- col := col - 1; update;
- exit;
- end;
- 77 : begin { cursor right }
- if col = lastcol then begin
- edit := false;
- bad_entry;
- exit;
- end;
- edit := true;
- tseg := tseg + 1;
- col := col + 1; update;
- exit;
- end;
- 80 : begin { cursor down }
- if ( row - frametop ) = ( maxline - 1 ) then begin
- bad_entry;
- exit;
- end;
- movedn := true;
- move_cursor;
- exit;
- end;
- 83 : begin { delete }
- if col = lastcol then begin
- edit := false;
- bad_entry;
- exit;
- end;
- edit := true;
- delete(line,tseg,1); chars := chars - 1;
- update;
- gotoxy(col,row); write(copy(line,tseg,length(line)),' ');
- lastcol := lastcol - 1;
- exit;
- end;
- else begin
- bad_entry;
- exit;
- end;
- end { of case }
- end; { of procedure }
-
- procedure enter_text;
-
- label jump;
-
- begin
- repeat
- repeat
- gotoxy(col,row); read(kbd,ch); key := ord(ch);
- if key = 27 then editor
- else
- if key = 13 then begin
- write(#174);
- goto jump;
- end
- else
- if ( key < keylo ) or ( key > keyhi ) then bad_entry
- else
- begin
- write(ch); insert(ch,line,tseg);
- chars := chars + 1;
- tseg := tseg + 1; col := col + 1;
- if not edit then lastcol := col;
- if edit then begin
- delete(line,tseg,1);
- chars := chars - 1;
- end;
- if edit and ( col = lastcol ) then edit := false;
- update;
- end
- until length(line) = rmargin + 1;
- begin
- if ch = #32 then begin
- line := copy(line,1,length(line) - 1);
- goto jump;
- end
- else
- len := length(line);
- repeat
- ch := copy(line,len,1);
- insert(ch,wrap,1);
- delete(line,len,1);
- seg := seg + 1; len := len - 1;
- until ( ch = #32 ) or ( len = 0 );
- if len = 0 then begin
- seg := length(wrap);
- wrap := copy(wrap,1,seg - 1);
- line := #174;
- end
- else begin
- seg := seg - 1;
- wrap := copy(wrap,2,seg);
- end;
- gotoxy(col - seg,row); write(copy(blankline,1,seg));
- gotoxy(lmargin,row + 1); write(wrap);
- if len = 0 then seg := 0;
- end;
- jump:
- begin
- check_eol;
- text [ indx ] := line; indx := indx + 1;
- if length(wrap) <> 0 then begin
- line := wrap; wrap := '';
- end
- else
- begin
- line := '';
- end;
- row := row + 1;
- col := lmargin + seg; lastcol := col;
- tseg := 1 + seg; seg := 0;
- update;
- end;
- until indx > maxline;
- end;
-
- begin
- start:
- clrscr;
- gotoxy( 1,2 ); write( 'TurboText - Text Handling Routines' );
- gotoxy( 1,3 ); write( 'Enter left margin ( 2 - 77 ) [ ]' );
- gotoxy( 1,4 ); write( 'Enter text columns ( 2 - 77 ) [ ]' );
- gotoxy( 1,5 ); write( 'Enter number of text lines ( 2 - 18 ) [ ]' );
- col := 32; row := 3; lastcol := col + 1; value := '';
- getval:
- repeat
- gotoxy(col,row); read(kbd,ch); key := ord(ch);
- write(ch);
- if key = 27 then exit;
- if ( key = 13 ) and ( length( value ) = 0 ) then bad_entry;
- if key = 13 then goto chkval;
- if ( key < 48 ) or ( key > 57 ) then bad_entry;
- value := value + ch; col := col + 1;
- until col = lastcol + 1;
- chkval:
- begin
- if row = 3 then begin
- val(value,lmargin,code);
- if ( lmargin < 2 ) or ( lmargin > 77 ) then goto start;
- col := 32; row := 4; value := '';
- goto getval;
- end;
- if row = 4 then begin
- val(value,totcol,code);
- if ( totcol < 2 ) or ( totcol > 77 ) then goto start;
- if lmargin + totcol > 78 then goto start;
- col := 40; row := 5; lastcol := 41; value := '';
- goto getval;
- end;
- if row = 5 then begin
- val(value,maxline,code);
- if ( maxline < 2 ) or ( maxline > 18 ) then goto start;
- end;
- end;
- rmargin := totcol - 1; framebot := frametop + maxline;
- lside := lmargin - 1; rside := lmargin + totcol;
- col := lmargin; row := frametop; chars := 0;
- topline := ''; botline := ''; midline := '';
- make_frame;
- indx := 1; line := ''; wrap := ''; tseg := 1;
- lastcol := col; seg := 0;
- edit := false; moveup := false; movedn := false;
- enter_text;
- gotoxy(1,16);
- for i := 1 to indx - 1 do
- writeln(text [ i ]);
- end.