Re: [Anjuta-list] Symbol Name generation from file for autocomplete/calltip



On 11 Sep 2001 17:06:38 +0530, Biswapesh Chattopadhyay wrote:
> 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.

Thanks it's really intutive, but will you please care to look in the
file src/tags_manager.c [tags_manager_update_using_ctags() or similar
function]? The function I wrote was quite fast (around 0.5 secs for each
file or lesser).

--

Regards,
-Naba

-------------------------------------------------------------
We do not colonize.  We conquer.  We rule.  There is no other way for
us.
		-- Rojan, "By Any Other Name", stardate 4657.5
-------------------------------------------------------------



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]