I have always thought that Archive has always been one of the underrated programming languages for the QL. When I first looked at Archive, it reminded me a lot of dBase III. What has limited me from really programming in Archive has been not having a big need to write a database application and not knowing Archive well enough to get what I wanted done.
Granted Archive is not the best database programming language for the QL, but it has two distinct things going for it: it is adequate enough for most database needs, and EVERY QL user has a copy. If you were going to write a database for other QLers to use, you would do it in Archive.
Recently when I did want to create a database application by putting the Master Sinclair E-Mail list in Archive and write some procedures to generate the lists. The problem I ran into is the knowledge factor I mentioned above. Joining two tables in Archive is not too obvious by reading the limited QL guide. Bill Cable has written a series of columns for UPDATE on Archive, but I have yet to get the energy to sit down and read them. To make it easier, Bill said that he is working on putting all of the columns in one booklet. For those who don’t know Bill Cable, he sells QL software as Wood & Wind Computing, and is probably THE North American Archive programmer.
One small nagging thing about programming in Archive is that the _prg files are not indented. When editing procedures in Archive, everything is indented, making the code easy to read. When you save the file and go to print it out, it’s all left justified. The following SuperBasic program takes in an Archive _prg file and indents it.
I’ve played with Archive and it will accept an indented file when you LOAD a procedure, but it still saves it as left justified. This means that you can create your code in another editor, load it into Archive to test, run it through the indenter, and still have code that will work in Archive.
Archive’s native indentation style is a little off the norm of indenting. It uses a style like this:
proc dummy
---------------
---------------
---------------
endproc
The more accepted style of indenting is like this:
proc dummy
--------------
--------------
--------------
endproc
By uncommenting two lines of code (marked in the code) and deleting these lines later in the code, the program will support the native Archive indenting style. You will also need to delete the two IF statements with “else” in them (when determining when to indent or unindent). Archive does not normally unindent an ELSE statement.
## Archive Indent
## This program will take a Archive program
## and produce an indented version of the
## program.
NONE = 0
PLUS = 1
MINUS = 2
OPEN #3,con_300x200a75x0_32
BORDER #3,2,4
PAPER #3,0 : INK #3,4 : CLS #3
PRINT #3,"Enter input file: (_prg) "
INPUT #3,in_file$
PRINT #3,"Enter output file: "
INPUT #3,out_file$
## assume all input files have a _prg ext.
in_file$ = in_file$&"_prg"
OPEN #4,in_file$
OPEN_NEW #5,out_file$
## indent$ holds how many spaces to indent.
## it will grow and shrink with the indenting.
indent$ = ""
REPEAT loop
indent = NONE
IF EOF(#4) THEN EXIT loop
INPUT #4,in$
## To use the same indent style as Archive does,
## uncomment these lines and delete/comment the
## same lines below.
## ## ignore any leading blanks
## temp = first_char(in$)
## PRINT #5,indent$;in$( temp TO )
first$ = first_word$(in$)
IF first$ = "endproc" THEN indent = MINUS
IF first$ = "endif" THEN indent = MINUS
IF first$ = "endwhile" THEN indent = MINUS
IF first$ = "endall" THEN indent = MINUS
IF first$ = "endcreate" THEN indent = MINUS
IF first$ = "else" THEN indent = MINUS
## if minus then shrink indent$
IF indent = MINUS THEN
IF LEN(indent$) = 3 THEN
indent$ = ""
ELSE
indent$ = indent$( 1 TO LEN(indent$)-3)
END IF
END IF
## ignore any leading blanks
temp = first_char(in$)
PRINT #5,indent$;in$( temp TO )
IF first$ = "proc" THEN indent = PLUS
IF first$ = "if" THEN indent = PLUS
IF first$ = "while" THEN indent = PLUS
IF first$ = "all" THEN indent = PLUS
IF first$ = "create" THEN indent = PLUS
IF first$ = "else" THEN indent = PLUS
## increase indent$ by 3 spaces
IF indent = PLUS THEN indent$ = indent$ & " "
END REPEAT loop
CLOSE #5
CLOSE #4
CLOSE #3
STOP
## Function first_word$
DEFine FuNction first_word$(a$)
LOCal x
REPEAT loop1
IF a$(1) = " " THEN
a$ = a$( 2 TO )
ELSE
EXIT loop1
END IF
END REPEAT loop1
x = " " INSTR a$
IF x = 0 THEN RETURN a$
RETURN a$( 1 TO x-1)
END DEFine
## Function first_char
## returns the location of the first non-white
## space character.
DEFine FuNction first_char (a$)
LOCal count
count=1
REPEAT loop2
IF a$(count) = " " THEN
count = count + 1
ELSE
RETURN count
END IF
END REPEAT loop2
END DEFine first_char