On 3/24/23 15:19, John Wheeler wrote:
On 3/24/23 14:41, Gavin Smith wrote:
Thanks for the detailed instructions on how to replicate this
problem. I agree that the extra blank line being inserted is
not a good thing.
Could it be fixed by avoiding adding an extra blank line if
not needed, rather than by deleting an extra line?
With your proposed fix, it is possible for a non-blank line
to be removed. So if 'dir' contains
* Menu:
Animals
* Gnu: (gnu). Wildebeest native to Africa.
Livestock
* Cow: (cow). A farm animal.
then running
../ginstall-info --remove --info-dir=. --info-file=./cow; \
../ginstall-info --info-dir=. --info-file=./cow \
cat dir
deletes the "* Gnu (gnu). ..." line.
I think that install-info should handle this case as well, which
would be possible if, for example, somebody hand-edited dir.
Unconditionally removing the line before the section doesn't seem
right.
Very good point, I had rashly assumed the sections would
never occur without an intervening blank line. Also, I will
consider your suggestion to avoid adding the extra blank
line. Will submit a revised patch when I get that done.
Can you think of a legitimate reason for there to be
multiple blank lines (a sequence of more that two
consecutive newline characters) in a valid dir file?
Thank you,
John
Attached is a revised patch that addresses your concern. With
this patch deleting a section will remove all preceding blank
lines. This change required changing file ii-0047-expected-dir-file
to remove the extra blank line at the end of the file.
I added test cases to check for correct behavior in the case you
pointed out and when deleting the last section: of the dir file and
of a non-terminal node in the dir file.
The one feature of this change that may raise an issue is in
case someone has used blank entry comment lines to create
a large vertical space between one dir section and the next. This
change will remove the extra blank lines if the following section
is removed. Examples of this behavior can be seen in tests
ii-0060-test and ii-0061-test.
Your thoughts?
Thank you,
John
diff --git a/ChangeLog b/ChangeLog
index cbc3cb0e1b..65a886afaa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-03-26 John Wheeler <wheelerw...@runbox.com>
+
+ * install-info/install-info.c: When deleting a section, remove
+ preceding blank lines.
+
2023-03-26 Gavin Smith <gavinsmith0...@gmail.com>
* NEWS: add 7.0.3 news.
diff --git a/install-info/install-info.c b/install-info/install-info.c
index 0899f8c683..8b966f6b9b 100644
--- a/install-info/install-info.c
+++ b/install-info/install-info.c
@@ -2533,6 +2533,12 @@ There is NO WARRANTY, to the extent permitted by law.\n"),
of the section, and the title too. */
for (i = section->end_line; i >= section->start_line; i--)
dir_lines[i - 1].delete = 1;
+ /* delete preceding blank lines */
+ for (i = section->start_line - 1; ; i--)
+ {
+ if (dir_lines[i - 1].size != 0) break;
+ dir_lines[i - 1].delete = 1;
+ }
}
}
}
diff --git a/install-info/tests/Makefile.am b/install-info/tests/Makefile.am
index 4f954dd6dc..54cc6d1d42 100644
--- a/install-info/tests/Makefile.am
+++ b/install-info/tests/Makefile.am
@@ -21,7 +21,8 @@ ii-0036-test ii-0037-test ii-0038-test ii-0039-test ii-0040-test \
ii-0041-test ii-0042-test ii-0043-test ii-0044-test ii-0045-test \
ii-0046-test ii-0047-test ii-0048-test ii-0049-test ii-0050-test \
ii-0051-test ii-0052-test ii-0053-test ii-0054-test ii-0055-test \
-ii-0056-test ii-0057-test
+ii-0056-test ii-0057-test ii-0058-test ii-0059-test ii-0060-test \
+ii-0061-test
noinst_SCRIPTS=$(TESTS)
@@ -252,4 +253,20 @@ ii-0056-expected-dir-file \
ii-0057-input-dir-file \
ii-0057-input-info-file \
ii-0057-expected-dir-file \
+\
+ii-0058-input-dir-file \
+ii-0058-input-info-file \
+ii-0058-expected-dir-file \
+\
+ii-0059-input-dir-file \
+ii-0059-input-info-file \
+ii-0059-expected-dir-file \
+\
+ii-0060-input-dir-file \
+ii-0060-input-info-file \
+ii-0060-expected-dir-file \
+\
+ii-0061-input-dir-file \
+ii-0061-input-info-file \
+ii-0061-expected-dir-file \
README
diff --git a/install-info/tests/README b/install-info/tests/README
index 634c71c851..4d5a03a9b8 100644
--- a/install-info/tests/README
+++ b/install-info/tests/README
@@ -176,3 +176,11 @@ This file describes each of the numbered install-info tests.
0055: --defsection when its value is used
0056: --defsection when its value is not used
0057: --maxwidth
+0058: Removing an Info file. Dir file contains run-on sections without
+ intervening blank line. Delete the second section.
+0059: Removing an Info file. Dir file contains run-on sections without
+ intervening blank line. Delete the first section.
+0060: Remove last section in dir file removing the blank line(s) that
+ precede it.
+0061: Remove last section a non-terminal node of dir file removing the
+ blank line(s) that precede it.
diff --git a/install-info/tests/ii-0047-expected-dir-file b/install-info/tests/ii-0047-expected-dir-file
index 9615d7528f..d2f31fd554 100644
--- a/install-info/tests/ii-0047-expected-dir-file
+++ b/install-info/tests/ii-0047-expected-dir-file
@@ -13,4 +13,3 @@ A few useful Info commands:
`mTexinfo RET' visits the Texinfo manual, etc.
* Menu:
-
diff --git a/install-info/tests/ii-0058-expected-dir-file b/install-info/tests/ii-0058-expected-dir-file
new file mode 100644
index 0000000000..cea95be087
--- /dev/null
+++ b/install-info/tests/ii-0058-expected-dir-file
@@ -0,0 +1,18 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu). Wildebeest native to Africa.
diff --git a/install-info/tests/ii-0058-input-dir-file b/install-info/tests/ii-0058-input-dir-file
new file mode 100644
index 0000000000..e52b27c074
--- /dev/null
+++ b/install-info/tests/ii-0058-input-dir-file
@@ -0,0 +1,20 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu). Wildebeest native to Africa.
+Livestock
+* Cow: (ii-0058-input-info-file). A farm animal.
diff --git a/install-info/tests/ii-0058-input-info-file b/install-info/tests/ii-0058-input-info-file
new file mode 100644
index 0000000000..f3f54686a4
--- /dev/null
+++ b/install-info/tests/ii-0058-input-info-file
@@ -0,0 +1,11 @@
+INFO-DIR-SECTION Livestock
+START-INFO-DIR-ENTRY
+* Cow: (cow). A farm animal.
+END-INFO-DIR-ENTRY
+
+File: cow, Node: Top, Next: Top, Up: (dir)
+
+Cow
+***
+
+The cow ...
diff --git a/install-info/tests/ii-0058-test b/install-info/tests/ii-0058-test
new file mode 100755
index 0000000000..a737c07651
--- /dev/null
+++ b/install-info/tests/ii-0058-test
@@ -0,0 +1,27 @@
+#!/bin/sh -x
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+. ./defs || exit 1
+
+# test of --maxwidth.
+testnum=0058
+
+outputdirfile=`mktemp ii$testnum-XXXXXXXX`
+cp ${testdir}/ii-$testnum-input-dir-file $outputdirfile || exit 1
+
+${install_info} \
+ --remove \
+ ${testdir}/ii-$testnum-input-info-file $outputdirfile \
+|| exit $?
+
+${diff} ${testdir}/ii-$testnum-expected-dir-file $outputdirfile
+retval=$?
+
+rm -f $outputdirfile
+exit $retval
diff --git a/install-info/tests/ii-0059-expected-dir-file b/install-info/tests/ii-0059-expected-dir-file
new file mode 100644
index 0000000000..07d33aec46
--- /dev/null
+++ b/install-info/tests/ii-0059-expected-dir-file
@@ -0,0 +1,17 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+Livestock
+* Cow: (cow). A farm animal.
diff --git a/install-info/tests/ii-0059-input-dir-file b/install-info/tests/ii-0059-input-dir-file
new file mode 100644
index 0000000000..d16b9a703c
--- /dev/null
+++ b/install-info/tests/ii-0059-input-dir-file
@@ -0,0 +1,24 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+
+
+
+
+Animals
+* Gnu: (ii-0059-input-info-file). Wildebeest native to Africa.
+Livestock
+* Cow: (cow). A farm animal.
diff --git a/install-info/tests/ii-0059-input-info-file b/install-info/tests/ii-0059-input-info-file
new file mode 100644
index 0000000000..5084ce1ab5
--- /dev/null
+++ b/install-info/tests/ii-0059-input-info-file
@@ -0,0 +1,12 @@
+INFO-DIR-SECTION Animals
+START-INFO-DIR-ENTRY
+* Gnu: (gnu). Wildebeest native to Africa.
+END-INFO-DIR-ENTRY
+
+
+File: gnu, Node: Top, Next: Top, Up: (dir)
+
+Gnu
+***
+
+The wildebeest (plural, wildebeest or wildebeests), also called the gnu (pronounced /ˈnuː/ or /ˈnjuː/), is an antelope of the genus Connochaetes. It is a hooved (ungulate) mammal. (Taken from wikepedia.)
diff --git a/install-info/tests/ii-0059-test b/install-info/tests/ii-0059-test
new file mode 100755
index 0000000000..700f0c2b82
--- /dev/null
+++ b/install-info/tests/ii-0059-test
@@ -0,0 +1,27 @@
+#!/bin/sh -x
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+. ./defs || exit 1
+
+# test of --maxwidth.
+testnum=0059
+
+outputdirfile=`mktemp ii$testnum-XXXXXXXX`
+cp ${testdir}/ii-$testnum-input-dir-file $outputdirfile || exit 1
+
+${install_info} \
+ --remove \
+ ${testdir}/ii-$testnum-input-info-file $outputdirfile \
+|| exit $?
+
+${diff} ${testdir}/ii-$testnum-expected-dir-file $outputdirfile
+retval=$?
+
+rm -f $outputdirfile
+exit $retval
diff --git a/install-info/tests/ii-0060-expected-dir-file b/install-info/tests/ii-0060-expected-dir-file
new file mode 100644
index 0000000000..a137e168a4
--- /dev/null
+++ b/install-info/tests/ii-0060-expected-dir-file
@@ -0,0 +1,20 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu). Wildebeest native to Africa.
+
+ An interesting article on African wild life.
diff --git a/install-info/tests/ii-0060-input-dir-file b/install-info/tests/ii-0060-input-dir-file
new file mode 100644
index 0000000000..72f4ae58c4
--- /dev/null
+++ b/install-info/tests/ii-0060-input-dir-file
@@ -0,0 +1,27 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu). Wildebeest native to Africa.
+
+ An interesting article on African wild life.
+
+
+
+
+Livestock
+* Cow: (ii-0060-input-info-file). A farm animal.
+
diff --git a/install-info/tests/ii-0060-input-info-file b/install-info/tests/ii-0060-input-info-file
new file mode 100644
index 0000000000..f3f54686a4
--- /dev/null
+++ b/install-info/tests/ii-0060-input-info-file
@@ -0,0 +1,11 @@
+INFO-DIR-SECTION Livestock
+START-INFO-DIR-ENTRY
+* Cow: (cow). A farm animal.
+END-INFO-DIR-ENTRY
+
+File: cow, Node: Top, Next: Top, Up: (dir)
+
+Cow
+***
+
+The cow ...
diff --git a/install-info/tests/ii-0060-test b/install-info/tests/ii-0060-test
new file mode 100755
index 0000000000..10f2dd1aba
--- /dev/null
+++ b/install-info/tests/ii-0060-test
@@ -0,0 +1,27 @@
+#!/bin/sh -x
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+. ./defs || exit 1
+
+# test of --maxwidth.
+testnum=0060
+
+outputdirfile=`mktemp ii$testnum-XXXXXXXX`
+cp ${testdir}/ii-$testnum-input-dir-file $outputdirfile || exit 1
+
+${install_info} \
+ --remove \
+ ${testdir}/ii-$testnum-input-info-file $outputdirfile \
+|| exit $?
+
+${diff} ${testdir}/ii-$testnum-expected-dir-file $outputdirfile
+retval=$?
+
+rm -f $outputdirfile
+exit $retval
diff --git a/install-info/tests/ii-0061-expected-dir-file b/install-info/tests/ii-0061-expected-dir-file
new file mode 100644
index 0000000000..e45f838154
--- /dev/null
+++ b/install-info/tests/ii-0061-expected-dir-file
@@ -0,0 +1,36 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu). Wildebeest native to Africa.
+
+ An interesting article on African wild life.
+
+File: dir1, Node: Space, This is the top of the Space INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Space Animals
+* Xyx: (Xyx). Animal native to Mars.
+
diff --git a/install-info/tests/ii-0061-input-dir-file b/install-info/tests/ii-0061-input-dir-file
new file mode 100644
index 0000000000..f293010ffe
--- /dev/null
+++ b/install-info/tests/ii-0061-input-dir-file
@@ -0,0 +1,43 @@
+This is the directory file `dir' a.k.a. `DIR', which contains the
+ topmost node of the Info hierarchy.
+
+
+File: dir, Node: Top, This is the top of the INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Animals
+* Gnu: (gnu). Wildebeest native to Africa.
+
+ An interesting article on African wild life.
+
+
+
+
+Livestock
+* Cow: (ii-0061-input-info-file). A farm animal.
+
+
+File: dir1, Node: Space, This is the top of the Space INFO tree.
+
+This is the Info main menu (aka directory node).
+A few useful Info commands:
+
+ `q' quits;
+ `?' lists all Info commands;
+ `h' starts the Info tutorial;
+ `mTexinfo RET' visits the Texinfo manual, etc.
+
+* Menu:
+
+Space Animals
+* Xyx: (Xyx). Animal native to Mars.
+
diff --git a/install-info/tests/ii-0061-input-info-file b/install-info/tests/ii-0061-input-info-file
new file mode 100644
index 0000000000..f3f54686a4
--- /dev/null
+++ b/install-info/tests/ii-0061-input-info-file
@@ -0,0 +1,11 @@
+INFO-DIR-SECTION Livestock
+START-INFO-DIR-ENTRY
+* Cow: (cow). A farm animal.
+END-INFO-DIR-ENTRY
+
+File: cow, Node: Top, Next: Top, Up: (dir)
+
+Cow
+***
+
+The cow ...
diff --git a/install-info/tests/ii-0061-test b/install-info/tests/ii-0061-test
new file mode 100755
index 0000000000..1c4b3fd5fa
--- /dev/null
+++ b/install-info/tests/ii-0061-test
@@ -0,0 +1,27 @@
+#!/bin/sh -x
+# This file is free software; as a special exception the author gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+. ./defs || exit 1
+
+# test of --maxwidth.
+testnum=0061
+
+outputdirfile=`mktemp ii$testnum-XXXXXXXX`
+cp ${testdir}/ii-$testnum-input-dir-file $outputdirfile || exit 1
+
+${install_info} \
+ --delete \
+ ${testdir}/ii-$testnum-input-info-file $outputdirfile \
+|| exit $?
+
+${diff} ${testdir}/ii-$testnum-expected-dir-file $outputdirfile
+retval=$?
+
+rm -f $outputdirfile
+exit $retval