| 1 | /*$Id: ezmlm-sub.c,v 1.18 1999/08/02 02:57:57 lindberg Exp $*/ |
| 2 | /*$Name: ezmlm-idx-040 $*/ |
| 3 | #include "strerr.h" |
| 4 | #include "subscribe.h" |
| 5 | #include "sgetopt.h" |
| 6 | #include "stralloc.h" |
| 7 | #include "substdio.h" |
| 8 | #include "readwrite.h" |
| 9 | #include "getln.h" |
| 10 | #include "errtxt.h" |
| 11 | #include "scan.h" |
| 12 | #include "idx.h" |
| 13 | |
| 14 | #define FATAL "ezmlm-sub: fatal: " |
| 15 | |
| 16 | void *psql = (void *) 0; |
| 17 | |
| 18 | char inbuf[512]; |
| 19 | substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf)); |
| 20 | |
| 21 | stralloc line = {0}; |
| 22 | |
| 23 | void die_usage() { |
| 24 | strerr_die1x(100, |
| 25 | "ezmlm-sub: usage: ezmlm-sub [-mMvV] [-h hash] [-n] dir " |
| 26 | "[box@domain [name]] ..."); |
| 27 | } |
| 28 | |
| 29 | int flagname = 0; |
| 30 | |
| 31 | void main(argc,argv) |
| 32 | int argc; |
| 33 | char **argv; |
| 34 | { |
| 35 | char *dir; |
| 36 | char *addr; |
| 37 | char *comment; |
| 38 | char *cp; |
| 39 | char ch; |
| 40 | int opt; |
| 41 | int match; |
| 42 | int flagmysql = 1; /* use mysql if supported */ |
| 43 | int forcehash = -1; |
| 44 | unsigned int u; |
| 45 | |
| 46 | (void) umask(022); |
| 47 | while ((opt = getopt(argc,argv,"h:HmMnNvV")) != opteof) |
| 48 | switch(opt) { |
| 49 | case 'h': (void) scan_ulong(optarg,&u); forcehash = 0; break; |
| 50 | case 'H': forcehash = -1; break; |
| 51 | case 'm': flagmysql = 1; break; |
| 52 | case 'M': flagmysql = 0; break; |
| 53 | case 'n': flagname = 1; break; |
| 54 | case 'N': flagname = 0; break; |
| 55 | case 'v': |
| 56 | case 'V': strerr_die2x(0, |
| 57 | "ezmlm-sub version: ezmlm-0.53+",EZIDX_VERSION); |
| 58 | default: |
| 59 | die_usage(); |
| 60 | } |
| 61 | |
| 62 | dir = argv[optind++]; |
| 63 | if (!dir) die_usage(); |
| 64 | |
| 65 | if (dir[0] != '/') |
| 66 | strerr_die2x(100,FATAL,ERR_SLASH); |
| 67 | |
| 68 | if (chdir(dir) == -1) |
| 69 | strerr_die4sys(111,FATAL,ERR_SWITCH,dir,": "); |
| 70 | |
| 71 | if (forcehash == 0) forcehash = (int) u; |
| 72 | |
| 73 | if (argv[optind]) { |
| 74 | if (flagname) { |
| 75 | /* allow repeats and last addr doesn't need comment */ |
| 76 | while ((addr = argv[optind++])) { |
| 77 | (void) subscribe(dir,addr,1,argv[optind],"+manual", |
| 78 | flagmysql,forcehash,(char *) 0,FATAL); |
| 79 | if (!argv[optind++]) break; |
| 80 | } |
| 81 | } else { |
| 82 | |
| 83 | while ((addr = argv[optind++])) |
| 84 | (void) subscribe(dir,addr,1,"","+manual",flagmysql, |
| 85 | forcehash,(char *) 0,FATAL); |
| 86 | } |
| 87 | } else { /* stdin */ |
| 88 | for (;;) { |
| 89 | if (getln(&ssin,&line,&match,'\n') == -1) |
| 90 | strerr_die2sys(111,FATAL,ERR_READ_INPUT); |
| 91 | if (!match) break; |
| 92 | if (line.len == 1 || *line.s == '#') continue; |
| 93 | line.s[line.len - 1] = '\0'; |
| 94 | comment = (char *) 0; |
| 95 | if (flagname) { |
| 96 | cp = line.s; |
| 97 | while ((ch = *cp)) { |
| 98 | if (ch == '\\') { |
| 99 | if (!*(++cp)) break; |
| 100 | } else if (ch == ' ' || ch == '\t' || ch == ',') break; |
| 101 | cp++; |
| 102 | } |
| 103 | if (ch) { |
| 104 | *cp = '\0'; |
| 105 | comment = cp + 1; |
| 106 | } |
| 107 | } |
| 108 | (void) subscribe(dir,line.s,1,comment,"+manual",flagmysql, |
| 109 | forcehash,(char *) 0,FATAL); |
| 110 | } |
| 111 | } |
| 112 | closesql(); |
| 113 | _exit(0); |
| 114 | } |