Ejemplo n.º 1
0
static char *
readutf8line (const char *prompt)
{
  char *p = readline (prompt);

  return locale_to_utf8 (p);
}
Ejemplo n.º 2
0
XCTRL_API void set_window_title(Display *disp, Window win, const char *title, char mode) {
  char *title_utf8;
  char *title_local;
  Atom utf8_atom = GetUTF8Atom();
  if (envir_utf8) {
    title_utf8 = strdup(title);
    title_local = NULL;
  } else {
    title_utf8 = locale_to_utf8(title);
    if (!title_utf8) { title_utf8 = strdup(title); }
    title_local = strdup(title);
  }
  if (mode == 'T' || mode == 'N') {
    if (title_local) {
      replace_prop(disp, win, XA_WM_NAME, XA_STRING,title_local);
    } else {
      XDeleteProperty(disp, win, XA_WM_NAME);
    }
    replace_prop(disp, win, XInternAtom(disp,"_NET_WM_NAME",False), utf8_atom, title_utf8);
  }
  if (mode == 'T' || mode == 'I') {
    if (title_local) {
      replace_prop(disp, win, XA_WM_ICON_NAME, XA_STRING, title_local);
    } else {
      XDeleteProperty(disp, win, XA_WM_ICON_NAME);
    }
    replace_prop(disp, win, XInternAtom(disp, "_NET_WM_ICON_NAME", False), utf8_atom, title_utf8);
  }
  sfree(title_utf8);
  sfree(title_local);
}
Ejemplo n.º 3
0
char *
replace_locale_to_utf8(char *src)
{
#ifdef ENABLE_LOCALE
	assert(src != NULL);

	if (noconvert)
		return src;

	return locale_to_utf8(src);
#else
	return src;
#endif
}
// http://stackoverflow.com/questions/3006229/get-a-text-from-the-error-code-returns-from-the-getlasterror-function
// The caller is responsible to free the returned message.
char* formatErrorMessage()
{
    DWORD error_code = GetLastError();
    if (error_code == 0) {
        return g_strdup("no error");
    }
    char buf[256] = {0};
    FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
                   NULL,
                   error_code,
                   MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                   buf,
                   sizeof(buf) - 1,
                   NULL);
    return locale_to_utf8(buf);
}
Ejemplo n.º 5
0
XCTRL_API char *get_window_class (Display *disp, Window win)
{
  char *class_utf8;
  char *wm_class;
  ulong size;
  wm_class = get_prop(disp, win, XA_STRING, "WM_CLASS", &size);
  if (wm_class) {
    char *p_0 = strchr(wm_class, '\0');
    if (wm_class + size - 1 > p_0) { *(p_0) = '.'; }
    class_utf8 = locale_to_utf8(wm_class);
  } else {
    class_utf8 = NULL;
  }
  sfree(wm_class);
  return class_utf8;
}
Ejemplo n.º 6
0
XCTRL_API char *get_window_title (Display *disp, Window win)
{
  char *wm_name = get_prop(disp, win, GetUTF8Atom(), "_NET_WM_NAME", NULL);
  if (wm_name) {
    return wm_name;
  } else {
    char *title_utf8 = NULL;
    wm_name = get_prop(disp, win, XA_STRING, "WM_NAME", NULL);
    if (wm_name) {
      title_utf8 = locale_to_utf8(wm_name);
      free(wm_name);
    } else {
      title_utf8 = NULL;
    }
    return title_utf8;
  }
}
Ejemplo n.º 7
0
unsigned
locale_width(const char *p)
{
#if defined(ENABLE_LOCALE) && defined(ENABLE_MULTIBYTE)
	char *utf8;
	unsigned width;

	if (noconvert)
		return utf8_width(p);

	utf8 = locale_to_utf8(p);
	width = utf8_width(utf8);
	g_free(utf8);

	return width;
#else
	return strlen(p);
#endif
}
Ejemplo n.º 8
0
static char *get_output_str(char *str, Bool is_utf8) {
  char *out;
  if (!str) { return NULL; }
  if (envir_utf8) {
    if (is_utf8) {
      out = strdup(str);
    } else {
      out=locale_to_utf8(str);
      if (!out) { out = strdup(str); }
    }
  } else {
    if (is_utf8) {
      out = utf8_to_locale(str);
      if (!out) { out = strdup(str); }
    } else {
      out = strdup(str);
    }
  }
  return out;
}
Ejemplo n.º 9
0
Archivo: sdcv.cpp Proyecto: 7799/sdcv
int main(int argc, char *argv[])
{
	setlocale(LC_ALL, "");
#if ENABLE_NLS
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);
#endif	 
	int optc;
	bool h = false, v = false, show_list_dicts=false, 
		use_book_name=false, non_interactive=false, 
		utf8_output=false, utf8_input=false;
	strlist_t enable_list;
	string data_dir;
	int option_index = 0;
	while ((optc = getopt_long (argc, argv, "hvu:ln", longopts, 
				    &option_index))!=-1)
		switch (optc){
		case 0:
			utf8_output=true;
			break;
		case 1:   
			utf8_input=true;
			break;
		case 2:
			data_dir=optarg;
			break;
		case 'v':
			v = true;
			break;
		case 'h':
			h = true;
			break;
		case 'l':
			show_list_dicts=true;
			break;
		case 'u':
			use_book_name=true;
			enable_list.push_back(locale_to_utf8(optarg));
			break;
		case 'n':
			non_interactive=true;
			break;
		case '?':
			fprintf(stderr, 
				_("Unknown option.\nTry '%s --help' for more information.\n"), 
				argv[0]);
			return EXIT_FAILURE;
		}
  
	if (h) {
		printf("sdcv - console version of StarDict.\n");
		printf(_("Usage: %s [OPTIONS] words\n"), argv[0]);
		printf(_("-h, --help               display this help and exit\n"));
		printf(_("-v, --version            display version information and exit\n"));
		printf(_("-l, --list-dicts         display list of available dictionaries and exit\n"));
		printf(_("-u, --use-dict bookname  for search use only dictionary with this bookname\n"));
		printf(_("-n, --non-interactive    for use in scripts\n"));
		printf(_("--utf8-output            output must be in utf8\n"));
		printf(_("--utf8-input             input of sdcv in utf8\n"));
		printf(_("--data-dir path/to/dir   use this directory as path to stardict data directory\n"));

		return EXIT_SUCCESS;
	}

	if (v) {
		printf(_("Console version of Stardict, version %s\n"), gVersion);
		return EXIT_SUCCESS;
	}

	const gchar *stardict_data_dir=g_getenv("STARDICT_DATA_DIR");
	if (data_dir.empty()) {
		if (stardict_data_dir)
			data_dir=stardict_data_dir;
		else
			data_dir="/usr/share/stardict/dic";
	}



	strlist_t dicts_dir_list;

	dicts_dir_list.push_back(std::string(g_get_home_dir())+G_DIR_SEPARATOR+
				 ".stardict"+G_DIR_SEPARATOR+"dic");
	dicts_dir_list.push_back(data_dir);   

	if (show_list_dicts) {
		printf(_("Dictionary's name   Word count\n"));
		PrintDictInfo print_dict_info;
		strlist_t order_list, disable_list;
		for_each_file(dicts_dir_list, ".ifo",  order_list, 
			      disable_list, print_dict_info); 
    
		return EXIT_SUCCESS;
	}

	strlist_t disable_list;
	//DictInfoList  dict_info_list;
  
	if (use_book_name) {
		strlist_t empty_list;
		CreateDisableList create_disable_list(enable_list, disable_list);
		for_each_file(dicts_dir_list, ".ifo", empty_list, 
			      empty_list, create_disable_list);
	}

    
	string conf_dir = string(g_get_home_dir())+G_DIR_SEPARATOR+".stardict";
	if (g_mkdir(conf_dir.c_str(), S_IRWXU)==-1 && errno!=EEXIST)
		fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno));

  
	Library lib(utf8_input, utf8_output);
	strlist_t empty_list;
	lib.load(dicts_dir_list, empty_list, disable_list);


	std::auto_ptr<read_line> io(create_readline_object());
	if (optind < argc) {
		for(int i=optind; i<argc; ++i)
			if (!lib.process_phrase(argv[i], *io, non_interactive))
				return EXIT_FAILURE;
	} else if (!non_interactive) {

		string phrase;
		while (io->read(_("Enter word or phrase: "), phrase)) {
			if (!lib.process_phrase(phrase.c_str(), *io))
				return EXIT_FAILURE;
			phrase.clear();
		}

		putchar('\n');
	} else
		fprintf(stderr, _("There are no words/phrases to translate.\n"));
	
    
	return EXIT_SUCCESS;
}
Ejemplo n.º 10
0
static void
handle_option(int c, const char *arg)
{
	switch (c) {
	case '?': /* --help */
		display_help();
		exit(EXIT_SUCCESS);
	case 'V': /* --version */
		puts(PACKAGE " version: " VERSION "\n"
		     "build options:"
#ifdef NCMPC_MINI
		     " mini"
#endif
#ifndef NDEBUG
		     " debug"
#endif
#ifdef ENABLE_MULTIBYTE
		     " multibyte"
#endif
#ifdef HAVE_CURSES_ENHANCED
		     " wide"
#endif
#ifdef ENABLE_LOCALE
		     " locale"
#endif
#ifdef ENABLE_NLS
		     " nls"
#endif
#ifdef ENABLE_COLORS
		     " colors"
#else
		     " no-colors"
#endif
#ifdef ENABLE_LIRC
		     " lirc"
#endif
#ifdef HAVE_GETMOUSE
		     " getmouse"
#endif
#ifdef ENABLE_ARTIST_SCREEN
		     " artist-screen"
#endif
#ifdef ENABLE_HELP_SCREEN
		     " help-screen"
#endif
#ifdef ENABLE_SEARCH_SCREEN
		     " search-screen"
#endif
#ifdef ENABLE_SONG_SCREEN
		     " song-screen"
#endif
#ifdef ENABLE_KEYDEF_SCREEN
		     " key-screen"
#endif
#ifdef ENABLE_LYRICS_SCREEN
		     " lyrics-screen"
#endif
#ifdef ENABLE_OUTPUTS_SCREEN
		     " outputs-screen"
#endif

		     "\n");
#ifndef NCMPC_MINI
		{
			char *user_conf = build_user_conf_filename();
			char *system_conf = build_system_conf_filename();

			printf("configuration files:\n %s\n %s\n\n",
			       user_conf, system_conf);

			g_free(user_conf);
			g_free(system_conf);
		}
		if (strcmp("translator-credits", _("translator-credits")) != 0)
			/* To translators: these credits are shown
			   when ncmpc is started with "--version" */
			printf("\n%s\n", _("translator-credits"));
#endif
		exit(EXIT_SUCCESS);
	case 'c': /* --colors */
#ifdef ENABLE_COLORS
		options.enable_colors = true;
#endif
		break;
	case 'C': /* --no-colors */
#ifdef ENABLE_COLORS
		options.enable_colors = false;
#endif
		break;
	case 'm': /* --mouse */
#ifdef HAVE_GETMOUSE
		options.enable_mouse = true;
#endif
		break;
	case 'M': /* --no-mouse */
#ifdef HAVE_GETMOUSE
		options.enable_mouse = false;
#endif
		break;
	case 'e': /* --exit */
		/* deprecated */
		break;
	case 'p': /* --port */
		options.port = atoi(arg);
		break;
	case 'h': /* --host */
		g_free(options.host);
		options.host = g_strdup(arg);
		break;
	case 'P': /* --password */
		g_free(options.password);
		options.password = locale_to_utf8(arg);
		break;
	case 'f': /* --config */
		g_free(options.config_file);
		options.config_file = g_strdup(arg);
		break;
	case 'k': /* --key-file */
		g_free(options.key_file);
		options.key_file = g_strdup(arg);
		break;
#if !defined(NDEBUG) && !defined(NCMPC_MINI)
	case 'K': /* --dump-keys */
		read_configuration();
		write_key_bindings(stdout, KEYDEF_WRITE_ALL | KEYDEF_COMMENT_ALL);
		exit(EXIT_SUCCESS);
		break;
#endif
	default:
		fprintf(stderr,"Unknown Option %c = %s\n", c, arg);
		break;
	}
}