| 1 | /*$Id: ezmlm-list.c,v 1.15 1999/09/12 20:25:33 lindberg Exp $*/ |
| 2 | /*$Name: ezmlm-idx-040 $*/ |
| 3 | #include "strerr.h" |
| 4 | #include "readwrite.h" |
| 5 | #include "substdio.h" |
| 6 | #include "subscribe.h" |
| 7 | #include "exit.h" |
| 8 | #include "fmt.h" |
| 9 | #include "sgetopt.h" |
| 10 | #include "errtxt.h" |
| 11 | #include "idx.h" |
| 12 | |
| 13 | #define FATAL "ezmlm-list: fatal: " |
| 14 | |
| 15 | int flagnumber = 0; /* default list subscribers, not number of */ |
| 16 | |
| 17 | void *psql = (void *) 0; |
| 18 | |
| 19 | char strnum[FMT_ULONG]; |
| 20 | |
| 21 | void die_write() |
| 22 | { |
| 23 | strerr_die3sys(111,FATAL,ERR_WRITE,"stdout: "); |
| 24 | } |
| 25 | |
| 26 | void die_usage() |
| 27 | { |
| 28 | strerr_die1x(100,"ezmlm-list: usage: ezmlm-list [-mMnNvV] dir"); |
| 29 | } |
| 30 | |
| 31 | static char outbuf[512]; |
| 32 | static substdio ssout = SUBSTDIO_FDBUF(write,1,outbuf,sizeof(outbuf)); |
| 33 | |
| 34 | int subwrite(s,l) |
| 35 | char *s; |
| 36 | unsigned int l; |
| 37 | { |
| 38 | return substdio_put(&ssout,s,l) | substdio_put(&ssout,"\n",1); |
| 39 | } |
| 40 | |
| 41 | int dummywrite(s,l) |
| 42 | char *s; /* ignored */ |
| 43 | unsigned int l; |
| 44 | { |
| 45 | return (int) l; |
| 46 | } |
| 47 | |
| 48 | void main(argc,argv) |
| 49 | int argc; |
| 50 | char **argv; |
| 51 | { |
| 52 | char *dir; |
| 53 | int flagmysql = 1; /* use if supported */ |
| 54 | unsigned long n; |
| 55 | int opt; |
| 56 | |
| 57 | while ((opt = getopt(argc,argv,"mMnNvV")) != opteof) |
| 58 | switch(opt) { |
| 59 | case 'm': flagmysql = 1; break; |
| 60 | case 'M': flagmysql = 0; break; |
| 61 | case 'n': flagnumber = 1; break; |
| 62 | case 'N': flagnumber = 0; break; |
| 63 | case 'v': |
| 64 | case 'V': strerr_die2x(0, |
| 65 | "ezmlm-list version: ezmlml-0.53+",EZIDX_VERSION); |
| 66 | default: |
| 67 | die_usage(); |
| 68 | } |
| 69 | |
| 70 | dir = argv[optind++]; |
| 71 | if (!dir) die_usage(); |
| 72 | |
| 73 | if (chdir(dir) == -1) |
| 74 | strerr_die4sys(111,FATAL,ERR_SWITCH,dir,": "); |
| 75 | |
| 76 | if (dir[0] != '/') |
| 77 | strerr_die2x(100,FATAL,ERR_SLASH); |
| 78 | |
| 79 | if (flagnumber) { |
| 80 | n = putsubs(dir,0L,52L,dummywrite,flagmysql,FATAL); |
| 81 | if (substdio_put(&ssout,strnum,fmt_ulong(strnum,n)) == -1) die_write(FATAL); |
| 82 | if (substdio_put(&ssout,"\n",1) == -1) die_write(FATAL); |
| 83 | } else |
| 84 | (void) putsubs(dir,0L,52L,subwrite,flagmysql,FATAL); |
| 85 | if (substdio_flush(&ssout) == -1) die_write(FATAL); |
| 86 | closesql(); |
| 87 | _exit(0); |
| 88 | } |