Exemplo n.º 1
0
int grifo_main(int argc, char *argv[])
{
	int nelem, m;

	debug_print("init starting\n");

	nelem = ReadCommands("init.ini");

	// Nothing good in the file, give up
	if (nelem == 0) {
		debug_print("init no init.ini entries\n");
		return EXIT_POWER_OFF;
	}

	// One menu item, run it if autobooting
	if ((nelem == 1) && MenuRecord[0].ok) {
	    debug_print("init boot only\n");
		chain(MenuRecord[0].command);
	}

	// menu for non-auto-boot
	debug_print("init choosing...\n");
	m = MenuHandler();
	if (MenuRecord[m].ok) {
		debug_printf("init chose %d\n", m);
		chain(MenuRecord[m].command);
	}

	return EXIT_POWER_OFF;
}
Exemplo n.º 2
0
static int ReadMenu(CurPos &cp, const char *MenuName) {
    unsigned char obj;
    unsigned short len;

    int menu = -1, item = -1;

    menu = NewMenu(MenuName);

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_ITEM:
            {
                if (len == 0) {
                    item = NewItem(menu, 0);
                } else {
                    const char *s = GetCharStr(cp, len);
                    int Cmd;
                    if (s == 0) return -1;
                    item = NewItem(menu, s);
                    if ((obj = GetObj(cp, len)) != CF_MENUSUB) return -1;
                    if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
                    Menus[menu].Items[item].Cmd = Cmd + 65536;
                }
            }
            break;
        case CF_SUBMENU:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_NORMAL);
            }
            break;

        case CF_SUBMENUCOND:
            {
                const char *s = GetCharStr(cp, len);
                const char *w;

                if ((obj = GetObj(cp, len)) != CF_STRING) return -1;
                if ((w = GetCharStr(cp, len)) == 0) return -1;
                item = NewSubMenu(menu, s, GetMenuId(w), SUBMENU_CONDITIONAL);
            }
            break;

        case CF_END:
            return 0;
        default:
            return -1;
        }
    }
    return -1;
}
Exemplo n.º 3
0
static int ReadEventMap(CurPos &cp, EEventMap *Map, const char * /*MapName*/) {
    unsigned char obj;
    unsigned short len;

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_KEY:
            {
                EKey *Key;
                const char *s;
                int Cmd;

                if ((s = GetCharStr(cp, len)) == 0) return -1;
                if ((Key = SetKey(Map, s)) == 0) return -1;
                if ((obj = GetObj(cp, len)) != CF_KEYSUB) return -1;
                if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
                Key->Cmd = Cmd;
            }
            break;

#ifdef CONFIG_ABBREV
        case CF_ABBREV:
            {
                EAbbrev *Ab;
                const char *s;
                const char *x;
                int Cmd;

                if ((s = GetCharStr(cp, len)) == 0) return -1;
                obj = GetObj(cp, len);
                if (obj == CF_KEYSUB) {
                    if ((Cmd = ReadCommands(cp, 0)) == -1) return -1;
                    Ab = new EAbbrev(s, Cmd);
                } else if (obj == CF_STRING) {
                    x = GetCharStr(cp, len);
                    Ab = new EAbbrev(s, x);
                } else
                    return -1;
                if (Ab) {
                    Map->AddAbbrev(Ab);
                }
            }
            break;
#endif

        case CF_SETVAR:
            {
                long what;

                if (GetNum(cp, what) == 0) return -1;
                switch (GetObj(cp, len)) {
                case CF_STRING:
                    {
                        const char *val = GetCharStr(cp, len);
                        if (len == 0) return -1;
                        if (SetEventString(Map, what, val) != 0) return -1;
                    }
                    break;
                    /*                case CF_INT:
                     {
                     long num;

                     if (GetNum(cp, num) == 0) return -1;
                     if (SetModeNumber(Mode, what, num) != 0) return -1;
                     }
                     break;*/
                default:
                    return -1;
                }
            }
            break;
        case CF_END:
            return 0;
        default:
            return -1;
        }
    }
    return -1;
}
Exemplo n.º 4
0
static int ReadConfigFile(CurPos &cp) {
    unsigned char obj;
    unsigned short len;

    {
        const char *p;

        obj = GetObj(cp, len);
        assert(obj == CF_STRING);
        if ((p = GetCharStr(cp, len)) == 0)
            return -1;

        if (ConfigSourcePath)
            free(ConfigSourcePath);

        ConfigSourcePath = strdup(p);
    }

    while ((obj = GetObj(cp, len)) != 0xFF) {
        switch (obj) {
        case CF_SUB:
            {
                const char *CmdName = GetCharStr(cp, len);

                if (ReadCommands(cp, CmdName) == -1) return -1;
            }
            break;
        case CF_MENU:
            {
                const char *MenuName = GetCharStr(cp, len);

                if (ReadMenu(cp, MenuName) == -1) return -1;
            }
            break;
        case CF_EVENTMAP:
            {
                EEventMap *EventMap = 0;
                const char *MapName = GetCharStr(cp, len);
                const char *UpMap = 0;

                if ((obj = GetObj(cp, len)) != CF_PARENT) return -1;
                if (len > 0)
                    if ((UpMap = GetCharStr(cp, len)) == 0) return -1;

                // add new mode
                if ((EventMap = FindEventMap(MapName)) == 0) {
                    EEventMap *OrgMap = 0;

                    if (strcmp(UpMap, "") != 0)
                        OrgMap = FindEventMap(UpMap);
                    EventMap = new EEventMap(MapName, OrgMap);
                } else {
                    if (EventMap->Parent == 0)
                        EventMap->Parent = FindEventMap(UpMap);
                }
                if (ReadEventMap(cp, EventMap, MapName) == -1) return -1;
            }
            break;

        case CF_COLORIZE:
            {
                EColorize *Mode = 0;
                const char *ModeName = GetCharStr(cp, len);
                const char *UpMode = 0;

                if ((obj = GetObj(cp, len)) != CF_PARENT) return -1;
                if (len > 0)
                    if ((UpMode = GetCharStr(cp, len)) == 0) return -1;

                // add new mode
                if ((Mode = FindColorizer(ModeName)) == 0)
                    Mode = new EColorize(ModeName, UpMode);
                else {
                    if (Mode->Parent == 0)
                        Mode->Parent = FindColorizer(UpMode);
                }
                if (ReadColorize(cp, Mode, ModeName) == -1)
                    return -1;
            }
            break;

        case CF_MODE:
            {
                EMode *Mode = 0;
                const char *ModeName = GetCharStr(cp, len);
                const char *UpMode = 0;

                if ((obj = GetObj(cp, len)) != CF_PARENT) return -1;
                if (len > 0)
                    if ((UpMode = GetCharStr(cp, len)) == 0) return -1;

                // add new mode
                if ((Mode = FindMode(ModeName)) == 0) {
                    EMode *OrgMode = 0;
                    EEventMap *Map;

                    if (strcmp(UpMode, "") != 0)
                        OrgMode = FindMode(UpMode);
                    Map = FindEventMap(ModeName);
                    if (Map == 0) {
                        EEventMap *OrgMap = 0;

                        if (strcmp(UpMode, "") != 0)
                            OrgMap = FindEventMap(UpMode);
                        Map = new EEventMap(ModeName, OrgMap);
                    }
                    Mode = new EMode(OrgMode, Map, ModeName);
                    Mode->fNext = Modes;
                    Modes = Mode;
                } else {
                    if (Mode->fParent == 0)
                        Mode->fParent = FindMode(UpMode);
                }
                if (ReadMode(cp, Mode, ModeName) == -1)
                    return -1;
            }
            break;
        case CF_OBJECT:
            {
                const char *ObjName;

                if ((ObjName = GetCharStr(cp, len)) == 0)
                    return -1;
                if (ReadObject(cp, ObjName) == -1)
                    return -1;
            }
            break;
        case CF_EOF:
            return 0;
        default:
            return -1;
        }
    }
    return -1;
}