示例#1
0
gchar *
cut_utils_fold (const gchar *string)
{
    GRegex *fold_re;
    GArray *folded_lines;
    gchar **lines, **line;
    gchar *folded_string;
    guint i;

    fold_re = g_regex_new("(.{78})", 0, 0, NULL);
    folded_lines = g_array_new(TRUE, FALSE, sizeof(gchar *));

    lines = g_regex_split_simple("\r?\n", string, 0, 0);
    for (line = lines; *line; line++) {
        gchar *folded_line;

        folded_line = g_regex_replace(fold_re, *line, -1, 0, "\\1\n", 0, NULL);
        g_array_append_val(folded_lines, folded_line);
    }
    g_strfreev(lines);

    folded_string = g_strjoinv("\n", (gchar **)(folded_lines->data));
    for (i = 0; i < folded_lines->len; i++) {
        gchar *folded_line;

        folded_line = g_array_index(folded_lines, gchar *, i);
        g_free(folded_line);
    }
    g_array_free(folded_lines, TRUE);
    g_regex_unref(fold_re);

    return folded_string;
}
示例#2
0
enclosurePtr
enclosure_from_string (const gchar *str)
{
	gchar 		**fields;
	enclosurePtr	enclosure;
	
	enclosure = g_new0 (struct enclosure, 1);
	
	/* legacy URL, migration case... */
	if (strstr (str, "enc:") != str) {
		enclosure->url = g_strdup (str);
		return enclosure;
	}
	
	fields = g_regex_split_simple ("^enc:([01]?):([^:]*):(\\d+):(.*)", str, 0, 0);
	if (6 > g_strv_length (fields)) {
		debug2 (DEBUG_PARSING, "Dropping incorrectly encoded enclosure: >>>%s<<< (nr of fields=%d)\n", str, g_strv_length (fields));
		enclosure_free (enclosure);
		return NULL;
	}
	
	enclosure->downloaded = ('1' == *fields[1]);
	if (strlen (fields[2]))
		enclosure->mime = g_strdup (fields[2]);
	if (strlen (fields[3]))
		enclosure->size = atol (fields[3]);
	enclosure->url = g_strdup (fields[4]);

	g_strfreev (fields);

	return enclosure;
}
GError*
service_info_from_chunk_id(struct grid_lbpool_s *glp,
		const gchar *chunk_id, service_info_t **srvinfo)
{
	GError *err = NULL;
	struct service_info_s *si = NULL;

	if (chunk_id == NULL || strlen(chunk_id) <= 0)
		return NEWERROR(CODE_INTERNAL_ERROR, "emtpy chunk id");

	// TODO FIXME Factorizes this with client/c/lib/loc_context.c and
	// TODO FIXME meta2v2/meta2_utils_lb.c, rawx-mover/src/main.c
	char **tok = g_regex_split_simple(
			"(([[:digit:]]{1,3}\\.){3}[[:digit:]]{1,3}:[[:digit:]]{1,5})",
			chunk_id, 0, 0);
	if (!tok || g_strv_length(tok) < 3)
		err = NEWERROR(CODE_INTERNAL_ERROR, "could not parse chunk id");

	if (err == NULL) {
		si = grid_lbpool_get_service_from_url(glp, "rawx", tok[1]);
		if (si == NULL)
			err = NEWERROR(CODE_INTERNAL_ERROR,
					"unable to find service info from %s", tok[1]);
		else
			*srvinfo = si;
	}

	g_strfreev(tok);
	return err;
}
示例#4
0
文件: dwbem.c 项目: vifino/dwb
static int
regex_replace_file(const char *path, const char *regex, const char *replacement) 
{
    int ret = -1;
    char *content = NULL; 
    if (g_file_get_contents(path, &content, NULL, NULL)) 
    {
        char **matches = g_regex_split_simple(regex, content, G_REGEX_DOTALL, 0);
        if (matches[0]) 
        {
            g_free(content);
            content = g_strdup_printf("%s%s%s", matches[0], replacement ? replacement : "", matches[1] ? matches[1] : "");
            if (g_file_set_contents(path, content, -1, NULL))
                ret = 0;
        }
        else 
            g_file_set_contents(path, replacement, -1, NULL);

        g_strfreev(matches);
    }
    else 
        g_file_set_contents(path, replacement, -1, NULL);

    g_free(content);
    return ret;
}
static char *
translated_city_name (TzLocation *loc)
{
  char *country;
  char *name;
  char *zone_translated;
  char **split_translated;
  gint length;

  /* Load the translation for it */
  zone_translated = g_strdup (dgettext (GETTEXT_PACKAGE_TIMEZONES, loc->zone));
  g_strdelimit (zone_translated, "_", ' ');
  split_translated = g_regex_split_simple ("[\\x{2044}\\x{2215}\\x{29f8}\\x{ff0f}/]",
                                           zone_translated,
                                           0, 0);
  g_free (zone_translated);

  length = g_strv_length (split_translated);

  country = gnome_get_country_from_code (loc->country, NULL);
  /* Translators: "city, country" */
  name = g_strdup_printf (C_("timezone loc", "%s, %s"),
                          split_translated[length-1],
                          country);
  g_free (country);
  g_strfreev (split_translated);

  return name;
}
static void
get_regions (TzLocation             *loc,
             struct get_region_data *data)
{
  gchar *zone;
  gchar **split;
  gchar **split_translated;
  gchar *translated_city;

  zone = g_strdup (loc->zone);
  g_strdelimit (zone, "_", ' ');
  split = g_strsplit (zone, "/", 2);
  g_free (zone);

  /* Load the translation for it */
  zone = g_strdup (dgettext (GETTEXT_PACKAGE_TIMEZONES, loc->zone));
  g_strdelimit (zone, "_", ' ');
  split_translated = g_regex_split_simple ("[\\x{2044}\\x{2215}\\x{29f8}\\x{ff0f}/]", zone, 0, 0);
  g_free (zone);

  if (!g_hash_table_lookup_extended (data->table, split[0], NULL, NULL))
    {
      g_hash_table_insert (data->table, g_strdup (split[0]),
                           GINT_TO_POINTER (1));
      gtk_list_store_insert_with_values (data->region_store, NULL, 0,
                                         REGION_COL_REGION, split[0],
                                         REGION_COL_REGION_TRANSLATED, split_translated[0], -1);
    }

  /* g_regex_split_simple() splits too much for us, and would break
   * America/Argentina/Buenos_Aires into 3 strings, so rejoin the city part */
  translated_city = g_strjoinv ("/", split_translated + 1);

  gtk_list_store_insert_with_values (data->city_store, NULL, 0,
                                     CITY_COL_CITY, split[1],
                                     CITY_COL_CITY_TRANSLATED, translated_city,
                                     CITY_COL_REGION, split[0],
                                     CITY_COL_REGION_TRANSLATED, split_translated[0],
                                     CITY_COL_ZONE, loc->zone,
                                     -1);

