コード例 #1
0
/* Scroll to the end of the buffer.
 */
static gboolean
scroll_to_end (GtkTextView *textview)
{
  GtkTextBuffer *buffer;
  GtkTextIter iter;
  GtkTextMark *mark;
  char *spaces;
  static int count;

  buffer = gtk_text_view_get_buffer (textview);

  /* Get "end" mark. It's located at the end of buffer because
   * of right gravity
   */
  mark = gtk_text_buffer_get_mark (buffer, "end");
  gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);

  /* and insert some text at its position, the iter will be
   * revalidated after insertion to point to the end of inserted text
   */
  spaces = g_strnfill (count++, ' ');
  gtk_text_buffer_insert (buffer, &iter, "\n", -1);
  gtk_text_buffer_insert (buffer, &iter, spaces, -1);
  gtk_text_buffer_insert (buffer, &iter,
                          "Scroll to end scroll to end scroll "
                          "to end scroll to end ",
                          -1);
  g_free (spaces);

  /* Now scroll the end mark onscreen.
   */
  gtk_text_view_scroll_mark_onscreen (textview, mark);

  /* Emulate typewriter behavior, shift to the left if we
   * are far enough to the right.
   */
  if (count > 150)
    count = 0;

  return G_SOURCE_CONTINUE;
}
コード例 #2
0
ファイル: indent.c プロジェクト: Mathias-Fuchs/ngahuru
static gint calculate_real_tab_width(GtkWidget *text_view, guint tab_size) //from gtksourceview
{
	PangoLayout *layout;
	gchar *tab_string;
	gint tab_width = 0;

	if (tab_size == 0)
		return -1;

	tab_string = g_strnfill(tab_size, 0x20);
	layout = gtk_widget_create_pango_layout(text_view, tab_string);
	g_free (tab_string);
	
	if (layout != NULL) {
		pango_layout_get_pixel_size(layout, &tab_width, NULL);
		g_object_unref(G_OBJECT(layout));
	} else
		tab_width = -1;

	return tab_width;
}
コード例 #3
0
ファイル: fo-object.c プロジェクト: hrs-allbsd/xmlroff
/**
 * _debug_dump_default:
 * @object: The #FoObject object.
 * @depth:  Indent level to add to the output.
 * 
 * Default debug_dump method.
 *
 * Return value: Result of debug_sprintf method of class of @object.
 **/
static void
_debug_dump_default (FoObject *object,
			      gint      depth)
{
  gchar *indent = g_strnfill (depth * 2, ' ');
  gchar *object_sprintf;

  g_return_if_fail (object != NULL);
  g_return_if_fail (FO_IS_OBJECT (object));

  object_sprintf = fo_object_debug_sprintf (object);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s%s",
	 indent,
	 object_sprintf);

  g_free (object_sprintf);
  g_free (indent);
}
コード例 #4
0
ファイル: fo-tree.c プロジェクト: hrs-allbsd/xmlroff
static void
_debug_dump_sorted_hash (GHashTable *hash,
			 gint depth)
{
  gchar *indent = g_strnfill (depth * 2, ' ');
  FoTreeSortedHashDumpData hash_dump_data = { hash, NULL, indent };

  g_hash_table_foreach (hash,
			_hash_key_to_list,
			&hash_dump_data);

  hash_dump_data.keys = g_slist_sort (hash_dump_data.keys,
				      (GCompareFunc) strcmp);

  g_slist_foreach (hash_dump_data.keys,
		   _debug_dump_hash_from_keys,
		   (gpointer) &hash_dump_data);

  g_slist_free (hash_dump_data.keys);
  g_free (indent);
}
コード例 #5
0
void
rygel_gst_utils_dump_encoding_profile (GstEncodingProfile *profile,
                                       gint                indent) {
  gchar *indent_s;
  const GstCaps *caps;
  gchar *format_name;
  const GstCaps *restriction;

  g_return_if_fail (profile != NULL);

  indent_s = g_strnfill ((gsize) indent, ' ');
  g_debug ("%s%s:", indent_s, gst_encoding_profile_get_name (profile));

  caps = gst_encoding_profile_get_format (profile);
  format_name = gst_caps_to_string (caps);
  g_debug ("%s  Format: %s", indent_s, format_name);
  g_free (format_name);

  restriction = gst_encoding_profile_get_restriction (profile);
  if (restriction) {
    gchar *restriction_name = gst_caps_to_string (restriction);
    g_debug ("%s  Restriction: %s", indent_s, restriction_name);
    g_free (restriction_name);
  }

  if (GST_IS_ENCODING_CONTAINER_PROFILE (profile)) {
    GstEncodingContainerProfile *container = GST_ENCODING_CONTAINER_PROFILE (profile);
    const GList *subprofile_collection = gst_encoding_container_profile_get_profiles (container);
    const GList *subprofile_it;

    for (subprofile_it = subprofile_collection; subprofile_it != NULL; subprofile_it = subprofile_it->next) {
      GstEncodingProfile *subprofile = GST_ENCODING_PROFILE (subprofile_it->data);

      rygel_gst_utils_dump_encoding_profile (subprofile, indent + 4);
    }
  }

  g_free (indent_s);
}
コード例 #6
0
ファイル: common.c プロジェクト: dreamerc/xmms2
static void
print_padded_string (gint columns, gchar padchar, gboolean padright, const gchar *fmt, ...)
{
	gchar buf[1024];
	gchar *padstring;

	va_list ap;

	va_start (ap, fmt);
	g_vsnprintf (buf, 1024, fmt, ap);
	va_end (ap);

	padstring = g_strnfill (columns - g_utf8_strlen (buf, -1), padchar);

	if (padright) {
		print_info ("%s%s", buf, padstring);
	} else {
		print_info ("%s%s", padstring, buf);
	}

	g_free (padstring);
}
コード例 #7
0
ファイル: fo-object.c プロジェクト: hrs-allbsd/xmlroff
/**
 * fo_object_debug_dump:
 * @object: The #FoObject object.
 * @depth:  Indent level to add to the output.
 * 
 * Calls debug_dump method of class of @object, if @object is an
 * #FoObject or descendant type of #FoObject.
 **/
void
fo_object_debug_dump (gpointer object,
		      gint     depth)
{
  gchar *indent = g_strnfill (depth * 2, ' ');

  if (object == NULL)
    {
      g_log (G_LOG_DOMAIN,
	     G_LOG_LEVEL_DEBUG,
	     "%s(null)",
	     indent);
    }
  else if (!G_IS_OBJECT (object))
    {
      g_log (G_LOG_DOMAIN,
	     G_LOG_LEVEL_DEBUG,
	     "%sNot a GObject: %p",
	     indent,
	     object);
    }
  else if (!FO_IS_OBJECT (object))
    {
      g_log (G_LOG_DOMAIN,
	     G_LOG_LEVEL_DEBUG,
	     "%sGObject but not an FoObject:: %s (%p : %d)",
	     indent,
	     g_type_name (G_TYPE_FROM_INSTANCE (object)),
	     object,
	     ((GObject *) object)->ref_count);
    }
  else
    {
      FO_OBJECT_GET_CLASS (object)->debug_dump (FO_OBJECT (object), depth);
    }

  g_free (indent);
}
コード例 #8
0
ファイル: fo-image.c プロジェクト: hrs-allbsd/xmlroff
/**
 * fo_image_debug_dump:
 * @fo: The #FoFo object
 * @depth: Indent level to add to the output
 * 
 * Calls #fo_object_debug_dump on each property of @fo then calls
 * debug_dump_properties method of parent class
 **/
void
fo_image_debug_dump (FoObject *object,
		     gint      depth)
{
  FoImage *fo_image;
  gchar *indent = g_strnfill (depth * 2, ' ');

  g_return_if_fail (object != NULL);
  g_return_if_fail (FO_IS_IMAGE (object));

  fo_image = FO_IMAGE (object);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%suri : %s",
	 indent,
	 fo_image->uri);
  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%spixbuf : %s",
	 indent,
	 fo_object_sprintf (fo_image->pixbuf));
  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%swidth :",
	 indent);
  fo_object_debug_dump (fo_image->width, depth + 1);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%sheight :",
	 indent);
  fo_object_debug_dump (fo_image->height, depth + 1);

  g_free (indent);
}
コード例 #9
0
ファイル: g_keys.c プロジェクト: pardo-bsso/geda-gaf
/* for now this only supports single chars, not shift/alt/ctrl etc... */
int g_keys_execute(GSCHEM_TOPLEVEL *w_current, int state, int keyval)
{
  char *guile_string = NULL;
  char *modifier = NULL;
  char *key_name = NULL;
  char *mod_end = NULL;
  SCM scm_retval;

  if (keyval == 0) {
    return 0;
  }

  key_name = gdk_keyval_name(keyval);
  if ( key_name == NULL ) {
    return 0;
  }

  /* don't pass the raw modifier key presses to the guile code */
  if (strstr(key_name, "Alt")    ||
      strstr(key_name, "Shift")  ||
      strstr(key_name, "Control") ) {
    return 0;
  }

  /* Allocate space for concatenation of all strings below */
  modifier = mod_end = g_strnfill(3*10, '\0');

  /* The accels below must be in alphabetic order! */
  if (state & GDK_MOD1_MASK) {
    mod_end = g_stpcpy(mod_end, "Alt ");
  }
  if (state & GDK_CONTROL_MASK) {
    mod_end = g_stpcpy(mod_end, "Control ");
  }
  if (state & GDK_SHIFT_MASK) {
    mod_end = g_stpcpy(mod_end, "Shift ");
  }

  if(strcmp(key_name, "Escape") == 0) {
     g_free(w_current->keyaccel_string);
     w_current->keyaccel_string = NULL;
  } else if(w_current->keyaccel_string &&
        strlen(w_current->keyaccel_string) + strlen(key_name) > 10) {
     g_free(w_current->keyaccel_string);
     w_current->keyaccel_string = g_strconcat(modifier, key_name, NULL);
  } else {
     gchar *p, *r;

     p = w_current->keyaccel_string;
     w_current->keyaccel_string = g_strconcat(modifier, key_name, NULL);
     if(p) {
        r = g_strconcat(p, w_current->keyaccel_string, NULL);
        g_free(p);
        g_free(w_current->keyaccel_string);
        w_current->keyaccel_string = r;
     }
  }

  i_show_state(w_current, NULL);

  guile_string = g_strdup_printf("(press-key \"%s%s\")",
                                 modifier, key_name);

#if DEBUG 
  printf("_%s_\n", guile_string);
#endif
  scm_retval = g_scm_c_eval_string_protected (guile_string);
  g_free(guile_string);
  g_free(modifier);

  return (SCM_FALSEP (scm_retval)) ? 0 : 1;
}
コード例 #10
0
ファイル: utils.c プロジェクト: aelarabawy/NetworkManager
/*
 * Print both headers or values of 'field_values' array.
 * Entries to print and their order are specified via indices in
 * 'nmc->print_fields.indices' array.
 * Various flags influencing the output of fields are set up in the first item
 * of 'field_values' array.
 */
