[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] install-info, remove empty sections
From: |
Ben Asselstine |
Subject: |
[PATCH] install-info, remove empty sections |
Date: |
Sat, 8 Dec 2007 19:17:50 -0500 |
Hello,
Here is a patch that allows install-info to remove empty sections in
the dir file. The idea here is that we've removed the final entry in
a section, and we want to also remove the section's title.
regards,
Ben
diff -uNrd texinfo.orig/util/install-info.c texinfo/util/install-info.c
--- texinfo.orig/util/install-info.c 2007-12-02 20:38:43.000000000 -0500
+++ texinfo/util/install-info.c 2007-12-08 19:01:23.000000000 -0500
@@ -131,6 +131,7 @@
{ "quiet", no_argument, NULL, 'q' },
{ "remove", no_argument, NULL, 'r' },
{ "remove-exactly", no_argument, NULL, 'x' },
+ { "remove-empty-sections", no_argument, NULL, 'm' },
{ "section", required_argument, NULL, 's' },
{ "section-regex", required_argument, NULL, 'R' },
{ "silent", no_argument, NULL, 'q' },
@@ -146,6 +147,10 @@
entries that must be removed. */
int remove_exactly = 0;
+/* Nonzero means that sections that don't have entries in them will be
+ deleted. */
+int remove_empty_sections = 0;
+
/* Nonzero means --test was specified, to inhibit updating the dir file. */
int chicken_flag = 0;
@@ -475,6 +480,8 @@
--remove same as --delete.\n\
--remove-exactly only remove if the info file name matches exactly;\n\
.info and/or .gz suffixes are not ignored.\n\
+ --remove-empty-sections When removing the final entry in a section, \
+ delete the section too.\n\
--section=SEC put this file's entries in section SEC of the directory.\n\
If you specify more than one section, all the entries\n\
are added in each of the sections.\n\
@@ -1204,7 +1211,7 @@
while (1)
{
- int opt = getopt_long (argc, argv, "i:d:e:s:hHr", longopts, 0);
+ int opt = getopt_long (argc, argv, "i:d:e:s:hHrm", longopts, 0);
if (opt == EOF)
break;
@@ -1337,6 +1344,10 @@
remove_exactly = 1;
break;
+ case 'm':
+ remove_empty_sections = 1;
+ break;
+
default:
suggest_asking_for_help ();
}
@@ -1438,6 +1449,37 @@
something_deleted
= parse_dir_file (dir_lines, dir_nlines, &dir_nodes, infile_sans_info);
+ /* Check for sections with zero entries and mark them for deletion */
+ if (delete_flag && remove_empty_sections)
+ {
+ struct node *node;
+ struct menu_section *section;
+ int section_empty;
+
+ for (node = dir_nodes; node ; node = node->next)
+ for (section = node->sections; section ; section = section->next)
+ {
+ section_empty = 1;
+ for (i = section->end_line; i > section->start_line; i--)
+ {
+ if (dir_lines[i - 1].delete == 0 &&
+ dir_lines[i - 1].size != 0)
+ {
+ section_empty = 0;
+ break;
+ }
+ }
+
+ if (section_empty)
+ {
+ /* This gets rid of any trailing empty lines at the end
+ of the section, and the title too. */
+ for (i = section->end_line; i >= section->start_line; i--)
+ dir_lines[i - 1].delete = 1;
+ }
+ }
+ }
+
/* Decide where to add the new entries (unless --delete was used).
Find the menu sections to add them in.
In each section, find the proper alphabetical place to add
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] install-info, remove empty sections,
Ben Asselstine <=