  g_free (translated_city);
  g_strfreev (split);
  g_strfreev (split_translated);
}
示例#7
0
static int parse_line(char* packet, unsigned* offset, char* line, int status)
{
	char** parts;
	char** part;
	guint32 value;
	size_t size;

	if (strlen(line) <= 1) {
		if (status == CISCODUMP_PARSER_IN_PACKET)
			return CISCODUMP_PARSER_END_PACKET;
		else
			return status;
	}

	/* we got the packet header                                    */
	/* The packet header is a line like:                           */
	/* 16:09:37.171 ITA Mar 18 2016 : IPv4 LES CEF    : Gi0/1 None */
	if (g_regex_match_simple("^\\d{2}:\\d{2}:\\d{2}.\\d+ .*", line, G_REGEX_CASELESS, G_REGEX_MATCH_ANCHORED)) {
		return CISCODUMP_PARSER_IN_HEADER;
	}

	/* we got a line of the packet                                                          */
	/* A line looks like                                                                    */
	/* <address>: <1st group> <2nd group> <3rd group> <4th group> <ascii representation>    */
	/* ABCDEF01: 01020304 05060708 090A0B0C 0D0E0F10 ................                       */
	/* Note that any of the 4 groups are optional and that a group can be 1 to 4 bytes long */
	parts = g_regex_split_simple(
		"^[\\dA-F]{8,8}:\\s+([\\dA-F]{2,8})\\s+([\\dA-F]{2,8}){0,1}\\s+([\\dA-F]{2,8}){0,1}\\s+([\\dA-F]{2,8}){0,1}.*",
		line, G_REGEX_CASELESS, G_REGEX_MATCH_ANCHORED);

	part = parts;
	while(*part) {
		if (strlen(*part) > 1) {
			value = (guint32)strtoul(*part, NULL, 16);
			value = ntohl(value);
			size = strlen(*part) / 2;
			memcpy(packet + *offset, &value, size);
			*offset += (guint32)size;
		}
		part++;
	}
	g_strfreev(parts);
	return CISCODUMP_PARSER_IN_PACKET;
}
示例#8
0
static struct service_info_s *
__service_info_from_chunkid(const struct loc_context_s *lc, const char *cid)
{
	struct service_info_s *si = NULL;
	// TODO FIXME Factorizes this with client/c/lib/loc_context.c and
	// TODO FIXME meta2v2/meta2_utils_lb.c, rawx-mover/src/main.c
	char **tok = g_regex_split_simple(
			"(([[:digit:]]{1,3}\\.){3}[[:digit:]]{1,3}:[[:digit:]]{1,5})",
			cid, 0, 0);
	if(!tok)
		return NULL;

	if(g_strv_length(tok) < 3) {
		return NULL;
	}

	si = grid_lbpool_get_service_from_url(lc->glp, "rawx", tok[1]);

	g_strfreev(tok);

	return si;
}
void SyntaxLineEdit::checkCustomColumn(QString fields)
{
    if (fields.isEmpty()) {
        setSyntaxState(SyntaxLineEdit::Empty);
        return;
    }

    gchar **splitted_fields = g_regex_split_simple(COL_CUSTOM_PRIME_REGEX,
                fields.toUtf8().constData(), G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED);

    for (guint i = 0; i < g_strv_length(splitted_fields); i++) {
        if (splitted_fields[i] && *splitted_fields[i]) {
            if (proto_check_field_name(splitted_fields[i]) != 0) {
                setSyntaxState(SyntaxLineEdit::Invalid);
                g_strfreev(splitted_fields);
                return;
            }
        }
    }
    g_strfreev(splitted_fields);

    checkDisplayFilter(fields);
}
示例#10
0
文件: givimage.c 项目: dov/giv
GivImage *giv_image_new_from_file(const char *filename,
                                  GError **error)
{
    GivImage *img = NULL;
    // TBD - run through a list of loaders. Right now just
    // use gdkpixbuf.
    gchar *extension = g_strrstr(filename, ".");
    if (extension)
        extension++;

    if ((img = giv_plugin_load_image(filename,
                                     error)) != NULL) {
        return img;
    }
    if (*error) {
        printf("Got error: %s\n", (*error)->message);
        return NULL;
    }
    else if (!extension) {
    }
    else if (g_regex_match_simple("png"
                                  "|jpe?g"
                                  "|p[bgp]m"
                                  "|bmp"
                                  "|svg"
                                  ,
                                  extension,
                                  G_REGEX_CASELESS,
                                  0)) {
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename,
                                                     error);
        
        if (*error)
            return img;

        gboolean is_mono = TRUE;

        // Check if the file is monochrome.
        int row_idx,col_idx;
        int width = gdk_pixbuf_get_width(pixbuf);
        int height = gdk_pixbuf_get_height(pixbuf);
        guint8 *buf = gdk_pixbuf_get_pixels(pixbuf);
        int row_stride = gdk_pixbuf_get_rowstride(pixbuf);

        for (row_idx=0; row_idx<height; row_idx++) {
            guint8 *p = buf + row_idx * row_stride;
            for (col_idx=0; col_idx<width; col_idx++) {
                if (p[0] != p[1]
                    || p[0] != p[2]) {
                    is_mono = FALSE;
                    break;
                }
                p+= 3;
            }
        }

        if (is_mono) {
            GivImageType img_type = GIVIMAGE_U8;
            img = giv_image_new_full(img_type,
                                     width,
                                     width,
                                     height,
                                     width * height,
                                     2,
                                     1);
            if (!img) {
                *error = g_error_new(GIV_IMAGE_ERROR, -1, "Failed allocating memory for an image of size %dx%d pixels!", width, height);
                return NULL;
            }

            guchar *src_buf = gdk_pixbuf_get_pixels(pixbuf);
            guchar *dst_buf = img->buf.buf;
            int row_idx, col_idx;
            int ncolors = 3;
            if (gdk_pixbuf_get_has_alpha(pixbuf))
                ncolors = 4;
            for (row_idx=0; row_idx<height; row_idx++) {
                guchar *dst_row = dst_buf + row_idx*width;
                guchar *src_row = src_buf + row_idx*row_stride;
                for (col_idx=0; col_idx<width; col_idx++) 
                    dst_row[col_idx] = src_row[col_idx*ncolors];
            }
        }
        else {
            GivImageType img_type = GIVIMAGE_RGB_U8;
            if (gdk_pixbuf_get_has_alpha(pixbuf)) 
                img_type = GIVIMAGE_RGBA_U8;
            img = giv_image_new_full(img_type,
                                     width,
                                     row_stride,
                                     height,
                                     row_stride * height,
                                     2,
                                     1);
            if (!img) {
                *error = g_error_new(GIV_IMAGE_ERROR, -1, "Failed allocating memory for an image of size %dx%d pixels!", width, height);
                return NULL;
            }
            memcpy(img->buf.buf,
                   gdk_pixbuf_get_pixels(pixbuf),
                   row_stride * height);
        }
        g_object_unref(pixbuf);
    }
    // Space separated value. A simple text format parser. Still
    // doesn't support comments. Fix this!
    else if (g_regex_match_simple("ssv",
                                  extension,
                                  G_REGEX_CASELESS,
                                  0)) {
        gchar *ssv_string;
        gsize length;
        
        g_file_get_contents(filename, &ssv_string, &length, error);
        gchar **lines = g_regex_split_simple("\r?\n",
                                             ssv_string,
                                             0, 0);
        int num_lines = g_strv_length(lines);

        // Count lines while skipping comments
        int height = 0;
        int line_idx;
        for (line_idx = 0; line_idx<num_lines; line_idx++) {
            if (lines[line_idx][0] == '#'
                || strlen(lines[line_idx]) == 0)
                continue;
            height++;
        }

        gint width = -1;
        float *fbuf;
        int row_idx = 0;
        for (line_idx=0; line_idx<num_lines; line_idx++) {
            int col_idx;
            if (lines[line_idx][0] == '#'
                || strlen(lines[line_idx]) == 0)
                continue;
            // comma or space split
            gchar *p = lines[line_idx];

            // skip whitespace
            while(*p == ' ')
                p++;
            gchar **fields = g_regex_split_simple("(?:,|;|\\s)\\s*",
                                                  p,
                                                  0,0);
            if (row_idx==0) {
                width = g_strv_length(fields);
                img = giv_image_new(GIVIMAGE_FLOAT,
                                    width, height);
                fbuf = img->buf.fbuf;
            }
            for (col_idx=0; col_idx<width; col_idx++) 
                fbuf[row_idx*width + col_idx] = atof(fields[col_idx]);
            g_strfreev(fields);
            row_idx++;

        }
        g_strfreev(lines);
        g_free(ssv_string);
    }
    else if (g_regex_match_simple("npy",
                                  extension,
                                  G_REGEX_CASELESS,
                                  0)) {
        gchar *npy_string;
        gsize length;
        
        g_file_get_contents(filename, &npy_string, &length, error);

        // Various checks that it is format we support
        gboolean header_ok = (g_strstr_len(npy_string, 6, "\223NUMPY") == npy_string );
        gboolean ver_ok = (npy_string[6] == 1
                           && npy_string[7] == 0);
        gint header_len = *((guint16*)(npy_string+8));

        // Use regex to parse the header. Should update this to allow
        // user attributes.
        GRegex *regex = g_regex_new ("^\\{\\s*"
                                     "'descr':\\s*\\'(.*?)\\'\\s*,\\s*"
                                     "'fortran_order':\\s*(\\w+)\\s*,\\s*"
                                     "'shape':\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\),?\\s*"
                                     "\\}", 0, 0, error);
        if (*error) {
            printf("Programming GivRegEx error: %s\n", (*error)->message);
            exit(-1);
        }
        GMatchInfo *match_info = NULL;
        gboolean is_match = g_regex_match_full(regex,
                                               npy_string+10,
                                               header_len,
                                               0,
                                               (GRegexMatchFlags)0,
                                               &match_info,
                                               error);
        gboolean is_supported_type = TRUE;
        gboolean is_fortran_type = FALSE;
        gint width=-1, height = -1;
        GivImageType image_type;
        if (is_match) {
            gchar *match_string = g_match_info_fetch(match_info, 1);

            if (strcmp(match_string, "<f8")==0) 
                image_type = GIVIMAGE_DOUBLE;
            else if (strcmp(match_string, "<f4")==0) 
                image_type = GIVIMAGE_FLOAT;
            else if (strcmp(match_string, "<i4")==0) 
                image_type = GIVIMAGE_I32;
            else if (strcmp(match_string, "<i2")==0) 
                image_type = GIVIMAGE_I16;
            else if (strcmp(match_string, "<u2")==0) 
                image_type = GIVIMAGE_U16;
            else if (strcmp(match_string, "|u1")==0) 
                image_type = GIVIMAGE_U8;
            else
                is_supported_type = FALSE;
            
            g_free(match_string);
            
            match_string = g_match_info_fetch(match_info, 2);
            is_fortran_type = strcmp(match_string, "True") == 0;
            g_free(match_string);
            
            match_string = g_match_info_fetch(match_info, 3);
            height = atoi(match_string);
            g_free(match_string);
            
            match_string = g_match_info_fetch(match_info, 4);
            width = atoi(match_string);
            g_free(match_string);
        }

        g_regex_unref(regex);
        g_match_info_free(match_info);
        
        if  (!is_match
             || !header_ok
             || !is_supported_type
             || is_fortran_type
            ) {
            *error = g_error_new(GIV_IMAGE_ERROR, -1, "Invalid npy file!");
            g_free(npy_string);
            return NULL;
        }

        img = giv_image_new(image_type,
                            width, height);

        // Copy the data
        //        printf("image: type size width height= %d %d\n", image_type, giv_image_type_get_size(image_type), width, height);

        memcpy(img->buf.buf,
               npy_string + 10 + header_len,
               giv_image_type_get_size(image_type) * width * height / 8);
        g_free(npy_string);
    }
    else {
        *error = g_error_new(GIV_IMAGE_ERROR, -1, "Giv: Unknown filetype %s!", extension);
    }

    if (!img && !*error)
        *error = g_error_new(GIV_IMAGE_ERROR, -1, "Giv: Failed loading %s!", filename);
    return img;
}
示例#11
0
文件: config.c 项目: asqz/tint2
void add_entry (char *key, char *value)
{
	char *value1=0, *value2=0, *value3=0;

	/* Background and border */
	if (strcmp (key, "rounded") == 0) {
		// 'rounded' is the first parameter => alloc a new background
		Background bg;
		bg.border.rounded = atoi(value);
		g_array_append_val(backgrounds, bg);
	}
	else if (strcmp (key, "border_width") == 0) {
		g_array_index(backgrounds, Background, backgrounds->len-1).border.width = atoi(value);
	}
	else if (strcmp (key, "background_color") == 0) {
		Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, bg->back.color);
		if (value2) bg->back.alpha = (atoi (value2) / 100.0);
		else bg->back.alpha = 0.5;
	}
	else if (strcmp (key, "border_color") == 0) {
		Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, bg->border.color);
		if (value2) bg->border.alpha = (atoi (value2) / 100.0);
		else bg->border.alpha = 0.5;
	}

	/* Panel */
	else if (strcmp (key, "panel_monitor") == 0) {
		panel_config.monitor = config_get_monitor(value);
	}
	else if (strcmp (key, "panel_size") == 0) {
		extract_values(value, &value1, &value2, &value3);

		char *b;
		if ((b = strchr (value1, '%'))) {
			b[0] = '\0';
			panel_config.pourcentx = 1;
		}
		panel_config.area.width = atoi(value1);
		if (panel_config.area.width == 0) {
			// full width mode
			panel_config.area.width = 100;
			panel_config.pourcentx = 1;
		}
		if (value2) {
			if ((b = strchr (value2, '%'))) {
				b[0] = '\0';
				panel_config.pourcenty = 1;
			}
			panel_config.area.height = atoi(value2);
		}
	}
	else if (strcmp (key, "panel_margin") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.marginx = atoi (value1);
		if (value2) panel_config.marginy = atoi (value2);
	}
	else if (strcmp (key, "panel_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.area.paddingxlr = panel_config.area.paddingx = atoi (value1);
		if (value2) panel_config.area.paddingy = atoi (value2);
		if (value3) panel_config.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "panel_position") == 0) {
		extract_values(value, &value1, &value2, &value3);
		if (strcmp (value1, "top") == 0) panel_position = TOP;
		else {
			if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
			else panel_position = CENTER;
		}

		if (!value2) panel_position |= CENTER;
		else {
			if (strcmp (value2, "left") == 0) panel_position |= LEFT;
			else {
				if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
				else panel_position |= CENTER;
			}
		}
		if (!value3) panel_horizontal = 1;
		else {
			if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
			else panel_horizontal = 1;
		}
	}
	else if (strcmp (key, "font_shadow") == 0)
		panel_config.g_task.font_shadow = atoi (value);
	else if (strcmp (key, "panel_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp (key, "wm_menu") == 0)
		wm_menu = atoi (value);
	else if (strcmp (key, "panel_dock") == 0)
		panel_dock = atoi (value);
	else if (strcmp (key, "urgent_nb_of_blink") == 0)
		max_tick_urgent = (atoi (value) * 2) + 1;
	else if (strcmp (key, "panel_layer") == 0) {
		if (strcmp(value, "bottom") == 0)
			panel_layer = BOTTOM_LAYER;
		else if (strcmp(value, "normal") == 0)
			panel_layer = NORMAL_LAYER;
		else if (strcmp(value, "top") == 0)
			panel_layer = TOP_LAYER;
	}

	/* Battery */
	else if (strcmp (key, "battery") == 0) {
#ifdef ENABLE_BATTERY
		if(atoi(value) == 1)
			battery_enabled = 1;
#else
		if(atoi(value) == 1)
			fprintf(stderr, "tint2 is build without battery support\n");
#endif
	}
	else if (strcmp (key, "battery_low_status") == 0) {
#ifdef ENABLE_BATTERY
		battery_low_status = atoi(value);
		if(battery_low_status < 0 || battery_low_status > 100)
			battery_low_status = 0;
#endif
	}
	else if (strcmp (key, "battery_low_cmd") == 0) {
#ifdef ENABLE_BATTERY
		if (strlen(value) > 0)
			battery_low_cmd = strdup (value);
#endif
	}
	else if (strcmp (key, "bat1_font") == 0) {
#ifdef ENABLE_BATTERY
		bat1_font_desc = pango_font_description_from_string (value);
#endif
	}
	else if (strcmp (key, "bat2_font") == 0) {
#ifdef ENABLE_BATTERY
		bat2_font_desc = pango_font_description_from_string (value);
#endif
	}
	else if (strcmp (key, "battery_font_color") == 0) {
#ifdef ENABLE_BATTERY
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, panel_config.battery.font.color);
		if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
		else panel_config.battery.font.alpha = 0.5;
#endif
	}
	else if (strcmp (key, "battery_padding") == 0) {
#ifdef ENABLE_BATTERY
		extract_values(value, &value1, &value2, &value3);
		panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
		if (value2) panel_config.battery.area.paddingy = atoi (value2);
		if (value3) panel_config.battery.area.paddingx = atoi (value3);
#endif
	}
	else if (strcmp (key, "battery_background_id") == 0) {
#ifdef ENABLE_BATTERY
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.battery.area.bg = &g_array_index(backgrounds, Background, id);
#endif
	}
	else if (strcmp (key, "battery_hide") == 0) {
#ifdef ENABLE_BATTERY
		percentage_hide = atoi (value);
		if (percentage_hide == 0)
			percentage_hide = 101;
#endif
	}

   /* Applets */
	else if (strcmp (key, "applets") == 0) {
#ifdef ENABLE_APPLETS
		if(atoi(value) == 1)
			applets_enabled = 1;
      else
         applets_enabled = 0;
#else
		if(atoi(value) == 1)
			fprintf(stderr, "tint2 is build without applets support\n");
#endif
	}
   else if (strcmp (key, "applets_background_id") == 0) {
#ifdef ENABLE_APPLETS
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.applets.area.bg = &g_array_index(backgrounds, Background, id);
#endif
	}


	/* Clock */
	else if (strcmp (key, "time1_format") == 0) {
		if (strlen(value) > 0) {
			time1_format = strdup (value);
			clock_enabled = 1;
		}
	}
	else if (strcmp (key, "time2_format") == 0) {
		if (strlen(value) > 0)
			time2_format = strdup (value);
	}
	else if (strcmp (key, "time1_font") == 0) {
		time1_font_desc = pango_font_description_from_string (value);
	}
	else if (strcmp(key, "time1_timezone") == 0) {
		if (strlen(value) > 0)
			time1_timezone = strdup(value);
	}
	else if (strcmp(key, "time2_timezone") == 0) {
		if (strlen(value) > 0)
			time2_timezone = strdup(value);
	}
	else if (strcmp (key, "time2_font") == 0) {
		time2_font_desc = pango_font_description_from_string (value);
	}
	else if (strcmp (key, "clock_font_color") == 0) {
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, panel_config.clock.font.color);
		if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
		else panel_config.clock.font.alpha = 0.5;
	}
	else if (strcmp (key, "clock_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
		if (value2) panel_config.clock.area.paddingy = atoi (value2);
		if (value3) panel_config.clock.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "clock_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.clock.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp(key, "clock_tooltip") == 0) {
		if (strlen(value) > 0)
			time_tooltip_format = strdup (value);
	}
	else if (strcmp(key, "clock_tooltip_timezone") == 0) {
		if (strlen(value) > 0)
			time_tooltip_timezone = strdup(value);
	}
	else if (strcmp(key, "clock_lclick_command") == 0) {
		if (strlen(value) > 0)
			clock_lclick_command = strdup(value);
	}
	else if (strcmp(key, "clock_rclick_command") == 0) {
		if (strlen(value) > 0)
			clock_rclick_command = strdup(value);
	}

	/* Taskbar */
	else if (strcmp (key, "taskbar_mode") == 0) {
		if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
		else panel_mode = SINGLE_DESKTOP;
	}
	else if (strcmp (key, "taskbar_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_taskbar.area.paddingxlr = panel_config.g_taskbar.area.paddingx = atoi (value1);
		if (value2) panel_config.g_taskbar.area.paddingy = atoi (value2);
		if (value3) panel_config.g_taskbar.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "taskbar_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_taskbar.bg = &g_array_index(backgrounds, Background, id);
		panel_config.g_taskbar.area.bg = panel_config.g_taskbar.bg;
	}
	else if (strcmp (key, "taskbar_active_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_taskbar.bg_active = &g_array_index(backgrounds, Background, id);
		panel_config.g_taskbar.use_active = 1;
	}

	/* Task */
	else if (strcmp (key, "task_text") == 0)
		panel_config.g_task.text = atoi (value);
	else if (strcmp (key, "task_icon") == 0)
		panel_config.g_task.icon = atoi (value);
	else if (strcmp (key, "task_centered") == 0)
		panel_config.g_task.centered = atoi (value);
	else if (strcmp (key, "task_width") == 0) {
		// old parameter : just for backward compatibility
		panel_config.g_task.maximum_width = atoi (value);
		panel_config.g_task.maximum_height = 30;
	}
	else if (strcmp (key, "task_maximum_size") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_task.maximum_width = atoi (value1);
		panel_config.g_task.maximum_height = 30;
		if (value2)
			panel_config.g_task.maximum_height = atoi (value2);
	}
	else if (strcmp (key, "task_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
		if (value2) panel_config.g_task.area.paddingy = atoi (value2);
		if (value3) panel_config.g_task.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "task_font") == 0) {
		panel_config.g_task.font_desc = pango_font_description_from_string (value);
	}
	else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) {
		gchar** split = g_regex_split_simple("_", key, 0, 0);
		int status = get_task_status(split[1]);
		g_strfreev(split);
		extract_values(value, &value1, &value2, &value3);
		float alpha = 1;
		if (value2) alpha = (atoi (value2) / 100.0);
		get_color (value1, panel_config.g_task.font[status].color);
		panel_config.g_task.font[status].alpha = alpha;
		panel_config.g_task.config_font_mask |= (1<<status);
	}
	else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
		gchar** split = g_regex_split_simple("_", key, 0, 0);
		int status = get_task_status(split[1]);
		g_strfreev(split);
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_task.alpha[status] = atoi(value1);
		panel_config.g_task.saturation[status] = atoi(value2);
		panel_config.g_task.brightness[status] = atoi(value3);
		panel_config.g_task.config_asb_mask |= (1<<status);
	}
	else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
		gchar** split = g_regex_split_simple("_", key, 0, 0);
		int status = get_task_status(split[1]);
		g_strfreev(split);
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
		panel_config.g_task.config_background_mask |= (1<<status);
		if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
	}

	/* Systray */
	// systray disabled in snapshot mode
	else if (strcmp (key, "systray") == 0 && snapshot_path == 0) {
		systray_enabled = atoi(value);
		// systray is latest option added. files without 'systray' are old.
		old_config_file = 0;
	}
	else if (strcmp (key, "systray_padding") == 0 && snapshot_path == 0) {
		if (old_config_file)
			systray_enabled = 1;
		extract_values(value, &value1, &value2, &value3);
		systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
		if (value2) systray.area.paddingy = atoi (value2);
		if (value3) systray.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "systray_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		systray.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp(key, "systray_sort") == 0) {
		if (strcmp(value, "descending") == 0)
			systray.sort = -1;
		else if (strcmp(value, "ascending") == 0)
			systray.sort = 1;
		else if (strcmp(value, "left2right") == 0)
			systray.sort = 2;
		else  if (strcmp(value, "right2left") == 0)
			systray.sort = 3;
	}
	else if (strcmp(key, "systray_icon_size") == 0) {
		systray_max_icon_size = atoi(value);
	}
	else if (strcmp(key, "systray_icon_asb") == 0) {
		extract_values(value, &value1, &value2, &value3);
		systray.alpha = atoi(value1);
		systray.saturation = atoi(value2);
		systray.brightness = atoi(value3);
	}

	/* Tooltip */
	else if (strcmp (key, "tooltip") == 0)
		g_tooltip.enabled = atoi(value);
	else if (strcmp (key, "tooltip_show_timeout") == 0) {
		int timeout_msec = 1000*atof(value);
		g_tooltip.show_timeout_msec = timeout_msec;
	}
	else if (strcmp (key, "tooltip_hide_timeout") == 0) {
		int timeout_msec = 1000*atof(value);
		g_tooltip.hide_timeout_msec = timeout_msec;
	}
	else if (strcmp (key, "tooltip_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		if (value1) g_tooltip.paddingx = atoi(value1);
		if (value2) g_tooltip.paddingy = atoi(value2);
	}
	else if (strcmp (key, "tooltip_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		g_tooltip.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp (key, "tooltip_font_color") == 0) {
		extract_values(value, &value1, &value2, &value3);
		get_color(value1, g_tooltip.font_color.color);
		if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
		else g_tooltip.font_color.alpha = 0.1;
	}
	else if (strcmp (key, "tooltip_font") == 0) {
		g_tooltip.font_desc = pango_font_description_from_string(value);
	}

	/* Mouse actions */
	else if (strcmp (key, "mouse_middle") == 0)
		get_action (value, &mouse_middle);
	else if (strcmp (key, "mouse_right") == 0)
		get_action (value, &mouse_right);
	else if (strcmp (key, "mouse_scroll_up") == 0)
		get_action (value, &mouse_scroll_up);
	else if (strcmp (key, "mouse_scroll_down") == 0)
		get_action (value, &mouse_scroll_down);

	/* autohide options */
	else if (strcmp(key, "autohide") == 0)
		panel_autohide = atoi(value);
	else if (strcmp(key, "autohide_show_timeout") == 0)
		panel_autohide_show_timeout = 1000*atof(value);
	else if (strcmp(key, "autohide_hide_timeout") == 0)
		panel_autohide_hide_timeout = 1000*atof(value);
	else if (strcmp(key, "strut_policy") == 0) {
		if (strcmp(value, "follow_size") == 0)
			panel_strut_policy = STRUT_FOLLOW_SIZE;
		else if (strcmp(value, "none") == 0)
			panel_strut_policy = STRUT_NONE;
		else
			panel_strut_policy = STRUT_MINIMUM;
	}
	else if (strcmp(key, "autohide_height") == 0) {
		panel_autohide_height = atoi(value);
		if (panel_autohide_height == 0) {
			// autohide need height > 0
			panel_autohide_height = 1;
		}
	}

	else
		fprintf(stderr, "tint2 : invalid option \"%s\",\n  upgrade tint2 or correct your config file\n", key);

	if (value1) free (value1);
	if (value2) free (value2);
	if (value3) free (value3);
}
示例#12
0
文件: gmimex.c 项目: swerter/gmimex
static GString *build_attributes(GumboNode* node, GumboAttribute *at, gboolean no_entities, GPtrArray *inlines_ary) {
  gchar *key = g_strjoin(NULL, "|", at->name, "|", NULL);
  gchar *key_pattern = g_regex_escape_string(key, -1);
  g_free(key);

  gboolean is_permitted_attribute = g_regex_match_simple(key_pattern, permitted_attributes, G_REGEX_CASELESS, 0);
  gboolean is_protocol_attribute  = g_regex_match_simple(key_pattern, protocol_attributes, G_REGEX_CASELESS, 0);
  gchar *cid_content_id = NULL;

  g_free(key_pattern);

  if (!is_permitted_attribute)
    return g_string_new(NULL);

  GString *attr_value = g_string_new(at->value);
  gstr_strip(attr_value);

  if (is_protocol_attribute) {
    gchar **protocol_parts = g_regex_split_simple(protocol_separators_regex, attr_value->str, G_REGEX_CASELESS, 0);
    guint pparts_length = 0;

    while (protocol_parts[pparts_length])
      pparts_length++;

    gboolean is_permitted_protocol = FALSE;

    if (pparts_length) {
      static gchar* protocol_join_str = ":";
      gchar* new_joined = g_strjoinv(protocol_join_str, protocol_parts);
      g_string_assign(attr_value, new_joined);
      g_free(new_joined);

      gchar *attr_protocol = g_strjoin(NULL, "|", protocol_parts[0], "|", NULL);
      gchar *attr_prot_pattern = g_regex_escape_string(attr_protocol, -1);
      g_free(attr_protocol);
      is_permitted_protocol = g_regex_match_simple(attr_prot_pattern, permitted_protocols, G_REGEX_CASELESS, 0);
      g_free(attr_prot_pattern);

      if (is_permitted_protocol && !g_ascii_strcasecmp(protocol_parts[0], "cid"))
        cid_content_id = g_strdup(protocol_parts[1]);
    }
    g_strfreev(protocol_parts);

    if (!is_permitted_protocol) {
      g_string_free(attr_value, TRUE);
      return g_string_new(NULL);
    }
  }

  gboolean cid_replaced = FALSE;
  if (cid_content_id) {
    if (inlines_ary && inlines_ary->len) {
      guint i;
      for (i = 0; i < inlines_ary->len; i++) {
        CollectedPart *inline_body = g_ptr_array_index(inlines_ary, i);
        if (inline_body->content_id && !g_ascii_strcasecmp(inline_body->content_id, cid_content_id)) {
          if (inline_body->content->len < MAX_CID_SIZE) {
            gchar *base64_data = g_base64_encode((const guchar *) inline_body->content->data, inline_body->content->len);
            gchar *new_attr_value = g_strjoin(NULL, "data:", inline_body->content_type, ";base64,", base64_data, NULL);
            g_string_assign(attr_value, new_attr_value);
            g_free(base64_data);
            g_free(new_attr_value);
            cid_replaced = TRUE;
          }
        }
      }
    }

    // `cid` is not a valid URI schema, so if it was not replaced by the inline content,
    // we replace it with a 1x1 image which should hide it. If there is content and we missed
    // it due to the wrong contentId given, it will be avaialable as a downloadable attachment.
    if (!cid_replaced)
      g_string_assign(attr_value, MIN_DATA_URI_IMAGE);

    g_free(cid_content_id);
  }

  GString *atts = g_string_new(" ");

  if (node->type == GUMBO_NODE_ELEMENT)
    if (((node->v.element.tag == GUMBO_TAG_IMG) &&
          !g_ascii_strcasecmp(at->name, "src")) ||
        (!g_ascii_strcasecmp(at->name, "style") &&
          g_regex_match_simple("url", attr_value->str, G_REGEX_CASELESS, 0)))
      g_string_append(atts, "data-proxy-");

  g_string_append(atts, at->name);

  // how do we want to handle attributes with empty values
  // <input type="checkbox" checked />  or <input type="checkbox" checked="" />

  gchar quote = at->original_value.data[0];

  if (attr_value->len || (quote == '"') || (quote == '\'')) {

    gchar *qs = "";
    if (quote == '\'')
      qs = "'";

    if (quote == '"')
      qs = "\"";

    g_string_append(atts, "=");
    g_string_append(atts, qs);

    if (no_entities) {
      g_string_append(atts, attr_value->str);
    } else {
      GString *subd = gstr_substitute_xml_entities_into_attributes(quote, attr_value->str);
      g_string_append(atts, subd->str);
      g_string_free(subd, TRUE);
    }
    g_string_append(atts, qs);
  }

  g_string_free(attr_value, TRUE);
  return atts;
}
示例#13
0
文件: config.c 项目: azubieta/tint2
void add_entry (char *key, char *value)
{
	char *value1=0, *value2=0, *value3=0;

	/* Background and border */
	if (strcmp (key, "rounded") == 0) {
		// 'rounded' is the first parameter => alloc a new background
		Background bg;
		bg.border.rounded = atoi(value);
		g_array_append_val(backgrounds, bg);
	}
	else if (strcmp (key, "border_width") == 0) {
		g_array_index(backgrounds, Background, backgrounds->len-1).border.width = atoi(value);
	}
	else if (strcmp (key, "background_color") == 0) {
		Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, bg->back.color);
		if (value2) bg->back.alpha = (atoi (value2) / 100.0);
		else bg->back.alpha = 0.5;
	}
	else if (strcmp (key, "border_color") == 0) {
		Background* bg = &g_array_index(backgrounds, Background, backgrounds->len-1);
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, bg->border.color);
		if (value2) bg->border.alpha = (atoi (value2) / 100.0);
		else bg->border.alpha = 0.5;
	}

	/* Panel */
	else if (strcmp (key, "panel_monitor") == 0) {
		panel_config.monitor = config_get_monitor(value);
	}
	else if (strcmp (key, "panel_size") == 0) {
		extract_values(value, &value1, &value2, &value3);

		char *b;
		if ((b = strchr (value1, '%'))) {
			b[0] = '\0';
			panel_config.pourcentx = 1;
		}
		panel_config.area.width = atoi(value1);
		if (panel_config.area.width == 0) {
			// full width mode
			panel_config.area.width = 100;
			panel_config.pourcentx = 1;
		}
		if (value2) {
			if ((b = strchr (value2, '%'))) {
				b[0] = '\0';
				panel_config.pourcenty = 1;
			}
			panel_config.area.height = atoi(value2);
		}
	}
	else if (strcmp (key, "panel_items") == 0) {
		new_config_file = 1;
		panel_items_order = strdup(value);
		int j;
		for (j=0 ; j < strlen(panel_items_order) ; j++) {
			if (panel_items_order[j] == 'L')
				launcher_enabled = 1;
			if (panel_items_order[j] == 'T')
				taskbar_enabled = 1;
			if (panel_items_order[j] == 'B') {
#ifdef ENABLE_BATTERY
				battery_enabled = 1;
#else
				fprintf(stderr, "tint2 is build without battery support\n");
#endif
			}
			if (panel_items_order[j] == 'S') {
				// systray disabled in snapshot mode
				if (snapshot_path == 0)
					systray_enabled = 1;
			}
			if (panel_items_order[j] == 'C')
				clock_enabled = 1;
		}
	}
	else if (strcmp (key, "panel_margin") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.marginx = atoi (value1);
		if (value2) panel_config.marginy = atoi (value2);
	}
	else if (strcmp (key, "panel_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.area.paddingxlr = panel_config.area.paddingx = atoi (value1);
		if (value2) panel_config.area.paddingy = atoi (value2);
		if (value3) panel_config.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "panel_position") == 0) {
		extract_values(value, &value1, &value2, &value3);
		if (strcmp (value1, "top") == 0) panel_position = TOP;
		else {
			if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM;
			else panel_position = CENTER;
		}

		if (!value2) panel_position |= CENTER;
		else {
			if (strcmp (value2, "left") == 0) panel_position |= LEFT;
			else {
				if (strcmp (value2, "right") == 0) panel_position |= RIGHT;
				else panel_position |= CENTER;
			}
		}
		if (!value3) panel_horizontal = 1;
		else {
			if (strcmp (value3, "vertical") == 0) panel_horizontal = 0;
			else panel_horizontal = 1;
		}
	}
	else if (strcmp (key, "font_shadow") == 0)
		panel_config.g_task.font_shadow = atoi (value);
	else if (strcmp (key, "panel_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp (key, "wm_menu") == 0)
		wm_menu = atoi (value);
	else if (strcmp (key, "panel_dock") == 0)
		panel_dock = atoi (value);
	else if (strcmp (key, "urgent_nb_of_blink") == 0)
		max_tick_urgent = atoi (value);
	else if (strcmp (key, "panel_layer") == 0) {
		if (strcmp(value, "bottom") == 0)
			panel_layer = BOTTOM_LAYER;
		else if (strcmp(value, "top") == 0)
			panel_layer = TOP_LAYER;
		else
			panel_layer = NORMAL_LAYER;
	}

	/* Battery */
	else if (strcmp (key, "battery_low_status") == 0) {
#ifdef ENABLE_BATTERY
		battery_low_status = atoi(value);
		if(battery_low_status < 0 || battery_low_status > 100)
			battery_low_status = 0;
#endif
	}
	else if (strcmp (key, "battery_low_cmd") == 0) {
#ifdef ENABLE_BATTERY
		if (strlen(value) > 0)
			battery_low_cmd = strdup (value);
#endif
	}
	else if (strcmp (key, "bat1_font") == 0) {
#ifdef ENABLE_BATTERY
		bat1_font_desc = pango_font_description_from_string (value);
#endif
	}
	else if (strcmp (key, "bat2_font") == 0) {
#ifdef ENABLE_BATTERY
		bat2_font_desc = pango_font_description_from_string (value);
#endif
	}
	else if (strcmp (key, "battery_font_color") == 0) {
#ifdef ENABLE_BATTERY
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, panel_config.battery.font.color);
		if (value2) panel_config.battery.font.alpha = (atoi (value2) / 100.0);
		else panel_config.battery.font.alpha = 0.5;
#endif
	}
	else if (strcmp (key, "battery_padding") == 0) {
#ifdef ENABLE_BATTERY
		extract_values(value, &value1, &value2, &value3);
		panel_config.battery.area.paddingxlr = panel_config.battery.area.paddingx = atoi (value1);
		if (value2) panel_config.battery.area.paddingy = atoi (value2);
		if (value3) panel_config.battery.area.paddingx = atoi (value3);
#endif
	}
	else if (strcmp (key, "battery_background_id") == 0) {
#ifdef ENABLE_BATTERY
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.battery.area.bg = &g_array_index(backgrounds, Background, id);
#endif
	}
	else if (strcmp (key, "battery_hide") == 0) {
#ifdef ENABLE_BATTERY
		percentage_hide = atoi (value);
		if (percentage_hide == 0)
			percentage_hide = 101;
#endif
	}

	/* Clock */
	else if (strcmp (key, "time1_format") == 0) {
		if (new_config_file == 0) {
			clock_enabled = 1;
			if (panel_items_order) {
				char* tmp = g_strconcat(panel_items_order, "C", NULL);
				g_free( panel_items_order );
				panel_items_order = tmp;
			}
			else 
				panel_items_order = g_strdup("C");
		}
		if (strlen(value) > 0) {
			time1_format = strdup (value);
			clock_enabled = 1;
		}
	}
	else if (strcmp (key, "time2_format") == 0) {
		if (strlen(value) > 0)
			time2_format = strdup (value);
	}
	else if (strcmp (key, "time1_font") == 0) {
		time1_font_desc = pango_font_description_from_string (value);
	}
	else if (strcmp(key, "time1_timezone") == 0) {
		if (strlen(value) > 0)
			time1_timezone = strdup(value);
	}
	else if (strcmp(key, "time2_timezone") == 0) {
		if (strlen(value) > 0)
			time2_timezone = strdup(value);
	}
	else if (strcmp (key, "time2_font") == 0) {
		time2_font_desc = pango_font_description_from_string (value);
	}
	else if (strcmp (key, "clock_font_color") == 0) {
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, panel_config.clock.font.color);
		if (value2) panel_config.clock.font.alpha = (atoi (value2) / 100.0);
		else panel_config.clock.font.alpha = 0.5;
	}
	else if (strcmp (key, "clock_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.clock.area.paddingxlr = panel_config.clock.area.paddingx = atoi (value1);
		if (value2) panel_config.clock.area.paddingy = atoi (value2);
		if (value3) panel_config.clock.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "clock_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.clock.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp(key, "clock_tooltip") == 0) {
		if (strlen(value) > 0)
			time_tooltip_format = strdup (value);
	}
	else if (strcmp(key, "clock_tooltip_timezone") == 0) {
		if (strlen(value) > 0)
			time_tooltip_timezone = strdup(value);
	}
	else if (strcmp(key, "clock_lclick_command") == 0) {
		if (strlen(value) > 0)
			clock_lclick_command = strdup(value);
	}
	else if (strcmp(key, "clock_rclick_command") == 0) {
		if (strlen(value) > 0)
			clock_rclick_command = strdup(value);
	}

	/* Taskbar */
	else if (strcmp (key, "taskbar_mode") == 0) {
		if (strcmp (value, "multi_desktop") == 0) panel_mode = MULTI_DESKTOP;
		else panel_mode = SINGLE_DESKTOP;
	}
	else if (strcmp (key, "taskbar_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_taskbar.area.paddingxlr = panel_config.g_taskbar.area.paddingx = atoi (value1);
		if (value2) panel_config.g_taskbar.area.paddingy = atoi (value2);
		if (value3) panel_config.g_taskbar.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "taskbar_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_taskbar.background[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);
		if (panel_config.g_taskbar.background[TASKBAR_ACTIVE] == 0)
			panel_config.g_taskbar.background[TASKBAR_ACTIVE] = panel_config.g_taskbar.background[TASKBAR_NORMAL];
	}
	else if (strcmp (key, "taskbar_active_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_taskbar.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp (key, "taskbar_name") == 0) {
		taskbarname_enabled = atoi (value);
	}
	else if (strcmp (key, "taskbar_name_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_taskbar.area_name.paddingxlr = panel_config.g_taskbar.area_name.paddingx = atoi (value1);
	}
	else if (strcmp (key, "taskbar_name_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);
		if (panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] == 0)
			panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = panel_config.g_taskbar.background_name[TASKBAR_NORMAL];
	}
	else if (strcmp (key, "taskbar_name_active_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp (key, "taskbar_name_font") == 0) {
		taskbarname_font_desc = pango_font_description_from_string (value);
	}
	else if (strcmp (key, "taskbar_name_font_color") == 0) {
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, taskbarname_font.color);
		if (value2) taskbarname_font.alpha = (atoi (value2) / 100.0);
		else taskbarname_font.alpha = 0.5;
	}
	else if (strcmp (key, "taskbar_name_active_font_color") == 0) {
		extract_values(value, &value1, &value2, &value3);
		get_color (value1, taskbarname_active_font.color);
		if (value2) taskbarname_active_font.alpha = (atoi (value2) / 100.0);
		else taskbarname_active_font.alpha = 0.5;
	}

	/* Task */
	else if (strcmp (key, "task_text") == 0)
		panel_config.g_task.text = atoi (value);
	else if (strcmp (key, "task_icon") == 0)
		panel_config.g_task.icon = atoi (value);
	else if (strcmp (key, "task_centered") == 0)
		panel_config.g_task.centered = atoi (value);
	else if (strcmp (key, "task_width") == 0) {
		// old parameter : just for backward compatibility
		panel_config.g_task.maximum_width = atoi (value);
		panel_config.g_task.maximum_height = 30;
	}
	else if (strcmp (key, "task_maximum_size") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_task.maximum_width = atoi (value1);
		panel_config.g_task.maximum_height = 30;
		if (value2)
			panel_config.g_task.maximum_height = atoi (value2);
	}
	else if (strcmp (key, "task_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_task.area.paddingxlr = panel_config.g_task.area.paddingx = atoi (value1);
		if (value2) panel_config.g_task.area.paddingy = atoi (value2);
		if (value3) panel_config.g_task.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "task_align") == 0) {
		extract_values(value, &value1, &value2, &value3);
		printf("task_align: %s\n", value1);
		if (strcmp (value1, "left") == 0) panel_config.g_task.align = ALIGN_LEFT;
		else if (strcmp (value1, "center") == 0) panel_config.g_task.align = ALIGN_CENTER;
		else if (strcmp (value1, "right") == 0) panel_config.g_task.align = ALIGN_RIGHT;
		else fprintf(stderr, "Unknown value for task_align: %s\n", value1);
	}
	else if (strcmp (key, "task_font") == 0) {
		panel_config.g_task.font_desc = pango_font_description_from_string (value);
	}
	else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) {
		gchar** split = g_regex_split_simple("_", key, 0, 0);
		int status = get_task_status(split[1]);
		g_strfreev(split);
		extract_values(value, &value1, &value2, &value3);
		float alpha = 1;
		if (value2) alpha = (atoi (value2) / 100.0);
		get_color (value1, panel_config.g_task.font[status].color);
		panel_config.g_task.font[status].alpha = alpha;
		panel_config.g_task.config_font_mask |= (1<<status);
	}
	else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
		gchar** split = g_regex_split_simple("_", key, 0, 0);
		int status = get_task_status(split[1]);
		g_strfreev(split);
		extract_values(value, &value1, &value2, &value3);
		panel_config.g_task.alpha[status] = atoi(value1);
		panel_config.g_task.saturation[status] = atoi(value2);
		panel_config.g_task.brightness[status] = atoi(value3);
		panel_config.g_task.config_asb_mask |= (1<<status);
	}
	else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
		gchar** split = g_regex_split_simple("_", key, 0, 0);
		int status = get_task_status(split[1]);
		g_strfreev(split);
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
		panel_config.g_task.config_background_mask |= (1<<status);
		if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
	}
	// "tooltip" is deprecated but here for backwards compatibility
	else if (strcmp (key, "task_tooltip") == 0 || strcmp(key, "tooltip") == 0)
		panel_config.g_task.tooltip_enabled = atoi(value);

	/* Systray */
	else if (strcmp (key, "systray_padding") == 0) {
		if (new_config_file == 0 && systray_enabled == 0) {
			systray_enabled = 1;
			if (panel_items_order) {
				char* tmp = g_strconcat(panel_items_order, "S", NULL);
				g_free( panel_items_order );
				panel_items_order = tmp;
			}
			else
				panel_items_order = g_strdup("S");
		}
		extract_values(value, &value1, &value2, &value3);
		systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
		if (value2) systray.area.paddingy = atoi (value2);
		if (value3) systray.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "systray_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		systray.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp(key, "systray_sort") == 0) {
		if (strcmp(value, "descending") == 0)
			systray.sort = -1;
		else if (strcmp(value, "ascending") == 0)
			systray.sort = 1;
		else if (strcmp(value, "left2right") == 0)
			systray.sort = 2;
		else  if (strcmp(value, "right2left") == 0)
			systray.sort = 3;
	}
	else if (strcmp(key, "systray_icon_size") == 0) {
		systray_max_icon_size = atoi(value);
	}
	else if (strcmp(key, "systray_icon_asb") == 0) {
		extract_values(value, &value1, &value2, &value3);
		systray.alpha = atoi(value1);
		systray.saturation = atoi(value2);
		systray.brightness = atoi(value3);
	}

	/* Launcher */
	else if (strcmp (key, "launcher_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		panel_config.launcher.area.paddingxlr = panel_config.launcher.area.paddingx = atoi (value1);
		if (value2) panel_config.launcher.area.paddingy = atoi (value2);
		if (value3) panel_config.launcher.area.paddingx = atoi (value3);
	}
	else if (strcmp (key, "launcher_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		panel_config.launcher.area.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp(key, "launcher_icon_size") == 0) {
		launcher_max_icon_size = atoi(value);
	}
	else if (strcmp(key, "launcher_item_app") == 0) {
		char *app = strdup(value);
		panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, app);
	}
	else if (strcmp(key, "launcher_apps_dir") == 0) {

		GList *list = dir_scan_alpha(value, "*.desktop");

		for (list = g_list_first(list); list; list = g_list_next(list)) {
			fprintf(stderr, "Add launcher app: %s\n", (const char *)list->data);
			panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, (char *)strdup((const char *)list->data));
		}

		// Cleanup
		g_list_free_full(list, g_free);
	}
	else if (strcmp(key, "launcher_icon_theme") == 0) {
		// if XSETTINGS manager running, tint2 use it.
		if (!icon_theme_name)
			icon_theme_name = strdup(value);
	}
	else if (strcmp(key, "launcher_icon_asb") == 0) {
		extract_values(value, &value1, &value2, &value3);
		launcher_alpha = atoi(value1);
		launcher_saturation = atoi(value2);
		launcher_brightness = atoi(value3);
	}
	else if (strcmp(key, "launcher_tooltip") == 0) {
		launcher_tooltip_enabled = atoi(value);
	}

	/* Tooltip */
	else if (strcmp (key, "tooltip_show_timeout") == 0) {
		int timeout_msec = 1000*atof(value);
		g_tooltip.show_timeout_msec = timeout_msec;
	}
	else if (strcmp (key, "tooltip_hide_timeout") == 0) {
		int timeout_msec = 1000*atof(value);
		g_tooltip.hide_timeout_msec = timeout_msec;
	}
	else if (strcmp (key, "tooltip_padding") == 0) {
		extract_values(value, &value1, &value2, &value3);
		if (value1) g_tooltip.paddingx = atoi(value1);
		if (value2) g_tooltip.paddingy = atoi(value2);
	}
	else if (strcmp (key, "tooltip_background_id") == 0) {
		int id = atoi (value);
		id = (id < backgrounds->len && id >= 0) ? id : 0;
		g_tooltip.bg = &g_array_index(backgrounds, Background, id);
	}
	else if (strcmp (key, "tooltip_font_color") == 0) {
		extract_values(value, &value1, &value2, &value3);
		get_color(value1, g_tooltip.font_color.color);
		if (value2) g_tooltip.font_color.alpha = (atoi (value2) / 100.0);
		else g_tooltip.font_color.alpha = 0.1;
	}
	else if (strcmp (key, "tooltip_font") == 0) {
		g_tooltip.font_desc = pango_font_description_from_string(value);
	}

	/* Mouse actions */
	else if (strcmp (key, "mouse_middle") == 0)
		get_action (value, &mouse_middle);
	else if (strcmp (key, "mouse_right") == 0)
		get_action (value, &mouse_right);
	else if (strcmp (key, "mouse_scroll_up") == 0)
		get_action (value, &mouse_scroll_up);
	else if (strcmp (key, "mouse_scroll_down") == 0)
		get_action (value, &mouse_scroll_down);

	/* autohide options */
	else if (strcmp(key, "autohide") == 0)
		panel_autohide = atoi(value);
	else if (strcmp(key, "autohide_show_timeout") == 0)
		panel_autohide_show_timeout = 1000*atof(value);
	else if (strcmp(key, "autohide_hide_timeout") == 0)
		panel_autohide_hide_timeout = 1000*atof(value);
	else if (strcmp(key, "strut_policy") == 0) {
		if (strcmp(value, "follow_size") == 0)
			panel_strut_policy = STRUT_FOLLOW_SIZE;
		else if (strcmp(value, "none") == 0)
			panel_strut_policy = STRUT_NONE;
		else
			panel_strut_policy = STRUT_MINIMUM;
	}
	else if (strcmp(key, "autohide_height") == 0) {
		panel_autohide_height = atoi(value);
		if (panel_autohide_height == 0) {
			// autohide need height > 0
			panel_autohide_height = 1;
		}
	}

	// old config option
	else if (strcmp(key, "systray") == 0) {
		if (new_config_file == 0) {
			systray_enabled = atoi(value);
			if (systray_enabled) {
				if (panel_items_order) {
					char* tmp = g_strconcat(panel_items_order, "S", NULL);
					g_free( panel_items_order );
					panel_items_order = tmp;
				}
				else
					panel_items_order = g_strdup("S");
			}
		}
	}
#ifdef ENABLE_BATTERY
	else if (strcmp(key, "battery") == 0) {
		if (new_config_file == 0) {
			battery_enabled = atoi(value);
			if (battery_enabled) {
				if (panel_items_order) {
					char* tmp = g_strconcat(panel_items_order, "B", NULL);
					g_free( panel_items_order );
					panel_items_order = tmp;
				}
				else
					panel_items_order = g_strdup("B");
			}
		}
	}
#endif
	else
		fprintf(stderr, "tint2 : invalid option \"%s\",\n  upgrade tint2 or correct your config file\n", key);

	if (value1) free (value1);
	if (value2) free (value2);
	if (value3) free (value3);
}