Пример #1
0
static void
pdb_lang_start_element_cb (void *user_data,
                           const char *name,
                           const char **atts)
{
  PdbLang *lang = user_data;

  if (lang->in_lingvo)
    {
      pdb_xml_abort (lang->parser,
                     PDB_ERROR,
                     PDB_ERROR_BAD_FORMAT,
                     _("Unexpected tag in a ‘lingvo’ tag"));
    }
  else if (!strcmp (name, "lingvo"))
    {
      const char *code;
      GError *attrib_error = NULL;

      if (pdb_xml_get_attribute (name, atts, "kodo", &code, &attrib_error))
        {
          g_string_set_size (lang->code_buf, 0);
          g_string_append (lang->code_buf, code);
          g_string_set_size (lang->name_buf, 0);
          lang->in_lingvo = TRUE;
        }
      else
        pdb_xml_abort_error (lang->parser, attrib_error);
    }
}
Пример #2
0
static void
dump_mem (guint8 * mem, guint size)
{
  guint i, j;
  GString *string = g_string_sized_new (50);
  GString *chars = g_string_sized_new (18);

  i = j = 0;
  while (i < size) {
    if (g_ascii_isprint (mem[i]))
      g_string_append_printf (chars, "%c", mem[i]);
    else
      g_string_append_printf (chars, ".");

    g_string_append_printf (string, "%02x ", mem[i]);

    j++;
    i++;

    if (j == 16 || i == size) {
      g_print ("%08x (%p): %-48.48s %-16.16s\n", i - j, mem + i - j,
          string->str, chars->str);
      g_string_set_size (string, 0);
      g_string_set_size (chars, 0);
      j = 0;
    }
  }
  g_string_free (string, TRUE);
  g_string_free (chars, TRUE);
}
Пример #3
0
static void
item_end_element (GMarkupParseContext *context,
		  const gchar         *element_name,
		  gpointer             user_data,
		  GError             **error)
{
  ItemParserData *data = (ItemParserData*)user_data;

  /* Append the translated strings */
  if (data->string->len)
    {
      if (data->translatable)
	{
	  gchar *translated;

	  /* FIXME: This will not use the domain set in the .ui file,
	   * since the parser is not telling the builder about the domain.
	   * However, it will work for gtk_builder_set_translation_domain() calls.
	   */
	  translated = _gtk_builder_parser_translate (data->domain,
						      data->context,
						      data->string->str);
	  g_string_set_size (data->string, 0);
	  g_string_append (data->string, translated);
	}

      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->object), data->string->str);
    }

  data->translatable = FALSE;
  g_string_set_size (data->string, 0);
  g_free (data->context);
  data->context = NULL;
  data->is_text = FALSE;
}
Пример #4
0
static liHandlerResult expire(liVRequest *vr, gpointer param, gpointer *context) {
	struct tm tm;
	time_t expire_date;
	guint len;
	gint max_age;
	GString *date_str = vr->wrk->tmp_str;
	expire_rule *rule = param;
	guint num = rule->num;
	time_t now = (time_t)li_cur_ts(vr->wrk);

	UNUSED(context);

	if (rule->base == EXPIRE_ACCESS) {
		expire_date = now + num;
		max_age = num;
	} else {
		/* modification */
		struct stat st;
		gint err;

		if (!vr->physical.path->len)
			return LI_HANDLER_GO_ON;

		switch (li_stat_cache_get(vr, vr->physical.path, &st, &err, NULL)) {
		case LI_HANDLER_GO_ON: break;
		case LI_HANDLER_WAIT_FOR_EVENT: return LI_HANDLER_WAIT_FOR_EVENT;
		default: return LI_HANDLER_GO_ON;
		}

		expire_date = st.st_mtime + num;

		if (expire_date < now)
			expire_date = now;

		max_age = expire_date - now;
	}

	/* format date */
	g_string_set_size(date_str, 255);

	if (!gmtime_r(&expire_date, &tm)) {
		VR_ERROR(vr, "gmtime_r(%"G_GUINT64_FORMAT") failed: %s", (guint64)expire_date, g_strerror(errno));
		return LI_HANDLER_GO_ON;
	}

	len = strftime(date_str->str, date_str->allocated_len, "%a, %d %b %Y %H:%M:%S GMT", &tm);
	if (len == 0)
		return LI_HANDLER_GO_ON;

	g_string_set_size(date_str, len);

	/* finally set the headers */
	li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Expires"), GSTR_LEN(date_str));
	g_string_truncate(date_str, 0);
	g_string_append_len(date_str, CONST_STR_LEN("max-age="));
	li_string_append_int(date_str, max_age);
	li_http_header_append(vr->response.headers, CONST_STR_LEN("Cache-Control"), GSTR_LEN(date_str));

	return LI_HANDLER_GO_ON;
}
Пример #5
0
static void
item_end_element (GMarkupParseContext *context,
		  const gchar         *element_name,
		  gpointer             user_data,
		  GError             **error)
{
  ItemParserData *data = (ItemParserData*)user_data;

  /* Append the translated strings */
  if (data->string->len)
    {
      if (data->translatable)
	{
	  const gchar *translated;

	  translated = _gtk_builder_parser_translate (data->domain,
						      data->context,
						      data->string->str);
	  g_string_set_size (data->string, 0);
	  g_string_append (data->string, translated);
	}

      gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (data->object), data->id, data->string->str);
    }

  data->translatable = FALSE;
  g_string_set_size (data->string, 0);
  g_free (data->context);
  data->context = NULL;
  g_free (data->id);
  data->id = NULL;
  data->is_text = FALSE;
}
Пример #6
0
/**
 * zif_load_multiline_key_file: (skip)
 * @filename: The repo file to load
 * @error: A #GError, or %NULL
 *
 * The source.repo files are not standard GKeyFiles as they can contain
 * multiple lines for a key value, e.g.
 *
 * [multiline1]
 * name=Multiline1
 * baseurl=http://download1.fedoraproject.org/
 *	http://download2.fedoraproject.org/
 * enabled=true
 *
 * Return value: A #GKeyFile, or %NULL
 *
 * Since: 0.2.4
 **/
