Beispiel #1
0
/**
 * shell_global_format_time_relative_pretty:
 * @global:
 * @delta: Time in seconds since the current time
 * @text: (out): Relative human-consumption-only time string
 * @next_update: (out): Time in seconds until we should redisplay the time
 *
 * Format a time value for human consumption only.  The passed time
 * value is a delta in terms of seconds from the current time.
 * This function needs to be in C because of its use of ngettext() which
 * is not accessible from JavaScript.
 */
void
shell_global_format_time_relative_pretty (ShellGlobal *global,
                                          guint        delta,
                                          char       **text,
                                          guint       *next_update)
{
#define MINUTE (60)
#define HOUR (MINUTE*60)
#define DAY (HOUR*24)
#define WEEK (DAY*7)
  if (delta < MINUTE) {
    *text = g_strdup (_("Less than a minute ago"));
    *next_update = MINUTE - delta;
   } else if (delta < HOUR) {
     *text = g_strdup_printf (dngettext (GETTEXT_PACKAGE,
                                         "%d minute ago", "%d minutes ago",
                                         delta / MINUTE), delta / MINUTE);
     *next_update = MINUTE - (delta % MINUTE);
   } else if (delta < DAY) {
     *text = g_strdup_printf (dngettext (GETTEXT_PACKAGE,
                                         "%d hour ago", "%d hours ago",
                                         delta / HOUR), delta / HOUR);
     *next_update = HOUR - (delta % HOUR);
   } else if (delta < WEEK) {
     *text = g_strdup_printf (dngettext (GETTEXT_PACKAGE,
                                         "%d day ago", "%d days ago",
                                         delta / DAY), delta / DAY);
     *next_update = DAY - (delta % DAY);
   } else {
     *text = g_strdup_printf (dngettext (GETTEXT_PACKAGE,
                                         "%d week ago", "%d weeks ago",
                                         delta / WEEK), delta / WEEK);
     *next_update = WEEK - (delta % WEEK);
   }
}
static void list_get_value (void * user, int row, int column, GValue * value)
{
    g_return_if_fail (items && row >= 0 && row < index_count (items));

    Item * item = index_get (items, row);
    char * string = NULL;

    switch (item->field)
    {
        int albums;
        char scratch[128];

    case TITLE:
        string = g_strdup_printf (_("%s\n on %s by %s"), item->name,
         item->parent->name, item->parent->parent->name);
        break;

    case ARTIST:
        albums = g_hash_table_size (item->children);
        snprintf (scratch, sizeof scratch, dngettext (PACKAGE, "%d album",
         "%d albums", albums), albums);
        string = g_strdup_printf (dngettext (PACKAGE, "%s\n %s, %d song",
         "%s\n %s, %d songs", item->matches->len), item->name, scratch,
         item->matches->len);
        break;

    case ALBUM:
        string = g_strdup_printf (dngettext (PACKAGE, "%s\n %d song by %s",
         "%s\n %d songs by %s", item->matches->len), item->name,
         item->matches->len, item->parent->name);
        break;
    }

    g_value_take_string (value, string);
}
Beispiel #3
0
gchar*
procman::format_size(guint64 size, guint64 max_size, bool want_bits)
{
	enum {
		K_INDEX,
		M_INDEX,
		G_INDEX
	};

	struct Format {
		guint64 factor;
		const char* string;
	};

	const Format all_formats[2][3] = {
		{ { 1UL << 10,	N_("%.1f KiB") },
		  { 1UL << 20,	N_("%.1f MiB") },
		  { 1UL << 30,	N_("%.1f GiB") } },
		{ { 1000,	N_("%.1f kbit") },
		  { 1000000,	N_("%.1f Mbit") },
		  { 1000000000,	N_("%.1f Gbit") } }
	};

	const Format (&formats)[3] = all_formats[want_bits ? 1 : 0];

	if (want_bits) {
	  size *= 8;
	  max_size *= 8;
	}

	if (max_size == 0)
		max_size = size;

	if (max_size < formats[K_INDEX].factor) {
		const char *format = (want_bits
			  ? dngettext(GETTEXT_PACKAGE, "%u bit", "%u bits", (guint) size)
			  : dngettext(GETTEXT_PACKAGE, "%u byte", "%u bytes",(guint) size));
		return g_strdup_printf (format, (guint) size);
	} else {
		guint64 factor;
		const char* format = NULL;

		if (max_size < formats[M_INDEX].factor) {
		  factor = formats[K_INDEX].factor;
		  format = formats[K_INDEX].string;
		} else if (max_size < formats[G_INDEX].factor) {
		  factor = formats[M_INDEX].factor;
		  format = formats[M_INDEX].string;
		} else {
		  factor = formats[G_INDEX].factor;
		  format = formats[G_INDEX].string;
		}

		return g_strdup_printf(_(format), size / (double)factor);
	}
}
Beispiel #4
0
static void
timezone_createconv_cb(PurpleConversation * conv, void *data)
{
    const char *name;
    PurpleBuddy *buddy;
    struct tm tm;
    const char *timezone;
    double diff;
    int ret;

    if (purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_IM)
        return;

    name = purple_conversation_get_name(conv);
    buddy = purple_find_buddy(purple_conversation_get_account(conv), name);
    if (!buddy)
        return;

    timezone = buddy_get_timezone((PurpleBlistNode *) buddy, TRUE, NULL);

    if (!timezone)
        return;

    ret = timezone_get_time(timezone, &tm, &diff, NULL);

    if (ret == 0)
    {
        const char *text = purple_time_format(&tm);

        char *str;
	if (diff < 0)
	{
            diff = 0 - diff;
            str = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
                                            "Remote Local Time: %s (%.4g hour behind)",
                                            "Remote Local Time: %s (%.4g hours behind)", diff),
                                  text, diff);
	}
	else
	{
            str = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
                                            "Remote Local Time: %s (%.4g hour ahead)",
                                            "Remote Local Time: %s (%.4g hours ahead)", diff),
                                  text, diff);
	}

        purple_conversation_write(conv, PLUGIN_STATIC_NAME, str, PURPLE_MESSAGE_SYSTEM, time(NULL));

        g_free(str);
    }
}
Beispiel #5
0
const char *
vips__ngettext( const char *msgid, const char *plural, unsigned long int n )
{
	vips_check_init();

	return( dngettext( GETTEXT_PACKAGE, msgid, plural, n ) );
}
Beispiel #6
0
static SeedValue
seed_gettext_dngettext (SeedContext ctx,
                        SeedObject function,
                        SeedObject this_object,
                        gsize argument_count,
                        const SeedValue args[],
                        SeedException * exception)
{
	gchar * domainname, * msgid, * msgid_plural;
	guint n;
	SeedValue ret;

	CHECK_ARG_COUNT("gettext.dngettext", 4);

	domainname = seed_value_to_string (ctx, args[0], exception);
	msgid = seed_value_to_string (ctx, args[1], exception);
	msgid_plural = seed_value_to_string (ctx, args[2], exception);
	n = seed_value_to_uint (ctx, args[3], exception);

	ret = seed_value_from_string (ctx, dngettext(domainname, msgid, msgid_plural, n), exception);
	g_free(domainname);
	g_free(msgid);
	g_free(msgid_plural);

	return ret;
}
Beispiel #7
0
static JSBool
gjs_dngettext(JSContext *context,
              unsigned   argc,
              jsval     *vp)
{
    jsval *argv = JS_ARGV(context, vp);
    char *domain;
    char *msgid1;
    char *msgid2;
    guint n;
    const char *translated;
    JSBool result;
    jsval retval;

    if (!gjs_parse_args (context, "dngettext", "zssu", argc, argv,
                         "domain", &domain, "msgid1", &msgid1,
                         "msgid2", &msgid2, "n", &n))
      return JS_FALSE;

    translated = dngettext(domain, msgid1, msgid2, n);
    g_free (domain);

    result = gjs_string_from_utf8(context, translated, -1, &retval);
    if (result)
        JS_SET_RVAL(context, vp, retval);
    g_free (msgid1);
    g_free (msgid2);
    return result;
}
Beispiel #8
0
//
// Handler
//
INT_32 FnGetText::Handler(CDT            * aArguments,
		          const UINT_32    iArgNum,
		          CDT            & oCDTRetVal,
		          Logger         & oLogger)
{
	if (iArgNum == 1)
	{
		oCDTRetVal = gettext(aArguments[0].GetString().c_str());
		return 0;
	}
	else if (iArgNum == 2)
	{
		oCDTRetVal = dgettext(aArguments[1].GetString().c_str(), aArguments[0].GetString().c_str());
		return 0;
	}
	else if (iArgNum == 3)
	{
		oCDTRetVal = ngettext(aArguments[2].GetString().c_str(), aArguments[1].GetString().c_str(), INT_32(aArguments[0].GetInt()));
		return 0;
	}
	else if (iArgNum == 4)
	{
		oCDTRetVal = dngettext(aArguments[3].GetString().c_str(), aArguments[2].GetString().c_str(), aArguments[1].GetString().c_str(), INT_32(aArguments[0].GetInt()));
		return 0;
	}

	oLogger.Emerg("Usage: GETTEXT(message), GETTEXT(domain, message) or GETTEXT(message, message-plural, n)");
	return -1;
}
Beispiel #9
0
/**
 * fm_delete_files
 * @parent: a window to place progress dialog over it
 * @files: list of files to delete
 *
 * Wipes out files opening progress dialog if that operation takes some time.
 *
 * Before 0.1.15 this call had different arguments.
 *
 * Since: 0.1.0
 */
