The Elementary Amiga
This month's installment focuses on the CLI and talks about special directories, logical devices, and timesaving command files. With command files, you can create your own CLI "macros" for copying fonts, deleting multiple files, or almost anything.
You may have noticed that most CLI commands reside in a directory called C (the directory has nothing to do with the language C). CLI commands are simply programs. So if I type ZAP, and there's a program called ZAP in my current directory, that program loads and runs. If I enter DIR, the computer looks for the DIR program in my current directory. Chances are, the computer will not find DIR in the current directory. In this case, it looks in the C directory.
C is just one of the Amiga's special directories. If I enter EXECUTE STARTUP—SEQUENCE, the computer knows that if it doesn't find the STARTUP—SEQUENCE in the current directory, it should look in the S directory. And if an Amiga Basic program contains a LIBRARY statement asking the system to load a specific BMAP file, the computer looks in the LIBS directory.
A number of Amiga directories are set aside for special jobs. But how does the Amiga know to look in these directories? Whenever the Amiga needs to access certain types of information, it uses a logical device.
Logical devices can be referred to just like hardware devices, such as DF0: for the internal disk drive or PRT: for a printer. For example, if the computer needs the system disk for some reason, it refers to it as logical device SYS:. When you boot your Amiga, the computer assigns SYS: to the Workbench disk that starts the system.
The Amiga has six other logical devices that are used to point to different disks and/or directories. These devices are explained below.
Logical device C: tells the computer where to look for CLI commands. By default, this device points to the C directory on the Workbench disk from which you booted. S: points to the S (sequence) directory, where the computer looks for command files. Files in this directory can usually be listed with the CLI's TYPE command and often make interesting reading.
DEVS: points to the DEVS directory, which holds information on devices. Information about your printer is found here, plus modules for handling other input/output operations. L: points to the L (library) directory. This contains overlays for large commands and nonresident parts of the operating system.
LIBS: specifies the LIBS directory, where information for Open Library calls is stored. Generally, this directory doesn't contain program code, just lookup tables. Logical device FONTS: points to the FONTS directory, where character fonts are kept. If you don't use fonts, you can delete this directory with no ill effects.
There's one more logical device called T: for temporary. During editing and similar operations, a copy of your original file is placed here. That way, if you really botch things up you can go back to the earlier file.
To see a complete list of logical devices and what disks and/or directories they are currently linked with, enter the CLI command ASSIGN without any parameters.
Flexible Commands With EXECUTE
If there's a series of commands that you need to repeat, EXECUTE can do the job nicely. We'll start with a simple example and then work up to something more elegant.
Suppose you want to search through a series of disks to see which ones contain the ADD-BUFFERS command within the C directory. You could insert each disk into DF1: and enter LIST DF1:C/ADDBUFFERS. That seems like a lot of typing, and if you're like me, you're likely to spell something wrong. You might find it easier to create a file named Q containing this command and then EXECUTE it repeatedly. Try this:
ECHO > RAM : Q "LIST DF1 : C / ADDBUFFERS" COPY C : EXECUTE RAM : EX CD RAM:
The first line creates a file called Q on the ramdisk, containing our LIST command; the second line copies the EXECUTE command to RAM, with a shorter name (EX); and the last line switches our current directory to RAM. Now, each time we put a disk into DF1:, we need only enter EX Q, and the command LIST DF1:C/ADDBUFFERS is executed. If ADDBUFFERS is not on the disk, you get an object not found response. If the file exists, the computer gives you details such as ADDBUFFER's file size and date.
Let's try something more complex. Suppose we want to copy a complete font set from one disk to another. In fact, maybe we want to copy several fonts.
Font copying is tedious. First, you must make a directory with the correct name on the target disk. Then you must copy all the individual fonts into the newly created directory. Finally, you must copy the associated .FONT file into the target disk's FONTS directory. This process is hard enough with just one font, but when you have to copy several fonts, it really becomes work.
Try this: Enter the command ED S:FC to create a new file within the S directory called FC (for Font Copy). Now enter the following lines:
.KEY fontname/a IF NOT EXISTS DF1 : FONTS MAKEDIR DF1 : FONTS ENDIF MAKEDIR DF1 : FONTS/<fontname> COPY DF0 : FONTS/<fontname> TO DF1 : FONTS/<fontname> COPY DF0 : FONTS/<fontname>.FONT TO DF1:FONTS
The first line insists on receiving a font name with this command. Lines 2–4 create a FONTS directory on the disk in DF1: if one does not already exist. Line 5 creates the font's subdirectory on the disk in DF1:. Line 6 copies the contents of the font's subdirectory from the disk in DF0: to the disk in DF1:, and line 7 copies the associated .FONT file to disk in DF1:. When you've completed entering this command file, press ESC, X, and then RETURN to wind things up.
Now, if you want to copy a set of fonts called SAPPHIRE from a disk in DF0: to a disk in DF1:, just enter EXECUTE FC SAPPHIRE. If you have several fonts to copy, this command file makes the job easy. Don't forget that by copying this command file into the ramdisk and entering CD RAM:, you can really speed things up.
More Command Files
The versatility of ED and the power of EXECUTE can make some useful combinations. Let's look at the possibility of deleting a whole set of files from a disk.
Insert a disk from which you'd like to delete a number of files into DF1: and type
LIST >RAM : FLIST DF1 : QUICK
Of course, you may list a subdirectory if that suits your purposes or use pattern matching to single out certain types of files. After entering this command, we have a list of files stored away in RAM:FLIST. Edit it with
ED RAM : FLIST
You'll see a list of files and directories, together with the header Directory . . . Move the cursor to this top line and press the ESC, D, and RETURN keys to delete this line.
In the same way, go through this list, removing the names of files that you don't want to delete. You can press the ESC-D sequence again, if you wish; alternatively, you may find it easier to press CTRL-G, which repeats the previous command. Either way, continue through the list until you have deleted the final line, which shows the count of files and directories.
At this point, you might like to press ESC followed by SA and then RETURN to save the file in its current state. Now, get ready for the high-powered stuff.
Press ESC and then type the following line, followed by a RETURN:
T; RP (E //DELETE DF1:/; N)
Let me explain this string of commands. The character T means go to the top of the document. The RP means repeat the following sequence in parentheses. In the repeated section, E means to exchange every null string (there's nothing between the first two slashes) with DELETE DF1:. The N commands the computer to move to the next line. Or in simpler terms, these commands mean go to the top of the text and insert the characters DELETE DF1: at the start of each line until you run out of lines.
Now we have a file to do some work for us. Exit the editor by pressing ESC, X, and RETURN. Then, assuming you really want to delete all those files on the disk in DF1:, activate the command file with
EXECUTE RAM : FLIST
You may have access to other supereditors with which you can do the same sort of thing. But if not, ED does the job neatly.
More To Come
Next time, we'll look at some more of my favorite CLI commands and take a closer look at multitasking.