summaryrefslogtreecommitdiffstats
path: root/doc/tools/src2html1.4a/ctags-emacs/etags.c-ada-patch
blob: 7f660ce8647759981f6738a35a7042ba685473dd (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
*** etags.c.orig	Wed Aug  6 02:09:19 1997
--- etags.c	Wed Nov  5 13:30:11 1997
***************
*** 31,37 ****
   *	Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer.
   */
  
! char pot_etags_version[] = "@(#) pot revision number is 12.11";
  
  #define	TRUE	1
  #define	FALSE	0
--- 31,37 ----
   *	Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer.
   */
  
! char pot_etags_version[] = "@(#) pot revision number is 12.11/patched for Ada";
  
  #define	TRUE	1
  #define	FALSE	0
***************
*** 182,193 ****
--- 182,195 ----
  char *relative_filename (), *absolute_filename (), *absolute_dirname ();
  void grow_linebuffer ();
  long *xmalloc (), *xrealloc ();
+ char *basename_no_extension ();
  
  typedef void Lang_function ();
  /* Many compilers barf on this:
  	Lang_function Asm_labels;
     so let's write it this way */
  void Asm_labels ();
+ void Ada_funcs ();
  void C_entries ();
  void default_C_entries ();
  void plain_C_entries ();
***************
*** 300,305 ****
--- 302,309 ----
  bool cxref_style;		/* -x: create cxref style output */
  bool cplusplus;			/* .[hc] means C++, not C */
  bool noindentypedefs;		/* -I: ignore indentation in C */
+ bool packages_only;             /* -P: only ada packages */
+ bool do_filename_tags;          /* -F: insert a tag for the filename */
  
  #ifdef LONG_OPTIONS
  struct option longopts[] =
***************
*** 330,335 ****
--- 334,341 ----
    { "update",			no_argument,	   NULL,     'u'   },
    { "version",			no_argument,	   NULL,     'V'   },
    { "vgrind",			no_argument,	   NULL,     'v'   },
+   { "packages-only",		no_argument,	   NULL,     'P'   }, 
+   { "do-filename-tags",		no_argument,	   NULL,     'F'   }, 
    { 0 }
  };
  #endif /* LONG_OPTIONS */
***************
*** 371,376 ****
--- 377,386 ----
  			  NULL
  			};
  
+ /* Ada code */
+ char *Ada_suffixes [] = 
+   { "ads", "adb", "ada", NULL };
+ 
  /* Note that .c and .h can be considered C++, if the --c++ flag was
     given.  That is why default_C_entries is called here. */
  char *default_C_suffixes [] =
***************
*** 445,450 ****
--- 455,461 ----
  struct lang_entry lang_names [] =
  {
    { "asm",     Asm_labels,          Asm_suffixes,         NULL              },
+   { "Ada",     Ada_funcs,           Ada_suffixes,         NULL              },
    { "c",       default_C_entries,   default_C_suffixes,   NULL              },
    { "c++",     Cplusplus_entries,   Cplusplus_suffixes,   NULL              },
    { "c*",      Cstar_entries,       Cstar_suffixes,       NULL              },
***************
*** 609,614 ****
--- 620,631 ----
          which you like.");
      }
  
