utils/getvar/getvar.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- main
1
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <fcntl.h>
5
6 #include <glib.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <stubs.h>
10 #include "ca_configFns.h"
11 #include "ca_dictionary.h"
12 #include "ca_macros.h"
13 #include "ca_srcAttribs.h"
14
15 int main (int argc, char** argv)
/* [<][>][^][v][top][bottom][index][help] */
16 {
17 /* Initialise the linked list of sources. */
18
19 ca_dbSource_t *source_hdl;
20 char *source_name, *config_name, *property;
21 int errflg;
22 int c;
23 extern int optind;
24 extern char *optarg;
25
26
27 errflg=0;
28 if(argc<2)errflg++;
29
30 while ((c = getopt(argc, argv, "s:c:p:?")) != EOF)
31 switch (c) {
32 case 's':
33 source_name = optarg;
34 break;
35
36 case 'c':
37 config_name = optarg;
38 break;
39
40 case 'p':
41 property = optarg;
42 break;
43
44 case '?':
45 default :
46 errflg++;
47 break;
48 }
49 if (errflg) {
50 fprintf(stderr,"usage: getvar -s <source> -c <configfile> -p <property>\n");
51 fprintf(stderr,"list of properties:\n\tdatabase\tdatabase name\n"
52 "\tdbhost\tsql server hostname\n"
53 "\tdbport\tsql server port\n"
54 "\tdbuser\tsql user name\n"
55 "\tdbpswd\tsql user password\n");
56 exit (2);
57 }
58
59
60 ca_init(config_name);
61
62 source_hdl = ca_get_SourceHandleByName(source_name);
63
64 if(source_hdl == NULL) exit(1);
65
66 if(strcasecmp(property, "dbname")==0){
67 printf("%s", ca_get_srcdbname(source_hdl)); exit(0);
68 } else
69 if(strcasecmp(property, "dbhost")==0){
70 printf("%s",ca_get_srcdbmachine(source_hdl)); exit(0);
71 } else
72 if(strcasecmp(property, "dbport")==0){
73 printf("%d",ca_get_srcdbport(source_hdl)); exit(0);
74 } else
75 if(strcasecmp(property, "dbuser")==0){
76 printf("%s",ca_get_srcdbuser(source_hdl)); exit(0);
77 } else
78 if(strcasecmp(property, "dbpswd")==0){
79 printf("%s",ca_get_srcdbpassword(source_hdl)); exit(0);
80 } else {
81 printf(""); exit(1);
82 }
83
84 }