aboutsummaryrefslogtreecommitdiff
path: root/contrib/global/nvi-1.34.diff
blob: f289e9a8fa98480a3a1a44462f1835ce6cb05fe0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
diff -c -r -N /usr/src/usr.bin/vi/USD.doc/vi.man/vi.1 ./USD.doc/vi.man/vi.1
*** /usr/src/usr.bin/vi/USD.doc/vi.man/vi.1	Wed Aug 17 08:36:39 1994
--- ./USD.doc/vi.man/vi.1	Sat Dec 14 11:54:14 1996
***************
*** 39,59 ****
  .Nd text editors
  .Sh SYNOPSIS
  .Nm \&ex
! .Op Fl eFRrsv
  .Op Fl c Ar cmd
  .Op Fl t Ar tag
  .Op Fl w Ar size
  .\".Op Fl X Ar \&aw
  .Op Ar "file ..."
  .Nm \&vi
! .Op Fl eFRrv
  .Op Fl c Ar cmd
  .Op Fl t Ar tag
  .Op Fl w Ar size
  .\".Op Fl X Ar \&aw
  .Op Ar "file ..."
  .Nm view
! .Op Fl eFRrv
  .Op Fl c Ar cmd
  .Op Fl t Ar tag
  .Op Fl w Ar size
--- 39,59 ----
  .Nd text editors
  .Sh SYNOPSIS
  .Nm \&ex
! .Op Fl eFGRrsv
  .Op Fl c Ar cmd
  .Op Fl t Ar tag
  .Op Fl w Ar size
  .\".Op Fl X Ar \&aw
  .Op Ar "file ..."
  .Nm \&vi
! .Op Fl eFGRrv
  .Op Fl c Ar cmd
  .Op Fl t Ar tag
  .Op Fl w Ar size
  .\".Op Fl X Ar \&aw
  .Op Ar "file ..."
  .Nm view
! .Op Fl eFGRrv
  .Op Fl c Ar cmd
  .Op Fl t Ar tag
  .Op Fl w Ar size
***************
*** 124,129 ****
--- 124,131 ----
  Don't copy the entire file when first starting to edit.
  (The default is to make a copy in case someone else modifies
  the file during your edit session.)
+ .It Fl G
+ Start editing in gtags mode, as if the gtagsmode option was set.
  .It Fl R
  Start editing in read-only mode, as if the command name was
  .Nm view ,
***************
*** 377,382 ****
--- 379,385 ----
  Move the cursor down
  .Li count
  lines to the first nonblank character of that line.
+ In gtags select mode, <control-M> select current line as a tag.
  .It Sy "[count] <control-P>"
  .It Sy "[count] k"
  Move the cursor up
***************
*** 402,408 ****
  .Nm \&ex
  commands or cancel partial commands.
  .It Sy "<control-]>"
! Push a tag reference onto the tag stack.
  .It Sy "<control-^>"
  Switch to the most recently edited file.
  .It Sy "[count] <space>"
--- 405,412 ----
  .Nm \&ex
  commands or cancel partial commands.
  .It Sy "<control-]>"
! Push a tag reference onto the tag stack. In gtagsmode, if at the first column
! of line, locate function references otherwise function definitions.
  .It Sy "<control-^>"
  Switch to the most recently edited file.
  .It Sy "[count] <space>"
***************
*** 780,785 ****
--- 784,793 ----
  Grow or shrink the current screen.
  .It Sy "rew[ind][!]"
  Rewind the argument list.
+ .It Sy "rta[g][!] tagstring"
+ Edit the file refering the specified tag. (Only in gtagsmode)
+ .It Sy "se[lect]"
+ Select a tag from gtags list.
  .It Sy "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
  Display or set editor options.
  .It Sy "sh[ell]"
***************
*** 901,906 ****
--- 909,916 ----
  style) expressions.
  .It Sy "flash [on]"
  Flash the screen instead of beeping the keyboard on error.
+ .It Sy "gtagsmode, gt [off]"
+ Use GTAGS and GRTAGS instead of tags.
  .It Sy "hardtabs, ht [8]"
  Set the spacing between hardware tab settings.
  .It Sy "ignorecase, ic [off]"
diff -c -r -N /usr/src/usr.bin/vi/common/Makefile ./common/Makefile
*** /usr/src/usr.bin/vi/common/Makefile	Mon Sep 12 07:01:45 1994
--- ./common/Makefile	Sat Dec 14 11:55:27 1996
***************
*** 9,15 ****
  LINKS+= ${BINDIR}/${VI} ${BINDIR}/view
  MAN1=	${.CURDIR}/../USD.doc/vi.man/vi.1
  
