1
/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* $Id: doc.c,v 1.1.1.1 2006/03/27 12:40:19 exodusd Exp $
23
#define MODE_RETURNTYPE 2
24
#define MODE_COMMENT 1
25
#define MODE_NOCOMMENT 0
26
#define MODE_NOTHING -1
28
struct ParameterDesc {
30
struct ParameterDesc* next;
35
struct ParameterDesc* params;
43
* @author Thomas Bopp (astra@upb.de)
47
parse_header(char* fname, char* synopsis, char* keywords,
48
char* header, int len, struct svalue* callback)
50
int begin, i, j, args;
52
struct mapping* doc_map;
58
struct svalue skey, sval, sarr;
62
description = _MALLOC(len);
63
description[0] = '\0';
64
/* first parse the function description */
66
while ( i < len && header[i] != '@' ) {
67
if ( header[i] != '*' )
68
description[j++] = header[i];
70
description[j++] = ' ';
73
while ( j > 0 && description[j] != '\n' ) j--;
74
description[j] = '\0';
76
push_svalue(callback);
80
push_text(description);
85
doc_map = allocate_mapping(10);
91
if ( strncmp(&header[i], " @", 2) == 0 ||
92
strncmp(&header[i], "\t@",2) == 0 )
98
((header[j] >= 'a' && header[j] <= 'z') ||
99
(header[j] >= 'A' && header[j] <= 'Z') ) )
101
name = create_string(name, &header[i+1], (j-i));
102
skey.u.string = make_shared_string(name);
103
skey.type = T_STRING;
105
while ( i < len && (header[i] != '@' || !nl) &&
106
strncmp(&header[i], "*/",2) != 0 )
108
if ( header[i] == '\n' ) nl = 1;
109
if ( header[i] == '*' ) header[i] = ' ';
113
res = simple_mapping_string_lookup(doc_map, name);
114
value = create_string_strip_spaces(NULL, &header[j], i-j);
115
//fprintf(stderr, "Found argument to function %s,%s:%s\n",
116
//fname, name, value);
119
if ( res->type == T_ARRAY ) {
121
arr = resize_array(arr, arr->size+1);
122
arr = array_insert(arr, &sval, arr->size-1);
125
arr = allocate_array(2);
126
params = malloc(res->u.string->len+1);
130
params[res->u.string->len] = '\0';
131
sval.u.string = make_shared_string(params);
132
arr = array_insert(arr, &sval, 0);
133
free_string(sval.u.string);
135
sval.u.string = make_shared_string(value);
136
sval.type = T_STRING;
137
arr = array_insert(arr, &sval, 1);
138
free_string(sval.u.string);
142
mapping_insert(doc_map, &skey, &sarr);
145
sval.u.string = make_shared_string(value);
146
sval.type = T_STRING;
147
mapping_insert(doc_map, &skey, &sval);
148
free_string(sval.u.string);
150
free_string(skey.u.string);
155
push_mapping(doc_map);
166
parse_doc(char* source, struct svalue* callback)
168
int begin, i, len, end;
169
int mode = MODE_NOTHING;
174
char* keyw[11] ={"void","array","string","object","float","int","mixed","mapping", "bool","function","program"};
176
len = strlen(source);
180
if ( mode == MODE_NOCOMMENT || mode == MODE_NOTHING ) {
181
if ( strncmp(&source[i], "/**", 3) == 0 &&
182
strncmp(&source[i], "/**/", 4) != 0 )
188
else if ( mode == MODE_COMMENT )
190
if ( strncmp(&source[i], "*/", 2) == 0 ) {
191
int brackets, keyword_start;
195
while ( i < len && mode != MODE_RETURNTYPE ) {
198
for ( j = 0; j < 11; j++ ) {
199
if ( strncmp(&source[i], keyw[j], strlen(keyw[j]))==0 )
200
mode = MODE_RETURNTYPE;
204
/* goto first space after function types and return value */
206
while ( i < len && (brackets != 0 ||
207
(source[i] != ' ' && source[i] != '\n')) ) {
208
if ( source[i] == '(' ) brackets++;
209
else if ( source[i] == ')' ) brackets--;
212
while ( i < len && source[i] != '(' )
214
if ( !( (source[i] >= 'a' && source[i] <='z') ||
215
(source[i] >= 'A' && source[i] <= 'Z') ||
216
(source[i] == '_')) )
220
f_keywords = (char*)create_string(NULL, &source[end+3],
223
create_string(NULL, &source[f_begin+1], i-f_begin);
225
if ( strncmp(f_name, "ASSERTINFO", 10) == 0 ) {
227
"Error, assertinfo function found ?!\nContext:%s",
230
else if ( f_name[0] == '/' || f_name[1] == '/' ) {
232
"error: Wrong beginning of function?!\nContext:%s",
238
while ( i < len && brackets != 0 ) {
239
if ( source[i] == '(' ) brackets++;
240
if ( source[i] == ')' ) brackets--;
243
f_synopsis = (char*) create_string(NULL, &source[f_begin+1],
245
parse_header(f_name, f_synopsis, f_keywords,
246
&source[begin], end-begin, callback);
247
mode = MODE_NOCOMMENT;
256
f_parse_functions(INT32 args)
261
get_all_args("parse_functions", args, "%s%*", &buf, &f);
270
add_function("parse_functions", f_parse_functions,
271
"function(string,function:void)", 0);