Ejemplo n.º 1
0
gchar* Inkscape::IO::locale_to_utf8_fallback( const gchar *opsysstring,
                                              gssize len,
                                              gsize *bytes_read,
                                              gsize *bytes_written,
                                              GError **error )
{
    gchar *result = NULL;
    if ( opsysstring ) {
        gchar *newFileName = g_locale_to_utf8( opsysstring, len, bytes_read, bytes_written, error );
        if ( newFileName ) {
            if ( !g_utf8_validate(newFileName, -1, NULL) ) {
                g_warning( "input filename did not yield UTF-8" );
                g_free( newFileName );
            } else {
                result = newFileName;
            }
            newFileName = 0;
        } else if ( g_utf8_validate(opsysstring, -1, NULL) ) {
            // This *might* be a case that we want
            // g_warning( "input failed filename->utf8, fell back to original" );
            // TODO handle cases when len >= 0
            result = g_strdup( opsysstring );
        } else {
            gchar const *charset = 0;
            g_get_charset(&charset);
            g_warning( "input filename conversion failed for file with locale charset '%s'", charset );
        }
    }
    return result;
}
Ejemplo n.º 2
0
int
get_stamp_str (char *fmt, time_t tim, char **ret)
{
	char *loc = NULL;
	char dest[128];
	gsize len;

	/* strftime wants the format string in LOCALE! */
	if (!prefs.utf8_locale)
	{
		const gchar *charset;

		g_get_charset (&charset);
		loc = g_convert_with_fallback (fmt, -1, charset, "UTF-8", "?", 0, 0, 0);
		if (loc)
			fmt = loc;
	}

	len = strftime_validated (dest, sizeof (dest), fmt, localtime (&tim));
	if (len)
	{
		if (prefs.utf8_locale)
			*ret = g_strdup (dest);
		else
			*ret = g_locale_to_utf8 (dest, len, 0, &len, 0);
	}

	if (loc)
		g_free (loc);

	return len;
}
Ejemplo n.º 3
0
GSList *
_gedit_utils_encoding_strv_to_list (const gchar * const *enc_str)
{
	GSList *res = NULL;
	gchar **p;

	for (p = (gchar **)enc_str; p != NULL && *p != NULL; p++)
	{
		const gchar *charset = *p;
		const GtkSourceEncoding *enc;

		if (g_str_equal (charset, "CURRENT"))
		{
			g_get_charset (&charset);
		}

		g_return_val_if_fail (charset != NULL, NULL);
		enc = gtk_source_encoding_get_from_charset (charset);

		if (enc != NULL &&
		    !data_exists (res, (gpointer)enc))
		{
			res = g_slist_prepend (res, (gpointer)enc);
		}
	}

	return g_slist_reverse (res);
}
Ejemplo n.º 4
0
/* schreibt eine UTF-8 Zeichenkette auf die Standardausgabe */
gint printf_utf8(const gchar *format, ...)
{
    gchar *str_utf8, *str_locale;
    const char *locale_charset;
    va_list ap;
    gsize len_utf8, len_locale;
    gint retval;

    va_start(ap, format);
    str_utf8 = g_strdup_vprintf(format, ap);
    va_end(ap);

    len_utf8 = (gsize) strlen(str_utf8);

    if (!g_get_charset(&locale_charset)) {
        str_locale = g_convert_with_fallback(str_utf8, (gssize) len_utf8,
                                             locale_charset, "UTF-8",
                                             "_",
                                             NULL, &len_locale, NULL);
        g_free(str_utf8);
    } else {
        str_locale = str_utf8;
        str_utf8 = NULL;
        len_locale = len_utf8;
    }

    if (str_locale == NULL)
        return -1;

    retval = (gint) fwrite(str_locale, sizeof(gchar), len_locale, stdout);

    g_free(str_locale);

    return retval;
}
Ejemplo n.º 5
0
/** Parse a given file into XML, handling old broken files correctly.
 * @param filename The name of the file to read.
 * @returns An XML document parsed from the file.
 * @see xmlParseFile() in the XML2 library for details on the return value.
 */
