| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | /* install-info -- create Info directory entry(ies) for an Info file. | | 1 | /* install-info -- create Info directory entry(ies) for an Info file. |
2 | $Id: install-info.c,v 1.2 2011/11/11 23:45:21 joerg Exp $ | | 2 | $Id: install-info.c,v 1.3 2013/09/08 16:31:13 joerg Exp $ |
3 | | | 3 | |
4 | Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software | | 4 | Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software |
5 | Foundation, Inc. | | 5 | Foundation, Inc. |
6 | | | 6 | |
7 | This program is free software; you can redistribute it and/or modify | | 7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | | 8 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or | | 9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | | 10 | (at your option) any later version. |
11 | | | 11 | |
12 | This program is distributed in the hope that it will be useful, | | 12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. | | 15 | GNU General Public License for more details. |
| @@ -128,49 +128,46 @@ struct option longopts[] = | | | @@ -128,49 +128,46 @@ struct option longopts[] = |
128 | { "quiet", no_argument, NULL, 'q' }, | | 128 | { "quiet", no_argument, NULL, 'q' }, |
129 | { "remove", no_argument, NULL, 'r' }, | | 129 | { "remove", no_argument, NULL, 'r' }, |
130 | { "section", required_argument, NULL, 's' }, | | 130 | { "section", required_argument, NULL, 's' }, |
131 | { "version", no_argument, NULL, 'V' }, | | 131 | { "version", no_argument, NULL, 'V' }, |
132 | { 0 } | | 132 | { 0 } |
133 | }; | | 133 | }; |
134 | | | 134 | |
135 | /* Error message functions. */ | | 135 | /* Error message functions. */ |
136 | | | 136 | |
137 | /* Print error message. S1 is printf control string, S2 and S3 args for it. */ | | 137 | /* Print error message. S1 is printf control string, S2 and S3 args for it. */ |
138 | | | 138 | |
139 | /* VARARGS1 */ | | 139 | /* VARARGS1 */ |
140 | void | | 140 | void |
141 | error (s1, s2, s3) | | 141 | error (const char *s1, const char *s2, const char *s3) |
142 | char *s1, *s2, *s3; | | | |
143 | { | | 142 | { |
144 | fprintf (stderr, "%s: ", progname); | | 143 | fprintf (stderr, "%s: ", progname); |
145 | fprintf (stderr, s1, s2, s3); | | 144 | fprintf (stderr, s1, s2, s3); |
146 | putc ('\n', stderr); | | 145 | putc ('\n', stderr); |
147 | } | | 146 | } |
148 | | | 147 | |
149 | /* VARARGS1 */ | | 148 | /* VARARGS1 */ |
150 | void | | 149 | void |
151 | warning (s1, s2, s3) | | 150 | warning (const char *s1, const char *s2, const char *s3) |
152 | char *s1, *s2, *s3; | | | |
153 | { | | 151 | { |
154 | fprintf (stderr, _("%s: warning: "), progname); | | 152 | fprintf (stderr, _("%s: warning: "), progname); |
155 | fprintf (stderr, s1, s2, s3); | | 153 | fprintf (stderr, s1, s2, s3); |
156 | putc ('\n', stderr); | | 154 | putc ('\n', stderr); |
157 | } | | 155 | } |
158 | | | 156 | |
159 | /* Print error message and exit. */ | | 157 | /* Print error message and exit. */ |
160 | | | 158 | |
161 | void | | 159 | void |
162 | fatal (s1, s2, s3) | | 160 | fatal (const char *s1, const char *s2, const char *s3) |
163 | char *s1, *s2, *s3; | | | |
164 | { | | 161 | { |
165 | error (s1, s2, s3); | | 162 | error (s1, s2, s3); |
166 | xexit (1); | | 163 | xexit (1); |
167 | } | | 164 | } |
168 | | | 165 | |
169 | /* Memory allocation and string operations. */ | | 166 | /* Memory allocation and string operations. */ |
170 | | | 167 | |
171 | /* Like malloc but get fatal error if memory is exhausted. */ | | 168 | /* Like malloc but get fatal error if memory is exhausted. */ |
172 | void * | | 169 | void * |
173 | xmalloc (size) | | 170 | xmalloc (size) |
174 | unsigned int size; | | 171 | unsigned int size; |
175 | { | | 172 | { |
176 | extern void *malloc (); | | 173 | extern void *malloc (); |
| @@ -186,61 +183,57 @@ xrealloc (obj, size) | | | @@ -186,61 +183,57 @@ xrealloc (obj, size) |
186 | void *obj; | | 183 | void *obj; |
187 | unsigned int size; | | 184 | unsigned int size; |
188 | { | | 185 | { |
189 | extern void *realloc (); | | 186 | extern void *realloc (); |
190 | void *result = realloc (obj, size); | | 187 | void *result = realloc (obj, size); |
191 | if (result == NULL) | | 188 | if (result == NULL) |
192 | fatal (_("virtual memory exhausted"), 0, 0); | | 189 | fatal (_("virtual memory exhausted"), 0, 0); |
193 | return result; | | 190 | return result; |
194 | } | | 191 | } |
195 | | | 192 | |
196 | /* Return a newly-allocated string | | 193 | /* Return a newly-allocated string |
197 | whose contents concatenate those of S1, S2, S3. */ | | 194 | whose contents concatenate those of S1, S2, S3. */ |
198 | char * | | 195 | char * |
199 | concat (s1, s2, s3) | | 196 | concat (const char *s1, const char *s2, const char *s3) |
200 | char *s1, *s2, *s3; | | | |
201 | { | | 197 | { |
202 | int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); | | 198 | int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); |
203 | char *result = (char *) xmalloc (len1 + len2 + len3 + 1); | | 199 | char *result = (char *) xmalloc (len1 + len2 + len3 + 1); |
204 | | | 200 | |
205 | strcpy (result, s1); | | 201 | strcpy (result, s1); |
206 | strcpy (result + len1, s2); | | 202 | strcpy (result + len1, s2); |
207 | strcpy (result + len1 + len2, s3); | | 203 | strcpy (result + len1 + len2, s3); |
208 | *(result + len1 + len2 + len3) = 0; | | 204 | *(result + len1 + len2 + len3) = 0; |
209 | | | 205 | |
210 | return result; | | 206 | return result; |
211 | } | | 207 | } |
212 | | | 208 | |
213 | /* Return a string containing SIZE characters | | 209 | /* Return a string containing SIZE characters |
214 | copied from starting at STRING. */ | | 210 | copied from starting at STRING. */ |
215 | | | 211 | |
216 | char * | | 212 | char * |
217 | copy_string (string, size) | | 213 | copy_string (const char *string, int size) |
218 | char *string; | | | |
219 | int size; | | | |
220 | { | | 214 | { |
221 | int i; | | 215 | int i; |
222 | char *copy = (char *) xmalloc (size + 1); | | 216 | char *copy = (char *) xmalloc (size + 1); |
223 | for (i = 0; i < size; i++) | | 217 | for (i = 0; i < size; i++) |
224 | copy[i] = string[i]; | | 218 | copy[i] = string[i]; |
225 | copy[size] = 0; | | 219 | copy[size] = 0; |
226 | return copy; | | 220 | return copy; |
227 | } | | 221 | } |
228 | | | 222 | |
229 | /* Print fatal error message based on errno, with file name NAME. */ | | 223 | /* Print fatal error message based on errno, with file name NAME. */ |
230 | | | 224 | |
231 | void | | 225 | void |
232 | pfatal_with_name (name) | | 226 | pfatal_with_name (const char *name) |
233 | char *name; | | | |
234 | { | | 227 | { |
235 | char *s = concat ("", strerror (errno), _(" for %s")); | | 228 | char *s = concat ("", strerror (errno), _(" for %s")); |
236 | fatal (s, name, 0); | | 229 | fatal (s, name, 0); |
237 | } | | 230 | } |
238 | | | 231 | |
239 | /* Given the full text of a menu entry, null terminated, | | 232 | /* Given the full text of a menu entry, null terminated, |
240 | return just the menu item name (copied). */ | | 233 | return just the menu item name (copied). */ |
241 | | | 234 | |
242 | char * | | 235 | char * |
243 | extract_menu_item_name (item_text) | | 236 | extract_menu_item_name (item_text) |
244 | char *item_text; | | 237 | char *item_text; |
245 | { | | 238 | { |
246 | char *p; | | 239 | char *p; |
| @@ -338,50 +331,47 @@ strip_info_suffix (fname) | | | @@ -338,50 +331,47 @@ strip_info_suffix (fname) |
338 | ret[len] = 0; | | 331 | ret[len] = 0; |
339 | } | | 332 | } |
340 | #endif /* __MSDOS__ */ | | 333 | #endif /* __MSDOS__ */ |
341 | | | 334 | |
342 | return ret; | | 335 | return ret; |
343 | } | | 336 | } |
344 | | | 337 | |
345 | | | 338 | |
346 | /* Return true if ITEM matches NAME and is followed by TERM_CHAR. ITEM | | 339 | /* Return true if ITEM matches NAME and is followed by TERM_CHAR. ITEM |
347 | can also be followed by `.gz', `.info.gz', or `.info' (and then | | 340 | can also be followed by `.gz', `.info.gz', or `.info' (and then |
348 | TERM_CHAR) and still match. */ | | 341 | TERM_CHAR) and still match. */ |
349 | | | 342 | |
350 | static int | | 343 | static int |
351 | menu_item_equal (item, term_char, name) | | 344 | menu_item_equal (const char *item, char term_char, const char *name) |
352 | char *item; | | | |
353 | char term_char; | | | |
354 | char *name; | | | |
355 | { | | 345 | { |
356 | unsigned name_len = strlen (name); | | 346 | unsigned name_len = strlen (name); |
357 | /* First, ITEM must actually match NAME (usually it won't). */ | | 347 | /* First, ITEM must actually match NAME (usually it won't). */ |
358 | int ret = strncasecmp (item, name, name_len) == 0; | | 348 | int ret = strncasecmp (item, name, name_len) == 0; |
359 | if (ret) | | 349 | if (ret) |
360 | { | | 350 | { |
361 | /* Then, `foobar' doesn't match `foo', so be sure we've got all of | | 351 | /* Then, `foobar' doesn't match `foo', so be sure we've got all of |
362 | ITEM. The various suffixes should never actually appear in the | | 352 | ITEM. The various suffixes should never actually appear in the |
363 | dir file, but sometimes people put them in. */ | | 353 | dir file, but sometimes people put them in. */ |
364 | static char *suffixes[] | | 354 | static const char *suffixes[] |
365 | = { "", ".info.gz", ".info", ".inf", ".gz", | | 355 | = { "", ".info.gz", ".info", ".inf", ".gz", |
366 | #ifdef __MSDOS__ | | 356 | #ifdef __MSDOS__ |
367 | ".inz", ".igz", | | 357 | ".inz", ".igz", |
368 | #endif | | 358 | #endif |
369 | NULL }; | | 359 | NULL }; |
370 | unsigned i; | | 360 | unsigned i; |
371 | ret = 0; | | 361 | ret = 0; |
372 | for (i = 0; !ret && suffixes[i]; i++) | | 362 | for (i = 0; !ret && suffixes[i]; i++) |
373 | { | | 363 | { |
374 | char *suffix = suffixes[i]; | | 364 | const char *suffix = suffixes[i]; |
375 | unsigned suffix_len = strlen (suffix); | | 365 | unsigned suffix_len = strlen (suffix); |
376 | ret = strncasecmp (item + name_len, suffix, suffix_len) == 0 | | 366 | ret = strncasecmp (item + name_len, suffix, suffix_len) == 0 |
377 | && item[name_len + suffix_len] == term_char; | | 367 | && item[name_len + suffix_len] == term_char; |
378 | } | | 368 | } |
379 | } | | 369 | } |
380 | | | 370 | |
381 | return ret; | | 371 | return ret; |
382 | } | | 372 | } |
383 | | | 373 | |
384 | | | 374 | |
385 | | | 375 | |
386 | void | | 376 | void |
387 | suggest_asking_for_help () | | 377 | suggest_asking_for_help () |