My "from PACKAGE import *" (Python) simulation project (reflection)

Anything QL Software or Programming Related.
User avatar
XorA
Site Admin
Posts: 1677
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: My

Post by XorA »

tofro wrote:
RalfR wrote: Tue Jul 15, 2025 8:53 am
XorA wrote: Tue Jul 15, 2025 8:15 amsqlux doesn't have clipboard support.
Ideally, sqLux should support both the Unix/Linux clipboard and the Windows clipboard. I doubt XorA will ever implement this.

:D
I'm not so sure: One of the advantages of having switched to SDL2 ist that there is multi-platform support for the system clipboard and drag&drop. It shouldn't be a monster task to implement this.
I think uqlx supports paste as emulated key presses. I really don't know what sqlux should do with a paste event.


User avatar
tofro
Font of All Knowledge
Posts: 3154
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: My

Post by tofro »

XorA wrote: Tue Jul 15, 2025 9:18 am
tofro wrote:
RalfR wrote: Tue Jul 15, 2025 8:53 am Ideally, sqLux should support both the Unix/Linux clipboard and the Windows clipboard. I doubt XorA will ever implement this.

:D
I'm not so sure: One of the advantages of having switched to SDL2 ist that there is multi-platform support for the system clipboard and drag&drop. It shouldn't be a monster task to implement this.
I think uqlx supports paste as emulated key presses. I really don't know what sqlux should do with a paste event.
Well, the "proper" way to handle paste would probably be to put the stuff pasted into the scratch. But that would assume the scratch Thing is present and active on the QL side, which is probably a bit much asked in terms of insight into the guest - I think, I'd simply just inject the key presses with a bit of appropriate delay in-between. "Copy" (from guest to host) is likely much harder to implement.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Aurora
Posts: 901
Joined: Mon Nov 24, 2014 2:03 pm

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by stevepoole »

Hi Folks,
Just been reading the entire thread about merging many basic modules into one program.
I do this sort of thing a lot, but by hand... it's quite quick ! (To get the highest line number LIST or ED 32767 is instantaneos).

First, RENUMber copies of ALL programs to be merged at 25000,1, and save them as say ProgName_mrg1_bas. or 2, 3, etc.
Then Load progname_mrg1_bas, and renumber it 1,1: Then MERGE progname_mrg2_bas and renum 1,1: etc, etc.
Finally RENUM the lot as 100,10 so as to be able to insert lines. (All RESTORES, GOTOs, GOSUBs catered for).

Obviously, the assembled Basic program can be added to at will by the same technique. or have obsolete modules DLINED !
The biggest headache can come from name-table clashes, but here SMSQ/E is great as it supports numerous Locals per FN !
As always, I try to adopt the old programming adage 'KISS', (Keep it simple stupid). Steve.( No offence meant ! ).


User avatar
ql_freak
Super Gold Card
Posts: 551
Joined: Sun Jan 18, 2015 1:29 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by ql_freak »

stevepoole wrote: Sat Jul 19, 2025 8:28 pm First, RENUMber copies of ALL programs to be merged at 25000,1, and save them...
Sorry, that's the problem with your approach (...of ALL programs...). With my reflection toolkit and my "rn" (C-)program it should be possible to merge any program (which [currently] must not have any GO TOs or GO SUBs) without renumbering before.

Note: FULL GO TOs (GO SUBs) will never be supported, but they can be adjusted (if I will succeed...).


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
User avatar
polka
Trump Card
Posts: 214
Joined: Mon Mar 07, 2011 11:43 am

Re: My "from PACKAGE import *" (Python) simulation project (reflection)

Post by polka »

And "with the little help of my..." 15 lines plain(+TK2)SuperBasic FuNction, never bother about line numbers or renumbering :

AddLineNumbers_bas

Code: Select all

   11 DEFine FuNction add_line_numbers(f$,first,interval)
   12    input_file$ = dev$ & f$ & "_txt"
   13    output_file$ = dev$ & f$ & "_bas"
   14    OPEN_IN#5,input_file$
   15    OPEN_OVER#6,output_file$
   16    l = first : i = interval
   17    REPeat number
   18       INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
   19          IF CODE(l$(k))=13 THEN k = k-1
   20          IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
   21       ELSE i = 0 : END IF
   22       IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
   23    END REPeat number
   24    CLOSE#6 : CLOSE#5 : RETurn l
   25 END DEFine add_line_numbers
