home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / EXAMPLES.ARC / CH18EX09.PRO < prev    next >
Encoding:
Text File  |  1988-06-21  |  1.3 KB  |  41 lines

  1. /*
  2.    Turbo Prolog 2.0 Chapter 18, Example Program 9
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.    
  8. include "CH18EX08.pro" /* CH18EX08.PRO, excluding the goal */
  9.  
  10. domains
  11.    row, col, length = integer
  12.    field = f(row, col, length)
  13.    position = pos(row, col)
  14.  
  15. predicates
  16.    scr(field, position, key)
  17.  
  18. goal
  19.    Row=10, Col=10, Length=30, cursor(Row, Col),
  20.    makewindow(1, 23, 1, "Example Editor", 0, 0, 25, 80),
  21.    write("Edit the text. Use the arrow keys to move"),
  22.    readkey(Key),
  23.    field_attr(Row, Col, Length, 112),
  24.    scr(f(Row, Col, Length), pos(Row, Col), Key), nl, nl,
  25.    field_str(Row, Col, Length, Contents),
  26.    write("Edited contents: ", Contents).
  27.  
  28. clauses
  29.    scr(_, _, esc) :- !, fail.
  30.    scr(_, _, fkey(10)) :- !.
  31.    scr(f(Row, Col, L), pos(R, C), char(Ch)) :-
  32.       scr_char(R, C, Ch), C1=C+1, C1<Col+L, cursor(R, C1),
  33.    readkey(Key), scr(f(Row, Col, L), pos(R, C1), Key).
  34.    scr(f(Row, Col, L), pos(R, C), Key) :- 
  35.       C1=C+1, C1<Col+L, cursor(R, C1), readkey(Key),
  36.       scr(f(Row, Col, L), pos(R, C1), Key).
  37.    scr(f(Row, Col, L), pos(R, C), Key) :- 
  38.       C1=C-1, C1>=Col, cursor(R, C1),
  39.       readkey(Key), scr(f(Row, Col, L), pos(R, C1), Key).
  40.    scr(Field, Pos, _) :- beep, readkey(Key), scr(Field, Pos, Key).
  41.