Esempio n. 1
0
void init_rc (void)
{
	FILE *f_rc;
	char buf[400];

	if ((f_rc = fopen("themerc", "r")) == NULL) {
		printf("themerc file is missing for the desired theme\n");
		exit(1);
	}

	while (!feof(f_rc)) {
		fgets(buf, 400, f_rc);
		if (strncmp(buf, "active_text_color", 17) == 0) {
			s_theme.text_color[1] |= (s_image_hex2int(buf + 19)) << 16;
			s_theme.text_color[1] |= (s_image_hex2int(buf + 21)) << 8;
			s_theme.text_color[1] |= (s_image_hex2int(buf + 23)) << 0;
		}
		if (strncmp(buf, "inactive_text_color", 19) == 0) {
			s_theme.text_color[0] |= (s_image_hex2int(buf + 21)) << 16;
			s_theme.text_color[0] |= (s_image_hex2int(buf + 23)) << 8;
			s_theme.text_color[0] |= (s_image_hex2int(buf + 25)) << 0;
		}
		if (strncmp(buf, "title_vertical_offset_active", 28) == 0) {
			sscanf(buf + 29, "%d", &s_theme.text_v_off[1]);
		}
		if (strncmp(buf, "title_vertical_offset_inactive", 30) == 0) {
			sscanf(buf + 31, "%d", &s_theme.text_v_off[0]);
		}
	}

	fclose(f_rc);
}
Esempio n. 2
0
void init_rc (void)
{
	FILE *f_rc;
	char buf[400];

	if ((f_rc = fopen("themerc", "r")) == NULL) {
		printf("themerc file is missing for the desired theme\n");
		exit(1);
	}

	while (!feof(f_rc)) {
		fgets(buf, 400, f_rc);
		if (strncmp(buf, "active_text_color", 17) == 0) {
			s_theme.text_color[1] |= (s_image_hex2int(buf + 19)) << 16;
			s_theme.text_color[1] |= (s_image_hex2int(buf + 21)) << 8;
			s_theme.text_color[1] |= (s_image_hex2int(buf + 23)) << 0;
		} else if (strncmp(buf, "inactive_text_color", 19) == 0) {
			s_theme.text_color[0] |= (s_image_hex2int(buf + 21)) << 16;
			s_theme.text_color[0] |= (s_image_hex2int(buf + 23)) << 8;
			s_theme.text_color[0] |= (s_image_hex2int(buf + 25)) << 0;
		} else if (strncmp(buf, "title_vertical_offset_active", 28) == 0) {
			sscanf(buf + 29, "%d", &s_theme.text_v_off[1]);
		} else if (strncmp(buf, "title_vertical_offset_inactive", 30) == 0) {
			sscanf(buf + 31, "%d", &s_theme.text_v_off[0]);
		} else if (strncmp(buf, "full_width_title", 16) == 0) {
			s_theme.title_full = (strncmp(buf + 17, "false", 5) == 0) ? 0 : 1;
		} else if (strncmp(buf, "title_alignment", 15) == 0) {
			s_theme.text_alignment = (strncmp(buf + 16, "left", 4) == 0) ? THEME_ALIGNMENT_LEFT :
			                         (strncmp(buf + 16, "right", 5) == 0) ? THEME_ALIGNMENT_RIGHT :
			                         (strncmp(buf + 16, "center", 6) == 0) ? THEME_ALIGNMENT_CENTER :
			                         THEME_ALIGNMENT_LEFT;
		}
	}

	fclose(f_rc);
}
Esempio n. 3
0
int s_image_xpm (char *file, s_image_t *img)
{
	int i;
	int j;
	int k;
	int l;
	int m;
	int x;
	int y;
	char *buf;
	char *buf_tmp;
	int colors = 0;
	int colors_pp = 0;
	char color_hex[10];
	unsigned int *rgba_tmp = NULL;
	struct xpm_rgb_s {
		char sign[10];
		unsigned char a;
		unsigned char r;
		unsigned char g;
		unsigned char b;
	} *rgb = NULL;
	char sign_str0[] = " .+@#$%&*=-;>,')!~{]^/(_:<[}|1234567890abcdefg"
                           "hijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`";
	char sign_str1[] = " .XoO+@#$%&*=-;:>,<1234567890qwertyuipasdfghjk"
	                   "lzxcvbnmMNBVCZASDFGHJKLPIUYTREWQ!~^/()_`'][{}|";
	FILE *fp;

	buf = (char *) s_malloc(sizeof(char) * BUFFSIZE + 1);
	buf_tmp = buf;

	if ((fp = fopen(file, "r")) == NULL) {
		debugf(DCLI | DFAT, "Coult not open file (%s) for reading");
	}

	while (!feof(fp)) {
		fgets(buf, BUFFSIZE, fp);
		if (strncmp(buf, "/*", 2) == 0) {
			continue;
		}
		if (buf[0] != '"') {
			continue;
		}
		sscanf(buf + 1, "%d %d %d %d", &(img->w), &(img->h), &colors, &colors_pp);
		rgb = (struct xpm_rgb_s *) s_calloc(1, colors * sizeof(struct xpm_rgb_s));
		img->rgba = (unsigned int *) s_calloc(1, img->w * img->h * sizeof(unsigned int));
		rgba_tmp = img->rgba;
		break;
	}

	if ((rgb == NULL) || (rgba_tmp == NULL)) {
		debugf(DCLI | DFAT, "Not enough memory");
	}

        for (i = 0; i < colors; i++) {
		fgets(buf, BUFFSIZE, fp);
		if (strncmp(buf, "/*", 2) == 0) {
			continue;
		}
		for (j = 0; j < colors_pp; j++) {
			rgb[i].sign[j] = buf[j + 1];
		}
		rgb[i].sign[j] = '\0';
		if ((buf_tmp = strstr(buf, "c #")) != NULL) {
			sscanf(buf_tmp, "c #%s", color_hex);
			rgb[i].a = 0;
			rgb[i].r = s_image_hex2int(color_hex);
			rgb[i].g = s_image_hex2int(color_hex + 2);
			rgb[i].b = s_image_hex2int(color_hex + 4);
		} else if ((buf_tmp = strstr(buf, "c ")) != NULL) {
			char rgbname[30];
			sscanf(buf_tmp, "c %s", rgbname);
			rgbname[strlen(rgbname) - 2] = 0;
			if (strcasecmp(rgbname, "none") == 0) {
				goto color_none;
			}
			for (k = 0; k < 234; k++) {
				if (strcasecmp(rgbname, rgbRecord[k].name) == 0) {
					rgb[i].a = 0;
					rgb[i].r = rgbRecord[k].r;
					rgb[i].g = rgbRecord[k].g;
					rgb[i].b = rgbRecord[k].b;
					break;
				}
			}
		} else {
color_none:		rgb[i].a = 255;
			rgb[i].r = 0;
			rgb[i].g = 0;
			rgb[i].b = 0;
		}
	}

	for (y = 0; y < img->h; y++) {
		fgets(buf, BUFFSIZE, fp);
		if (strncmp(buf, "/*", 2) == 0) {
			continue;
		}
		buf_tmp = buf + 1;
		for (x = 0; x < img->w; x++, buf_tmp += colors_pp) {
			find_sign(sign_str0);
			m = i;
			find_sign(sign_str1);
			i = (m < i) ? m : i;
			for (; i < colors; i++) {
				if (s_image_xpm_memcmp(buf_tmp, rgb[i].sign, colors_pp) == 0) {
					*rgba_tmp |= (rgb[i].r << 0x18);
					*rgba_tmp |= (rgb[i].g << 0x10);
					*rgba_tmp |= (rgb[i].b << 0x08);
					*rgba_tmp |= (rgb[i].a << 0x00);
					rgba_tmp++;
					break;
				}
			}
		}
	}

	s_free(rgb);
	s_free(buf);
	fclose(fp);
	
	return 0;
}