! CFLAGS+=-I. -I${.CURDIR}
  DPADD+= ${LIBCURSES} ${LIBTERMCAP} ${LIBUTIL}
  LDADD+=	-lcurses -ltermcap -lutil
  
--- 9,15 ----
  LINKS+= ${BINDIR}/${VI} ${BINDIR}/view
  MAN1=	${.CURDIR}/../USD.doc/vi.man/vi.1
  
! CFLAGS+=-I. -I${.CURDIR} -DGTAGS
  DPADD+= ${LIBCURSES} ${LIBTERMCAP} ${LIBUTIL}
  LDADD+=	-lcurses -ltermcap -lutil
  
diff -c -r -N /usr/src/usr.bin/vi/common/exf.c ./common/exf.c
*** /usr/src/usr.bin/vi/common/exf.c	Tue May 30 15:35:44 1995
--- ./common/exf.c	Sat Dec 14 11:54:15 1996
***************
*** 156,162 ****
--- 156,169 ----
  	 * Required FRP initialization; the only flag we keep is the
  	 * cursor information.
  	 */
+ #ifdef GTAGS
+ 	/*
+ 	 * we must keep gtagstmp information too.
+ 	 */
+ 	F_CLR(frp, ~(FR_CURSORSET|FR_GTAGSTMP));
+ #else
  	F_CLR(frp, ~FR_CURSORSET);
+ #endif
  
  	/*
  	 * Required EXF initialization:
***************
*** 290,295 ****
--- 297,305 ----
  	 * an error.
  	 */
  	if (rcv_name == NULL)
