Fix font rendering in the Scintilla when using Cairo
[geany-mirror.git] / tagmanager / matlab.c
blob49d6d89dfc2617e49a56ad09f8c1779ffcb87905
1 /*
3 * Copyright (c) 2000-2001, Darren Hiebert
5 * This source code is released for free distribution under the terms of the
6 * GNU General Public License.
8 * This module contains functions for generating tags for Matlab scripts.
9 * The tags 'function' and 'struct' are parsed.
10 * Author Roland Baudin <roland65@free.fr>
14 * INCLUDE FILES
16 #include "general.h" /* must always come first */
18 #include <string.h>
20 #include "parse.h"
21 #include "read.h"
22 #include "vstring.h"
25 * DATA DEFINITIONS
27 typedef enum {
28 K_FUNCTION,
29 K_STRUCT
30 } MatlabKind;
32 static kindOption MatlabKinds [] = {
33 { TRUE, 'f', "function", "Functions" },
34 { TRUE, 's', "struct", "Structures" },
38 * FUNCTION DEFINITIONS
41 static void findMatlabTags (void)
43 vString *name = vStringNew ();
44 const unsigned char *line;
45 const unsigned char *p;
47 while ((line = fileReadLine ()) != NULL)
49 int i, ic;
51 if (line [0] == '\0' || line [0] == '%')
52 continue;
54 /* search if the line has a comment */
55 for (ic = 0 ; line [ic] != '\0' && line [ic]!='%' ; ++ic)
58 /* function tag */
60 /* read first word */
61 for (i = 0 ; line [i] != '\0' && ! isspace (line [i]) ; ++i)
64 if (strncmp ((const char *) line, "function", (size_t) 8) == 0)
66 const unsigned char *cp = line + i;
67 const unsigned char *ptr = cp;
68 boolean eq=FALSE;
70 while (isspace ((int) *cp))
71 ++cp;
73 /* search for '=' character in the line */
74 while (*ptr != '\0')
76 if (*ptr == '=')
78 eq=TRUE;
79 break;
81 ptr++;
84 /* '=' was found => get the right most part of the line after '=' and before '%' */
85 if (eq)
87 ptr++;
88 while (isspace ((int) *ptr))
89 ++ptr;
91 while (*ptr != '\0' && *ptr != '%')
93 vStringPut (name, (int) *ptr);
94 ++ptr;
98 /* '=' was not found => get the right most part of the line after
99 * 'function' and before '%' */
100 else
102 while (*cp != '\0' && *cp != '%')
104 vStringPut (name, (int) *cp);
105 ++cp;
109 vStringTerminate (name);
110 makeSimpleTag (name, MatlabKinds, K_FUNCTION);
111 vStringClear (name);
114 /* struct tag */
116 /* search if the line contains the keyword 'struct' */
117 p=(const unsigned char*) strstr ((const char*) line, "struct");
119 /* and avoid the part after the '%' if any */
120 if ( p != NULL && ic>0 && p < line+ic)
122 const unsigned char *cp = line;
124 /* get the left most part of the line before '=' */
125 while (*cp != '\0' && !isspace(*cp) && *cp != '=' )
127 vStringPut (name, (int) *cp);
128 ++cp;
131 vStringTerminate (name);
132 makeSimpleTag (name, MatlabKinds, K_STRUCT);
133 vStringClear (name);
136 vStringDelete (name);
139 extern parserDefinition* MatlabParser (void)
141 static const char *const extensions [] = { "m", NULL };
142 parserDefinition* def = parserNew ("Matlab");
143 def->kinds = MatlabKinds;
144 def->kindCount = KIND_COUNT (MatlabKinds);
145 def->extensions = extensions;
146 def->parser = findMatlabTags;
147 return def;
150 /* vi:set tabstop=8 shiftwidth=4: */