manual: added documentation about replacement of 'untitled.ext' with filename (#1804)
[geany-mirror.git] / ctags / parsers / matlab.c
bloba51fb14764389e6fc6b489003653034b0b294aa0
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 "routines.h"
22 #include "read.h"
23 #include "vstring.h"
26 * DATA DEFINITIONS
28 typedef enum {
29 K_FUNCTION,
30 K_STRUCT
31 } MatlabKind;
33 static kindOption MatlabKinds [] = {
34 { true, 'f', "function", "Functions" },
35 { true, 's', "struct", "Structures" },
39 * FUNCTION DEFINITIONS
42 static void findMatlabTags (void)
44 vString *name = vStringNew ();
45 const unsigned char *line;
46 const unsigned char *p;
48 while ((line = readLineFromInputFile ()) != NULL)
50 int i, ic;
52 if (line [0] == '\0' || line [0] == '%')
53 continue;
55 /* search if the line has a comment */
56 for (ic = 0 ; line [ic] != '\0' && line [ic]!='%' ; ++ic)
59 /* function tag */
61 /* read first word */
62 for (i = 0 ; line [i] != '\0' && ! isspace (line [i]) ; ++i)
65 if (strncmp ((const char *) line, "function", (size_t) 8) == 0)
67 const unsigned char *cp = line + i;
68 const unsigned char *ptr = cp;
69 bool eq=false;
71 while (isspace ((int) *cp))
72 ++cp;
74 /* search for '=' character in the line */
75 while (*ptr != '\0')
77 if (*ptr == '=')
79 eq=true;
80 break;
82 ptr++;
85 /* '=' was found => get the right most part of the line after '=' and before '%' */
86 if (eq)
88 ptr++;
89 while (isspace ((int) *ptr))
90 ++ptr;
92 while (*ptr != '\0' && *ptr != '%')
94 vStringPut (name, (int) *ptr);
95 ++ptr;
99 /* '=' was not found => get the right most part of the line after
100 * 'function' and before '%' */
101 else
103 while (*cp != '\0' && *cp != '%')
105 vStringPut (name, (int) *cp);
106 ++cp;
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 makeSimpleTag (name, MatlabKinds, K_STRUCT);
132 vStringClear (name);
135 vStringDelete (name);
138 extern parserDefinition* MatlabParser (void)
140 static const char *const extensions [] = { "m", NULL };
141 parserDefinition* def = parserNew ("Matlab");
142 def->kinds = MatlabKinds;
143 def->kindCount = ARRAY_SIZE (MatlabKinds);
144 def->extensions = extensions;
145 def->parser = findMatlabTags;
146 return def;