source: buchla-68k/libcio/filname.c@ c59409e

Last change on this file since c59409e was 8973acd, checked in by Thomas Lopatic <thomas@…>, 7 years ago

No more warnings in libcio.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 =============================================================================
3 filname.c -- file name and extension extractors
4 Version 3 -- 1987-07-09 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define TESTER 0 /* define non-zero for test routine */
9
10#include "ram.h"
11
12#define MAX_NAME 8 /* maximum length of a file name */
13#define MAX_EXT 3 /* maximum length of an extension */
14
15/*
16 =============================================================================
17 FilName(s, p) -- Return a pointer to a string containing the file name
18 found in the string at 's'. Copy the file name into string 'p'.
19 =============================================================================
20*/
21
22int8_t *FilName(int8_t *s, int8_t *p)
23{
24 register int8_t *tp;
25 register int16_t i;
26
27 tp = p;
28
29 for (i = 0; i < MAX_NAME; i++) { /* scan the name */
30
31 if (*s) { /* ... until we hit a '\0' */
32
33 if (*s EQ '.') /* ... or a '.' */
34 break;
35
36 *p++ = *s++; /* ... copying as we go */
37
38 } else { /* stop at '\0' */
39
40 *p = '\0'; /* terminate the string */
41 return(tp); /* return a pointer to it */
42 }
43 }
44
45 *p = '\0'; /* copied MAX_NAME bytes - that's all folks */
46 return(tp);
47}
48
49/*
50 =============================================================================
51 FilExt(s, p) -- Returns a pointer to a copy of the extension of
52 the file name in 's'. The file name is copied into string 'p' and
53 a pointer to 'p' is returned.
54 =============================================================================
55*/
56
57int8_t *FilExt(int8_t *s, int8_t *p)
58{
59 register int8_t c, *tp;
60 register int16_t i;
61
62 tp = p;
63
64 while ((c = *s)) { /* scan the string */
65
66 if (c EQ '.') { /* ... until we hit the dot */
67
68 ++s; /* point past the dot */
69
70 for (i = 0; i < MAX_EXT; i++) { /* scan the extension ... */
71
72 if (*s) { /* ... until we hit a '\0' */
73
74 *p++ = *s++; /* ... copying as we go */
75
76 } else { /* stop at '\0' */
77
78 *p = '\0'; /* terminate the string */
79 return(tp); /* return a pointer to it */
80 }
81 }
82
83 *p = '\0'; /* copied MAX_EXT bytes - that's all folks */
84 return(tp); /* return a pointer to the result */
85
86 } else {
87
88 ++s; /* advance the pointer */
89 }
90 }
91
92 *p = '\0'; /* terminate the string */
93 return(tp); /* return a pointer to the result */
94}
95
96#if TESTER
97
98char *fn[] = { /* test cases */
99
100 "FILE.NAM",
101 "FILE",
102 "FILE.",
103 ".NAM",
104 ".",
105 "",
106 "fartoolonganame.longextension",
107 "fartoolonganame",
108 "fartoolonganame.",
109 ".longextension"
110};
111
112#define NCASES ((sizeof fn) / (sizeof (char *)))
113
114char temp1[MAX_NAME+1], temp2[MAX_EXT+1];
115
116fnt(s) /* test both functions and print the result */
117char *s;
118{
119 printf("[%s] gave [%s] [%s]\r\n",
120 s, FilName(s, temp1), FilExt(s, temp2));
121}
122
123main()
124{
125 int i;
126
127 /* hand the functions each of the test cases */
128
129 for (i = 0; i < NCASES; i++)
130 fnt(fn[i]);
131
132 exit();
133}
134
135#endif
136
Note: See TracBrowser for help on using the repository browser.