Last change
on this file since 99fed2e was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago |
Imported original source code.
|
-
Property mode
set to
100755
|
File size:
1.7 KB
|
Rev | Line | |
---|
[3ae31e9] | 1 | /*
|
---|
| 2 | ============================================================================
|
---|
| 3 | basenam.c -- Extract base name from a path
|
---|
| 4 | Version 4 -- 1988-07-13 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
| 6 | Extracts the base name of a file from a path.
|
---|
| 7 |
|
---|
| 8 | char *
|
---|
| 9 | basenam(s)
|
---|
| 10 | char *s;
|
---|
| 11 |
|
---|
| 12 | Can be used with MSDOS, PCDOS, GEMDOS, or Unix(tm) with suitable
|
---|
| 13 | defines for SWITCHAR and DRIVES, as follows:
|
---|
| 14 |
|
---|
| 15 | For Unix(tm):
|
---|
| 16 | SWITCHAR '/'
|
---|
| 17 | DRIVES FALSE
|
---|
| 18 |
|
---|
| 19 | For MSDOS or PCDOS:
|
---|
| 20 | SWITCHAR swchar() function to get DOS SWITCHAR
|
---|
| 21 | DRIVES (c == ':')
|
---|
| 22 |
|
---|
| 23 | For GEMDOS:
|
---|
| 24 | SWITCHAR '\\'
|
---|
| 25 | DRIVES (c == ':')
|
---|
| 26 |
|
---|
| 27 | Define TESTER to get a test program and edit the array of test cases
|
---|
| 28 | for the system you're compiling for.
|
---|
| 29 | ============================================================================
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 | #define FALSE 0
|
---|
| 33 |
|
---|
| 34 | #define SWITCHAR '\\' /* TOS definition */
|
---|
| 35 | #define DRIVES (c == ':') /* TOS / MSDOS / PCDOS definition */
|
---|
| 36 |
|
---|
| 37 | /* |
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | /*
|
---|
| 41 | ============================================================================
|
---|
| 42 | basenam(s) -- extract the base name from the path at s
|
---|
| 43 | ============================================================================
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | char *
|
---|
| 47 | basenam(s)
|
---|
| 48 | char *s;
|
---|
| 49 | {
|
---|
| 50 | register char *cp = s;
|
---|
| 51 | register char c;
|
---|
| 52 |
|
---|
| 53 | while ('\0' != *s) {
|
---|
| 54 |
|
---|
| 55 | c = *s++;
|
---|
| 56 |
|
---|
| 57 | if ((c == SWITCHAR) || DRIVES)
|
---|
| 58 | cp = s;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | return(cp);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /* |
---|
| 65 | */
|
---|
| 66 |
|
---|
| 67 | #ifdef TESTER
|
---|
| 68 |
|
---|
| 69 | #include "stdio.h"
|
---|
| 70 |
|
---|
| 71 | char *t[] = { /* test cases for GEMDOS */
|
---|
| 72 |
|
---|
| 73 | "simple.one",
|
---|
| 74 | "c:more.doc",
|
---|
| 75 | "c:\\more",
|
---|
| 76 | "\\yet\\more.doc",
|
---|
| 77 | "another.1\\yet.more\\complex\\",
|
---|
| 78 | "and\\still.one\\more",
|
---|
| 79 | NULL
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | main()
|
---|
| 83 | {
|
---|
| 84 | register int n = 0;
|
---|
| 85 | register char *p;
|
---|
| 86 |
|
---|
| 87 | while (NULL != (p = t[n++]) )
|
---|
| 88 | printf("%s returned %s\n", p, basenam(p));
|
---|
| 89 |
|
---|
| 90 | printf("Done.\n");
|
---|
| 91 | exit(0);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.