Page 1 of 6

Writing $$external extensions with QLib

Posted: Wed Jan 29, 2020 5:05 pm
by HAOUI
Firstly, an (little long) introduction to explain why I have wished this topic.

Recentely I have decided to write some extensions for QL plateforms using Externals QLIB tools which was fairly new to me. At the begining it seemed very easy to write some Basic PROCs, compile, LRESPR binary et have resident extensions ready to use.

But when I wanted something more serious to be done, I realized that it was quite difficult to make programs work in a table and secure way on different systems.

So, I started interesting exploring and learning period to find out some useful and fundamentals rules, at least not documented enough AFAIK, but necessary.

I wanted to share my experience here and discuss improvements and solutions that could be found to reduce cavities and issues in this likely inacheved implementation under QLib.

I will start here with a minor and general point about the QLib Run time which is crucial when writing and using externals. We absolutely need to use the right version, modified, patched, repatched...Otherwise, things go very wrong and very very often crash and freeze the system.

I tried several packages and patch programs but nothing really worked for me. I finally found the only one run time library that really worked, from QLiberator page on Dilwyn site (obviously), over all my QL plateforms.

This one is untitiled "QLIB_RUN modified 2" (qlibrunmod2.zip from unknown author) with a very short description saying "To get External compiled procedures working on SMSQ/E systems". Indeed it really works on SMSQ/E but also on all systems that I could tested (SGC/Minerva/SMSQ, Q40, QPC2, QDOS/JS).

I don't know if anyone can confirm this and if Yes, it will be a good idea to be clairely stated some where and may be included in "official" QLiberator kit.

it's really useful not to have to get embeded this Run Time in each external extension because extensions reside all time in memory (unless you OVERLAY - for QLib fluidely users). I wrote some complexes externals within 3-4 KBytes for binary, while Run Time is bigger than 10 Kbytes.

Next time, I will address how Exit/RETurn from an External extension without crash/freeze the system...Not trivial.

Re: Writing $$external extensions with QLib

Posted: Sat Feb 01, 2020 6:25 pm
by EmmBee
HAOUI wrote: This one is untitiled "QLIB_RUN modified 2" (qlibrunmod2.zip from unknown author) with a very short description saying "To get External compiled procedures working on SMSQ/E systems". Indeed it really works on SMSQ/E but also on all systems that I could tested (SGC/Minerva/SMSQ, Q40, QPC2, QDOS/JS).

Next time, I will address how Exit/RETurn from an External extension without crash/freeze the system...Not trivial.
It is good to hear that the latest QLIB_RUN works well on all your systems. This should mean that you could have just one Boot file unmodified which would work on all your systems.

I have written a Qlib external called DCOPY, the 'D' standing for DATE. So, I can DCOPY "File_A" TO "File_B", and it will copy the file including the DATE. This only works on SMSQ/E. One thing I have to remember is to always use the quote marks, else it won't work.

I'll look forward to reading your next article on returning from such externals without crashing the whole works.

Re: Writing $$external extensions with QLib

Posted: Sun Feb 02, 2020 8:35 am
by HAOUI
It is good to hear that the latest QLIB_RUN works well on all your systems. This should mean that you could have just one Boot file unmodified which would work on all your systems.
This is what I have observed on my several systems at least with QLIB V3.36 but I don't know if still true with earlier versions. Will be good to have more feedback.
I have written a Qlib external called DCOPY, the 'D' standing for DATE. So, I can DCOPY "File_A" TO "File_B", and it will copy the file including the DATE.
I totaly agree. I don't like that COPY modify date of the file while it has not been modified.
Backup option in QPAC2 does not modify date but there is no equivalent command.
One thing I have to remember is to always use the quote marks, else it won't work.
Passing name paramaters to $$external is a real cavity especially with PARNAM$() and PARSTR$() FUNCtions not working under QLIB.
I spent a lot of time exploring this point and wrote a program to monitor name tables of jobs. I understand now what is going on but still unable to find a reliable solution. I would like to rewrite PARNAM$() and PARSTR$() that work with $$external but I need some more information on how QLIB store some pointers in the OBJ file (may be Martin could help).
Anyway i will share what i know about parameters passing. Keep watching.
Alain

Re: Writing $$external extensions with QLib

