1 /* 2 * Copyright (c) 1983 Eric P. Allman 3 * Copyright (c) 1988 Regents of the University of California. 4 * All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 */ 8 9 #ifndef lint 10 char copyright[] = 11 "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 12 All rights reserved.\n"; 13 #endif /* not lint */ 14 15 #ifndef lint 16 static char sccsid[] = "@(#)praliases.c 6.1 (Berkeley) 12/21/92"; 17 #endif /* not lint */ 18 19 #include <sendmail.h> 20 21 typedef struct { 22 char *dptr; 23 int dsize; 24 } datum; 25 26 27 main(argc, argv) 28 char **argv; 29 { 30 extern char *optarg; 31 extern int optind; 32 static char *filename = "/usr/lib/aliases"; 33 datum content, key, firstkey(), nextkey(), fetch(); 34 int ch; 35 36 while ((ch = getopt(argc, argv, "f:")) != EOF) 37 switch((char)ch) { 38 case 'f': 39 filename = optarg; 40 break; 41 case '?': 42 default: 43 fputs("usage: praliases [-f file]\n", stderr); 44 exit(EX_USAGE); 45 } 46 argc -= optind; 47 argv += optind; 48 49 if (dbminit(filename) < 0) 50 exit(EX_OSFILE); 51 if (!argc) 52 for (key = firstkey(); key.dptr; key = nextkey(key)) { 53 content = fetch(key); 54 printf("%s:%s\n", key.dptr, content.dptr); 55 } 56 else for (; *argv; ++argv) { 57 key.dptr = *argv; 58 key.dsize = strlen(*argv) + 1; 59 content = fetch(key); 60 if (!content.dptr) 61 printf("%s: No such key\n", key.dptr); 62 else 63 printf("%s:%s\n", key.dptr, content.dptr); 64 } 65 exit(EX_OK); 66 } 67