Mercurial > hg > forks > yadex
annotate src/aym.cc @ 33:a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 24 Sep 2011 15:59:33 +0300 |
parents | f5375d9255f0 |
children | 0602d9bf474a |
rev | line source |
---|---|
0 | 1 /* |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
2 * aym.cc |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
3 * Misc. functions |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
4 * AYM 1997-??-?? |
0 | 5 */ |
6 | |
7 | |
8 /* | |
9 This file is part of Yadex. | |
10 | |
11 Yadex incorporates code from DEU 5.21 that was put in the public domain in | |
12 1994 by Raphaël Quinet and Brendon Wyber. | |
13 | |
14 The rest of Yadex is Copyright © 1997-2003 André Majorel and others. | |
15 | |
16 This program is free software; you can redistribute it and/or modify it under | |
17 the terms of the GNU General Public License as published by the Free Software | |
18 Foundation; either version 2 of the License, or (at your option) any later | |
19 version. | |
20 | |
21 This program is distributed in the hope that it will be useful, but WITHOUT | |
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
23 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
24 | |
25 You should have received a copy of the GNU General Public License along with | |
26 this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
27 Place, Suite 330, Boston, MA 02111-1307, USA. | |
28 */ | |
29 | |
30 | |
31 #include "yadex.h" | |
32 #include "game.h" | |
33 | |
34 | |
35 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
36 * levelname2levelno |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
37 * Used to know if directory entry is ExMy or MAPxy |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
38 * For "ExMy" (case-insensitive), returns 10x + y |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
39 * For "ExMyz" (case-insensitive), returns 100*x + 10y + z |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
40 * For "MAPxy" (case-insensitive), returns 1000 + 10x + y |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
41 * E0My, ExM0, E0Myz, ExM0z are not considered valid names. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
42 * MAP00 is considered a valid name. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
43 * For other names, returns 0. |
0 | 44 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 int levelname2levelno(const char *name) |
0 | 46 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
47 const unsigned char *s = (const unsigned char *) name; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 if (toupper(s[0]) == 'E' |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
49 && isdigit(s[1]) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
50 && s[1] != '0' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
51 && toupper(s[2]) == 'M' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
52 && isdigit(s[3]) && s[3] != '0' && s[4] == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
53 return 10 * dectoi(s[1]) + dectoi(s[3]); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
54 if (yg_level_name == YGLN_E1M10 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
55 && toupper(s[0]) == 'E' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
56 && isdigit(s[1]) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
57 && s[1] != '0' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
58 && toupper(s[2]) == 'M' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
59 && isdigit(s[3]) && s[3] != '0' && isdigit(s[4]) && s[5] == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
60 return 100 * dectoi(s[1]) + 10 * dectoi(s[3]) + dectoi(s[4]); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
61 if (toupper(s[0]) == 'M' |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
62 && toupper(s[1]) == 'A' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
63 && toupper(s[2]) == 'P' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
64 && isdigit(s[3]) && isdigit(s[4]) && s[5] == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
65 return 1000 + 10 * dectoi(s[3]) + dectoi(s[4]); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 return 0; |
0 | 67 } |
68 | |
69 | |
70 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
71 * levelname2rank |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
72 * Used to sort level names. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
73 * Identical to levelname2levelno except that, for "ExMy", |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
74 * it returns 100x + y, so that |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
75 * - f("E1M10") = f("E1M9") + 1 |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
76 * - f("E2M1") > f("E1M99") |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
77 * - f("E2M1") > f("E1M99") + 1 |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
78 * - f("MAPxy") > f("ExMy") |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
79 * - f("MAPxy") > f("ExMyz") |
0 | 80 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
81 int levelname2rank(const char *name) |
0 | 82 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
83 const unsigned char *s = (const unsigned char *) name; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
84 if (toupper(s[0]) == 'E' |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
85 && isdigit(s[1]) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
86 && s[1] != '0' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
87 && toupper(s[2]) == 'M' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
88 && isdigit(s[3]) && s[3] != '0' && s[4] == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
89 return 100 * dectoi(s[1]) + dectoi(s[3]); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
90 if (yg_level_name == YGLN_E1M10 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
91 && toupper(s[0]) == 'E' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
92 && isdigit(s[1]) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
93 && s[1] != '0' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
94 && toupper(s[2]) == 'M' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
95 && isdigit(s[3]) && s[3] != '0' && isdigit(s[4]) && s[5] == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
96 return 100 * dectoi(s[1]) + 10 * dectoi(s[3]) + dectoi(s[4]); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
97 if (toupper(s[0]) == 'M' |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
98 && toupper(s[1]) == 'A' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
99 && toupper(s[2]) == 'P' |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
100 && isdigit(s[3]) && isdigit(s[4]) && s[5] == '\0') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
101 return 1000 + 10 * dectoi(s[3]) + dectoi(s[4]); |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
102 return 0; |
0 | 103 } |
104 | |
105 | |
106 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
107 * spec_path |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
108 * Extract the path of a spec |
0 | 109 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
110 const char *spec_path(const char *spec) |
0 | 111 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
112 static char path[Y_PATH + 1]; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
113 size_t n; |
0 | 114 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
115 *path = '\0'; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
116 strncat(path, spec, sizeof path - 1); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
117 for (n = strlen(path); n > 0 && !al_fisps(path[n - 1]); n--) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
118 ; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
119 path[n] = '\0'; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
120 return path; |
0 | 121 } |
122 | |
123 | |
124 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
125 * fncmp |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
126 * Compare two filenames |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
127 * For Unix, it's a simple strcmp. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
128 * For DOS, it's case insensitive and "/" and "\" are equivalent. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
129 * FIXME: should canonicalize both names and compare that. |
0 | 130 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
131 int fncmp(const char *name1, const char *name2) |
0 | 132 { |
133 #if defined Y_DOS | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
134 char c1, c2; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
135 for (;;) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
136 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
137 c1 = tolower((unsigned char) *name1++); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
138 c2 = tolower((unsigned char) *name2++); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
139 if (c1 == '\\') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
140 c1 = '/'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
141 if (c2 == '\\') |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
142 c2 = '/'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
143 if (c1 != c2) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
144 return c1 - c2; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
145 if (!c1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
146 return 0; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
147 } |
0 | 148 #elif defined Y_UNIX |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
149 return strcmp(name1, name2); |
0 | 150 #endif |
151 } | |
152 | |
153 | |
154 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
155 * is_absolute |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
156 * Tell whether a file name is absolute or relative. |
0 | 157 * |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
158 * Note: for DOS, a filename of the form "d:foo" is |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
159 * considered absolute, even though it's technically |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
160 * relative to the current working directory of "d:". |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
161 * My reasoning is that someone who wants to specify a |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
162 * name that's relative to one of the standard |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
163 * directories is not going to put a "d:" in front of it. |
0 | 164 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
165 int is_absolute(const char *filename) |
0 | 166 { |
167 #if defined Y_UNIX | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
168 return *filename == '/'; |
0 | 169 #elif defined Y_DOS |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
170 return *filename == '/' |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
171 || *filename == '\\' || isalpha(*filename) && filename[1] == ':'; |
0 | 172 #endif |
173 } | |
174 | |
175 | |
176 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
177 * y_stricmp |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
178 * A case-insensitive strcmp() |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
179 * (same thing as DOS stricmp() or GNU strcasecmp()) |
0 | 180 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
181 int y_stricmp(const char *s1, const char *s2) |
0 | 182 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
183 for (;;) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
184 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
185 if (tolower(*s1) != tolower(*s2)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
186 return (unsigned char) *s1 - (unsigned char) *s2; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
187 if (!*s1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
188 return *s2 ? -1 : 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
189 if (!*s2) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
190 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
191 s1++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
192 s2++; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
193 } |
0 | 194 } |
195 | |
196 | |
197 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
198 * y_strnicmp |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
199 * A case-insensitive strncmp() |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
200 * (same thing as DOS strnicmp() or GNU strncasecmp()) |
0 | 201 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
202 int y_strnicmp(const char *s1, const char *s2, size_t len) |
0 | 203 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
204 while (len-- > 0) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
205 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
206 if (tolower(*s1) != tolower(*s2)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
207 return (unsigned char) *s1 - (unsigned char) *s2; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
208 if (!*s1) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
209 return *s2 ? -1 : 0; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
210 if (!*s2) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
211 return 1; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
212 s1++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
213 s2++; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
214 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
215 return 0; |
0 | 216 } |
217 | |
218 | |
219 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
220 * y_snprintf |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
221 * If available, snprintf(). Else sprintf(). |
0 | 222 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
223 int y_snprintf(char *buf, size_t size, const char *fmt, ...) |
0 | 224 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
225 va_list args; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
226 va_start(args, fmt); |
0 | 227 #ifdef Y_SNPRINTF |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
228 return vsnprintf(buf, size, fmt, args); |
0 | 229 #else |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
230 return vsprintf(buf, fmt, args); |
0 | 231 #endif |
232 } | |
233 | |
234 | |
235 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
236 * y_vsnprintf |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
237 * If available, vsnprintf(). Else vsprintf(). |
0 | 238 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
239 int y_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
0 | 240 { |
241 #ifdef Y_SNPRINTF | |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
242 return vsnprintf(buf, size, fmt, args); |
0 | 243 #else |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
244 return vsprintf(buf, fmt, args); |
0 | 245 #endif |
246 } | |
247 | |
248 | |
249 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
250 * y_strupr |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
251 * Upper-case a string |
0 | 252 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
253 void y_strupr(char *string) |
0 | 254 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
255 while (*string) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
256 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
257 *string = toupper(*string); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
258 string++; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
259 } |
0 | 260 } |
261 | |
262 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
263 * is_one_of |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
264 * Return non-zero if <s> is equal (in the strcmp() sense) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
265 * to one of the other strings (retrieved from the argument |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
266 * list as const char *). The last string must be followed |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
267 * by (const char *) 0. |
0 | 268 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
269 int is_one_of(const char *needle, ...) |
0 | 270 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
271 va_list args; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
272 va_start(args, needle); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
273 for (;;) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
274 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
275 const char *haystack = va_arg(args, const char *); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
276 if (haystack == Y_NULL) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
277 break; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
278 if (!strcmp(needle, haystack)) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
279 return 1; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
280 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
281 return 0; |
0 | 282 } |
283 | |
284 | |
285 | |
286 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
287 * file_exists |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
288 * Check whether a file exists and is readable. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
289 * Returns true if it is, false if it isn't. |
0 | 290 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
291 bool file_exists(const char *filename) |
0 | 292 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
293 FILE *test; |
0 | 294 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
295 if ((test = fopen(filename, "rb")) == NULL) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
296 return 0; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
297 fclose(test); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
298 return 1; |
0 | 299 } |
300 | |
301 | |
302 /* | |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
303 * y_filename |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
304 * Copies into <buf> a string that is a close as possible |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
305 * to <filename> but is guaranteed to be no longer than |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
306 * <size> - 1 and contain only printable characters. Non |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
307 * printable characters are replaced by question marks. |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
308 * Excess characters are replaced by an ellipsis. |
0 | 309 */ |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
310 void y_filename(char *buf, size_t size, const char *filename) |
0 | 311 { |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
312 if (size == 0) |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
313 return; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
314 if (size == 1) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
315 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
316 *buf = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
317 return; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
318 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
319 size_t len = strlen(filename); |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
320 size_t maxlen = size - 1; |
0 | 321 |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
322 if (len > 3 && maxlen <= 3) // Pathological case, fill with dots |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
323 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
324 memset(buf, '.', maxlen); |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
325 buf[maxlen] = '\0'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
326 return; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
327 } |
0 | 328 |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
329 size_t len1 = len; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
330 size_t len2 = 0; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
331 if (len > maxlen) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
332 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
333 len1 = (maxlen - 3) / 2; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
334 len2 = maxlen - 3 - len1; |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
335 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
336 char *p = buf; |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
337 for (size_t n = 0; n < len1; n++) |
0 | 338 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
339 *p++ = y_isprint(*filename) ? *filename : '?'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
340 filename++; |
0 | 341 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
342 if (len2 > 0) |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
343 { |
33
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
344 *p++ = '.'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
345 *p++ = '.'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
346 *p++ = '.'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
347 filename += len - len1 - len2; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
348 for (size_t n = 0; n < len2; n++) |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
349 { |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
350 *p++ = y_isprint(*filename) ? *filename : '?'; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
351 filename++; |
a68786b9c74b
Oops, used indent with tabs enabled. Remove tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
352 } |
25
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
353 } |
8eaf72e2041b
Reindent the source using GNU indent and "indent -i4 -bli0 -npcs -nprs -npsl".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
354 *p++ = '\0'; |
0 | 355 } |