home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / dos / filepart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  4.2 KB  |  181 lines

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