Groups | Search | Server Info | Login | Register


Groups > comp.os.os2.programmer.tools > #19

Re: DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor)

From "A.D. Fundum" <what.ever@neverm.ind>
Message-ID <cSWxyCWhUBcp-pn2-ukwFVnsMMr19@localhost> (permalink)
Newsgroups comp.os.os2.programmer.tools, comp.os.os2.programmer.misc, comp.os.os2.apps
Subject Re: DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor)
References <4dfdcf49$0$7624$9b4e6d93@newsspool1.arcor-online.net> <o8uYFJ3iqTdG-pn2-lddw7WF8YUTz@localhost> <o8uYFJ3iqTdG-pn2-dKTjwP0UB8sB@localhost> <97c9mpF42tU1@mid.uni-berlin.de> <o8uYFJ3iqTdG-pn2-l1zCrydyidcP@localhost>
Organization News-Service.com
Date 2011-07-21 22:54 +0200

Cross-posted to 3 groups.

Show all headers | View raw


 >>> As an aside: is there an API or function which consistenly 
returns
 >>> the case of a directory as-is, with or without the drive letter?
 
 >> A combination of DosQueryPathInfo with DosFind* works for me.
 >> (DosFindNext returns the correct case, so SysFileTree may work
 >> as well for REXX.)

 > [D:\Database\Caf‚]dir

 > Directory of D:\Database
 > 4-07-11 10:50          <DIR>      0 ----  Caf‚

FTR: this seems to work. It prints the current directory of a drive, 
recursivly using DosFind* in the final stage to preserve, or rather 
respect, the original case.

Together with e.g. Sergey Yevtushenko's CLIP.CPP this already has some
use, possibly while installing software and creating WPS program 
objects. It's basicly the CMD.EXE-equivalent of a RMB on a WPS folder 
object to copy the full path of a directory to the eCS clipboard: 
"PRINTDIR | CLIP". 

I haven't embedded the clipboard funcionality, so PRINTDIR isn't 
DIR2CLIP. For one because the .subject-EA of a file downloaded with 
FF/SM also is a possible candidate to be copied to the clipboard, and 
I don't really want an *.EXE for each silly idea, with RFC #1 being a 
version which optionally adds quotes to the full path. Hey, write your
own Rexx 2Clip-frontend! ;-) 

--


/* ICC PRINTDIR.C, Q&D Worked At Least Once For Me Amateur Alert */

#define INCL_DOSFILEMGR

#include <direct.h>
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[])
{
APIRET rc;
char *buffer,buffer2[CCHMAXPATH],path[CCHMAXPATH],path2[CCHMAXPATH];
FILEFINDBUF3 filebuf={0};
HDIR hdir=HDIR_SYSTEM;
int drive=0,length,position;
ULONG filebuflen=sizeof(FILEFINDBUF3),searchlimit=1;

if (argc>2)
   {
   printf("Usage: PRINTDIR.EXE [drive]\n");
   return 1;
   }
if (argc==2)
   {
   if (strlen(argv[1])!=2)
      {
      printf("Usage: PRINTDIR.EXE [drive]\n");
      return 1;
      }
   if (argv[1][1]!=':')
      {
      printf("Usage: PRINTDIR.EXE [drive]\n");
      return 1;
      }
   if (argv[1][0]>90)
      argv[1][0]-=32;
   if (argv[1][0]<'A')
      {
      printf("Usage: PRINTDIR.EXE [drive]\n");
      return 1;
      }
   if (argv[1][0]>'Z')
      {
      printf("Usage: PRINTDIR.EXE [drive]\n");
      return 1;
      }
   drive=argv[1][0]-64;
   }

if (drive)
   buffer=_getdcwd(drive,buffer2,CCHMAXPATH);
else
   buffer=_getcwd(buffer2,CCHMAXPATH);
if (NULL==buffer)
   {
   fprintf(stderr,"SYS0021: The drive is not ready.\n");
   return 1;
   }

/* No root directory? DosFindFirst() each involved (sub-)directory */
if (strlen(buffer)>3)
   {
   while (strlen(buffer)>3)
      {
      rc=DosFindFirst(buffer,&hdir,FILE_DIRECTORY,&filebuf,filebuflen
                      &searchlimit,FIL_STANDARD);      
      if (rc)
         {
         fprintf(stderr,"DosFindFirst() error: rc=%u\n",rc);
         return 1;
         }
      length=strlen(buffer);   
      position=length;
      while (buffer[position]!='\\'&&position>3)
         --position;
      buffer[position]='\0';
      if (strlen(path))
         sprintf(path2,"%s\\%s",filebuf.achName,path);
      else
         sprintf(path2,"%s",filebuf.achName);
      sprintf(path,"%s",path2);
      rc=DosFindClose(hdir);
      if (rc)
         {
         fprintf(stderr,"DosFindClose() error: rc=%u\n",rc);
         return 1;
         }
      }
   strcat(buffer,path);
   }

if (strlen(buffer)<3)
   {
   fprintf(stderr,
           "Error: unexpected number of characters (%u) in %s\n",
           strlen(buffer),buffer);
   return 1;
   }

printf("%s\n",buffer);

return 0;
}

Back to comp.os.os2.programmer.tools | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Force gnu assembler to invoke the preprocessor Marcel Müller <news.5.maazl@spamgourmet.org> - 2011-06-19 12:28 +0200
  Re: Force gnu assembler to invoke the preprocessor "A.D. Fundum" <what.ever@neverm.ind> - 2011-06-19 15:42 +0200
    Re: Force gnu assembler to invoke the preprocessor "A.D. Fundum" <what.ever@neverm.ind> - 2011-07-03 16:46 +0200
      DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor) Andreas Schnellbacher <aschn@despammed.com> - 2011-07-04 00:44 +0200
        Re: DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor) "A.D. Fundum" <what.ever@neverm.ind> - 2011-07-04 11:09 +0200
          Re: DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor) "A.D. Fundum" <what.ever@neverm.ind> - 2011-07-21 22:54 +0200
            Re: DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor) "A.D. Fundum" <what.ever@neverm.ind> - 2011-07-24 12:23 +0200
            Re: DosQueryPathInfo with correct case (was: Force gnu assembler to invoke the preprocessor) "A.D. Fundum" <what.ever@neverm.ind> - 2011-07-24 12:32 +0200
  Re: Force gnu assembler to invoke the preprocessor Dave Yeo <dave.r.yeo@gmail.com> - 2011-06-19 11:24 -0700

csiph-web