void
print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
{
	GString *str;
	int width1, width2;
	int table_width = 0;
	char *line = NULL;
	char *indent_str;
	const char *not_set_str = "--";
	int i;
	const NmcPrintFields fields = nmc->print_fields;
	gboolean multiline = nmc->multiline_output;
	gboolean terse = (nmc->print_output == NMC_PRINT_TERSE);
	gboolean pretty = (nmc->print_output == NMC_PRINT_PRETTY);
	gboolean escape = nmc->escape_values;
	gboolean main_header_add = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ADD;
	gboolean main_header_only = field_values[0].flags & NMC_OF_FLAG_MAIN_HEADER_ONLY;
	gboolean field_names = field_values[0].flags & NMC_OF_FLAG_FIELD_NAMES;
	gboolean section_prefix = field_values[0].flags & NMC_OF_FLAG_SECTION_PREFIX;
	gboolean main_header = main_header_add || main_header_only;

	/* No headers are printed in terse mode:
	 * - neither main header nor field (column) names
	 */
	if ((main_header_only || field_names) && terse)
		return;

	if (multiline) {
	/* --- Multiline mode --- */
		enum { ML_HEADER_WIDTH = 79 };
		enum { ML_VALUE_INDENT = 40 };
		if (main_header && pretty) {
			/* Print the main header */
			int header_width = nmc_string_screen_width (fields.header_name, NULL) + 4;
			table_width = header_width < ML_HEADER_WIDTH ? ML_HEADER_WIDTH : header_width;

			line = g_strnfill (ML_HEADER_WIDTH, '=');
			width1 = strlen (fields.header_name);
			width2 = nmc_string_screen_width (fields.header_name, NULL);
			g_print ("%s\n", line);
			g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, fields.header_name);
			g_print ("%s\n", line);
			g_free (line);
		}

		/* Print values */
		if (!main_header_only && !field_names) {
			for (i = 0; i < fields.indices->len; i++) {
				char *tmp;
				int idx = g_array_index (fields.indices, int, i);
				gboolean is_array = field_values[idx].value_is_array;

				/* section prefix can't be an array */
				g_assert (!is_array || !section_prefix || idx != 0);

				if (section_prefix && idx == 0)  /* The first field is section prefix */
					continue;

				if (is_array) {
					/* value is a null-terminated string array */
					const char **p;
					int j;

					for (p = (const char **) field_values[idx].value, j = 1; p && *p; p++, j++) {
						tmp = g_strdup_printf ("%s%s%s[%d]:",
						                       section_prefix ? (const char*) field_values[0].value : "",
						                       section_prefix ? "." : "",
						                       _(field_values[idx].name_l10n),
						                       j);
						width1 = strlen (tmp);
						width2 = nmc_string_screen_width (tmp, NULL);
						g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp,
						         *p ? *p : not_set_str);
						g_free (tmp);
					}
				} else {
					/* value is a string */
					const char *hdr_name = (const char*) field_values[0].value;
					const char *val = (const char*) field_values[idx].value;

					tmp = g_strdup_printf ("%s%s%s:",
					                       section_prefix ? hdr_name : "",
					                       section_prefix ? "." : "",
					                       _(field_values[idx].name_l10n));
					width1 = strlen (tmp);
					width2 = nmc_string_screen_width (tmp, NULL);
					g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp,
					         val ? val : not_set_str);
					g_free (tmp);
				}
			}
			if (pretty) {
				line = g_strnfill (ML_HEADER_WIDTH, '-');
				g_print ("%s\n", line);
				g_free (line);
			}
		}
		return;
	}

	/* --- Tabular mode: each line = one object --- */
	str = g_string_new (NULL);

	for (i = 0; i < fields.indices->len; i++) {
		int idx = g_array_index (fields.indices, int, i);
		gboolean dealloc;
		char *value = get_value_to_print ((NmcOutputField *) field_values+idx, field_names, not_set_str, &dealloc);

		if (terse) {
			if (escape) {
				const char *p = value;
				while (*p) {
					if (*p == ':' || *p == '\\')
						g_string_append_c (str, '\\');  /* Escaping by '\' */
					g_string_append_c (str, *p);
					p++;
				}
			}
			else
				g_string_append_printf (str, "%s", value);
			g_string_append_c (str, ':');  /* Column separator */
		} else {
			width1 = strlen (value);
			width2 = nmc_string_screen_width (value, NULL);  /* Width of the string (in screen colums) */
			g_string_append_printf (str, "%-*s", field_values[idx].width + width1 - width2, strlen (value) > 0 ? value : "--");
			g_string_append_c (str, ' ');  /* Column separator */
			table_width += field_values[idx].width + width1 - width2 + 1;
		}

		if (dealloc)
			g_free (value);
	}

	/* Print the main table header */
	if (main_header && pretty) {
		int header_width = nmc_string_screen_width (fields.header_name, NULL) + 4;
		table_width = table_width < header_width ? header_width : table_width;

		line = g_strnfill (table_width, '=');
		width1 = strlen (fields.header_name);
		width2 = nmc_string_screen_width (fields.header_name, NULL);
		g_print ("%s\n", line);
		g_print ("%*s\n", (table_width + width2)/2 + width1 - width2, fields.header_name);
		g_print ("%s\n", line);
		g_free (line);
	}

	/* Print actual values */
	if (!main_header_only && str->len > 0) {
		g_string_truncate (str, str->len-1);  /* Chop off last column separator */
		if (fields.indent > 0) {
			indent_str = g_strnfill (fields.indent, ' ');
			g_string_prepend (str, indent_str);
			g_free (indent_str);
		}
		g_print ("%s\n", str->str);
	}

	/* Print horizontal separator */
	if (!main_header_only && field_names && pretty) {
		if (str->len > 0) {
			line = g_strnfill (table_width, '-');
			g_print ("%s\n", line);
			g_free (line);
		}
	}

	g_string_free (str, TRUE);
}
コード例 #11
0
ファイル: printing.c プロジェクト: Hamakor/geany
static void draw_page(GtkPrintOperation *operation, GtkPrintContext *context,
					  gint page_nr, gpointer user_data)
{
	DocInfo *dinfo = user_data;
	GeanyEditor *editor;
	cairo_t *cr;
	gdouble width, height;
	gdouble x = 0.0, y = 0.0;
	/*gint layout_h;*/
	gint count;
	GString *str;

	if (dinfo == NULL || page_nr >= dinfo->n_pages)
		return;

	editor = dinfo->doc->editor;

	if (dinfo->n_pages > 0)
	{
		gdouble fraction = (page_nr + 1) / (gdouble) dinfo->n_pages;
		gchar *text = g_strdup_printf(_("Page %d of %d"), page_nr, dinfo->n_pages);
		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(main_widgets.progressbar), fraction);
		gtk_progress_bar_set_text(GTK_PROGRESS_BAR(main_widgets.progressbar), text);
		g_free(text);
	}

#ifdef GEANY_PRINT_DEBUG
	geany_debug("draw_page = %d, pages = %d, (real) lines_per_page = %d",
		page_nr, dinfo->n_pages, dinfo->lines_per_page);
#endif

	str = g_string_sized_new(256);
	cr = gtk_print_context_get_cairo_context(context);
	width = gtk_print_context_get_width(context);
	height = gtk_print_context_get_height(context);

	cairo_set_source_rgb(cr, 0, 0, 0);
#ifdef GEANY_PRINT_DEBUG
	cairo_set_line_width(cr, 0.2);
	cairo_rectangle(cr, 0, 0, width, height);
	cairo_stroke(cr);
