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 */
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
)
52 if (line
[0] == '\0' || line
[0] == '%')
55 /* search if the line has a comment */
56 for (ic
= 0 ; line
[ic
] != '\0' && line
[ic
]!='%' ; ++ic
)
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
;
71 while (isspace ((int) *cp
))
74 /* search for '=' character in the line */
85 /* '=' was found => get the right most part of the line after '=' and before '%' */
89 while (isspace ((int) *ptr
))
92 while (*ptr
!= '\0' && *ptr
!= '%')
94 vStringPut (name
, (int) *ptr
);
99 /* '=' was not found => get the right most part of the line after
100 * 'function' and before '%' */
103 while (*cp
!= '\0' && *cp
!= '%')
105 vStringPut (name
, (int) *cp
);
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 makeSimpleTag (name
, MatlabKinds
, K_STRUCT
);
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
;