xmlDocPtr
xmlDiaParseFile(const char *filename)
{
  G_CONST_RETURN char *local_charset = NULL;

  if (   !g_get_charset(&local_charset)
      && local_charset) {
    /* we're not in an UTF-8 environment. */
    const gchar *fname = xml_file_check_encoding(filename,local_charset);
    if (fname != filename) {
      /* We've got a corrected file to parse. */
      xmlDocPtr ret = xmlDoParseFile(fname);
      unlink(fname);
      /* printf("has read %s instead of %s\n",fname,filename); */
      g_free((void *)fname);
      return ret;
    } else {
      /* the XML file is good. libxml is "old enough" to handle it correctly.
       */
      return xmlDoParseFile(filename);
    }
  } else {
    return xmlDoParseFile(filename);
  }
}
Ejemplo n.º 6
0
/* Must free the returned string yourself */
gchar *charset_track_charset_from_utf8 (Track *s, const gchar *str)
{
    gchar *charset;
    const gchar *locale_charset;
    gchar *result;
    ExtraTrackData *etd;

    g_return_val_if_fail (s, NULL);
    g_return_val_if_fail (s->userdata, NULL);

    if (str == NULL) return NULL;  /* sanity */

    etd = s->userdata;

    if (etd->charset && strlen (etd->charset))
	   charset = g_strdup(etd->charset);
    else
	charset = prefs_get_string("charset");

    if (!charset || !strlen (charset))
    {    /* use standard locale charset */
	g_free(charset);
	g_get_charset (&locale_charset);
	charset = g_strdup(locale_charset);
    }

    result = charset_to_charset ("UTF-8", charset, str);
    g_free(charset);
    return result;
}
Ejemplo n.º 7
0
void CoreManager::InputInit()
{
  // init libtermkey
  TERMKEY_CHECK_VERSION;
  if (!(tk = termkey_new(STDIN_FILENO, TERMKEY_FLAG_NOTERMIOS))) {
    g_critical(_("Libtermkey initialization failed."));
    exit(1);
  }
  utf8 = g_get_charset(NULL);

  io_input_channel = g_io_channel_unix_new(STDIN_FILENO);
  // set channel encoding to NULL so it can be unbuffered
  g_io_channel_set_encoding(io_input_channel, NULL, NULL);
  g_io_channel_set_buffered(io_input_channel, FALSE);
  g_io_channel_set_close_on_unref(io_input_channel, TRUE);

  io_input_channel_id = g_io_add_watch_full(io_input_channel, G_PRIORITY_HIGH,
      static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI),
      io_input_, this, NULL);
  g_io_add_watch_full(io_input_channel, G_PRIORITY_HIGH, G_IO_NVAL,
      io_input_error_, this, NULL);
  g_io_channel_unref(io_input_channel);

  // screen resizing
  if (!pipe(pipefd)) {
    pipe_valid = true;
    resize_channel = g_io_channel_unix_new(pipefd[0]);
    g_io_channel_set_encoding(resize_channel, NULL, NULL);
    g_io_channel_set_buffered(resize_channel, FALSE);
    g_io_channel_set_close_on_unref(resize_channel, TRUE);

    resize_channel_id = g_io_add_watch_full(resize_channel, G_PRIORITY_HIGH,
        G_IO_IN, resize_input_, this, NULL);
  }
}
Ejemplo n.º 8
0
static gchar *
str_to_utf8 (const gchar *text)
{
	static const gchar *encodings_to_try[2];
	static gint n_encodings_to_try = 0;
	gchar *utf8_text = NULL;
	gint i;

	if (n_encodings_to_try == 0) {
		const gchar *charset;
		gboolean charset_is_utf8;

		charset_is_utf8 = g_get_charset (&charset);
		if (!charset_is_utf8) {
			encodings_to_try[n_encodings_to_try++] = charset;
		}

		if (g_ascii_strcasecmp (charset, "ISO-8859-1") != 0) {
			encodings_to_try[n_encodings_to_try++] = "ISO-8859-1";
		}
	}

	for (i = 0; i < n_encodings_to_try; i++) {
		utf8_text = g_convert (text, -1, "UTF-8",
				       encodings_to_try[i],
				       NULL, NULL, NULL);
		if (utf8_text)
			break;
	}

	return utf8_text;
}
Ejemplo n.º 9
0
/* Must free the returned string yourself */
gchar *charset_to_utf8 (const gchar *str)
{
    gchar *charset;  /* From prefs */
    const gchar *locale_charset; /* Used if prefs doesn't have a charset */
    gchar *result;

    if (str == NULL) return NULL;  /* sanity */
    charset = charset_check_auto (str);
    if (charset)
    {
	g_free(auto_charset);
	auto_charset = g_strdup(charset);
    }
    else
    {
	charset = prefs_get_string("charset");
	if (!charset || !strlen (charset))
	{    /* use standard locale charset */
	    g_free(charset);
	    g_get_charset (&locale_charset);
	    charset = g_strdup(locale_charset);
	}
    }

    result = charset_to_charset (charset, "UTF-8", str);
    g_free(charset);
    return result;
}
Ejemplo n.º 10
0
/* Use this function to process a line for the first time, it will convert the
 * string to UTF-8.
 */