+ #ifdef GTAGS
+ 	if (!F_ISSET(frp, FR_GTAGSTMP))
+ #endif
  		switch (file_lock(oname,
  		    &ep->fcntl_fd, ep->db->fd(ep->db), 0)) {
  		case LOCK_FAILED:
diff -c -r -N /usr/src/usr.bin/vi/common/gs.h ./common/gs.h
*** /usr/src/usr.bin/vi/common/gs.h	Wed Aug 17 08:36:42 1994
--- ./common/gs.h	Sat Dec 14 11:54:15 1996
***************
*** 48,53 ****
--- 48,56 ----
  
  	sigset_t blockset;		/* Signal mask. */
  
+ #ifdef GTAGS
+ 	char	*gtagstmp;		/* gtagstmp made by -t option */
+ #endif
  #ifdef DEBUG
  	FILE	*tracefp;		/* Trace file pointer. */
  #endif
diff -c -r -N /usr/src/usr.bin/vi/common/main.c ./common/main.c
*** /usr/src/usr.bin/vi/common/main.c	Tue May 30 15:35:45 1995
--- ./common/main.c	Sat Dec 14 11:54:15 1996
***************
*** 98,103 ****
--- 98,106 ----
  	SCR *sp;
  	u_int flags, saved_vi_mode;
  	int ch, eval, flagchk, readonly, silent, snapshot;
+ #ifdef GTAGS
+ 	int gtags = 0;
+ #endif
  	char *excmdarg, *myname, *p, *tag_f, *trace_f, *wsizearg;
  	char path[MAXPATHLEN];
  
***************
*** 134,140 ****
--- 137,147 ----
  	excmdarg = tag_f = trace_f = wsizearg = NULL;
  	silent = 0;
  	snapshot = 1;
+ #ifdef GTAGS
+ 	while ((ch = getopt(argc, argv, "c:eFGRrsT:t:vw:X:")) != EOF)
+ #else
  	while ((ch = getopt(argc, argv, "c:eFRrsT:t:vw:X:")) != EOF)
+ #endif
  		switch (ch) {
  		case 'c':		/* Run the command. */
  			excmdarg = optarg;
***************
*** 146,151 ****
--- 153,163 ----
  		case 'F':		/* No snapshot. */
  			snapshot = 0;
  			break;
+ #ifdef GTAGS
+ 		case 'G':		/* gtags mode. */
+ 			gtags = 1;
+ 			break;
+ #endif
  		case 'R':		/* Readonly. */
  			readonly = 1;
  			break;
***************
*** 245,250 ****
--- 257,266 ----
  		goto err;
  	if (readonly)			/* Global read-only bit. */
  		O_SET(sp, O_READONLY);
+ #ifdef GTAGS
+ 	if (gtags)			/* Global gtags bit. */
+ 		O_SET(sp, O_GTAGSMODE);
+ #endif
  	if (silent) {			/* Ex batch mode. */
  		O_CLR(sp, O_AUTOPRINT);
  		O_CLR(sp, O_PROMPT);
***************
*** 515,520 ****
--- 531,539 ----
  	LIST_INIT(&gp->cutq);
  	LIST_INIT(&gp->seqq);
  
+ #ifdef GTAGS
+ 	gp->gtagstmp = NULL;
+ #endif
  	/* Set a flag if we're reading from the tty. */
  	if (isatty(STDIN_FILENO))
  		F_SET(gp, G_STDIN_TTY);
***************
*** 554,559 ****
--- 573,584 ----
  	SCR *sp;
  	char *tty;
  
+ #ifdef GTAGS
+ 	if (gp->gtagstmp) {
+ 		if (!strncmp(gp->gtagstmp, _PATH_GTAGSTMP, strlen(_PATH_GTAGSTMP)))
+ 			(void)unlink(gp->gtagstmp);
+ 	}
+ #endif
  	/* Default buffer storage. */
  	(void)text_lfree(&gp->dcb_store.textq);
  
diff -c -r -N /usr/src/usr.bin/vi/common/msg.c ./common/msg.c
*** /usr/src/usr.bin/vi/common/msg.c	Thu Aug 18 10:10:54 1994
--- ./common/msg.c	Sat Dec 14 11:54:15 1996
***************
*** 338,343 ****
--- 338,352 ----
  #else
  	pid = "";
  #endif
+ #ifdef GTAGS
+ 	if (F_ISSET(sp->frp, FR_GTAGSTMP)) {
+ 		if (file_lline(sp, ep, &last)) {
+ 			return (1);
+ 		}
+ 		msgq(sp, M_INFO, "[GTAGS SELECT MODE] %d lines", last);
+ 		return (0);
+ 	}
+ #endif
  	/*
  	 * See nvi/exf.c:file_init() for a description of how and
  	 * when the read-only bit is set.
diff -c -r -N /usr/src/usr.bin/vi/common/options.c ./common/options.c
*** /usr/src/usr.bin/vi/common/options.c	Tue May 30 15:35:46 1995
--- ./common/options.c	Sat Dec 14 11:54:15 1996
***************
*** 103,108 ****
--- 103,112 ----
  	{"extended",	NULL,		OPT_0BOOL,	0},
  /* O_FLASH	    HPUX */
  	{"flash",	NULL,		OPT_1BOOL,	0},
+ #ifdef GTAGS
+ /* O_GTAGSMODE	    SPECIAL */
+ 	{"gtagsmode",	NULL,		OPT_0BOOL,	0},
+ #endif
  /* O_HARDTABS	    4BSD */
  	{"hardtabs",	NULL,		OPT_NUM,	0},
  /* O_IGNORECASE	    4BSD */
***************
*** 228,233 ****
--- 232,240 ----
  	{"eb",		O_ERRORBELLS},		/*     4BSD */
  	{"ed",		O_EDCOMPATIBLE},	/*     4BSD */
  	{"ex",		O_EXRC},		/* System V (undocumented) */
+ #ifdef GTAGS
+ 	{"gt",		O_GTAGSMODE},		/* Special  */
+ #endif
  	{"ht",		O_HARDTABS},		/*     4BSD */
  	{"ic",		O_IGNORECASE},		/*     4BSD */
  	{"li",		O_LINES},		/*   4.4BSD */
diff -c -r -N /usr/src/usr.bin/vi/common/pathnames.h ./common/pathnames.h
*** /usr/src/usr.bin/vi/common/pathnames.h	Wed Aug 17 08:36:43 1994
--- ./common/pathnames.h	Sat Dec 14 11:54:15 1996
***************
*** 43,45 ****
--- 43,48 ----
  #define	_PATH_TAGS	"tags"
  #define	_PATH_TMP	"/tmp"
  #define	_PATH_TTY	"/dev/tty"
+ #ifdef GTAGS
+ #define	_PATH_GTAGSTMP	"/var/tmp/gtags"
+ #endif
diff -c -r -N /usr/src/usr.bin/vi/common/screen.h ./common/screen.h
*** /usr/src/usr.bin/vi/common/screen.h	Wed Aug 17 08:36:43 1994
--- ./common/screen.h	Sat Dec 14 11:54:15 1996
***************
*** 87,92 ****
--- 87,95 ----
  #define	FR_TMPEXIT	0x100		/* Modified temporary file, no exit. */
  #define	FR_TMPFILE	0x200		/* If file has no name. */
  #define	FR_UNLOCKED	0x400		/* File couldn't be locked. */
+ #ifdef GTAGS
+ #define	FR_GTAGSTMP	0x800		/* File is gtags temporary file. */
+ #endif
  	u_int16_t flags;
  };
  
diff -c -r -N /usr/src/usr.bin/vi/ex/ex_tag.c ./ex/ex_tag.c
*** /usr/src/usr.bin/vi/ex/ex_tag.c	Thu Aug 18 10:13:20 1994
--- ./ex/ex_tag.c	Sat Dec 14 11:54:15 1996
***************
*** 64,69 ****
--- 64,72 ----
  #include "vi.h"
  #include "excmd.h"
  #include "tag.h"
+ #ifdef GTAGS
+ #include "pathnames.h"
+ #endif
  
  static char	*binary_search __P((char *, char *, char *));
  static int	 compare __P((char *, char *, char *));
***************
*** 71,76 ****
--- 74,288 ----
  static int	 search __P((SCR *, char *, char *, char **));
  static int	 tag_get __P((SCR *, char *, char **, char **, char **));
  
+ #ifdef DEBUG
+ void
+ trace(fp)
+ 	FILE *fp;
+ {
+ 	SCR *sp;
+ 	TAG *tp;
+ 	FREF *frp;
+ 	int scr, fref, tag;
+ 
+ 	fprintf(fp, "------------------------------------\n");
+ 	scr = 0;
+ 	for (sp = __global_list->dq.cqh_first; sp != (void *)&__global_list->dq; sp = sp->q.cqe_next) {
+ 		fprintf(fp, "screen %d {\n", ++scr);
+ 		fref = 0;
+ 		for (frp = sp->frefq.cqh_first;
+ 			frp != (FREF *)&sp->frefq; frp = frp->q.cqe_next) {
+ 			fprintf(fp, "    FREF %d ", ++fref);
+ 			if (F_ISSET(frp, FR_GTAGSTMP))
+ 				fprintf(fp, "<%s>\n", frp->name);
+ 			else
+ 				fprintf(fp, "%s\n", frp->name);
+ 		}
+ 		tag = 0;
+ 		if (!EXP(sp))
+ 			continue;
+ 		fprintf(fp, "    ................................\n");
+ 		for (tp = EXP(sp)->tagq.tqh_first; tp != NULL; tp = tp->q.tqe_next) {
+ 			fprintf(fp, "    TAG %d ", ++tag);
+ 			if (F_ISSET(tp->frp, FR_GTAGSTMP))
+ 				fprintf(fp, "<%s>\n", tp->frp->name);
+ 			else
+ 				fprintf(fp, "%s\n", tp->frp->name);
+ 		}
+ 		fprintf(fp, "}\n");
+ 	}
+ 	fprintf(fp, "------------------------------------\n");
+ }
+ #endif
+ #ifdef GTAGS
+ /*
+  * getentry --
+  *	get tag information from current line.
+  *
+  * gtags temporary file format.
+  * <tag>   <lineno>  <file>         <image>
+  *
+  * sample.
+  * +------------------------------------------------
+  * |main     30      main.c         main(argc, argv)
+  * |func     21      subr.c         func(arg)
+  */
+ static int
+ getentry(buf, tag, file, line)
+ 	char *buf, *tag, *file, *line;
+ {
+ 	char *p;
+ 
+ 	p = tag;
+ 	while (*buf && !isspace(*buf))		/* tag name */
+ 		*p++ = *buf++;
+ 	*p = 0;
+ 	while (*buf && isspace(*buf))		/* skip blanks */
+ 		buf++;
+ 	p = line;
+ 	while (*buf && !isspace(*buf))		/* line no */
+ 		*p++ = *buf++;
+ 	*p = 0;
+ 	while (*buf && isspace(*buf))		/* skip blanks */
+ 		buf++;
+ 	p = file;
+ 	while (*buf && !isspace(*buf))		/* file name */
+ 		*p++ = *buf++;
+ 	*p = 0;
+ 
+ 	/* value check */
+ 	if (strlen(tag) && strlen(line) && strlen(file) && atoi(line) > 0)
+ 		return 1;	/* OK */
+ 	return 0;		/* ERROR */
+ }
+ 
+ /*
+  * gtag_get --
+  *	Get a gtag from the GTAGS files.
+  */
+ static int
+ gtag_get(sp, ref, gtagselect, tag, tagp, filep, searchp)
+ 	SCR *sp;
+ 	int ref;
+ 	int *gtagselect;
+ 	char *tag, **tagp, **filep, **searchp;
+ {
+ 	static char name[80], file[200], line[10], gtagstmp[80];
+ 	char command[200];
+ 	char buf[BUFSIZ+1];
+ 	FILE *fp;
+ 
+ 	sprintf(gtagstmp, "%s.XXXXXXXX", _PATH_GTAGSTMP);
+ 	if (mktemp(gtagstmp) == 0) {
+ 		msgq(sp, M_ERR, "cannot generate temporary file name");
+ 		return (1);
+ 	}
+ 	sprintf(command, "global -%s '%s' > %s; chmod 600 %s",
+ 			ref ? "rx" : "x", tag, gtagstmp, gtagstmp);
+ 	if (system(command)) {
+ 		msgq(sp, M_ERR, "cannot exec global");
+ 		goto err;
+ 	}
+ 	if (!(fp = fopen(gtagstmp, "r"))) {
+ 		msgq(sp, M_ERR, "tag file cannot open.");
+ 		goto err;
+ 	}
+ 	if (!(fgets(buf, BUFSIZ, fp))) {
+ 		msgq(sp, M_ERR, "%s: tag not found", tag);
+ 		fclose(fp);
+ 		goto err;
+ 	}
+ 
+ 	if (getentry(buf, name, file, line) == 0) {
+ 		msgq(sp, M_ERR, "%s: illegal tag entry", tag);
+ 		fclose(fp);
+ 		goto err;
+ 	}
+ 
+ 	if (!(fgets(buf, BUFSIZ, fp))) {	/* just one line */
+ 		fclose(fp);
+ 		(void)unlink(gtagstmp);
+ 		*gtagselect  = 0;	/* go to user's file immediately */	
+ 		*tagp    = strdup(name);
+ 		*filep   = file;
+ 		*searchp = line;
+ 		if (*tagp == NULL) {
+ 			msgq(sp, M_SYSERR, NULL);
+ 			return (1);
+ 		}
+ 		return (0);
+ 	}
+ 	fclose(fp);
+ 	*gtagselect  = 1;		/* go to gtags select mode */
+ 	*tagp    = strdup(name);
+ 	*filep   = gtagstmp;
+ 	*searchp = "1";
+ 	if (*tagp == NULL) {
+ 		msgq(sp, M_SYSERR, NULL);
+ 		return (1);
+ 	}
+ 	return (0);
+ err:
+ 	(void)unlink(gtagstmp);
+ 	return (1);
+ }
+ 
+ /*
+  * ex_gtagselect --
+  *	The tag code can be entered from gtag select mode.
+  */
+ int
+ ex_gtagselect(sp, ep, cmdp)
+ 	SCR *sp;
+ 	EXF *ep;
+ 	EXCMDARG *cmdp;
+ {
+ 	if (!F_ISSET(sp->frp, FR_GTAGSTMP)) {
+ 		msgq(sp, M_ERR, "illegal tag entry");
+ 		return (1);
+ 	}
+ 	cmdp->cmd = &cmds[C_TAG];
+ 	cmdp->flags |= (E_GTAGSELECT|E_FORCE);
+ 	return ex_tagpush(sp, ep, cmdp);
+ }
+ 
+ /*
+  * should_delete --
+  *	1: should delete, 0: should not delete
+  */
+ int
+ should_delete(gtagstmp)
+ 	char *gtagstmp;
+ {
+ 	SCR *sp;
+ 	TAG *tp;
+ 	int tagcnt = 0;
+ 
+ 	/* make sure */
+ 	if (strncmp(gtagstmp, _PATH_GTAGSTMP, strlen(_PATH_GTAGSTMP)))
+ 		return 0;
+ 	/* this gtag is generated by -t option. don't delete here */
+ 	if (__global_list->gtagstmp && !strcmp(gtagstmp, __global_list->gtagstmp))
+ 		return 0;
+ 
+ 	for (sp = __global_list->dq.cqh_first; sp != (void *)&__global_list->dq; sp = sp->q.cqe_next) {
+ 		if (!EXP(sp))
+ 			continue;
+ 		for (tp = EXP(sp)->tagq.tqh_first; tp != NULL; tp = tp->q.tqe_next) {
+ 			if (!tp->frp || !F_ISSET(tp->frp, FR_GTAGSTMP))
+ 				continue;
+ 			if (!strcmp(tp->frp->name, gtagstmp))
+ 				++tagcnt;
+ 		}
+ 	}
+ 	if (tagcnt == 1)
+ 		return 1;
+ 	if (tagcnt > 1)
+ 		return 0;
+ 	/* IMPOSSIBLE */
+ 	return 0;
+ }
+ #endif
+ 
  /*
   * ex_tagfirst --
   *	The tag code can be entered from main, i.e. "vi -t tag".
***************
*** 86,96 ****
--- 298,317 ----
  	u_int flags;
  	int sval;
  	char *p, *tag, *name, *search;
+ #ifdef GTAGS
+ 	int gtagselect = 0;
+ #endif
  
  	/* Taglength may limit the number of characters. */
  	if ((tl = O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(tagarg) > tl)
  		tagarg[tl] = '\0';
  
+ #ifdef GTAGS
+ 	if (O_ISSET(sp, O_GTAGSMODE)) {
+ 		if (gtag_get(sp, 0, &gtagselect, tagarg, &tag, &name, &search))
+ 			return (1);
+ 	} else 
+ #endif
  	/* Get the tag information. */
  	if (tag_get(sp, tagarg, &tag, &name, &search))
  		return (1);
***************
*** 106,111 ****
--- 327,336 ----
  	 * The historic tags file format (from a long, long time ago...)
  	 * used a line number, not a search string.  I got complaints, so
  	 * people are still using the format.
+ #ifdef GTAGS
+ 	 * Yes, gtags use the old format. Search string is very flexible
+ 	 * but is not suitable to treat duplicate entries.
+ #endif
  	 */
  	if (isdigit(search[0])) {
  		m.lno = atoi(search);
***************
*** 132,137 ****
--- 357,371 ----
  	frp->lno = m.lno;
  	frp->cno = m.cno;
  	F_SET(frp, FR_CURSORSET);
+ #ifdef GTAGS
+ 	if (gtagselect) {
+ 		F_SET(frp, FR_GTAGSTMP);
+ 		if (!(sp->gp->gtagstmp = strdup(name))) {
+ 			msgq(sp, M_SYSERR, NULL);
+ 			return (1);
+ 		}
+ 	}
+ #endif
  
  	/* Might as well make this the default tag. */
  	if ((EXP(sp)->tlast = strdup(tagarg)) == NULL) {
***************
*** 142,153 ****
--- 376,399 ----
  }
  
  /* Free a tag or tagf structure from a queue. */
+ #ifdef GTAGS
  #define	FREETAG(tp) {							\
+ 	if (F_ISSET(tp->frp, FR_GTAGSTMP))				\
+ 		if (should_delete(tp->frp->name))			\
+ 			unlink(tp->frp->name);				\
  	TAILQ_REMOVE(&exp->tagq, (tp), q);				\
  	if ((tp)->search != NULL)					\
  		free((tp)->search);					\
  	FREE((tp), sizeof(TAGF));					\
  }
+ #else
+ #define	FREETAG(tp) {							\
+ 	TAILQ_REMOVE(&exp->tagq, (tp), q);				\
+ 	if ((tp)->search != NULL)					\
+ 		free((tp)->search);					\
+ 	FREE((tp), sizeof(TAGF));					\
+ }
+ #endif
  #define	FREETAGF(tfp) {							\
  	TAILQ_REMOVE(&exp->tagfq, (tfp), q);				\
  	free((tfp)->name);						\
***************
*** 182,189 ****
--- 428,464 ----
  	int sval;
  	long tl;
  	char *name, *p, *search, *tag;
+ #ifdef GTAGS
+ 	int gtagselect = 0;
+ 	char *line;
+ 	size_t len;
+ 	char tagbuf[80], namebuf[200], linebuf[10];
+ #endif
  
  	exp = EXP(sp);
+ #ifdef GTAGS
+ 	/*
+ 	 * Enter from gtag select mode.
+ 	 * get tag information from current line.
+ 	 */
+ 	if (F_ISSET(cmdp, E_GTAGSELECT)) {
+ 		if ((line = file_gline(sp, ep, sp->lno, &len)) == NULL) {
+ 			GETLINE_ERR(sp, sp->lno);
+ 			return (1);
+ 		}
+ 		if (getentry(line, tagbuf, namebuf, linebuf) == 0) {
+ 			msgq(sp, M_ERR, "illegal tag entry");
+ 			return (1);
+ 		}
+ 		if (!(tag = strdup(tagbuf))) {
+ 			msgq(sp, M_SYSERR, NULL);
+ 			return (1);
+ 		}
+ 		name = namebuf;
+ 		search = linebuf;
+ 		goto getfref;
+ 	}
+ #endif
  	switch (cmdp->argc) {
  	case 1:
  		if (exp->tlast != NULL)
***************
*** 207,216 ****
--- 482,504 ----
  	if ((tl = O_VAL(sp, O_TAGLENGTH)) != 0 && strlen(exp->tlast) > tl)
  		exp->tlast[tl] = '\0';
  
+ #ifdef GTAGS
+ 	if (O_ISSET(sp, O_GTAGSMODE)) {
+ 		if (gtag_get(sp, F_ISSET(cmdp->cmd, E_REFERENCE), &gtagselect,
+ 			exp->tlast, &tag, &name, &search))
+ 			return (1);
+ 	} else if (F_ISSET(cmdp->cmd, E_REFERENCE)) {
+ 		msgq(sp, M_ERR, "Please set gtagsmode");
+ 		return (1);
+ 	} else
+ #endif
  	/* Get the tag information. */
  	if (tag_get(sp, exp->tlast, &tag, &name, &search))
  		return (1);
  
+ #ifdef GTAGS
+ getfref:
+ #endif
  	/* Get the (possibly new) FREF structure. */
  	if ((frp = file_add(sp, name)) == NULL)
  		goto err;
***************
*** 305,310 ****
--- 593,603 ----
  		sp->cno = m.cno;
  		break;
  	}
+ #ifdef GTAGS
+ 	if (gtagselect) {
+ 		F_SET(frp, FR_GTAGSTMP);
+ 	}
+ #endif
  	return (0);
  }
  
***************
*** 490,495 ****
--- 783,793 ----
  	for (cnt = 1, tp = exp->tagq.tqh_first; tp != NULL;
  	    ++cnt, tp = tp->q.tqe_next) {
  		len = strlen(name = tp->frp->name);	/* The original name. */
+ #ifdef GTAGS
+ 		if (F_ISSET(tp->frp, FR_GTAGSTMP)) {
+ 			(void)ex_printf(EXCOOKIE, "%2d [GTAGS]\n", cnt);
+ 		} else
+ #endif
  		if (len > maxlen || len + tp->slen > sp->cols)
  			if (tp == NULL || tp->search == NULL)
  				(void)ex_printf(EXCOOKIE,
diff -c -r -N /usr/src/usr.bin/vi/ex/excmd.c ./ex/excmd.c
*** /usr/src/usr.bin/vi/ex/excmd.c	Thu Aug 18 10:13:29 1994
--- ./ex/excmd.c	Sat Dec 14 11:54:15 1996
***************
*** 319,324 ****
--- 319,331 ----
  	    "!",
  	    "rew[ind][!]",
  	    "re-edit all the files in the file argument list"},
+ #ifdef GTAGS
+ /* C_RTAG */
+ 	{"rtag",	ex_tagpush,	E_NOGLOBAL|E_REFERENCE,
+ 	    "!w1o",
+ 	    "rta[g][!] [string]",
+ 	    "edit the file containing the tag"},
+ #endif
  /* C_SUBSTITUTE */
  	{"substitute",	ex_substitute,	E_ADDR2|E_NORC,
  	    "s",
***************
*** 329,334 ****
--- 336,348 ----
  	    "!f1o",
  	    "sc[ript][!] [file]",
  	    "run a shell in a screen"},
+ #ifdef GTAGS
+ /* C_GTAGSELECT */
+ 	{"select",	ex_gtagselect,	E_NOGLOBAL,
+ 	    "",
+ 	    "sel[ect]",
+ 	    "edit the file containing the tag"},
+ #endif
  /* C_SET */
  	{"set",		ex_set,		E_NOGLOBAL,
  	    "wN",
diff -c -r -N /usr/src/usr.bin/vi/ex/excmd.h.stub ./ex/excmd.h.stub
*** /usr/src/usr.bin/vi/ex/excmd.h.stub	Wed Aug 17 08:36:28 1994
--- ./ex/excmd.h.stub	Sat Dec 14 11:54:15 1996
***************
*** 69,74 ****
--- 69,79 ----
  #define	E_NORC		0x0800000	/* Not from a .exrc or EXINIT. */
  #define	E_ZERO		0x1000000	/* 0 is a legal addr1. */
  #define	E_ZERODEF	0x2000000	/* 0 is default addr1 of empty files. */
+ 
+ #ifdef GTAGS
+ #define E_REFERENCE	0x4000000	/* locate function references */
+ #define E_GTAGSELECT	0x8000000	/* current line is gtags entry */
+ #endif
  	u_int32_t flags;
  	char	 *syntax;		/* Syntax script. */
  	char	*usage;			/* Usage line. */
***************
*** 234,239 ****
--- 239,245 ----
  EXPROTO(ex_fg);
  EXPROTO(ex_file);
  EXPROTO(ex_global);
+ EXPROTO(ex_gtagselect);
  EXPROTO(ex_help);
  EXPROTO(ex_insert);
  EXPROTO(ex_join);
diff -c -r -N /usr/src/usr.bin/vi/svi/svi_refresh.c ./svi/svi_refresh.c
*** /usr/src/usr.bin/vi/svi/svi_refresh.c	Tue May 30 15:35:56 1995
--- ./svi/svi_refresh.c	Sat Dec 14 11:54:16 1996
***************
*** 725,731 ****
--- 725,736 ----
  	EXF *ep;
  {
  	size_t cols, curlen, endpoint, len, midpoint;
+ #ifdef GTAGS
+ 	char *p, buf[30];
+ 	recno_t last;
+ #else
  	char *p, buf[20];
+ #endif
  
  	/* Clear the mode line. */
  	MOVE(sp, INFOLINE(sp), 0);
***************
*** 746,751 ****
--- 751,765 ----
  
  	curlen = 0;
  	if (sp->q.cqe_next != (void *)&sp->gp->dq) {
+ #ifdef GTAGS
+ 		if (F_ISSET(sp->frp, FR_GTAGSTMP)) {
+ 			if (file_lline(sp, ep, &last)) {
+ 				return (1);
+ 			}
+ 			sprintf(buf, "[GTAGS SELECT MODE] %d lines", last);
+ 			p = buf;
+ 		} else {
+ #endif
  		for (p = sp->frp->name; *p != '\0'; ++p);
  		while (--p > sp->frp->name) {
  			if (*p == '/') {
***************
*** 758,764 ****
  				break;
  			}
  		}
! 
  		MOVE(sp, INFOLINE(sp), 0);
  		standout();
  		for (; *p != '\0'; ++p)
--- 772,780 ----
  				break;
  			}
  		}
! #ifdef GTAGS
! 		}
! #endif
  		MOVE(sp, INFOLINE(sp), 0);
  		standout();
  		for (; *p != '\0'; ++p)
diff -c -r -N /usr/src/usr.bin/vi/vi/v_ex.c ./vi/v_ex.c
*** /usr/src/usr.bin/vi/vi/v_ex.c	Thu Aug 18 10:15:03 1994
--- ./vi/v_ex.c	Sat Dec 14 11:54:16 1996
***************
*** 298,303 ****
--- 298,308 ----
  	ARGS *ap[2], a;
  	EXCMDARG cmd;
  
+ #ifdef GTAGS
+ 	if (O_ISSET(sp, O_GTAGSMODE) && vp->m_start.cno == 0)
+ 		excmd(&cmd, C_RTAG, 0, OOBLNO, 0, 0, ap, &a, vp->keyword);
+ 	else
+ #endif
  	excmd(&cmd, C_TAG, 0, OOBLNO, 0, 0, ap, &a, vp->keyword);
  	return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
  }
diff -c -r -N /usr/src/usr.bin/vi/vi/v_scroll.c ./vi/v_scroll.c
*** /usr/src/usr.bin/vi/vi/v_scroll.c	Thu Aug 18 10:15:15 1994
--- ./vi/v_scroll.c	Sat Dec 14 11:54:16 1996
***************
*** 255,260 ****
--- 255,269 ----
  	EXF *ep;
  	VICMDARG *vp;
  {
+ #ifdef GTAGS
+ 	EXCMDARG cmd;
+ 
+ 	if (F_ISSET(sp->frp, FR_GTAGSTMP)) {
+ 		memset(&cmd, 0, sizeof(EXCMDARG));
+ 		cmd.cmd = &cmds[C_GTAGSELECT];
+ 		return (sp->s_ex_cmd(sp, ep, &cmd, &vp->m_final));
+ 	}
+ #endif
  	/*
  	 * If it's a script window, exec the line,
  	 * otherwise it's the same as v_down().