GKeyFile *
zif_load_multiline_key_file (const gchar *filename,
			     GError **error)
{
	gboolean ret;
	gchar *data = NULL;
	gchar **lines = NULL;
	GKeyFile *file = NULL;
	gsize len;
	GString *string = NULL;
	guint i;

	/* load file */
	ret = g_file_get_contents (filename, &data, &len, error);
	if (!ret)
		goto out;

	/* split into lines */
	string = g_string_new ("");
	lines = g_strsplit (data, "\n", -1);
	for (i = 0; lines[i] != NULL; i++) {
		/* if a line starts with whitespace, then append it on
		 * the previous line */
		g_strdelimit (lines[i], "\t", ' ');
		if (lines[i][0] == ' ' && string->len > 0) {
			g_string_set_size (string, string->len - 1);
			g_string_append_printf (string,
						";%s\n",
						g_strchug (lines[i]));
		} else {
			g_string_append_printf (string,
						"%s\n",
						lines[i]);
		}
	}

	/* remove final newline */
	if (string->len > 0)
		g_string_set_size (string, string->len - 1);

	/* load modified lines */
	file = g_key_file_new ();
	ret = g_key_file_load_from_data (file,
					 string->str,
					 -1,
					 G_KEY_FILE_KEEP_COMMENTS,
					 error);
	if (!ret) {
		g_key_file_free (file);
		file = NULL;
		goto out;
	}
out:
	if (string != NULL)
		g_string_free (string, TRUE);
	g_free (data);
	g_strfreev (lines);
	return file;
}
void cd_do_search_matching_icons (void)
{
	if (myData.sCurrentText->len == 0)
		return;
	g_print ("%s (%s)\n", __func__, myData.sCurrentText->str);
	gchar *str = strchr (myData.sCurrentText->str, ' ');  // on ne compte pas les arguments d'une eventuelle commande deja tapee.
	int length = myData.sCurrentText->len;
	if (str != NULL)
	{
		g_string_set_size (myData.sCurrentText, str - myData.sCurrentText->str + 1);
		g_print (" on ne cherchera que '%s' (len=%d)\n", myData.sCurrentText->str, myData.sCurrentText->len);
	}
		
	if (myData.pMatchingIcons == NULL)
	{
		if (myData.bSessionStartedAutomatically)  // on cherche dans le dock courant.
		{
			g_print ("on cherche dans le dock\n");
			_cd_do_search_matching_icons_in_dock (myData.pCurrentDock);
			myData.pMatchingIcons = g_list_reverse (myData.pMatchingIcons);
		}
		else
		{
			g_print ("on cherche tout\n");
			// on parcours tous les docks.
			cairo_dock_foreach_icons_in_docks ((CairoDockForeachIconFunc) _cd_do_search_in_one_dock, NULL);
			myData.pMatchingIcons = g_list_reverse (myData.pMatchingIcons);
			
			// on rajoute les icones ne venant pas du dock.
			cd_do_find_matching_applications ();
		}
	}
	else  // optimisation : on peut se contenter de chercher parmi les icones deja trouvees.
	{
		g_print ("on se contente d'enlever celles en trop\n");
		GList *ic, *next_ic;
		Icon *pIcon;
		ic = myData.pMatchingIcons;
		while (ic != NULL)
		{
			pIcon = ic->data;
			next_ic = ic->next;
			if (! _cd_do_icon_match (pIcon, myData.sCurrentText->str, myData.sCurrentText->len))
				myData.pMatchingIcons = g_list_delete_link (myData.pMatchingIcons, ic);
			ic = next_ic;
		}
	}
	myData.pCurrentMatchingElement = NULL;
	myData.iMatchingGlideCount = 0;
	myData.iPreviousMatchingOffset = 0;
	myData.iCurrentMatchingOffset = 0;
	if (myData.pCurrentApplicationToLoad != NULL)  // on va continuer le chargement sur la sous-liste.
		myData.pCurrentApplicationToLoad = myData.pMatchingIcons;  // comme l'ordre de la liste n'a pas ete altere, on n'est sur de ne pas sauter d'icone.
	cairo_dock_redraw_container (CAIRO_CONTAINER (myData.pCurrentDock));
	//g_print ("%d / %d\n", length , myData.sCurrentText->len);
	if (length != myData.sCurrentText->len)
		g_string_set_size (myData.sCurrentText, length);
}
Пример #8
0
/* convert qq format to purple
   Notice: text is in qq charset, GB18030 or utf8 */
