util  Diff

Differences From Artifact [8e7c9355c5]:

To Artifact [9504e2c85c]:

  • File ord.c — part of check-in [6a14de1811] at 2019-07-20 23:37:03 on branch trunk — udpate xpriv to use sysv shmem by default; give iaia an option to generate its own types, and allow selecting between 7-bit and 8-bit encodings for ascii (defaulting to 8-bit); update mkpw to work with new iaia; update ord to add flag controlling byte length (7 or 8) for iaia's ascii mode (user: lexi, size: 10625) [annotate] [blame] [check-ins using]

    81     81   	arg_asc,
    82     82   
    83     83   	arg_bin, arg_trn, arg_oct, arg_dec,
    84     84   	arg_duo, arg_hex, arg_b32, arg_b64,
    85     85   
    86     86   	switch_prefix, param_prefix,
    87     87   	switch_lowercase,
           88  +	switch_7bit,
    88     89   
    89     90   	arg_ebcdic,
    90     91   };
    91     92   
    92     93   word bases[] = {
    93     94   	[arg_asc] =  0,
    94     95   	[arg_bin] =  2,
................................................................................
   124    125   	{arg_duo, "duo"}, {arg_duo, "duodecimal"},
   125    126   	{arg_hex, "hex"}, {arg_hex, "hexadecimal"},
   126    127   
   127    128   	{arg_hex, "b32"}, {arg_hex, "base32"}, /* not padded! */
   128    129   
   129    130   	{switch_prefix, "-p"}, {switch_prefix, "--prefix"},
   130    131   	{switch_lowercase, "-l"}, {switch_lowercase, "--lowercase"},
          132  +	{switch_7bit, "-7"}, {switch_7bit, "--7bit"},
   131    133   	{param_prefix, "-m"}, {param_prefix, "--manual-prefix"},
   132    134   
   133    135   	{arg_ebcdic, "ebcdic"},
   134    136   };
   135    137   
   136    138   /* import the conversion utilities */
   137    139   typedef bad iaia_error_type;
................................................................................
   138    140   typedef word iaia_word_type;
   139    141   enum /* iaia synonyms */ {
   140    142   	iaia_e_ok = ok,
   141    143   	iaia_e_domain = bad_domain,
   142    144   	iaia_e_base = bad_base,
   143    145   	iaia_e_overflow = bad_overflow,
   144    146   };
          147  +bool ascii_7bit = false;
          148  +#define _IAIA_EXP_ASCFORM ascii_7bit
          149  +#define _IAIA_EXTERNAL_TYPES
   145    150   #include "clib/iaia.c"
   146    151   
   147    152   bad run(const int argc, const char** argv) {
   148    153   #	ifndef _POSIX_IO
   149    154   		/* fuck your buffering, it only ever makes
   150    155   		 * things worse */
   151    156   		setvbuf(stdout,null,_IONBF);
................................................................................
   161    166   	
   162    167   	bool raw = false;
   163    168   	bool prefix = false;
   164    169   	bool lowercase = false;
   165    170   
   166    171   	for (const char** arg = argv + 1; *arg != null; ++arg) {
   167    172   		uint8_t tblval;
   168         -		if (*arg[0] == '%') { ++ *arg; goto number; } else
          173  +		if (*arg[0] == '`') { ++ *arg; goto number; } else
   169    174   		if (!raw && (tblget(sz(argtbl),argtbl, *arg, &tblval) == ok)) {
   170    175   			enum argument symbol = (enum argument) tblval;
   171    176   			switch (symbol) {
   172    177   				case arg_to: {
   173    178   					if (curset == set_out) return bad_syntax;
   174    179   					else curset = set_out;
   175    180   				} break;
................................................................................
   197    202   					forposix(pfxstrlen = strlen(pfxstr));
   198    203   					++arg;
   199    204   				} break;
   200    205   
   201    206   				/* specify an automatic output prefix */
   202    207   				case switch_prefix: { prefix = true; pfxstr = null; } break;
   203    208   				case switch_lowercase: { lowercase = true; } break;
          209  +				case switch_7bit: { ascii_7bit = true; } break;
   204    210   
   205    211   				default: {
   206    212   					/* assume base shorthand */
   207    213   					base[curset] = bases[symbol];
   208    214   				}
   209    215   			}
   210    216   		} else /* bad_find */ number: {
................................................................................
   286    292   					lit("base") " " box("0-9") plus OR "asc")),
   287    293   		}, ints[] = {
   288    294   			p("default base: \x1b[94m.+\x1b[m"),
   289    295   			p("binary literal: "lit("0b") box("01") plus),
   290    296   			p("ternary literal: "lit("0t") box("012") plus),
   291    297   			p("hex literal: "lit("0x") box("0-9A-Fa-f") plus),
   292    298   			p("ascii literal: "lit("@") "\x1b[94m.+\x1b[m"),
   293         -			p("interpret any string (e.g. a keyword) as integer: " lit("%") box("0-9A-Za-z") plus),
          299  +			p("interpret any string (e.g. a keyword) as integer: " lit("`") box("0-9A-Za-z") plus),
   294    300   		}, opts[] = {
   295    301   			p("-p --prefix       : print known prefix codes on output strings"),
   296    302   			p("-m --manual-prefix: specify a manual prefix to print before each number"),
   297    303   			p("-l --lowercase    : prefer lowercase for case-insensitive bases"),
          304  +			p("-7 --7bit         : encode ascii in 7-bit space instead of keeping the"),
          305  +			p("                    eighth empty bit. if this option is used, ascii"),
          306  +			p("                    strings will be maximally compact, but will not match"),
          307  +			p("                    the way they are stored in computer memory!"),
          308  +			/* p("-u --utf           : allow non-ascii input"), */
   298    309   		};
   299    310   #	undef p
   300    311   #	undef OR
   301    312   #	undef plus
   302    313   
   303    314   #	define hl_on  "\x1b[;1m" 
   304    315   #	define hl_off "\x1b[m"