#endif
	cairo_move_to(cr, 0, 0);

	pango_layout_set_width(dinfo->layout, width * PANGO_SCALE);
	pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_LEFT);
	pango_layout_set_ellipsize(dinfo->layout, FALSE);
	pango_layout_set_justify(dinfo->layout, FALSE);

	if (printing_prefs.print_page_header)
		add_page_header(dinfo, cr, width, page_nr);

	count = 0;	/* the actual line counter for the current page, might be different from
				 * dinfo->cur_line due to possible line breaks */
	while (count < dinfo->lines_per_page)
	{
		gchar c = 'a';
		gint style = -1;
		PangoAttrList *layout_attr;
		PangoAttribute *attr;
		gint colours[3] = { 0 };
		gboolean add_linenumber = TRUE;
		gboolean at_eol;

		while (count < dinfo->lines_per_page && c != '\0')
		{
			at_eol = FALSE;

			g_string_erase(str, 0, str->len); /* clear the string */

			/* line numbers */
			if (printing_prefs.print_line_numbers && add_linenumber)
			{
				/* if we had a wrapped line on the last page which needs to be continued, don't
				 * add a line number */
				if (dinfo->long_line)
				{
					add_linenumber = FALSE;
				}
				else
				{
					gchar *line_number = NULL;
					gint cur_line_number_margin = get_line_numbers_arity(dinfo->cur_line + 1);
					gchar *fill = g_strnfill(
						dinfo->max_line_number_margin - cur_line_number_margin - 1, ' ');

					line_number = g_strdup_printf("%s%d ", fill, dinfo->cur_line + 1);
					g_string_append(str, line_number);
					dinfo->cur_line++; /* increase document line */
					add_linenumber = FALSE;
					style = STYLE_LINENUMBER;
					c = 'a'; /* dummy value */
					g_free(fill);
					g_free(line_number);
				}
			}
			/* data */
			else
			{
				style = sci_get_style_at(dinfo->doc->editor->sci, dinfo->cur_pos);
				c = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos);
				if (c == '\0' || style == -1)
				{	/* if c gets 0, we are probably out of document boundaries,
					 * so stop to break out of outer loop */
					count = dinfo->lines_per_page;
					break;
				}
				dinfo->cur_pos++;

				/* convert tabs to spaces which seems to be better than using Pango tabs */
				if (c == '\t')
				{
					gint tab_width = sci_get_tab_width(editor->sci);
					gchar *s = g_strnfill(tab_width, ' ');
					g_string_append(str, s);
					g_free(s);
				}
				/* don't add line breaks, they are handled manually below */
				else if (c == '\r' || c == '\n')
				{
					gchar c_next = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos);
					at_eol = TRUE;
					if (c == '\r' && c_next == '\n')
						dinfo->cur_pos++; /* skip LF part of CR/LF */
				}
				else
				{
					g_string_append_c(str, c); /* finally add the character */

					/* handle UTF-8: since we add char by char (better: byte by byte), we need to
					 * keep UTF-8 characters together(e.g. two bytes for one character)
					 * the input is always UTF-8 and c is signed, so all non-Ascii
					 * characters are less than 0 and consist of all bytes less than 0.
					 * style doesn't change since it is only one character with multiple bytes. */
					while (c < 0)
					{
						c = sci_get_char_at(dinfo->doc->editor->sci, dinfo->cur_pos);
						if (c < 0)
						{	/* only add the byte when it is part of the UTF-8 character
							 * otherwise we could add e.g. a '\n' and it won't be visible in the
							 * printed document */
							g_string_append_c(str, c);
							dinfo->cur_pos++;
						}
					}
				}
			}

			if (! at_eol)
			{
				/* set text */
				pango_layout_set_text(dinfo->layout, str->str, -1);
				/* attributes */
				layout_attr = pango_attr_list_new();
				/* foreground colour */
				get_rgb_values(dinfo->styles[style][FORE], &colours[0], &colours[1], &colours[2]);
				attr = pango_attr_foreground_new(colours[0], colours[1], colours[2]);
				ADD_ATTR(layout_attr, attr);
				/* background colour */
				get_rgb_values(dinfo->styles[style][BACK], &colours[0], &colours[1], &colours[2]);
				attr = pango_attr_background_new(colours[0], colours[1], colours[2]);
				ADD_ATTR(layout_attr, attr);
				/* bold text */
				if (dinfo->styles[style][BOLD])
				{
					attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
					ADD_ATTR(layout_attr, attr);
				}
				/* italic text */
				if (dinfo->styles[style][ITALIC])
				{
					attr = pango_attr_style_new(PANGO_STYLE_ITALIC);
					ADD_ATTR(layout_attr, attr);
				}
				pango_layout_set_attributes(dinfo->layout, layout_attr);
				pango_layout_context_changed(dinfo->layout);
				pango_attr_list_unref(layout_attr);
			}

			cairo_get_current_point(cr, &x, &y);


			/* normal line break at eol character in document */
			if (at_eol)
			{
				/*pango_layout_get_size(dinfo->layout, NULL, &layout_h);*/
				/*cairo_move_to(cr, 0, y + (gdouble)layout_h / PANGO_SCALE);*/
				cairo_move_to(cr, 0, y + dinfo->line_height);

				count++;
				/* we added a new document line so request a new line number */
				add_linenumber = TRUE;
			}
			else
			{
				gint x_offset = 0;
				/* maybe we need to force a line break because of too long line */
				if (x >= (width - dinfo->font_width))
				{
					/* don't start the line at horizontal origin because we need to skip the
					 * line number margin */
					if (printing_prefs.print_line_numbers)
					{
						x_offset = (dinfo->max_line_number_margin + 1) * dinfo->font_width;
					}

					/*pango_layout_get_size(dinfo->layout, NULL, &layout_h);*/
					/*cairo_move_to(cr, x_offset, y + (gdouble)layout_h / PANGO_SCALE);*/
					/* this is faster but not exactly the same as above */
					cairo_move_to(cr, x_offset, y + dinfo->line_height);
					cairo_get_current_point(cr, &x, &y);
					count++;
				}
				if (count < dinfo->lines_per_page)
				{
					/* str->len is counted in bytes not characters, so use g_utf8_strlen() */
					x_offset = (g_utf8_strlen(str->str, -1) * dinfo->font_width);

					if (dinfo->long_line && count == 0)
					{
						x_offset = (dinfo->max_line_number_margin + 1) * dinfo->font_width;
						dinfo->long_line = FALSE;
					}

					pango_cairo_show_layout(cr, dinfo->layout);
					cairo_move_to(cr, x + x_offset, y);
				}
				else
				/* we are on a wrapped line but we are out of lines on this page, so continue
				 * the current line on the next page and remember to continue in current line */
					dinfo->long_line = TRUE;
			}
		}
	}

	if (printing_prefs.print_line_numbers)
	{	/* print a thin line between the line number margin and the data */
		gint y_start = 0;

		if (printing_prefs.print_page_header)
			y_start = (dinfo->line_height * 3) - 2;	/* "- 2": to connect the line number line to
													 * the page header frame */

		cairo_set_line_width(cr, 0.3);
		cairo_move_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1, y_start);
		cairo_line_to(cr, (dinfo->max_line_number_margin * dinfo->font_width) + 1,
			y + dinfo->line_height); /* y is last added line, we reuse it */
		cairo_stroke(cr);
	}

	if (printing_prefs.print_page_numbers)
	{
		gchar *line = g_strdup_printf("<small>- %d -</small>", page_nr + 1);
		pango_layout_set_markup(dinfo->layout, line, -1);
		pango_layout_set_alignment(dinfo->layout, PANGO_ALIGN_CENTER);
		cairo_move_to(cr, 0, height - dinfo->line_height);
		pango_cairo_show_layout(cr, dinfo->layout);
		g_free(line);

#ifdef GEANY_PRINT_DEBUG
		cairo_set_line_width(cr, 0.3);
		cairo_move_to(cr, 0, height - (1.25 * dinfo->line_height));
		cairo_line_to(cr, width - 1, height - (1.25 * dinfo->line_height));
		cairo_stroke(cr);
#endif
	}
	g_string_free(str, TRUE);
}
コード例 #12
0
ファイル: usermenu.c プロジェクト: NoSeungHwan/mc_kor_dev
char *
expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
{
    WPanel *panel = NULL;
    char *(*quote_func) (const char *, int);
    char *fname = NULL;
    char *result;
    char c_lc;

#ifndef USE_INTERNAL_EDIT
    (void) edit_widget;
#endif

    if (c == '%')
        return g_strdup ("%");

    switch (mc_global.mc_run_mode)
    {
    case MC_RUN_FULL:
        if (g_ascii_islower ((gchar) c))
            panel = current_panel;
        else
        {
            if (get_other_type () != view_listing)
                return g_strdup ("");
            panel = other_panel;
        }
        fname = g_strdup (panel->dir.list[panel->selected].fname);
        break;

#ifdef USE_INTERNAL_EDIT
    case MC_RUN_EDITOR:
        fname = edit_get_file_name (edit_widget);
        break;
#endif

    default:
        /* other modes don't use formats */
        return g_strdup ("");
    }

    if (do_quote)
        quote_func = name_quote;
    else
        quote_func = fake_name_quote;

    c_lc = g_ascii_tolower ((gchar) c);

    switch (c_lc)
    {
    case 'f':
    case 'p':
        result = (*quote_func) (fname, 0);
        goto ret;
    case 'x':
        result = (*quote_func) (extension (fname), 0);
        goto ret;
    case 'd':
        {
            char *cwd;
            char *qstr;

            if (panel)
                cwd = g_strdup (vfs_path_as_str (panel->cwd_vpath));
            else
                cwd = vfs_get_current_dir ();

            qstr = (*quote_func) (cwd, 0);

            g_free (cwd);

            result = qstr;
            goto ret;
        }
    case 'i':                  /* indent equal number cursor position in line */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            result = g_strnfill (edit_get_curs_col (edit_widget), ' ');
            goto ret;
        }
#endif
        break;
    case 'y':                  /* syntax type */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            const char *syntax_type = edit_get_syntax_type (edit_widget);
            if (syntax_type != NULL)
            {
                result = g_strdup (syntax_type);
                goto ret;
            }
        }
#endif
        break;
    case 'k':                  /* block file name */
    case 'b':                  /* block file name / strip extension */
        {
#ifdef USE_INTERNAL_EDIT
            if (edit_widget)
            {
                char *file;

                file = mc_config_get_full_path (EDIT_BLOCK_FILE);
                result = (*quote_func) (file, 0);
                g_free (file);
                goto ret;
            }
#endif
            if (c_lc == 'b')
            {
                result = strip_ext ((*quote_func) (fname, 0));
                goto ret;
            }
            break;
        }
    case 'n':                  /* strip extension in editor */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            result = strip_ext ((*quote_func) (fname, 0));
            goto ret;
        }
