[Anjuta-list] Symbol Name generation from file for autocomplete/calltip
- From: Biswapesh Chattopadhyay <biswapesh_chatterjee tcscal co in>
- To: anjuta-list lists sourceforge net
- Subject: [Anjuta-list] Symbol Name generation from file for autocomplete/calltip
- Date: Mon Sep 10 09:28:05 2001
Hi all
Working on a suggestion posted on the list, here is a function which takes
any C/C++ file name as input and extracts for each symbol the symbol name,
symbol type, file name, line number and the symbol definition. Tested on
Linux but should work on all *nix AFAICS. Takes two arguments, the name of
the file to analyze and the C and C++ flags to use with the pre-processor
(basically the same as the compiler flags). You need ctags installed.
int analyzeSymbols(const char *fileName, const char *cFlags)
{
char buf[BUFSIZ];
char symbol[255];
char type[20];
char file[255];
char line[10];
char def[BUFSIZ];
FILE *symbolList;
sprintf(buf, "cpp %s -MG -MM -H %s 2>&1 | grep \"^\\.\\.* \" | awk '{print
$2}' | sort -u | xargs ctags --filter -x --c++-types=+px", cFlags, fileName);
printf("%s\n", buf);
if (NULL == (symbolList = popen(buf, "r")))
exit(1);
while (4 == fscanf(symbolList, "%s %s %s %s", symbol, type, file, line))
{
fgets(def, BUFSIZ, symbolList);
def[strlen(def) -1] = '\0';
printf("%s (%s at %s %s): %s\n", symbol, type, file, line, def);
}
fclose(symbolList);
return 0;
}
CAVEAT: This is currently a bit slow (~ .6 secs per file - doesn't seem to
vary too much with size), probably because it uses a lot of piped UNIX utils,
namely, grep, sort, xargs and awk. Probably can be made much faster if
written in plain C.
Hope this helps.
- Biswa.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]