chiark / gitweb /
Various fixes.
authormdw <mdw>
Sat, 5 Feb 2005 10:40:12 +0000 (10:40 +0000)
committermdw <mdw>
Sat, 5 Feb 2005 10:40:12 +0000 (10:40 +0000)
debian/changelog
debian/control
gorp.1
gorp.c
locking.c
splitconf
splitconf.1

index 8e19ae52c1c7c3e7df7687a7c0b2fdb9fd697877..9773ddecc8d81451f4b9f566eed355c703f74d7d 100644 (file)
@@ -1,13 +1,14 @@
 nsict-utils (1.1.1) experimental; urgency=low
 
-  * Add pause program.
+  * Add pause, buf, create and inplace programs.
+  * Fix splitconf documentation to be right.
+  * Fix gorp to produce base32 (ugh!) and safe64 output.
 
- -- Mark Wooding <mdw@nsict.org>  Sat, 11 Sep 2004 18:13:25 +0100
+ -- Mark Wooding <mdw@nsict.org>  Sat,  5 Feb 2005 10:39:52 +0000
 
 nsict-utils (1.1.0) experimental; urgency=low
 
   * Make gorp a much more useful program.
-  
   * Get the right version number.  Oops!
 
  -- Mark Wooding <mdw@nsict.org>  Tue, 18 Nov 2003 18:47:21 +0000
index 271d1d43be89afffe27003405bff7fec7debc62d..758281c00630784f2f59ed63149f9a6976120d2b 100644 (file)
@@ -10,7 +10,7 @@ Package: nsict-utils
 Architecture: all
 Section: utils
 Depends: mdwopt-perl, nsict-cdb, locking, qmail-checkspam, nsict-mail,
- if-mtu, shadowfix, zz, gorp, splitconf, xtitle, buf, create, inplace
+ if-mtu, shadowfix, zz, gorp, splitconf, xtitle, pause, buf, create, inplace
 Description: Dummy package for convenience.
 
 Package: mdwopt-perl
