home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / dos / filepart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  3.8 KB  |  164 lines

  1. /*
  2.     (C) 1995 AROS - The Amiga Replacement OS
  3.     $Id: filepart.c,v 1.4 1996/10/24 15:50:27 aros Exp $
  4.     $Log: filepart.c,v $
  5.     Revision 1.4  1996/10/24 15:50:27  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.3  1996/10/21 17:43:31  aros
  9.     Better way to create a TEST
  10.  
  11.     Revision 1.2  1996/08/23 17:06:17  digulla
  12.     Added #include "dos_intern.h"
  13.  
  14.     Revision 1.1  1996/08/20 11:58:36  digulla
  15.     FilePart by Martin Steigerwald
  16.  
  17.     Revision 1.0    1996/08/01 14:14:00     steigerwald
  18.     Untested first version!!!
  19.     Revision 1.1    1996/08/07 00:24:00     steigerwald
  20.     Revision 1.2    1996/08/20 12:42:99     steigerwald
  21.     Finally tested! ;-) It works, but I am not quite happy about how
  22.     it gets the result ;-((
  23.     Only rudimentary tests.
  24.  
  25.     Desc: Returns a pointer to the first char of the filename in the given
  26.       file part.
  27.     Lang: english
  28. */
  29. #ifndef TEST
  30. #include "dos_intern.h"
  31. #else
  32. #define AROS_LH1(t,fn,a1,bt,bn,o,lib)     t fn (a1)
  33. #define AROS_LHA(t,n,r)                   t n
  34. #define AROS_LIBFUNC_INIT
  35. #define AROS_LIBBASE_EXT_DECL(bt,bn)
  36. #define AROS_LIBFUNC_EXIT
  37. #include <exec/types.h>
  38. #define CLIB_DOS_PROTOS_H
  39. #endif
  40.  
  41.  
  42. /*****************************************************************************
  43.  
  44.     NAME */
  45.     #include <clib/dos_protos.h>
  46.  
  47.     AROS_LH1(STRPTR, FilePart,
  48.  
  49. /*  SYNOPSIS */
  50.     AROS_LHA(STRPTR, path, D1),
  51.  
  52. /*  LOCATION */
  53.     struct DosLibrary *, DOSBase, 145, Dos)
  54.  
  55. /*  FUNCTION
  56.     Get a pointer to the last component of a path, which is normally the
  57.     filename.
  58.  
  59.     INPUTS
  60.     path - pointer AmigaDOS path string
  61.         May be relative to the current directory or the current disk.
  62.  
  63.     RESULT
  64.     A pointer to the first char of the filename!
  65.  
  66.     NOTES
  67.  
  68.     EXAMPLE
  69.     FilePart("xxx:yyy/zzz/qqq") returns a pointer to the first 'q'.
  70.     FilePart("xxx:yyy")         returns a pointer to the first 'y'.
  71.     FilePart("yyy")             returns a pointer to the first 'y'.
  72.  
  73.     BUGS
  74.     None known.
  75.  
  76.     SEE ALSO
  77.     PathPart(), AddPart()
  78.  
  79.     INTERNALS
  80.     Goes from the last char of the pathname back until it finds a ':',
  81.     a '/' or until the first char reached.
  82.  
  83.     HISTORY
  84.     29-10-95    digulla automatically created from
  85.                 dos_lib.fd and clib/dos_protos.h
  86.  
  87.     04-08-96    steigerwald hopefully filled up with something useful
  88.                 ;-), however untested!
  89.  
  90.     07-08-96    steigerwald reworked code, implented digulla's
  91.                 suggestions, thanks Aaron ;-)
  92.  
  93.                 added some documentation ;-)
  94.  
  95.                 converted all comments in function to
  96.                 c++ style to avoid nested comments
  97.  
  98.                 again untested, cause too much AROS stuff
  99.                 that is not easy to #ifdef out missing
  100.  
  101.     20-08-96    steigerwald finally added all those #ifndef NO_AROS
  102.                 to get this thing working stand-alone
  103.                 test routine added
  104.                 some bugs fixed
  105.  
  106.                 problem: see while and ifs below ;-(((
  107.  
  108.                 routine seems to work so far, but doesnt
  109.                 check for path consistency so
  110.                 FilePart("dh0:test/exec:now") will give a
  111.                 pointer to "now" ;-)
  112.  
  113. *****************************************************************************/
  114. {
  115.     AROS_LIBFUNC_INIT
  116.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  117.  
  118.     if(path)
  119.     {
  120.     STRPTR i;
  121.  
  122.     /* set i to last char of path */
  123.  
  124.     if (!*path) /* path == "" ? */
  125.       return path;
  126.  
  127.     i = path + strlen (path) -1;   /* set i to the \0-byte */
  128.  
  129.     /* decrease pointer as long as there is no ':', no '/' or till
  130.       the first char anyway. hope this works in all situations */
  131.     while ((*i != ':') && (*i != '/') && (i != path))
  132.         i--;
  133.  
  134.     if ((*i == ':')) i++;
  135.     if ((*i == '/')) i++;
  136.  
  137.     return(i);
  138.     } /* path */
  139.  
  140.     return (0L);  /* if no path is given return NIL pointer */
  141.  
  142.     AROS_LIBFUNC_EXIT
  143. } /* FilePart */
  144.  
  145. #ifdef TEST
  146.  
  147. #include <stdio.h>
  148.  
  149. int main (int argc, char ** argv)
  150. {
  151.     UWORD i;
  152.     STRPTR s,fileptr;
  153.  
  154.     while (--argc)
  155.     {
  156.     s = *++argv;
  157.     fileptr = FilePart(s);
  158.  
  159.     printf("Pfad:  %s\nDatei: %s\n", s, fileptr);
  160.     }
  161. }
  162.  
  163. #endif /* TEST */
  164.