1 // test the readtags library
2 
3 #include "readtags.h"
4 
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 
9 static int extensionFields;
10 
printTag(const tagEntry * entry)11 static void printTag (const tagEntry *entry)
12 {
13     int i;
14     int first = 1;
15     const char* separator = ";\"";
16     const char* const empty = "";
17 /* "sep" returns a value only the first time it is evaluated */
18 #define sep (first ? (first = 0, separator) : empty)
19     printf ("%s\t%s\t%s",
20 	entry->name, entry->file, entry->address.pattern);
21     if (extensionFields)
22     {
23 	if (entry->kind != NULL  &&  entry->kind [0] != '\0')
24 	    printf ("%s\tkind:%s", sep, entry->kind);
25 	if (entry->fileScope)
26 	    printf ("%s\tfile:", sep);
27 	for (i = 0  ;  i < entry->fields.count  ;  ++i)
28 	    printf ("%s\t%s:%s", sep, entry->fields.list [i].key,
29 		entry->fields.list [i].value);
30     }
31     putchar ('\n');
32 #undef sep
33 }
34 
listTags(const char * TagFileName)35 static void listTags (const char *TagFileName)
36 {
37     tagFileInfo info;
38     tagEntry entry;
39     tagFile *const file = tagsOpen (TagFileName, &info);
40     if (file == NULL)
41     {
42 	fprintf (stderr, "%s: cannot open tag file: %s: %s\n",
43 		"test_readtags", strerror (info.status.error_number), TagFileName);
44 	exit (1);
45     }
46     else
47     {
48 	while (tagsNext (file, &entry) == TagSuccess)
49 	    printTag (&entry);
50 	tagsClose (file);
51     }
52 }
53 
54 int
main()55 main()
56 {
57   listTags("mytags");
58 
59   return 0;
60 }
61 
62