Example #1
0
void Conf::load(kchar* cfgFile)
{
    FILE* pf = _ttfopen(cfgFile, "rb");
    if(pf) {
        AutoCall<int (*)(FILE*), FILE*>    _a(::fclose, pf);
        char        pred[128];
        char        val[128];
        char        line[256];
        bool        inComment = false;
        try {
            while(!feof(pf)) {

                if(fgets(line,255,pf)) {
                    str_prepline(line);
                    if(*line==0)
                        continue;

                    if(inComment || *line=='#')
                        continue;

                    kchar* pnext = str_ccpy(pred, line,'=');

                    if(*pred=='[') {
                        str_lrtim(pred);
                        _section = pred;
                        continue;

                    } else   if(*pred=='}') {
                        _assign("}", " ", 0);
                    }
                    if(pnext && *pnext) {
                        str_scpy(val, (char*)pnext+1, "#");

                        str_lrtim(val);
                        str_lrtim(pred);
                        _assign(pred, val, 0);
                    }

                } else
                    break;
                if(feof(pf)) {
                    break;
                }
            }
        } catch(int& err) {
        }
    } else {
        printf( "Cannot find configuration file in curent folder\r\n");
        exit(0);
    }
}
Example #2
0
//-----------------------------------------------------------------------------
bool Conf::load(const char* cfgFile)
{
    FILE* pf;
    char locations[512];

    ::sprintf(locations,"/etc/%s",cfgFile);
    pf = _ttfopen(locations, "rb"); if(pf) goto done;

    ::sprintf(locations,"/home/%s/.%s",getenv("USER"),cfgFile);
    pf = _ttfopen(locations, "rb"); if(pf) goto done;

    pf = _ttfopen(cfgFile, "rb");

done:
    if(pf)
    {
        AutoCall<int (*)(FILE*), FILE*>    _a(::fclose, pf);
        char        pred[128];
        char        val[128];
        char        line[512];
        bool        in_comment = false;
        try
        {
            while(!::feof(pf))
            {
                if(::fgets(line,512,pf))
                {
                    ::str_prepline(line);
                    if(*line==0)
                        continue;
                    if(in_comment || *line=='#')
                        continue;
                    const char* pnext = ::str_ccpy(pred, line,'=');
                    if(*pred=='[')
                    {
                        str_lrtim(pred);
                        _section = pred;
                        continue;

                    }
                    else   if(*pred=='}')
                    {
                        _assign("}", " ", 0);
                    }
                    if(pnext && *pnext)
                    {
                        ::str_scpy(val, (char*)pnext+1, "#");
                        ::str_lrtim(val);
                        ::str_lrtim(pred);

                        //cheak the logs folder
                         if(pred[0]=='l')
                            _bind(pred, "logs_path", _logs_path, val);

                        _assign(pred, val, 0);
                    }

                }
                else
                    break;
                if(feof(pf))
                {
                    break;
                }
            }
        }
        catch(int& err)
        {
            ;//noting
        }
    }
    else
    {
        printf( "Cannot find configuration file in any of /etc/, ~/. and  ./. \r\n");
        //exit(0);
    }
    return finalize();
}