gchar *qq_im_fmt_to_purple(qq_im_format *fmt, gchar *text)
{
	GString *converted, *tmp;
	gchar *ret;
	gint size;

	converted = g_string_new(text);
	tmp = g_string_new("");
	g_string_append_printf(tmp, "<font color=\"#%02x%02x%02x\">",
		fmt->rgb[0], fmt->rgb[1], fmt->rgb[2]);
	g_string_prepend(converted, tmp->str);
	g_string_set_size(tmp, 0);
	g_string_append(converted, "</font>");

	/* Fixme:
	 * check font face can be convert to utf8 or not?
	 * If failed, prepending font face cause msg display as "(NULL)" */
	if (fmt->font != NULL) {
		g_string_append_printf(tmp, "<font face=\"%s\">", fmt->font);
		g_string_prepend(converted, tmp->str);
		g_string_set_size(tmp, 0);
		g_string_append(converted, "</font>");
	}
	size = (fmt->attr & 0x1f) / 3;
	if (size >= 0) {
		g_string_append_printf(tmp, "<font size=\"%d\">", size);
		g_string_prepend(converted, tmp->str);
		g_string_set_size(tmp, 0);
		g_string_append(converted, "</font>");
	}
	if (fmt->attr & 0x20) {
		/* bold */
		g_string_prepend(converted, "<b>");
		g_string_append(converted, "</b>");
	}
	if (fmt->attr & 0x40) {
		/* italic */
		g_string_prepend(converted, "<i>");
		g_string_append(converted, "</i>");
	}
	if (fmt->attr & 0x80) {
		/* underline */
		g_string_prepend(converted, "<u>");
		g_string_append(converted, "</u>");
	}

	g_string_free(tmp, TRUE);
	ret = converted->str;
	g_string_free(converted, FALSE);
	return ret;
}
Пример #9
0
END_TEST

