Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / dos / splitname.c
blobd3dd54e2a5e9f0147e2f6c2a35beb3f1446a1dfa
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Split a path into pieces
6 Lang: english
7 */
8 #ifndef TEST
9 # include "dos_intern.h"
10 #else
11 # include <proto/dos.h>
12 # undef SplitName
13 # undef AROS_LH5
14 # define AROS_LH5(t,fn,a1,a2,a3,a4,a5,bt,bn,o,lib) t fn (a1,a2,a3,a4,a5)
15 # undef AROS_LHA
16 # define AROS_LHA(t,n,r) t n
17 # undef AROS_LIBFUNC_INIT
18 # define AROS_LIBFUNC_INIT
19 # undef AROS_LIBFUNC_EXIT
20 # define AROS_LIBFUNC_EXIT
21 #endif
23 /*****************************************************************************
25 NAME */
26 #include <proto/dos.h>
28 AROS_LH5(LONG, SplitName,
30 /* SYNOPSIS */
31 AROS_LHA(CONST_STRPTR, name, D1),
32 AROS_LHA(ULONG , separator, D2),
33 AROS_LHA(STRPTR, buf, D3),
34 AROS_LHA(LONG , oldpos, D4),
35 AROS_LHA(LONG , size, D5),
37 /* LOCATION */
38 struct DosLibrary *, DOSBase, 69, Dos)
40 /* FUNCTION
41 Split a path into parts at the position of separator.
43 INPUTS
44 name - Split this path
45 separator - Split it at this separator
46 buf - Copy the current part into this buffer
47 oldpos - Begin at this place with the search for separator.
48 If you call this function for the first time, set it
49 to 0.
50 size - The size of the buffer. If the current part of the
51 path is bigger than size-1, only size-1 bytes will
52 be copied.
54 RESULT
55 The next position to continue for the next part or -1 if
56 there is no separator after name+oldpos.
58 NOTES
60 EXAMPLE
61 See below.
63 BUGS
65 SEE ALSO
67 INTERNALS
69 *****************************************************************************/
71 AROS_LIBFUNC_INIT
73 size --;
75 name += oldpos;
77 while (*name != separator && *name && size)
79 size --;
80 *buf++ = *name++;
81 oldpos ++;
84 *buf = 0;
86 if (*name == separator)
87 return oldpos + 1;
89 return -1;
90 AROS_LIBFUNC_EXIT
91 } /* SplitName */
93 #ifdef TEST
95 # include <stdio.h>
96 # include <dos/dos.h>
98 # include <proto/dos.h>
100 int main (int argc, char ** argv)
102 LONG pos;
103 UBYTE buffer[256];
105 if (argc < 3)
107 fprintf (stderr, "Usage: %s <path> <separator>\n", argv[0]);
108 return RETURN_ERROR;
111 pos=0;
115 pos = SplitName (argv[1], *(argv[2]), buffer, pos, sizeof(buffer));
117 printf ("pos = %3ld buffer = \"%s\"\n", pos, buffer);
119 while (pos != -1);
121 return RETURN_OK;
124 #endif /* TEST */