/* be_sys_find_resource:
 *  This is the same of the unix resource finder; it looks into the
 *  home directory and in /etc.
 */
int be_sys_find_resource(char *dest, AL_CONST char *resource, int size)
{
    char buf[256], tmp[256], *last;
    char *home = getenv("HOME");

    if (home) {
        /* look for ~/file */
        append_filename(buf, uconvert_ascii(home, tmp), resource, sizeof(buf));
        if (exists(buf)) {
            ustrzcpy(dest, size, buf);
            return 0;
        }

        /* if it is a .cfg, look for ~/.filerc */
        if (ustricmp(get_extension(resource), uconvert_ascii("cfg", tmp)) == 0) {
            ustrzcpy(buf, sizeof(buf) - ucwidth(OTHER_PATH_SEPARATOR), uconvert_ascii(home, tmp));
            put_backslash(buf);
            ustrzcat(buf, sizeof(buf), uconvert_ascii(".", tmp));
            ustrzcpy(tmp, sizeof(tmp), resource);
            ustrzcat(buf, sizeof(buf), ustrtok_r(tmp, ".", &last));
            ustrzcat(buf, sizeof(buf), uconvert_ascii("rc", tmp));
            if (file_exists(buf, FA_ARCH | FA_RDONLY | FA_HIDDEN, NULL)) {
                ustrzcpy(dest, size, buf);
                return 0;
            }
        }
    }

    /* look for /etc/file */
    append_filename(buf, uconvert_ascii("/etc/", tmp), resource, sizeof(buf));
    if (exists(buf)) {
        ustrzcpy(dest, size, buf);
        return 0;
    }

    /* if it is a .cfg, look for /etc/filerc */
    if (ustricmp(get_extension(resource), uconvert_ascii("cfg", tmp)) == 0) {
        ustrzcpy(buf, sizeof(buf), uconvert_ascii("/etc/", tmp));
        ustrzcpy(tmp, sizeof(tmp), resource);
        ustrzcat(buf, sizeof(buf), ustrtok_r(tmp, ".", &last));
        ustrzcat(buf, sizeof(buf), uconvert_ascii("rc", tmp));
        if (exists(buf)) {
            ustrzcpy(dest, size, buf);
            return 0;
        }
    }

    return -1;
}
Example #2
0
/* Parses an input string to read settings */
static void agl_parse_section(int sec, char *section, char *name) {
	const char *end;
	char *buf;
	char *ptr;
	int strsize;
	int opt = 0;

	end = get_config_string(section, name, "");
	strsize = ustrsizez(end);
	
	buf = (char*)malloc(sizeof(char) * strsize);
	
	if (!buf) {
		TRACE(PREFIX_E "parse_section: Ran out of memory "
		      "while trying to allocate %i bytes!",
		      (int)sizeof(char) * strsize);
		return;
	}

	memcpy(buf, end, strsize);
	end = buf + strsize;
	ptr = buf;

	while (ptr < end) {
		char *s = ustrtok_r(ptr, " ;|+", &ptr);
		
		if (!ustrcmp(s, "allegro_format"))
			opt |= AGL_ALLEGRO_FORMAT;
		if (!ustrcmp(s, "red_depth"))
			opt |= AGL_RED_DEPTH;
		if (!ustrcmp(s, "green_depth"))
			opt |= AGL_GREEN_DEPTH;
		if (!ustrcmp(s, "blue_depth"))
			opt |= AGL_BLUE_DEPTH;
		if (!ustrcmp(s, "alpha_depth"))
			opt |= AGL_ALPHA_DEPTH;
		if (!ustrcmp(s, "color_depth"))
			opt |= AGL_COLOR_DEPTH;
		if (!ustrcmp(s, "accum_red_depth"))
			opt |= AGL_ACC_RED_DEPTH;
		if (!ustrcmp(s, "accum_green_depth"))
			opt |= AGL_ACC_GREEN_DEPTH;
		if (!ustrcmp(s, "accum_blue_depth"))
			opt |= AGL_ACC_BLUE_DEPTH;
		if (!ustrcmp(s, "accum_alpha_depth"))
			opt |= AGL_ACC_ALPHA_DEPTH;
		if (!ustrcmp(s, "double_buffer"))
			opt |= AGL_DOUBLEBUFFER;
		if (!ustrcmp(s, "stereo_display"))
			opt |= AGL_STEREO;
		if (!ustrcmp(s, "aux_buffers"))
			opt |= AGL_AUX_BUFFERS;
		if (!ustrcmp(s, "z_depth"))
			opt |= AGL_Z_DEPTH;
		if (!ustrcmp(s, "stencil_depth"))
			opt |= AGL_STENCIL_DEPTH;
		if (!ustrcmp(s, "window_x"))
			opt |= AGL_WINDOW_X;
		if (!ustrcmp(s, "window_y"))
			opt |= AGL_WINDOW_Y;
		if (!ustrcmp(s, "fullscreen"))
			opt |= AGL_FULLSCREEN;
		if (!ustrcmp(s, "windowed"))
			opt |= AGL_WINDOWED;
		if (!ustrcmp(s, "video_memory_policy"))
			opt |= AGL_VIDEO_MEMORY_POLICY;
		if (!ustrcmp(s, "sample_buffers"))
			opt |= AGL_SAMPLE_BUFFERS;
		if (!ustrcmp(s, "samples"))
			opt |= AGL_SAMPLES;
		if (!ustrcmp(s, "float_color"))
			opt |= AGL_FLOAT_COLOR;
		if (!ustrcmp(s, "float_depth"))
			opt |= AGL_FLOAT_Z;
	}
	
	free(buf);
	
	allegro_gl_set(sec, opt);
}
Example #3
0
/* parse_extension_string:
  *  Parses the extension string, possibly containing attribute characters.
  */
