File: filenames.h

package info (click to toggle)
quakespasm 0.93.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,672 kB
  • sloc: ansic: 52,034; sh: 306; makefile: 263
file content (193 lines) | stat: -rw-r--r-- 6,876 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* Macros for taking apart, interpreting and processing file names.
 *
 * These are here because some non-Posix (a.k.a. DOSish) systems have
 * drive letter brain-damage at the beginning of an absolute file name,
 * use forward- and back-slash in path names interchangeably, and
 * some of them have case-insensitive file names.
 *
 * This was based on filenames.h from BFD, the Binary File Descriptor
 * library, Copyright (C) 2000-2016 Free Software Foundation, Inc.,
 * and changed by O. Sezer <sezero@users.sourceforge.net> for our needs.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
 */

#ifndef FILENAMES_H
#define FILENAMES_H

#include <string.h>

/* ---------------------- Windows, DOS, OS2: ---------------------- */
#if defined(__MSDOS__) || defined(__DOS__) || defined(__DJGPP__) || \
    defined(_MSDOS) || defined(__OS2__) || defined(__EMX__) || \
    defined(_WIN32) || defined(_Windows) || defined(__WINDOWS__) || \
    defined(__NT__) || defined(__CYGWIN__)

#define HAVE_DOS_BASED_FILE_SYSTEM 1
#define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1

#define HAS_DRIVE_SPEC(f)	((f)[0] && ((f)[1] == ':'))
#define STRIP_DRIVE_SPEC(f)	((f) + 2)
#define IS_DIR_SEPARATOR(c)	((c) == '/' || (c) == '\\')
/* both '/' and '\\' work as dir separator.  djgpp likes changing
 * '\\' into '/', so I define DIR_SEPARATOR_CHAR as '/' for djgpp,
 * '\\' otherwise.  */
#ifdef __DJGPP__
#define DIR_SEPARATOR_CHAR	'/'
#define DIR_SEPARATOR_STR	"/"
#else
#define DIR_SEPARATOR_CHAR	'\\'
#define DIR_SEPARATOR_STR	"\\"
#endif
/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is
   only semi-absolute.  This is because the users of IS_ABSOLUTE_PATH
   want to know whether to prepend the current working directory to
   a file name, which should not be done with a name like d:foo.  */
#define IS_ABSOLUTE_PATH(f)	(IS_DIR_SEPARATOR((f)[0]) || HAS_DRIVE_SPEC((f)))

#ifdef __cplusplus
static inline char *FIND_FIRST_DIRSEP(char *_the_path) {
/* FIXME: What about C:FOO ? */
    char *p1 = strchr(_the_path, '/');
    char *p2 = strchr(_the_path, '\\');
    if (p1 == NULL) return p2;
    if (p2 == NULL) return p1;
    return (p1 < p2)? p1 : p2;
}
static inline char *FIND_LAST_DIRSEP (char *_the_path) {
/* FIXME: What about C:FOO ? */
    char *p1 = strrchr(_the_path, '/');
    char *p2 = strrchr(_the_path, '\\');
    if (p1 == NULL) return p2;
    if (p2 == NULL) return p1;
    return (p1 > p2)? p1 : p2;
}
static inline const char *FIND_FIRST_DIRSEP(const char *_the_path) {
/* FIXME: What about C:FOO ? */
    const char *p1 = strchr(_the_path, '/');
    const char *p2 = strchr(_the_path, '\\');
    if (p1 == NULL) return p2;
    if (p2 == NULL) return p1;
    return (p1 < p2)? p1 : p2;
}
static inline const char *FIND_LAST_DIRSEP (const char *_the_path) {
/* FIXME: What about C:FOO ? */
    const char *p1 = strrchr(_the_path, '/');
    const char *p2 = strrchr(_the_path, '\\');
    if (p1 == NULL) return p2;
    if (p2 == NULL) return p1;
    return (p1 > p2)? p1 : p2;
}
#else
static inline char *FIND_FIRST_DIRSEP(const char *_the_path) {
/* FIXME: What about C:FOO ? */
    char *p1 = strchr(_the_path, '/');
    char *p2 = strchr(_the_path, '\\');
    if (p1 == NULL) return p2;
    if (p2 == NULL) return p1;
    return (p1 < p2)? p1 : p2;
}
static inline char *FIND_LAST_DIRSEP (const char *_the_path) {
/* FIXME: What about C:FOO ? */
    char *p1 = strrchr(_the_path, '/');
    char *p2 = strrchr(_the_path, '\\');
    if (p1 == NULL) return p2;
    if (p2 == NULL) return p1;
    return (p1 > p2)? p1 : p2;
}
#endif /* C++ */

