Esempio n. 1
0
bool XMap::LoadMap(const char *szDirectory)
{
    char szLine[1024], szPoolPath[256], *szSetting, *szValue;
    FILE *FSettings;

    strncpy(szPoolPath, szDirectory, 256);
    FSettings = fopen(strcat(szPoolPath, "SETTINGS"), "r");

    if(!FSettings)
    {
        sys_err(__FUNCTION__, __LINE__, "Impossible to load the map %s", szPoolPath);
        return false;
    }

    while(fgets(szLine, 1024, FSettings))
    {
        szSetting = strcln(strtok(szLine, " \t"));
        szValue   = strcln(strtok(NULL, " \t"));

        if(!strcasecmp(szSetting, "INDEX"))             this->iIndex = atoi(szValue);
        else if(!strcasecmp(szSetting, "ENABLED"))      this->bIsEnable = strcmp(szValue, "1") == 0;
        else if(!strcasecmp(szSetting, "HEIGHT"))       this->iHeight = atoi(szValue);
        else if(!strcasecmp(szSetting, "WIDTH"))        this->iWidth = atoi(szValue);

        //else if(!strcasecmp(szSetting, "HEIGHTMAP"))    this->LoadHeightMap(strcat(szPoolPath, szValue));
        //else if(!strcasecmp(szSetting, "ATTRIBUTEMAP")) this->LoadAttributeMap(strcat(szPoolPath, szValue));
        //else if(!strcasecmp(szSetting, "REGEN_NPC"))    this->LoadRegenMap(strcat(szPoolPath, szValue));
        //else if(!strcasecmp(szSetting, "REGEN_MOB"))    this->LoadRegenMap(strcat(szPoolPath, szValue));
        //else if(!strcasecmp(szSetting, "REGEN_BOSS"))   this->LoadRegenMap(strcat(szPoolPath, szValue));
    }

    fclose(FSettings);
}
Esempio n. 2
0
/*
 * switches on hash values of commands to determine
 * what to do
 */
void parsebuf(char *buf, int fd) {
    strcln(buf);
    switch(hash(buf)) {
    /* List */
    case 3999452:
        listpkg(data, fd);
        break;
    /* Query */
    case 138327574:
        /* query */
        break;
    /* Help */
    case 3851113:
        cleanup(data);
        exit(1);
        break;
    /* Quit */
    case 4191875:
        cleanup(data);
        exit(0);
        break;
    default:
        break;
    }
}
Esempio n. 3
0
void str_replace(char **str,const char *new_text) {
	SDELETEA((*str));
	(*str)=strcln(new_text);
}
Esempio n. 4
0
static char*
read_config_file (const char* filename, int flags)
{
    char* config = NULL;
    FILE* f = NULL;
    int error = 0;
    long len;

    assert (filename);

    f = fopen (filename, "r");
    if (f == NULL) {
        error = errno;
        if ((flags & CONF_IGNORE_MISSING) &&
                (error == ENOENT || error == ENOTDIR)) {
            debug ("config file does not exist");
            config = strdup ("\n");
            if (!config)
                errno = ENOMEM;
            return config;
        }
        _p11_message ("couldn't open config file: %s: %s", filename,
                      strerror (error));
        errno = error;
        return NULL;
    }

    /* Figure out size */
    if (fseek (f, 0, SEEK_END) == -1 ||
            (len = ftell (f)) == -1 ||
            fseek (f, 0, SEEK_SET) == -1) {
        error = errno;
        _p11_message ("couldn't seek config file: %s", filename);
        errno = error;
        return NULL;
    }

    if ((config = (char*)malloc (len + 2)) == NULL) {
        _p11_message ("out of memory");
        errno = ENOMEM;
        return NULL;
    }

    /* And read in one block */
    if (fread (config, 1, len, f) != len) {
        error = errno;
        _p11_message ("couldn't read config file: %s", filename);
        errno = error;
        return NULL;
    }

    fclose (f);

    /* Null terminate the data */
    config[len] = '\n';
    config[len + 1] = 0;

    /* Remove nasty dos line endings */
    strcln (config, '\r');

    return config;
}