void fm_delete_files(GtkWindow* parent, FmPathList* files)
{
    char *msg, *name;
    int len;

    if (fm_config->confirm_del)
    {
        len = fm_path_list_get_length(files);
        if (len == 1)
        {
            name = fm_path_display_basename(fm_path_list_peek_head(files));
            msg = g_strdup_printf(_("Do you want to delete the file '%s'?"), name);
            g_free(name);
        }
        else
            msg = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
                                            "Do you want to delete the %d selected file?",
                                            "Do you want to delete the %d selected files?",
                                            (gulong)len), len);
        if (!fm_yes_no(parent, NULL, msg, TRUE))
        {
            g_free(msg);
            return;
        }
        g_free(msg);
    }
    fm_delete_files_internal(parent, files);
}
Beispiel #10
0
/**
 * fm_trash_files
 * @parent: a window to place progress dialog over it
 * @files: list of files to move to trash
 *
 * Removes files into trash can opening progress dialog if that operation
 * takes some time.
 *
 * Before 0.1.15 this call had different arguments.
 *
 * Since: 0.1.0
 */
void fm_trash_files(GtkWindow* parent, FmPathList* files)
{
    FmFileOpsJob *job;
    char *msg, *name;
    int len;

    if (fm_config->confirm_trash)
    {
        len = fm_path_list_get_length(files);
        if (len == 1)
        {
            name = fm_path_display_basename(fm_path_list_peek_head(files));
            msg = g_strdup_printf(_("Do you want to move the file '%s' to trash can?"), name);
            g_free(name);
        }
        else
            msg = g_strdup_printf(dngettext(GETTEXT_PACKAGE,
                                            "Do you want to move the %d selected file to trash can?",
                                            "Do you want to move the %d selected files to trash can?",
                                            (gulong)len), len);
        if (!fm_yes_no(parent, NULL, msg, TRUE))
        {
            g_free(msg);
            return;
        }
        g_free(msg);
    }
    job = fm_file_ops_job_new(FM_FILE_OP_TRASH, files);
    fm_file_ops_job_run_with_progress(parent, job); /* it eats reference! */
}
Beispiel #11
0
static GList *
deja_dup_nautilus_extension_get_file_items(NautilusMenuProvider *provider,
                                           GtkWidget *window,
                                           GList *files)
{
  NautilusMenuItem *item;
  guint length;
  GList *file_copies;
  gchar *path;

  if (files == NULL)
    return NULL;

  path = g_find_program_in_path("deja-dup");
  if (!path)
    return NULL;
  g_free(path);

  gboolean is_one_included = FALSE;
  GList *p;
  for (p = files; p; p = p->next) {
    GFile *gfile = nautilus_file_info_get_location((NautilusFileInfo *)p->data);
    if (is_dir_included(gfile))
      is_one_included = TRUE;
  }
  if (!is_one_included)
    return NULL;

  length = g_list_length(files);
  item = nautilus_menu_item_new("DejaDupNautilusExtension::restore_item",
                                dngettext(GETTEXT_PACKAGE,
                                          "Revert to Previous Version…",
                                          "Revert to Previous Versions…",
                                          length),
                                dngettext(GETTEXT_PACKAGE,
                                          "Restore file from backup",
                                          "Restore files from backup",
                                          length),
                                "deja-dup");

  g_signal_connect(item, "activate", G_CALLBACK(restore_files_callback), NULL);
  g_object_set_data_full (G_OBJECT(item), "deja_dup_extension_files", 
                          nautilus_file_info_list_copy(files),
                          (GDestroyNotify)nautilus_file_info_list_free);

  return g_list_append(NULL, item);
}
Beispiel #12
0
static uim_lisp
intl_dngettext(uim_lisp domainname, uim_lisp msgid1, uim_lisp msgid2, uim_lisp n)
{
    return MAKE_STR(dngettext(REFER_C_STR(domainname),
                              REFER_C_STR(msgid1),
                              REFER_C_STR(msgid2),
                              C_INT(n)));
}
Beispiel #13
0
QString u2dTr(const char* singular, const char* plural, int n, const char* domain)
{
    QString text = QString::fromUtf8(dngettext(domain, singular, plural, n));
    // Note: if `text` is "%%n" (meaning the string on screen should be "%n"
    // literally), this will fail. I think we don't care for now.
    text.replace("%n", QString::number(n));
    return text;
}
Beispiel #14
0
static int lua_dngettext(lua_State*L)
{
  const char* domainname = luaL_checkstring(L,1);
  const char* msgid = luaL_checkstring(L,2);
  const char* msgid_plural = luaL_checkstring(L,3);
  int n = luaL_checkinteger(L,4);
  lua_pushstring(L,dngettext(domainname,msgid,msgid_plural,n));
  return 1;
}
Beispiel #15
0
char *G_ngettext(const char *package, const char *msgids, const char *msgidp, unsigned long int n)
{
#if defined(HAVE_LIBINTL_H) && defined(USE_NLS)
    G_init_locale();

    return dngettext(package, msgids, msgidp, n);
#else
    return n == 1 ? (char *)msgids : (char *)msgidp;
#endif
}
Beispiel #16
0
/**
 * g_dngettext:
 * @domain: (allow-none): the translation domain to use, or %NULL to use
 *   the domain set with textdomain()
 * @msgid: message to translate
 * @msgid_plural: plural form of the message
 * @n: the quantity for which translation is needed
 *
 * This function is a wrapper of dngettext() which does not translate
 * the message if the default domain as set with textdomain() has no
 * translations for the current locale.
 *
 * See g_dgettext() for details of how this differs from dngettext()
 * proper.
 *
 * Returns: The translated string
 *
 * Since: 2.18
 */