START_TEST(test_http_requests_on_same_socket)
{
	guint i;
	gint err;
	gchar sid[32];
	GString *buff = qev_buffer_get();
	GString *msg = qev_buffer_get();
	qev_fd_t s = test_socket();

	_uuid(sid);

	// Opening handshake
	g_string_printf(buff, INIT_HEADERS, sid);
	err = send(s, buff->str, buff->len, 0);
	ck_assert_int_eq(err, buff->len);

	err = recv(s, buff->str, buff->allocated_len, 0);
	ck_assert(err > 0);
	g_string_set_size(buff, err);
	ck_assert(strstr(buff->str, "/qio/callback/1") != NULL);

	// First poll, sending nothing
	g_string_printf(buff, MSG_HEADERS, sid, msg->len, msg->str);
	err = send(s, buff->str, buff->len, 0);
	ck_assert_int_eq(err, buff->len);

	// Send a ping with an expected callback: the first request should bring
	// back the ping's callback
	g_string_assign(msg, "/qio/ping:2=null");
	g_string_printf(buff, MSG_HEADERS, sid, msg->len, msg->str);
	err = send(s, buff->str, buff->len, 0);
	ck_assert_int_eq(err, buff->len);

	for (i = 0; i < 2; i++) {
		err = recv(s, buff->str, buff->allocated_len, 0);
		ck_assert(err > 0);
		g_string_set_size(buff, err);
		if (strstr(buff->str, "/qio/callback/2") != NULL) {
			break;
		}
	}

	ck_assert(strstr(buff->str, "/qio/callback/2") != NULL);

	qev_buffer_put(msg);
	qev_buffer_put(buff);
	close(s);
}
Пример #10
0
gboolean
read_subshell_prompt (void)
{
    int rc = 0;
    ssize_t bytes = 0;
    struct timeval timeleft = { 0, 0 };

    fd_set tmp;
    FD_ZERO (&tmp);
    FD_SET (mc_global.tty.subshell_pty, &tmp);

    /* First time through */
    if (subshell_prompt == NULL)
        subshell_prompt = g_string_sized_new (INITIAL_PROMPT_SIZE);

    while (subshell_alive
            && (rc = select (mc_global.tty.subshell_pty + 1, &tmp, NULL, NULL, &timeleft)) != 0)
    {
        ssize_t i;

        /* Check for `select' errors */
        if (rc == -1)
        {
            if (errno == EINTR)
            {
                if (mc_global.tty.winch_flag != 0)
                    tty_change_screen_size ();

                continue;
            }

            fprintf (stderr, "select (FD_SETSIZE, &tmp...): %s\r\n", unix_error_string (errno));
            exit (EXIT_FAILURE);
        }

        bytes = read (mc_global.tty.subshell_pty, pty_buffer, sizeof (pty_buffer));

        /* Extract the prompt from the shell output */
        g_string_set_size (subshell_prompt, 0);
        for (i = 0; i < bytes; i++)
            if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r')
                g_string_set_size (subshell_prompt, 0);
            else if (pty_buffer[i] != '\0')
                g_string_append_c (subshell_prompt, pty_buffer[i]);
    }

    return (rc != 0 || bytes != 0);
}
Пример #11
0
static void
attributes_end_element (GMarkupParseContext  *context,
			const gchar          *element_name,
			gpointer              user_data,
			GError              **error)
{
  AttributesSubParserData *data = (AttributesSubParserData*)user_data;
  GValue val = G_VALUE_INIT;

  if (!data->attr_name)
    return;

  if (!gtk_builder_value_from_string_type (data->builder, G_TYPE_INT, data->string->str, &val, error))
    {
      _gtk_builder_prefix_error (data->builder, context, error);
       return;
    }

  gtk_cell_layout_add_attribute (data->cell_layout,
				 data->renderer,
				 data->attr_name,
                                 g_value_get_int (&val));

  g_free (data->attr_name);
  data->attr_name = NULL;

  g_string_set_size (data->string, 0);
}
Пример #12
0
static void
gnt_text_view_reflow(GntTextView *view)
{
	/* This is pretty ugly, and inefficient. Someone do something about it. */
	GntTextLine *line;
	GList *back, *iter, *list;
	GString *string;
	int pos = 0;    /* no. of 'real' lines */

	list = view->list;
	while (list->prev) {
		line = list->data;
		if (!line->soft)
			pos++;
		list = list->prev;
	}

	back = g_list_last(view->list);
	view->list = NULL;

	string = view->string;
	view->string = NULL;
	reset_text_view(view);

	view->string = g_string_set_size(view->string, string->len);
	view->string->len = 0;
	GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING);

	for (; back; back = back->prev) {
		line = back->data;
		if (back->next && !line->soft) {
			gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL);
		}

		for (iter = line->segments; iter; iter = iter->next) {
			GntTextSegment *seg = iter->data;
			char *start = string->str + seg->start;
			char *end = string->str + seg->end;
			char back = *end;
			*end = '\0';
			gnt_text_view_append_text_with_flags(view, start, seg->tvflag);
			*end = back;
		}
		free_text_line(line, NULL);
	}
	g_list_free(list);

	list = view->list = g_list_first(view->list);
	/* Go back to the line that was in view before resizing started */
	while (pos--) {
		while (((GntTextLine*)list->data)->soft)
			list = list->next;
		list = list->next;
	}
	view->list = list;
	GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING);
	if (GNT_WIDGET(view)->window)
		gnt_widget_draw(GNT_WIDGET(view));
	g_string_free(string, TRUE);
}
Пример #13
0
void
pdb_trim_buf (GString *buf)
{
  char *dst;
  const char *src;

  /* Skip leading spaces and replacing all sets of whitespace
   * characters with a single space */
  for (dst = buf->str, src = buf->str;
       *src;
       src++)
    if (g_ascii_isspace (*src))
      {
        if (dst > buf->str && dst[-1] != ' ')
          *(dst)++ = ' ';
      }
    else
      *(dst++) = *src;

  /* Remove any trailing space */
  if (dst > buf->str && dst[-1] == ' ')
    dst--;

  g_string_set_size (buf, dst - buf->str);
}
Пример #14
0
static gint
format_padded_int64(GString *result, gint field_len, gchar pad_char, gint sign, gint base, guint64 value)
{
  gchar num[64];
  gint len, i, pos;

  if (base == 10)
    len = format_uint64_base10_rev(num, sizeof(num), sign, value);
  else if (base == 16)
    len = format_uint64_base16_rev(num, sizeof(num), value);
  else
    return 0;

  if (field_len == 0 || field_len < len)
    field_len = len;

  pos = result->len;
  if (G_UNLIKELY(result->allocated_len < pos + field_len + 1))
    {
      g_string_set_size(result, pos + field_len);
    }
  else
    {
      result->len += field_len;
      result->str[pos + field_len] = 0;
    }

  memset(result->str + pos, pad_char, field_len - len);
  for (i = 0; i < len; i++)
    {
      result->str[pos + field_len - i - 1] = num[i];
    }
  return field_len;
}
Пример #15
0
static gboolean
_manage_and_renew_header(struct http_parser_s *parser, GString *buf)
{
	if (!buf->len)
		return TRUE;

	gstr_chomp(buf);
	gchar *header = buf->str;
	gchar *sep = strchr(header, ':');
	if (!sep)
		return FALSE;
	*(sep++) = '\0';
	if (*(sep++) != ' ')
		return FALSE;

	oio_str_lower (header);
	if (*header == 'c' && !strcmp(header, "content-length"))
		parser->content_length = g_ascii_strtoll(sep, NULL, 10);

	if (parser->header_provider)
		parser->header_provider(header, sep);

	g_string_set_size(buf, 0);
	return TRUE;
}
Пример #16
0
/**
 * gusb_cmd_get_descriptions:
 **/
