chiark / gitweb /
Import ezmlm-idx 0.40
[ezmlm] / ezmlm-issubn.c
1 /*$Id: ezmlm-issubn.c,v 1.13 1999/08/07 20:45:16 lindberg Exp $*/
2 /*$Name: ezmlm-idx-040 $*/
3 #include "strerr.h"
4 #include "env.h"
5 #include "subscribe.h"
6 #include "sgetopt.h"
7 #include "errtxt.h"
8 #include "idx.h"
9
10 #define FATAL "ezmlm-issubn: fatal: "
11
12 void *psql = (void *) 0;
13
14 void die_usage()
15 {
16   strerr_die1x(100,"ezmlm-issubn: usage: ezmlm-issubn [-nN] dir [dir1 ...]");
17 }
18
19 void die_sender()
20 {
21   strerr_die2x(100,FATAL,ERR_NOSENDER);
22 }
23
24 void main(argc,argv)
25 int argc;
26 char **argv;
27 {
28   char *dir;
29   char *addr;
30   int flagsub = 0;
31   int opt;
32
33   addr = env_get("SENDER");
34   if (!addr) die_sender();      /* REQUIRE sender */
35
36   while ((opt = getopt(argc,argv,"nNvV")) != opteof)
37     switch(opt) {
38       case 'n': flagsub = 99; break;
39       case 'N': flagsub = 0; break;
40       case 'v':
41       case 'V': strerr_die2x(0,
42                 "ezmlm-issubn version: ezmlm-0.53+",EZIDX_VERSION);
43       default:
44         die_usage();
45     }
46
47   dir = argv[optind];
48   if (chdir(dir) == -1)
49     strerr_die4sys(111,FATAL,ERR_SWITCH,dir,": ");
50
51   while ((dir = argv[optind++])) {
52     if (dir[0] != '/')
53       strerr_die2x(100,FATAL,ERR_SLASH);
54     if (issub(dir,addr,(char *) 0,FATAL)) {
55       closesql();
56       _exit(flagsub);           /* subscriber */
57     }
58   }
59   closesql();
60   if (flagsub)                  /* not subscriber anywhere */
61     _exit(0);
62   else
63     _exit(99);
64 }