const gchar *
g_dngettext (const gchar *domain,
             const gchar *msgid,
             const gchar *msgid_plural,
             gulong       n)
{
  if (domain && G_UNLIKELY (!_g_dgettext_should_translate ()))
    return n == 1 ? msgid : msgid_plural;

  return dngettext (domain, msgid, msgid_plural, n);
}
Beispiel #17
0
Variant HHVM_FUNCTION(dngettext, const String& domain, const String& msgid1,
                      const String& msgid2, int64_t count) {
  CHECK_DOMAIN_LENGTH();
  CHECK_GETTEXT_LENGTH("msgid1", msgid1.length());
  CHECK_GETTEXT_LENGTH("msgid2", msgid2.length());

  auto msgstr = dngettext(domain.data(), msgid1.data(), msgid2.data(), count);
  if (!msgstr) {
    return init_null();
  }
  return String(msgstr, CopyString);
}
Beispiel #18
0
const char* dsngettext (const char * domainname, const char *singular, const char *plural, int n)
{
	bind_textdomain_codeset(domainname, "UTF-8");
	const char *msgval = dngettext (domainname, singular, plural, n);
	if (msgval == singular) {
		msgval = std::strrchr (singular, '^');
		if (msgval == NULL)
			msgval = singular;
		else
			msgval++;
	}
	return msgval;
}
Beispiel #19
0
static void
system_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
{
    GHashTable *table;
    const char *type_s;

    if (strcmp(msg->remote_user, "Hotmail"))
    {
        pecan_warning ("unofficial message");
        return;
    }

    table = msn_message_get_hashtable_from_body(msg);

    if ((type_s = g_hash_table_lookup(table, "Type")) != NULL)
    {
        int type = atoi(type_s);
        char buf[MSN_BUF_LEN];
        int minutes;

        switch (type)
        {
            case 1:
                minutes = atoi(g_hash_table_lookup(table, "Arg1"));
                g_snprintf(buf, sizeof(buf), dngettext(PACKAGE, 
                                                       "The MSN server will shut down for maintenance "
                                                       "in %d minute. You will automatically be "
                                                       "signed out at that time.  Please finish any "
                                                       "conversations in progress.\n\nAfter the "
                                                       "maintenance has been completed, you will be "
                                                       "able to successfully sign in.",
                                                       "The MSN server will shut down for maintenance "
                                                       "in %d minutes. You will automatically be "
                                                       "signed out at that time.  Please finish any "
                                                       "conversations in progress.\n\nAfter the "
                                                       "maintenance has been completed, you will be "
                                                       "able to successfully sign in.", minutes),
                           minutes);
            default:
                break;
        }

        if (*buf != '\0')
            purple_notify_info(cmdproc->session->account->gc, NULL, buf, NULL);
    }

    g_hash_table_destroy(table);
}
Beispiel #20
0
/* same, with pluralized message */
void
PLy_exception_set_plural(PyObject *exc,
						 const char *fmt_singular, const char *fmt_plural,
						 unsigned long n,...)
{
	char		buf[1024];
	va_list		ap;

	va_start(ap, n);
	vsnprintf(buf, sizeof(buf),
			  dngettext(TEXTDOMAIN, fmt_singular, fmt_plural, n),
			  ap);
	va_end(ap);

	PyErr_SetString(exc, buf);
}
Beispiel #21
0
static int
do_test (void)
{
  const char *strs[2] = { "singular", "plural" };
  unsigned long int i;
  int res = 0;

  /* We don't want any translation here.  */
  setenv ("LANGUAGE", "C", 1);
  unsetenv ("OUTPUT_CHARSET");

  for (i = 0; i < 30; ++i)
    {
      char *tr;

      tr = ngettext (strs[0], strs[1], i);
#define TEST \
      do								      \
	if (tr != strs[i != 1])						      \
	  {								      \
	    if (strcmp (tr, strs[i != 1]) == 0)				      \
	      printf ("%lu: correct string, wrong pointer (%s)\n", i, tr);    \
	    else							      \
	      printf ("%lu: wrong result (%s)\n", i, tr);		      \
	    res = 1;							      \
	  }								      \
      while (0)
      TEST;

      tr = dngettext ("messages", strs[0], strs[1], i);
      TEST;

      tr = dcngettext ("messages", strs[0], strs[1], i, LC_MESSAGES);
      TEST;
    }

  return res;
}
Beispiel #22
0
static int intl_ctl(ErlDrvData drv_data, unsigned int command, char *buf,
                    int len, char **rbuf, int rlen)
{
    void* d = (void*)drv_data;
    char* aptr = buf;
    int   alen = len;
    char* str1;
    char* str2;
    char* str3;
    int   int1;
    int   int2;
    unsigned int uint1;

    switch(command) {
    case INTL_GETTEXT:
	/* arguments: string msgid */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(gettext(str1), rbuf, rlen);

    case INTL_NGETTEXT:
	/* arguments: string msgid, string msgid_plural, int n */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_uinteger(&aptr, &alen, &uint1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(ngettext(str1,str2,uint1), rbuf, rlen);

    case INTL_DGETTEXT:
	/* arguments: string domain, string msgid */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dgettext(str1,str2), rbuf, rlen);

    case INTL_DNGETTEXT:
	/* arguments: string domain, string msgid, 
	   string msgid_plural, integer n */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str3) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_uinteger(&aptr, &alen, &uint1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dngettext(str1,str2,str3,uint1), rbuf, rlen);
	
    case INTL_DCGETTEXT:
	/* arguments: string domain, string msgid, int category */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_integer(&aptr,&alen, &int1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if ((int1 = get_category(int1)) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dcgettext(str1,str2,int1),rbuf,rlen);

    case INTL_DCNGETTEXT:
	/* arguments: string domain, string msgid, 
	   strinf msgid_plural, unsigned n, int category */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str3) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_uinteger(&aptr,&alen, &uint1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_integer(&aptr,&alen, &int1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if ((int1 = get_category(int1)) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dcngettext(str1,str2,str3,uint1,int1),rbuf,rlen);

    case INTL_TEXTDOMAIN:
	/* arguments: string domainname */
	if (len == 0)
	    return ret_string(textdomain(NULL), rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(textdomain(str1), rbuf, rlen);

    case INTL_BINDTEXTDOMAIN:
	/* arguments: string domainname, string dirname */
	if (len == 0)
	    return ret_string(textdomain(NULL), rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(bindtextdomain(str1,str2), rbuf, rlen);

    case INTL_BIND_TEXTDOMAIN_CODESET:
	/* arguments: string domainname, string dirname */
	if (len == 0)
	    return ret_string(textdomain(NULL), rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(bind_textdomain_codeset(str1,str2), rbuf, rlen);

    case INTL_SETLOCALE:
	if (get_integer(&aptr,&alen, &int1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if ((int1 = get_category(int1)) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(setlocale(int1,str1), rbuf, rlen);
    }
    return -1;
}
Beispiel #23
0
const char* Gobby::ngettext(const char* msgid,
                            const char* msgid_plural,
                            unsigned long int n)
{
    return dngettext(GETTEXT_PACKAGE, msgid, msgid_plural, n);
}
Beispiel #24
0
char *
libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n)
{
    libpq_binddomain();
    return dngettext(PG_TEXTDOMAIN("libpq"), msgid, msgid_plural, n);
}
Beispiel #25
0
static int
last_login_failed(pam_handle_t *pamh, int announce, const char *user, time_t lltime)
{
    int retval;
    int fd;
    struct utmp ut;
    struct utmp utuser;
    int failed = 0;
    char the_time[256];
    char *date = NULL;
    char *host = NULL;
    char *line = NULL;

    if (strlen(user) > UT_NAMESIZE) {
	pam_syslog(pamh, LOG_WARNING, "username too long, output might be inaccurate");
    }

    /* obtain the failed login attempt records from btmp */
    fd = open(_PATH_BTMP, O_RDONLY);
    if (fd < 0) {
        int save_errno = errno;
	pam_syslog(pamh, LOG_ERR, "unable to open %s: %m", _PATH_BTMP);
	D(("unable to open %s file", _PATH_BTMP));
        if (save_errno == ENOENT)
	  return PAM_SUCCESS;
	else
	  return PAM_SERVICE_ERR;
    }

    while ((retval=pam_modutil_read(fd, (void *)&ut,
			 sizeof(ut))) == sizeof(ut)) {
	if (ut.ut_tv.tv_sec >= lltime && strncmp(ut.ut_user, user, UT_NAMESIZE) == 0) {
	    memcpy(&utuser, &ut, sizeof(utuser));
	    failed++;
	}
    }

    if (failed) {
	/* we want the date? */
	if (announce & LASTLOG_DATE) {
	    struct tm *tm, tm_buf;
	    time_t lf_time;

	    lf_time = utuser.ut_tv.tv_sec;
	    tm = localtime_r (&lf_time, &tm_buf);
	    strftime (the_time, sizeof (the_time),
	        /* TRANSLATORS: "strftime options for date of last login" */
		_(" %a %b %e %H:%M:%S %Z %Y"), tm);

	    date = the_time;
	}

	/* we want & have the host? */
	if ((announce & LASTLOG_HOST)
		&& (utuser.ut_host[0] != '\0')) {
	    /* TRANSLATORS: " from <host>" */
	    if (asprintf(&host, _(" from %.*s"), UT_HOSTSIZE,
		    utuser.ut_host) < 0) {
		pam_syslog(pamh, LOG_ERR, "out of memory");
		retval = PAM_BUF_ERR;
		goto cleanup;
	    }
	}

	/* we want and have the terminal? */
	if ((announce & LASTLOG_LINE)
		&& (utuser.ut_line[0] != '\0')) {
	    /* TRANSLATORS: " on <terminal>" */
	    if (asprintf(&line, _(" on %.*s"), UT_LINESIZE,
			utuser.ut_line) < 0) {
		pam_syslog(pamh, LOG_ERR, "out of memory");
		retval = PAM_BUF_ERR;
		goto cleanup;
	    }
	}

	if (line != NULL || date != NULL || host != NULL) {
	    /* TRANSLATORS: "Last failed login: <date> from <host> on <terminal>" */
	    pam_info(pamh, _("Last failed login:%s%s%s"),
			      date ? date : "",
			      host ? host : "",
			      line ? line : "");
	}

	_pam_drop(line);
#if defined HAVE_DNGETTEXT && defined ENABLE_NLS
        retval = asprintf (&line, dngettext(PACKAGE,
		"There was %d failed login attempt since the last successful login.",
		"There were %d failed login attempts since the last successful login.",
		failed),
	    failed);
#else
	if (failed == 1)
	    retval = asprintf(&line,
		_("There was %d failed login attempt since the last successful login."),
		failed);
	else
	    retval = asprintf(&line,
		/* TRANSLATORS: only used if dngettext is not supported */
		_("There were %d failed login attempts since the last successful login."),
		failed);
#endif
	if (retval >= 0)
		retval = pam_info(pamh, "%s", line);
	else {
		retval = PAM_BUF_ERR;
		line = NULL;
	}
    }

cleanup:
    free(host);
    free(line);
    close(fd);
    D(("all done with btmp"));

    return retval;
}
void draw_background(LoadGraph *g) {
	double dash[2] = { 1.0, 2.0 };
	cairo_t *cr;
	guint i;
	unsigned num_bars;
	char *caption;
	cairo_text_extents_t extents;

	num_bars = g->num_bars();
	g->graph_dely = (g->draw_height - 15) / num_bars; /* round to int to avoid AA blur */
	g->real_draw_height = g->graph_dely * num_bars;
	g->graph_delx = (g->draw_width - 2.0 - g->rmargin - g->indent) / (LoadGraph::NUM_POINTS - 3);
	g->graph_buffer_offset = (int) (1.5 * g->graph_delx) + FRAME_WIDTH ;

	g->background = gdk_pixmap_new (GDK_DRAWABLE (g->disp->window),
					g->disp->allocation.width,
					g->disp->allocation.height,
					-1);
	cr = gdk_cairo_create (g->background);
	
	// set the background colour
	GtkStyle *style = gtk_widget_get_style (ProcData::get_instance()->notebook);
	gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
	cairo_paint (cr);

	/* draw frame */
	cairo_translate (cr, FRAME_WIDTH, FRAME_WIDTH);
	
	/* Draw background rectangle */
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_rectangle (cr, g->rmargin + g->indent, 0,
			 g->draw_width - g->rmargin - g->indent, g->real_draw_height);
	cairo_fill(cr);
	
	cairo_set_line_width (cr, 1.0);
	cairo_set_dash (cr, dash, 2, 0);
	cairo_set_font_size (cr, g->fontsize);

	for (i = 0; i <= num_bars; ++i) {
		double y;

		if (i == 0)
			y = 0.5 + g->fontsize / 2.0;
		else if (i == num_bars)
			y = i * g->graph_dely + 0.5;
		else
			y = i * g->graph_dely + g->fontsize / 2.0;

		gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
		if (g->type == LOAD_GRAPH_NET) {
			// operation orders matters so it's 0 if i == num_bars
			unsigned rate = g->net.max - (i * g->net.max / num_bars);
			const std::string caption(procman::format_rate(rate, g->net.max));
			cairo_text_extents (cr, caption.c_str(), &extents);
			cairo_move_to (cr, g->indent - extents.width + 20, y);
			cairo_show_text (cr, caption.c_str());
		} else {
			// operation orders matters so it's 0 if i == num_bars
			caption = g_strdup_printf("%d %%", 100 - i * (100 / num_bars));
			cairo_text_extents (cr, caption, &extents);
			cairo_move_to (cr, g->indent - extents.width + 20, y);
			cairo_show_text (cr, caption);
			g_free (caption);
		}

		cairo_set_source_rgba (cr, 0, 0, 0, 0.75);
		cairo_move_to (cr, g->rmargin + g->indent - 3, i * g->graph_dely + 0.5);
		cairo_line_to (cr, g->draw_width - 0.5, i * g->graph_dely + 0.5);
	}
	cairo_stroke (cr);

	cairo_set_dash (cr, dash, 2, 1.5);

	const unsigned total_seconds = g->speed * (LoadGraph::NUM_POINTS - 2) / 1000;

	for (unsigned int i = 0; i < 7; i++) {
		double x = (i) * (g->draw_width - g->rmargin - g->indent) / 6;
		cairo_set_source_rgba (cr, 0, 0, 0, 0.75);
		cairo_move_to (cr, (ceil(x) + 0.5) + g->rmargin + g->indent, 0.5);
		cairo_line_to (cr, (ceil(x) + 0.5) + g->rmargin + g->indent, g->real_draw_height + 4.5);
		cairo_stroke(cr);
		unsigned seconds = total_seconds - i * total_seconds / 6;
		const char* format;
		if (i == 0)
			format = dngettext(GETTEXT_PACKAGE, "%u second", "%u seconds", seconds);
		else
			format = "%u";
		caption = g_strdup_printf(format, seconds);
		cairo_text_extents (cr, caption, &extents);
		cairo_move_to (cr, ((ceil(x) + 0.5) + g->rmargin + g->indent) - (extents.width/2), g->draw_height);
		gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]);
		cairo_show_text (cr, caption);
		g_free (caption);
	}

	cairo_stroke (cr);
	cairo_destroy (cr);
}