diff options
Diffstat (limited to 'contrib/texinfo/util/install-info.c')
-rw-r--r-- | contrib/texinfo/util/install-info.c | 80 |
1 files changed, 71 insertions, 9 deletions
diff --git a/contrib/texinfo/util/install-info.c b/contrib/texinfo/util/install-info.c index d346fb7..7f538b6 100644 --- a/contrib/texinfo/util/install-info.c +++ b/contrib/texinfo/util/install-info.c @@ -1,5 +1,6 @@ +/* $FreeBSD$ */ /* install-info -- create Info directory entry(ies) for an Info file. - $Id: install-info.c,v 1.9 2003/05/19 13:10:59 karl Exp $ + $Id: install-info.c,v 1.7 2003/01/19 18:46:51 karl Exp $ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. @@ -22,6 +23,7 @@ #include <getopt.h> static char *progname = "install-info"; +static char *default_section = NULL; struct line_data *findlines (); void insert_entry_here (); @@ -117,6 +119,8 @@ struct menu_section struct option longopts[] = { { "delete", no_argument, NULL, 'r' }, + { "defentry", required_argument, NULL, 'E' }, + { "defsection", required_argument, NULL, 'S' }, { "dir-file", required_argument, NULL, 'd' }, { "entry", required_argument, NULL, 'e' }, { "help", no_argument, NULL, 'h' }, @@ -165,6 +169,33 @@ fatal (s1, s2, s3) xexit (1); } +/* Memory allocation and string operations. */ + +/* Like malloc but get fatal error if memory is exhausted. */ +void * +xmalloc (size) + unsigned int size; +{ + extern void *malloc (); + void *result = malloc (size); + if (result == NULL) + fatal (_("virtual memory exhausted"), 0, 0); + return result; +} + +/* Like realloc but get fatal error if memory is exhausted. */ +void * +xrealloc (obj, size) + void *obj; + unsigned int size; +{ + extern void *realloc (); + void *result = realloc (obj, size); + if (result == NULL) + fatal (_("virtual memory exhausted"), 0, 0); + return result; +} + /* Return a newly-allocated string whose contents concatenate those of S1, S2, S3. */ char * @@ -374,6 +405,10 @@ DIR-FILE.\n\ Options:\n\ --delete delete existing entries for INFO-FILE from DIR-FILE;\n\ don't insert any new entries.\n\ + --defentry=TEXT like --entry, but only use TEXT if an entry\n\ + is not present in INFO-FILE.\n\ + --defsection=TEXT like --section, but only use TEXT if a section\n\ + is not present in INFO-FILE.\n\ --dir-file=NAME specify file name of Info directory file.\n\ This is equivalent to using the DIR-FILE argument.\n\ --entry=TEXT insert TEXT as an Info directory entry.\n\ @@ -854,7 +889,8 @@ parse_input (lines, nlines, sections, entries) specified. Default to section "Miscellaneous". */ *sections = (struct spec_section *) xmalloc (sizeof (struct spec_section)); - (*sections)->name = "Miscellaneous"; + (*sections)->name = + default_section ? default_section : "Miscellaneous"; (*sections)->next = 0; (*sections)->missing = 1; head = *sections; @@ -1102,6 +1138,8 @@ main (argc, argv) struct spec_section *input_sections = NULL; struct spec_entry *entries_to_add = NULL; int n_entries_to_add = 0; + struct spec_entry *default_entries_to_add = NULL; + int n_default_entries_to_add = 0; /* Record the old text of the dir file, as plain characters, as lines, and as nodes. */ @@ -1165,6 +1203,7 @@ main (argc, argv) dirfile = concat (optarg, "", "/dir"); break; + case 'E': case 'e': { struct spec_entry *next @@ -1179,9 +1218,18 @@ main (argc, argv) next->text_len = olen; next->entry_sections = NULL; next->entry_sections_tail = NULL; - next->next = entries_to_add; - entries_to_add = next; - n_entries_to_add++; + if (opt == 'e') + { + next->next = entries_to_add; + entries_to_add = next; + n_entries_to_add++; + } + else + { + next->next = default_entries_to_add; + default_entries_to_add = next; + n_default_entries_to_add++; + } } break; @@ -1219,6 +1267,10 @@ main (argc, argv) } break; + case 'S': + default_section = optarg; + break; + case 'V': printf ("install-info (GNU %s) %s\n", PACKAGE, VERSION); puts (""); @@ -1262,6 +1314,11 @@ For more information about these matters, see the files named COPYING.\n"), &input_sections, &entries_to_add); if (i > n_entries_to_add) n_entries_to_add = i; + else if (n_entries_to_add == 0) + { + entries_to_add = default_entries_to_add; + n_entries_to_add = n_default_entries_to_add; + } if (!delete_flag) { @@ -1293,7 +1350,8 @@ For more information about these matters, see the files named COPYING.\n"), { input_sections = (struct spec_section *) xmalloc (sizeof (struct spec_section)); - input_sections->name = "Miscellaneous"; + input_sections->name = + default_section ? default_section : "Miscellaneous"; input_sections->next = NULL; input_sections->missing = 1; } @@ -1370,7 +1428,7 @@ For more information about these matters, see the files named COPYING.\n"), } if (!spec || spec == entry->entry_sections_tail) continue; - + /* Subtract one because dir_lines is zero-based, but the `end_line' and `start_line' members are one-based. */ @@ -1386,9 +1444,14 @@ For more information about these matters, see the files named COPYING.\n"), dir_lines[i].start, dir_lines[i].size) && !dir_lines[i].delete) - fatal (_("menu item `%s' already exists, for file `%s'"), + { + if (quiet_flag) + dir_lines[i].delete = 1; + else + fatal (_("menu item `%s' already exists, for file `%s'"), extract_menu_item_name (entry->text), extract_menu_file_name (dir_lines[i].start)); + } if (dir_lines[i].start[0] == '*' && menu_line_lessp (entry->text, entry->text_len, dir_lines[i].start, @@ -1415,7 +1478,6 @@ For more information about these matters, see the files named COPYING.\n"), entries_to_add, input_sections, compression_program); xexit (0); - return 0; /* Avoid bogus warnings. */ } /* Divide the text at DATA (of SIZE bytes) into lines. |