static gchar *
gusb_cmd_get_descriptions (GPtrArray *array)
{
	guint i;
	guint j;
	guint len;
	guint max_len = 19;
	GUsbCmdItem *item;
	GString *string;

	/* print each command */
	string = g_string_new ("");
	for (i = 0; i < array->len; i++) {
		item = g_ptr_array_index (array, i);
		g_string_append (string, "  ");
		g_string_append (string, item->name);
		g_string_append (string, " ");
		len = strlen (item->name);
		for (j = len; j < max_len+2; j++)
			g_string_append_c (string, ' ');
		g_string_append (string, item->description);
		g_string_append_c (string, '\n');
	}

	/* remove trailing newline */
	if (string->len > 0)
		g_string_set_size (string, string->len - 1);

	return g_string_free (string, FALSE);
}
Пример #17
0
/**
 * gpk_log_get_details_localised:
 **/
static gchar *
gpk_log_get_details_localised (const gchar *timespec, const gchar *data)
{
	GString *string;
	gchar *text;
	gchar **array;

	string = g_string_new ("");
	array = g_strsplit (data, "\n", 0);

	/* get each type */
	text = gpk_log_get_type_line (array, PK_INFO_ENUM_INSTALLING);
	if (text != NULL)
		g_string_append (string, text);
	g_free (text);
	text = gpk_log_get_type_line (array, PK_INFO_ENUM_REMOVING);
	if (text != NULL)
		g_string_append (string, text);
	g_free (text);
	text = gpk_log_get_type_line (array, PK_INFO_ENUM_UPDATING);
	if (text != NULL)
		g_string_append (string, text);
	g_free (text);
	g_strfreev (array);

	/* remove last \n */
	if (string->len > 0)
		g_string_set_size (string, string->len - 1);

	return g_string_free (string, FALSE);
}
Пример #18
0
gboolean li_chunkqueue_extract_to(liVRequest *vr, liChunkQueue *cq, goffset len, GString *dest) {
	liChunkIter ci;
	goffset coff, clen;
	g_string_set_size(dest, 0);
	if (len > cq->length) return FALSE;

	ci = li_chunkqueue_iter(cq);

	while (len > 0) {
		coff = 0;
		clen = li_chunkiter_length(ci);
		while (coff < clen) {
			gchar *buf;
			off_t we_have;
			if (LI_HANDLER_GO_ON != li_chunkiter_read(vr, ci, coff, len, &buf, &we_have)) goto error;
			g_string_append_len(dest, buf, we_have);
			coff += we_have;
			len -= we_have;
			if (len <= 0) return TRUE;
		}
		li_chunkiter_next(&ci);
	}

	return TRUE;

error:
	g_string_assign(dest, "");
	return FALSE;
}
Пример #19
0
/**
\brief Verifies that an argument list matches a given pattern.

The string pattern describes all acceptable variations of Mbus basic
types by representing each type by one single letter. An exception is
the Mbus list object that is is represented by two angle brackets
enclosing the the list elements representations. The following table
shows a list of possible types and the representation:

\li \c i MInteger
\li \c f MFloat
\li \c s MString
\li \c y MSymbol
\li \c d MData
\li \c <...> MList

For example, the pattern \c "<iify>" describes a list with four
elements. The first two elements are of type MInteger, the third
should be a MFloat and the fourth a MSymbol. If the given parameter
arguments matches this specification the function returns
TRUE. Otherwise FALSE is returned and if the third parameter is valid
GString object a description of the failure is append to it.

\param pattern describes the specification
\param arguments points to the arguments to check
\param[out] error if the match fails this parameter contains an error
description
\return TRUE if the pattern matches otherwise FALSE
*/
gboolean
mbus_argument_check( const gchar * pattern, const MObject * arguments,
		GString * error )
{
	GString *	args = g_string_new( NULL );
	guint		i;

	M_OBJECT_ASSERT( arguments, MLIST );
	g_string_set_size( args, 10 );

	for ( i = 0; i < mbus_list_length( ( MObject * ) arguments ); i++ ) {
		MObject * elem = mbus_list_index( ( MObject * ) arguments, i );

		switch ( elem->type ) {
		case MINTEGER:
		case MFLOAT:
		case MSTRING:
		case MSYMBOL:
		case MDATA:
		case MLIST:
			break;

		}
	}

	return TRUE;
}
Пример #20
0
/**
 * cd_parse_beagle_process_entry_huey:
 **/
