NameCheck

Anything QL Software or Programming Related.
User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: NameCheck

Post by dilwyn »

Ooh, better results than I expected. Thank you Steve. I'd been afraid to throw large programs at it so far.

Next part of the project will be:

1. Add an option to work on _sav files - I have notes and code from Norman (thanks again Norman!) which will help a lot with that.
2. Add config block
3. Improve display output to 'page' through long lists
4. Option to send list output to file or printer
5. General code tidy up to avoid some duplication and try to speed it up a little, although speed is great on QPC2. already.


Derek_Stewart
Font of All Knowledge
Posts: 3929
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: NameCheck

Post by Derek_Stewart »

Hi,

I had a look at NameCheck, looks very nicely programmed.

But it is not really what I was meaning, which was to check a variable name is not a resident command or function.

Something like:

IF EXISTS("PI") THEN Pie=4 * ATAN(1)

But I suppose the NameCheck programme could be run after the programme has been saved.

Another alternative would be to use QD Hyperhelp system, which relies on the S*Basic commands being imported into the QD Help system and pressing Help (F1) on the Keyword in question, will bring up the definition. If it does not exist, then the standard help screen is displayed.

A good system, once setup, but relies on reading and understanding the QD manual.

I have created DBAS, EasyPTR, QMENU Toolkit extension help definitions, mainly because I could not remember syntax of creating a DBAS data table.

I have not done much on this project, but I was looking to integrate the ASM help sysem, by listing all the commands for assembler syntax, but still work in progress.


Regards,

Derek
User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: NameCheck

Post by pjw »

Derek_Stewart wrote:<>
But it is not really what I was meaning, which was to check a variable name is not a resident command or function.

Something like:

IF EXISTS("PI") THEN Pie=4 * ATAN(1)
If that sort of thing is truly all you need there is FINDNAME%():

Code: Select all

Given a function or procedure name, FINDNAME% searches the nametable of
job #0 for a match

©pjwitte 2oo2++             Use at own risk!

System requirements: Any QL. Can be used in compiled programs.

Usage:

        type% = FINDNAME%(name$)

        where type% = 0 => no match found
                      1 => procedure found
                      2 => function found
              name$ = upper or lower case name to search for

This can be had of the toolkit section in Knoware.no

For day-to-day use in the CLI I normally use DP's WHERE command. You give it a name, or part of a name, and it lists all names that match, as in WHERE 'QPC_'. This command is found in the IDIS0 toolkit, part of IDIS, DP's "Intelligent" Disassembler.

QD Help is a great, er, help. Pity its such a hassle to keep up to date. However, if you have produced some good quality help files, particularly over rarely-used commands or commands with obscure parameters, Id love to add them.

Glad youre all happily busy! Thats just what we need :)


Per
dont be happy. worry
- ?
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: NameCheck

Post by stevepoole »

Hi Dilwyn,

Just a little point that may need clarifying concening MERGEing:

<< Of course it's as simple as BASIC moves about and details in the nametable change as it runs. Even using the Turbo Toolkit functions to access BASIC structures may see things change between commands. So while a program is trying to examine itself, things can move and cause chaos. >>

As I understood it, BASIC may move up and down to make room if it needs to. But on QPC2 there is plenty of free memory, so surely this is not a problem ?

And if we MERGE another program on to the end of yours, it never gets called because you have used a STOP anyway....

What is changing in the name-table as it runs? LOCals ?

No doubt you can remind me of where to lookfor the details !

Steve.


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: NameCheck

Post by dilwyn »

Why are you so insistent on merging namecheck with your own programs? It's the most clumsy and error prone way of doing this - just don't do it.


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: NameCheck

Post by dilwyn »

dilwyn wrote:Why are you so insistent on merging namecheck with your own programs? It's the most clumsy and error prone way of doing this - just don't do it.
Sorry, I pressed Submit by mistake before finishing the message.

There are two factors involved. I am not sufficiently expert on the internals of SBASIC to fully explain it, here's what I suspect:

1. The Turbo Toolkit commands used to access the BASIC areas were written to be used by the compiler, i.e. alongside BASIC.

2. As NameCheck itself runs when it's merged to your program, it creates and alters variables for itself in your program, so the nametable may expand. I am not fully sure, there seems to be instances where the nametable expands without meaningful data in it. I don't really know if the SBASIC name table expands in "chunks" or by the exact amounts it needs for new names.

All I can say with any certainty is that it works fine from a daughter SBASIC or from a compiled version. I suspect that in addition to the dangers of reading direct from BASIC structures, there may be bugs in NameCheck itself which I haven't found yet. I'm working on handling _sav files atm. The routines for handling those files are just sufficiently different that they may show up bugs in the earlier routines.

You could of course study the routines in NameCheck and work on a shorter, simpler version which would work when merged with a program. The Jan Jones book and the QL Technical Manual both have good descriptions of the internal structures read by my program.


swensont
Forum Moderator
Posts: 252
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: NameCheck

Post by swensont »

I'm trying to understand why there is a need to create NameCheck as a program. If the issue is "have I used a variable name that is used by a toolkit", then it would be far simpler to just create a list of all keywords from toolkits and then just create a script that does a brute force "grep" of each of the keywords against the SuperBasic _bas file. I've done something similar using perl and it runs fairly quick and is about a 10 lines perl program. If doing it in SuperBASIC, you just need to read in the keyword file, and then for each word in that file, fire off a grep (IIRC its comes with C68 and/or the GNU text utilities).

Tim


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: NameCheck

Post by dilwyn »

Long time since I used Grep. I know it can do clever searches, can it cope with the S*BASIC syntax? Can it evaluate the differences between:
LEY key=0
LET keystroke=CODE(INKEY$)
LET key% = 6
IF keys = 1 THEN
LET key$='A'
IF A$="A key is needed"
LET key=2000
GOSUB key
PRINT key%;" is a key requirement"
WHEN key$="A Key"

and so on.

It was written as a program partly because Steve asked, partly because it was an interesting exercice in itself, and partly because I wanted it to cope with syntax, which clearly searching with a Find command in an editor would not suffice, for example.


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: NameCheck

Post by stevepoole »

Hi,

Swensont wrote << I'm trying to understand why there is a need to create NameCheck as a program >>.

It is not everyone who uses many different QL systems... with various obscure toolkits loaded.

When posting code on the Forum, it should be as widely compatible as possible. Preemptively testing ALL known QL names is nigh on impossible.

A big new program will contain lots of names, and it is hard to remember even the common names used by different toolkits which others will be using....

Hence the usefullness of Dilwyn's program TO AVOID CRASHES on your setup. And it seems to be a very fast and effective check. Just what I wanted for ages !

Steve.


swensont
Forum Moderator
Posts: 252
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: NameCheck

Post by swensont »

The goal seems to be to make sure that variables don't use the same name as a keyword. The next step would be how to distinguish a variable in an SB file. LET is one way, but LET does not have to be used. Everything to the left of the = side could be variable. Using multiple grep commands or using regular expressions in Perl would work and take a whole let less coding effort. One could use a variety of text commands (cut, uniq, etc) that some with the GNU Text Utilities to get the job done. Once a list of variables is created, then just compare the list with a list of keywords. It would take a lot less programming time using existing tools.

Tim


Post Reply