This commit is contained in:
Troy D. Hanson
2015-08-16 14:55:55 -04:00
parent 81eb26b52e
commit 1960222e00

View File

@@ -16,11 +16,15 @@
#include "kvspool.h"
#include "kvsp-bconfig.h"
/* read spool, cast to binary (like bpub, tpub), write to stdout */
int verbose;
int blocking=1;
char *spool;
void usage(char *prog) {
fprintf(stderr, "usage: %s [-v] -b <config> -d spool\n", prog);
fprintf(stderr, "usage: %s -[vo] -b <config> -d spool\n", prog);
fprintf(stderr, " -o (oneshot) read spool and exit\n");
exit(-1);
}
@@ -79,7 +83,8 @@ int main(int argc, char *argv[]) {
void *sp=NULL;
void *set=NULL;
int opt,rc=-1;
char *config_file;
char *config_file, *b;
size_t l;
set = kv_set_new();
utarray_new(output_keys, &ut_str_icd);
utarray_new(output_defaults, &ut_str_icd);
@@ -87,9 +92,10 @@ int main(int argc, char *argv[]) {
UT_string *tmp;
utstring_new(tmp);
while ( (opt = getopt(argc, argv, "v+d:b:")) != -1) {
while ( (opt = getopt(argc, argv, "v+d:b:o")) != -1) {
switch (opt) {
case 'v': verbose++; break;
case 'o': blocking=0; break;
case 'd': spool=strdup(optarg); break;
case 'b': config_file=strdup(optarg); break;
default: usage(argv[0]); break;
@@ -101,8 +107,15 @@ int main(int argc, char *argv[]) {
sp = kv_spoolreader_new(spool);
if (!sp) goto done;
while (kv_spool_read(sp,set,1) > 0) {
while (kv_spool_read(sp,set,blocking) > 0) {
if (set_to_binary(set,tmp) < 0) goto done;
b = utstring_body(tmp);
l = utstring_len(tmp);
if (write(STDOUT_FILENO, b, l) != l) {
fprintf(stderr,"write: %s\n", l>0 ?
"incomplete" : strerror(errno));
}
}
rc = 0;