CIDS Part -2
In this installment of CIDS, we will develop six essential routines. The only routine that is not a command is the error report routine. Also, as all programs are prone to revisions and extensions, the error routine may not reflect future versions, since the error routine takes memory that could be used for another command.
The names of these routines are:
1. MAKE 4. DELETE 2. FIND 5. DISPLAY 3. ADTO
To get started, LOAD”” and ENTER. Note that if CIDS was not properly SAVEd, you will get a variable not found error. To correct the problem, EDIT 9010 and remove the REM in the statement. RUN the program.
When the READY>> prompt appears, SHIFT 6 and LIST 9010. CIDS is now ready to be edited or otherwise modified.
As I began to program CIDS, I realized that I needed an error routine [Listing One] unlike those used for menu based programs. Since the program is controlled through the parser [200-290], you cannot be sure what command will be presented next. Most of the trapping is therefore taken care of within the subroutines themselves. When an error is detected and if it is sent to the error routine, an appropriate response is displayed on the monitor. Some errors are taken care of within the routines themsevles rather than the error routine. For example, it would be inappropriate to have a special error report if you happen to hit the ‘t’ key instead of the ‘y’ key.
Listing One should be entered now.
The most common error is the ‘no file’ error. When this error is encountered it means that you did not ‘find’ the file before you attempted to work on it. If you remember to ‘find’ your files, then you won’t ever encounter this error. Other errors are a little less encountered. For example, if you try to invoke the ‘previous’ command, but you haven’t used the ‘next’ command. If you think about it a bit, it only makes sense. How can you go to a previous screen if you haven’t gone to at least the second one. This part of the program is almost self explanatory. It gives you an idea of the variety of things that can happen when CIDS is presented with bogus input.
It’s simply impossible to know what is going to be proffered to the program, but it is an easy matter to know what is allowed and what kind of input to look for. We will focus our error trapping, not by predetermining the input, but by using only input that makes sense. Note that the majority of the routines have as their first line of code:
nn IF g=0 THEN GO TO 9995
We know that a file cannot be worked with unless it in working memory. Since g keeps track of this, we know that if g is equal to zero we have no file with which to work. It simply a matter of displaying the appropriate error on the screen. There is no need to balk on the rest of the input because of one error. The error routine is hard to follow, but it is essential if CIDS is to run properly.
The ‘make’ routine [LISTING TWO], is the command that will allow you to create new files. Follow the procedure in Figure two to make a file.
Figure two. Making Files. Filenames must be five or more characters. 1. make <filename> ENTER 2. make <filename>-<extension>- ... ENTER 3. make <filename>[SPACE],[SPACE]<filename> , ... ENTER
In the first case only one file is being made. The second example illustrates the fact that if you are going to make files with names consisting of two or more words, the words must be separated by any character other than a space. The last example creates two different files. Enter listing two. When you are done, practice making your own files. Remember that you must use GO TO 98 to get CIDS running again.
Resume editing CIDS. Now that you have the ability to make files, you will need some way to locate them. This can easily be accomplished by a loop that compares the name that you supply with the names in the database. Then it is simply a matter of printing the appropriate responses. The ‘find’ command [LISTING THREE] will allow you to do this. The command syntax is:
1. find <filename> ENTER
As CIDS stands right now you cannot do anything to the files you find. The majority of your time will probably be spent editing files. This means that you will need a routine that allows you to:
1. Edit files easily. 2. Restore messed up files to their original state. 3. Accomodate new commands.
Figure three. Full screen editor commands. To access the editor: 1. You must have a file in memory. If you don't, then 'find' one. 2. From READY>> enter the command 'adto,' and you will be in the SCAN MODE. SCAN MODE commands. 5, 6, 7, 8, keys Cursor movement. h key Home (1,1) position SHIFT 1 keys Go to EDIT MODE r key Return to READY>> prompt. EDIT MODE commands. SHIFT 5, 6, 7, 8, Cursor movement. SHIFT 4 key Insert characters. SHIFT 0 key Delete characters. ENTER Acts as a return key. SHIFT 1 keys Go to SCAN MODE.
The next command to take care of is the ‘display’ command [LISTING FIVE]. This command will allow you display any file on the screen. Of course the file must be found if it is to be displayed. Enter listing five into the computer. To display files, enter ‘display’ at the READY>> prompt, and the file that is currently being worked with will be promptly displayed.
This is a lot more work than you think. Just take a gander at listing four and you will see what I mean! In Figure three, you will find a table of the commands available while using the editor. This is by no means a full compliment of commands.
When entering listing four be extra careful. One wrong GO TO can cause errors that are difficult to trace. Any line that has N/U as its annotation can be omitted. When you are done, test the editor by actually editing a file. Make sure to use every command available. If there are any discrepencies use a GO TO 98 and edit the file again. In this way you will be able to hunt down and crush any errors that crop up. Remember that a shifted space bar will stop the editor, simply CONTINUE to resume.
As you can see, the subroutine is extremely simple. First, it does some error detecting, and then it calls a subroutine that checks to see if you want to display only a certain range of lines. After completing this subroutine, a call to the screen adjust makes the display pleasing to the eye. The loop starting at line 710 actually displays the file on the screen.
The subroutine starting at line 750 checks the first character of a$. If it is not a number, then we return. Otherwise you take the VAL of the numbers and store them in the variables h and i. These two variables control the loop to display the file. To use the line clause, follow this syntax:
disp xx to xx where xx is a two digit number.
disp 01 to 09 will display the first nine lines of every file. The line clause will stay in effect until you change it again.
Now that you can create, edit and display files, you will need a way to remove unwanted files from the database. Since we are not working with linked lists or tree structures, we will use a simple method of deletion. This entails writing over the file to be removed with the file that immediatly follows it, and continuing until the entire database is moved up one file. This brute force method will eliminate the offending file while keeping the integrity of the rest of the database. Enter listing six into the computer. Now when you wish to delete a file, you simply find it and invoke the delete command. You will be prompted to verify the delete process.
Before the file is deleted, it is written to a 2D array. This array can be written back to the database if you decide that you want the file back. As it is now, you are unable to ‘restore’ a file. Although most of the work can be done by the routines we have just written, it will be up to you whether or not you wish to wait for the next installment of CIDS, or boldly plunge into the unknown and attempt to write a restore routine for yourself.
You will be unable to save or load your database from CIDS, but you can program these routines from Basic if needed. I am going to save these for the next issue. In the next issue we will discuss the following commands as well:
1. SORT 4. PREVIOUS 2. NEXT 5. RESTORE 3. NAME 6. MOVE
LISTING ONE – ERROR ROUTINE [9995-9999]
9995 PRINT "[illegible] ";w$( TO 4);">";
9996 PRINT ("no file" AND w$="right")+("no file" AND w$="left")+("no file" AND w$="cent")+("no fie" AND w$="copy")+("no file" AND w$="move")+("no file" AND w$="zone2")+("no file" AND w$="edit1")+("no file" AND w$="bloc1")+("no file" AND w$="adto")+("out of range" AND w$="zone1")+("no file" AND w$="dele")+("no file" AND w$="display");
9997 PRINT ("see pg.28" AND w$="zone4")+("no file" AND w$="grap")+("no previous file" AND w$="prev")+("column?" AND w$="zone")+("next before find" AND w$="next")+("out of range" AND w$="disp")+("operator required" AND w$="eval")+("name short" AND w$="find")+("name short" AND w$="make");
9998 PRINT " pg.";(18 AND w$="disp")+(25 AND w$="left")+(27 AND w$="righ")+(27 AND w$="cent")+(12 AND w$="make")+(13 AND w$="find")+(14 AND w$="adto")+(16 AND w$="dele")+(18 AND w$="display")+(19 AND w$="next")+(20 AND w$="prev")+(22 AND w$="move")+(30 AND w$="zone")+(32 AND w$="eval")+(29 AND w$="sort")
9999 PRINT : RETURN
9995-9998 print 'error' and appropriate response depending on w$ 9999 print blank and return VARIABLES USED w$ =: word sliced from a$ or set from program.
LISTING TWO – MAKE ROUTINE
1510 IF LEN a$<5 THEN GO TO 9995
1512 GO SUB 240
1513 IF LEN w$<5 THEN GO TO 9995
1517 IF f=mf THEN PRINT ">--CAPACITY REACHED--<"
1518 IF f=25 THEN GO TO 9995
1519 LET s$=w$
1520 LET f=f+1: LET f$(f,1)=s$: PRINT s$;" >--MADE--<"
1535 RETURN
1510 command line <5 chars.? 1512 slice filename out of a$ 1513 filename <5 chars.? 1517 # files (f)= max allowed 1518 files equal mf? 1519 store name of file in s$ 1520 open new file: insert name: print response 1535 return to process next command VARIABLES USED a$ =:command line mf =:max. no. of files w$ =:word sliced from a$ s$ =:general purpose variable f =:file counter f$(f,1) =:first line of file f
LISTING THREE – FIND ROUTINE [500-555]
500 IF LEN a$<5 THEN GO TO 9995
505 GO SUB 240: IF LEN w$<5 THEN GO TO 9995
515 LET s$=w$
530 FOR g=1 TO f: IF f$(g,1, TO LEN s$)=s$ THEN GO TO 555
540 NEXT g
541 LET g=prev
545 PRINT s$;" <NOT THERE>": RETURN
555 PRINT s$;" >--FOUND--<": RETURN
500 command line< 5 chars. 505 slice filename out of a$: filename <5 chars? 515 store name in s$ 530 loop to search for file 540 keep looping until a match is found or all files exhausted 541 g=previous filenumber 545 file not found report 555 file found report: return VARIABLES USED a$ =: command line w$ =: word sliced from a$ s$ =: general purpose g =: loop f =: file counter prev =: number of previous file
LISTING FOUR – ADTO ROUTINE
5010 IF g=0 THEN GO TO 9995
5015 CLS : PRINT AT 0,0; INK 6; FLASH 1;"SETTING": GO SUB 6000: PRINT AT 0,0; FLASH 0;"[illegible]
5020 GO SUB main
5025 RETURN
5030 PRINT AT 0,0;"l ";l;" chr ";c
5040 PRINT AT x,y; INVERSE 0;b$(l,c): LET x=x+1: IF x>ml THEN LET x=ml
5042 LET l=l+1: IF l>ml THEN LET l=ml
5046 GO TO main
5060 PRINT AT x,y; INVERSE 0;b$(l,c): LET x=x-1: IF x<1 THEN LET x=1
5062 LET l=l-1: IF l<1 THEN LET l=1
5066 GO TO main
5070 PRINT AT x,y; INVERSE 0;b$(l,c): LET y=y+1
5072 LET c=c+1: IF y>(mc-1) THEN LET y=(mc-1)
5076 IF c>mc THEN LET c=mc: GO TO main
5078 GO TO main
5080 PRINT AT x,y; INVERSE 0;b$(l,c): LET y=y-1: IF y<0 THEN LET y=0
5082 LET c=c-1: IF c<1 THEN LET c=1
5086 GO TO main
5088 PRINT AT 0,0;"EDIT MODE"
5090 LET e$=INKEY$
5091 IF INKEY$=CHR$ (7) THEN GO TO 1000
5092 IF e$="" THEN GO TO 91
5093 LET b$(l,c)=e$
5094 PRINT AT x,y;b$(l,c)
5095 GO TO 90
5096 PRINT AT 0,0;" ": GO TO main
5098 PRINT AT x,y;b$(l,c): LET x=1: LET y=0: LET l=1: LET c=1: LET pl=1: LET pc=1: LET bc=1: LET ec=32: GO TO main
5100 LET ec=ec+1: IF ec>80 THEN LET ec=80
5102 LET bc=bc+1: LET y=31: IF c>80 THEN LET c=80
5104 GO TO main
5120 LET bc=bc-1: IF bc<1 THEN LET bc=1
5122 LET ec=ec-1: LET y=0: IF c<1 THEN LET c=1
5124 IF ec<mc THEN LET ec=mc
5125 LET c=c-1: IF c<1 THEN LET c=1
5126 GO TO main
5150 LET main=5154: PRINT AT 0,0; INK 1; FLASH 1;"EDIT MODE"; FLASH 0
5154 IF x=0 THEN LET x=1
5155 PRINT AT x,0;b$(l,bc TO ec);AT x,y; INVERSE 1; INK 2; PAPER 7;b$(l,c);AT 0,18; PAPER 0; INK 1;"ln "; INK 6;l;"[illegible]";AT 0,26; INK 1;"ch "; INK 6;c; INK 1;"[illegible]"
5156 LET c$=INKEY$: IF c$="" THEN GO TO 5156
5157 LET v=CODE c$: IF v>13 AND v<32 THEN GO TO 5155
5158 IF v>143 THEN GO TO 5155
5159 IF v=13 THEN GO TO 5400
5160 IF v=10 THEN GO TO 5040
5170 IF v=11 THEN GO TO 5060
5180 IF v=9 THEN GO TO 5070
5190 IF v=8 THEN GO TO 5080
5195 IF v=7 THEN GO TO 5300
5196 IF v=12 THEN GO TO 5310
5197 IF v=5 THEN GO TO 5430
5198 GO TO 5201
5200 GO TO main
5201 LET b$(l,c)=c$: PRINT AT x,y;c$: LET c=c+1: IF c>mc THEN LET c=1
5202 LET y=y+1: IF y>(mc-1) THEN GO TO 5245
5219 GO TO main
5220 LET y=1: GO TO main
5230 LET bc=bc+1:: LET ec=ec+1: IF ec>(mc-1) THEN GO TO 5245
5240 GO TO main
5245 LET c=1: LET ec=31: LET bc=1: LET l=l+1: IF l>ml THEN LET l=ml
5250 LET x=l: LET y=0: GO TO main
5300 PAUSE 20: LET main=5500: PRINT AT 0,0;"[illegible] GO TO main
5312 LET b$(l,c TO )=b$(l,c+1 TO ): GO TO main
5313 LET b$(l,c TO )=" "+b$(l,c TO ): GO TO main
5314 LET y=y-1: IF y<0 THEN LET y=0
5318 GO TO main
5400 PRINT AT x,y;f$(g,l,c): LET l=l+1: IF l>ml THEN LET l=ml
5410 LET c=1: LET y=0: LET bc=1: LET ec=mc: LET x=x+1: IF x>ml THEN LET x=ml
5420 GO TO main
5430 LET b$(l,c TO )=" "+b$(l,c TO ): GO TO main
5500 PRINT AT 0,0; FLASH 1; INK 5;"SCAN MODE"
5501 PRINT AT x,0;b$(l,bc TO ec);AT x,y; INVERSE 1; INK 4;b$(l,c);AT 0,18; INK 3;"ln "; INK 5;l;"[illegible]";AT 0,26; INK 3;"ch "; INK 5;c; INK 3;"[illegible]"
5510 LET c$=INKEY$: IF c$="" THEN GO TO 5510
5520 IF c$="6" THEN GO TO 5040
5530 IF c$="7" THEN GO TO 5060
5540 IF c$="8" THEN GO TO 5070
5550 IF c$="5" THEN GO TO 5080
5560 IF c$=CHR$ (7) THEN GO TO 5150
5570 IF c$="h" THEN GO TO 5098
5575 IF c$="r" THEN GO TO 6060
5580 GO TO main
6000 LET main=5500: LET text=5201: LET a$="": DIM b$(21,32): LET x=1: LET y=0: LET l=1: LET c=1: LET pl=1: LET pc=1
6030 LET bc=1: LET ec=mc:
6040 FOR w=1 TO ml: LET b$(w)=f$(g,w): NEXT w
6045 FOR w=1 TO ml: PRINT INK 4; INVERSE 1;b$(w): NEXT w: FOR w=21 TO 1 STEP -1: PRINT AT w,0; INK 1; INVERSE 1;b$(w): NEXT w: PRINT AT 1,0;: FOR w=1 TO ml: PRINT b$(w): NEXT w: RETURN
6060 PRINT AT 0,0; FLASH 1; INK 4;"RESTORING": FOR w=1 TO ml: LET f$(g,w)=b$(w): NEXT w
6070 FOR w=1 TO 21: PRINT INK 3; INVERSE 1;b$(w): NEXT w: FOR w=21 TO 1 STEP -1: PRINT AT w,0; INK 5; INVERSE 1;b$(w): NEXT w: PRINT AT 1,0;: FOR w=1 TO 21: PRINT b$(w): NEXT w: PRINT AT 0,0; INK 4;"Ok --------": RETURN
5010 file to be edited? 5015 set screen & variables 5020 go to SCAN mode 5025 return 5030 output cursor pos. 5040 cursor down 5042 ditto 5046 go to main 5060 cursor up 5062 ditto 5066 go to main 5070 cursor right 5072 ditto 5076 ditto: go to main 5078 go to main 5080 cursor left 5082 ditto 5086 go to main 5088 go to EDIT mode 5090 accept keyboard input 5091-5095 N/U 5096 clean status line 5098 home cursor position 5100-5126 N/U 5150 see line 5560: EDIT mode-set main to 5154 5154 error trap 5155 print text, current cursor pos. and set up status line 5156 keyboard input in c$ 5157 take the CODE of c$: error trapping 5158 error trap 5159 ENTER key 5160 cursor down 5170 cursor up 5180 cursor right 5190 cursor left 5195 SCAN mode (SHIFT '1' 5196 delete character 5197 insert character 5198 it's a character not a command so insert it into the file 5200 do it again 5201 insert the character: adjust the cursor pos. 5202 our we on the last line of the file? 5219 go to main 5220 adjust y 5230 N/U 5240 N/U 5245 move cursor down: check for last line 5250 adjust x: adjust y 5300 go back to SCAN MODE 5312 delete character at cursor pos.: go to main 5313 insert character at cursor pos.: go to main 5314 adjust y 5318 go to main 5400 ENTER routine 5410 ditto 5420 go to main 5430 insert character 5500 SCAN mode: set up status line 5501 ditto 5510 accept keyboard input 5520 cursor down 5530 cursor up 5540 cursor right 5550 cursor left 5560 go to EDIT mode 5570 put cursor at (1,1) 5575 return to READY>> 5580 do it again 6000 set up editor variables 6030 ditto 6040 loop to put file to be edited in a 2D array 6045 flashy screen display 6060 restore file: put 2D array back into 3D array of database 6070 flashy screen display return to READY>>
LISTING FIVE – DELETE ROUTINE
1080 IF g=0 THEN GO TO 9995
1090 CLS : PRINT AT 0,0;"Delete file ";f$(g,1, TO 18): LET x=2: INK 7: GO SUB 300: INPUT "Are you sure? "; LINE y$
1091 IF y$="y" THEN GO TO 1094
1092 IF y$<>"n" THEN GO TO 1090
1093 RETURN
1094 FOR s=1 TO ml: LET r$(s)=f$(g,s): NEXT s
1100 FOR s=g TO f: PRINT AT 1,0;
1105 FOR t=1 TO ml
1110 PRINT AT t,0;f$(s,t): LET f$(s,t)=f$(s+1,t): PRINT AT t,0; PAPER 2; INK 0;f$(s+1,t)
1115 NEXT t: BEEP .01,40: NEXT s: LET f=f-1: LET x=0: INK o: CLS : GO SUB 300: PRINT AT 0,0;s$;" >--DELETED--<": LET g=0: RETURN
1080 file to delete? 1090 print filename and verification prompt 1091 delete the file? 1092 abort the procedure 1094 loop to move file to be deleted into a temporary storage array so that it can be restored if you desire 1100 loop through the database 1110 display current line in file: overwrite file to be deleted 1115 keep looping: beep after each file: move to next file in database:
Media
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.