static void parse_extension_string(AL_CONST char *ext)
{
    attrb_state_t state;
    char ext_tokens[32], attrb_char[32];
    char *last, *p, *attrb_p;
    int c, c2, i;
    
    i = 0;
    fext_size = 0;
    fext_p = NULL;
    attrb_p = NULL;
    
    if(!ext)
        return;
        
    fext = ustrdup(ext);
    
    /* Tokenize the extension string and record the pointers to the
      * beginning of each token in a dynamically growing array.
      * ???? We rely on the implementation of ustrtok_r() which writes
      * null characters in the string to delimit the tokens. Yuck.
      */
    c = usetc(ext_tokens, ' ');
    c += usetc(ext_tokens+c, ',');
    c += usetc(ext_tokens+c, ';');
    usetc(ext_tokens+c, 0);
    
    p = ustrtok_r(fext, ext_tokens, &last);
    
    if(p == NULL || !ugetc(p))
        return;
        
    do
    {
        /* Set of attribute characters. */
        if(ugetc(p) == '/')
        {
            attrb_p = p + ucwidth('/');
            continue;
        }
        
        /* Dynamically grow the array if needed. */
        if(i >= fext_size)
        {
            fext_size = (fext_size ? fext_size*2 : 2);
            fext_p = (char **)_al_sane_realloc(fext_p, fext_size * sizeof(char *));
        }
        
        /* Record a pointer to the beginning of the token. */
        fext_p[i++] = p;
        
    }
    while((p = ustrtok_r(NULL, ext_tokens, &last))!=NULL);
    
    /* This is the meaningful size now. */
    fext_size = i;
    
    if(attrb_p)
    {
        state = ATTRB_SET;
        c = usetc(attrb_char, 'r');
        c += usetc(attrb_char+c, 'h');
        c += usetc(attrb_char+c, 's');
        c += usetc(attrb_char+c, 'd');
        c += usetc(attrb_char+c, 'a');
        c += usetc(attrb_char+c, '+');
        c += usetc(attrb_char+c, '-');
        usetc(attrb_char+c, 0);
        
        /* Scan the string. */
        while((c = utolower(ugetx(&attrb_p)))!=0)
        {
            p = attrb_char;
            
            for(i = 0; (c2 = ugetx(&p))!=0; i++)
            {
                if(c == c2)
                {
                    if(i < ATTRB_MAX)
                        attrb_state[i] = state;
                    else
                        state = (i == ATTRB_MAX) ? ATTRB_SET : ATTRB_UNSET;
                        
                    break;
                }
            }
        }
    }
}