aboutsummaryrefslogtreecommitdiff
path: root/src/util/profile/test_profile.c
blob: 19edbaf3f616916e40c931253b660ed339c489df (plain)
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
/*
 * test_profile.c --- testing program for the profile routine
 */

#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include "profile.h"
#ifndef _MSDOS
#include "com_err.h"
#else

/* Stubs for the error handling routines */
#include "prof_int.h"
void initialize_prof_error_table() {}
void com_err (char *fmt, long err, char *msg) {
    printf (fmt, err, msg);
}
#endif

const char *program_name = "test_profile";

int main(argc, argv)
    int		argc;
    char	**argv;
{
    profile_t	profile;
    long	retval;
    char	**values, **cpp;
    const char	**names;
    char	*cmd;
    
    if (argc < 3) {
	    fprintf(stderr, "Usage: %s filename cmd argset\n", program_name);
	    exit(1);
    }

    initialize_prof_error_table();
    
    retval = profile_init_path(argv[1], &profile);
    if (retval) {
	com_err(program_name, retval, "while initializing profile");
	exit(1);
    }
    cmd = *(argv+2);
    names = (const char **) argv+3;
    if (!strcmp(cmd, "query")) {
	    retval = profile_get_values(profile, names, &values);
    } else if (!strcmp(cmd, "list_sections")) {
	    retval = profile_get_subsection_names(profile, names, &values);
    } else if (!strcmp(cmd, "list_relations")) {
	    retval = profile_get_relation_names(profile, names, &values);
    } else {
	    fprintf(stderr, "Invalid command.\n");
	    exit(1);
    }
    if (retval) {
	    com_err(argv[0], retval, "while getting values");
	    exit(1);
    }
    for (cpp = values; *cpp; cpp++) {
	printf("%s\n", *cpp);
	free(*cpp);
    }
    free(values);
    profile_release(profile);

    return 0;
}