#endif
        break;
    case 'm':                  /* menu file name */
        if (menu)
        {
            result = (*quote_func) (menu, 0);
            goto ret;
        }
        break;
    case 's':
        if (!panel || !panel->marked)
        {
            result = (*quote_func) (fname, 0);
            goto ret;
        }

        /* Fall through */

    case 't':
    case 'u':
        {
            GString *block;
            int i;

            if (panel == NULL)
            {
                result = g_strdup ("");
                goto ret;
            }

            block = g_string_sized_new (16);

            for (i = 0; i < panel->dir.len; i++)
                if (panel->dir.list[i].f.marked)
                {
                    char *tmp;

                    tmp = (*quote_func) (panel->dir.list[i].fname, 0);
                    g_string_append (block, tmp);
                    g_string_append_c (block, ' ');
                    g_free (tmp);

                    if (c_lc == 'u')
                        do_file_mark (panel, i, 0);
                }
            result = g_string_free (block, FALSE);
            goto ret;
        }                       /* sub case block */
    }                           /* switch */
    result = g_strdup ("% ");
    result[1] = c;
  ret:
    g_free (fname);
    return result;
}
コード例 #13
0
ファイル: facebook-util.c プロジェクト: MartinBriza/gFB
void fb_util_hexdump(const GByteArray *bytes, guint indent,
                     const gchar *fmt, ...)
{
    GString *gstr;
    va_list  ap;
    gchar   *instr;
    guint    i;
    guint    j;
    gchar    c;

    if (fmt != NULL) {
        va_start(ap, fmt);
        instr = g_strdup_vprintf(fmt, ap);
        FB_UTIL_DEBUGLN("%s", instr);
        g_free(instr);
        va_end(ap);
    }

    instr = g_strnfill(indent, ' ');
    gstr  = g_string_sized_new(80);
    i     = 0;

    if (G_UNLIKELY(bytes == NULL))
        goto finish;

    for (; i < bytes->len; i += 16) {
        g_string_append_printf(gstr, "%s%08x  ", instr, i);

        for (j = 0; j < 16; j++) {
            if ((i + j) < bytes->len) {
                g_string_append_printf(gstr, "%02x ", bytes->data[i + j]);
            } else {
                g_string_append(gstr, "   ");
            }

            if (j == 7)
                g_string_append_c(gstr, ' ');
        }

        g_string_append(gstr, " |");

        for (j = 0; (j < 16) && ((i + j) < bytes->len); j++) {
            c = bytes->data[i + j];

            if (!g_ascii_isprint(c) || g_ascii_isspace(c))
                c = '.';

            g_string_append_c(gstr, c);
        }

        g_string_append_c(gstr, '|');
        FB_UTIL_DEBUGLN("%s", gstr->str);
        g_string_erase(gstr, 0, -1);
    }

finish:
    g_string_append_printf(gstr, "%s%08x", instr, i);
    FB_UTIL_DEBUGLN("%s", gstr->str);

    g_string_free(gstr, TRUE);
    g_free(instr);
}
コード例 #14
0
ファイル: rtf-field.c プロジェクト: ptomato/osxcart
/* Free the return value when done with it */
static gchar *
format_integer(gint number, GeneralNumberFormat format)
{
	switch(format)
	{
		case NUMBER_ALPHABETIC:
			if(number < 1)
				break;
			return g_strnfill(number / 26 + 1, number % 26 - 1 + 'A');
		case NUMBER_alphabetic:
			if(number < 1)
				break;
			return g_strnfill(number / 26 + 1, number % 26 - 1 + 'a');
		case NUMBER_ARABIC_DASH:
			return g_strdup_printf("- %d -", number);
		case NUMBER_HEX:
			return g_strdup_printf("%X", number);
		case NUMBER_ORDINAL:
			if(number % 10 == 1 && number % 100 != 11)
				return g_strdup_printf("%dst", number);
			if(number % 10 == 2 && number % 100 != 12)
				return g_strdup_printf("%dnd", number);
			if(number % 10 == 3 && number % 100 != 13)
				return g_strdup_printf("%drd", number);
			return g_strdup_printf("%dth", number);
		case NUMBER_ROMAN:
			if(number < 1)
				break;
		{
			const gchar *r_hundred[] = { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" };
			const gchar *r_ten[] = { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" };
			const gchar *r_one[] = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" };
			gint thousands = number / 1000;
			gint hundreds = (number % 1000) / 100;
			gint tens = (number % 100) / 10;
			gint ones = number % 10;
			gchar *thousandstring = g_strnfill(thousands, 'M');
			gchar *retval = g_strconcat(thousandstring, r_hundred[hundreds], r_ten[tens], r_one[ones], NULL);
			g_free(thousandstring);
			return retval;
		}
		case NUMBER_roman:
			if(number < 1)
				break;
		{
			const gchar *r_hundred[] = { "", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm" };
			const gchar *r_ten[] = { "", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc" };
			const gchar *r_one[] = { "", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix" };
			gint thousands = number / 1000;
			gint hundreds = (number % 1000) / 100;
			gint tens = (number % 100) / 10;
			gint ones = number % 10;
			gchar *thousandstring = g_strnfill(thousands, 'm');
			gchar *retval = g_strconcat(thousandstring, r_hundred[hundreds], r_ten[tens], r_one[ones], NULL);
			g_free(thousandstring);
			return retval;
		}
		case NUMBER_CIRCLENUM:
			if(number >= 1 && number <= 20)
				return g_strdup_printf("\xE2\x91%c", 0x9F + number);
			break;
		case NUMBER_DECIMAL_ENCLOSED_PERIOD:
			if(number >= 1 && number <= 20)
				return g_strdup_printf("\xE2\x92%c", 0x87 + number);
			break;
		case NUMBER_DECIMAL_ENCLOSED_PARENTHESES:
			if(number >= 1 && number <= 12)
				return g_strdup_printf("\xE2\x91%c", 0xB3 + number);
			if(number >= 13 && number <= 20)
				return g_strdup_printf("\xE2\x92%c", 0x73 + number);
			break;
		case NUMBER_ARABIC:
		default:
			break;
	}
	return g_strdup_printf("%d", number);
}
コード例 #15
0
ファイル: strutil.c プロジェクト: novacej/School_OSP
static estr_t
_str_convert (GIConv coder, const char *string, int size, GString * buffer)
{
    estr_t state = ESTR_SUCCESS;
    gchar *tmp_buff = NULL;
    gssize left;
    gsize bytes_read = 0;
    gsize bytes_written = 0;
    GError *error = NULL;
    errno = 0;

    if (coder == INVALID_CONV)
        return ESTR_FAILURE;

    if (string == NULL || buffer == NULL)
        return ESTR_FAILURE;

    /*
       if (! used_class.is_valid_string (string))
       {
       return ESTR_FAILURE;
       }
     */
    if (size < 0)
    {
        size = strlen (string);
    }
    else
    {
        left = strlen (string);
        if (left < size)
            size = left;
    }

    left = size;
    g_iconv (coder, NULL, NULL, NULL, NULL);

    while (left)
    {
        tmp_buff = g_convert_with_iconv ((const gchar *) string,
                                         left, coder, &bytes_read, &bytes_written, &error);
        if (error)
        {
            int code = error->code;

            g_error_free (error);
            error = NULL;

            switch (code)
            {
            case G_CONVERT_ERROR_NO_CONVERSION:
                /* Conversion between the requested character sets is not supported. */
                tmp_buff = g_strnfill (strlen (string), '?');
                g_string_append (buffer, tmp_buff);
                g_free (tmp_buff);
                return ESTR_FAILURE;

            case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
                /* Invalid byte sequence in conversion input. */
                if ((tmp_buff == NULL) && (bytes_read != 0))
                    /* recode valid byte sequence */
                    tmp_buff = g_convert_with_iconv ((const gchar *) string,
                                                     bytes_read, coder, NULL, NULL, NULL);

                if (tmp_buff != NULL)
                {
                    g_string_append (buffer, tmp_buff);
                    g_free (tmp_buff);
                }

                if ((int) bytes_read < left)
                {
                    string += bytes_read + 1;
                    size -= (bytes_read + 1);
                    left -= (bytes_read + 1);
                    g_string_append_c (buffer, *(string - 1));
                }
                else
                {
                    return ESTR_PROBLEM;
                }
                state = ESTR_PROBLEM;
                break;

            case G_CONVERT_ERROR_PARTIAL_INPUT:
                /* Partial character sequence at end of input. */
                g_string_append (buffer, tmp_buff);
                g_free (tmp_buff);
                if ((int) bytes_read < left)
                {
                    left = left - bytes_read;
                    tmp_buff = g_strnfill (left, '?');
                    g_string_append (buffer, tmp_buff);
                    g_free (tmp_buff);
                }
                return ESTR_PROBLEM;

            case G_CONVERT_ERROR_BAD_URI:      /* Don't know how handle this error :( */
            case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH:    /* Don't know how handle this error :( */
            case G_CONVERT_ERROR_FAILED:       /* Conversion failed for some reason. */
            default:
                g_free (tmp_buff);
                return ESTR_FAILURE;
            }
        }
        else
        {
            if (tmp_buff != NULL)
            {
                if (*tmp_buff)
                {
                    g_string_append (buffer, tmp_buff);
                    g_free (tmp_buff);
                    string += bytes_read;
                    left -= bytes_read;
                }
                else
                {
                    g_free (tmp_buff);
                    g_string_append (buffer, string);
                    return state;
                }
            }
            else
            {
                g_string_append (buffer, string);
                return ESTR_PROBLEM;
            }
        }
    }
    return state;
}
コード例 #16
0
ファイル: user.c プロジェクト: dborca/mc
char *
expand_format (struct WEdit *edit_widget, char c, int quote)
{
    WPanel *panel = NULL;
    char *(*quote_func) (const char *, int);
    char *fname;
    char *result;
    char c_lc;

    if (c == '%')
	return g_strdup ("%");

    if (edit_one_file != NULL)
	fname = edit_widget->filename;
    else {
	if (islower ((unsigned char) c))
	    panel = current_panel;
	else {
	    if (get_other_type () != view_listing)
		return g_strdup ("");
	    panel = other_panel;
	}
	fname = panel->dir.list[panel->selected].fname;
    }

    if (quote)
	quote_func = name_quote;
    else
	quote_func = fake_name_quote;

    c_lc = tolower ((unsigned char) c);

    switch (c_lc) {
    case 'f':
    case 'p':
	return (*quote_func) (fname, 0);
    case 'x':
	return (*quote_func) (extension (fname), 0);
    case 'd':
	{
	    char *cwd;
	    char *qstr;

	    cwd = g_malloc(MC_MAXPATHLEN + 1);

	    if (panel)
		g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
	    else
		mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);

	    qstr = (*quote_func) (cwd, 0);

	    g_free (cwd);

	    return qstr;
	}
    case 'i':			/* indent equal number cursor position in line */
	if (edit_widget)
	    return g_strnfill (edit_widget->curs_col, ' ');
	break;
    case 'y':			/* syntax type */
	if (edit_widget && edit_widget->syntax_type)
	    return g_strdup (edit_widget->syntax_type);
	break;
    case 'k':			/* block file name */
    case 'b':			/* block file name / strip extension */  {
	    if (edit_widget) {
		char *file = g_strconcat (home_dir, PATH_SEP_STR BLOCK_FILE, (char *) NULL);
		fname = (*quote_func) (file, 0);
		g_free (file);
		return fname;
	    } else if (c_lc == 'b') {
		return strip_ext ((*quote_func) (fname, 0));
	    }
	    break;
	}
    case 'e':			/* was "cooledit.error" */
	return g_strdup("/dev/null");
    case 'n':			/* strip extension in editor */
	if (edit_widget)
	    return strip_ext ((*quote_func) (fname, 0));
	break;
    case 'm':			/* menu file name */
	if (menu)
	    return (*quote_func) (menu, 0);
	break;
    case 's':
	if (!panel || !panel->marked)
	    return (*quote_func) (fname, 0);

	/* Fall through */

    case 't':
    case 'u':
	{
	    int length = 2, i;
	    char *block, *tmp;

	    if (!panel)
		return g_strdup ("");

	    for (i = 0; i < panel->count; i++)
		if (panel->dir.list[i].f.marked)
		    length += strlen (panel->dir.list[i].fname) + 1;	/* for space */

	    block = g_malloc (length * 2 + 1);
	    *block = 0;
	    for (i = 0; i < panel->count; i++)
		if (panel->dir.list[i].f.marked) {
		    strcat (block, tmp =
			    (*quote_func) (panel->dir.list[i].fname, 0));
		    g_free (tmp);
		    strcat (block, " ");
		    if (c_lc == 'u')
			do_file_mark (panel, i, 0);
		}
	    return block;
	}			/* sub case block */
    }				/* switch */
    result = g_strdup ("% ");
    result[1] = c;
    return result;
}
コード例 #17
0
ファイル: fo-doc-cairo.c プロジェクト: hrs-allbsd/xmlroff
/**
 * fo_doc_cairo_debug_dump:
 * @object: #FoObject to be dumped.
 * @depth:  Relative indent to add to the output.
 * 
 * Implements #FoObject debug_dump method for #FoDocCairo.
 **/
void
fo_doc_cairo_debug_dump (FoObject *object,
			  gint      depth)
{
  FoDocCairo *fo_doc_cairo;
  gchar *indent = g_strnfill (depth * 2, ' ');
  gchar* object_sprintf;

  g_return_if_fail (object != NULL);
  g_return_if_fail (FO_IS_DOC_CAIRO (object));

  fo_doc_cairo = FO_DOC_CAIRO (object);

  object_sprintf = fo_object_debug_sprintf (object);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s%s",
	 indent,
	 object_sprintf);

  g_free (object_sprintf);

  object_sprintf = fo_object_debug_sprintf (fo_doc_cairo->cr);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s    cr: %s",
	 indent,
	 object_sprintf);

  g_free (object_sprintf);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s    base_filename: %s",
	 indent,
	 fo_doc_cairo->base_filename);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s    output_sequence: %d",
	 indent,
	 fo_doc_cairo->output_sequence);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s    current_filename: %s",
	 indent,
	 fo_doc_cairo->current_filename);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s    page_width: %g",
	 indent,
	 fo_doc_cairo->page_width);

  g_log (G_LOG_DOMAIN,
	 G_LOG_LEVEL_DEBUG,
	 "%s    page_height: %g",
	 indent,
	 fo_doc_cairo->page_height);

  g_free (indent);

}
コード例 #18
0
ファイル: xmlnode.c プロジェクト: BackupTheBerlios/koopa-svn
static char *xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth)
{
	char *ret;
	GString *text = g_string_new("");
	xmlnode *c;
	char *node_name, *esc, *esc2, *tab = NULL;
	gboolean need_end = FALSE, pretty = formatting;
#ifdef _WIN32
	static const char *newline = "\r\n";
#else
	static const char *newline = "\n";
#endif

	if(pretty && depth) {
		tab = g_strnfill(depth, '\t');
		text = g_string_append(text, tab);
	}

	node_name = g_markup_escape_text(node->name, -1);
	g_string_append_printf(text, "<%s", node_name);

	for(c = node->child; c; c = c->next)
	{
		if(c->type == XMLNODE_TYPE_ATTRIB) {
			esc = g_markup_escape_text(c->name, -1);
			esc2 = g_markup_escape_text(c->data, -1);
			g_string_append_printf(text, " %s='%s'", esc, esc2);
			g_free(esc);
			g_free(esc2);
		} else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) {
			if(c->type == XMLNODE_TYPE_DATA)
				pretty = FALSE;
			need_end = TRUE;
		}
	}

	if(need_end) {
		g_string_append_printf(text, ">%s", pretty ? newline : "");

		for(c = node->child; c; c = c->next)
		{
			if(c->type == XMLNODE_TYPE_TAG) {
				int esc_len;
				esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1);
				text = g_string_append_len(text, esc, esc_len);
				g_free(esc);
			} else if(c->type == XMLNODE_TYPE_DATA) {
				esc = g_markup_escape_text(c->data, c->data_sz);
				text = g_string_append(text, esc);
				g_free(esc);
			}
		}

		if(tab && pretty)
			text = g_string_append(text, tab);
		g_string_append_printf(text, "</%s>%s", node_name, pretty ? newline : "");
	} else {
		g_string_append_printf(text, "/>%s", pretty ? newline : "");
	}

	g_free(node_name);

	if(tab)
		g_free(tab);

	ret = text->str;
	if(len)
		*len = text->len;
	g_string_free(text, FALSE);
	return ret;
}
コード例 #19
0
char *
expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
{
    WPanel *panel = NULL;
    char *(*quote_func) (const char *, int);
    char *fname = NULL;
    char *result;
    char c_lc;

#ifndef USE_INTERNAL_EDIT
    (void) edit_widget;
#endif

    if (c == '%')
        return g_strdup ("%");

    if (mc_run_mode == MC_RUN_FULL)
    {
        if (g_ascii_islower ((gchar) c))
            panel = current_panel;
        else
        {
            if (get_other_type () != view_listing)
                return g_strdup ("");
            panel = other_panel;
        }
        fname = panel->dir.list[panel->selected].fname;
    }
#ifdef USE_INTERNAL_EDIT
    else if (mc_run_mode == MC_RUN_EDITOR)
        fname = (char *) edit_get_file_name (edit_widget);
#endif

    if (do_quote)
        quote_func = name_quote;
    else
        quote_func = fake_name_quote;

    c_lc = g_ascii_tolower ((gchar) c);

    switch (c_lc)
    {
    case 'f':
    case 'p':
        return (*quote_func) (fname, 0);
    case 'x':
        return (*quote_func) (extension (fname), 0);
    case 'd':
        {
            char *cwd;
            char *qstr;

            cwd = g_malloc (MC_MAXPATHLEN + 1);

            if (panel)
                g_strlcpy (cwd, panel->cwd, MC_MAXPATHLEN + 1);
            else
                mc_get_current_wd (cwd, MC_MAXPATHLEN + 1);

            qstr = (*quote_func) (cwd, 0);

            g_free (cwd);

            return qstr;
        }
    case 'i':                  /* indent equal number cursor position in line */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
            return g_strnfill (edit_get_curs_col (edit_widget), ' ');
#endif
        break;
    case 'y':                  /* syntax type */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            const char *syntax_type = edit_get_syntax_type (edit_widget);
            if (syntax_type != NULL)
                return g_strdup (syntax_type);
        }
#endif
        break;
    case 'k':                  /* block file name */
    case 'b':                  /* block file name / strip extension */
        {
#ifdef USE_INTERNAL_EDIT
            if (edit_widget)
            {
                char *file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
                fname = (*quote_func) (file, 0);
                g_free (file);
                return fname;
            }
#endif
            if (c_lc == 'b')
                return strip_ext ((*quote_func) (fname, 0));
            break;
        }
    case 'n':                  /* strip extension in editor */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
            return strip_ext ((*quote_func) (fname, 0));
#endif
        break;
    case 'm':                  /* menu file name */
        if (menu)
            return (*quote_func) (menu, 0);
        break;
    case 's':
        if (!panel || !panel->marked)
            return (*quote_func) (fname, 0);

        /* Fall through */

    case 't':
    case 'u':
        {
            int length = 2, i;
            char *block, *tmp;

            if (!panel)
                return g_strdup ("");

            for (i = 0; i < panel->count; i++)
                if (panel->dir.list[i].f.marked)
                    length += strlen (panel->dir.list[i].fname) + 1;    /* for space */

            block = g_malloc (length * 2 + 1);
            *block = 0;
            for (i = 0; i < panel->count; i++)
                if (panel->dir.list[i].f.marked)
                {
                    tmp = (*quote_func) (panel->dir.list[i].fname, 0);
                    strcat (block, tmp);
                    g_free (tmp);
                    strcat (block, " ");
                    if (c_lc == 'u')
                        do_file_mark (panel, i, 0);
                }
            return block;
        }                       /* sub case block */
    }                           /* switch */
    result = g_strdup ("% ");
    result[1] = c;
    return result;
}
コード例 #20
0
static void
enumerate_dir (MpdStorageDevice  *self)
{
  MpdStorageDevicePrivate *priv = GET_PRIVATE (self);
  GFileEnumerator *enumerator;
  GFileInfo       *info;
  GError          *error = NULL;

  g_return_if_fail (priv->dir_stack);
  enumerator = G_FILE_ENUMERATOR (priv->dir_stack->data);
  g_return_if_fail (G_IS_FILE_ENUMERATOR (enumerator));

  while (NULL !=
         (info = g_file_enumerator_next_file (enumerator, NULL, &error)))
  {
    char const *content_type = g_file_info_get_content_type (info);
    char const *name = g_file_info_get_name (info);

    /* Debug */
    char *indent = g_strnfill (g_slist_length (priv->dir_stack), ' ');
    g_debug ("%s%s %s", indent, name, content_type);
    g_free (indent);

    /* Do not recurse into "dot" directories, they are use for trash. */
    if (0 == g_strcmp0 ("inode/directory", content_type) &&
        name[0] != '.')
    {
      char const *path = g_object_get_data (G_OBJECT (enumerator), "path");
      char *subpath = g_build_filename (path, name, NULL);
      GFile *subdir = file_new_for_path (subpath);

      /* Push and recurse. */
      push_dir_async (self, subdir);

      file_destroy (subdir);
      g_free (subpath);
      break;

    } else if (g_str_has_prefix (content_type, "audio/") ||
               g_str_has_prefix (content_type, "image/") ||
               g_str_has_prefix (content_type, "video/")) {

      /* Media found. */
      char const *path = g_object_get_data (G_OBJECT (enumerator), "path");
      char *filename = g_build_filename (path, name, NULL);
      priv->media_files = g_slist_prepend (priv->media_files, filename);
      priv->media_files_size += g_file_info_get_size (info);
    }

    g_object_unref (info);
  }

  if (info)
  {
    /* Broke out of loop, not done yet. */
    g_object_unref (info);

  } else {

    /* Directory finished, pop. */
    g_object_unref (enumerator);
    priv->dir_stack = g_slist_delete_link (priv->dir_stack, priv->dir_stack);
    if (priv->dir_stack)
    {
      enumerate_dir (self);
    } else {
      /* Done iterating. */
      g_signal_emit_by_name (self, "has-media", (bool) priv->media_files);
    }
  }

  if (error)
  {
    g_critical ("%s : %s", G_STRLOC, error->message);
    g_clear_error (&error);
  }
}
コード例 #21
0
ファイル: infb_docbook.c プロジェクト: Distrotech/bluefish
void infb_db_fill_node(GtkTextView *view,xmlDocPtr doc,xmlNodePtr node,gint level) {
	xmlNodePtr an;
	GtkTextBuffer *buff = gtk_text_view_get_buffer(view);
	xmlChar *text;
	xmlNodePtr auxn;
	gchar *levstr=NULL;
	if ( level > 0 ) 
		levstr = g_strnfill(2*level,' ');
	else
		levstr = "";
			
	if ( xmlStrcmp(node->name,BAD_CAST "book") ==0 /*||
				  xmlStrcmp(node->name,BAD_CAST "part") ==0*/	) {
				text = infb_db_get_title(doc,FALSE,node);
				if (text) {
					infb_insert_text(buff,text,INFB_TT_TITLE,TRUE);
					xmlFree(text);
				}
				text = infb_db_get_title(doc,TRUE,node);
				if (text) {
					infb_insert_text(buff,text,INFB_TT_DESC,TRUE);
					xmlFree(text);
				}
				
				auxn = node->xmlChildrenNode;
				while (auxn) {
					infb_db_fill_node(view,doc,auxn,level+1);				
					auxn = auxn->next;
				}				
									
			}
			else if ( xmlStrcmp(node->name,BAD_CAST "bookinfo") ==0 || 
						 xmlStrcmp(node->name,BAD_CAST "info") ==0) 
			{
			  if (level==0)
				infb_db_prepare_info(view,doc,node);
			  else { 
					infb_insert_icon(view,gtk_image_new_from_stock(GTK_STOCK_EDIT,GTK_ICON_SIZE_MENU),levstr);
					infb_insert_node(buff,BAD_CAST _("Info"),node,TRUE);											
			  } 		
			}
			else if ( xmlStrcmp(node->name,BAD_CAST "itemizedlist") ==0 ||
						 xmlStrcmp(node->name,BAD_CAST "orderedlist") ==0 ||
						 xmlStrcmp(node->name,BAD_CAST "segmentedlist") ==0 ||
						 xmlStrcmp(node->name,BAD_CAST "procedure") ==0 ) {
				auxn = node->xmlChildrenNode;
				while (auxn) {
					infb_insert_text(buff,BAD_CAST "•",INFB_TT_NONE,FALSE);
					infb_db_fill_node(view,doc,auxn,level+1);
					auxn = auxn->next;
				}				
			}			
			else  if ( xmlStrcmp(node->name,BAD_CAST "simpara") ==0 ) {
				text = xmlNodeGetContent(node);
				if (text) {
					infb_insert_text(buff,text,INFB_TT_NONE,TRUE);
					xmlFree(text);
				}
			}
			else  if ( xmlStrcmp(node->name,BAD_CAST "formalpara") ==0  ||
						  xmlStrcmp(node->name,BAD_CAST "term") ==0  ||
						  xmlStrcmp(node->name,BAD_CAST "indexterm") ==0  ||
						  xmlStrcmp(node->name,BAD_CAST "synopsis") ==0 ||	
						  xmlStrcmp(node->name,BAD_CAST "listitem") ==0  ||
						  xmlStrcmp(node->name,BAD_CAST "seglistitem") ==0  ||
						  xmlStrcmp(node->name,BAD_CAST "seg") ==0  ||
						  xmlStrcmp(node->name,BAD_CAST "varlistentry") ==0  ||					  			   	
						  xmlStrcmp(node->name,BAD_CAST "para") ==0) {
				an = getnode(doc,BAD_CAST "title",node);
				if (an) {
					text = xmlNodeGetContent(an);
					if (text) {
						infb_insert_text(buff,text,INFB_TT_SECTION,TRUE);
						xmlFree(text);
					}
				}
				auxn = node->xmlChildrenNode;
				while ( auxn ) {
					infb_db_fill_node(view,doc,auxn,level+1);						
					auxn = auxn->next;
				} 							
				infb_insert_text(buff,BAD_CAST "",INFB_TT_NONE,TRUE);
			}			
			else  if ( xmlStrcmp(node->name,BAD_CAST "refentry") ==0 ) {
				if (level==0) 
				{
					an = getnode(doc,BAD_CAST "refnamediv/refname",node);
					if (an) {
						text = xmlNodeGetContent(an);
						if (text) {
							infb_insert_text(buff,text,INFB_TT_TITLE,TRUE);
							xmlFree(text);
						}
					}
					an = getnode(doc,BAD_CAST "refnamediv/refpurpose",node);
					if (an) {
						text = xmlNodeGetContent(an);
						if (text) {
							infb_insert_text(buff,text,INFB_TT_DESC,TRUE);
							xmlFree(text);
						}
					}
					auxn = node->xmlChildrenNode;
					while ( auxn ) {
						infb_db_fill_node(view,doc,auxn,level+1);						
						auxn = auxn->next;
					} 						
				} 
				else
				{
			 		an = getnode(doc,BAD_CAST "refnamediv/refname",node);
					if (an) {
						text = xmlNodeGetContent(an);
						if (text) {
							infb_insert_icon(view,gtk_image_new_from_stock(GTK_STOCK_ABOUT,GTK_ICON_SIZE_MENU),NULL);
							infb_insert_node(buff,text,node,TRUE);
							xmlFree(text);
						}
					}				
				}
			}
			else  if ( xmlStrcmp(node->name,BAD_CAST "link") ==0 ) {
				gchar *pstr;
				xmlChar *text2;
				text = xmlGetProp(node,BAD_CAST "linkend");
				if (text) {
					pstr = g_strdup_printf("//refentry[@id=\"%s\"]",(gchar*)text);
					auxn = getnode(doc,BAD_CAST pstr,NULL);
					if (auxn) {
						text2 = xmlNodeGetContent(node);
						if (text2) {
							infb_insert_node(buff,text2,auxn,FALSE);
							xmlFree(text2);
						} 
					} else 
					{
						text2 = xmlNodeGetContent(node);
						if (text2) {
							infb_insert_text(buff,text2,INFB_TT_NONE,FALSE);
							xmlFree(text2);
						}	
					}	
					xmlFree(text);
					g_free(pstr);
				}
			}
			else  if ( xmlStrcmp(node->name,BAD_CAST "sect1") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "sect2") ==0	||
						  xmlStrcmp(node->name,BAD_CAST "sect3") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "sect4") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "sect5") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "section") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "refsect3") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "refsect2") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "refsection") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "refsynopsisdiv") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "refsect1") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "chapter") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "article") ==0 ||	
						  xmlStrcmp(node->name,BAD_CAST "preface") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "abstract") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "appendix") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "partintro") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "part") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "step") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "note") ==0 ||
						  xmlStrcmp(node->name,BAD_CAST "variablelist") ==0  						   
						) 
			{
			 if ( level == 0 ) {
				an = getnode(doc,BAD_CAST "child::title",node);
				if (an) {
					text = xmlNodeGetContent(an);
					if (text) {
						infb_insert_text(buff,text,INFB_TT_TITLE,TRUE);
						xmlFree(text);
					}
				}
				an = getnode(doc,BAD_CAST "child::subtitle",node);
				if (an) {
					text = xmlNodeGetContent(an);
					if (text) {
						infb_insert_text(buff,text,INFB_TT_DESC,TRUE);
						xmlFree(text);
					}
				}				
				auxn = node->xmlChildrenNode;
				while ( auxn ) {
					infb_db_fill_node(view,doc,auxn,level+1);
					auxn = auxn->next;
				} 												
			 }
			 else {
			 		an = getnode(doc,BAD_CAST "title",node);
					if (an) {
						text = xmlNodeGetContent(an);
						if (text) {
							infb_insert_icon(view,gtk_image_new_from_stock(GTK_STOCK_ABOUT,GTK_ICON_SIZE_MENU),levstr);
							infb_insert_node(buff,text,node,TRUE);
							xmlFree(text);
						} else {
							infb_insert_icon(view,gtk_image_new_from_stock(GTK_STOCK_ABOUT,GTK_ICON_SIZE_MENU),levstr);
							infb_insert_node(buff,BAD_CAST node->name,node,TRUE);					
						}
					}
			  }
			 } /*sections */
			 else  if ( xmlStrcmp(node->name,BAD_CAST "refmeta") ==0 ||
			 				xmlStrcmp(node->name,BAD_CAST "glossary") ==0 ||
			 				xmlStrcmp(node->name,BAD_CAST "refnamediv") ==0 
			 				) {
			 	/* not shown */
			 }
			 else { /* other elements */
			 	infb_db_format_element(view,doc,node);
			 }						 
}
コード例 #22
0
ファイル: xmppconsole.c プロジェクト: renatosilva/pidgin-plus
static char *
xmlnode_to_pretty_str(xmlnode *node, int *len, int depth)
{
	GString *text = g_string_new("");
	xmlnode *c;
	char *node_name, *esc, *esc2, *tab = NULL;
	gboolean need_end = FALSE, pretty = TRUE;

	g_return_val_if_fail(node != NULL, NULL);

	if (pretty && depth) {
		tab = g_strnfill(depth, '\t');
		text = g_string_append(text, tab);
	}

	node_name = g_markup_escape_text(node->name, -1);
	g_string_append_printf(text,
	                       "<font color='" BRACKET_COLOR "'>&lt;</font>"
	                       "<font color='" TAG_COLOR "'><b>%s</b></font>",
	                       node_name);

	if (node->xmlns) {
		if ((!node->parent ||
		     !node->parent->xmlns ||
		     strcmp(node->xmlns, node->parent->xmlns)) &&
		    strcmp(node->xmlns, "jabber:client"))
		{
			char *xmlns = g_markup_escape_text(node->xmlns, -1);
			g_string_append_printf(text,
			                       " <font color='" ATTR_NAME_COLOR "'><b>xmlns</b></font>="
			                       "'<font color='" XMLNS_COLOR "'><b>%s</b></font>'",
			                       xmlns);
			g_free(xmlns);
		}
	}
	for (c = node->child; c; c = c->next)
	{
		if (c->type == XMLNODE_TYPE_ATTRIB) {
			esc = g_markup_escape_text(c->name, -1);
			esc2 = g_markup_escape_text(c->data, -1);
			g_string_append_printf(text,
			                       " <font color='" ATTR_NAME_COLOR "'><b>%s</b></font>="
			                       "'<font color='" ATTR_VALUE_COLOR "'>%s</font>'",
			                       esc, esc2);
			g_free(esc);
			g_free(esc2);
		} else if (c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) {
			if (c->type == XMLNODE_TYPE_DATA)
				pretty = FALSE;
			need_end = TRUE;
		}
	}

	if (need_end) {
		g_string_append_printf(text,
		                       "<font color='"BRACKET_COLOR"'>&gt;</font>%s",
		                       pretty ? "<br>" : "");

		for (c = node->child; c; c = c->next)
		{
			if (c->type == XMLNODE_TYPE_TAG) {
				int esc_len;
				esc = xmlnode_to_pretty_str(c, &esc_len, depth+1);
				text = g_string_append_len(text, esc, esc_len);
				g_free(esc);
			} else if (c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) {
				esc = g_markup_escape_text(c->data, c->data_sz);
				text = g_string_append(text, esc);
				g_free(esc);
			}
		}

		if(tab && pretty)
			text = g_string_append(text, tab);
		g_string_append_printf(text,
		                       "<font color='" BRACKET_COLOR "'>&lt;</font>/"
		                       "<font color='" TAG_COLOR "'><b>%s</b></font>"
		                       "<font color='" BRACKET_COLOR "'>&gt;</font><br>",
		                       node_name);
	} else {
		g_string_append_printf(text,
		                       "/<font color='" BRACKET_COLOR "'>&gt;</font><br>");
	}

	g_free(node_name);

	g_free(tab);

	if(len)
		*len = text->len;

	return g_string_free(text, FALSE);
}
コード例 #23
0
ファイル: opml_export.c プロジェクト: Mortal/claws
void rssyl_opml_export(void)
{
	FILE *f;
	gchar *opmlfile, *tmp;
	time_t tt = time(NULL);
	RSSylOpmlCtx *ctx = NULL;
	gboolean err = FALSE;

	opmlfile = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RSSYL_DIR,
			G_DIR_SEPARATOR_S, RSSYL_OPML_FILE, NULL);

	if( g_file_test(opmlfile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR ) ) {
		if (g_remove(opmlfile) != 0) {
			log_warning(LOG_PROTOCOL,
					_("RSSyl: Couldn't delete old OPML file '%s': %s\n"),
					opmlfile, g_strerror(errno));
			debug_print("RSSyl: couldn't delete old file '%s'\n", opmlfile);
			g_free(opmlfile);
			return;
		}
	}
	
	if( (f = g_fopen(opmlfile, "w")) == NULL ) {
		log_warning(LOG_PROTOCOL,
				_("RSSyl: Couldn't open file '%s' for feed list exporting: %s\n"),
				opmlfile, g_strerror(errno));
		debug_print("RSSyl: Couldn't open feed list export file, returning.\n");
		g_free(opmlfile);
		return;
	}

	tmp = createRFC822Date(&tt);

	/* Write OPML header */
	err |= (fprintf(f,
				"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
				"<opml version=\"1.1\">\n"
				"\t<head>\n"
				"\t\t<title>RSSyl Feed List Export</title>\n"
				"\t\t<dateCreated>%s</dateCreated>\n"
				"\t</head>\n"
				"\t<body>\n",
				tmp) < 0);
	g_free(tmp);

	ctx = g_new0(RSSylOpmlCtx, 1);
	ctx->f = f;
	ctx->depth = 1;

	folder_func_to_all_folders(
			(FolderItemFunc)rssyl_opml_export_func, ctx);

	/* Print close all open <outline> tags if needed. */
	while( ctx->depth > 2 ) {
		ctx->depth--;
		tmp = g_strnfill(ctx->depth, '\t');
		err |= (fprintf(f, "%s</outline>\n", tmp) < 0);
		g_free(tmp);
	}

	err |= (fprintf(f,
				"\t</body>\n"
				"</opml>\n") < 0);

	if( err ) {
		log_warning(LOG_PROTOCOL, _("RSSyl: Error during writing feed export file.\n"));
		debug_print("RSSyl: Error during writing feed export file.\n");
	}

	debug_print("RSSyl: Feed export finished.\n");

	fclose(f);
	g_free(opmlfile);
	g_free(ctx);
}
コード例 #24
0
void
generate_username_choices (const gchar  *name,
                           GtkListStore *store)
{
        gboolean in_use, same_as_initial;
        char *lc_name, *ascii_name, *stripped_name;
        char *default_username;
        char **words1;
        char **words2 = NULL;
        char **w1, **w2;
        char *c;
        char *unicode_fallback = "?";
        GString *first_word, *last_word;
        GString *item0, *item1, *item2, *item3, *item4;
        int len;
        int nwords1, nwords2, i;
        GHashTable *items = NULL;
        GtkTreeIter iter;

        gtk_list_store_clear (store);

        ascii_name = g_convert_with_fallback (name, -1, "ASCII//TRANSLIT", "UTF-8",
                                              unicode_fallback, NULL, NULL, NULL);

        lc_name = g_ascii_strdown (ascii_name, -1);

        /* Remove all non ASCII alphanumeric chars from the name,
         * apart from the few allowed symbols.
         *
         * We do remove '.', even though it is usually allowed,
         * since it often comes in via an abbreviated middle name,
         * and the dot looks just wrong in the proposals then.
         */
        stripped_name = g_strnfill (strlen (lc_name) + 1, '\0');
        i = 0;
        for (c = lc_name; *c; c++) {
                if (!(g_ascii_isdigit (*c) || g_ascii_islower (*c) ||
                    *c == ' ' || *c == '-' || *c == '_' ||
                    /* used to track invalid words, removed below */
                    *c == '?') )
                        continue;

                    stripped_name[i] = *c;
                    i++;
        }

        if (strlen (stripped_name) == 0) {
                g_free (ascii_name);
                g_free (lc_name);
                g_free (stripped_name);
                goto bailout;
        }

        /* we split name on spaces, and then on dashes, so that we can treat
         * words linked with dashes the same way, i.e. both fully shown, or
         * both abbreviated
         */
        words1 = g_strsplit_set (stripped_name, " ", -1);
        len = g_strv_length (words1);

        item0 = g_string_sized_new (strlen (stripped_name));

        g_free (ascii_name);
        g_free (lc_name);
        g_free (stripped_name);

        /* Concatenate the whole first word with the first letter of each
         * word (item1), and the last word with the first letter of each
         * word (item2). item3 and item4 are symmetrical respectively to
         * item1 and item2.
         *
         * Constant 5 is the max reasonable number of words we may get when
         * splitting on dashes, since we can't guess it at this point,
         * and reallocating would be too bad.
         */
        item1 = g_string_sized_new (strlen (words1[0]) + len - 1 + 5);
        item3 = g_string_sized_new (strlen (words1[0]) + len - 1 + 5);

        item2 = g_string_sized_new (strlen (words1[len - 1]) + len - 1 + 5);
        item4 = g_string_sized_new (strlen (words1[len - 1]) + len - 1 + 5);

        /* again, guess at the max size of names */
        first_word = g_string_sized_new (20);
        last_word = g_string_sized_new (20);

        nwords1 = 0;
        nwords2 = 0;
        for (w1 = words1; *w1; w1++) {
                if (strlen (*w1) == 0)
                        continue;

                /* skip words with string '?', most likely resulting
                 * from failed transliteration to ASCII
                 */
                if (strstr (*w1, unicode_fallback) != NULL)
                        continue;

                nwords1++; /* count real words, excluding empty string */

                item0 = g_string_append (item0, *w1);

                words2 = g_strsplit_set (*w1, "-", -1);
                /* reset last word if a new non-empty word has been found */
                if (strlen (*words2) > 0)
                        last_word = g_string_set_size (last_word, 0);

                for (w2 = words2; *w2; w2++) {
                        if (strlen (*w2) == 0)
                                continue;

                        nwords2++;

                        /* part of the first "toplevel" real word */
                        if (nwords1 == 1) {
                                item1 = g_string_append (item1, *w2);
                                first_word = g_string_append (first_word, *w2);
                        }
                        else {
                                item1 = g_string_append_unichar (item1,
                                                                 g_utf8_get_char (*w2));
                                item3 = g_string_append_unichar (item3,
                                                                 g_utf8_get_char (*w2));
                        }

                        /* not part of the last "toplevel" word */
                        if (w1 != words1 + len - 1) {
                                item2 = g_string_append_unichar (item2,
                                                                 g_utf8_get_char (*w2));
                                item4 = g_string_append_unichar (item4,
                                                                 g_utf8_get_char (*w2));
                        }

                        /* always save current word so that we have it if last one reveals empty */
                        last_word = g_string_append (last_word, *w2);
                }

                g_strfreev (words2);
        }

        g_string_truncate (first_word, MAXNAMELEN);
        g_string_truncate (last_word, MAXNAMELEN);

        item2 = g_string_append (item2, last_word->str);
        item3 = g_string_append (item3, first_word->str);
        item4 = g_string_prepend (item4, last_word->str);

        g_string_truncate (item0, MAXNAMELEN);
        g_string_truncate (item1, MAXNAMELEN);
        g_string_truncate (item2, MAXNAMELEN);
        g_string_truncate (item3, MAXNAMELEN);
        g_string_truncate (item4, MAXNAMELEN);

        items = g_hash_table_new (g_str_hash, g_str_equal);

        /* add the first word */
        in_use = is_username_used (first_word->str);
        if (*first_word->str && !in_use && !g_ascii_isdigit (first_word->str[0]) &&
            !g_hash_table_lookup (items, first_word->str)) {
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, 0, first_word->str, -1);
                g_hash_table_insert (items, first_word->str, first_word->str);
        }

        /* add the last word */
        in_use = is_username_used (last_word->str);
        if (*last_word->str && !in_use && !g_ascii_isdigit (last_word->str[0]) &&
            !g_hash_table_lookup (items, last_word->str)) {
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter, 0, last_word->str, -1);
                g_hash_table_insert (items, last_word->str, last_word->str);
        }

        /* if there's only one word, would be the same as item1 */
        if (nwords2 > 1) {
                /* add other items */
                in_use = is_username_used (item0->str);
                if (*item0->str && !in_use && !g_ascii_isdigit (item0->str[0])) {
                        gtk_list_store_append (store, &iter);
                        gtk_list_store_set (store, &iter, 0, item0->str, -1);
                        g_hash_table_insert (items, item0->str, item0->str);
                }

                in_use = is_username_used (item1->str);
                same_as_initial = (g_strcmp0 (item0->str, item1->str) == 0);
                if (*item1->str && !same_as_initial && nwords2 > 0 && !in_use && !g_ascii_isdigit (item1->str[0])) {
                        gtk_list_store_append (store, &iter);
                        gtk_list_store_set (store, &iter, 0, item1->str, -1);
                        g_hash_table_insert (items, item1->str, item1->str);
                }

                in_use = is_username_used (item2->str);
                if (*item2->str && !in_use && !g_ascii_isdigit (item2->str[0]) &&
                    !g_hash_table_lookup (items, item2->str)) {
                        gtk_list_store_append (store, &iter);
                        gtk_list_store_set (store, &iter, 0, item2->str, -1);
                        g_hash_table_insert (items, item2->str, item2->str);
                }

                in_use = is_username_used (item3->str);
                if (*item3->str && !in_use && !g_ascii_isdigit (item3->str[0]) &&
                    !g_hash_table_lookup (items, item3->str)) {
                        gtk_list_store_append (store, &iter);
                        gtk_list_store_set (store, &iter, 0, item3->str, -1);
                        g_hash_table_insert (items, item3->str, item3->str);
                }

                in_use = is_username_used (item4->str);
                if (*item4->str && !in_use && !g_ascii_isdigit (item4->str[0]) &&
                    !g_hash_table_lookup (items, item4->str)) {
                        gtk_list_store_append (store, &iter);
                        gtk_list_store_set (store, &iter, 0, item4->str, -1);
                        g_hash_table_insert (items, item4->str, item4->str);
                }
        }

        g_strfreev (words1);
        g_string_free (first_word, TRUE);
        g_string_free (last_word, TRUE);
        g_string_free (item0, TRUE);
        g_string_free (item1, TRUE);
        g_string_free (item2, TRUE);
        g_string_free (item3, TRUE);
        g_string_free (item4, TRUE);

