Im Magazin „8000 PLUS" wurde im März 1988 der folgende Artikel abgedruckt.
(Im April 1988 erfolgte eine Korrektur)
Ein BASIC-Programm zum Erstellen von Referenzen in BASIC Programmen1
Variable Lister
by Geoff Buckeridge
 
Now all you BASIC programmers have no excuse for not being really organised. Of course it's a good idea to take a careful note of all those variables in a program and what they all do but somehow life always seems loo short to do it. Now this program does virtually everything for you. It simply goes through any listing you want, extracts the names of all the variables, and then presents them in a couple of helpful layouts.
It is really invaluable for those times when you have to stop halfway through a program or when you have a program that you want to develop further. Just save your program in ASCII form (type save "filename",a) and then run this listing. Enter the name of the program to be worked on when asked, and it immediately sets to work picking out all the variables it can find and printing them on screen.
It then allows you to either view on screen or print out the information in a couple of different forms. Style one sorts the variables into alphabetical order, lists the number of times the variable is used and the line numbers it is used in.
Style two lists each variable with the number of the lirst line it is used in, the number of times it is used and a space to allow you to write in a brief description of what the variable does.
One point of interest is the POKE in line 330 which takes everything that would normally be shown on screen and prints out a hard copy. Line 520 puts everything back in order.
[BASIC-Listing]

Gremlins Corner

This month's Gremlins Corner doesn't deal so much with mistakes as with one or two suggested improvements to last month's listings.
The Variable Lister has posed a few problems because the programs you have been running through it are so complicated. If you have more than 50 different variables in your program, the Lister will go wrong. This is easily fixed by changing the DIM statement in line 10. Bump the 50s in this line up to a figure greater than your greatest number of variables to solve this (for example DIM var$(150)).
More complicated is the fact that some programs put through the lister are producing a 'String too long' error message. This is because you've got too many occurrences of a variable (like over 50), and the variable ln$ is getting more than 255 characters in it. Here is a suggestion from Mr J Dulton to get round this. Change line 390 to:
390 a$=ln$(i%):newa$=newln$(i%)
and then change 410 to
410 IF b%=0 THEN newa$=aS+newa$:GOTO 441
Then add
441 IF newa$="" THEN 450 ELSE a%=LEN(newa$):b%=INT(a%/55)
442 IF b%=0 THEN PRINT TAB(26) newa$:GOTO 450
443 c%=INSTR(50,newa$,","):IF c%=0 THEN c%=a%+1
444 PRINT TAB(26) LEFT$(newa$,c%-1):newa$=RIGHT$(newa$,a%-c%)
445 GOTO 441
Now alter 540 to
540 IF var$<>var$(j%) THEN 550
and add
542 no%(j%)=no%(j%)+1
546 IF LEN(ln$(j%))>240 THEN newln$(j%)=newln$(j%)+","+line$ ELSE ln$(j%)=ln$(j%)+","+line$
Other matters to clear up are the fact that of course the program only differentiates between variables and BASIC command words by the fact that it expects variables in lower case and commands in upper case. If you have a program with variables in capitals you must convert them to lower case, which is easily done with PIP. The command
PIP FREDL.BAS=FRED.BAS[L]
creates a file FREDL.BAS which is a lower case version of FRED.BAS (you must have saved FRED.BAS with the ,A option in BASIC). You then convert the BASIC keywords back into upper case simply by LOADing and reSAVEing the program - BASIC automatically converts all the command words back into capitals, so the Variable Lister only picks up the variables.
The final point is something we omitted to mention. The Lister expects the first line of your program to be a REM line which it prints at the top of the page to help you keep track of which program is being listed. If you have any variables in this line they will be ignored.
[Das angepasste BASIC-Listing]

1. Die im Text erwähnten POKE-Anweisungen schränken den Gebrauch des Programmes ein. Es handelt sich hier um eine Adresse der Mallard BASIC Version 1.29. Zwar habe ich die entsprechende Adresse für die von mir genutzen Version 1.47 gefunden, allerdings ist das Programm mit dem Microsoft BASIC nicht lauffähig.

Die Adresse bezieht sich auf die Statement-Tabelle, die bei Version 1.29 bei &H47F9 und bei bei Version 1.47 bei &H4976 beginnt. In der Adresse &H485F steht die Adresse &H5E64, das ist die Adresse der PRINT-Anweisung. Durch die POKE-Anweisung wird die Adresse geändert auf &H5E5A, das ist die Adresse der LPRINT-Anweisung.
330 IF a$="Y" THEN POKE 18527,90 ELSE POKE 18527,100
520 POKE 18527,100:END

Bei der Version 1.47 ist &H6047 die Adresse der PRINT-Anweisung und &H603d die Adresse der LPRINT-Anweisung. In dieser Version muss dann die POKE-Anweisung für Adresse &H49DC ausgeführt werden.
330 IF a$="Y" THEN POKE 18908,61 ELSE POKE 18908,71
520 POKE 18908,71:END
Die Lösung zu dem Problem wäre: Abfrage der Version und dann entsprechende unterschiedliche-Anweisungen — ähnlich wie in FIREWORX — oder Änderung der PRINT- in die LPRINT-Anweisung an den entsprechenden Stellen, wenn das Ergebnis auf dem Drucker protokolliert werden soll.
Ich hatte ein Programm zum Listen von Variablen in Assembler geschrieben. Auch dieses Programm läuft nur mit Variablen unter Mallard BASIC — darüberhinaus läft es nur mit BASIC Tokens anstatt mit ASCII Zeichen. Besser ist da das BASIC-Programm für BASIC Referenzen, das ich für den PCW angepasst habe.

HTML-Bearbeitung von Werner Cirsovius
Dezember 2014
© 8000 PLUS