Annotation of nono/util/autoserial/res2h.cpp, revision 1.1

1.1     ! root        1: #include <vector>
        !             2: #include <stdio.h>
        !             3: 
        !             4: template <class T>
        !             5: std::vector<T>
        !             6: splitx(const char *buf)
        !             7: {
        !             8:        std::vector<T> rv;
        !             9:        T v = 0;
        !            10:        bool a = false;
        !            11: 
        !            12:        for (; *buf; buf++) {
        !            13:                char c = *buf;
        !            14:                if ('0' <= c && c <= '9') {
        !            15:                        v = v * 16 + (c - '0');
        !            16:                        a = true;
        !            17:                } else if ('A' <= c && c <= 'F') {
        !            18:                        v = v * 16 + (c - 'A' + 10);
        !            19:                        a = true;
        !            20:                } else if ('a' <= c && c <= 'f') {
        !            21:                        v = v * 16 + (c - 'a' + 10);
        !            22:                        a = true;
        !            23:                } else {
        !            24:                        if (a) {
        !            25:                                rv.push_back(v);
        !            26:                                v = 0;
        !            27:                                a = false;
        !            28:                        }
        !            29:                }
        !            30:        }
        !            31:        if (a) {
        !            32:                rv.push_back(v);
        !            33:        }
        !            34:        return rv;
        !            35: }
        !            36: 
        !            37: int
        !            38: main(int ac, char *av[])
        !            39: {
        !            40:        int d[2];
        !            41:        int line = 0;
        !            42:        char buf[1024];
        !            43: 
        !            44:        for (;;line = (line + 1) % 5) {
        !            45:                auto p = fgets(buf, sizeof(buf), stdin);
        !            46:                if (p == NULL) {
        !            47:                        return 0;
        !            48:                }
        !            49:                switch (line) {
        !            50:                 case 0:
        !            51:                 case 1:
        !            52:                        d[line] = splitx<int>(buf)[1];
        !            53:                        break;
        !            54:                 case 2 ... 3:
        !            55:                        break;
        !            56:                 case 4:
        !            57:                        auto v0 = splitx<int>(buf);
        !            58:                        auto v = decltype(v0) (v0.begin() + 1, v0.end());
        !            59:                        int y = d[1] & 0xff;
        !            60:                        int m = (d[1] >> 8) & 0xff;
        !            61:                        int md = (d[1] >> 16) & 0xff;
        !            62:                        int wd = (d[1] >> 24) & 0xff;
        !            63:                        int h = d[0] & 0xff;
        !            64:                        int n = (d[0] >> 8) & 0xff;
        !            65:                        int s = (d[0] >> 16) & 0xff;
        !            66:                        printf("%02x/%02x/%02x(%02x) %02x:%02x:%02x"
        !            67:                                " | %02x/%02x/%02x(%02x) %02x:%02x:%02x\n",
        !            68:                                y, m, md, wd, h, n, s,
        !            69:                                v[7], v[6], v[5], v[4], v[3], v[2], v[1]);
        !            70:                        break;
        !            71:                }
        !            72:        }
        !            73:        return 0;
        !            74: }
        !            75: 

unix.superglobalmegacorp.com

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