
/*
   $Log: genlist.c,v $
   Revision 1.5  2003/09/08 15:06:03  clip
   uri: next step fixes for mingw from uri

   Revision 1.4  2003/07/03 07:15:56  clip
   fix a lot of warnings
   paul

   Revision 1.3  2000/05/24 18:34:26  clip
   _clip_push_area
   indents all
   Paul Lasarev <paul@itk.ru>

   Revision 1.2  1999/10/26 19:11:29  paul
   start cvs logging

 */

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

int
main(int argc, char **argv)
{
	char buf[4096];
	char word1[80], word2[80], word3[80];
	int i;
	FILE *in;
	time_t tbuf;

	if (argc < 1)
		return 0;

	strcpy(buf, "nm");
	for (i = 1; i < argc; i++)
	{
		strcat(buf, " ");
		strcat(buf, argv[i]);
	}

	in = popen(buf, "r");

	if (!in)
	{
		perror("genlist");
		exit(2);
	}

	printf("/*\n");
	printf(" *\tautomatically generated by 'genlist'\n");
	time(&tbuf);
	printf(" *\tat %s", ctime(&tbuf));
	printf(" *\tfrom sources:\n");
	for (i = 1; i < argc; ++i)
		printf(" *\t%s\n", argv[i]);
	printf(" */\n");

	printf("\n#include \"clip.h\"\n\n");

	printf("struct ClipNameEntry _cfunctions[]=\n{\n");
	while (fgets(buf, sizeof(buf), in) != NULL)
	{
		char *s;
		int n = sscanf(buf, "%s %s %s", word1, word2, word3);

		if (n < 3)
			continue;
		if (strcmp(word2, "T"))
			continue;
		for (s = word3; *s; ++s)
			if (!isupper(*s) && !isdigit(*s) && *s != '_')
				goto next;

		printf("\t{ %s, \"%s\" },\n", word3, word3);
	      next:
		;
	}
	printf("\t{ 0, 0 }\n");
	printf("};\n\n");

	pclose(in);
	return 0;
}