Posted: Sun Feb 02, 2020 11:27 am
by Andrew
EmmBee wrote: I have written a Qlib external called DCOPY, the 'D' standing for DATE. So, I can DCOPY "File_A" TO "File_B", and it will copy the file including the DATE. This only works on SMSQ/E. One thing I have to remember is to always use the quote marks, else it won't work.
Please, can you publish the DCOPY ? I would like to use it in QLCommander instead of Copy .
Do you also have a variant of WCOPY that preserves the date ?
In QL Commander I use both Copy and WCopy and it would be nice to be able to preserve the date.

Re: Writing $$external extensions with QLib

Posted: Sun Feb 02, 2020 6:29 pm
by EmmBee
Andrew wrote:
EmmBee wrote: I have written a Qlib external called DCOPY, the 'D' standing for DATE. So, I can DCOPY "File_A" TO "File_B", and it will copy the file including the DATE. This only works on SMSQ/E. One thing I have to remember is to always use the quote marks, else it won't work.
Please, can you publish the DCOPY ? I would like to use it in QLCommander instead of Copy .
Do you also have a variant of WCOPY that preserves the date ?
In QL Commander I use both Copy and WCopy and it would be nice to be able to preserve the date.
I've just updated DCOPY so that it runs from the PROG_USE directory. The source is included.
It does both Copy and also WCopy including recursing down any sub-directories encountered. You can also enter a pattern, as you can in DIR or WSTAT, etc.
I hope it works for you. Let me know if there are any problems.
DCOPY.zip
(16.06 KiB) Downloaded 209 times

Re: Writing $$external extensions with QLib

Posted: Sun Feb 02, 2020 7:08 pm
by RalfR
EmmBee wrote:
Andrew wrote:
EmmBee wrote: I have written a Qlib external called DCOPY, the 'D' standing for DATE. So, I can DCOPY "File_A" TO "File_B", and it will copy the file including the DATE. This only works on SMSQ/E. One thing I have to remember is to always use the quote marks, else it won't work.
Please, can you publish the DCOPY ? I would like to use it in QLCommander instead of Copy .
Do you also have a variant of WCOPY that preserves the date ?
In QL Commander I use both Copy and WCopy and it would be nice to be able to preserve the date.
I've just updated DCOPY so that it runs from the PROG_USE directory. The source is included.
It does both Copy and also WCopy including recursing down any sub-directories encountered. You can also enter a pattern, as you can in DIR or WSTAT, etc.
I hope it works for you. Let me know if there are any problems.
DCOPY.zip
I think "SET_HEAD" and "GET_HEAD" from SG are quite good to preserve the dates,

Re: Writing $$external extensions with QLib

Posted: Sun Feb 02, 2020 7:25 pm
by Andrew
EmmBee wrote:I've just updated DCOPY so that it runs from the PROG_USE directory. The source is included.
It does both Copy and also WCopy including recursing down any sub-directories encountered. You can also enter a pattern, as you can in DIR or WSTAT, etc.
I hope it works for you. Let me know if there are any problems.
DCOPY.zip
Thank you !

Re: Writing $$external extensions with QLib

Posted: Mon Feb 03, 2020 7:17 pm
by HAOUI
Ralf R. wrote:I think "SET_HEAD" and "GET_HEAD" from SG are quite good to preserve the dates,
Alternately, for simple COPY you can use standard TK2 commands to reset original update date;

oldate=FUPDT(\file_A):COPY file_A TO file_B:SET_FUPDT \file_B,oldate

(pay attention to backslash)

Alain

Re: Writing $$external extensions with QLib

Posted: Mon Feb 03, 2020 7:25 pm
by RalfR
HAOUI wrote:
Ralf R. wrote:I think "SET_HEAD" and "GET_HEAD" from SG are quite good to preserve the dates,
Alternately, for simple COPY you can use standard TK2 commands to reset original update date;

oldate=FUPDT(\file_A):COPY file_A TO file_B:SET_FUPDT \file_B,oldate

(pay attention to backslash)
This may put the version +1?

Re: Writing $$external extensions with QLib

Posted: Mon Feb 03, 2020 7:41 pm
by HAOUI
Ralf R. wrote:This may put the version +1?
Usually, COPY command doesn't change the version number but if this happens in some way, you have similar TK2 commands to reset the version number;

oldvers=FVERS(\file_A):COPY file_A to file_B:SET_FVERS \file_B,oldvers

Alain