home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_oth / comal.lzh / COMAL / INFOTEXT / EXAMPLES < prev    next >
Encoding:
Text File  |  1991-08-16  |  6.9 KB  |  290 lines

  1. This database program displays brief instructions
  2. and asks for your text input. Everything you type
  3. BEFORE the last character on a line is considered
  4. data. The LAST character is the COMMAND. Thus what
  5. you type resembles an English sentence.
  6.  
  7.     * End your line with a period, and the data is
  8.          written to the file.
  9.  
  10. * End with a ? and a text search starts.
  11.  
  12. * Type just a ? for a full listing of the file.
  13.  
  14. * Type just a @ to quit.
  15.  
  16. An example RUN is included below. Text the user
  17. types follows the > prompt. The computer response
  18. is on the next line(s) and explanations are inside
  19. <brackets>.
  20.  
  21. RUN
  22. <file is created>
  23. > COMAL is nicer than BASIC.
  24. <text is added to file>
  25.  
  26. > Len Lindsay is Captain COMAL.
  27. <text is added to file>
  28.  
  29. > nicer?
  30. COMAL is nicer than BASIC.
  31.  
  32. > Len Lindsay: 608-222-4432.
  33. <text is added to file>
  34.  
  35. > COMAL?
  36. COMAL is nicer than BASIC.
  37. Len Lindsay is Captain COMAL.
  38.  
  39. > ?
  40. freeform.dat.
  41. Demo.
  42. COMAL is nicer than BASIC.
  43. Len Lindsay is Captain COMAL.
  44. Len Lindsay: 608-222-4432.
  45.  
  46. > @
  47. <program ends>
  48.                                                                                           
  49. Read the directions after the program listing for
  50. info on how to enter this same exact program into
  51. ANY COMAL. (hint: line numbers are required for
  52. COMAL programs, but AUTO will provide them for you
  53. as you type):
  54.  
  55. PAGE // clear the screen
  56. PRINT "Free Form Database by Joel Rea"
  57. PRINT "Last character is the command:" 
  58. PRINT "   .    -- add to file," 
  59. PRINT "   ?    -- search file," 
  60. PRINT "   @    -- exit program." 
  61. DIM line$ OF 80, text$ OF 80
  62. DIM filename$ OF 20, command$ OF 1
  63. filename$:="freeform.dat"; num=7 // file specs
  64. filecheck(filename$,num) // if file not exist,
  65. create it
  66. REPEAT  
  67.   get'line'from'user 
  68.   CASE command$ OF 
  69.   WHEN "." // period
  70.     add'line'to'file 
  71.   WHEN "?" 
  72.     display'matches 
  73.   OTHERWISE  
  74.     NULL // do nothing
  75.   ENDCASE  
  76. UNTIL command$="@" 
  77. END // optional end statement
  78. // 
  79. PROC get'line'from'user  
  80.   PRINT // blank line
  81.   REPEAT  
  82.     INPUT "> ": line$ // user types in something
  83.     max:=LEN(line$) // length of input
  84.   UNTIL max>0 // must enter something
  85.   command$:=line$(max:max) // just last character
  86.   IF max>1 THEN // more than just a command
  87.     line$:=line$(1:max-1) // remove last character
  88.   ELSE  
  89.     line$:="" // only a command, no other text
  90.   ENDIF  
  91. ENDPROC get'line'from'user 
  92. //  
  93. PROC add'line'to'file  
  94.   OPEN FILE num,filename$,APPEND 
  95.   WRITE FILE num: line$ 
  96.   CLOSE FILE num 
  97. ENDPROC add'line'to'file 
  98. //  
  99. PROC display'matches  
  100.   OPEN FILE num,filename$,READ 
  101.   WHILE NOT EOF(num) DO
  102.     READ FILE num: text$ 
  103.     IF line$="" OR line$ IN text$ THEN
  104.       PRINT text$,"."
  105.     ENDIF
  106.   ENDWHILE
  107.   CLOSE FILE num
  108. ENDPROC display'matches
  109. //
  110. PROC filecheck(filename$,filenum) CLOSED
  111.   TRAP // check if the file exists
  112.     OPEN FILE filenum,filename$,READ //try opening
  113.   HANDLER //if file doesn't exist drop down here
  114.     OPEN FILE filenum,filename$,WRITE //create it
  115.     WRITE FILE filenum: filename$,"Demo" //1st rec
  116.   ENDTRAP
  117.   CLOSE FILE filenum //close file from either open
  118. ENDPROC filecheck
  119.  
  120. HOW TO DO IT...
  121.  
  122. It is easy to enter a COMAL program. COMAL helps
  123. you out every step of the way. Before you start a
  124. new program, erase any current program. Type:
  125.  
  126.     NEW   <Enter>
  127.  
  128. After each line, hit the <Enter> key.
  129.  
  130. COMAL programs require line numbers. However, we
  131. list them without line numbers since you can use
  132. AUTO mode to enter the program. Type:
  133.  
  134.     AUTO
  135.  
  136. COMAL will respond with:
  137.  
  138.     0010 *
  139.  
  140. The cursor (shown above as *) is after the line
  141. number 10. You just type the first program line
  142. and hit <Enter>. COMAL then prompts you with the
  143. next line number:
  144.  
  145.     0020 *
  146.  
  147. (Again, the * represents your cursor.) Type each
  148. line in the program in this manner. COMAL will
  149. help you. Don't type in the spaces to indent the
  150. lines. COMAL does that automatically for you. No
  151. need to capitalize the keywords. COMAL will do
  152. that for you too. Don't type the name after
  153. ENDPROC. COMAL will add it for you later. If you
  154. make a mistake, COMAL will offer you advice.
  155.  
  156. After typing all the lines, stop AUTO mode
  157. pressing the <ESC> key.
  158.  
  159. Before you try out the program store it on disk to
  160. be safe. If anything goes wrong (lightning
  161. strikes), you can reload the program from disk.
  162. Type:
  163.  
  164.     SAVE "freeform"
  165.  
  166. Now run the program (see sample run earlier in
  167. this article). Make sure you have the program in
  168. memory before continuing!
  169.  
  170. ROUTINE STEALING!
  171.  
  172. This is a COMAL specialty. It is easy for you to
  173. steal routines (called procedures or functions)
  174. from other COMAL programs, and merge them into a
  175. new program you are writing!
  176.  
  177. To do this just store the routine to disk in ASCII
  178. text form (with the LIST command). To merge it
  179. with a future program use the MERGE command. As an
  180. example let's store the procedure FILECHECK:
  181.  
  182.     LIST filecheck "filecheck"
  183.  
  184. PHONE BOOK, PHASE 1...
  185.  
  186. Now you are ready to try the second program, doing
  187. some routine stealing! First erase the current
  188. program. Type:
  189.  
  190.     NEW
  191.  
  192. As before, the AUTO command gives you line
  193. numbers. Type:
  194.  
  195.     AUTO
  196.  
  197. Now just enter the program as shown just below.
  198. When you get to the end, stop AUTO mode by
  199. pressing the <ESC> key.
  200.  
  201. Now we will merge the routine we are stealing from
  202. Free Form Database. Type:
  203.  
  204.     MERGE "filecheck"
  205.  
  206. COMAL will automatically renumber the lines as
  207. they are merged into the program!
  208.  
  209. The program is now ready to SAVE and RUN. However,
  210. to satisfy your curiosity, list it to see the
  211. merged procedure:
  212.  
  213.     LIST
  214.  
  215. ELECTRONIC PHONE BOOK
  216.  
  217. DIM name$ OF 20,phone$ OF 12
  218. DIM filename$ OF 20
  219. filename$:="phone.dat";num:=5//filespec
  220. filecheck(filename$,num) // check on file
  221. REPEAT
  222.   PRINT "e=enter f=find l=list q=quit"
  223.   CASE INKEY$ OF  
  224.   WHEN "e","E" 
  225.     enter'name 
  226.   WHEN "f","F" 
  227.     INPUT "What name? ": name$
  228.     search'for(name$) 
  229.   WHEN "l","L" 
  230.     search'for("") 
  231.   WHEN "q","Q"
  232.     END // This ends the program here!
  233.   OTHERWISE // not valid key
  234.     PAGE // clear the screen
  235.   ENDCASE  
  236. UNTIL TRUE=FALSE // forever
  237. // 
  238. PROC enter'name 
  239.   INPUT "Enter name:  ": name$ 
  240.   IF name$>"" THEN //name required
  241.     INPUT "Enter phone: ": phone$
  242.     add'to'file 
  243.   ENDIF
  244. ENDPROC enter'name 
  245. // 
  246. PROC add'to'file 
  247.   OPEN FILE num,filename$,APPEND
  248.   WRITE FILE num: name$,phone$ 
  249.   CLOSE  
  250. ENDPROC add'to'file 
  251. // 
  252. PROC search'for(search$) 
  253.   OPEN FILE num,filename$,READ  
  254.   WHILE NOT EOF(num) DO  
  255.     READ FILE num: name$,phone$ 
  256.     IF search$="" or search$ in name$
  257.       PRINT name$,TAB(21),phone$ 
  258.     ENDIF  
  259.   ENDWHILE  
  260.   CLOSE  
  261.   PRINT "Hit <Enter> when ready." 
  262.   WHILE inkey$<>chr$(13) DO NULL
  263. ENDPROC search'for 
  264. <stop AUTO mode here, press <Esc>
  265.  
  266. Here's a sample of what it does:
  267.  
  268. RUN
  269. e=enter  f=find  l=list  q=quit
  270. e
  271. Enter name: Captain COMAL
  272. Enter phone: 608-222-4432
  273. e=enter  f=find  l=list  q=quit
  274. e
  275. Enter name: Emergency
  276. Enter phone: 911
  277. e=enter  f=find  l=list  q=quit
  278. l
  279. phone.dat            Demo
  280. Captain COMAL        608-222-4432
  281. Emergency            911
  282. Hit <Enter> when ready.
  283. e=enter  f=find  l=list  q=quit
  284. f
  285. What name? COMAL
  286. Captain COMAL        608-222-4432
  287. Hit <Enter> when ready.
  288. e=enter  f=find  l=list  q=quit
  289. q  
  290.