Less permissive syntax for notreached comment.
[splint-patched.git] / src / fileLib.c
blob80fc3378d3e88b1a540862ac8dad2e31fc2e39bc
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
5 **
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.
10 **
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.
15 **
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
25 ** fileLib.c
28 # include "splintMacros.nf"
29 # include "basic.h"
30 # include "osd.h"
32 bool
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"));
45 bool
46 fileLib_isLCLFile (cstring s)
48 return cstring_equal (fileLib_getExtension (s), LCL_EXTENSION);
51 /*@only@*/ cstring fileLib_withoutExtension (/*@temp@*/ cstring s, cstring suffix)
53 /*@access cstring@*/
54 char *t;
55 char *s2;
57 if (cstring_isUndefined (s)) {
58 return cstring_undefined;
61 t = strrchr (s, '.');
62 if (t == (char *) 0 || !mstring_equal (t, suffix))
64 return mstring_copy (s);
67 /*@-mods@*/
68 *t = '\0';
69 s2 = mstring_copy (s);
70 *t = '.';
71 /*@=mods@*/ /* Modification is undone. */
72 return s2;
73 /*@noaccess cstring@*/
76 /*@only@*/ cstring fileLib_removePath (cstring s)
78 /*@access cstring@*/
79 if (cstring_isUndefined (s)) {
80 return cstring_undefined;
83 return mstring_copy (osd_pathBase (s));
84 /*@noaccess cstring@*/
87 /*@only@*/ cstring
88 fileLib_removePathFree (/*@only@*/ cstring s)
90 /*@access cstring@*/
91 char *t;
93 if (cstring_isUndefined (s)) {
94 return cstring_undefined;
97 t = osd_pathBase (s);
99 if (t == s)
101 return s;
103 else
105 char *res = mstring_copy (t);
106 mstring_free (s);
107 return res;
109 /*@noaccess cstring@*/
112 /*@only@*/ cstring
113 fileLib_removeAnyExtension (cstring s)
115 /*@access cstring@*/
116 char *ret;
117 char *t;
120 if (cstring_isUndefined (s)) {
121 return cstring_undefined;
124 t = strrchr (s, '.');
126 if (t == (char *) 0)
128 return mstring_copy (s);
131 /*@-mods@*/
132 *t = '\0';
133 ret = mstring_copy (s);
134 *t = '.';
135 /*@=mods@*/ /* modification is undone */
137 return ret;
138 /*@noaccess cstring@*/
141 /*@only@*/ cstring
142 fileLib_addExtension (/*@temp@*/ cstring s, cstring suffix)
144 /*@access cstring@*/
145 llassert (cstring_isDefined (s));
147 if (strrchr (s, '.') == (char *) 0)
149 /* <<< was mstring_concatFree1 --- bug detected by splint >>> */
150 return (cstring_concat (s, suffix));
152 else
154 return cstring_copy (s);
158 /*@observer@*/ cstring fileLib_getExtension (/*@returned@*/ cstring s)
160 llassert (cstring_isDefined (s));
162 /*@access cstring@*/
163 return (strrchr(s, '.'));
164 /*@noaccess cstring@*/
167 bool isHeaderFile (cstring fname)
169 cstring ext = fileLib_getExtension (fname);
171 return (cstring_equalLit (ext, ".h")
172 || cstring_equalLit (ext, ".H")
173 || cstring_equal (ext, LH_EXTENSION));
176 cstring fileLib_cleanName (cstring s)
178 if (cstring_equalPrefixLit (s, "./"))
180 cstring res = cstring_copySegment (s, 2, cstring_length (s) - 1);
181 cstring_free (s);
182 return res;
185 return s;