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>
16 #include "general.h" /* must always come first */
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
)
51 if (line
[0] == '\0' || line
[0] == '%')
54 /* search if the line has a comment */
55 for (ic
= 0 ; line
[ic
] != '\0' && line
[ic
]!='%' ; ++ic
)
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
;
70 while (isspace ((int) *cp
))
73 /* search for '=' character in the line */
84 /* '=' was found => get the right most part of the line after '=' and before '%' */
88 while (isspace ((int) *ptr
))
91 while (*ptr
!= '\0' && *ptr
!= '%')
93 vStringPut (name
, (int) *ptr
);
98 /* '=' was not found => get the right most part of the line after
99 * 'function' and before '%' */
102 while (*cp
!= '\0' && *cp
!= '%')
104 vStringPut (name
, (int) *cp
);
109 vStringTerminate (name
);
110 makeSimpleTag (name
, MatlabKinds
, K_FUNCTION
);
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
);
131 vStringTerminate (name
);
132 makeSimpleTag (name
, MatlabKinds
, K_STRUCT
);
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
;
150 /* vi:set tabstop=8 shiftwidth=4: */