File: hesinfo.c

package info (click to toggle)
hesiod 3.0.2-20
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 716 kB
  • ctags: 111
  • sloc: ansic: 1,269; sh: 236; makefile: 142
file content (113 lines) | stat: -rw-r--r-- 2,774 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* Copyright 1988, 1996 by the Massachusetts Institute of Technology.
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in
 * advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.
 * M.I.T. makes no representations about the suitability of
 * this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 */

/* This file is a simple driver for the Hesiod library. */

static char rcsid[] = "$Id: hesinfo.c,v 1.8 1996/12/08 21:29:54 ghudson Exp $";

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "hesiod.h"

extern int optind;

int main(int argc, char **argv)
{
  char **list, **p, *bindname, *name, *type;
  int lflag = 0, errflg = 0, bflag = 0, c, status;
  void *context;

  while ((c = getopt(argc, argv, "lb")) != EOF)
    {
      switch (c)
	{
	case 'l':
	  lflag = 1;
	  break;
	case 'b':
	  bflag = 1;
	  break;
	default:
	  errflg++;
	  break;
	}
    }
  if (argc - optind != 2 || errflg)
    {
      fprintf(stderr,"Usage: %s [-bl] name type\n",argv[0]);
      fprintf(stderr,"\t-l selects long format\n");
      fprintf(stderr,"\t-b also does hes_to_bind conversion\n");
      return 2;
    }

  name = argv[optind];
  type = argv[optind + 1];

  if (hesiod_init(&context) < 0)
    {
      if (errno == ENOEXEC)
	fprintf(stderr, "hesiod_init: Invalid Hesiod configuration file.\n");
      else
	perror("hesiod_init");
    }

  /* Display bind name if requested. */
  if (bflag)
    {
      if (lflag)
	printf("hes_to_bind(%s, %s) expands to\n", name, type);
      bindname = hesiod_to_bind(context, name, type);
      if (!bindname)
	{
	  if (lflag)
	    printf("nothing\n");
	  if (errno == ENOENT)
	    fprintf(stderr, "hesiod_to_bind: Unknown rhs-extension.\n");
	  else
	    perror("hesiod_to_bind");
	  exit(1);
	}
      printf("%s\n", bindname);
      free(bindname);
      if (lflag)
	printf("which ");
    }

  if (lflag) 
    printf("resolves to\n");

  /* Do the hesiod resolve and check for errors. */
  list = hesiod_resolve(context, name, type);
  if (!list)
    { 
      if (lflag)
	printf("nothing\n");
      if (errno == ENOENT)
	fprintf(stderr, "hesiod_resolve: Hesiod name not found.\n");
      else
	perror("hesiod_resolve");
      return 1;
    }

  /* Display the results. */
  for (p = list; *p; p++)
    printf("%s\n", *p);

  hesiod_free_list(context, list);
  hesiod_end(context);
  return 0;
}