Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>parsfnm() parse file name</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 parsfnm()               Parse File Name

 #include   <dos.h>

 char *parsfnm(cmdline,fcbptr,option);
 const char  *cmdline;                   String to be parsed
 struct fcb  *fcbptr;                    Pointer to FCB
 int          option;                    AL value

    parsfnm() parses a string for a file name.  The string is pointed to
    by 'cmdline', and the file name (drive, file name, and extension) is
    placed in an FCB pointed to by 'fcbptr'.   'option' determines how
    the file name is parsed; it is the same as the value of AL as used in
    in the DOS parse-filename system call 0x29.

       Returns:     If successful, a pointer to the byte following the
                    end of the file name.  On error, 0 is returned.

          Note:     Directory-names are not supported by this function.

   Portability:     MS-DOS only

   -------------------------------- Example ---------------------------------

    The following statements parse several different file names. The
    resulting filename is indicated in comments

           #include <stdio.h>
           #include <dos.h>
           #include <mem.h>

           #define SKIPSEP 0x1  /* skip leading separators */
           #define NODRIVE 0x2  /* only set drive if specified */
           #define NOFNAME 0x4  /* only set filename if specified */
           #define NOEXT   0x8  /* only set extension if specified */

           char *cmdline = "c:filename.ext thisfile.dat .txt a: lastname";

           print_fcb(struct fcb *fcbp, char *cmd)
               {
               char drv, name[9], ext[4];

               movmem(fcbp->fcb_name, name, 8);
               name[8] = 0;
               movmem(fcbp->fcb_ext, ext, 3);
               ext[3] = 0;
               drv = fcbp->fcb_drive;
               printf("%c%c%s%c%s   %s\n", drv ? 'A'-1+drv : ' ',
                       drv ? ':' : ' ',name, ext[0] == ' ' ? ' ' : '.',
                       ext, cmd);
               }

           main()
               {
               char *cmd;
               struct fcb fn;

               cmd = parsfnm(cmdline, &fn, 0);  /* c:filename.ext */
               print_fcb(&fn, cmd);
               cmd = parsfnm(cmd, &fn, SKIPSEP|NODRIVE); /* c:thisfile.dat */
               print_fcb(&fn, cmd);
               cmd = parsfnm(cmd, &fn, SKIPSEP|NOFNAME); /* thisfile.txt */
               print_fcb(&fn, cmd);
               /* a:thisfile.txt */
               cmd = parsfnm(cmd, &fn, SKIPSEP|NOFNAME|NOEXT);
               print_fcb(&fn, cmd);
               cmd = parsfnm(cmd, &fn, SKIPSEP|NODRIVE); /* a:lastname */
               print_fcb(&fn, cmd);
               }


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson