[PATCH] Allow for case-insensitive context search if option --ignore-case is given

Fabian Wiget <[email protected]>
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <CABBhTm_hcDotz4X8FzJkB7rog7XzHcjCWN0Z-pdo8zwVsHd6xw@mail.gmail.com>
Hi everybody

If the option --from-here is specified, the resulting search by context is
always case-sensitive even if the option --ignore-case is present.

Example:

// will find your main function
global --from-here=25:/path/to/file.c main

// won't find your main function
global --from-here=25:/path/to/file.c -i Main

The attached patch fixes this issue.

Thank you & best regards
fabian

_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global
global-from-here.patch (text/x-patch, 900 B)
--- a/global/global.c	2017-03-02 23:30:18.632268436 +0100
+++ b/global/global.c	2017-03-02 22:59:17.867998651 +0100
@@ -841,6 +841,23 @@
 		if (isregex(av))
 			die_with_code(2, "regular expression is not allowed with the --from-here option.");
 		db = decide_tag_by_context(av, context_file, atoi(context_lineno));
+		/*
+		 * If we are in case-insensitive mode and have not found
+		 * anything yet, we try to find a matching definition and
+		 * try again.
+		 */
+		if (iflag && db == GSYMS) {
+			GTOP *gtop = gtags_open(dbpath, root, GTAGS, GTAGS_READ, 0);
+			GTP *gtp;
+			char edit[IDENTLEN];
+
+			snprintf(edit, sizeof(edit), "^%s$", av);
+			gtp = gtags_first(gtop, edit, GTOP_KEY | GTOP_BASICREGEX | GTOP_IGNORECASE);
+			gtags_close(gtop);
+			if (gtp) {
+				db = decide_tag_by_context(gtp->tag, context_file, atoi(context_lineno));
+			}
+		}
 	} else {
 		if (dflag)
 			db = GTAGS;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.