delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/01/14/13:30:40

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Trace-PostClient-IP: 68.147.177.20
From: Brian Inglis <Brian DOT Inglis AT SystematicSW DOT Invalid>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: intdos question
Organization: Systematic Software
Message-ID: <jn2gu0poddqg34n9cp2mr4dq4u29323lg5@4ax.com>
References: <oGSFd.353$N25 DOT 335 AT newsfe3-gui DOT ntli DOT net>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Lines: 96
Date: Fri, 14 Jan 2005 18:25:32 GMT
NNTP-Posting-Host: 24.71.223.147
X-Complaints-To: abuse AT shaw DOT ca
X-Trace: pd7tw1no 1105727132 24.71.223.147 (Fri, 14 Jan 2005 11:25:32 MST)
NNTP-Posting-Date: Fri, 14 Jan 2005 11:25:32 MST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Fri, 14 Jan 2005 16:45:08 GMT in comp.os.msdos.djgpp, "Mike C"
<My DOT address AT end DOT of DOT post> wrote:

>Can somebody please point me in the right direction?
>
>I have written a parser, which parses a source file and creates a
>destination file.
>
>To operate the program, I select the source file in Windows explorer and
>drag it onto a shortcut to my program. This leaves the path to the source
>file in argv[1].  My problem is that the string that I find in argv[1] is
>all in DOS 8.3 format.  I would like to name the destination file the same
>as the source file, with a long filename, changing only the extension.
>
>As I know the short filename, I thought of using findfirst() and findnext()
>to locate the long filenames, then generate the short filename for each one
>and compare it to the known short filename. Simple in concept!
>
>I have been looking at Ralph Brown's interrupt list, int21, AX=7160.
>
>It says :
>
>AX = 7160h
>CL = 00h
>CH = SUBST expansion flag
>  00h return a path containing true path for a SUBSTed drive letter
>  80h return a path containing the SUBSTed drive letter
>DS:SI -> ASCIZ filename or path (either long name or short name)
>ES:DI -> 261-byte buffer for canonicalized name
>
>Return:CF set on error
>AX = error code
>  02h invalid component in directory path or drive letter only
>  03h malformed path or invalid drive letter
>ES:DI buffer unchanged
>CF clear if successful
>ES:DI buffer filled with fully qualified name
>AX destroyed
>
>... so I guess I need to load DS:SI with a pointer to my long filename
>buffer, and it will return a pointer to the short filename in ES:DI, but
>that's where I get stuck.

You want to go the other way from short to long, don't you? 
You use subfunction 2 to get the long name from the short name. 

>I'm not very familiar with the Intel registers.  How do I get my pointer
>into DS:SI?  If I'm not mistaken, SI is an index register that gets added to
>DS?  How do I work it all out?
>
>With thanks to anybody who spends their precious time on this,

You need to use the go32 transfer buffer in low memory.
Try this: 

#include <dpmi.h>
#include <go32.h>

/* get lfn */
static char *
get_lfn( char *long_name, const char *short_name, int long_len)
{
      __dpmi_regs r;

      dosmemput( short_name, strlen(short_name)+1, __tb);
      r.x.ax = 0x7160;          /* Truename */
      r.x.cx = 2;                       /* Get long name */
      r.x.ds = r.x.es = __tb / 16;
      r.x.si = r.x.di = __tb & 15;
      __dpmi_int(0x21, &r);

      if (r.x.flags & 1 || r.x.ax == 0x7100)
      /* Shouldn't happen: LFN *is* supported and file *does* exist.
*/
        return NULL;

      dosmemget(__tb, long_len, long_name);
      return long_name;
}

and wrap the call with a test, just to be safe:

#include <fcntl.h>
#include <string.h>

...

  if (!_use_lfn( short_name )
        || !get_lfn( long_name, short_name, long_len))
    strcpy( long_name, short_name);

-- 
Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada

Brian DOT Inglis AT CSi DOT com 	(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address		use address above to reply

- Raw text -


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