Annotation of nono/lib/mainapp.cpp, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2018 [email protected]
        !             4: //
        !             5: 
        !             6: #include "header.h"
        !             7: #include "mainapp.h"
        !             8: 
        !             9: // 高速モード (XXX 設定ファイルと含めて見直すこと)
        !            10: bool fast_mode;
        !            11: 
        !            12: // VM ディレクトリ
        !            13: std::string vmdir;
        !            14: 
        !            15: // ログ指定文字列 (-L)
        !            16: char logopt[256];
        !            17: 
        !            18: // 引数 arg のログ指定文字列をパースする。
        !            19: // arg は "foo=1,bar=2" 形式の文字列で、これを分解して
        !            20: // それぞれ担当するオブジェクトのログレベルにセットする。
        !            21: bool
        !            22: parse_logopt(const char *arg, u_int vmtype)
        !            23: {
        !            24:        char *buf;
        !            25:        char *last;
        !            26:        char *p;
        !            27:        bool rv;
        !            28: 
        !            29:        // "help" (完全一致) なら識別子一覧を表示。
        !            30:        if (strcmp(arg, "help") == 0) {
        !            31:                for (auto& obj : gObjects) {
        !            32:                        if (obj->logname != "?") {
        !            33:                                printf("%s\n", obj->logname.c_str());
        !            34:                        }
        !            35:                }
        !            36:                // エイリアスとか
        !            37:                printf("sch -> scheduler\n");
        !            38:                if (vmtype == VM::TYPE_LUNA) {
        !            39:                        printf("ppi -> pio\n");
        !            40:                        printf("scc -> sio\n");
        !            41:                }
        !            42:                printf("all\n");
        !            43:                return false;
        !            44:        }
        !            45: 
        !            46:        rv = false;
        !            47:        buf = strdup(arg);
        !            48:        for (p = strtok_r(buf, ",", &last);
        !            49:                p;
        !            50:                p = strtok_r(NULL, ",", &last))
        !            51:        {
        !            52:                const char *name;
        !            53:                char *v;
        !            54:                int val;
        !            55: 
        !            56:                name = p;
        !            57: 
        !            58:                v = strchr(p, '=');
        !            59:                if (v) {
        !            60:                        *v++ = '\0';
        !            61:                        val = atoi(v);
        !            62:                } else {
        !            63:                        val = 1;
        !            64:                }
        !            65:                // ここで name は変数名、val は値(省略されたら1)
        !            66: 
        !            67:                if (strlen(name) < 1) {
        !            68:                        printf("invalid logname '%s'\n", name);
        !            69:                        goto abort;
        !            70:                }
        !            71: 
        !            72:                // 短縮形とかエイリアスとか
        !            73:                if (strcmp(name, "sch") == 0)
        !            74:                        name = "scheduler";
        !            75:                if (vmtype == VM::TYPE_LUNA) {
        !            76:                        if (strcmp(name, "pio") == 0)
        !            77:                                name = "ppi";
        !            78:                        if (strcmp(name, "scc") == 0)
        !            79:                                name = "sio";
        !            80:                }
        !            81: 
        !            82:                // 比較
        !            83:                if (strcmp(name, "all") == 0) {
        !            84:                        // "all" なら none 以外の全部にセット
        !            85:                        for (auto& obj : gObjects) {
        !            86:                                obj->loglevel = val;
        !            87:                        }
        !            88:                } else {
        !            89:                        // それ以外は一致するキーを探してセット
        !            90:                        std::string sname = name;
        !            91:                        bool found = false;
        !            92:                        for (auto& obj : gObjects) {
        !            93:                                if (obj->logname == sname) {
        !            94:                                        obj->loglevel = val;
        !            95:                                        found = true;
        !            96:                                        break;
        !            97:                                }
        !            98:                        }
        !            99:                        // 見つからない場合はエラー
        !           100:                        if (!found) {
        !           101:                                printf("invalid logname '%s'\n", name);
        !           102:                                goto abort;
        !           103:                        }
        !           104:                }       
        !           105:        }
        !           106: 
        !           107:        rv = true;
        !           108:  abort:
        !           109:        free(buf);
        !           110:        return rv;
        !           111: }

unix.superglobalmegacorp.com

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