-#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);
}