source: trunk/athena/bin/getcluster/getcluster.c @ 749

Revision 749, 1.5 KB checked in by treese, 37 years ago (diff)
Added version-handling.
Line 
1#include <stdio.h>
2#include <ctype.h>
3#include <hesiod.h>
4
5/*
6 * Make a hesiod cluster query
7 * for the machine you are on
8 * and produce a set of environment variable
9 * assignments for the C shell or the Bourne shell,
10 * depending on the '-b' flag
11 *
12 * If any stdio errors, truncate standard output to 0
13 * and return an exit status.
14 */
15
16main(argc, argv)
17char *argv[];
18{
19        register char **hp;
20        int bourneshell = 0;
21        char myself[80];
22
23        if (argc < 3 || argc > 4) {
24                fprintf(stderr, "usage: getcluster [-b] hostname version\n");
25                exit(-1);
26        }
27        if (argc == 4 && strcmp(argv[1], "-b") == 0) {
28                bourneshell++;
29                argv++;
30        }
31       
32        hp = hes_resolve(argv[1], "cluster");
33        if (hp == NULL) {
34                fprintf(stderr, "No Hesiod information available for %s\n", argv[1]);
35                exit(-1);
36        }
37        shellenv(hp, bourneshell, argv[2]);
38}
39
40shellenv(hp, bourneshell, version)
41char **hp;
42int bourneshell;
43char *version;
44{
45        char var[80], val[80], vers[80];
46
47        if (bourneshell) {
48                while(*hp) {
49                        vers[0] = '\0';
50                        sscanf(*hp++, "%s %s %s", var, val, vers);
51                        if (vers[0] != '\0' && strcmp(vers, version))
52                                continue;
53                        upper(var);
54                        printf("%s=%s ; export %s\n", var, val, var);
55                }
56        } else
57                while(*hp) {
58                        vers[0] = '\0';
59                        sscanf(*hp++, "%s %s %s", var, val, vers);
60                        if (vers[0] != '\0' && strcmp(vers, version))
61                                continue;
62                        upper(var);
63                        printf("setenv %s %s\n", var, val);
64                }
65        if (ferror(stdout)) {
66                ftruncate(fileno(stdout), 0L);
67                exit(-1);
68        }
69}
70
71upper(v)
72register char *v;
73{
74        while(*v) {
75                *v = toupper(*v);
76                v++;
77        }
78}
Note: See TracBrowser for help on using the repository browser.