2 Copyright © 2011, The AROS Development Team. All rights reserved.
9 /******************************************************************************
25 Extracts directory or file name from a path, or assembles a path
29 PATHPART [DIR <path name>] [FILE <path name>] [ADD {<device name | directory name | file name>}]
33 Standard DOS return codes.
36 ******************************************************************************/
38 #include <proto/exec.h>
39 #include <proto/dos.h>
42 #include <aros/debug.h>
44 #include <aros/shcommands.h>
46 #define MAX_PATH_LEN 2048 /* Same as in C:Delete */
48 AROS_SH3H(PathPart
,50.1, "extract directory or file name from a path, or assemble a path\n",
49 AROS_SHAH(STRPTR
,,DIR ,/K
,NULL
,"Path from which to extract the directory name"),
50 AROS_SHAH(STRPTR
,,FILE,/K
,NULL
,"Path from which to extract the file name"),
51 AROS_SHAH(STRPTR
*,,ADD
,/K
/M
,NULL
,"Device and/or directory(ies) and/or file names from\n"
52 "\twhich to build a path (order matters!)\n") )
57 STRPTR outstr
= NULL
, buf
= NULL
;
58 UBYTE buf2
[MAX_PATH_LEN
];
61 if ( (SHArg(ADD
) && SHArg(DIR))
62 || (SHArg(ADD
) && SHArg(FILE))
63 || (SHArg(DIR) && SHArg(FILE))
66 SetIoErr(ERROR_BAD_TEMPLATE
);
70 size
= strlen((char *)SHArg(DIR));
71 if ((buf
= AllocVec(size
, MEMF_ANY
)))
73 CopyMem (SHArg(DIR), buf
, size
);
74 buf
[PathPart(buf
) - buf
] = '\0';
81 outstr
= FilePart(SHArg(FILE));
89 if (!AddPart(buf2
,*SHArg(ADD
)++ ,MAX_PATH_LEN
))
91 /* rc == RETURN_FAIL until this point... */
96 if (rc
!= RETURN_ERROR
)
103 SetIoErr(ERROR_REQUIRED_ARG_MISSING
);
110 FPutC(Output(), '\n');
114 PrintFault(IoErr(), (CONST_STRPTR
)"PathPart");