Give it a file name of a SuperBasic program without line numbers prefixed by a DEV$ and suffixed with "_txt" and it wil create (or overwrite) a line-numbered SuperBasic program file on the same DEV$ and suffixed with "_bas" : with given first line and interval. I coded it as a FuNction so that it could return the last line number.

Now suppose that you have split a SuperBasic program PROG into let's say 4 modules called PROG1..PROG4, in files without line numbers, because you may change or modify some modules while developping the program.

So,"with the little help of your..." SuperBasic file without line numbers (here in its simplest "_text" form !)

MakeProg_txt

Code: Select all

Linc = 10
R = add_line_numbers("Prog1",100,Linc)
MERGE DEV$ & "Prog1_bas"
R = add_line_numbers("Prog2",R+Linc,Linc)
MERGE DEV$ & "Prog2_bas"
R = add_line_numbers("Prog3",R+Linc,Linc)
MERGE DEV$ & "Prog3_bas"
R = add_line_numbers("Prog4",R+Linc,Linc)
MERGE DEV$ & "Prog4_bas"
PRINT R : STOP
You put it through the add_line_numbers to get a corresponding "_bas" file, you merge it and then run it to fetch all the (un-numbered) SuperBasic source modules of PROG1..PROG4, put them through the add_line_numbers and merge them together on the spot.

MakeProg_bas

Code: Select all

    1 Linc = 10
    2 R = add_line_numbers("Prog1",100,Linc)
    3 MERGE DEV$ & "Prog1_bas"
    4 R = add_line_numbers("Prog2",R+Linc,Linc)
    5 MERGE DEV$ & "Prog2_bas"
    6 R = add_line_numbers("Prog3",R+Linc,Linc)
    7 MERGE DEV$ & "Prog3_bas"
    8 R = add_line_numbers("Prog4",R+Linc,Linc)
    9 MERGE DEV$ & "Prog4_bas"
   10 PRINT R : STOP
All automatically ! No problem, even if the size of some modules varied.
And to do it again and again(in this simple case), you may just save all that you need in this file :

MakeProg_etc

Code: Select all

1 Linc = 10
2 R = add_line_numbers("Prog1",100,Linc)
3 MERGE DEV$ & "Prog1_bas"
4 R = add_line_numbers("Prog2",R+Linc,Linc)
5 MERGE DEV$ & "Prog2_bas"
6 R = add_line_numbers("Prog3",R+Linc,Linc)
7 MERGE DEV$ & "Prog3_bas"
8 R = add_line_numbers("Prog4",R+Linc,Linc)
9 MERGE DEV$ & "Prog4_bas"
10 PRINT R : STOP
11 DEFine FuNction add_line_numbers(f$,first,interval)
12    input_file$ = DEV$ & f$ & "_txt"
13    output_file$ = DEV$ & f$ & "_bas"
14    OPEN_IN#5,input_file$
15    OPEN_OVER#6,output_file$
16    l = first : i = interval
17    REPeat number
18       INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
19          IF CODE(l$(k))=13 THEN k = k-1
20          IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
21       ELSE i = 0 : END IF
22       IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
23    END REPeat number
24    CLOSE#6 : CLOSE#5 : RETurn l
25 END DEFine add_line_numbers
However, you understand that "MakeProg" is just another SuperBasic program that may be adapted to more complex situations, using all the power of the SuperBasic langage (conditionnal line adding and merging, etc.).

Note also that the add_line_numbers "_bas" shown above came itself from a "_txt" file maybe with blank lines or spurious CR characters all automatically removed but that the indentations were conserved. This file actually :

AddLineNumbers_txt

Code: Select all

DEFine FuNction add_line_numbers(f$,first,interval)
   input_file$ = dev$ & f$ & "_txt"
   output_file$ = dev$ & f$ & "_bas"
   OPEN_IN#5,input_file$
   OPEN_OVER#6,output_file$
   l = first : i = interval

   REPeat number
      INPUT#5,l$ : k = LEN(l$) : IF k > 1 THEN
         IF CODE(l$(k))=13 THEN k = k-1
         IF k > 0 THEN PRINT#6,IDEC$(l,5,0);" ";l$( 1 TO k )
      ELSE i = 0 : END IF
      IF EOF(#5) THEN EXIT number : ELSE l = l+i : i = interval
   END REPeat number

   CLOSE#6 : CLOSE#5 : RETurn l
END DEFine add_line_numbers


When selecting this code and try to view it in a QL, you will see the CR characters before they are erased by the add_line_numbers FuNction. The blank lines are supressed too.


May the FORTH be with you !
POLKa
Post Reply