/*
 * With this patch, elvis doesn't sort the output of global(1).
 *
 * This file is placed into the public domain by the author,
 * Shigio Yamaguchi <shigio@gnu.org>
 */

diff -c elvis-2.2_0-org/main.c elvis-2.2_0/main.c
*** elvis-2.2_0-org/main.c	Tue Oct 21 11:32:25 2003
--- elvis-2.2_0/main.c	Fri Dec  9 22:02:58 2011
***************
*** 808,813 ****
--- 808,820 ----
  	/* Execute the initialization buffer (which may create some windows) */
  	doexrc();
  
+ 	/* Not to sort tag-list generated by global(1) */
+ 	if (o_tagprg) {
+ 		if (!strncmp(o_tagprg, "elvis-global ", strlen("elvis-global ")) ||
+ 		    !strncmp(o_tagprg, "global ", strlen("global ")))
+ 			usegtags = 1;
+ 	}
+ 
  	/* Load the verbose messages, plus a few others */
  	if (((lc = getenv("LC_ALL")) != NULL && *lc)
  	 || ((lc = getenv("LC_MESSAGES")) != NULL && *lc)
diff -c elvis-2.2_0-org/tag.c elvis-2.2_0/tag.c
*** elvis-2.2_0-org/tag.c	Tue Oct 21 11:32:25 2003
--- elvis-2.2_0/tag.c	Fri Dec  9 20:56:59 2011
***************
*** 22,27 ****
--- 22,31 ----
   */
  TAG *taglist;
  
+ /* For GNU GLOBAL */
+ TAG *taglast;
+ int usegtags;
+ 
  /* Tag comparison function, returns non-zero if t1 should be inserted before t2.
   */
  static ELVBOOL tagbefore(t1, t2)
***************
*** 170,175 ****
--- 174,190 ----
  	TAG	*tag;
  {
  	TAG	*scan;
+ 
+ 	/* Don't sort global's output */
+ 	if (usegtags) {
+ 		if (!taglist) {
+ 			taglist = taglast = tag;
+ 		} else {
+ 			taglast->next = tag;	
+ 			taglast = tag;
+ 		}
+ 		return;
+ 	}
  
  	/* if empty list, this is easy */
  	if (!taglist)
diff -c elvis-2.2_0-org/tag.h elvis-2.2_0/tag.h
*** elvis-2.2_0-org/tag.h	Tue Oct 21 11:32:25 2003
--- elvis-2.2_0/tag.h	Fri Dec  9 20:53:36 2011
***************
*** 28,33 ****
--- 28,34 ----
  
  extern char *tagattrname[MAXATTR];
  extern TAG *taglist;
+ extern int usegtags;
  extern ELVBOOL tagforward;
  
  BEGIN_EXTERNC
