1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 char copyright[] =
15 "@(#) Copyright (c) 1988 Regents of the University of California.\n\
16  All rights reserved.\n";
17 #endif /* not lint */
18 
19 #ifndef lint
20 static char sccsid[] = "@(#)praliases.c	5.3 (Berkeley) 04/21/88";
21 #endif /* not lint */
22 
23 #include <sendmail.h>
24 
25 typedef struct {
26 	char *dptr;
27 	int dsize;
28 } datum;
29 
30 
31 main(argc, argv)
32 	char **argv;
33 {
34 	extern char *optarg;
35 	extern int optind;
36 	static char *filename = "/usr/lib/aliases";
37 	datum content, key, firstkey(), nextkey(), fetch();
38 	int ch;
39 
40 	while ((ch = getopt(argc, argv, "f:")) != EOF)
41 		switch((char)ch) {
42 		case 'f':
43 			filename = optarg;
44 			break;
45 		case '?':
46 		default:
47 			fputs("usage: praliases [-f file]\n", stderr);
48 			exit(EX_USAGE);
49 		}
50 	argc -= optind;
51 	argv += optind;
52 
53 	if (dbminit(filename) < 0)
54 		exit(EX_OSFILE);
55 	if (!argc)
56 		for (key = firstkey(); key.dptr; key = nextkey(key)) {
57 			content = fetch(key);
58 			printf("%s:%s\n", key.dptr, content.dptr);
59 		}
60 	else for (; *argv; ++argv) {
61 		key.dptr = *argv;
62 		key.dsize = strlen(*argv) + 1;
63 		content = fetch(key);
64 		if (!content.dptr)
65 			printf("%s: No such key\n", key.dptr);
66 		else
67 			printf("%s:%s\n", key.dptr, content.dptr);
68 	}
69 	exit(EX_OK);
70 }
71