diff --git a/gorp.1 b/gorp.1
index 66de0a1cc6826493f7af652c814ad50900a38a5d..572bee736ce9b345481d98dda5f61974d7e58b41 100644 (file)
--- a/gorp.1
+++ b/gorp.1
@@ -41,6 +41,19 @@ which may be
 instead of
 .RB ` / ',
 so the output is suitable for use as a filename),
+.B safe64
+(Base64 encoding, with
+.RB ` - '
+instead of
+.RB ` + ',
+and
+.RB ` _ '
+instead of
+.RB ` / ',
+as specified in RFC3548, as an attempt to achieve the same goal but
+inconveniently using up all the good separator characters),
+.B base32
+(Base32 encoding, as described in RFC2938),
 .B hex
 (plain hexadecimal encoding), or
 .B raw
diff --git a/gorp.c b/gorp.c
index 398e852b3b2dbc260e827da26c93575e2792227e..81b4608d8c425c56f9ffddb60fc9a5a3459f6415 100644 (file)
--- a/gorp.c
+++ b/gorp.c
@@ -7,6 +7,7 @@
 
 #include <mLib/alloc.h>
 #include <mLib/base64.h>
+#include <mLib/base32.h>
 #include <mLib/dstr.h>
 #include <mLib/hex.h>
 #include <mLib/mdwopt.h>
@@ -23,102 +24,91 @@ struct format {
 
 #define CHUNK 1024
 
-static void format_base64(size_t n, unsigned line)
+static void do_format(size_t n, unsigned line, void *ctx,
+                     void (*encode)(void *, char *, size_t, dstr *),
+                     void (*fix)(char *, size_t))
 {
-  unsigned char buf[CHUNK];
+  char buf[CHUNK];
   dstr d = DSTR_INIT;
-  base64_ctx b;
-
-  base64_init(&b);
-  if (line) {
-    b.indent = "\n";
-    b.maxline = line;
-  } else {
-    b.indent = "";
-    b.maxline = 0;
-  }
 
   while (n) {
     size_t nn = CHUNK;
     if (nn > n) nn = n;
     rand_get(RAND_GLOBAL, buf, nn);
-    base64_encode(&b, buf, nn, &d);
+    encode(ctx, buf, nn, &d);
+    if (fix) fix(d.buf, d.len);
     DWRITE(&d, stdout);
     DRESET(&d);
     n -= nn;
   }
-  base64_encode(&b, 0, 0, &d);
+  encode(ctx, 0, 0, &d);
   if (!line) {
     while (d.len && d.buf[d.len - 1] == '=')
       d.len--;
   }
+  if (fix) fix(d.buf, d.len);
   DPUTC(&d, '\n');
-  DWRITE(&d, stdout);
+  DWRITE(&d, stdout);  
 }
 
-static void file_fix(char *p, size_t n)
+static void do_base64(void *ctx, char *p, size_t sz, dstr *d)
+  { base64_encode(ctx, p, sz, d); }
+static void do_format_base64(size_t n, unsigned line,
+                            void (*fix)(char *, size_t))
+{
+  base64_ctx b;
+
+  base64_init(&b);
+  if (line) { b.indent = "\n"; b.maxline = line; }
+  else { b.indent = ""; b.maxline = 0; }
+  do_format(n, line, &b, do_base64, fix);
+}
+static void format_base64(size_t n, unsigned line)
+  { do_format_base64(n, line, 0); }
+  
+static void do_base32(void *ctx, char *p, size_t sz, dstr *d)
+  { base32_encode(ctx, p, sz, d); }
+static void format_base32(size_t n, unsigned line)
+{
+  base32_ctx b;
+
+  base32_init(&b);
+  if (line) { b.indent = "\n"; b.maxline = line; }
+  else { b.indent = ""; b.maxline = 0; }
+  do_format(n, line, &b, do_base32, 0);
+}
+
+static void fix_file64(char *p, size_t n)
 {
   while (n) {
     if (*p == '/') *p = '%';
     p++; n--;
   }
 }
-
 static void format_file64(size_t n, unsigned line)
-{
-  unsigned char buf[CHUNK];
-  dstr d = DSTR_INIT;
-  base64_ctx b;
-
-  base64_init(&b);
-  b.indent = "";
-  b.maxline = 0;
+  { do_format_base64(n, line, fix_file64); }
 
+static void fix_safe64(char *p, size_t n)
+{
   while (n) {
-    size_t nn = CHUNK;
-    if (nn > n) nn = n;
-    rand_get(RAND_GLOBAL, buf, nn);
-    base64_encode(&b, buf, nn, &d);
-    file_fix(d.buf, d.len);
-    DWRITE(&d, stdout);
-    DRESET(&d);
-    n -= nn;
+    if (*p == '+') *p = '-';
+    else if (*p == '/') *p = '_';
+    p++; n--;
   }
-  base64_encode(&b, 0, 0, &d);
-  file_fix(d.buf, d.len);
-  while (d.len && d.buf[d.len - 1] == '=')
-    d.len--;
-  DPUTC(&d, '\n');
-  DWRITE(&d, stdout);
 }
+static void format_safe64(size_t n, unsigned line)
+  { do_format_base64(n, line, fix_safe64); }
 
+static void do_hex(void *ctx, char *p, size_t sz, dstr *d)
+  { hex_encode(ctx, p, sz, d); }
 static void format_hex(size_t n, unsigned line)
 {
-  unsigned char buf[CHUNK];
-  dstr d = DSTR_INIT;
-  hex_ctx h;
+  hex_ctx b;
 
-  hex_init(&h);
-  if (line) {
-    h.indent = "\n";
-    h.maxline = line;
-  } else {
-    h.indent = "";
-    h.maxline = 0;
-  }
-
-  while (n) {
-    size_t nn = CHUNK;
-    if (nn > n) nn = n;
-    rand_get(RAND_GLOBAL, buf, nn);
-    hex_encode(&h, buf, nn, &d);
-    DWRITE(&d, stdout);
-    DRESET(&d);
-    n -= nn;
-  }
-  hex_encode(&h, 0, 0, &d);
-  DPUTC(&d, '\n');
-  DWRITE(&d, stdout);
+  hex_init(&b);
+  if (line) { b.indent = "\n"; b.maxline = line; }
+  else { b.indent = ""; b.maxline = 0; }
+  do_format(n, line, &b, do_hex, 0);
 }
 
 static void format_raw(size_t n, unsigned line)
@@ -137,6 +127,8 @@ static void format_raw(size_t n, unsigned line)
 static const struct format fmt[] = {
   { "base64",  format_base64 },
   { "file64",  format_file64 },
+  { "safe64",  format_safe64 },
+  { "base32",  format_base32 },
   { "hex",     format_hex },
   { "raw",     format_raw },
   { 0,         0 }
@@ -178,7 +170,8 @@ Options:\n\
 \n\
 -y, --bytes            Output length is bytes, not bits.\n\
 -l, --line=LENGTH      For textual output, limit line length to LENGTH.\n\
--f, --format=FORMAT    Select output format: base64, file64, hex, raw.\n\
+-f, --format=FORMAT    Select output format:\n\
+                         base64, file64, safe64, base32, hex, raw.\n\
 ", stdout);
 }
 
index 2e61f0d26ecfef8fa1c4a5291f7a75c524d7d0a8..cf2917a6008ca5c3f1b6578ed64e13ea91bec660 100644 (file)
--- a/locking.c
+++ b/locking.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: locking.c,v 1.3 2004/04/08 01:36:26 mdw Exp $
+ * $Id$
  *
  * Lock a file, run a program
  *
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #include <sys/types.h>
 #include <sys/time.h>
index 0b2f672f47546ff722b50c4e688c6bbc883bf8f1..12e63d223bcb11df1844ccb64eade76048c28ea4 100755 (executable)
--- a/splitconf
+++ b/splitconf
@@ -18,9 +18,7 @@ proc die {msg} {
 
 proc usage {file} {
   global argv0
-  puts $file "Usage: \n\
-       $argv0 \[-s\] FILE\n
-       $argv0 -u OUTPUT FILE FILE ..."
+  puts $file "Usage: \n\t$argv0 \[-s\] FILE\n\t$argv0 -u OUTPUT FILE FILE ..."
 }
 
 # clear-arrays ARRAY ...
@@ -229,15 +227,14 @@ switch $job {
     write-safe {
       while {[gets $c line] >= 0} {
        if {[regexp -- {^\[(.*)\]\s*$} $line . name]} {
-         if {[info exists o]} {
-           close $o
-         } elseif {!$donebefore} {
-           exec "sh" "-c" $opt(before) <@ stdin >@ stdout 2>@ stderr
-           set donebefore 1
-         }
+         if {[info exists o]} { close $o }
          if {[string equal $name ""]} {
            catch { unset o }
          } else {
+           if {!$donebefore} {
+             exec "sh" "-c" $opt(before) <@ stdin >@ stdout 2>@ stderr
+             set donebefore 1
+           }
            set name "$opt(prefix)$name"
            set o [write-safe-open $name]
            set new($name) 1
@@ -284,7 +281,9 @@ switch $job {
       }
       write-safe-manifest $conf [array names new]
     } {
-      exec "sh" "-c" $opt(after) <@ stdin >@ stdout 2>@ stderr
+      if {$donebefore} {
+       exec "sh" "-c" $opt(after) <@ stdin >@ stdout 2>@ stderr
+      }
     }
   }
 }
index e8b40166e7bffd17bc640644d3061e8f4084c6f3..2c4875dacf99e03a4cadffb9e37459a3d2175fa0 100644 (file)
@@ -93,22 +93,32 @@ A file section begins with a line of the form
 .BR ] '
 and is followed by lines to write to the file.  In these lines, comments
 (lines beginning with a
-.RB ` # '
+.RB ` ## '
 are stripped out, and any trailing blank lines are removed.  Also, any
 line beginning with an exclamation mark
 .RB ` ! '
 is written out with the leading exclamation mark removed.
 .PP
+A file section with an empty
+.I name
+is treated specially: its contents are scanned for more preamble
+directives.
+.PP
 Options are as follows.
 .TP
 .B prefix
-A string to attach to the front of all filenames.  (Default is empty.)
+A string to attach to the front of all subsequent filenames, until
+overridden.  (Default is empty.)
 .TP
 .B before
-A shell command to execute before starting to write any files.
+A shell command to execute before starting to write any files.  There is
+only one before-command, which is the one current when the first file is
+written.
 .TP
 .B after
 A shell command to execute after committing the changes or backing out.
+There is only one after-command, which is the last one set in the
+configuration file.
 .SH BUGS
 None known.
 .SH AUTHOR