Exemplo n.º 1
0
/* read and compile the rc file, if any */
OCerror
ocrc_load(void)
{
    OCerror stat = OC_NOERR;
    char* path = NULL;

    if(ocglobalstate.rc.ignore) {
        oclog(OCLOGDBG,"No runtime configuration file specified; continuing");
	return OC_NOERR;
    }
    if(ocglobalstate.rc.loaded) return OC_NOERR;

    /* locate the configuration files in the following order:
       1. specified by set_rcfile
       2. set by DAPRCFILE env variable
       3. '.'
       4. $HOME
    */  
    if(ocglobalstate.rc.rcfile != NULL) { /* always use this */
	path = strdup(ocglobalstate.rc.rcfile);
    } else if(getenv(OCRCFILEENV) != NULL && strlen(getenv(OCRCFILEENV)) > 0) {
        path = strdup(getenv(OCRCFILEENV));
    } else {
	char** rcname;
	int found = 0;
	for(rcname=rcfilenames;!found && *rcname;rcname++) {
	    stat = rc_search(".",*rcname,&path);
    	    if(stat == OC_NOERR && path == NULL)  /* try $HOME */
	        stat = rc_search(ocglobalstate.home,*rcname,&path);
	    if(stat != OC_NOERR)
		goto done;
	    if(path != NULL)
		found = 1;
	}
    }
    if(path == NULL) {
        oclog(OCLOGDBG,"Cannot find runtime configuration file; continuing");
    } else {
	if(ocdebug > 0)
	    fprintf(stderr, "RC file: %s\n", path);
        if(ocrc_compile(path) == 0) {
	    oclog(OCLOGERR, "Error parsing %s\n",path);
	    stat = OC_ERCFILE;
	}
    }
done:
    ocglobalstate.rc.loaded = 1; /* even if not exists */
    if(path != NULL)
	free(path);
    return stat;
}
Exemplo n.º 2
0
/* read and compile the rc file, if any */
OCerror
ocrc_load(void)
{
    OCerror stat = OC_NOERR;
    char* path = NULL;

    if(ocglobalstate.rc.ignore) {
        oclog(OCLOGDBG,"No runtime configuration file specified; continuing");
	return OC_NOERR;
    }
    if(ocglobalstate.rc.loaded) return OC_NOERR;

    /* locate the configuration files: first if specified,
       then '.',  then $HOME */
    if(ocglobalstate.rc.rcfile != NULL) { /* always use this */
	path = ocglobalstate.rc.rcfile;
    } else {
	char** rcname;
	int found = 0;
	for(rcname=rcfilenames;!found && *rcname;rcname++) {
	    stat = rc_search(".",*rcname,&path);
    	    if(stat == OC_NOERR && path == NULL)  /* try $HOME */
	        stat = rc_search(ocglobalstate.home,*rcname,&path);
	    if(stat != OC_NOERR)
		goto done;
	    if(path != NULL)
		found = 1;
	}
    }
    if(path == NULL) {
        oclog(OCLOGDBG,"Cannot find runtime configuration file; continuing");
    } else {
	if(ocdebug > 0)
	    fprintf(stderr, "RC file: %s\n", path);
        if(ocrc_compile(path) == 0) {
	    oclog(OCLOGERR, "Error parsing %s\n",path);
	    stat = OC_ERCFILE;
	}
    }
done:
    ocglobalstate.rc.loaded = 1; /* even if not exists */
    if(path != NULL)
	free(path);
    return stat;
}