static void
cd_parse_beagle_process_entry_huey (CdParseEntry *entry)
{
	gchar **tok;
	guint j;
	guint8 cmd;
	guint8 instruction = 0;
	const gchar *command_as_text;
	GString *output = NULL;

	entry->ep_description = "default";

	/* only know how to parse 8 bytes */
	tok = g_strsplit (entry->summary, " ", -1);
	if (g_strv_length (tok) != 8) {
		g_print ("not 8 tokens: %s\n", entry->summary);
		goto out;
	}

	output = g_string_new ("");
	for (j = 0; j < 8; j++) {
		command_as_text = NULL;
		cmd = g_ascii_strtoll (tok[j], NULL, 16);
		if (j == 0 && entry->direction == CD_PARSE_ENTRY_DIRECTION_REPLY) {
			command_as_text = huey_rc_to_string (cmd);
			if (command_as_text == NULL)
				g_warning ("return code 0x%02x not known in %s", cmd, entry->summary);
		}
		if ((j == 0 && entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST) ||
		    (j == 1 && entry->direction == CD_PARSE_ENTRY_DIRECTION_REPLY)) {
			instruction = cmd;
			command_as_text = huey_cmd_code_to_string (instruction);
			if (command_as_text == NULL)
				g_warning ("command code 0x%02x not known", cmd);
		}

		/* some requests are filled with junk data */
		if (entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST &&
		    instruction == HUEY_CMD_REGISTER_READ && j > 1)
			g_string_append_printf (output, "xx ");
		else if (entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST &&
			 instruction == HUEY_CMD_SET_LEDS && j > 4)
			g_string_append_printf (output, "xx ");
		else if (entry->direction == CD_PARSE_ENTRY_DIRECTION_REQUEST &&
			 instruction == HUEY_CMD_GET_AMBIENT && j > 3)
			g_string_append_printf (output, "xx ");
		else if (command_as_text != NULL)
			g_string_append_printf (output, "%02x(%s) ", cmd, command_as_text);
		else
			g_string_append_printf (output, "%02x ", cmd);
	}

	/* remove trailing space */
	if (output->len > 1)
		g_string_set_size (output, output->len - 1);
out:
	if (output != NULL)
		entry->summary_pretty = g_string_free (output, FALSE);
	g_strfreev (tok);
}
Пример #21
0
static gchar *
format(Log4gLayout *base, Log4gLoggingEvent *event)
{
	struct Private *priv = GET_PRIVATE(base);
	g_string_set_size(priv->string, 0);
	log4g_date_layout_date_format(base, priv->string, event);
	g_string_append_c(priv->string, ' ');
	if (priv->thread) {
		g_string_append_printf(priv->string, "[%s] ",
				log4g_logging_event_get_thread_name(event));
	}
	g_string_append(priv->string,
			log4g_level_to_string(log4g_logging_event_get_level(
					event)));
	g_string_append_c(priv->string, ' ');
	if (priv->category) {
		g_string_append(priv->string,
				log4g_logging_event_get_logger_name(event));
		g_string_append_c(priv->string, ' ');
	}
	if (priv->context) {
		const gchar *ndc = log4g_logging_event_get_ndc(event);
		if (ndc) {
			g_string_append(priv->string, ndc);
			g_string_append_c(priv->string, ' ');
		}
	}
	g_string_append(priv->string, "- ");
	g_string_append(priv->string,
			log4g_logging_event_get_rendered_message(event));
	g_string_append(priv->string, LOG4G_LAYOUT_LINE_SEP);
	return priv->string->str;
}
Пример #22
0
static gboolean
_manage_and_renew_command(struct http_parser_s *parser, GString *buf)
{
	gchar *cmd, *selector, *version;

	if (!buf->len)
		return FALSE;

	gstr_chomp(buf);
	cmd = buf->str;
	selector = strchr(cmd, ' ');
	if (!selector)
		return FALSE;
	*(selector++) = '\0';
	version = strrchr(selector, ' ');
	if (!version)
		return FALSE;
	*(version++) = '\0';

	if (parser->command_provider)
		parser->command_provider(cmd, selector, version);

	g_string_set_size(buf, 0);
	return TRUE;
}
Пример #23
0
/**
 * pk_filter_bitfield_to_string:
 * @filters: The enumerated type values
 *
 * Converts a enumerated type bitfield to its text representation
 *
 * Return value: the enumerated constant value, e.g. "available;~gui"
 *
 * Since: 0.5.2
 **/