static void
process_line (LatexilaPostProcessor *pp,
              gchar                 *line)
{
  gchar *utf8_line = NULL;

  /* locale is not UTF-8 */
  if (!g_get_charset (NULL))
    {
      utf8_line = g_locale_to_utf8 (line, -1, NULL, NULL, NULL);
    }
  else if (g_utf8_validate (line, -1, NULL))
    {
      utf8_line = line;
      line = NULL;
    }

  /* The LaTeX output can be in ISO-8859-1, with accents in a filename for
   * instance.
   */
  if (utf8_line == NULL)
    utf8_line = g_convert (line, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);

  if (utf8_line != NULL)
    latexila_post_processor_process_line (pp, utf8_line);
  else
    g_warning ("Failed to convert subprocess output to UTF-8: %s", line);

  g_free (line);
}
Ejemplo n.º 11
0
Archivo: dia_xml.c Proyecto: UIKit0/dia
/*!
 * \brief Parse a given file into XML, handling old broken files correctly.
 * @param filename The name of the file to read.
 * @returns An XML document parsed from the file.
 * @see xmlParseFile() in the XML2 library for details on the return value.
 * @param ctx The context in which this function is called
 * \ingroup DiagramXmlIo
 */
static xmlDocPtr
xmlDiaParseFile(const char *filename, DiaContext *ctx)
{
  const char *local_charset = NULL;
  xmlErrorPtr error_xml = NULL;
  xmlDocPtr ret = NULL;

  if (   !g_get_charset(&local_charset)
      && local_charset) {
    /* we're not in an UTF-8 environment. */ 
    const gchar *fname = xml_file_check_encoding(filename,local_charset, ctx);
    if (fname != filename) {
      /* We've got a corrected file to parse. */
      xmlDocPtr ret = xmlDoParseFile(fname, &error_xml);
      unlink(fname);
      /* printf("has read %s instead of %s\n",fname,filename); */
      g_free((void *)fname);
    } else {
      /* the XML file is good. libxml is "old enough" to handle it correctly.
       */
      ret = xmlDoParseFile(filename, &error_xml);
    }
  } else {
    ret = xmlDoParseFile(filename, &error_xml);
  }
  if (error_xml)
    dia_context_add_message (ctx, error_xml->message);
  return ret;
}
Ejemplo n.º 12
0
const PlumaEncoding *
pluma_encoding_get_current (void)
{
	static gboolean initialized = FALSE;
	static const PlumaEncoding *locale_encoding = NULL;

	const gchar *locale_charset;

	pluma_encoding_lazy_init ();

	if (initialized != FALSE)
		return locale_encoding;

	if (g_get_charset (&locale_charset) == FALSE) 
	{
		g_return_val_if_fail (locale_charset != NULL, &utf8_encoding);
		
		locale_encoding = pluma_encoding_get_from_charset (locale_charset);
	}
	else
	{
		locale_encoding = &utf8_encoding;
	}
	
	if (locale_encoding == NULL)
	{
		locale_encoding = &unknown_encoding;
	}

	g_return_val_if_fail (locale_encoding != NULL, NULL);

	initialized = TRUE;

	return locale_encoding;
}
Ejemplo n.º 13
0
/*
 * Conversion with UTF-8 for Ogg Vorbis and FLAC tags (current_charset <===> UTF-8)
 */
