source: trunk/athena/bin/hesinfo/hesinfo.c @ 11913

Revision 11913, 2.7 KB checked in by ghudson, 26 years ago (diff)
Shiny new home for hesinfo command (was in athena/lib/hesiod).
Line 
1/* Copyright 1988, 1996 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose.  It is provided "as is"
13 * without express or implied warranty.
14 */
15
16/* This file is a simple driver for the Hesiod library. */
17
18static char rcsid[] = "$Id: hesinfo.c,v 1.1 1998-09-03 01:12:50 ghudson Exp $";
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <errno.h>
24#include "hesiod.h"
25
26extern int optind;
27
28int main(int argc, char **argv)
29{
30  char **list, **p, *bindname, *name, *type;
31  int lflag = 0, errflg = 0, bflag = 0, c, status;
32  void *context;
33
34  while ((c = getopt(argc, argv, "lb")) != EOF)
35    {
36      switch (c)
37        {
38        case 'l':
39          lflag = 1;
40          break;
41        case 'b':
42          bflag = 1;
43          break;
44        default:
45          errflg++;
46          break;
47        }
48    }
49  if (argc - optind != 2 || errflg)
50    {
51      fprintf(stderr,"Usage: %s [-bl] name type\n",argv[0]);
52      fprintf(stderr,"\t-l selects long format\n");
53      fprintf(stderr,"\t-b also does hes_to_bind conversion\n");
54      return 2;
55    }
56
57  name = argv[optind];
58  type = argv[optind + 1];
59
60  if (hesiod_init(&context) < 0)
61    {
62      if (errno == ENOEXEC)
63        fprintf(stderr, "hesiod_init: Invalid Hesiod configuration file.\n");
64      else
65        perror("hesiod_init");
66    }
67
68  /* Display bind name if requested. */
69  if (bflag)
70    {
71      if (lflag)
72        printf("hes_to_bind(%s, %s) expands to\n", name, type);
73      bindname = hesiod_to_bind(context, name, type);
74      if (!bindname)
75        {
76          if (lflag)
77            printf("nothing\n");
78          if (errno == ENOENT)
79            fprintf(stderr, "hesiod_to_bind: Unknown rhs-extension.\n");
80          else
81            perror("hesiod_to_bind");
82          exit(1);
83        }
84      printf("%s\n", bindname);
85      free(bindname);
86      if (lflag)
87        printf("which ");
88    }
89
90  if (lflag)
91    printf("resolves to\n");
92
93  /* Do the hesiod resolve and check for errors. */
94  list = hesiod_resolve(context, name, type);
95  if (!list)
96    {
97      if (lflag)
98        printf("nothing\n");
99      if (errno == ENOENT)
100        fprintf(stderr, "hesiod_resolve: Hesiod name not found.\n");
101      else
102        perror("hesiod_resolve");
103      return 1;
104    }
105
106  /* Display the results. */
107  for (p = list; *p; p++)
108    printf("%s\n", *p);
109
110  hesiod_free_list(context, list);
111  hesiod_end(context);
112  return 0;
113}
Note: See TracBrowser for help on using the repository browser.