bailout:
        if (items == NULL || g_hash_table_size (items) == 0) {
                gtk_list_store_append (store, &iter);
                default_username = g_strdup (DEFAULT_USERNAME);
                i = 0;
                while (is_username_used (default_username)) {
                        g_free (default_username);
                        default_username = g_strdup_printf (DEFAULT_USERNAME "%d", ++i);
                }
                gtk_list_store_set (store, &iter, 0, default_username, -1);
                g_free (default_username);
        }
        if (items != NULL) {
                g_hash_table_destroy (items);
        }
}
コード例 #25
0
ファイル: opml_export.c プロジェクト: Mortal/claws
static void rssyl_opml_export_func(FolderItem *item, gpointer data)
{
	RSSylOpmlCtx *ctx = (RSSylOpmlCtx *)data;
	RFolderItem *ritem = (RFolderItem *)item;
	gboolean isfolder = FALSE, err = FALSE;
	gboolean haschildren = FALSE;
	gchar *indent = NULL, *xmlurl = NULL;
	gchar *tmpoffn = NULL, *tmpurl = NULL, *tmpname = NULL;
	gint depth;

	if( !IS_RSSYL_FOLDER_ITEM(item) )
		return;

	if( folder_item_parent(item) == NULL )
		return;

	/* Check for depth and adjust indentation */
	depth = rssyl_folder_depth(item);
	if( depth < ctx->depth ) {
		for( ctx->depth--; depth <= ctx->depth; ctx->depth-- ) {
			indent = g_strnfill(ctx->depth + 1, '\t');
			err |= (fprintf(ctx->f, "%s</outline>\n", indent) < 0);
			g_free(indent);
		}
	}
	ctx->depth = depth;

	if( ritem->url == NULL ) {
		isfolder = TRUE;
	} else {
		tmpurl = rssyl_strreplace(ritem->url, "&", "&amp;");
		xmlurl = g_strdup_printf("xmlUrl=\"%s\"", tmpurl);
		g_free(tmpurl);
	}

	if( g_node_n_children(item->node) )
		haschildren = TRUE;

	indent = g_strnfill(ctx->depth + 1, '\t');

	tmpname = rssyl_strreplace(item->name, "&", "&amp;");
	 if( ritem->official_title != NULL )
		 tmpoffn = rssyl_strreplace(ritem->official_title, "&", "&amp;");
	 else
		 tmpoffn = g_strdup(tmpname);

	err |= (fprintf(ctx->f,
				"%s<outline title=\"%s\" text=\"%s\" description=\"%s\" type=\"%s\" %s%s>\n",
				indent, tmpname, tmpoffn, tmpoffn,
				(isfolder ? "folder" : "rss"),
				(xmlurl ? xmlurl : ""), (haschildren ? "" : "/")) < 0);

	g_free(indent);
	g_free(xmlurl);
	g_free(tmpname);
	g_free(tmpoffn);
	
	if( err ) {
		log_warning(LOG_PROTOCOL,
				_("RSSyl: Error while writing '%s' to feed export list.\n"),
				item->name);
		debug_print("Error while writing '%s' to feed_export list.\n",
				item->name);
	}
}
コード例 #26
0
ファイル: xmlnode.c プロジェクト: bf4/pidgin-mac
static char *
xmlnode_to_str_helper(const xmlnode *node, int *len, gboolean formatting, int depth)
{
	GString *text = g_string_new("");
	const char *prefix;
	const xmlnode *c;
	char *node_name, *esc, *esc2, *tab = NULL;
	gboolean need_end = FALSE, pretty = formatting;

	g_return_val_if_fail(node != NULL, NULL);

	if(pretty && depth) {
		tab = g_strnfill(depth, '\t');
		text = g_string_append(text, tab);
	}

	node_name = g_markup_escape_text(node->name, -1);
	prefix = xmlnode_get_prefix(node);

	if (prefix) {
		g_string_append_printf(text, "<%s:%s", prefix, node_name);
	} else {
		g_string_append_printf(text, "<%s", node_name);
	}

	if (node->namespace_map) {
		g_hash_table_foreach(node->namespace_map,
			(GHFunc)xmlnode_to_str_foreach_append_ns, text);
	} else if (node->xmlns) {
		if(!node->parent || !node->parent->xmlns || strcmp(node->xmlns, node->parent->xmlns))
		{
			char *xmlns = g_markup_escape_text(node->xmlns, -1);
			g_string_append_printf(text, " xmlns='%s'", xmlns);
			g_free(xmlns);
		}
	}
	for(c = node->child; c; c = c->next)
	{
		if(c->type == XMLNODE_TYPE_ATTRIB) {
			const char *aprefix = xmlnode_get_prefix(c);
			esc = g_markup_escape_text(c->name, -1);
			esc2 = g_markup_escape_text(c->data, -1);
			if (aprefix) {
				g_string_append_printf(text, " %s:%s='%s'", aprefix, esc, esc2);
			} else {
				g_string_append_printf(text, " %s='%s'", esc, esc2);
			}
			g_free(esc);
			g_free(esc2);
		} else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) {
			if(c->type == XMLNODE_TYPE_DATA)
				pretty = FALSE;
			need_end = TRUE;
		}
	}

	if(need_end) {
		g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : "");

		for(c = node->child; c; c = c->next)
		{
			if(c->type == XMLNODE_TYPE_TAG) {
				int esc_len;
				esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1);
				text = g_string_append_len(text, esc, esc_len);
				g_free(esc);
			} else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) {
				esc = g_markup_escape_text(c->data, c->data_sz);
				text = g_string_append(text, esc);
				g_free(esc);
			}
		}

		if(tab && pretty)
			text = g_string_append(text, tab);
		if (prefix) {
			g_string_append_printf(text, "</%s:%s>%s", prefix, node_name, formatting ? NEWLINE_S : "");
		} else {
			g_string_append_printf(text, "</%s>%s", node_name, formatting ? NEWLINE_S : "");
		}
	} else {
		g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : "");
	}

	g_free(node_name);

	g_free(tab);

	if(len)
		*len = text->len;

	return g_string_free(text, FALSE);
}
コード例 #27
0
ファイル: login_logout.c プロジェクト: arminius2/apolloim
/* It is fixed to 16 bytes 0x01 for QQ2003, 
 * Any value works (or a random 16 bytes string) */
static guint8 *_gen_login_key(void)
{
	return (guint8 *) g_strnfill(QQ_KEY_LENGTH, 0x01);
}