X-Git-Url: https://git.distorted.org.uk/~mdw/ezmlm/blobdiff_plain/5b62e993b0af39700031c2875d7f6654e6a02850..f8beb284087c279acfb30506f5bb32baa4949b44:/ezmlm-list.c diff --git a/ezmlm-list.c b/ezmlm-list.c index c6ec801..644c514 100644 --- a/ezmlm-list.c +++ b/ezmlm-list.c @@ -1,62 +1,88 @@ -#include "stralloc.h" -#include "substdio.h" -#include "getln.h" +/*$Id: ezmlm-list.c,v 1.15 1999/09/12 20:25:33 lindberg Exp $*/ +/*$Name: ezmlm-idx-040 $*/ #include "strerr.h" -#include "error.h" #include "readwrite.h" +#include "substdio.h" +#include "subscribe.h" #include "exit.h" -#include "open.h" +#include "fmt.h" +#include "sgetopt.h" +#include "errtxt.h" +#include "idx.h" #define FATAL "ezmlm-list: fatal: " + +int flagnumber = 0; /* default list subscribers, not number of */ + +void *psql = (void *) 0; + +char strnum[FMT_ULONG]; + void die_write() { - strerr_die2sys(111,FATAL,"unable to write: "); + strerr_die3sys(111,FATAL,ERR_WRITE,"stdout: "); +} + +void die_usage() +{ + strerr_die1x(100,"ezmlm-list: usage: ezmlm-list [-mMnNvV] dir"); } -char outbuf[1024]; -substdio out = SUBSTDIO_FDBUF(write,1,outbuf,sizeof(outbuf)); -char inbuf[1024]; -substdio in; +static char outbuf[512]; +static substdio ssout = SUBSTDIO_FDBUF(write,1,outbuf,sizeof(outbuf)); -stralloc line = {0}; +int subwrite(s,l) +char *s; +unsigned int l; +{ + return substdio_put(&ssout,s,l) | substdio_put(&ssout,"\n",1); +} -char fn[14] = "subscribers/?"; +int dummywrite(s,l) +char *s; /* ignored */ +unsigned int l; +{ + return (int) l; +} void main(argc,argv) int argc; char **argv; { char *dir; - int fd; - int match; + int flagmysql = 1; /* use if supported */ + unsigned long n; + int opt; - dir = argv[1]; - if (!dir) strerr_die1x(100,"ezmlm-list: usage: ezmlm-list dir"); + while ((opt = getopt(argc,argv,"mMnNvV")) != opteof) + switch(opt) { + case 'm': flagmysql = 1; break; + case 'M': flagmysql = 0; break; + case 'n': flagnumber = 1; break; + case 'N': flagnumber = 0; break; + case 'v': + case 'V': strerr_die2x(0, + "ezmlm-list version: ezmlml-0.53+",EZIDX_VERSION); + default: + die_usage(); + } - if (chdir(dir) == -1) - strerr_die4sys(111,FATAL,"unable to switch to ",dir,": "); + dir = argv[optind++]; + if (!dir) die_usage(); - for (fn[12] = 64;fn[12] < 64 + 53;++fn[12]) { - fd = open_read(fn); - if (fd == -1) { - if (errno != error_noent) - strerr_die4sys(111,FATAL,"unable to open ",fn,": "); - } - else { - substdio_fdbuf(&in,read,fd,inbuf,sizeof(inbuf)); - for (;;) { - if (getln(&in,&line,&match,'\0') == -1) - strerr_die4sys(111,FATAL,"unable to read ",fn,": "); - if (!match) break; - if (line.s[str_chr(line.s,'\n')]) - strerr_die3x(111,FATAL,"newline in ",fn); - if (substdio_puts(&out,line.s + 1)) die_write(); - if (substdio_put(&out,"\n",1) == -1) die_write(); - } - } + if (chdir(dir) == -1) + strerr_die4sys(111,FATAL,ERR_SWITCH,dir,": "); - } + if (dir[0] != '/') + strerr_die2x(100,FATAL,ERR_SLASH); - if (substdio_flush(&out) == -1) die_write(); + if (flagnumber) { + n = putsubs(dir,0L,52L,dummywrite,flagmysql,FATAL); + if (substdio_put(&ssout,strnum,fmt_ulong(strnum,n)) == -1) die_write(FATAL); + if (substdio_put(&ssout,"\n",1) == -1) die_write(FATAL); + } else + (void) putsubs(dir,0L,52L,subwrite,flagmysql,FATAL); + if (substdio_flush(&ssout) == -1) die_write(FATAL); + closesql(); _exit(0); }