On 2023/02/08 20:17, Tatsuo Ishii wrote:
Attached is the v2 patch.

Thanks for the patch!

With the patch, I got the following error when executing make_etags..

$ ./src/tools/make_etags
etags: invalid option -- 'e'
        Try 'etags --help' for a complete list of options.
sort: No such file or directory

Oops. Thank you for pointing it out. BTW, just out of curiosity, do
you have etags on you Mac?

Yes.

$ etags --version
etags (GNU Emacs 28.2)
Copyright (C) 2022 Free Software Foundation, Inc.
This program is distributed under the terms in ETAGS.README


This is the comment for the commit d1e2a380cb. I found that make_etags
with
an invalid option reported the following usage message mentioning
make_ctags
(not make_etags). Isn't this confusing?

$ ./src/tools/make_etags -a
Usage: /.../make_ctags [-e][-n]

That's hard to fix without some code duplication. We decided that
make_etags is not a symlink to make_ctags, rather execs make_ctags. Of
course we could let make_etags perform the same option check, but I
doubt it's worth the trouble.

How about just applying the following into make_etags?

+if [ $# -gt 1 ] || ( [ $# -eq 1 ] && [ $1 != "-n" ] )
+then   echo "Usage: $0 [-n]"
+       exit 1
+fi


Anyway, attached is the v3 patch.

Thanks for updating the patch!

With the patch, make_etags caused the following error messages
on my MacOS.

$ ./src/tools/make_etags
No such file or directory
No such file or directory

To fix this error, probaby we should get rid of double-quotes
from "$FLAGS" "$IGNORE_IDENTIFIES" in the following command.

-       xargs ctags $MODE -a -f $TAGS_FILE "$FLAGS" "$IGNORE_IDENTIFIES"
+       xargs $PROG $MODE $TAGS_OPT $TAGS_FILE "$FLAGS" "$IGNORE_IDENTIFIES"



+       else    ctags --help 2>&1 | grep -- -e >/dev/null
+               # Note that "ctags --help" does not always work. Even certain 
ctags does not have the option.

This code seems to assume that there is non-Exuberant ctags
supporting -e option. But does such ctags really exist?


I fixed the above issues and refactored the code.
Attached is the updated version of the patch. Thought?

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/src/tools/make_ctags b/src/tools/make_ctags
index 102881667b..aa7d7b573f 100755
--- a/src/tools/make_ctags
+++ b/src/tools/make_ctags
@@ -9,15 +9,19 @@ then  echo $usage
        exit 1
 fi
 
-MODE=
+EMACS_MODE=
 NO_SYMLINK=
+IS_EXUBERANT=
+PROG="ctags"
+TAGS_OPT="-a -f"
 TAGS_FILE="tags"
+FLAGS=
+IGNORE_IDENTIFIES=
 
 while [ $# -gt 0 ]
 do
        if [ $1 = "-e" ]
-       then    MODE="-e"
-               TAGS_FILE="TAGS"
+       then    EMACS_MODE="Y"
        elif [ $1 = "-n" ]
        then    NO_SYMLINK="Y"
        else
@@ -27,15 +31,24 @@ do
        shift
 done
 
-command -v ctags >/dev/null || \
+if [ ! "$EMACS_MODE" ]
+then   (command -v ctags >/dev/null) || \
        { echo "'ctags' program not found" 1>&2; exit 1; }
+fi
 
-trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15
-rm -f ./$TAGS_FILE
-
-IS_EXUBERANT=""
 ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y"
 
+if [ "$EMACS_MODE" ]
+then   TAGS_FILE="TAGS"
+       if [ "$IS_EXUBERANT" ]
+       then PROG="ctags -e"
+       else    (command -v etags >/dev/null) || \
+               { echo "neither 'etags' nor exuberant 'ctags' program not 
found" 1>&2; exit 1; }
+               PROG="etags"
+               TAGS_OPT="-a -o"
+       fi
+fi
+
 # List of kinds supported by Exuberant Ctags 5.8
 # generated by ctags --list-kinds
 # --c-kinds was called --c-types before 2003
@@ -56,20 +69,23 @@ ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y"
 
 if [ "$IS_EXUBERANT" ]
 then   FLAGS="--c-kinds=+dfmstuv"
-else   FLAGS="-dt"
+elif [ ! "$EMACS_MODE" ]
+then   FLAGS="-dt"
 fi
 
 # Use -I option to ignore a macro
 if [ "$IS_EXUBERANT" ]
 then   IGNORE_IDENTIFIES="-I pg_node_attr+"
-else   IGNORE_IDENTIFIES=
 fi
 
+trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15
+rm -f ./$TAGS_FILE
+
 # this is outputting the tags into the file 'tags', and appending
 find `pwd`/ \( -name tmp_install -prune -o -name tmp_check -prune \) \
        -o \( -name "*.[chly]" -o -iname "*makefile*" -o -name "*.mk" -o -name 
"*.in" \
        -o -name "*.sql" -o -name "*.p[lm]" \) -type f -print |
-       xargs ctags $MODE -a -f $TAGS_FILE "$FLAGS" "$IGNORE_IDENTIFIES"
+       xargs $PROG $TAGS_OPT $TAGS_FILE $FLAGS $IGNORE_IDENTIFIES
 
 # Exuberant tags has a header that we cannot sort in with the other entries
 # so we skip the sort step
diff --git a/src/tools/make_etags b/src/tools/make_etags
index afc57e3e89..7e51bb4c4e 100755
--- a/src/tools/make_etags
+++ b/src/tools/make_etags
@@ -1,5 +1,11 @@
 #!/bin/sh
-# src/tools/make_etags
+
+# src/tools/make_etags [-n]
+
+if [ $# -gt 1 ] || ( [ $# -eq 1 ] && [ $1 != "-n" ] )
+then   echo "Usage: $0 [-n]"
+       exit 1
+fi
 
 cdir=`dirname $0`
 dir=`(cd $cdir && pwd)`

Reply via email to