Merge from vendor branch TNF:
[pkgsrc.git] / editors / nvi-m17n / patches / patch-global
1 $NetBSD$
2
3 diff -NrU2 ../build/Makefile.in ../../nvi-1.79/build/Makefile.in
4 --- ../build/Makefile.in        Mon May  8 16:05:17 2000
5 +++ ../../nvi-1.79/build/Makefile.in    Mon May  8 16:06:15 2000
6 @@ -4,5 +4,5 @@
7  CC=    @CC@
8  OPTFLAG=@OPTFLAG@
9 -CFLAGS=        -c $(OPTFLAG) @CFLAGS@ -I. -I$(srcdir)/include @CPPFLAGS@
10 +CFLAGS=        -c $(OPTFLAG) @CFLAGS@ -I. -I$(srcdir)/include @CPPFLAGS@ -DGTAGS
11  LDFLAGS=@LDFLAGS@
12  PERL=  @vi_cv_path_perl@
13 diff -NrU2 ../common/main.c ../../nvi-1.79/common/main.c
14 --- ../common/main.c    Sat Oct 12 07:28:28 1996
15 +++ ../../nvi-1.79/common/main.c        Mon May  8 16:06:15 2000
16 @@ -65,4 +65,7 @@
17         u_int flags;
18         int ch, flagchk, lflag, secure, startup, readonly, rval, silent;
19 +#ifdef GTAGS
20 +       int gtags = 0;
21 +#endif
22         char *tag_f, *wsizearg, path[256];
23  
24 @@ -114,4 +117,11 @@
25         F_SET(gp, G_SNAPSHOT);
26  
27 +#ifdef GTAGS
28 +#ifdef DEBUG
29 +       while ((ch = getopt(argc, argv, "c:D:eFGlRrSsT:t:vw:")) != EOF)
30 +#else
31 +       while ((ch = getopt(argc, argv, "c:eFGlRrSst:vw:")) != EOF)
32 +#endif
33 +#else
34  #ifdef DEBUG
35         while ((ch = getopt(argc, argv, "c:D:eFlRrSsT:t:vw:")) != EOF)
36 @@ -119,4 +129,5 @@
37         while ((ch = getopt(argc, argv, "c:eFlRrSst:vw:")) != EOF)
38  #endif
39 +#endif
40                 switch (ch) {
41                 case 'c':               /* Run the command. */
42 @@ -155,4 +166,9 @@
43                         F_CLR(gp, G_SNAPSHOT);
44                         break;
45 +#ifdef GTAGS
46 +               case 'G':               /* gtags mode. */
47 +                       gtags = 1;
48 +                       break;
49 +#endif
50                 case 'l':               /* Set lisp, showmatch options. */
51                         lflag = 1;
52 @@ -253,4 +269,8 @@
53         if (readonly)
54                 *oargp++ = O_READONLY;
55 +#ifdef GTAGS
56 +       if (gtags)
57 +               *oargp++ = O_GTAGSMODE;
58 +#endif
59         if (secure)
60                 *oargp++ = O_SECURE;
61 diff -NrU2 ../common/options.c ../../nvi-1.79/common/options.c
62 --- ../common/options.c Mon May  8 16:05:18 2000
63 +++ ../../nvi-1.79/common/options.c     Mon May  8 16:20:26 2000
64 @@ -129,4 +129,8 @@
65  /* O_FLASH         HPUX */
66         {"flash",       NULL,           OPT_1BOOL,      0},
67 +#ifdef GTAGS
68 +/* O_GTAGSMODE      FreeBSD2.2 */
69 +       {"gtagsmode",   NULL,           OPT_0BOOL,      0},
70 +#endif
71  /* O_HARDTABS      4BSD */
72         {"hardtabs",    NULL,           OPT_NUM,        0},
73 @@ -313,4 +317,7 @@
74  #ifdef MULTIBYTE
75         {"fe",          O_FILEENCODING},        /* MULTIBYTE */
76 +#endif
77 +#ifdef GTAGS
78 +       {"gt",          O_GTAGSMODE},           /*    GTAGS */
79  #endif
80         {"ht",          O_HARDTABS},            /*     4BSD */
81 diff -NrU2 ../docs/USD.doc/vi.man/vi.1 ../../nvi-1.79/docs/USD.doc/vi.man/vi.1
82 --- ../docs/USD.doc/vi.man/vi.1 Fri Oct 11 10:34:05 1996
83 +++ ../../nvi-1.79/docs/USD.doc/vi.man/vi.1     Mon May  8 16:06:15 2000
84 @@ -18,5 +18,5 @@
85  .B ex
86  [\c
87 -.B -eFRrSsv\c
88 +.B -eFGRrSsv\c
89  ] [\c
90  .BI -c " cmd"\c
91 @@ -29,5 +29,5 @@
92  .B vi
93  [\c
94 -.B -eFlRrSv\c
95 +.B -eFGlRrSv\c
96  ] [\c
97  .BI -c " cmd"\c
98 @@ -40,5 +40,5 @@
99  .B view
100  [\c
101 -.B -eFRrSv\c
102 +.B -eFGRrSv\c
103  ] [\c
104  .BI -c " cmd"\c
105 @@ -122,4 +122,7 @@
106  Start editing with the lisp and showmatch options set.
107  .TP
108 +.B \-G
109 +Start editing in gtags mode, as if the gtagsmode option was set.
110 +.TP
111  .B \-R
112  Start editing in read-only mode, as if the command name was
113 @@ -430,4 +433,6 @@
114  .B "<control-]>"
115  Push a tag reference onto the tag stack.
116 +In gtagsmode, if at the first column of line,
117 +locate function references otherwise function definitions.
118  .TP
119  .B "<control-^>"
120 @@ -941,4 +946,7 @@
121  Rewind the argument list.
122  .TP
123 +.B "rta[g][!] tagstring"
124 +Edit the file refering the specified tag. (Only in gtagsmode)
125 +.TP
126  .B "se[t] [option[=[value]] ...] [nooption ...] [option? ...] [all]"
127  Display or set editor options.
128 @@ -1110,4 +1118,7 @@
129  .B "flash [on]"
130  Flash the screen instead of beeping the keyboard on error.
131 +.TP
132 +.B "gtagsmode, gt [off]"
133 +Use GTAGS and GRTAGS instead of tags.
134  .TP
135  .B "hardtabs, ht [8]"
136 diff -NrU2 ../ex/ex.h ../../nvi-1.79/ex/ex.h
137 --- ../ex/ex.h  Mon May  8 16:05:18 2000
138 +++ ../../nvi-1.79/ex/ex.h      Mon May  8 16:06:15 2000
139 @@ -165,4 +165,7 @@
140  #define        E_USELASTCMD    0x02000000      /* Use the last command. */
141  #define        E_VISEARCH      0x04000000      /* It's really a vi search command. */
142 +#ifdef GTAGS
143 +#define        E_REFERENCE     0x08000000      /* locate function references */
144 +#endif
145         u_int32_t flags;                /* Current flags. */
146  };
147 diff -NrU2 ../ex/ex_cmd.c ../../nvi-1.79/ex/ex_cmd.c
148 --- ../ex/ex_cmd.c      Wed Oct 23 22:31:01 1996
149 +++ ../../nvi-1.79/ex/ex_cmd.c  Mon May  8 16:06:15 2000
150 @@ -303,4 +303,11 @@
151             "rew[ind][!]",
152             "re-edit all the files in the file argument list"},
153 +#ifdef GTAGS
154 +/* C_RTAG */
155 +       {"rtag",        ex_rtag_push,   E_NEWSCREEN,
156 +           "!w1o",
157 +           "rta[g][!] [string]",
158 +           "edit the file containing the tag"},
159 +#endif
160  /*
161   * !!!
162 diff -NrU2 ../ex/ex_tag.c ../../nvi-1.79/ex/ex_tag.c
163 --- ../ex/ex_tag.c      Mon Sep 16 05:02:43 1996
164 +++ ../../nvi-1.79/ex/ex_tag.c  Mon May  8 16:06:15 2000
165 @@ -47,4 +47,8 @@
166  static void     ctag_file __P((SCR *, TAGF *, char *, char **, size_t *));
167  static int      ctag_search __P((SCR *, char *, size_t, char *));
168 +#ifdef GTAGS
169 +static int      getentry __P((char *, char **, char **, char **));
170 +static TAGQ    *gtag_slist __P((SCR *, char *, int));
171 +#endif
172  static int      ctag_sfile __P((SCR *, TAGF *, TAGQ *, char *));
173  static TAGQ    *ctag_slist __P((SCR *, char *));
174 @@ -90,4 +94,23 @@
175  }
176  
177 +#ifdef GTAGS
178 +/*
179 + * ex_rtag_push -- ^]
180 + *               :rtag[!] [string]
181 + *
182 + * Enter a new TAGQ context based on a ctag string.
183 + *
184 + * PUBLIC: int ex_rtag_push __P((SCR *, EXCMD *));
185 + */
186 +int
187 +ex_rtag_push(sp, cmdp)
188 +       SCR *sp;
189 +       EXCMD *cmdp;
190 +{
191 +       F_SET(cmdp, E_REFERENCE);
192 +       return ex_tag_push(sp, cmdp);
193 +}
194 +#endif
195 +
196  /*
197   * ex_tag_push -- ^]
198 @@ -139,4 +162,10 @@
199  
200         /* Get the tag information. */
201 +#ifdef GTAGS
202 +       if (O_ISSET(sp, O_GTAGSMODE)) {
203 +               if ((tqp = gtag_slist(sp, exp->tag_last, F_ISSET(cmdp, E_REFERENCE))) == NULL)
204 +                       return (1);
205 +       } else
206 +#endif
207         if ((tqp = ctag_slist(sp, exp->tag_last)) == NULL)
208                 return (1);
209 @@ -970,4 +999,127 @@
210  }
211  
212 +#ifdef GTAGS
213 +/*
214 + * getentry --
215 + *     get tag information from current line.
216 + *
217 + * gtags temporary file format.
218 + * <tag>   <lineno>  <file>         <image>
219 + *
220 + * sample.
221 + * +------------------------------------------------
222 + * |main     30      main.c         main(argc, argv)
223 + * |func     21      subr.c         func(arg)
224 + */
225 +static int
226 +getentry(buf, tag, file, line)
227 +       char *buf, **tag, **file, **line;
228 +{
229 +       char *p = buf;
230 +
231 +       for (*tag = p; *p && !isspace(*p); p++)         /* tag name */
232 +               ;
233 +       if (*p == 0)
234 +               goto err;
235 +       *p++ = 0;
236 +       for (; *p && isspace(*p); p++)                  /* (skip blanks) */
237 +               ;
238 +       if (*p == 0)
239 +               goto err;
240 +       *line = p;                                      /* line no */
241 +       for (*line = p; *p && !isspace(*p); p++)
242 +               ;
243 +       if (*p == 0)
244 +               goto err;
245 +       *p++ = 0;
246 +       for (; *p && isspace(*p); p++)                  /* (skip blanks) */
247 +               ;
248 +       if (*p == 0)
249 +               goto err;
250 +       *file = p;                                      /* file name */
251 +       for (*file = p; *p && !isspace(*p); p++)
252 +               ;
253 +       if (*p == 0)
254 +               goto err;
255 +       *p = 0;
256 +
257 +       /* value check */
258 +       if (strlen(*tag) && strlen(*line) && strlen(*file) && atoi(*line) > 0)
259 +               return 1;       /* OK */
260 +err:
261 +       return 0;               /* ERROR */
262 +}
263 +
264 +/*
265 + * gtag_slist --
266 + *     Search the list of tags files for a tag, and return tag queue.
267 + */
268 +static TAGQ *
269 +gtag_slist(sp, tag, ref)
270 +       SCR *sp;
271 +       char *tag;
272 +       int ref;
273 +{
274 +       EX_PRIVATE *exp;
275 +       TAGF *tfp;
276 +       TAGQ *tqp;
277 +       size_t len;
278 +       int echk;
279 +       TAG *tp;
280 +       char *name, *file, *line;
281 +       char command[BUFSIZ];
282 +       char buf[BUFSIZ];
283 +       FILE *fp;
284 +
285 +       /* Allocate and initialize the tag queue structure. */
286 +       len = strlen(tag);
287 +       CALLOC_GOTO(sp, tqp, TAGQ *, 1, sizeof(TAGQ) + len + 1);
288 +       CIRCLEQ_INIT(&tqp->tagq);
289 +       tqp->tag = tqp->buf;
290 +       memcpy(tqp->tag, tag, (tqp->tlen = len) + 1);
291 +
292 +       /*
293 +        * Find the tag, only display missing file messages once, and
294 +        * then only if we didn't find the tag.
295 +        */
296 +       snprintf(command, sizeof(command), "global -%s '%s' 2>/dev/null", ref ? "rx" : "x", tag);
297 +       if (fp = popen(command, "r")) {
298 +               while (fgets(buf, sizeof(buf), fp)) {
299 +                       if (buf[strlen(buf)-1] == '\n')         /* chop(buf) */
300 +                               buf[strlen(buf)-1] = 0;
301 +                       else
302 +                               while (fgetc(fp) != '\n')
303 +                                       ;
304 +                       if (getentry(buf, &name, &file, &line) == 0) {
305 +                               echk = 1;
306 +                               F_SET(tfp, TAGF_ERR);
307 +                               break;
308 +                       }
309 +                       CALLOC_GOTO(sp, tp,
310 +                           TAG *, 1, sizeof(TAG) + strlen(file) + 1 + strlen(line) + 1);
311 +                       tp->fname = tp->buf;
312 +                       strcpy(tp->fname, file);
313 +                       tp->fnlen = strlen(file);
314 +                       tp->search = tp->fname + tp->fnlen + 1;
315 +                       strcpy(tp->search, line);
316 +                       CIRCLEQ_INSERT_TAIL(&tqp->tagq, tp, q);
317 +               }
318 +               pclose(fp);
319 +       }
320 +
321 +       /* Check to see if we found anything. */
322 +       if (tqp->tagq.cqh_first == (void *)&tqp->tagq) {
323 +               msgq_str(sp, M_ERR, tag, "162|%s: tag not found");
324 +               free(tqp);
325 +               return (NULL);
326 +       }
327 +
328 +       tqp->current = tqp->tagq.cqh_first;
329 +       return (tqp);
330 +
331 +alloc_err:
332 +       return (NULL);
333 +}
334 +#endif
335  /*
336   * ctag_slist --
337 diff -NrU2 ../include/ex_def.h ../../nvi-1.79/include/ex_def.h
338 --- ../include/ex_def.h Wed Oct 23 22:53:09 1996
339 +++ ../../nvi-1.79/include/ex_def.h     Mon May  8 16:06:15 2000
340 @@ -48,31 +48,32 @@
341  #define C_RESIZE 47
342  #define C_REWIND 48
343 -#define C_SUBSTITUTE 49
344 -#define C_SCRIPT 50
345 -#define C_SET 51
346 -#define C_SHELL 52
347 -#define C_SOURCE 53
348 -#define C_STOP 54
349 -#define C_SUSPEND 55
350 -#define C_T 56
351 -#define C_TAG 57
352 -#define C_TAGNEXT 58
353 -#define C_TAGPOP 59
354 -#define C_TAGPREV 60
355 -#define C_TAGTOP 61
356 -#define C_TCLCMD 62
357 -#define C_UNDO 63
358 -#define C_UNABBREVIATE 64
359 -#define C_UNMAP 65
360 -#define C_V 66
361 -#define C_VERSION 67
362 -#define C_VISUAL_EX 68
363 -#define C_VISUAL_VI 69
364 -#define C_VIUSAGE 70
365 -#define C_WRITE 71
366 -#define C_WN 72
367 -#define C_WQ 73
368 -#define C_XIT 74
369 -#define C_YANK 75
370 -#define C_Z 76
371 -#define C_SUBTILDE 77
372 +#define C_RTAG 49
373 +#define C_SUBSTITUTE 50
374 +#define C_SCRIPT 51
375 +#define C_SET 52
376 +#define C_SHELL 53
377 +#define C_SOURCE 54
378 +#define C_STOP 55
379 +#define C_SUSPEND 56
380 +#define C_T 57
381 +#define C_TAG 58
382 +#define C_TAGNEXT 59
383 +#define C_TAGPOP 60
384 +#define C_TAGPREV 61
385 +#define C_TAGTOP 62
386 +#define C_TCLCMD 63
387 +#define C_UNDO 64
388 +#define C_UNABBREVIATE 65
389 +#define C_UNMAP 66
390 +#define C_V 67
391 +#define C_VERSION 68
392 +#define C_VISUAL_EX 69
393 +#define C_VISUAL_VI 70
394 +#define C_VIUSAGE 71
395 +#define C_WRITE 72
396 +#define C_WN 73
397 +#define C_WQ 74
398 +#define C_XIT 75
399 +#define C_YANK 76
400 +#define C_Z 77
401 +#define C_SUBTILDE 78
402 diff -NrU2 ../include/ex_extern.h ../../nvi-1.79/include/ex_extern.h
403 --- ../include/ex_extern.h      Wed Oct 23 22:53:10 1996
404 +++ ../../nvi-1.79/include/ex_extern.h  Mon May  8 16:06:15 2000
405 @@ -90,4 +90,5 @@
406  void re_error __P((SCR *, int, regex_t *));
407  int ex_tag_first __P((SCR *, char *));
408 +int ex_rtag_push __P((SCR *, EXCMD *));
409  int ex_tag_push __P((SCR *, EXCMD *));
410  int ex_tag_next __P((SCR *, EXCMD *));
411 diff -NrU2 ../include/options_def.h ../../nvi-1.79/include/options_def.h
412 --- ../include/options_def.h    Mon May  8 16:05:18 2000
413 +++ ../../nvi-1.79/include/options_def.h        Mon May  8 16:24:38 2000
414 @@ -25,65 +25,66 @@
415  #define O_FILEENCODING 24
416  #define O_FLASH 25
417 -#define O_HARDTABS 26
418 -#define O_ICLOWER 27
419 -#define O_IGNORECASE 28
420 -#define O_INPUTENCODING 29
421 -#define O_KEYTIME 30
422 -#define O_LEFTRIGHT 31
423 -#define O_LINES 32
424 -#define O_LISP 33
425 -#define O_LIST 34
426 -#define O_LOCKFILES 35
427 -#define O_MAGIC 36
428 -#define O_MATCHTIME 37
429 -#define O_MESG 38
430 -#define O_MODELINE 39
431 -#define O_MSGCAT 40
432 -#define O_NOPRINT 41
433 -#define O_NUMBER 42
434 -#define O_OCTAL 43
435 -#define O_OPEN 44
436 -#define O_OPTIMIZE 45
437 -#define O_PARAGRAPHS 46
438 -#define O_PATH 47
439 -#define O_PRINT 48
440 -#define O_PROMPT 49
441 -#define O_READONLY 50
442 -#define O_RECDIR 51
443 -#define O_REDRAW 52
444 -#define O_REMAP 53
445 -#define O_REPORT 54
446 -#define O_RULER 55
447 -#define O_SCROLL 56
448 -#define O_SEARCHINCR 57
449 -#define O_SECTIONS 58
450 -#define O_SECURE 59
451 -#define O_SHELL 60
452 -#define O_SHELLMETA 61
453 -#define O_SHIFTWIDTH 62
454 -#define O_SHOWMATCH 63
455 -#define O_SHOWMODE 64
456 -#define O_SIDESCROLL 65
457 -#define O_SKIPDISPLAY 66
458 -#define O_SLOWOPEN 67
459 -#define O_SOURCEANY 68
460 -#define O_TABSTOP 69
461 -#define O_TAGLENGTH 70
462 -#define O_TAGS 71
463 -#define O_TERM 72
464 -#define O_TERSE 73
465 -#define O_TILDEOP 74
466 -#define O_TIMEOUT 75
467 -#define O_TTYWERASE 76
468 -#define O_VERBOSE 77
469 -#define O_W1200 78
470 -#define O_W300 79
471 -#define O_W9600 80
472 -#define O_WARN 81
473 -#define O_WINDOW 82
474 -#define O_WINDOWNAME 83
475 -#define O_WRAPLEN 84
476 -#define O_WRAPMARGIN 85
477 -#define O_WRAPSCAN 86
478 -#define O_WRITEANY 87
479 -#define O_OPTIONCOUNT 88
480 +#define O_GTAGSMODE 26
481 +#define O_HARDTABS 27
482 +#define O_ICLOWER 28
483 +#define O_IGNORECASE 29
484 +#define O_INPUTENCODING 30
485 +#define O_KEYTIME 31
486 +#define O_LEFTRIGHT 32
487 +#define O_LINES 33
488 +#define O_LISP 34
489 +#define O_LIST 35
490 +#define O_LOCKFILES 36
491 +#define O_MAGIC 37
492 +#define O_MATCHTIME 38
493 +#define O_MESG 39
494 +#define O_MODELINE 40
495 +#define O_MSGCAT 41
496 +#define O_NOPRINT 42
497 +#define O_NUMBER 43
498 +#define O_OCTAL 44
499 +#define O_OPEN 45
500 +#define O_OPTIMIZE 46
501 +#define O_PARAGRAPHS 47
502 +#define O_PATH 48
503 +#define O_PRINT 49
504 +#define O_PROMPT 50
505 +#define O_READONLY 51
506 +#define O_RECDIR 52
507 +#define O_REDRAW 53
508 +#define O_REMAP 54
509 +#define O_REPORT 55
510 +#define O_RULER 56
511 +#define O_SCROLL 57
512 +#define O_SEARCHINCR 58
513 +#define O_SECTIONS 59
514 +#define O_SECURE 60
515 +#define O_SHELL 61
516 +#define O_SHELLMETA 62
517 +#define O_SHIFTWIDTH 63
518 +#define O_SHOWMATCH 64
519 +#define O_SHOWMODE 65
520 +#define O_SIDESCROLL 66
521 +#define O_SKIPDISPLAY 67
522 +#define O_SLOWOPEN 68
523 +#define O_SOURCEANY 69
524 +#define O_TABSTOP 70
525 +#define O_TAGLENGTH 71
526 +#define O_TAGS 72
527 +#define O_TERM 73
528 +#define O_TERSE 74
529 +#define O_TILDEOP 75
530 +#define O_TIMEOUT 76
531 +#define O_TTYWERASE 77
532 +#define O_VERBOSE 78
533 +#define O_W1200 79
534 +#define O_W300 80
535 +#define O_W9600 81
536 +#define O_WARN 82
537 +#define O_WINDOW 83
538 +#define O_WINDOWNAME 84
539 +#define O_WRAPLEN 85
540 +#define O_WRAPMARGIN 86
541 +#define O_WRAPSCAN 87
542 +#define O_WRITEANY 88
543 +#define O_OPTIONCOUNT 89
544 diff -NrU2 ../vi/v_ex.c ../../nvi-1.79/vi/v_ex.c
545 --- ../vi/v_ex.c        Mon May  8 16:05:18 2000
546 +++ ../../nvi-1.79/vi/v_ex.c    Mon May  8 16:06:15 2000
547 @@ -227,4 +227,9 @@
548         EXCMD cmd;
549  
550 +#ifdef GTAGS
551 +       if (O_ISSET(sp, O_GTAGSMODE) && vp->m_start.cno == 0)
552 +               ex_cinit(&cmd, C_RTAG, 0, OOBLNO, 0, 0, ap);
553 +       else
554 +#endif
555         ex_cinit(&cmd, C_TAG, 0, OOBLNO, 0, 0, ap);
556         ex_cadd(&cmd, &a, VIP(sp)->keyw, strlen(VIP(sp)->keyw));