Post by tsh73 on Jan 24, 2019 21:38:45 GMT
Attempt at making EXE programmatically
create BAS -> TKN -> EXE
(I have very vague idea why could one wish to do that.
Making compiler with JB as code generator?)
tested on JB 2 under Win 10.
Probably will work on LB with paths/filenames tuned (not tried yet).
How it works:
program has bunch of string constants at the top, saying
where JB folder is, how JB EXE named, how runtime named, what destination folder is,
and listing all necessary DLLs/SLLs.
After start program checks if these paths/filenames are exist, if not program aborts.
Then program ask for a file name, for example "hello".
Then it creates project folder as <destination folder >\hello
It asks a few things about future program
and writes it as
<destination folder >\hello\hello.bas
Something along
(then it opens it in Notepad just to show off. You can safely close it)
Now, the task is to create TKN file.
There is a command line switch that starts that (documented in help file under "Using a Different Code Editor"), but the process stops on SAVE TKN dialog. So you have to press OK a few times. Program waits for you with a message "Press ENTER then ready".
(alternatively you can automate these "OK pressing" with some tool like AHK or AutoIt. I happen to have AHK installed - so I compiled this script saveTKNok.ahk to saveTKNok.exe:
It does work for me under Win 10, but I cannot be sure it works always.
(and "ahk_class #32770" looks like a black magic for me, so I'm rather surprised it works at all)
If you want it, just uncomment
)
Now if you pressed Enter on "Press ENTER then ready"
(or some program did that for you), program checks if TKN file is created in <destination folder >\hello folder.
If it is, it copies / renames runtime (in our example it will be hello.exe)
and copy all necessary DLL/SLL. (copy done via DOS/Windows command line COPY command)
Finally it opens project folder
<destination folder >\hello
in explorer
- it should contain BAS file, TKN file, renamed runtime EXE, and necessary DLL/SLL
If you run this EXE you'll get message box with title and message you provided.
Mission accomplished
If you run program again and give another filename, you'll have another folder with all stuff in <destination folder>.
Program writes to a mainwin, something like this
Finally, the program itself
create BAS -> TKN -> EXE
(I have very vague idea why could one wish to do that.
Making compiler with JB as code generator?)
tested on JB 2 under Win 10.
Probably will work on LB with paths/filenames tuned (not tried yet).
How it works:
program has bunch of string constants at the top, saying
where JB folder is, how JB EXE named, how runtime named, what destination folder is,
and listing all necessary DLLs/SLLs.
After start program checks if these paths/filenames are exist, if not program aborts.
Then program ask for a file name, for example "hello".
Then it creates project folder as <destination folder >\hello
It asks a few things about future program
and writes it as
<destination folder >\hello\hello.bas
Something along
nomainwin
notice "made EXE"+chr$(13)+"Hello there"
end
but with things you've just entered instead of these strings.(then it opens it in Notepad just to show off. You can safely close it)
Now, the task is to create TKN file.
There is a command line switch that starts that (documented in help file under "Using a Different Code Editor"), but the process stops on SAVE TKN dialog. So you have to press OK a few times. Program waits for you with a message "Press ENTER then ready".
(alternatively you can automate these "OK pressing" with some tool like AHK or AutoIt. I happen to have AHK installed - so I compiled this script saveTKNok.ahk to saveTKNok.exe:
IfWinExist Save *.TKN File As...
{
WinActivate
Send {Enter}
;Sleep 2000
if WinActive("ahk_class #32770")
{
;file alreday exist - say Overwrite
;ahk_class #32770
Send {tab}{Enter}
}
Sleep 1000
if WinActive ("ahk_class #32770")
{
;saved as
Send {Enter}
}
}
else
{
MsgBox Save TKN dialog is not active
}
It does work for me under Win 10, but I cannot be sure it works always.
(and "ahk_class #32770" looks like a black magic for me, so I'm rather surprised it works at all)
If you want it, just uncomment
'RUN "saveTKNok.exe"
line.)
Now if you pressed Enter on "Press ENTER then ready"
(or some program did that for you), program checks if TKN file is created in <destination folder >\hello folder.
If it is, it copies / renames runtime (in our example it will be hello.exe)
and copy all necessary DLL/SLL. (copy done via DOS/Windows command line COPY command)
Finally it opens project folder
<destination folder >\hello
in explorer
- it should contain BAS file, TKN file, renamed runtime EXE, and necessary DLL/SLL
If you run this EXE you'll get message box with title and message you provided.
Mission accomplished
If you run program again and give another filename, you'll have another folder with all stuff in <destination folder>.
Program writes to a mainwin, something like this
Attempt at making EXE programmatically
create BAS -> TKN -> EXE
0) Checking files/folders
LBpath$= C:\Program Files\Just BASIC v2.0
exists
LBexe$= jbasic.exe
exists
LBruntime$= jbrun2.exe
exists
DestPath$= C:\WRK\JB\madeEXE
exists
1) Create BAS file
Enter file name (no extension):hello
BAS file name:
hello.bas
make a directory for a project:
C:\WRK\JB\madeEXE\hello
gathering data for BAS file...
Enter window title:A title
Enter message:Hello there
creating file hello.bas...
created BAS file:
C:\WRK\JB\madeEXE\hello\hello.bas
running file in Notepad (just close it)
2) Creating a TKN file
this will leave SAVE TKN dialog
*Just press ENTER*
(and on Information box(es) press Ok too)
Press ENTER then ready
C:\WRK\JB\madeEXE\hello\hello.tkn
exists
3) Copy necessary files
runtime
C:\WRK\JB\madeEXE\hello\hello.exe
exists
DLL / SLL
C:\WRK\JB\madeEXE\hello\vbas31w.sll
C:\WRK\JB\madeEXE\hello\vgui31w.sll
C:\WRK\JB\madeEXE\hello\voflr31w.sll
C:\WRK\JB\madeEXE\hello\vthk31w.dll
C:\WRK\JB\madeEXE\hello\vtk1631w.dll
C:\WRK\JB\madeEXE\hello\vtk3231w.dll
C:\WRK\JB\madeEXE\hello\vvm31w.dll
C:\WRK\JB\madeEXE\hello\vvmt31w.dll
Folder with project
C:\WRK\JB\madeEXE\hello
-=*over*=-
Finally, the program itself
'attempt at making EXE programmatically
'tsh73 Jan 2019
'paths and filenames. Check them!
LBpath$="C:\Program Files\Just BASIC v2.0"
LBexe$="jbasic.exe"
LBruntime$="jbrun2.exe"
DestPath$="C:\WRK\JB\madeEXE"
DllList$="vbas31w.sll vgui31w.sll voflr31w.sll vthk31w.dll vtk1631w.dll vtk3231w.dll vvm31w.dll vvmt31w.dll"
qq$=chr$(34) '(")
'" -> ";qq$;"
print "Attempt at making EXE programmatically"
print " create BAS -> TKN -> EXE"
print
'0) check files/folders
print "0) Checking files/folders"
ok=1
print "LBpath$=",LBpath$
res=pathExists(LBpath$)
if res then print " exists" else print " not exists"
ok=ok and res
print "LBexe$=",LBexe$
res=fileExists(LBpath$,LBexe$)
if res then print " exists" else print " not exists"
ok=ok and res
print "LBruntime$=",LBruntime$
res=fileExists(LBpath$,LBruntime$)
if res then print " exists" else print " not exists"
ok=ok and res
print "DestPath$=",DestPath$
res=pathExists(DestPath$)
if res then print " exists" else print " not exists"
ok=ok and res
if not(ok) then
print "-----------------------"
print "program aborted - check your files/folders!"
end
end if
'1) create BAS file
print
print "1) Create BAS file"
input "Enter file name (no extension):";fname$
'fname$="hello"
fname0$=trim$(fname$) 'base name
fname$=fname0$
if right$(lower$(fname$),4)<>".bas" then fname$=fname$+".bas"
print "BAS file name: "
print, fname$
'make a directory for a project
DestPath1$=DestPath$;"\";fname0$
print "make a directory for a project: "
print, DestPath1$
'goto [copy]
result = mkdir(DestPath1$)
if result = 183 then
print "-----------------------"
print "Directory for a project "
print " ";DestPath1$
print "already exists - delete it or change your filename"
end
end if
if result <> 0 then
print "-----------------------"
print "Directory for a project "
print " ";DestPath1$
print "not created - check your filename"
end
end if
print "gathering data for BAS file..."
input "Enter window title:";ttl$
input "Enter message:";msg$
print
print "creating file ";fname$;"..."
' nomainwin
' notice "made EXE"+chr$(13)+"Hello there"
' end
open DestPath1$;"\";fname$ for output as #1
#1, "nomainwin"
#1, "notice "; qq$;ttl$;qq$; "+chr$(13)+"; qq$;msg$;qq$
#1, "end"
close #1
print "created BAS file: "
print, DestPath1$;"\";fname$
call pause 300
print "running file in Notepad (just close it)"
run "notepad.exe ";DestPath1$;"\";fname$
'2) create TKN file
print
print "2) Creating a TKN file"
print "this will leave SAVE TKN dialog"
print " *Just press ENTER* "
print "(and on Information box(es) press Ok too)"
'RUN "JBASIC -T -A PROG.BAS"
RUN LBpath$;"\";LBexe$;" -T -A ";DestPath1$;"\";fname$
'this leaves a dialog or two. If one pass ENTER there it will help.
'now, this file is AHK script pressing OK for you
call pause 2000 'may take a while
'RUN "saveTKNok.exe"
input "Press ENTER then ready";dummy$
print ,DestPath1$;"\";fname0$;".tkn"
res=fileExists(DestPath1$,fname0$;".tkn")
if res then print " exists" else print " not exists"
ok=ok and res
if not(ok) then
print "-----------------------"
print "TKN creation failed"
end
end if
[copy]
'3) copy files
print
print "3) Copy necessary files"
'runtime
print "runtime"
from$=LBpath$;"\";LBruntime$
to$=DestPath1$;"\";fname0$;".exe"
'run "cmd.exe /k echo ";qq$;from$;qq$;" ";qq$;to$;qq$
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
call pause 300
print , to$
res=fileExists(DestPath1$,fname0$;".exe")
if res then print " exists" else print " not exists"
ok=ok and res
'dll sll
print "DLL / SLL"
w$=""
i=0
while 1
i=i+1
w$=word$(DllList$,i)
if w$="" then exit while
from$=LBpath$;"\";w$
to$=DestPath1$;"\";w$
print ,to$
run "cmd.exe /c copy ";qq$;from$;qq$;" ";qq$;to$;qq$
wend
print "Folder with project"
print DestPath1$
run "explorer ";qq$;DestPath1$;qq$
print "-=*over*=-"
'-----------------------------
sub pause mil
t=time$("ms")+mil
while time$("ms")<t
scan
wend
end sub
function fileExists(path$, filename$)
dim info$(0, 0)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function
function pathExists(path$)
'if we need it exist anyway
'catch error "Directory already exists".
pathExists = (mkdir(path$)=183)
end function