aboutsummaryrefslogtreecommitdiff
path: root/vendor/voclient/libvoclient/examples/registry3.c
blob: ed9fd63e2faad01a1704de59bee015f0d613a1ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/************************************************************************
 *   Simple test program of a Registry query using the high-level procedure
 *   voc_regSearchByService() to do the search.
 *
 *   Usage:    registry3 [-flags] [keyword_list]
 *
 *   Or call with no args for the built-in unit test.  The '-o' flag says
 *   to logically OR the keywords
 *
 *   Examples:
 *
 *	registry3 -siap   		// List all SIAP services
 *	registry3 -cone cool stars	// keyword search on Cone services
 *	registry3 cool stars		// keyword search on all resources
 *
 *
 *   M. Fitzpatrick, NOAO, July 2006
 */


#include <stdio.h>
#include <stdlib.h>
#include "VOClient.h"


#define	ANY	-1
#define	CONE	0
#define SIAP	1
#define TABULAR	2


char    *keywords = "cool stars\0";		/* default search terms	*/
int	orValues = 0;
int	svc_type = ANY;


static void callRegistry (char *keywords, int orValues, int type);



int main (int argc, char *argv[])
{
    /* Process command line arguments.
     */
    if (argc <= 1) {
        callRegistry (keywords, orValues, svc_type); 	/* use defaults	*/
        return (0);

    } else if (argc >= 2) {
	int   arg = 1;
	char  keyw[1024];
    
	bzero (keyw, 1024);
	while (arg < argc) {
	    if (strncmp (argv[arg], "-any", 2) == 0)
		svc_type = ANY;
	    else if (strncmp (argv[arg], "-cone", 2) == 0)
		svc_type = CONE;
	    else if (strncmp (argv[arg], "-siap", 2) == 0)
		svc_type = SIAP;
	    else if (strncmp (argv[arg], "-tabular", 2) == 0)
		svc_type = TABULAR;
	    else if (strncmp (argv[arg], "-or", 2) == 0)
	        orValues = 1;
	    else {
	        strcat (keyw, argv[arg]); 
	        if (arg < (argc-1)) strcat (keyw, " ");
	    }
	    arg++;
	}
    
       /* Now call the SIAP Service and summarize the results.
        */
	callRegistry (keyw, orValues, svc_type);
    }

    return (0);
}


/*  Simple procedure to test a Registry query and print some results.
 */
static void
callRegistry (char *keywords, int orValues, int type)
{
    int  i, nresources = -1;
    char *rtype, *title, *sname, *clev;
    char *svc = 
	(type == CONE ?  "cone" :
          (type == SIAP ?  "siap" :
            (type == TABULAR ?  "tabular" : NULL)
	  ) 
	);


    /* Initialize the VO Client interface.
     */
    if (voc_initVOClient ("") == ERR) 
        return;

    printf ("#\n# Search words:  '%s'\n", keywords);
    printf ("# Service Type:  '%s'\n#\n", svc);

    /* Do the search.
     */
    RegResult res = voc_regSearchByService (svc, keywords, orValues);

    /* Summarize the results.
     */
    nresources = voc_resGetCount (res);
    printf ("#\n#Found %d matching records\n#\n\n", nresources);

    for (i = 0; i < nresources; i++) {
	title  = voc_resGetStr (res, "Title", i);
	rtype  = voc_resGetStr (res, "ServiceType", i);
	sname  = voc_resGetStr (res, "ShortName", i);
	clev   = voc_resGetStr (res, "ContentLevel", i);

	printf ("----------------------------------------------------------\n");
	printf ("(%d of %d) %s\n", i+1, nresources, title);
	printf ("ShortName:  %-30.30s\tResType:  %s\n", sname, rtype);
	printf ("ContentLevel: %s\n\n", (clev ? clev : "none provided"));

	/* Free the pointers returned. */
	if (title) free ((char *)title);
	if (rtype) free ((char *)rtype);
	if (sname) free ((char *)sname);
	if (clev)  free ((char *)clev);
    }

    voc_closeVOClient (0);		/* shutdown	*/
}