gchar *
pk_filter_bitfield_to_string (PkBitfield filters)
{
	GString *string;
	guint i;

	/* shortcut */
	if (filters == 0)
		return g_strdup (pk_filter_enum_to_string (PK_FILTER_ENUM_NONE));

	string = g_string_new ("");
	for (i = 0; i < PK_FILTER_ENUM_LAST; i++) {
		if ((filters & pk_bitfield_value (i)) == 0)
			continue;
		g_string_append_printf (string, "%s;", pk_filter_enum_to_string (i));
	}
	/* do we have a 'none' filter? \n */
	if (string->len == 0) {
		g_warning ("not valid!");
		g_string_append (string, pk_filter_enum_to_string (PK_FILTER_ENUM_NONE));
	} else {
		/* remove last \n */
		g_string_set_size (string, string->len - 1);
	}
	return g_string_free (string, FALSE);
}
Пример #24
0
static gboolean
plugin_custom_tag_start (GtkBuildable  *buildable,
			 GtkBuilder    *builder,
			 GObject       *child,
			 const gchar   *tagname,
			 GMarkupParser *parser,
			 gpointer      *data)
{
	GigglePluginPriv         *priv = GET_PRIV (buildable);
	GigglePluginParseContext *context;

	g_return_val_if_fail (NULL == child, FALSE);
	g_return_val_if_fail (!g_strcmp0 (tagname, "ui"), FALSE);

	parser->start_element = plugin_start_element;
	parser->end_element   = plugin_end_element;
	parser->text          = plugin_text;

	g_string_set_size (priv->ui_buffer, 0);

	context = *data = g_slice_new0 (GigglePluginParseContext);
	context->buffer = priv->ui_buffer;

	return TRUE;
}
Пример #25
0
/**
 * pk_transaction_flag_bitfield_to_string:
 * @transaction_flags: The enumerated type values
 *
 * Converts a enumerated type bitfield to its text representation
 *
 * Return value: the enumerated constant value, e.g. "only-trusted;simulate"
 *
 * Since: 0.8.1
 **/
