Example #1
0
bool CVarSet::bLoad(void) {
    FILE *fp;
    char In[256];
    char temp[1024];
    float f;
    vector <string> lin;
    fp=fopen(filename.c_str(),"rt");
    if(!fp) return false;
    while(fgets(In,255,fp)) {
        In[strlen(In)-1]=0;
        lin = dlcs_explode("=",In);
        if(lin.size()>1) {
            set_cvar(lin[0].c_str(),(char *)lin[1].c_str());
        }
    }
    fclose(fp);
    return true;
}
Example #2
0
static void
set_cvar
(struct app* app,
 const char* cvar_name,
 const struct app_cvar* cvar,
 const struct app_cmdarg_value* value_list,
 size_t count)
{
    float f3[3] = { 0.f, 0.f, 0.f };
    size_t id = 0;
    long int i = 0;
    float f = 0.f;
    char* ptr = NULL;
    assert(count > 0 && value_list[0].is_defined);

#define ERR_MSG(msg, id) \
     APP_PRINT_ERR \
      (app->logger, "%s: " msg " `%s'\n", cvar_name, value_list[id].data.string)

    switch(cvar->type) {
    case APP_CVAR_BOOL:
        i = strtol(value_list[0].data.string, &ptr, 10);
        if(*ptr != '\0') {
            ERR_MSG("unexpected non integer value", 0);
        } else {
            APP(set_cvar(app, cvar_name, APP_CVAR_BOOL_VALUE(i != 0L)));
        }
        break;
    case APP_CVAR_INT:
        i = strtol(value_list[0].data.string, &ptr, 10);
        if(*ptr != '\0') {
            ERR_MSG("unexpected non integer value", 0);
        } else {
            if(i > INT_MAX || i < INT_MIN) {
                ERR_MSG("out of range integer value", 0);
            } else {
                APP(set_cvar(app, cvar_name, APP_CVAR_INT_VALUE(i)));
            }
        }
        break;
    case APP_CVAR_FLOAT:
        f = strtof(value_list[0].data.string, &ptr);
        if(*ptr != '\0') {
            ERR_MSG("unexpected non real value", 0);
        } else {
            APP(set_cvar(app, cvar_name, APP_CVAR_FLOAT_VALUE(f)));
        }
        break;
    case APP_CVAR_FLOAT3:
        f3[0] = cvar->value.real3[0];
        f3[1] = cvar->value.real3[1];
        f3[2] = cvar->value.real3[2];
        for(id = 0; value_list[id].is_defined && id < count && id < 3; ++id) {
            f = strtof(value_list[id].data.string, &ptr);
            if(*ptr != '\0') {
                ERR_MSG("unexpected non real value", id);
            } else {
                f3[id] = f;
            }
        }
        APP(set_cvar(app, cvar_name, APP_CVAR_FLOAT3_VALUE(f3[0], f3[1], f3[2])));
        break;
    case APP_CVAR_STRING:
        APP(set_cvar
            (app, cvar_name, APP_CVAR_STRING_VALUE(value_list[0].data.string)));
        break;
    default:
        assert(0);
        break;
    }

#undef ERR_MSG
}