示例#1
0
bool DLCODESTORM::dlcs_dir_to_file(char *szDir,char *szFile,char *szWildCard) {
    FILE *fp;
    fp=fopen(szFile,"wt");
    if(!fp) return false;
    DIR *dpdf;
    struct dirent *epdf;
    dpdf = opendir(szDir);
    if (dpdf != NULL) {
        while (epdf = readdir(dpdf)) {
            if(!((dlcs_strcasecmp(epdf->d_name,".")) || (dlcs_strcasecmp(epdf->d_name,".."))))
               if(!dlcs_isdir(epdf->d_name))
                fputs(epdf->d_name,fp);
        }
    }
    closedir(dpdf);
    fclose(fp);
    return true;
}
示例#2
0
int CVarSet::get_cvartype(const char * s) {
    vector <string> vt;
    vt=dlcs_explode("_",s);
    if(vt.size()>1) {
        if(dlcs_strcasecmp(vt[0].c_str(),"b"))  return CVAR_BOOL;
        if(dlcs_strcasecmp(vt[0].c_str(),"s"))  return CVAR_STRING;
        if(dlcs_strcasecmp(vt[0].c_str(),"c"))  return CVAR_CHAR;
        if(dlcs_strcasecmp(vt[0].c_str(),"uc")) return CVAR_UCHAR;
        if(dlcs_strcasecmp(vt[0].c_str(),"i"))  return CVAR_INT;
        if(dlcs_strcasecmp(vt[0].c_str(),"ui")) return CVAR_UINT;
        if(dlcs_strcasecmp(vt[0].c_str(),"l"))  return CVAR_LONG;
        if(dlcs_strcasecmp(vt[0].c_str(),"ul")) return CVAR_ULONG;
        if(dlcs_strcasecmp(vt[0].c_str(),"f"))  return CVAR_FLOAT;
    }
    return CVAR_NULL;
}
示例#3
0
vector<string> DLCODESTORM::dlcs_dir_to_vector(char* szDir, char* szWildCard) {
    vector <string> diro;
    string f;
    string d;
    d.assign(szDir);
    diro.clear();
    DIR *dpdf;
    struct dirent *epdf;
    dpdf = opendir(szDir);
    if (dpdf != NULL) {
        while (epdf = readdir(dpdf)) {
            if((!((dlcs_strcasecmp(epdf->d_name,".")) || (dlcs_strcasecmp(epdf->d_name,".."))))) {
                f.assign(va("%s%c%s",szDir,PATH_SEP,epdf->d_name));
                if(!dlcs_isdir(f.c_str())) {
                    diro.push_back(f);
                }
                else {
                    vector<string>x=dlcs_dir_to_vector(f.c_str(),szWildCard);
                    diro.insert( diro.end(), x.begin(), x.end() );
                }
            }
        }
    }
    closedir(dpdf);
    return diro;
/* #include <fnmatch.h>
int fnmatch(const char *pattern, const char *string, int flags);
Description
The fnmatch() function checks whether the string argument matches the pattern argument, which is a shell wildcard pattern.
The flags argument modifies the behavior; it is the bitwise OR of zero or more of the following flags:
FNM_NOESCAPE If this flag is set, treat backslash as an ordinary character, instead of an escape character.
FNM_PATHNAME If this flag is set, match a slash in string only with a slash in pattern and not by an asterisk (*) or a question mark (?) metacharacter, nor by a bracket expression ([]) containing a slash.
FNM_PERIOD   If this flag is set, a leading period in string has to be matched exactly by a period in pattern. A period is considered to be leading if it is the first character in string, or if both FNM_PATHNAME is set and the period immediately follows a slash.
FNM_FILE_NAME This is a GNU synonym for FNM_PATHNAME.
FNM_LEADING_DIR If this flag (a GNU extension) is set, the pattern is considered to be matched if it matches an initial segment of string which is followed by a slash. This flag is mainly for the internal use of glibc and is only implemented in certain cases.
FNM_CASEFOLD  If this flag (a GNU extension) is set, the pattern is matched case-insensitively.
Return Value  Zero if string matches pattern, FNM_NOMATCH if there is no match or another nonzero value if there is an error.*/
}
示例#4
0
bool CC_Data::bLoad(void) {
    SetToDefaults();
    pLog->_Add("LOADING CONFIG FROM %s",filename.c_str());
    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) {
            strcpy(temp,lin[1].c_str());
            if(dlcs_strcasecmp(lin[0].c_str(),"name")) {
                Name.assign(lin[1].c_str());
                pLog->_Add(" Name [%s]",Name.c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"password")) {
                Password.assign(lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"save password")) {
                bSavePassword=dlcs_istrue(lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"last server")) {
                strcpy(ServerName,lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"last server ip")) {
                strcpy(IPAddress,lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"port")) {
                strcpy(Port,lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"log")) {
                bLog=dlcs_istrue(temp);
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"download")) {
                bDownload=dlcs_istrue(lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"sound volume")) {
                f=atof(lin[1].c_str());
                if(f>100) f=100;
                if(f<0)   f=0;
                fSoundVolume=f;
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"music volume")) {
                f=atof(lin[1].c_str());
                if(f>100) f=100;
                if(f<0)   f=0;
                fMusicVolume=f;
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"sound")) {
                bSound=dlcs_istrue(lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"music")) {
                bMusic=dlcs_istrue(lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"master server")) {
                strcpy(MasterIPAddress,lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"master server port")) {
                strcpy(MasterPort,lin[1].c_str());
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"fullscreen")) {
                bFullScreen=dlcs_istrue(temp);
                pLog->_Add(" bFullScreen [%d]",bFullScreen);
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"screen width")) {
                ScreenWidth=atoi(lin[1].c_str());
                pLog->_Add(" ScreenWidth [%d]",ScreenWidth);
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"screen height")) {
                ScreenHeight=atoi(lin[1].c_str());
                pLog->_Add(" ScreenHeight [%d]",ScreenHeight);
                continue;
            }
            if(dlcs_strcasecmp(lin[0].c_str(),"screen colors")) {
                ScreenColors=atoi(lin[1].c_str());
                pLog->_Add(" ScreenColors [%d]",ScreenColors);
                continue;
            }
        }
    }
    fclose(fp);
    if(bSavePassword==false) {
        Password.clear();
        bSave();
    }
    return true;
}
示例#5
0
void CVarSet::set_cvar(const char *name, char *value) {
    
    // printf("CVarSet: Setting %s to %s\n",name,value);
    int ivartype;
    bool bFound;
    int *newint;
    ivartype=get_cvartype(name);
    bFound=0;
    for( svm_i=varmap.begin(); svm_i!=varmap.end(); ++svm_i) {
        if( dlcs_strcasecmp( ((*svm_i).first.c_str()), name) ) {
            bFound=1;
            break;
        }
    }
    if(!bFound) {
        char *newchars=new char[256];
        varmap[name]=newchars;
        strcpy(newchars,value);
    } else {
        strcpy( (char *)(varmap.find(name)->second), value);
    }
    /*
    switch(ivartype) {
    case CVAR_BOOL:
        (*(bool *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_INT:
        if(!bFound) {
            newint = new int(atoi(value));
            varmap[name]=newint;
        } else {
            (*(int *)(*svm_i).second) = atoi(value);
        }
        break;
    case CVAR_UINT:
        (*(unsigned int *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_CHAR:
        (*(char *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_UCHAR:
        (*(unsigned char *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_FLOAT:
        (*(float *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_LONG:
        (*(long *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_ULONG:
        (*(unsigned long *)(*svm_i).second) = atoi(value);
        break;
    case CVAR_STRING:
        if(!bFound) {
            char *newchars=new char[256];
            varmap[name]=newchars;
            strcpy(newchars,value);
        } else {
            strcpy( (char *)(varmap.find(name)->second), value);
        }
        break;
    }
    */
}