util  Diff

Differences From Artifact [4cd517ba89]:

To Artifact [c509ad7fa4]:


   142    142   
   143    143   bad run(const int argc, const char** argv) {
   144    144   #	ifndef _POSIX_IO
   145    145   		/* fuck your buffering, it only ever makes
   146    146   		 * things worse */
   147    147   		setvbuf(stdout,null,_IONBF);
   148    148   #	endif
   149         -	word rv;
   150    149   	
   151    150   	enum { set_in, set_out, _set_sz } curset = set_in;
   152    151   	word base[_set_sz] = { 10, 0 };
   153    152   
   154    153   	const char* in_vals[argc]; *in_vals = null; /* null-terminated! */
   155    154   	const char** invalp = in_vals;
   156    155   	const char* pfxstr;
   157    156   	forposix(size_t pfxstrlen);
   158         -
   159    157   	
   160    158   	bool raw = false;
   161    159   	bool prefix = false;
   162    160   	bool lowercase = false;
   163    161   
   164    162   	for (const char** arg = argv + 1; *arg != null; ++arg) {
   165    163   		uint8_t tblval;
................................................................................
   236    234   	forposix(char* lastptr = ptr);
   237    235   
   238    236   	for (const char** s = in_vals; *s != null; ++s) {
   239    237   		word val;
   240    238   		bad e = atoi(base[set_in], *s, &val);
   241    239   		if (e == ok) {
   242    240   			bad e = itoa(base[set_out], val, buf, ptr, &ptr, lowercase);
          241  +			if (e != ok) return e;
   243    242   
   244    243   			if (prefix) {
   245    244   				if (pfxstr != null) { print(pfxstrlen, pfxstr); }
   246    245   				else if (base[set_out] < sz(prefixes)) {
   247    246   					print((size_t)prefixes[base[set_out]][0],
   248    247   							prefixes[base[set_out]] + 1);
   249    248   				}
................................................................................
   251    250   			print(lastptr-ptr, ptr);
   252    251   			print(1, "\n");
   253    252   			forposix(lastptr = ptr);
   254    253   		} else {
   255    254   			return e;
   256    255   		}
   257    256   	}
          257  +	return ok;
   258    258   }
   259    259   
   260    260   void usage(const char* name) {
   261    261   #	ifdef _POSIX_IO
   262    262   		typedef struct pstr { size_t len; const char* str; } pstr;
   263    263   #		define p(x) {sizeof (x "\n"), (x "\n")}
   264    264   		size_t namelen = strlen(name);
................................................................................
   336    336   
   337    337   int main(int argc, const char** argv) {
   338    338   	if (argc == 0) return -1;
   339    339   	if (argc == 1) usage(argv[0]);
   340    340   	bad e = run(argc, argv);
   341    341   	switch (e) {
   342    342   		case ok: return 0;
          343  +		case fail: return -1;
   343    344   #		define e(kind, desc) case bad_##kind:\
   344         -				 say("\x1b[31;1merror:\x1b[m "); say(desc "\n"); break;
          345  +				 say("\x1b[31;1merror:\x1b[m "); say(desc "\n"); return e;
   345    346   			error_list
   346    347   #		undef e
   347    348   	}
   348    349   }