[649] | 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 | |
---|
[749] | 23 | if (argc < 3 || argc > 4) { |
---|
| 24 | fprintf(stderr, "usage: getcluster [-b] hostname version\n"); |
---|
[649] | 25 | exit(-1); |
---|
| 26 | } |
---|
[749] | 27 | if (argc == 4 && strcmp(argv[1], "-b") == 0) { |
---|
| 28 | bourneshell++; |
---|
| 29 | argv++; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | hp = hes_resolve(argv[1], "cluster"); |
---|
[649] | 33 | if (hp == NULL) { |
---|
[749] | 34 | fprintf(stderr, "No Hesiod information available for %s\n", argv[1]); |
---|
[649] | 35 | exit(-1); |
---|
| 36 | } |
---|
[749] | 37 | shellenv(hp, bourneshell, argv[2]); |
---|
[649] | 38 | } |
---|
| 39 | |
---|
[749] | 40 | shellenv(hp, bourneshell, version) |
---|
[649] | 41 | char **hp; |
---|
| 42 | int bourneshell; |
---|
[749] | 43 | char *version; |
---|
[649] | 44 | { |
---|
[749] | 45 | char var[80], val[80], vers[80]; |
---|
[649] | 46 | |
---|
| 47 | if (bourneshell) { |
---|
| 48 | while(*hp) { |
---|
[749] | 49 | vers[0] = '\0'; |
---|
| 50 | sscanf(*hp++, "%s %s %s", var, val, vers); |
---|
| 51 | if (vers[0] != '\0' && strcmp(vers, version)) |
---|
| 52 | continue; |
---|
[649] | 53 | upper(var); |
---|
| 54 | printf("%s=%s ; export %s\n", var, val, var); |
---|
| 55 | } |
---|
| 56 | } else |
---|
| 57 | while(*hp) { |
---|
[749] | 58 | vers[0] = '\0'; |
---|
| 59 | sscanf(*hp++, "%s %s %s", var, val, vers); |
---|
| 60 | if (vers[0] != '\0' && strcmp(vers, version)) |
---|
| 61 | continue; |
---|
[649] | 62 | upper(var); |
---|
[749] | 63 | printf("setenv %s %s\n", var, val); |
---|
[649] | 64 | } |
---|
| 65 | if (ferror(stdout)) { |
---|
| 66 | ftruncate(fileno(stdout), 0L); |
---|
| 67 | exit(-1); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | upper(v) |
---|
| 72 | register char *v; |
---|
| 73 | { |
---|
| 74 | while(*v) { |
---|
| 75 | *v = toupper(*v); |
---|
| 76 | v++; |
---|
| 77 | } |
---|
| 78 | } |
---|