1 /*
2  * (c) Oleg Puchinin 2010
3  * graycardinalster@gmail.com
4  *
5  */
6 
7 #include <head.h>
8 
print_lua_tag(char * f_name,int lnum,char * line,FILE * of)9 void print_lua_tag (char * f_name, int lnum, char * line, FILE *of)
10 {
11 	char *S;
12 	char *S2;
13 	strip(line);
14 
15 	if (strncmp (line, "function", 8))
16 		return;
17 	if ((line[8] != ' ') && (line[8] != '\t'))
18 		return;
19 	S = strchr (line, '(');
20 	if (! S)
21 		return;
22 
23 	*S = '\0';
24 	S = &line[8];
25 	strip (S);
26 	strip2 (S);
27 
28 	S2 = strchr (S, '.');
29 	if (S2)
30 		S = S2+1;
31 	if (!strlen (S))
32 		return;
33 
34 	fprintf (of, "%s\t%s\t%d\t; %c\n", S, f_name, lnum, 'f');
35 }
36 
lua_ctags(char * f_name,FILE * of)37 int lua_ctags (char * f_name, FILE *of)
38 {
39 	FILE * myfile;
40 	char * buf;
41 	int line = 0;
42 
43 	myfile = fopen (f_name, "r");
44 	if (! myfile)
45 		return -1;
46 
47 	buf = CNEW (char, 4096);
48 	while (fgets (buf, 4096, myfile)) {
49 		++line;
50 		if (strstr (buf, "function"))
51 			print_lua_tag (f_name, line, buf, of);
52 	}
53 
54 	fclose (myfile);
55 	DROP (buf);
56 
57 	return 0;
58 }
59 
60