Ejemplo n.º 1
0
int configFileHandler(
    void* user, const char *section, const char *name, const char *value)
{
    gamedef_t *gamedef = (gamedef_t*)user;
    int result = -1;
    currentName = (const char*)NULL;
    char *gameSectionPrefix = currentGame->configSectionPrefix;

    // semicolons not strictly needed but good for consistency's sake
    MATCH_SECTION((char*)NULL, "global", handleGlobalSection);
    MATCH_SECTION((char*)NULL, "colors", handleColorsSection);
    MATCH_PLAYER_SECTION((char*)NULL, "player1", 0, handlePlayerSection);
    MATCH_PLAYER_SECTION((char*)NULL, "player2", 1, handlePlayerSection);

    MATCH_SECTION(gameSectionPrefix, "global", handleGlobalSection);
    MATCH_SECTION(gameSectionPrefix, "colors", handleColorsSection);
    MATCH_PLAYER_SECTION(gameSectionPrefix, "player1", 0, handlePlayerSection);
    MATCH_PLAYER_SECTION(gameSectionPrefix, "player2", 1, handlePlayerSection);

    MATCH_SECTION(gameSectionPrefix, "boxIDs", handleBoxIDsSection);

    return result;
}
Ejemplo n.º 2
0
static int layout_ini_handler(void* user, const char* section, const char* name, const char* value)
{
    struct Model *m = (struct Model *)user;
    u16 i;
    int offset_x = 0, offset_y = 0;
    CLOCK_ResetWatchdog();
    int idx;
    if (MATCH_START(name, GUI_QUICKPAGE)) {
        u8 idx = name[9] - '1';
        if (idx >= NUM_QUICKPAGES) {
            printf("%s: Only %d quickpages are supported\n", section, NUM_QUICKPAGES);
            return 1;
        }
        int max = PAGE_GetNumPages();
        for(i = 0; i < max; i++) {
            if(mapstrcasecmp(PAGE_GetName(i), value) == 0) {
                m->pagecfg2.quickpage[idx] = i;
                return 1;
            }
        }
        printf("%s: Unknown page '%s' for quickpage%d\n", section, value, idx+1);
        return 1;
    }
#ifdef ENABLE_320x240_GUI
    static u8 seen_res = 0;
    enum {
        LOWRES = 1,
        HIRES,
    };
    if (! MATCH_SECTION(SECTION_GUI)) {
        if(MATCH_SECTION("gui-320x240")
           && (! ELEM_USED(Model.pagecfg2.elem[0]) || seen_res != HIRES))
        {
            seen_res = LOWRES;
            offset_x = (LCD_WIDTH - 320) / 2;
            offset_y = (LCD_HEIGHT - 240) / 2;
        } else
            return 1;
    } else {
        if (seen_res == LOWRES) {
            memset(&Model.pagecfg2.elem, 0, sizeof(Model.pagecfg2.elem));
        }
        seen_res = HIRES;
    }
#else 
    if (! MATCH_SECTION(SECTION_GUI))
        return 1;
#endif
    for (idx = 0; idx < NUM_ELEMS; idx++) {
        if (! ELEM_USED(Model.pagecfg2.elem[idx]))
            break;
    }
    
    if (idx == NUM_ELEMS) {
        printf("No free element available (max = %d)\n", NUM_ELEMS);
        return 1;
    }
    int type;
    for (type = 0; type < ELEM_LAST; type++)
        if(mapstrcasecmp(name, GetElemName(type)) == 0)
            break;
    if (type == ELEM_LAST)
        return 1;
    int count = 5;
    s16 data[6] = {0};
    const char *ptr = parse_partial_int_list(value, data, &count, S16);
    data[0] += offset_x;
    data[1] += offset_y;
    if (count > 3) {
        printf("Could not parse coordinates from %s=%s\n", name,value);
        return 1;
    }
    switch(type) {
        //case ELEM_MODEL:  //x, y
        case ELEM_VTRIM:  //x, y, src
        case ELEM_HTRIM:  //x, y, src
            data[5] = data[2];
            data[2] = 0;
            break;
        case ELEM_SMALLBOX: //x, y, src
        case ELEM_BIGBOX:   //x. y. src
        {
            s16 src = -1;
            char str[20];
            if (count != 3)
                return 1;
#if HAS_RTC
            for(i = 0; i < NUM_RTC; i++) {
                if(mapstrcasecmp(ptr, RTC_Name(str, i)) == 0) {
                    src = i + 1;
                    break;
                }
            }
#endif
            if (src == -1) {
                for(i = 0; i < NUM_TIMERS; i++) {
                    if(mapstrcasecmp(ptr, TIMER_Name(str, i)) == 0) {
                        src = i + 1 + NUM_RTC;
                        break;
                    }
                }
            }
            if (src == -1) {
                for(i = 0; i < NUM_TELEM; i++) {
                    if(mapstrcasecmp(ptr, TELEMETRY_Name(str, i+1)) == 0) {
                        src = i + 1 + NUM_RTC + NUM_TIMERS;
                        break;
                    }
                }
            }
            if (src == -1) {
                u8 newsrc = get_source(section, ptr);
                if(newsrc >= NUM_INPUTS) {
                    src = newsrc - (NUM_INPUTS + 1 - (NUM_RTC + NUM_TIMERS + NUM_TELEM + 1));
                }
            }
            if (src == -1)
                src = 0;
            data[5] = src;
            break;
        }
        case ELEM_BAR: //x, y, src
        {
            if (count != 3)
                return 1;
            u8 src = get_source(section, ptr);
            if (src < NUM_INPUTS)
                src = 0;
            data[5] = src - NUM_INPUTS;
            break;
        }
        case ELEM_TOGGLE: //x, y, tgl0, tgl1, tgl2, src
        {
            if(count)
                return 1;
            for (int j = 0; j <= NUM_SOURCES; j++) {
                char cmp[10];
                if(mapstrcasecmp(INPUT_SourceNameAbbrevSwitchReal(cmp, j), ptr+1) == 0) {
                    data[5] = j;
                    break;
                }
            }
            break;
        }
    }
    create_element(&m->pagecfg2.elem[idx], type, data);
    return 1;
}
Ejemplo n.º 3
0
static int ini_handler(void* user, const char* section, const char* name, const char* value)
{
    struct Transmitter *t = (struct Transmitter *)user;

    s32 value_int = atoi(value);
    if (section[0] == '\0') {
        if (MATCH_KEY(CURRENT_MODEL)) {
            t->current_model = value_int;
            return 1;
        }
        if (MATCH_KEY(LANGUAGE)) {
            t->language = value_int;
            return 1;
        }
	if (MATCH_KEY(MUSIC_SHUTD)) {
            t->music_shutdown = atoi(value);
            return 1;
        }
        if (MATCH_KEY(MODE)) {
            t->mode = atoi(value);
            return 1;
        }
        if (MATCH_KEY(BRIGHTNESS)) {
            t->brightness = atoi(value);
            return 1;
        }
        if (MATCH_KEY(CONTRAST)) {
            t->contrast = atoi(value);
            return 1;
        }
        if (MATCH_KEY(VOLUME)) {
            t->volume = atoi(value);
            return 1;
        }
        if (MATCH_KEY(VIBRATION)) {
            t->vibration_state = atoi(value);
            return 1;
        }
        if (MATCH_KEY(POWER_ALARM)) {
            t->power_alarm = atoi(value);
            return 1;
        }
        if (MATCH_KEY(BATT_ALARM)) {
            t->batt_alarm = atoi(value);
            return 1;
        }
        if (MATCH_KEY(BATT_CRITICAL)) {
            t->batt_critical = atoi(value);
            return 1;
        }
	if (MATCH_KEY(BATT_WARNING_INTERVAL)) {
            t->batt_warning_interval = atoi(value);
            return 1;
        }
	if (MATCH_KEY(SPLASH_DELAY)) {
            t->splash_delay = atoi(value);
            return 1;
        }
    #if HAS_RTC
        if (MATCH_KEY(TIME_FORMAT)) {
            t->rtcflags = (t->rtcflags & ~TIMEFMT) | (atoi(value) & TIMEFMT);
            return 1;
        }
        if (MATCH_KEY(DATE_FORMAT)) {
            t->rtcflags = (t->rtcflags & ~DATEFMT) | ((atoi(value) << 4) & DATEFMT);
            return 1;
        }
    #endif
    }
    if(MATCH_START(section, SECTION_CALIBRATE) && strlen(section) >= sizeof(SECTION_CALIBRATE)) {
        uint8_t idx = atoi(section + sizeof(SECTION_CALIBRATE)-1);
        if (idx == 0) {
            printf("%s: Unknown Calibration\n", section);
            return 0;
        }
        if (idx > INP_HAS_CALIBRATION) {
            printf("%s: Only %d calibrations are supported\n", section, INP_HAS_CALIBRATION);
            return 1;
        }
        idx--;
        if (MATCH_KEY(CALIBRATE_MAX)) {
            t->calibration[idx].max = value_int;
            return 1;
        }
        if (MATCH_KEY(CALIBRATE_MIN)) {
            t->calibration[idx].min = value_int;
            return 1;
        }
        if (MATCH_KEY(CALIBRATE_ZERO)) {
            t->calibration[idx].zero = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_TOUCH)) {
        if (MATCH_KEY(TOUCH_XSCALE)) {
            t->touch.xscale = value_int;
            return 1;
        }
        if (MATCH_KEY(TOUCH_YSCALE)) {
            t->touch.yscale = value_int;
            return 1;
        }
        if (MATCH_KEY(TOUCH_XOFFSET)) {
            t->touch.xoffset = value_int;
            return 1;
        }
        if (MATCH_KEY(TOUCH_YOFFSET)) {
            t->touch.yoffset = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_AUTODIMMER)) {
        if (MATCH_KEY(AUTODIMMER_TIME)) {
            t->auto_dimmer.timer = value_int;
            return 1;
        }
        if (MATCH_KEY(AUTODIMMER_DIMVALUE)) {
            t->auto_dimmer.backlight_dim_value = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_TIMERSETTINGS)) {
        if (MATCH_KEY(TIMERSETTINGS_PREALERT_TIME)) {
            t->countdown_timer_settings.prealert_time = value_int;
            return 1;
        }
        if (MATCH_KEY(TIMERSETTINGS_PREALERT_INTERVAL)) {
            t->countdown_timer_settings.prealert_interval = value_int;
            return 1;
        }
        if (MATCH_KEY(TIMERSETTINGS_TIMEUP_INTERVAL)) {
            t->countdown_timer_settings.timeup_interval = value_int;
            return 1;
        }
    }
    if (MATCH_SECTION(SECTION_TELEMETRY)) {
        if (MATCH_KEY(TELEM_TEMP)) {
            if(strcasecmp(TELEM_TEMP_VAL[1], value) == 0)
                t->telem |= TELEMUNIT_FAREN;
            return 1;
        }
        if (MATCH_KEY(TELEM_LENGTH)) {
            if(strcasecmp(TELEM_LENGTH_VAL[1], value) == 0)
                t->telem |= TELEMUNIT_FEET;
            return 1;
        }
    }
    printf("Unknown values section: %s key: %s\n", section, name);
    return 0;
}
Ejemplo n.º 4
0
int ini_file_handler (void* pconfig, const char* section,
        const char* key, const char* value)
{
#define MATCH_SECTION(s) strcmp(section, s) == 0
#define MATCH_KEY(s) strcmp(key,s) == 0
    configuration* config = (configuration*)pconfig;
    int handled = 1;
    if (MATCH_SECTION("listen")) {
        if (MATCH_KEY("ip")) {
            config->listen_ip = strdup(value);
        } else if (MATCH_KEY("port")) {
            config->listen_port = atoi(value);
        } else if (MATCH_KEY("visible")) {
            config->listen_visible = atoi(value);
        } else if (MATCH_KEY("debuginfo")) {
            config->listen_debuginfo = atoi(value);
        } else {
            handled = 0;
        }
    } else if (MATCH_SECTION("gae")) {
        if (MATCH_KEY("appid")) {
            config->gae_appid = strdup(value);
        } else if (MATCH_KEY("password")) {
            config->gae_password = strdup(value);
        } else if (MATCH_KEY("path")) {
            config->gae_path = strdup(value);
        } else if (MATCH_KEY("profile")) {
            config->gae_profile = strdup(value);
        } else if (MATCH_KEY("crlf")) {
            config->gae_crlf = atoi(value);
        } else if (MATCH_KEY("validate")) {
            config->gae_validate = atoi(value);
        } else {
            handled = 0;
        }
    } else if (strstr(section,"google_") == section) {
        profile* p = find_profile(section,config,1);
        if (MATCH_KEY("mode")) {
            p->mode = strdup(value);
        } else if (MATCH_KEY("window")) {
            p->window = atoi(value);
        } else if (MATCH_KEY("hosts")) {
            p->hosts = strdup(value);
        } else if (MATCH_KEY("sites")) {
            p->sites = strdup(value);
        } else if (MATCH_KEY("forcehttps")) {
            p->forcehttps = strdup(value);
        } else if (MATCH_KEY("withgae")) {
            p->withgae = strdup(value);
        } else if (MATCH_KEY("withdns")) {
            p->withdns = strdup(value);
        } else {
            handled = 0;
        }
    } else if (MATCH_SECTION("crlf")) {
        if (MATCH_KEY("enable")) {
            config->crlf_enable = atoi(value);
        } else if (MATCH_KEY("dns")) {
            config->crlf_dns = strdup(value);
        } else if (MATCH_KEY("sites")) {
            config->crlf_sites = strdup(value);
        }
    }
    if (!handled) {
        fprintf(stderr,"Unrecognized section:%s key:%s\r\n", section, key);
    }
    return 1;
}