File:  [Isaki's NoNo m68k/m88k emulator] / nono / util / autoserial / res2h.cpp
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:05:05 2026 UTC (3 months ago) by root
Branches: MAIN, Isaki
CVS tags: v027, v026, v025, v024, v023, v022, v021, v020, v019, v018, v017, v016, v015, v014, HEAD
nono 0.2.3

#include <vector>
#include <stdio.h>

template <class T>
std::vector<T>
splitx(const char *buf)
{
	std::vector<T> rv;
	T v = 0;
	bool a = false;

	for (; *buf; buf++) {
		char c = *buf;
		if ('0' <= c && c <= '9') {
			v = v * 16 + (c - '0');
			a = true;
		} else if ('A' <= c && c <= 'F') {
			v = v * 16 + (c - 'A' + 10);
			a = true;
		} else if ('a' <= c && c <= 'f') {
			v = v * 16 + (c - 'a' + 10);
			a = true;
		} else {
			if (a) {
				rv.push_back(v);
				v = 0;
				a = false;
			}
		}
	}
	if (a) {
		rv.push_back(v);
	}
	return rv;
}

int
main(int ac, char *av[])
{
	int d[2];
	int line = 0;
	char buf[1024];

	for (;;line = (line + 1) % 5) {
		auto p = fgets(buf, sizeof(buf), stdin);
		if (p == NULL) {
			return 0;
		}
		switch (line) {
		 case 0:
		 case 1:
			d[line] = splitx<int>(buf)[1];
			break;
		 case 2 ... 3:
			break;
		 case 4:
			auto v0 = splitx<int>(buf);
			auto v = decltype(v0) (v0.begin() + 1, v0.end());
			int y = d[1] & 0xff;
			int m = (d[1] >> 8) & 0xff;
			int md = (d[1] >> 16) & 0xff;
			int wd = (d[1] >> 24) & 0xff;
			int h = d[0] & 0xff;
			int n = (d[0] >> 8) & 0xff;
			int s = (d[0] >> 16) & 0xff;
			printf("%02x/%02x/%02x(%02x) %02x:%02x:%02x"
				" | %02x/%02x/%02x(%02x) %02x:%02x:%02x\n",
				y, m, md, wd, h, n, s,
				v[7], v[6], v[5], v[4], v[3], v[2], v[1]);
			break;
		}
	}
	return 0;
}


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.