2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
28 # include "splintMacros.nf"
33 fileLib_isCExtension (cstring ext)
35 return (cstring_equalLit (ext, ".c")
36 || cstring_equalLit (ext, ".C")
37 || cstring_equalLit (ext, ".h")
38 || cstring_equalLit (ext, ".lh")
39 || cstring_equalLit (ext, ".xh")
40 || cstring_equalLit (ext, ".H")
41 || cstring_equalLit (ext, ".y")
42 || cstring_equalLit (ext, ".l"));
46 fileLib_isLCLFile (cstring s)
48 return (fileLib_hasExtension (s, LCL_EXTENSION));
51 /*@only@*/ cstring fileLib_withoutExtension (/*@temp@*/ cstring s, cstring suffix)
57 if (cstring_isUndefined (s)) {
58 return cstring_undefined;
62 if (t == (char *) 0 || !mstring_equal (t, suffix))
64 return mstring_copy (s);
69 s2 = mstring_copy (s);
71 /*@=mods@*/ /* Modification is undone. */
73 /*@noaccess cstring@*/
77 /*@only@*/ cstring fileLib_removePath (cstring s)
82 if (cstring_isUndefined (s)) {
83 return cstring_undefined;
86 t = strrchr (s, CONNECTCHAR);
88 if (t == NULL) return (mstring_copy (s));
89 else return (mstring_copy (t + 1));
90 /*@noaccess cstring@*/
95 fileLib_removePathFree (/*@only@*/ cstring s)
101 if (cstring_isUndefined (s)) {
102 return cstring_undefined;
105 t = strrchr (s, CONNECTCHAR);
107 # ifdef ALTCONNECTCHAR
109 char *at = strrchr (s, ALTCONNECTCHAR);
110 if (t == NULL || (at > t)) {
122 char *res = mstring_copy (t + 1);
126 /*@noaccess cstring@*/
130 fileLib_removeAnyExtension (cstring s)
137 if (cstring_isUndefined (s)) {
138 return cstring_undefined;
141 t = strrchr (s, '.');
145 return mstring_copy (s);
150 ret = mstring_copy (s);
152 /*@=mods@*/ /* modification is undone */
155 /*@noaccess cstring@*/
159 fileLib_addExtension (/*@temp@*/ cstring s, cstring suffix)
162 llassert (cstring_isDefined (s));
164 if (strrchr (s, '.') == (char *) 0)
166 /* <<< was mstring_concatFree1 --- bug detected by splint >>> */
167 return (cstring_concat (s, suffix));
171 return cstring_copy (s);
175 bool fileLib_hasExtension (cstring s, cstring ext)
177 return cstring_equal (fileLib_getExtension (s), ext);
180 /*@observer@*/ cstring fileLib_getExtension (/*@returned@*/ cstring s)
182 llassert (cstring_isDefined (s));
185 return (strrchr(s, '.'));
186 /*@noaccess cstring@*/
189 cstring removePreDirs (cstring s)
193 llassert (cstring_isDefined (s));
195 while (*s == '.' && *(s + 1) == CONNECTCHAR)
200 # if defined(OS2) || defined(MSDOS)
201 /* remove remainders from double path delimiters... */
202 while (*s == CONNECTCHAR)
206 # endif /* !defined(OS2) && !defined(MSDOS) */
209 /*@noaccess cstring@*/
212 bool isHeaderFile (cstring fname)
214 cstring ext = fileLib_getExtension (fname);
216 return (cstring_equalLit (ext, ".h")
217 || cstring_equalLit (ext, ".H")
218 || cstring_equal (ext, LH_EXTENSION));
221 cstring fileLib_cleanName (cstring s)
223 if (cstring_equalPrefixLit (s, "./"))
225 return cstring_copySegment (s, 2, cstring_length (s) - 1);
230 return cstring_copy (s);