delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2011/11/28/21:15:13

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Rod Pemberton" <do_not_have AT noavailemail DOT cmm>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: argv[0]
Date: Mon, 28 Nov 2011 21:05:49 -0500
Organization: Aioe.org NNTP Server
Lines: 67
Message-ID: <jb1ejh$hm8$1@speranza.aioe.org>
References: <16b04d29-8317-4c7f-929c-1a22a328fa32 AT p9g2000vbb DOT googlegroups DOT com> <jaueod$2t8$1 AT speranza DOT aioe DOT org> <9bf257a7-a0f8-43ba-a65f-36c6027f68cb AT r28g2000yqj DOT googlegroups DOT com>
NNTP-Posting-Host: qBjb0U1QTH77eiTXJSCpEw.user.speranza.aioe.org
X-Complaints-To: abuse AT aioe DOT org
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.2001
X-Notice: Filtered by postfilter v. 0.8.2
X-Newsreader: Microsoft Outlook Express 6.00.2800.2001
X-Priority: 3
X-MSMail-Priority: Normal
Bytes: 4202
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Georg" <dosusb AT googlemail DOT com> wrote in message
news:9bf257a7-a0f8-43ba-a65f-36c6027f68cb AT r28g2000yqj DOT googlegroups DOT com...
> I am looking for the absolute path to the running progam. Ralph Brown
> mentions this in table 01379 and I thought argv[0] may be a way in
> djgpp to retrieve that.
>
> Here is a link to that table 01379:
> http://www.ctyme.com/intr/rb-2682.htm
>
> I tried to use _go32_info_block.linear_address_of_original_psp to get
> the PSP and then read the environment block segment from 0x2C in there
> but did not succeed in reading the envrionment and following that the
> absolute path that way.
>

I've not had to do this, so some of the suggested details below may be
incomplete, sketchy, or plain wrong, but it's what I would try ...

1) It might be available as an internal variable.  You'll have to find that
on your own ...  e.g., might be int crt0.S or crt1.c or c1args.c etc.

2) Alternately, you should be able to call Int 21h, ah=51h or Int 21h,
ah=62h to get the current PSP segment.  You'll need to setup and use
__dpmi_int() to call DOS interrupts.  Next, you'll need to copy BX into a C
variable.  Then, multiply variable with BX's value from one of those DOS
calls by 16 to get an offset.  Then, you'll need to use dosmemget() with the
BX*16 offset to copy the word ("unsigned short" in this case) at 2Ch into a
C variable.  Next, that variable will have to be multipled by sixteen also
to convert the segment to an offset.  Next, you should be able to use
dosmemget() with the computed 2Ch offset to copy the data in memory that
RBIL describes as table 01379.  Or, it should be something like that ...

3) You can use DOS' "truename" functions to expand a known path.  I.e., if
the current directory is the directory the app was executed from, you should
be able to trim argv[0] to just the filename and file extension using
strrchr() for '\\', append ".\\" to the front and expand.  Note that the
backslashes are escaped with a backslash, i.e., two means just one of them.
To append, you'll do something like strcat() the trimmed argv[0] onto a
string filled with ".\\" via strcpy(var,".\\")), e.g.:

  strcpy(str,".\\");
  if(strrchr(argv[0],'\\'))
    strcat(str,strrchr(argv[0],'\\')+1);
  else
    strcat(str,argv[0]);

If argv[0] always has one backslash, you can eliminate the if, keeping the
first body.  str will need to have sufficient space pre-allocated, i.e.,
declared as an empty "array" of characters of sufficient length or a char
pointer set via malloc() of sufficient space.  For SFN's, you can call Int
21h, ah=60h using __dpmi_int().  If LFN support is available, i.e., Win98
"dosbox" or Haftmann's DOSLFN driver, you can use the LFN truename function,
Int 21h, AX=7160h with CL=2 using __dpmi_int().  That'll return the full
path expanded will all LFNs.  7160h also accepts CL=0 and 1.  One of them
returns the full path but as SFNs instead of LFNs.  Of course, all of this
is dependent on having the correct directory.  Otherwise, you may have to
walk the default paths for the application, hopefully, only finding one by
that name.  There is a DJGPP function for walking directories, and probably
some for reading the default paths or maybe they already work together ...

HTH,


Rod Pemberton



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019