util  Check-in [8ce91f9627]

Overview
Comment:fxi ubgs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8ce91f96277451a841312cd7b492af0cd61b7a9bafba744d8981f69c094eff72
User & Date: lexi on 2019-07-19 12:07:46
Other Links: manifest | tags
Context
2019-07-19
20:50
fix usage error check-in: 4af59f8377 user: lexi tags: trunk
12:07
fxi ubgs check-in: 8ce91f9627 user: lexi tags: trunk
11:50
fix static assert check-in: da3eccdcfa user: lexi tags: trunk
Changes

Modified ord.c from [4cd517ba89] to [c509ad7fa4].

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
236
237
238
239
240
241
242

243
244
245
246
247
248
249
...
251
252
253
254
255
256
257

258
259
260
261
262
263
264
...
336
337
338
339
340
341
342

343
344
345
346
347
348

bad run(const int argc, const char** argv) {
#	ifndef _POSIX_IO
		/* fuck your buffering, it only ever makes
		 * things worse */
		setvbuf(stdout,null,_IONBF);
#	endif
	word rv;
	
	enum { set_in, set_out, _set_sz } curset = set_in;
	word base[_set_sz] = { 10, 0 };

	const char* in_vals[argc]; *in_vals = null; /* null-terminated! */
	const char** invalp = in_vals;
	const char* pfxstr;
	forposix(size_t pfxstrlen);

	
	bool raw = false;
	bool prefix = false;
	bool lowercase = false;

	for (const char** arg = argv + 1; *arg != null; ++arg) {
		uint8_t tblval;
................................................................................
	forposix(char* lastptr = ptr);

	for (const char** s = in_vals; *s != null; ++s) {
		word val;
		bad e = atoi(base[set_in], *s, &val);
		if (e == ok) {
			bad e = itoa(base[set_out], val, buf, ptr, &ptr, lowercase);


			if (prefix) {
				if (pfxstr != null) { print(pfxstrlen, pfxstr); }
				else if (base[set_out] < sz(prefixes)) {
					print((size_t)prefixes[base[set_out]][0],
							prefixes[base[set_out]] + 1);
				}
................................................................................
			print(lastptr-ptr, ptr);
			print(1, "\n");
			forposix(lastptr = ptr);
		} else {
			return e;
		}
	}

}

void usage(const char* name) {
#	ifdef _POSIX_IO
		typedef struct pstr { size_t len; const char* str; } pstr;
#		define p(x) {sizeof (x "\n"), (x "\n")}
		size_t namelen = strlen(name);
................................................................................

int main(int argc, const char** argv) {
	if (argc == 0) return -1;
	if (argc == 1) usage(argv[0]);
	bad e = run(argc, argv);
	switch (e) {
		case ok: return 0;

#		define e(kind, desc) case bad_##kind:\
				 say("\x1b[31;1merror:\x1b[m "); say(desc "\n"); break;
			error_list
#		undef e
	}
}







<








<







 







>







 







>







 







>

|




142
143
144
145
146
147
148

149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349

bad run(const int argc, const char** argv) {
#	ifndef _POSIX_IO
		/* fuck your buffering, it only ever makes
		 * things worse */
		setvbuf(stdout,null,_IONBF);
#	endif

	
	enum { set_in, set_out, _set_sz } curset = set_in;
	word base[_set_sz] = { 10, 0 };

	const char* in_vals[argc]; *in_vals = null; /* null-terminated! */
	const char** invalp = in_vals;
	const char* pfxstr;
	forposix(size_t pfxstrlen);

	
	bool raw = false;
	bool prefix = false;
	bool lowercase = false;

	for (const char** arg = argv + 1; *arg != null; ++arg) {
		uint8_t tblval;
................................................................................
	forposix(char* lastptr = ptr);

	for (const char** s = in_vals; *s != null; ++s) {
		word val;
		bad e = atoi(base[set_in], *s, &val);
		if (e == ok) {
			bad e = itoa(base[set_out], val, buf, ptr, &ptr, lowercase);
			if (e != ok) return e;

			if (prefix) {
				if (pfxstr != null) { print(pfxstrlen, pfxstr); }
				else if (base[set_out] < sz(prefixes)) {
					print((size_t)prefixes[base[set_out]][0],
							prefixes[base[set_out]] + 1);
				}
................................................................................
			print(lastptr-ptr, ptr);
			print(1, "\n");
			forposix(lastptr = ptr);
		} else {
			return e;
		}
	}
	return ok;
}

void usage(const char* name) {
#	ifdef _POSIX_IO
		typedef struct pstr { size_t len; const char* str; } pstr;
#		define p(x) {sizeof (x "\n"), (x "\n")}
		size_t namelen = strlen(name);
................................................................................

int main(int argc, const char** argv) {
	if (argc == 0) return -1;
	if (argc == 1) usage(argv[0]);
	bad e = run(argc, argv);
	switch (e) {
		case ok: return 0;
		case fail: return -1;
#		define e(kind, desc) case bad_##kind:\
				 say("\x1b[31;1merror:\x1b[m "); say(desc "\n"); return e;
			error_list
#		undef e
	}
}