home *** CD-ROM | disk | FTP | other *** search
/ Between Heaven & Hell 2 / BetweenHeavenHell.cdr / garden / textpro.src < prev    next >
Text File  |  1988-01-06  |  7KB  |  222 lines

  1. (* TEXTPRO.SRC   DECEMBER 28, 1987
  2.  
  3. This is the engine that lets you read and write hypertext documents.
  4. Written in the KnowledgePro development environment by Bev and Bill Thompson.
  5. Copyright 1987  Knowledge Garden Inc.
  6.  
  7. TextPro may be freely copied and distributed but may not be modified
  8. or used for commercial purposes. *)
  9.  
  10. do (setup).
  11. do (menu).
  12.  
  13. topic menu.
  14. ask ('What would you like to do with hypertext?',want,['Read a hypertext document',
  15.   'Create or Edit a hypertext document',Quit]).
  16.  
  17. if ?want <> Quit
  18.    then do (?want) and
  19.    do (menu).
  20.  
  21.   topic 'Read a hypertext document'.
  22.   file_name (input).
  23.   if ?file <> ?ESC
  24.       then do (read_hyper).
  25.  
  26.     topic read_hyper.
  27.     text is read (?file,concat ('/page',?current),'/end').
  28.     if ?text <> ?EOF
  29.        then say (?text) and
  30.             current = ?current + 1 and
  31.             do (read_hyper)
  32.        else if ?current = 1
  33.                  then text is read (?file,,'/end') and
  34.                       say (?text)
  35.                  else close (?file) and
  36.                     current = 1.
  37.     end. (* read_hyper *)
  38.  
  39.   end. (* Read a hypertext document *)
  40.  
  41.  
  42.   topic 'Create or Edit a hypertext document'.
  43.   file_name ().
  44.   if ?file <> ?ESC
  45.      then do (create_hyper).
  46.  
  47.     topic create_hyper.
  48.     window ('',white,yellow,black,1,20,78,1).
  49.     write ('con:','
  50.  Press F4 if you want an #mexplanation#m of how to create a hypertext document.').
  51.     edit_file (?file,,,,1,1,78,17).
  52.     close_window ().
  53.     close (?file).
  54.     finding is user_file.
  55.     end. (* create_hyper *)
  56.  
  57.   end. (* Create or Edit a hypertext document *)
  58.  
  59.   topic file_name (check).
  60.   write (con:,#e,'
  61.                     Type the name of the file you want to use.
  62.                        File names use DOS file conventions.
  63.    File names entered using a #fyellow *#d will display a menu of all matching files.
  64.                  Press #fyellow ESC#d to return to the opening menu.').
  65.   window ('',,,,1,9,78,3).
  66.   read_response ('#s#nName of file ',file,?last_file).
  67.   close_window ().
  68.   if ?file is ?ESC
  69.      then exit ().
  70.   if string_where (?file,*) <> 0
  71.      then do (show_files).
  72.   if ?file <> ?new
  73.      then do (?check) and
  74.           (if ?file <> ?new
  75.              then last_file is ?file
  76.              else file_name (?check) )
  77.      else file_name (?check).
  78.  
  79.     topic show_files.
  80.     list is dir (?file).
  81.     list gets ?new.
  82.     if ?list is ?new
  83.        then message is ['
  84.  There are no files with the description #fred
  85.  ',?file,#d,'
  86.  Enter a new file name.'] and
  87.             error (?message)
  88.        else ask ('Which file would you like to select ?',file,?list).
  89.     end. (* show_files *)
  90.  
  91.     topic input.
  92.     text is read_char (?file).
  93.     if ?text is ?EOF
  94.        then message is ['
  95.  
  96.      The file #s',#fred,?file,#d,#l,'
  97.  
  98.      does not exist.  Enter a new file name.'] and
  99.             error (?message).
  100.     end. (* input *)
  101.  
  102.     topic error (message).
  103.     window ('',black,lightcyan,lightcyan,15,7,51,7) and
  104.     say (?message).
  105.     close_window ().
  106.     file is ?new.
  107.     end.
  108.  
  109.   end. (* file_name *)
  110.  
  111.   topic mark (find_string) .
  112.   new_string is concat ('/',?find_string).
  113.   text is read (?file,?new_string,'/end')  .
  114.  
  115.   if ?text is ?EOF
  116.      then say ('Sorry, I can''t find that thread')
  117.      else do (print).
  118.  
  119.     topic print.
  120.     item is ?item + 1.
  121.     if ?item > ?colors
  122.        then item = 1.
  123.     text_color is element (?fore,?item).
  124.     window (?find_string,?text_color,element (?back,?item),white).
  125.     say (?text) .
  126.     close_window ().
  127.     end. (* print *)
  128.  
  129.   end . (* mark *)
  130.  
  131. end. (* menu *)
  132.  
  133. (* ======================== Hypertext for explanation =============== *)
  134.  
  135. topic explanation.
  136. window (Explanation).
  137. say ('
  138.   In TextPro, information is broken up into units called
  139.   #fyellow messages#d.  A message is a section of text that is
  140.   made up of a label, the text of the message, and an ending.
  141.   The label depends on the type of message.  The ending is
  142.   simply a line containing #fyellow /end#d.  There are two
  143.   different types of messages; page and thread.
  144.  
  145.                                             ... PgDn
  146.  
  147.  
  148.   Page messages are labeled with the name #fyellow /page#d followed by the
  149.   number of the page.  These messages are displayed sequentially
  150.   to provide a context for your information.  The page messages
  151.   should be formatted with a #mright margin#m of 78.  The length of
  152.   the display window is 19 rows but longer messages will be
  153.   automatically formatted so that PgUp and PgDn can be used.
  154.   Within a page message you can mark important concepts by
  155.   enclosing the words with the symbols #fyellow ##m#d.  These concepts are
  156.   called hypertext threads.  Each thread will be linked to
  157.   another message which will be displayed when the #mreader selects#m
  158.   the thread.                                ... PgDn
  159.  
  160.   Thread messages are labeled with the name #fyellow /#d followed by the
  161.   name of the hypertext thread to which it''s related.  These
  162.   messages are displayed only when the #mreader selects#m the
  163.   hypertext thread in its label.  Threaded messages should be
  164.   formatted with a right margin of 65.  The length of the display
  165.   window is 11 rows but longer messages will be automatically
  166.   formatted so that PgUp and PgDn can be used.  Threaded messages
  167.   can contain other threaded messages.     ... PgDn
  168.  
  169.  
  170.  
  171.   If you would like to see an example of a hypertext file, you
  172.   can copy the file SAMPLE.HYP into the text editor as soon as
  173.   you are finished with this message.  To do this use the editor
  174.   command ^KR and when you''re asked for the name of the file type
  175.   in SAMPLE.HYP.  The text read in will appear in inverse video.
  176.   To return to the normal video type ^KH.').
  177. close_window ().
  178. end. (* explanation *)
  179.  
  180. topic 'reader selects'.
  181. window ('',white,magenta,white).
  182. say ('
  183.  
  184.  The reader can select a hypertext message by pointing to its
  185.  highlighted thread with the mouse or, by pressing the F3 key to
  186.  move the cursor.  Once a thread has been selected, the message
  187.  is displayed when the mouse button is clicked or, the F4 button
  188.  is pressed.').
  189. close_window ().
  190. end. (* reader selects *)
  191.  
  192. topic 'right margin'.
  193. window ('',black,green,white).
  194. say ('
  195.  
  196.  To change the margin press ^OR while in the text editor.  A
  197.  window will appear which asks you the new value for the right
  198.  margin.').
  199. close_window ().
  200. end. (* right margin *)
  201.  
  202. topic setup.
  203. no_edit_key ().
  204. no_debug ().
  205. EOF = number_to_char(26).
  206. ESC = number_to_char(27).
  207. colors is 5.
  208. if monitor_type () is mono
  209.    then fore is [white,white,white,white,white] and
  210.         back is [black,black,black,black,black]
  211.    else fore is [white,black,red,black,white] and
  212.         back is [red,green,lightcyan,white,magenta].
  213. item = 0.
  214. current = 1.
  215. new is 'Enter a new file name.'.
  216. last_file is ''.
  217. end. (* setup *)
  218.  
  219.  
  220.  
  221.  
  222.