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

Revision 14160, 2.7 KB checked in by ghudson, 25 years ago (diff)
Fix a bug noticed by Aaron (hesiod_free_string() takes two arguments).
RevLine 
[11913]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
[14160]18static const char rcsid[] = "$Id: hesinfo.c,v 1.5 2000-01-05 22:00:46 ghudson Exp $";
[11913]19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
[13615]23#include <unistd.h>
[11913]24#include <errno.h>
25#include "hesiod.h"
26
27extern int optind;
28
29int main(int argc, char **argv)
30{
31  char **list, **p, *bindname, *name, *type;
[13606]32  int lflag = 0, errflg = 0, bflag = 0, c;
[11913]33  void *context;
34
35  while ((c = getopt(argc, argv, "lb")) != EOF)
36    {
37      switch (c)
38        {
39        case 'l':
40          lflag = 1;
41          break;
42        case 'b':
43          bflag = 1;
44          break;
45        default:
46          errflg++;
47          break;
48        }
49    }
50  if (argc - optind != 2 || errflg)
51    {
52      fprintf(stderr,"Usage: %s [-bl] name type\n",argv[0]);
53      fprintf(stderr,"\t-l selects long format\n");
54      fprintf(stderr,"\t-b also does hes_to_bind conversion\n");
55      return 2;
56    }
57
58  name = argv[optind];
59  type = argv[optind + 1];
60
61  if (hesiod_init(&context) < 0)
62    {
63      if (errno == ENOEXEC)
64        fprintf(stderr, "hesiod_init: Invalid Hesiod configuration file.\n");
65      else
66        perror("hesiod_init");
67    }
68
69  /* Display bind name if requested. */
70  if (bflag)
71    {
72      if (lflag)
73        printf("hes_to_bind(%s, %s) expands to\n", name, type);
74      bindname = hesiod_to_bind(context, name, type);
75      if (!bindname)
76        {
77          if (lflag)
78            printf("nothing\n");
79          if (errno == ENOENT)
80            fprintf(stderr, "hesiod_to_bind: Unknown rhs-extension.\n");
81          else
82            perror("hesiod_to_bind");
83          exit(1);
84        }
85      printf("%s\n", bindname);
[14160]86      hesiod_free_string(context, bindname);
[11913]87      if (lflag)
88        printf("which ");
89    }
90
91  if (lflag)
92    printf("resolves to\n");
93
94  /* Do the hesiod resolve and check for errors. */
95  list = hesiod_resolve(context, name, type);
96  if (!list)
97    {
98      if (lflag)
99        printf("nothing\n");
100      if (errno == ENOENT)
101        fprintf(stderr, "hesiod_resolve: Hesiod name not found.\n");
102      else
103        perror("hesiod_resolve");
104      return 1;
105    }
106
107  /* Display the results. */
108  for (p = list; *p; p++)
109    printf("%s\n", *p);
110
111  hesiod_free_list(context, list);
112  hesiod_end(context);
113  return 0;
114}
Note: See TracBrowser for help on using the repository browser.