chiark / gitweb /
codec: New flag to ignore linear whitespace.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 24 Feb 2014 17:32:01 +0000 (17:32 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 27 Feb 2014 18:32:29 +0000 (18:32 +0000)
Why was this missed the first time around?  Set this by default in the
`bincode' program.

codec/baseconv.c
codec/bincode.1
codec/bincode.c
codec/codec.3
codec/codec.h

index 1d507359ae75f1975b6f87d7d16c2740224a99b3..bdb850f7d19ca53b2cbf4c9092e8fd7b6758852e 100644 (file)
@@ -48,6 +48,7 @@
 #define NV -1                          /* Not valid */
 #define PC -2                          /* Padding character */
 #define NL -3                          /* Newline character */
 #define NV -1                          /* Not valid */
 #define PC -2                          /* Padding character */
 #define NL -3                          /* Newline character */
+#define SP -4                          /* Space character */
 
 /* --- Base64 --- */
 
 
 /* --- Base64 --- */
 
@@ -63,27 +64,27 @@ static const char
                            "0123456789-_" };
 
 static const signed char decodemap_base64[] = {
                            "0123456789-_" };
 
 static const signed char decodemap_base64[] = {
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV,  /* 0x */
+  NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV,  /* 0x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV, NV, 63,  /* 2x */
+  SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV, NV, 63,  /* 2x */
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV,  /* 5x */
   NV, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ,37, 38, 39, 40,  /* 6x */
   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NV, NV, NV, NV, NV   /* 7x */
 }, decodemap_file64[] = {
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV,  /* 5x */
   NV, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ,37, 38, 39, 40,  /* 6x */
   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NV, NV, NV, NV, NV   /* 7x */
 }, decodemap_file64[] = {
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV,  /* 0x */
+  NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV,  /* 0x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
-  NV, NV, NV, NV, NV, 63, NV, NV, NV, NV, NV, 62, NV, NV, NV, NV,  /* 2x */
+  SP, NV, NV, NV, NV, 63, NV, NV, NV, NV, NV, 62, NV, NV, NV, NV,  /* 2x */
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV,  /* 5x */
   NV, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ,37, 38, 39, 40,  /* 6x */
   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NV, NV, NV, NV, NV   /* 7x */
 }, decodemap_base64url[] = {
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV,  /* 5x */
   NV, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 ,37, 38, 39, 40,  /* 6x */
   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, NV, NV, NV, NV, NV   /* 7x */
 }, decodemap_base64url[] = {
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV,  /* 0x */
+  NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV,  /* 0x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV,  /* 2x */
+  SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, 62, NV, NV,  /* 2x */
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, 63,  /* 5x */
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, 63,  /* 5x */
@@ -98,18 +99,18 @@ static const char
   encodemap_base32hex[] =   { "0123456789ABCDEFGHIJKLMNOPQRSTUV" };
 
 static const signed char decodemap_base32[] = {
   encodemap_base32hex[] =   { "0123456789ABCDEFGHIJKLMNOPQRSTUV" };
 
 static const signed char decodemap_base32[] = {
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV,  /* 0x */
+  NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV,  /* 0x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 2x */
+  SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 2x */
   NV, NV, 26, 27, 28, 29, 30, 31, NV, NV, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV,  /* 5x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 6x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 7x */
 }, decodemap_base32hex[] = {
   NV, NV, 26, 27, 28, 29, 30, 31, NV, NV, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,  /* 4x */
   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, NV, NV, NV, NV, NV,  /* 5x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 6x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 7x */
 }, decodemap_base32hex[] = {
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV,  /* 0x */
+  NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV,  /* 0x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 2x */
+  SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 2x */
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,  /* 4x */
   25, 26, 27, 28, 29, 30, 31, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 5x */
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, NV, NV, NV, PC, NV, NV,  /* 3x */
   NV, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,  /* 4x */
   25, 26, 27, 28, 29, 30, 31, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 5x */
@@ -123,9 +124,9 @@ static const char
   encodemap_hex[] =   { "0123456789ABCDEF" };
 
 static const signed char decodemap_hex[] = {
   encodemap_hex[] =   { "0123456789ABCDEF" };
 
 static const signed char decodemap_hex[] = {
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NL, NV, NV, NL, NV, NV,  /* 0x */
+  NV, NV, NV, NV, NV, NV, NV, NV, NV, SP, NL, NV, SP, NL, NV, NV,  /* 0x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 1x */
-  NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 2x */
+  SP, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 2x */
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, NV, NV, NV, NV, NV, NV,  /* 3x */
   NV, 10, 11, 12, 13, 14, 15, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 4x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 5x */
    0,  1,  2,  3,  4,  5,  6,  7,  8,  9, NV, NV, NV, NV, NV, NV,  /* 3x */
   NV, 10, 11, 12, 13, 14, 15, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 4x */
   NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV, NV,  /* 5x */
@@ -375,9 +376,11 @@ static int ctxn##_dodecode(ctxn##_ctx *ctx,                                \
        case NL:                                                        \
          if (f & CDCF_IGNNEWL) break;                                  \
          return (CDCERR_INVCH);                                        \
        case NL:                                                        \
          if (f & CDCF_IGNNEWL) break;                                  \
          return (CDCERR_INVCH);                                        \
+       case SP:                                                        \
+         if (f & CDCF_IGNSPC) break;                                   \
+         return (CDCERR_INVCH);                                        \
        default:                                                        \
        default:                                                        \
-         if (st != ST_MAIN)                                            \
-           return (CDCERR_INVEQPAD);                                   \
+         if (st != ST_MAIN) return (CDCERR_INVEQPAD);                  \
          BASECONV(x, wd, 8, PUTRAW);                                   \
          break;                                                        \
       }                                                                        \
          BASECONV(x, wd, 8, PUTRAW);                                   \
          break;                                                        \
       }                                                                        \
index 7914f75659859469582dfb569d84e6a2302dbd6e..4e828b71edda503bb63388650d05cc2dba8fc4ea 100644 (file)
@@ -54,7 +54,9 @@ prefix; e.g.,
 may be specified as
 .RB ` ignnewl '.
 This option may be repeated: the options are scanned left-to-right.  The
 may be specified as
 .RB ` ignnewl '.
 This option may be repeated: the options are scanned left-to-right.  The
-only flag set by default is
+flags set by default are
+.RB ` ignspc '
+and
 .RB ` ignnewl '.
 .TP
 .BI "\-i, \-\-indent=" indent
 .RB ` ignnewl '.
 .TP
 .BI "\-i, \-\-indent=" indent
index 0a7d5c50b8f4bca35cf56e4e9514bfcc86a348b3..af1e677242fc955c452486993dc88370d3df4247 100644 (file)
@@ -65,6 +65,7 @@ static const struct { const char *name; unsigned f; } flagtab[] = {
   { "igneqmid",                CDCF_IGNEQMID },
   { "ignzpad",         CDCF_IGNZPAD },
   { "ignnewl",         CDCF_IGNNEWL },
   { "igneqmid",                CDCF_IGNEQMID },
   { "ignzpad",         CDCF_IGNZPAD },
   { "ignnewl",         CDCF_IGNNEWL },
+  { "ignspc",          CDCF_IGNSPC },
   { "igninvch",                CDCF_IGNINVCH },
   { "ignjunk",         CDCF_IGNJUNK },
   { 0,                 0, }
   { "igninvch",                CDCF_IGNINVCH },
   { "ignjunk",         CDCF_IGNJUNK },
   { 0,                 0, }
@@ -139,7 +140,7 @@ int main(int argc, char *argv[])
   const char *indent = "";
   const char *imode, *omode, *ofile = 0;
   unsigned maxline = 64;
   const char *indent = "";
   const char *imode, *omode, *ofile = 0;
   unsigned maxline = 64;
-  unsigned f = CDCF_IGNNEWL;
+  unsigned f = CDCF_IGNSPC | CDCF_IGNNEWL;
   const char *p;
   char *q;
   FILE *ifp, *ofp = stdout;
   const char *p;
   char *q;
   FILE *ifp, *ofp = stdout;
index 96174f3353a0405829a3fea19f8c83f744a81f81..efc0b7e666f08da92dd316c40c1af75684a4338a 100644 (file)
@@ -122,6 +122,11 @@ Ignore newline (and carriage-return) characters when decoding: the
 default for RFC4648 codecs is to reject newline characters.  If these
 characters are significant in the encoding, then this flag is ignored.
 .TP
 default for RFC4648 codecs is to reject newline characters.  If these
 characters are significant in the encoding, then this flag is ignored.
 .TP
+.B CDCF_IGNSPC
+Ignore whitespace characters (other than newlines) when decoding: the
+default for RFC4648 codecs is to reject whitespace characters.  If these
+characters are significant in the encoding, then this flag is ignored.
+.TP
 .B CDCF_IGNINVCH
 Ignore any other invalid characters appearing in the input when
 decoding.
 .B CDCF_IGNINVCH
 Ignore any other invalid characters appearing in the input when
 decoding.
index 2c3e6942845fbbfbb3f101e1eb458763481ca268..6155d5a5e640fbeec566bb1473a98056bc1a7ae4 100644 (file)
@@ -58,10 +58,11 @@ typedef struct codec_class {
 #define CDCF_IGNZPAD 32u               /* Ignore zero padding on input */
 #define CDCF_IGNNEWL 64u               /* Ignore newlines on input */
 #define CDCF_IGNINVCH 128u             /* Ignore invalid chars on input */
 #define CDCF_IGNZPAD 32u               /* Ignore zero padding on input */
 #define CDCF_IGNNEWL 64u               /* Ignore newlines on input */
 #define CDCF_IGNINVCH 128u             /* Ignore invalid chars on input */
+#define CDCF_IGNSPC 256u               /* Ignore whitespace on input */
 
 
-#define CDCF_IGNJUNK                   /* Ignore all bad things */     \
+#define CDCF_IGNJUNK                   /* Ignore all bad things */     \
   (CDCF_IGNEQMID | CDCF_IGNZPAD |                                      \
   (CDCF_IGNEQMID | CDCF_IGNZPAD |                                      \
-   CDCF_IGNCASE | CDCF_IGNNEWL | CDCF_IGNINVCH)
+   CDCF_IGNCASE | CDCF_IGNNEWL | CDCF_IGNSPC | CDCF_IGNINVCH)
 
 } codec_class;
 
 
 } codec_class;