11 #define LIBCTAGS_DEFINED
12 #include "tm_work_object.h"
14 #include "tm_source_file.h"
19 guint source_file_class_id
= 0;
20 static TMSourceFile
*current_source_file
= NULL
;
23 int tm_source_file_tags(const tagEntryInfo
*tag
)
25 if (NULL
== current_source_file
)
27 if (NULL
== current_source_file
->work_object
.tags_array
)
28 current_source_file
->work_object
.tags_array
= g_ptr_array_new();
29 g_ptr_array_add(current_source_file
->work_object
.tags_array
,
30 tm_tag_new(current_source_file
, tag
));
32 // g_message ("adding new tag: %s", tag->name);
38 static gboolean
tm_buffer_parse(TMSourceFile
*source_file
, unsigned char* buf
, int buf_size
)
40 const char *file_name
;
41 gboolean status
= TRUE
;
43 if ((NULL
== source_file
) || (NULL
== source_file
->work_object
.file_name
))
45 g_warning("Attempt to parse NULL file");
50 g_message("Parsing %s", source_file
->work_object
.file_name
);
52 file_name
= source_file
->work_object
.file_name
;
53 if (NULL
== LanguageTable
)
56 installLanguageMapDefaults();
57 if (NULL
== TagEntryFunction
)
58 TagEntryFunction
= tm_source_file_tags
;
60 current_source_file
= source_file
;
61 if (LANG_AUTO
== source_file
->lang
)
62 source_file
->lang
= getFileLanguage (file_name
);
63 if (source_file
->lang
== LANG_IGNORE
)
66 g_warning("ignoring %s (unknown language)\n", file_name
);
69 else if (! LanguageTable
[source_file
->lang
]->enabled
)
72 g_warning("ignoring %s (language disabled)\n", file_name
);
78 while ((TRUE
== status
) && (passCount
< 3))
80 if (source_file
->work_object
.tags_array
)
81 tm_tags_array_free(source_file
->work_object
.tags_array
, FALSE
);
82 if (bufferOpen (buf
, buf_size
, file_name
, source_file
->lang
))
84 if (LanguageTable
[source_file
->lang
]->parser
!= NULL
) {
85 LanguageTable
[source_file
->lang
]->parser ();
87 else if (LanguageTable
[source_file
->lang
]->parser2
!= NULL
) {
88 status
= LanguageTable
[source_file
->lang
]->parser2 (passCount
);
90 g_message ("closing buffer");
95 g_warning("Unable to open %s", file_name
);
107 int main (int argc
, char** argv
) {
109 TMWorkObject
*source_file_wo
;
115 g_message ("usage: %s <file.c>", argv
[0]);
119 source_file_wo
= tm_source_file_new (argv
[1], FALSE
);
121 if ( (fp
= fopen (argv
[1], "rb")) == NULL
) {
122 g_message ("cannot open file for buffering...");
126 fseek (fp
, 0, SEEK_END
);
127 file_size
= (int)ftell (fp
);
129 fseek (fp
, 0, SEEK_SET
);
131 buf
= (unsigned char*)calloc (file_size
+ 1, sizeof(unsigned char));
133 memset( buf
, 0, file_size
+1 );
135 fread (buf
, file_size
, sizeof(unsigned char), fp
);
139 g_message ("file size is %d, buf %s", file_size
, buf
);
140 tm_buffer_parse (TM_SOURCE_FILE(source_file_wo
), buf
, file_size
);
143 if (source_file_wo
->tags_array
== NULL
) {
144 g_message ("no tags identified");
147 g_message ("total tags discovered: %d", source_file_wo
->tags_array
->len
);
149 /* gonna list the tags, just a test */
150 for (i
=0; i
< source_file_wo
->tags_array
->len
; i
++) {
153 tag
= (TMTag
*)g_ptr_array_index(source_file_wo
->tags_array
, i
);
154 g_message ("tag %d is: %s", i
, tag
->name
);