]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/ctags/fortran.c
login(1): when exporting variables check the result of setenv(3)
[FreeBSD/FreeBSD.git] / usr.bin / ctags / fortran.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1987, 1993, 1994
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31
32 #if 0
33 #ifndef lint
34 static char sccsid[] = "@(#)fortran.c   8.3 (Berkeley) 4/2/94";
35 #endif
36 #endif
37
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
40
41 #include <ctype.h>
42 #include <limits.h>
43 #include <stdio.h>
44 #include <string.h>
45
46 #include "ctags.h"
47
48 static void takeprec(void);
49
50 char *lbp;                              /* line buffer pointer */
51
52 int
53 PF_funcs(void)
54 {
55         bool    pfcnt;                  /* pascal/fortran functions found */
56         char    *cp;
57         char    tok[MAXTOKEN];
58
59         for (pfcnt = NO;;) {
60                 lineftell = ftell(inf);
61                 if (!fgets(lbuf, sizeof(lbuf), inf))
62                         return (pfcnt);
63                 ++lineno;
64                 lbp = lbuf;
65                 if (*lbp == '%')        /* Ratfor escape to fortran */
66                         ++lbp;
67                 for (; isspace(*lbp); ++lbp)
68                         continue;
69                 if (!*lbp)
70                         continue;
71                 switch (*lbp | ' ') {   /* convert to lower-case */
72                 case 'c':
73                         if (cicmp("complex") || cicmp("character"))
74                                 takeprec();
75                         break;
76                 case 'd':
77                         if (cicmp("double")) {
78                                 for (; isspace(*lbp); ++lbp)
79                                         continue;
80                                 if (!*lbp)
81                                         continue;
82                                 if (cicmp("precision"))
83                                         break;
84                                 continue;
85                         }
86                         break;
87                 case 'i':
88                         if (cicmp("integer"))
89                                 takeprec();
90                         break;
91                 case 'l':
92                         if (cicmp("logical"))
93                                 takeprec();
94                         break;
95                 case 'r':
96                         if (cicmp("real"))
97                                 takeprec();
98                         break;
99                 }
100                 for (; isspace(*lbp); ++lbp)
101                         continue;
102                 if (!*lbp)
103                         continue;
104                 switch (*lbp | ' ') {
105                 case 'f':
106                         if (cicmp("function"))
107                                 break;
108                         continue;
109                 case 'p':
110                         if (cicmp("program") || cicmp("procedure"))
111                                 break;
112                         continue;
113                 case 's':
114                         if (cicmp("subroutine"))
115                                 break;
116                 default:
117                         continue;
118                 }
119                 for (; isspace(*lbp); ++lbp)
120                         continue;
121                 if (!*lbp)
122                         continue;
123                 for (cp = lbp + 1; *cp && intoken(*cp); ++cp)
124                         continue;
125                 if (cp == lbp + 1)
126                         continue;
127                 *cp = EOS;
128                 (void)strlcpy(tok, lbp, sizeof(tok));   /* possible trunc */
129                 get_line();                     /* process line for ex(1) */
130                 pfnote(tok, lineno);
131                 pfcnt = YES;
132         }
133         /*NOTREACHED*/
134 }
135
136 /*
137  * cicmp --
138  *      do case-independent strcmp
139  */
140 int
141 cicmp(const char *cp)
142 {
143         int     len;
144         char    *bp;
145
146         for (len = 0, bp = lbp; *cp && (*cp &~ ' ') == (*bp++ &~ ' ');
147             ++cp, ++len)
148                 continue;
149         if (!*cp) {
150                 lbp += len;
151                 return (YES);
152         }
153         return (NO);
154 }
155
156 static void
157 takeprec(void)
158 {
159         for (; isspace(*lbp); ++lbp)
160                 continue;
161         if (*lbp == '*') {
162                 for (++lbp; isspace(*lbp); ++lbp)
163                         continue;
164                 if (!isdigit(*lbp))
165                         --lbp;                  /* force failure */
166                 else
167                         while (isdigit(*++lbp))
168                                 continue;
169         }
170 }