!pr1
!lm12
!rm75
A Filename Editor for CATALOG ARRANGER..............Bill Morgan

Many thanks to all of you who have called and written to say how much you like the CATALOG ARRANGER.  I'm glad to hear that others find it as useful as I do.  Here's my favorite addition to the program, the ability to edit the filename in the cursor.  Now you can change a name by inserting or deleting characters, insert control characters, and place display titles in the catalog, using normal, inverse, flashing, or lower case text.

There are a couple of unique features in this editor.  The cursor clearly indicates Insert, Overtype, or Override mode, and also shows whether the input will be Normal, Inverse, Flashing, or Lower Case.  The display unambiguously shows all these types, plus Control.  The price of all this clarity is three display lines for one text line, but that's no problem in this program.  These concepts can easily be adapted to edit any line of forty or fewer characters.  The principles also apply to longer lines, but the screen display would have to be handled carefully.


Installation

To add FILENAME EDITOR to CATALOG ARRANGER just type in S.FILENAME.EDITOR from this listing, and save it on the same disk with S.CATALOG.ARRANGER.  Then LOAD S.CATALOG.ARRANGER and make the following changes and additions:

!lm+5
1030       .TF CATALOG.ARRANGER.NEW

1480 LINE.COUNT   .EQ 21

1915       CMP #$85    ^E
1920       BNE .1
1922       JSR RENAME.FILE
1924       JMP DISPLAY.AND.READ.KEY

5865       .IN S.FILENAME.EDITOR
!lm-5

Then SAVE the new S.CATALOG.ARRANGER and assemble it.


Operation

To rename a file, just use the arrow keys to move the cursor to the file you want, and type "CTRL-E" (for Edit).  The name you selected will appear near the bottom of the screen, between square brackets.  Any control characters in the name will have a bar above them.  The caret below the first character of the name is the cursor.  Any non-control characters you type will replace the characters on the screen.  Control characters will have the effects shown in the command list below.  Especially note that RETURN will enter the name in the lower buffer into the filename array, ESC will return you to the Arranger without altering the filename, and CTRL-R will restore the original filename.

One way to have fun with this program is to put dummy files in the catalog, for titles or just for decoration.  In Applesoft, SAVE as many dummy programs (10 REM, for example) as you need.  Then BRUN CATALOG ARRANGER, move the dummy programs to where you want them, and edit the names.  If you start the new file name with six CTRL-H's, it will blank out the "A 002 " before the name.  You can use inverse, flashing or lower case text in titles.  If you insert CTRL-M's (RETURNS) after a name there will be blank lines in the catalog.  Play with it for a while, and let me know if you come up with any especially neat tricks.

Here are the commands:

!lm+10
!pp-10
   <-- -- Left Arrow.  Move the cursor left one position.
   --> -- Right Arrow.  Move the cursor right one position.
RETURN -- Enter.  Enter the changed name into the upper display.
   ESC -- Escape.  Return to arranging, without entering the changed name.
    ^B -- Beginning.  Move the cursor to the beginning of the line.
    ^D -- Delete.  Delete one character at the cursor.
    ^E -- End.  Move the cursor to the end of the name.
    ^F -- Find.  Move the cursor to a particular character.  Type "^FA" to move the cursor to the next "A" in the name.  Type another "A" to move to the following "A", and so on.  Any character other than the search key will be entered or executed.
    ^I -- Insert.  Turn on Insert Mode.  Following characters will be inserted to the left of the backslash cursor.  Any control character turns Insert off.
    ^O -- Override.  Insert the next character typed "as is".  This allows you to insert control characters into a name.
    ^R -- Restore.  Restore the name to its original condition, as it appears in the upper display.
    ^S -- Shift Mode.  Cycle between Normal, Inverse, Flashing, and Lower Case entry.  The cursor changes to show the current mode.
    ^Z -- Zap.  Remove all characters from the cursor to the end of the name.
!lm-10
!pp0


How it All Works

When you type CTRL-E to enter the editor, line 1090 transfers the filename into an edit buffer located in the screen memory at $757-$774.  The main loop of the editor is lines 1190-1320.  All through the editor the Y-register is the cursor position in the line.  The routine DISPLAY.EDIT.BUFFER shows the brackets before and after the name, puts bars over any control characters, displays the cursor, and gets the next keystroke.  The main loop then checks whether that key was a control.

If it was not a control character, it is passed to the input section (lines 1340-1570), where the character is masked according to the current MASK.MODE (Normal, Inverse, Flashing, or Lower-case) and either inserted or just placed in the line.  The program then jumps back to E.START to redisplay the buffer and get the next key.

If you enter a control character, the program JSR's to the SEARCH.AND.PERFORM routine at lines 3250-3390 (taken straight from Bob's article in the August '82 AAL.)  Here we look up the command key in the table at lines 3420-3550 and do a PHA, PHA, RTS type branch to the appropriate command handler, or to the monitor's BELL, if the command didn't match anything in the table.

Almost all of the command handlers end with an RTS that returns control to line 1320.  The exceptions are OVERRIDE (lines 1590-1650) and RESTORE (lines 2150-2180), since they exit through internal JMP's, and RETURN/ESC (lines 2660-2720), since those return to the main program.  Another oddity is the FIND routine (lines 2420-2640), since it has two exits.  Line 2640 returns to line 1320 through the BELL routine.  Lines 2590-2620 are needed to process a keystroke that is not a repetition of the search key.
