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 | |
---|
16 | main(argc, argv) |
---|
17 | char *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 | |
---|
40 | shellenv(hp, bourneshell, version) |
---|
41 | char **hp; |
---|
42 | int bourneshell; |
---|
43 | char *version; |
---|
44 | { |
---|
45 | char var[80], val[80], vers[80], **hp_save=hp; |
---|
46 | int specific = 0; |
---|
47 | |
---|
48 | while (specific < 2) { |
---|
49 | if (bourneshell) { |
---|
50 | while(*hp) { |
---|
51 | vers[0] = '\0'; |
---|
52 | sscanf(*hp++, "%s %s %s", var, val, vers); |
---|
53 | if ((specific && !vers[0]) || |
---|
54 | (!specific && vers[0]) || |
---|
55 | (vers[0] != '\0' && strcmp(vers, version))) |
---|
56 | continue; |
---|
57 | upper(var); |
---|
58 | printf("%s=%s ; export %s\n", var, val, var); |
---|
59 | } |
---|
60 | } else |
---|
61 | while(*hp) { |
---|
62 | vers[0] = '\0'; |
---|
63 | sscanf(*hp++, "%s %s %s", var, val, vers); |
---|
64 | if ((specific && !vers[0]) || |
---|
65 | (!specific && vers[0]) || |
---|
66 | (vers[0] != '\0' && strcmp(vers, version))) |
---|
67 | continue; |
---|
68 | upper(var); |
---|
69 | printf("setenv %s %s\n", var, val); |
---|
70 | } |
---|
71 | specific++; |
---|
72 | hp = hp_save; |
---|
73 | } |
---|
74 | if (ferror(stdout)) { |
---|
75 | ftruncate(fileno(stdout), 0L); |
---|
76 | exit(-1); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | upper(v) |
---|
81 | register char *v; |
---|
82 | { |
---|
83 | while(*v) { |
---|
84 | *v = toupper(*v); |
---|
85 | v++; |
---|
86 | } |
---|
87 | } |
---|