Debian Codegraph @

lisp.c

raw
1 /*
2 * $Id: lisp.c 717 2009-07-07 03:40:50Z dhiebert $
3 *
4 * Copyright (c) 2000-2002, Darren Hiebert
5 *
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
8 *
9 * This module contains functions for generating tags for LISP files.
10 */
11
12 /*
13 * INCLUDE FILES
14 */
15 #include "general.h" /* must always come first */
16
17 #include "parse.h"
18 #include "read.h"
19 #include "vstring.h"
20
21 /*
22 * DATA DEFINITIONS
23 */
24 typedef enum {
25 K_FUNCTION
26 } lispKind;
27
28 static kindOption LispKinds [] = {
29 { TRUE, 'f', "function", "functions" }
30 };
31
32 /*
33 * FUNCTION DEFINITIONS
34 */
35
36 /*
37 * lisp tag functions
38 * look for (def or (DEF, quote or QUOTE
39 */
40 static int L_isdef (const unsigned char *strp)
41 {
42 return ( (strp [1] == 'd' || strp [1] == 'D')
43 && (strp [2] == 'e' || strp [2] == 'E')
44 && (strp [3] == 'f' || strp [3] == 'F'));
45 }
46
47 static int L_isquote (const unsigned char *strp)
48 {
49 return ( (*(++strp) == 'q' || *strp == 'Q')
50 && (*(++strp) == 'u' || *strp == 'U')
51 && (*(++strp) == 'o' || *strp == 'O')
52 && (*(++strp) == 't' || *strp == 'T')
53 && (*(++strp) == 'e' || *strp == 'E')
54 && isspace (*(++strp)));
55 }
56
57 static void L_getit (vString *const name, const unsigned char *dbp)
58 {
59 const unsigned char *p;
60
61 if (*dbp == '\'') /* Skip prefix quote */
62 dbp++;
63 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */
64 {
65 dbp += 7;
66 while (isspace (*dbp))
67 dbp++;
68 }
69 for (p=dbp ; *p!='\0' && *p!='(' && !isspace ((int) *p) && *p!=')' ; p++)
70 vStringPut (name, *p);
71 vStringTerminate (name);
72
73 if (vStringLength (name) > 0)
74 makeSimpleTag (name, LispKinds, K_FUNCTION);
75 vStringClear (name);
76 }
77
78 /* Algorithm adapted from from GNU etags.
79 */
80 static void findLispTags (void)
81 {
82 vString *name = vStringNew ();
83 const unsigned char* p;
84
85
86 while ((p = fileReadLine ()) != NULL)
87 {
88 if (*p == '(')
89 {
90 if (L_isdef (p))
91 {
92 while (*p != '\0' && !isspace ((int) *p))
93 p++;
94 while (isspace ((int) *p))
95 p++;
96 L_getit (name, p);
97 }
98 else
99 {
100 /* Check for (foo::defmumble name-defined ... */
101 do
102 p++;
103 while (*p != '\0' && !isspace ((int) *p)
104 && *p != ':' && *p != '(' && *p != ')');
105 if (*p == ':')
106 {
107 do
108 p++;
109 while (*p == ':');
110
111 if (L_isdef (p - 1))
112 {
113 while (*p != '\0' && !isspace ((int) *p))
114 p++;
115 while (isspace (*p))
116 p++;
117 L_getit (name, p);
118 }
119 }
120 }
121 }
122 }
123 vStringDelete (name);
124 }
125
126 extern parserDefinition* LispParser (void)
127 {
128 static const char *const extensions [] = {
129 "cl", "clisp", "el", "l", "lisp", "lsp", NULL
130 };
131 parserDefinition* def = parserNew ("Lisp");
132 def->kinds = LispKinds;
133 def->kindCount = KIND_COUNT (LispKinds);
134 def->extensions = extensions;
135 def->parser = findLispTags;
136 return def;
137 }
138
139 /* vi:set tabstop=4 shiftwidth=4: */