gchar *
pk_transaction_flag_bitfield_to_string (PkBitfield transaction_flags)
{
	GString *string;
	guint i;

	/* shortcut */
	if (transaction_flags == 0)
		return g_strdup (pk_transaction_flag_enum_to_string (PK_TRANSACTION_FLAG_ENUM_NONE));

	string = g_string_new ("");
	for (i = 0; i < PK_TRANSACTION_FLAG_ENUM_LAST; i++) {
		if ((transaction_flags & pk_bitfield_value (i)) == 0)
			continue;
		g_string_append_printf (string, "%s;", pk_transaction_flag_enum_to_string (i));
	}
	/* do we have a 'none' transaction_flag? \n */
	if (string->len == 0) {
		g_warning ("not valid!");
		g_string_append (string, pk_transaction_flag_enum_to_string (PK_TRANSACTION_FLAG_ENUM_NONE));
	} else {
		/* remove last \n */
		g_string_set_size (string, string->len - 1);
	}
	return g_string_free (string, FALSE);
}
void
tpaw_string_replace_escaped (const gchar *text,
    gssize len,
    gpointer match_data,
    gpointer user_data)
{
  GString *string = user_data;
  gchar *escaped;
  guint i;
  gsize escaped_len, old_len;

  escaped = g_markup_escape_text (text, len);
  escaped_len = strlen (escaped);

  /* Allocate more space to string (we really need a g_string_extend...) */
  old_len = string->len;
  g_string_set_size (string, old_len + escaped_len);
  g_string_truncate (string, old_len);

  /* Remove '\r' */
  for (i = 0; i < escaped_len; i++)
    {
      if (escaped[i] != '\r')
        g_string_append_c (string, escaped[i]);
    }

  g_free (escaped);
}
Пример #27
0
void lttv_event_to_string(LttvEvent *event, GString *a_string,
				gboolean field_names, gboolean long_version)
{
	GString* processInfos = g_string_new("");
	GString* fields = g_string_new("");
	GString* cpuId_str = g_string_new("");

	getProcessInfosFromEvent(event, processInfos);
	getFieldsFromEvent(event->bt_event, fields, field_names);
	getCPUIdFromEvent(event, cpuId_str);

	g_string_set_size(a_string,0);
	if(long_version){
		g_string_append_printf(a_string,"%" PRIu64 " %s: ", 
				       bt_ctf_get_timestamp(event->bt_event), 
				       bt_ctf_event_name(event->bt_event));
	}
	g_string_append_printf(a_string, "{ %s }", cpuId_str->str);
	
	if (strcmp("", processInfos->str) < 0) {
		g_string_append_printf(a_string, ", { %s }", processInfos->str);
	}
	if (strcmp("", fields->str) < 0) {
		g_string_append_printf(a_string, ", { %s }", fields->str);
	}

	g_string_free(fields, TRUE);
	g_string_free(processInfos, TRUE);
	g_string_free(cpuId_str, TRUE);
}
Пример #28
0
Файл: util.c Проект: Jat15/uzbl
GString *
append_escaped (GString *dest, const gchar *src) {
    g_assert(dest);
    g_assert(src);

    // Hint that we are going to append another string.
    int oldlen = dest->len;
    g_string_set_size (dest, dest->len + strlen(src) * 2);
    g_string_truncate (dest, oldlen);

    // Append src char by char with baddies escaped
    for (const gchar *p = src; *p; p++) {
        switch (*p) {
        case '\\':
            g_string_append (dest, "\\\\");
            break;
        case '\'':
            g_string_append (dest, "\\'");
            break;
        case '\n':
            g_string_append (dest, "\\n");
            break;
        default:
            g_string_append_c (dest, *p);
            break;
        }
    }
    return dest;
}
Пример #29
0
/**
 * pk_backend_get_accepted_eula_string:
 */
gchar *
pk_backend_get_accepted_eula_string (PkBackend *backend)
{
	GString *string;
	gchar *result = NULL;
	GList *keys = NULL;
	GList *l;

	g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);

	/* optimise for the common case */
	if (g_hash_table_size (backend->priv->eulas) == 0)
		goto out;

	/* create a string of the accepted EULAs */
	string = g_string_new ("");
	keys = g_hash_table_get_keys (backend->priv->eulas);
	for (l=keys; l != NULL; l=l->next)
		g_string_append_printf (string, "%s;", (const gchar *) l->data);

	/* remove the trailing ';' */
	g_string_set_size (string, string->len -1);
	result = g_string_free (string, FALSE);
out:
	g_list_free (keys);
	return result;
}
Пример #30
0
static gboolean
emss_process_message (struct _write_msg *msg)
{
	struct _EMSyncStream *emss = msg->emss;

	/* Force out any pending data before doing anything else. */
	if (emss->buffer != NULL && emss->buffer->len > 0) {
		EMSS_CLASS (emss)->sync_write (
			CAMEL_STREAM (emss), emss->buffer->str,
			emss->buffer->len);
		g_string_set_size (emss->buffer, 0);
	}

	switch (msg->op) {
		case EMSS_WRITE:
			EMSS_CLASS (emss)->sync_write (
				CAMEL_STREAM (emss), msg->string, msg->len);
			break;
		case EMSS_FLUSH:
			EMSS_CLASS (emss)->sync_flush (
				CAMEL_STREAM (emss));
			break;
		case EMSS_CLOSE:
			EMSS_CLASS (emss)->sync_close (
				CAMEL_STREAM (emss));
			break;
	}

	e_flag_set (msg->done);

	return FALSE;
}