Mail Archives: djgpp/2011/11/28/21:15:13
"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 -