+   puts ("-P, --packages-only\n\
+         For Ada files, generates tags entries only for packages.");
+ 
+   puts ("-F, --do-filename-tags\n\
+         Generates a tag entry with tagname being file basename without suffix.");
+ 
    puts ("-V, --version\n\
          Print the version of the program.\n\
  -h, --help\n\
***************
*** 816,824 ****
        char *optstring;
  
  #ifdef ETAGS_REGEXPS
!       optstring = "-aCdDf:Il:o:r:RStTi:BuvxwVhH";
  #else
!       optstring = "-aCdDf:Il:o:StTi:BuvxwVhH";
  #endif /* ETAGS_REGEXPS */
  
  #ifndef LONG_OPTIONS
--- 833,841 ----
        char *optstring;
  
  #ifdef ETAGS_REGEXPS
!       optstring = "-aCdDf:Il:o:r:RStTi:BuvxwVhHPF";
  #else
!       optstring = "-aCdDf:Il:o:StTi:BuvxwVhHPF";
  #endif /* ETAGS_REGEXPS */
  
  #ifndef LONG_OPTIONS
***************
*** 892,897 ****
--- 909,923 ----
  	case 'T':
  	  typedefs = typedefs_and_cplusplus = TRUE;
  	  break;
+ 
+         case 'P':
+           packages_only++;
+           break;
+ 
+         case 'F':
+           do_filename_tags++;
+           break;
+ 
  #if (!CTAGS)
  	  /* Etags options */
  	case 'i':
***************
*** 1169,1174 ****
--- 1195,1201 ----
    if (!CTAGS)
      {
        char *filename;
+       char *tagfilename;
  
        if (absolutefn (file))
  	{
***************
*** 1181,1186 ****
--- 1208,1220 ----
  	     to the directory of the tags file. */
  	  filename = relative_filename (file, tagfiledir);
  	}
+       if (do_filename_tags)
+         {
+           tagfilename = basename_no_extension(filename);
+           pfnote(savestr(tagfilename), FALSE, tagfilename, 0, 1, 0);
+           free (tagfilename);
+         }
+       
        fprintf (tagf, "\f\n%s,%d\n", filename, total_size_of_entries (head));
        free (filename);
        put_entries (head);
***************
*** 2954,2959 ****
--- 2988,3198 ----
    C_entries (YACC, inf);
  }
  
+ /* ada parsing */
+ 
+ char    *adbp;
+ int     apfcnt;
+ 
+ void
+ Ada_funcs(fi)
+      FILE *fi;
+ {
+   int inquote;
+ 
+   inquote = 0;
+   lineno = 0;
+   charno = 0;
+   apfcnt = 0;
+ 
+   while (!feof (fi))
+     {
+       if (adbp == NULL || *adbp == 0)
+       {
+         lineno++;
+         linecharno = charno;
+         charno += readline (&lb, fi) + 1;
+         adbp = lb.buffer;
+       }
+       if (*adbp == '-')
+       {
+         adbp++ ;
+         if (*adbp == '-')
+         {
+           while (*adbp)
+             adbp++;
+           continue;
+         }
+       }
+       if (*adbp == '\'')
+       {
+         adbp++ ;
+         if (*adbp) adbp++;
+         continue;
+       }
+       if (inquote || (*adbp == '"'))
+       {
+         inquote = 1;
+         adbp++ ;
+         while (*adbp && *adbp != '"')
+           adbp++;
+         if (*adbp == '"')
+         {
+           adbp++;
+           inquote = 0;
+         }
+         continue;
+       }
+       while (*adbp && !begtoken(*adbp))
+       {
+         if ((*adbp == '-') || (*adbp == '"') || (*adbp == '\''))
+           break;
+         adbp++;
+       }
+       if ((*adbp == '-') || (*adbp == '"') || (*adbp == '\''))
+         continue;
+       if (*adbp == 0)
+         continue;
+       switch (*adbp)
+         {
+         case 'f':
+         case 'F':
+           if (adatail("function") && !packages_only)
+             adagetit(fi, "/f");
+           else
+             adaskip();
+           continue;
+         case 'p':
+         case 'P':
+           if (adatail("procedure") && !packages_only)
+             adagetit(fi, "/p");
+           else if (adatail("package"))
+             adagetit(fi, "/s");
+           else
+             adaskip();
+           continue;
+         case 't':
+         case 'T':
+           if (adatail("task") && !packages_only)
+               adagetit(fi, "/k");
+           else if (typedefs && adatail("type") && !packages_only)
+             adagetit(fi, "/t");
+           else
+             adaskip();
+           continue;
+ 
+         default:
+           adaskip();
+           continue;
+         }
+     }
+ }
+ adaskip()
+ {
+    while (*adbp && !endtoken(*adbp))
+      adbp++;
+    while (*adbp && !begtoken(*adbp))
+    {
+      if ((*adbp == '"') || (*adbp == '\'') || (*adbp == '-'))
+        return;
+      adbp++;
+    }
+ }
+ 
+ adatail(cp)
+      char *cp;
+ {
+   register int len = 0;
+ 
+   while (*cp && (*cp == tolower(*(adbp+len))))
+     cp++, len++;
+   if (*cp == 0)
+     {
+       adbp += len;
+       if (intoken(*adbp))
+         return (0);
+       else
+         return (1);
+     }
+   return (0);
+ }
+ 
+ adagetit(fi, name_qualifier)
+      FILE *fi;
+      char *name_qualifier;
+      
+ {
+   register char *cp;
+   char c;
+   char nambuf[BUFSIZ];
+   char * local_name_qualifier;
+   
+   local_name_qualifier = name_qualifier;
+   
+   while (!feof (fi))
+     {
+       if (*adbp == '\0')
+       {
+         lineno++;
+         linecharno = charno;
+         charno += readline (&lb, fi) + 1;
+         adbp = lb.buffer;
+       }
+       if (*adbp == '-')
+       {
+         adbp++ ;
+         if (*adbp == '-')
+         {
+           while (*adbp)
+             adbp++;
+           continue;
+         }
+       }
+       while (isspace(*adbp))
+         adbp++;
+       if (*adbp == 0)
+         continue;
+       if (*adbp == '-')
+         continue;
+       switch(*adbp)
+         {
+         case 'b':
+         case 'B':
+           if (adatail("body"))
+             {
+               local_name_qualifier = "/b";
+               continue;
+             }
+           break;
+           
+         case 't':
+         case 'T':
+           if (adatail("type"))
+             continue;
+           break;
+         }
+       if (*adbp == '"')
+       {
+         for (cp = adbp+1; *cp && *cp != '"'; cp++)
+           continue;
+       }
+       else
+         for (cp = adbp+1;
+              *cp && (isalpha(*cp) || isdigit(*cp) || *cp == '_');
+              cp++)
+           continue;
+       c = cp[0];
+       cp[0] = 0;
+       strcpy(nambuf, adbp);
+       strcat(nambuf, local_name_qualifier);
+       cp[0] = c;
+       pfnote(savenstr (nambuf, strlen(nambuf)), TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
+       /* I am not really sure what the name is used for. */
+       /* probably to be used to add a qualifier like /f /p /b /s /k /t */
+       apfcnt++;
+       return;
+     }
+ }
+ 
  /* Fortran parsing */
  
  char *dbp;
***************
*** 4684,4689 ****
--- 4923,4968 ----
    return path.buffer;
  #endif /* not MSDOS */
  #endif /* not HAVE_GETCWD */
+ }
+ 
+ /* Returna newly allocated string containing the filename
+    of FILE without any precending directory and without
+    extension. */
+ char *
+ basename_no_extension (file)
+      char *file;
+ {
+   char *begin = file + strlen(file);
+   char *end = begin;
+   char *res, *rescp;
+   bool in_extension;
+   
+ 
+   /* position begin at the begining of the basename
+      end will point to the end of the basename 
+      without extension */
+   in_extension = TRUE;
+   
+   while (begin > file && *begin != '/')
+     {
+       if (*begin == '.' && in_extension)
+         {
+           end = begin;
+           in_extension = FALSE;
+         }
+       begin--;
+     }
+   if (*begin == '/') 
+     begin++;
+ 
+   res = xnew(strlen(begin) - strlen(end) + 1, char);
+   rescp = res;
+   while (begin != end)
+     {
+       *rescp++ = *begin++;
+     }
+   *rescp = '\0';
+   return res;
  }
  
  /* Return a newly allocated string containing the file name