source: rtems/doc/tools/src2html1.4a/ctags-emacs/etags.c-ada-patch @ 56cab83

4.104.114.84.95
Last change on this file since 56cab83 was 56cab83, checked in by Joel Sherrill <joel.sherrill@…>, on 04/14/98 at 17:09:26

Added emacs Ada tags stuff

  • Property mode set to 100644
File size: 10.0 KB
Line 
1*** etags.c.orig        Wed Aug  6 02:09:19 1997
2--- etags.c     Wed Nov  5 13:30:11 1997
3***************
4*** 31,37 ****
5   *    Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer.
6   */
7 
8! char pot_etags_version[] = "@(#) pot revision number is 12.11";
9 
10  #define       TRUE    1
11  #define       FALSE   0
12--- 31,37 ----
13   *    Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer.
14   */
15 
16! char pot_etags_version[] = "@(#) pot revision number is 12.11/patched for Ada";
17 
18  #define       TRUE    1
19  #define       FALSE   0
20***************
21*** 182,193 ****
22--- 182,195 ----
23  char *relative_filename (), *absolute_filename (), *absolute_dirname ();
24  void grow_linebuffer ();
25  long *xmalloc (), *xrealloc ();
26+ char *basename_no_extension ();
27 
28  typedef void Lang_function ();
29  /* Many compilers barf on this:
30        Lang_function Asm_labels;
31     so let's write it this way */
32  void Asm_labels ();
33+ void Ada_funcs ();
34  void C_entries ();
35  void default_C_entries ();
36  void plain_C_entries ();
37***************
38*** 300,305 ****
39--- 302,309 ----
40  bool cxref_style;             /* -x: create cxref style output */
41  bool cplusplus;                       /* .[hc] means C++, not C */
42  bool noindentypedefs;         /* -I: ignore indentation in C */
43+ bool packages_only;             /* -P: only ada packages */
44+ bool do_filename_tags;          /* -F: insert a tag for the filename */
45 
46  #ifdef LONG_OPTIONS
47  struct option longopts[] =
48***************
49*** 330,335 ****
50--- 334,341 ----
51    { "update",                 no_argument,       NULL,     'u'   },
52    { "version",                        no_argument,       NULL,     'V'   },
53    { "vgrind",                 no_argument,       NULL,     'v'   },
54+   { "packages-only",          no_argument,       NULL,     'P'   },
55+   { "do-filename-tags",               no_argument,       NULL,     'F'   },
56    { 0 }
57  };
58  #endif /* LONG_OPTIONS */
59***************
60*** 371,376 ****
61--- 377,386 ----
62                          NULL
63                        };
64 
65+ /* Ada code */
66+ char *Ada_suffixes [] =
67+   { "ads", "adb", "ada", NULL };
68+
69  /* Note that .c and .h can be considered C++, if the --c++ flag was
70     given.  That is why default_C_entries is called here. */
71  char *default_C_suffixes [] =
72***************
73*** 445,450 ****
74--- 455,461 ----
75  struct lang_entry lang_names [] =
76  {
77    { "asm",     Asm_labels,          Asm_suffixes,         NULL              },
78+   { "Ada",     Ada_funcs,           Ada_suffixes,         NULL              },
79    { "c",       default_C_entries,   default_C_suffixes,   NULL              },
80    { "c++",     Cplusplus_entries,   Cplusplus_suffixes,   NULL              },
81    { "c*",      Cstar_entries,       Cstar_suffixes,       NULL              },
82***************
83*** 609,614 ****
84--- 620,631 ----
85          which you like.");
86      }
87 
88+   puts ("-P, --packages-only\n\
89+         For Ada files, generates tags entries only for packages.");
90+
91+   puts ("-F, --do-filename-tags\n\
92+         Generates a tag entry with tagname being file basename without suffix.");
93+
94    puts ("-V, --version\n\
95          Print the version of the program.\n\
96  -h, --help\n\
97***************
98*** 816,824 ****
99        char *optstring;
100 
101  #ifdef ETAGS_REGEXPS
102!       optstring = "-aCdDf:Il:o:r:RStTi:BuvxwVhH";
103  #else
104!       optstring = "-aCdDf:Il:o:StTi:BuvxwVhH";
105  #endif /* ETAGS_REGEXPS */
106 
107  #ifndef LONG_OPTIONS
108--- 833,841 ----
109        char *optstring;
110 
111  #ifdef ETAGS_REGEXPS
112!       optstring = "-aCdDf:Il:o:r:RStTi:BuvxwVhHPF";
113  #else
114!       optstring = "-aCdDf:Il:o:StTi:BuvxwVhHPF";
115  #endif /* ETAGS_REGEXPS */
116 
117  #ifndef LONG_OPTIONS
118***************
119*** 892,897 ****
120--- 909,923 ----
121        case 'T':
122          typedefs = typedefs_and_cplusplus = TRUE;
123          break;
124+
125+         case 'P':
126+           packages_only++;
127+           break;
128+
129+         case 'F':
130+           do_filename_tags++;
131+           break;
132+
133  #if (!CTAGS)
134          /* Etags options */
135        case 'i':
136***************
137*** 1169,1174 ****
138--- 1195,1201 ----
139    if (!CTAGS)
140      {
141        char *filename;
142+       char *tagfilename;
143 
144        if (absolutefn (file))
145        {
146***************
147*** 1181,1186 ****
148--- 1208,1220 ----
149             to the directory of the tags file. */
150          filename = relative_filename (file, tagfiledir);
151        }
152+       if (do_filename_tags)
153+         {
154+           tagfilename = basename_no_extension(filename);
155+           pfnote(savestr(tagfilename), FALSE, tagfilename, 0, 1, 0);
156+           free (tagfilename);
157+         }
158+       
159        fprintf (tagf, "\f\n%s,%d\n", filename, total_size_of_entries (head));
160        free (filename);
161        put_entries (head);
162***************
163*** 2954,2959 ****
164--- 2988,3198 ----
165    C_entries (YACC, inf);
166  }
167 
168+ /* ada parsing */
169+
170+ char    *adbp;
171+ int     apfcnt;
172+
173+ void
174+ Ada_funcs(fi)
175+      FILE *fi;
176+ {
177+   int inquote;
178+
179+   inquote = 0;
180+   lineno = 0;
181+   charno = 0;
182+   apfcnt = 0;
183+
184+   while (!feof (fi))
185+     {
186+       if (adbp == NULL || *adbp == 0)
187+       {
188+         lineno++;
189+         linecharno = charno;
190+         charno += readline (&lb, fi) + 1;
191+         adbp = lb.buffer;
192+       }
193+       if (*adbp == '-')
194+       {
195+         adbp++ ;
196+         if (*adbp == '-')
197+         {
198+           while (*adbp)
199+             adbp++;
200+           continue;
201+         }
202+       }
203+       if (*adbp == '\'')
204+       {
205+         adbp++ ;
206+         if (*adbp) adbp++;
207+         continue;
208+       }
209+       if (inquote || (*adbp == '"'))
210+       {
211+         inquote = 1;
212+         adbp++ ;
213+         while (*adbp && *adbp != '"')
214+           adbp++;
215+         if (*adbp == '"')
216+         {
217+           adbp++;
218+           inquote = 0;
219+         }
220+         continue;
221+       }
222+       while (*adbp && !begtoken(*adbp))
223+       {
224+         if ((*adbp == '-') || (*adbp == '"') || (*adbp == '\''))
225+           break;
226+         adbp++;
227+       }
228+       if ((*adbp == '-') || (*adbp == '"') || (*adbp == '\''))
229+         continue;
230+       if (*adbp == 0)
231+         continue;
232+       switch (*adbp)
233+         {
234+         case 'f':
235+         case 'F':
236+           if (adatail("function") && !packages_only)
237+             adagetit(fi, "/f");
238+           else
239+             adaskip();
240+           continue;
241+         case 'p':
242+         case 'P':
243+           if (adatail("procedure") && !packages_only)
244+             adagetit(fi, "/p");
245+           else if (adatail("package"))
246+             adagetit(fi, "/s");
247+           else
248+             adaskip();
249+           continue;
250+         case 't':
251+         case 'T':
252+           if (adatail("task") && !packages_only)
253+               adagetit(fi, "/k");
254+           else if (typedefs && adatail("type") && !packages_only)
255+             adagetit(fi, "/t");
256+           else
257+             adaskip();
258+           continue;
259+
260+         default:
261+           adaskip();
262+           continue;
263+         }
264+     }
265+ }
266+ adaskip()
267+ {
268+    while (*adbp && !endtoken(*adbp))
269+      adbp++;
270+    while (*adbp && !begtoken(*adbp))
271+    {
272+      if ((*adbp == '"') || (*adbp == '\'') || (*adbp == '-'))
273+        return;
274+      adbp++;
275+    }
276+ }
277+
278+ adatail(cp)
279+      char *cp;
280+ {
281+   register int len = 0;
282+
283+   while (*cp && (*cp == tolower(*(adbp+len))))
284+     cp++, len++;
285+   if (*cp == 0)
286+     {
287+       adbp += len;
288+       if (intoken(*adbp))
289+         return (0);
290+       else
291+         return (1);
292+     }
293+   return (0);
294+ }
295+
296+ adagetit(fi, name_qualifier)
297+      FILE *fi;
298+      char *name_qualifier;
299+     
300+ {
301+   register char *cp;
302+   char c;
303+   char nambuf[BUFSIZ];
304+   char * local_name_qualifier;
305+   
306+   local_name_qualifier = name_qualifier;
307+   
308+   while (!feof (fi))
309+     {
310+       if (*adbp == '\0')
311+       {
312+         lineno++;
313+         linecharno = charno;
314+         charno += readline (&lb, fi) + 1;
315+         adbp = lb.buffer;
316+       }
317+       if (*adbp == '-')
318+       {
319+         adbp++ ;
320+         if (*adbp == '-')
321+         {
322+           while (*adbp)
323+             adbp++;
324+           continue;
325+         }
326+       }
327+       while (isspace(*adbp))
328+         adbp++;
329+       if (*adbp == 0)
330+         continue;
331+       if (*adbp == '-')
332+         continue;
333+       switch(*adbp)
334+         {
335+         case 'b':
336+         case 'B':
337+           if (adatail("body"))
338+             {
339+               local_name_qualifier = "/b";
340+               continue;
341+             }
342+           break;
343+           
344+         case 't':
345+         case 'T':
346+           if (adatail("type"))
347+             continue;
348+           break;
349+         }
350+       if (*adbp == '"')
351+       {
352+         for (cp = adbp+1; *cp && *cp != '"'; cp++)
353+           continue;
354+       }
355+       else
356+         for (cp = adbp+1;
357+              *cp && (isalpha(*cp) || isdigit(*cp) || *cp == '_');
358+              cp++)
359+           continue;
360+       c = cp[0];
361+       cp[0] = 0;
362+       strcpy(nambuf, adbp);
363+       strcat(nambuf, local_name_qualifier);
364+       cp[0] = c;
365+       pfnote(savenstr (nambuf, strlen(nambuf)), TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
366+       /* I am not really sure what the name is used for. */
367+       /* probably to be used to add a qualifier like /f /p /b /s /k /t */
368+       apfcnt++;
369+       return;
370+     }
371+ }
372+
373  /* Fortran parsing */
374 
375  char *dbp;
376***************
377*** 4684,4689 ****
378--- 4923,4968 ----
379    return path.buffer;
380  #endif /* not MSDOS */
381  #endif /* not HAVE_GETCWD */
382+ }
383+
384+ /* Returna newly allocated string containing the filename
385+    of FILE without any precending directory and without
386+    extension. */
387+ char *
388+ basename_no_extension (file)
389+      char *file;
390+ {
391+   char *begin = file + strlen(file);
392+   char *end = begin;
393+   char *res, *rescp;
394+   bool in_extension;
395+   
396+
397+   /* position begin at the begining of the basename
398+      end will point to the end of the basename
399+      without extension */
400+   in_extension = TRUE;
401+   
402+   while (begin > file && *begin != '/')
403+     {
404+       if (*begin == '.' && in_extension)
405+         {
406+           end = begin;
407+           in_extension = FALSE;
408+         }
409+       begin--;
410+     }
411+   if (*begin == '/')
412+     begin++;
413+
414+   res = xnew(strlen(begin) - strlen(end) + 1, char);
415+   rescp = res;
416+   while (begin != end)
417+     {
418+       *rescp++ = *begin++;
419+     }
420+   *rescp = '\0';
421+   return res;
422  }
423 
424  /* Return a newly allocated string containing the file name
Note: See TracBrowser for help on using the repository browser.