gchar *convert_to_utf8 (const gchar *string)
{
    gchar *output;
    GError *error = NULL;

    g_return_val_if_fail (string != NULL, NULL);

    output = g_locale_to_utf8(string, -1, NULL, NULL, &error);

    if (output == NULL)
    {
        const gchar *usercharset;
        gchar *escaped_str = g_strescape(string, NULL);
        g_get_charset(&usercharset);
        Log_Print(LOG_ERROR,"convert_to_utf8(): Failed conversion from charset '%s'. "
                  "String '%s'. Errcode %d (%s).",
                  usercharset, escaped_str, error->code, error->message);
        g_free(escaped_str);

        if (g_utf8_validate(string, -1, NULL))
            Log_Print(LOG_ERROR,"convert_to_utf8(): String was valid UTF-8.");
        else
            Log_Print(LOG_ERROR,"convert_to_utf8(): String was INVALID UTF-8.");

        g_error_free(error);
        return g_strdup(string);
    }

    return output;
}
Ejemplo n.º 14
0
/**
 * gtk_content_formats_add_text_targets:
 * @list: a #GdkContentFormats
 * 
 * Appends the text targets supported by #GtkSelectionData to
 * the target list. All targets are added with the same @info.
 **/
GdkContentFormats *
gtk_content_formats_add_text_targets (GdkContentFormats *list)
{
  GdkContentFormatsBuilder *builder;

  g_return_val_if_fail (list != NULL, NULL);
  
  init_atoms ();

  builder = gdk_content_formats_builder_new ();
  gdk_content_formats_builder_add_formats (builder, list);
  gdk_content_formats_unref (list);

  /* Keep in sync with gtk_selection_data_targets_include_text()
   */
  gdk_content_formats_builder_add_mime_type (builder, utf8_atom);  
  gdk_content_formats_builder_add_mime_type (builder, ctext_atom);  
  gdk_content_formats_builder_add_mime_type (builder, text_atom);  
  gdk_content_formats_builder_add_mime_type (builder, g_intern_static_string ("STRING"));  
  gdk_content_formats_builder_add_mime_type (builder, text_plain_utf8_atom);  
  if (!g_get_charset (NULL))
    gdk_content_formats_builder_add_mime_type (builder, text_plain_locale_atom);  
  gdk_content_formats_builder_add_mime_type (builder, text_plain_atom);  

  return gdk_content_formats_builder_free_to_formats (builder);
}
static void
test_non_utf8_import (NMVpnPluginUiInterface *plugin, const char *dir)
{
	NMConnection *connection;
	NMSettingConnection *s_con;
	NMSettingVPN *s_vpn;
	const char *expected_id = "Att äta en ko";
	const char *charset = NULL;

	/* Change charset to ISO-8859-15 to match iso885915.pcf */
	g_get_charset (&charset);
	setlocale (LC_ALL, "de_DE@euro");
	connection = get_basic_connection ("non-utf8-import", plugin, dir, "iso885915.pcf");
	setlocale (LC_ALL, charset);

	ASSERT (connection != NULL, "non-utf8-import", "failed to import connection");

	/* Connection setting */
	s_con = nm_connection_get_setting_connection (connection);
	ASSERT (s_con != NULL,
	        "non-utf8-import", "missing 'connection' setting");

	ASSERT (strcmp (nm_setting_connection_get_id (s_con), expected_id) == 0,
	        "non-utf8-import", "unexpected connection ID");

	ASSERT (nm_setting_connection_get_uuid (s_con) == NULL,
	        "non-utf8-import", "unexpected valid UUID");

	/* VPN setting */
	s_vpn = nm_connection_get_setting_vpn (connection);
	ASSERT (s_vpn != NULL,
	        "non-utf8-import", "missing 'vpn' setting");

	g_object_unref (connection);
}
Ejemplo n.º 16
0
const gchar *get_default_charset(void)
{
	const gchar *charset;
	
	g_get_charset(&charset);
	
	return charset;
}
Ejemplo n.º 17
0
gchar *
gdk_wcstombs (const GdkWChar *src)
{
  const gchar *charset;

  g_get_charset (&charset);
  return g_convert ((char *) src, -1, charset, "UCS-4LE", NULL, NULL, NULL);
}
Ejemplo n.º 18
0
void
netinfo_text_buffer_insert (Netinfo * netinfo)
{
	gchar *dir = g_get_current_dir ();
	gint child_pid, pout;
	GIOChannel *channel;
	const gchar *charset;
	GIOStatus status;
	GError *err = NULL;

	g_return_if_fail (netinfo != NULL);
	g_return_if_fail (netinfo->command_line != NULL);

	if (g_spawn_async_with_pipes (dir, netinfo->command_line, NULL,
				      G_SPAWN_FILE_AND_ARGV_ZERO |
				      G_SPAWN_DO_NOT_REAP_CHILD, NULL,
				      NULL, &child_pid, NULL, &pout,
				      NULL,
				      &err)) {

		netinfo->child_pid = child_pid;
		netinfo->pipe_out = pout;
		fcntl (pout, F_SETFL, O_NONBLOCK);
		fcntl (pout, F_SETFL, O_NONBLOCK);
		netinfo->command_output = NULL;

		g_child_watch_add (child_pid, netinfo_reap_child, netinfo);

		g_get_charset(&charset);
		channel = g_io_channel_unix_new (pout);
		status = g_io_channel_set_encoding(channel,
						   charset,
						   &err);
		if (G_IO_STATUS_NORMAL == status) {
			g_io_add_watch (channel,
					G_IO_IN | G_IO_HUP |
					G_IO_ERR | G_IO_NVAL,
					netinfo_io_text_buffer_dialog, netinfo);
			g_io_channel_unref (channel);
		} else {
			g_warning ("Error: %s\n", err->message);
			g_error_free (err);
		}
	} else {
		gint len = strlen (err->message);

		if (netinfo->process_line != NULL) {
			(netinfo->process_line) ((gpointer) netinfo,
						 err->message, len, NULL);
		}
		netinfo_toggle_state (netinfo, ACTIVE, NULL);

		g_warning ("Error: %s\n", err->message);
		g_error_free (err);
	}

	g_free (dir);
}
Ejemplo n.º 19
0
static gboolean recode_get_charset(const char **charset)
{
	*charset = settings_get_str("term_charset");
	if (**charset)
		/* we use the same test as in src/fe-text/term.c:123 */
		return (g_strcasecmp(*charset, "utf-8") == 0);

	return g_get_charset(charset);
}
Ejemplo n.º 20
0
static void GtkErrorLog (const char *format, ...)
{
	GtkWidget *dialog, *label;
	va_list args;
	char buf[256];

	if (dialog_connecting != NULL) {
		gtk_widget_destroy (dialog_connecting);
		dialog_connecting = NULL;
	}

	va_start (args, format);
	vsnprintf (buf, 255, format, args);
	va_end (args);

	if (g_utf8_validate (buf, strlen (buf), NULL)) {
		label = gtk_label_new (buf);
	} else {
		const gchar *charset;
		gchar       *utf8;

		(void) g_get_charset (&charset);
		utf8 = g_convert_with_fallback (buf, strlen (buf), "UTF-8",
		                                charset, NULL, NULL, NULL, NULL);

		if (utf8) {
			label = gtk_label_new (utf8);
			g_free (utf8);
		} else {
			label = gtk_label_new (buf);
			g_warning ("Message Output is not in UTF-8"
			           "nor in locale charset.\n");
		}
	}

	dialog = gtk_dialog_new_with_buttons ("Error",
	                                       NULL,
	                                       GTK_DIALOG_DESTROY_WITH_PARENT,
	                                       GTK_STOCK_OK,
	                                       GTK_RESPONSE_ACCEPT,
	                                       NULL);
	label = gtk_label_new (buf);
	gtk_widget_show (label);

	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
	                   label);
	gtk_widget_show (dialog);

	switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
	case GTK_RESPONSE_ACCEPT:
		break;
	default:
		break;
	}
	gtk_widget_destroy (dialog);
}
Ejemplo n.º 21
0
static char const *
get_locale_encoding_name(GOCharmapSel *cs)
{
    char const *locale_encoding;
    char const *name;

    g_get_charset(&locale_encoding);
    name = go_charmap_sel_get_encoding_name(cs, locale_encoding);
    return name ? name : locale_encoding;
}
Ejemplo n.º 22
0
static const gchar *GetLocaleCodeset(void)
{
#ifdef HAVE_GLIB2
  const gchar *codeset;

  g_get_charset(&codeset);
  return FixedCodeset(codeset);
#else
  return "ISO-8859-1";
#endif
}
Ejemplo n.º 23
0
gboolean
mu_util_locale_is_utf8 (void)
{
	const gchar *dummy;
	static int is_utf8 = -1;

	if (G_UNLIKELY(is_utf8 == -1))
	    	is_utf8 = g_get_charset(&dummy) ? 1 : 0;

	return is_utf8 ? TRUE : FALSE;
}
Ejemplo n.º 24
0
static const char *
_fr_process_get_charset (FrProcess *process)
{
	const char *charset = NULL;

	if (process->priv->current_charset >= 0)
		charset = try_charsets[process->priv->current_charset];
	else if (g_get_charset (&charset))
		charset = NULL;

	return charset;
}
Ejemplo n.º 25
0
GstTagList *
gst_rm_utils_read_tags (const guint8 * data, guint datalen,
    GstRmUtilsStringReadFunc read_string_func)
{
  const gchar *gst_tags[] = { GST_TAG_TITLE, GST_TAG_ARTIST,
    GST_TAG_COPYRIGHT, GST_TAG_COMMENT
  };
  GstTagList *tags;
  guint i;

  g_assert (read_string_func != NULL);

  GST_DEBUG ("File Content : (CONT) len = %d", datalen);

  tags = gst_tag_list_new ();

  for (i = 0; i < G_N_ELEMENTS (gst_tags); ++i) {
    gchar *str = NULL;
    guint total_length = 0;

    str = read_string_func (data, datalen, &total_length);
    data += total_length;
    datalen -= total_length;

    if (str != NULL && !g_utf8_validate (str, -1, NULL)) {
      const gchar *encoding;
      gchar *tmp;

      encoding = g_getenv ("GST_TAG_ENCODING");
      if (encoding == NULL || *encoding == '\0') {
        if (g_get_charset (&encoding))
          encoding = "ISO-8859-15";
      }
      GST_DEBUG ("converting tag from %s to UTF-8", encoding);
      tmp = g_convert_with_fallback (str, -1, "UTF-8", encoding, "*",
          NULL, NULL, NULL);
      g_free (str);
      str = tmp;
    }

    GST_DEBUG ("%s = %s", gst_tags[i], GST_STR_NULL (str));
    if (str != NULL && *str != '\0') {
      gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, gst_tags[i], str, NULL);
    }
    g_free (str);
  }

  if (gst_structure_n_fields ((GstStructure *) tags) > 0)
    return tags;

  gst_tag_list_free (tags);
  return NULL;
}
Ejemplo n.º 26
0
static gchar *
get_string_from_guessed_encoding (const gchar *str,
                                  gsize        str_len,
                                  gsize       *utf8_len)
{
	const gchar *current = NULL;

	/* If we have embedded NULs try UTF-16 directly */
	if (memchr (str, '\0', str_len))
		current = "UTF-16";
	/* If locale charset is UTF-8, try with windows-1252.
	 * NOTE: g_get_charset() returns TRUE if locale charset is UTF-8 */
	else if (g_get_charset (&current))
		current = "windows-1252";

	while (current) {
		gchar *utf8_str;
		gsize bytes_read = 0;
		gsize bytes_written = 0;

		utf8_str = g_convert (str,
		                      str_len,
		                      "UTF-8",
		                      current,
		                      &bytes_read,
		                      &bytes_written,
		                      NULL);
		if (utf8_str &&
		    str_len == bytes_read) {
			g_debug ("Converted %" G_GSIZE_FORMAT " bytes in '%s' codeset "
			         "to %" G_GSIZE_FORMAT " bytes in UTF-8",
			         bytes_read,
			         current,
			         bytes_written);
			*utf8_len = bytes_written;
			return utf8_str;
		}
		g_free (utf8_str);

		g_debug ("Text not in '%s' encoding", current);

		if (!strcmp (current, "windows-1252") ||
		    !strcmp (current, "UTF-16"))
			/* If we tried windows-1252 or UTF-16, don't try anything else */
			current = NULL;
		else
			/* If we tried a locale encoding and didn't work, retry with
			 * windows-1252 */
			current = "windows-1252";
	}

	return NULL;
}
Ejemplo n.º 27
0
bool
log_init(bool verbose, bool use_stdout, GError **error_r)
{
	const struct config_param *param;

	g_get_charset(&log_charset);

	if (verbose)
		log_threshold = G_LOG_LEVEL_DEBUG;
	else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL)
		log_threshold = parse_log_level(param->value, param->line);

	if (use_stdout) {
		log_init_stdout();
		return true;
	} else {
		param = config_get_param(CONF_LOG_FILE);
		if (param == NULL) {
#ifdef HAVE_SYSLOG
			/* no configuration: default to syslog (if
			   available) */
			log_init_syslog();
			return true;
#else
			g_set_error(error_r, log_quark(), 0,
				    "config parameter \"%s\" not found",
				    CONF_LOG_FILE);
			return false;
#endif
#ifdef HAVE_SYSLOG
		} else if (strcmp(param->value, "syslog") == 0) {
			log_init_syslog();
			return true;
#endif
		} else {
			GError *error = NULL;
			char *path = config_dup_path(CONF_LOG_FILE, &error);
			if (path == NULL) {
				assert(error != NULL);
				g_propagate_error(error_r, error);
				return false;
			}

			bool success = log_init_file(path, param->line,
						     error_r);
			g_free(path);
			return success;
		}
	}
}
Ejemplo n.º 28
0
/* {{{ proto array Glib::getCharset()
	   Obtains the character set for the current locale.
	   Returns an array, the first element of which is a boolean indicating if the
	   current charset is UTF-8. The remaining element is the charset.
	   */
PHP_METHOD(Glib, getCharset)
{
	gboolean status;
	const gchar *charset;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

	status = g_get_charset(&charset);
	array_init(return_value);
	add_next_index_bool(return_value, status);
	add_next_index_string(return_value, (char *)charset, 1);
}
Ejemplo n.º 29
0
const gchar*
get_codeset(void)
{
    const char *codeset = NULL;
    gboolean ret;
    ret = g_get_charset(&codeset);
    if(!ret && codeset == NULL){
        codeset = setlocale(LC_CTYPE, NULL);
        if (codeset != NULL) {
            codeset = strchr(codeset, '.');
            if (codeset != NULL) ++codeset;
        }
    }
    return codeset;
}
const char *
terminal_encoding_get_charset (TerminalEncoding *encoding)
{
  g_return_val_if_fail (encoding != NULL, NULL);

  if (strcmp (encoding->id, "current") == 0)
    {
      const char *charset;

      g_get_charset (&charset);
      return charset;
    }

  return encoding->id;
}