/* ----------------- AmigaOS, MorphOS, AROS, etc: ----------------- */
#elif defined(__MORPHOS__) || defined(__AROS__) || defined(AMIGAOS)	|| \
      defined(__amigaos__) || defined(__amigaos4__) ||defined(__amigados__) || \
      defined(AMIGA) || defined(_AMIGA) || defined(__AMIGA__)

#define HAS_DRIVE_SPEC(f)	(0) /* */
#define STRIP_DRIVE_SPEC(f)	(f) /* */
#define IS_DIR_SEPARATOR(c)	((c) == '/' || (c) == ':')
#define DIR_SEPARATOR_CHAR	'/'
#define DIR_SEPARATOR_STR	"/"
#define IS_ABSOLUTE_PATH(f)	(IS_DIR_SEPARATOR((f)[0]) || (strchr((f), ':')))
#define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1

#ifdef __cplusplus
static inline char *FIND_FIRST_DIRSEP(char *_the_path) {
    char *p = strchr(_the_path, ':');
    if (p != NULL) return p;
    return strchr(_the_path, '/');
}
static inline char *FIND_LAST_DIRSEP (char *_the_path) {
    char *p = strrchr(_the_path, '/');
    if (p != NULL) return p;
    return strchr(_the_path, ':');
}
static inline const char *FIND_FIRST_DIRSEP(const char *_the_path) {
    const char *p = strchr(_the_path, ':');
    if (p != NULL) return p;
    return strchr(_the_path, '/');
}
static inline const char *FIND_LAST_DIRSEP (const char *_the_path) {
    const char *p = strrchr(_the_path, '/');
    if (p != NULL) return p;
    return strchr(_the_path, ':');
}
#else
static inline char *FIND_FIRST_DIRSEP(const char *_the_path) {
    char *p = strchr(_the_path, ':');
    if (p != NULL) return p;
    return strchr(_the_path, '/');
}
static inline char *FIND_LAST_DIRSEP (const char *_the_path) {
    char *p = strrchr(_the_path, '/');
    if (p != NULL) return p;
    return strchr(_the_path, ':');
}
#endif /* C++ */

/* ---------------------- assumed UNIX-ish : ---------------------- */
#else /* */

#define IS_DIR_SEPARATOR(c)	((c) == '/')
#define DIR_SEPARATOR_CHAR	'/'
#define DIR_SEPARATOR_STR	"/"
#define IS_ABSOLUTE_PATH(f)	(IS_DIR_SEPARATOR((f)[0]))
#define HAS_DRIVE_SPEC(f)	(0)
#define STRIP_DRIVE_SPEC(f)	(f)

#ifdef __cplusplus
static inline char *FIND_FIRST_DIRSEP(char *_the_path) {
    return strchr(_the_path, '/');
}
static inline char *FIND_LAST_DIRSEP (char *_the_path) {
    return strrchr(_the_path, '/');
}
static inline const char *FIND_FIRST_DIRSEP(const char *_the_path) {
    return strchr(_the_path, '/');
}
static inline const char *FIND_LAST_DIRSEP (const char *_the_path) {
    return strrchr(_the_path, '/');
}
#else
static inline char *FIND_FIRST_DIRSEP(const char *_the_path) {
    return strchr(_the_path, '/');
}
static inline char *FIND_LAST_DIRSEP (const char *_the_path) {
    return strrchr(_the_path, '/');
}
#endif /* C++ */

#endif

#endif /* FILENAMES_H */