--
Inside my shell, I wait and bleed.
Written yes, Posted no.
Roughly for the asm version:
__psp is a global in compiled programs, filled in by the startup code.
I am not sure how to find it otherwise.
mov ax,__psp ; sb seg of psp
mov es,ax
mov ax,es:[2ch] ; seg of environ
mov es,ax
mov di,0
mov cx,-1
xor ax,ax
@@: repne scasb ; find a null
scasb ; check next char
jnz @b ; if not null, not end of env
inc di ;
inc di
mov bx,di ; save start of exe name
repne scasb
sub di,bx
dec di
at this point, es:bx has the start, di has the length
The exe name is the last thing in the environment segment, preceeded
by two nulls.
--
ArarghMail808 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html
To reply by email, remove the extra stuff from the reply address.
Thanks. Mind if I use this in a GPL'd project?
--
Now over to our weatherman, Dwayne TheBathtub.
Below is already in the public domain.
It's for PowerBASIC but I am confident you can convert to MS-BASIC without a
whole lot of trouble.
Sorry it's so well commented... I know that has to make you suspicious that
I ever had a clue how to program.
--
Michael C. Mattias
Tal Systems Inc.
Racine WI
mmat...@talsystems.com
' file:exename.bas. creates a UNIT which can be linked which has the
' FUNCTION ExeName$. Exename$ returns the fully qualified DOS file name of
' the current program. See BasicPro Vol. 3 No. 1 (Feb/Mar 1993) page
' 49-50 for the code listing there.
' HISTORY ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' 02.16.93 coded (pb2.10)
' 01.05.94 created pb3.0c UNIT file
' 12.27.95 created PB 3.2 unit file RENAMED EXENAMEU
' 12.04.00 updated to PB 3.5
' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$STACK 2048
' Valid values for $STACK are 1536 thru 32766 (decimal)
$OPTION AUTODIM-, CNTLBREAK+
$LIB ALL OFF
$COMPILE UNIT
DEFINT A - Z ' Variables are Integer unless overridden
FUNCTION ExeFileName$ LOCAL PUBLIC
REG 1, &h6200 ' set AX = &6200 function &62
CALL INTERRUPT &h21 ' call DOS: returns....
EnvSeg= REG(2) ' environment segment in bx
DEF SEG=EnvSeg
EnvPtr& = CLNG(PEEKI(44)) ' bytes 44,45 of envseg
DEF SEG=EnvPtr& ' set segment here
Byte = 0
DO ' search for two zero bytes in a row
IF Peek(Byte) = 0 THEN
IF PEEK(Byte + 1) = 0 THEN
INCR Byte, 2
EXIT LOOP
END IF
END IF
INCR Byte,1
LOOP
IF PEEK(byte)=1 THEN ' if next byte is 1, then the program
INCR Byte,2 ' program name follows.
Temp$=STRING$(128,0) ' set up a buffer
Ptr = 0
DO
IF PEEK(Byte) = 0 THEN ' the name is ASCII-Z terminated (CHR$(0))
EXIT LOOP ' if it ain't terminated, read it in
ELSE ' a byte at a time.
INCR Ptr,1
MID$(temp$,ptr,1)=CHR$(PEEK(Byte))
INCR Byte
END IF
LOOP
ExeFileName$=LEFT$(Temp$,ptr) ' strip trailing chr$(0)
ELSE ' error: return the null string
ExeFileName$= ""
END IF
DEF SEG ' restore default data segment
END FUNCTION ' ExeFileName$
I don't, but this is/was a rewrite of a Crescent Software routine,
which was probably a rewrite of somebody elses routine.
However, it is about the only way to get the info.
This version comes from the MS C 6.00 runtime startup source. It does
about the same thing in about the same way.
mov es,_psp
mov es,es:[DOS_envp] ; get environment segment
mov word ptr [_pgmptr+2],es ; set global var "_pgmptr"
xor ax,ax
cwd ; DX=0
mov cx,8000H
xor di,di ; scan from beginning of environment
find_env_end:
repne scasb
scasb
jne find_env_end
;
inc di ; skip count word (always 0x0001)
inc di
mov word ptr [_pgmptr],di ; set global variable "_pgmptr"
mov cx,-1
repne scasb
not cx
mov dx,cx ; DX=number of bytes in argv[0]
> On Thu, 21 Aug 2008 22:13:02 +0000 (UTC), "Auric__"
> <not.m...@email.address> wrote:
>
>>On Thu, 21 Aug 2008 21:49:06 GMT, wrote:
>>
>>> On Thu, 21 Aug 2008 21:11:35 +0000 (UTC), "Auric__"
>>> <not.m...@email.address> wrote:
>>>
>>>>My "m4d Google sk1llz" have failed me (although I didn't try all that
>>>>hard -- lazy, I know). I'm looking for QBX7 (PDS, whatever) to give me
>>>>the equivalent to VB6's App.Path (full path that the executable is in,
>>>>i.e. "C:\QBX") and App.EXEName (name of the executable, i.e.
>>>>"foo.exe"). I can *probably* do it myself, but I'm hoping that someone
>>>>else has already written it and posted it for others to use. (Again,
>>>>lazy, I know. This is for a toy project; I have other things on my
>>>>plate with higher priority.)
>>>
>>> Written yes, Posted no.
>>>
>>> Roughly for the asm version:
>>>
>>> __psp is a global in compiled programs, filled in by the startup code.
>>> I am not sure how to find it otherwise.
[snippage]
>>> at this point, es:bx has the start, di has the length
>>>
>>> The exe name is the last thing in the environment segment, preceeded
>>> by two nulls.
>>
>>Thanks. Mind if I use this in a GPL'd project?
>
> I don't, but this is/was a rewrite of a Crescent Software routine,
> which was probably a rewrite of somebody elses routine.
>
> However, it is about the only way to get the info.
>
> This version comes from the MS C 6.00 runtime startup source. It does
> about the same thing in about the same way.
Huh. Didn't think to look there. Thanks again.
--
Hysteria isn't going to help us.
> "Auric__" <not.m...@email.address> wrote in message
> news:g8kp9d$b1k$1...@registered.motzarella.org...
>>
>> Thanks. Mind if I use this in a GPL'd project?
>
> Below is already in the public domain.
>
> It's for PowerBASIC but I am confident you can convert to MS-BASIC
> without a whole lot of trouble.
>
> Sorry it's so well commented... I know that has to make you suspicious
> that I ever had a clue how to program.
I'm a bit rusty on my PB/DOS (well, really rusty) but I think I'll end up
using this version, because then I don't have to try to make MS license vs.
GPL work.
--
- You are such an elitist bastard.
- Yeah, but am I wrong?
- Hell no.
A plain MS BASIC version using Call Interrupt is on my Articles page:
http://www.ethanwiner.com/articles.html
Search for ExeName to find it.
--Ethan
And they say there's no place for us 'legacy' programmers.....score one for
the old fogeys!
(And I wouldn't be at all surprised to learn the code in the BasicPro
article from which I worked was yours to begin with).
MCM
Thank you, Mr. Ethan sir. <g> Safe to add to a GPL program, yes?
Been a while since I looked at your stuff, and I gotta say, you got a lotta
stuff up.
--
That Maxwell Snort is a Right Bastard he is.