Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions bin/xbps-install/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@
#include <xbps.h>
#include "defs.h"


#include <libintl.h>
#include <locale.h>
#define _(STRING) gettext(STRING)
Comment on lines +41 to +43
Copy link
Contributor

@meator meator Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be put into a common header (without the locale.h header, which should be only needed in main()).




static void __attribute__((noreturn))
usage(bool fail)
{
fprintf(stdout,
"Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n"
_("Usage: xbps-install [OPTIONS] [PKGNAME...]\n\n"
"OPTIONS\n"
" -A, --automatic Set automatic installation mode\n"
" -C, --config <dir> Path to confdir (xbps.d)\n"
Expand All @@ -66,7 +73,7 @@ usage(bool fail)
" -u, --update Update target package(s)\n"
" -v, --verbose Verbose messages\n"
" -y, --yes Assume yes to all questions\n"
" -V, --version Show XBPS version\n");
" -V, --version Show XBPS version\n"));
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
}

Expand All @@ -76,7 +83,7 @@ unpack_progress_cb(const struct xbps_unpack_cb_data *xpd, void *cbdata UNUSED)
if (xpd->entry == NULL || xpd->entry_total_count <= 0)
return;

printf("%s: unpacked %sfile `%s' (%" PRIi64 " bytes)\n",
printf(_("%s: unpacked %sfile `%s' (%" PRIi64 " bytes)\n"),
xpd->pkgver,
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
xpd->entry_size);
Expand All @@ -88,16 +95,21 @@ repo_import_key_cb(struct xbps_repo *repo, void *arg UNUSED, bool *done UNUSED)
int rv;

if ((rv = xbps_repo_key_import(repo)) != 0)
xbps_error_printf("Failed to import pubkey from %s: %s\n",
xbps_error_printf(_("Failed to import pubkey from %s: %s\n"),
repo->uri, strerror(rv));

return rv;
}


int
main(int argc, char **argv)
{

const char *shortopts = "AC:c:DdfhIiMnR:r:SuUVvy";

// Movido as declarações para o início

const struct option longopts[] = {
{ "automatic", no_argument, NULL, 'A' },
{ "config", required_argument, NULL, 'C' },
Expand All @@ -122,6 +134,9 @@ main(int argc, char **argv)
{ "staging", no_argument, NULL, 2 },
{ NULL, 0, NULL, 0 }
};



struct xbps_handle xh;
struct xferstat xfer;
const char *rootdir, *cachedir, *confdir;
Expand All @@ -135,6 +150,14 @@ main(int argc, char **argv)

memset(&xh, 0, sizeof(xh));


setlocale(LC_ALL, "");
bindtextdomain("xbps-install", "/usr/share/locale");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't hardcode paths like that. This would require tighter build system integration, see my other comments on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not 100% sure on this, but setlocale(LC_ALL, ""); can have unanticipated consequences in a codebase which was locale-unaware before. This could lead to non-English users seeing snippets of translated/localized strings in xbps-install while the rest of the strings remain in English. This can be distracting and it could be considered intrusive to non-English users who are used to English XBPS.

textdomain("xbps-install");




while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch (c) {
case 1:
Expand Down Expand Up @@ -229,7 +252,7 @@ main(int argc, char **argv)
xh.unpack_cb = unpack_progress_cb;

if ((rv = xbps_init(&xh)) != 0) {
xbps_error_printf("Failed to initialize libxbps: %s\n",
xbps_error_printf(_("Failed to initialize libxbps: %s\n"),
strerror(rv));
exit(EXIT_FAILURE);
}
Expand All @@ -250,7 +273,7 @@ main(int argc, char **argv)

if (!(xh.flags & XBPS_FLAG_DOWNLOAD_ONLY) && !drun) {
if ((rv = xbps_pkgdb_lock(&xh)) != 0) {
xbps_error_printf("Failed to lock the pkgdb: %s\n", strerror(rv));
xbps_error_printf(_("Failed to lock the pkgdb: %s\n"), strerror(rv));
exit(rv);
}
}
Expand Down
14 changes: 11 additions & 3 deletions bin/xbps-install/question.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@

#include "defs.h"


#include <libintl.h>
#include <locale.h>
#define _(STRING) gettext(STRING)


#ifdef __clang__
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
Expand All @@ -45,14 +51,16 @@ question(bool preset, const char *fmt, va_list ap)

vfprintf(stderr, fmt, ap);
if (preset)
fputs(" [Y/n] ", stderr);
fputs(_(" [Y/n] "), stderr);
else
fputs(" [y/N] ", stderr);
fputs(_(" [y/N] "), stderr);

response = fgetc(stdin);
if (response == '\n')
rv = preset;
else if (response == 'y' || response == 'Y')

// Apenas acrescente S/s como equivalentes
else if (response == 'y' || response == 'Y' || response == 's' || response == 'S')
rv = true;
else if (response == 'n' || response == 'N')
rv = false;
Comment on lines -55 to 66
Copy link
Contributor

@meator meator Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not acceptable. If you really want to do this, the following might be better:

response = fgetc(stdin);
// TRANSLATORS: The following string isn't displayed to the user, it is used to
//              determine what the user's response to a yes/no question means.
//              The characters in this string should be the same characters
//              as in the TODO string (without the separator, / or otherwise).
//              Only the first character of the user's response is considered,
//              for example, the default English version consideres "y", "ye",
//              "yes" and "yn" the same. You therefore cannot include whole
//              words here.
//              TODO: One letter may occupy multiple bytes. I suspect that the
//              current setup doesn't handle that.
//              This string defines a positive response. See the string below
//              for a negative one.
const char * positive_response = _("yY");
// TRANSLATORS: This string defines a negative response. See the translators
//              comment for positive_response above for more info.
const char * negative_response = _("nN");

if (response == "\n")
	rv = preset;
else if (strchr(positive_response, response) != NULL)
	rt = true;
else if (strchr(negative_response, response) != NULL)
	rt = false;

// ...

Expand Down
58 changes: 31 additions & 27 deletions bin/xbps-install/state_cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <xbps.h>
#include "defs.h"

#include <libintl.h>
#include <locale.h>
#define _(STRING) gettext(STRING)

int
state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
{
Expand All @@ -48,25 +52,25 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
switch (xscd->state) {
/* notifications */
case XBPS_STATE_TRANS_DOWNLOAD:
printf("\n[*] Downloading packages\n");
printf(_("\n[*] Downloading packages\n"));
break;
case XBPS_STATE_TRANS_VERIFY:
printf("\n[*] Verifying package integrity\n");
printf(_("\n[*] Verifying package integrity\n"));
break;
case XBPS_STATE_TRANS_FILES:
printf("\n[*] Collecting package files\n");
printf(_("\n[*] Collecting package files\n"));
break;
case XBPS_STATE_TRANS_RUN:
printf("\n[*] Unpacking packages\n");
printf(_("\n[*] Unpacking packages\n"));
break;
case XBPS_STATE_TRANS_CONFIGURE:
printf("\n[*] Configuring unpacked packages\n");
printf(_("\n[*] Configuring unpacked packages\n"));
break;
case XBPS_STATE_PKGDB:
printf("[*] pkgdb upgrade in progress, please wait...\n");
printf(_("[*] pkgdb upgrade in progress, please wait...\n"));
break;
case XBPS_STATE_REPOSYNC:
printf("[*] Updating repository `%s' ...\n", xscd->arg);
printf(_("[*] Updating repository `%s' ...\n"), xscd->arg);
break;
case XBPS_STATE_TRANS_ADDPKG:
if (xscd->xhp->flags & XBPS_FLAG_VERBOSE)
Expand All @@ -83,16 +87,16 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
printf("%s\n", xscd->desc);
break;
case XBPS_STATE_REMOVE:
printf("%s: removing ...\n", xscd->arg);
printf(_("%s: removing ...\n"), xscd->arg);
break;
case XBPS_STATE_CONFIGURE:
printf("%s: configuring ...\n", xscd->arg);
printf(_("%s: configuring ...\n"), xscd->arg);
break;
case XBPS_STATE_CONFIGURE_DONE:
/* empty */
break;
case XBPS_STATE_UNPACK:
printf("%s: unpacking ...\n", xscd->arg);
printf(_("%s: unpacking ...\n"), xscd->arg);
break;
case XBPS_STATE_INSTALL:
case XBPS_STATE_DOWNLOAD:
Expand All @@ -105,10 +109,10 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
newver = xbps_pkg_version(xscd->arg);
pkgd = xbps_pkgdb_get_pkg(xscd->xhp, pkgname);
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &instver);
printf("%s: updating to %s ...\n", instver, newver);
printf(_("%s: updating to %s ...\n"), instver, newver);
if (slog) {
syslog(LOG_NOTICE, "%s: updating to %s ... "
"(rootdir: %s)\n", instver, newver,
syslog(LOG_NOTICE, _("%s: updating to %s ... "
"(rootdir: %s)\n"), instver, newver,
xscd->xhp->rootdir);
}
break;
Expand All @@ -123,37 +127,37 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
}
break;
case XBPS_STATE_INSTALL_DONE:
printf("%s: installed successfully.\n", xscd->arg);
printf(_("%s: installed successfully.\n"), xscd->arg);
if (slog) {
syslog(LOG_NOTICE, "Installed `%s' successfully "
"(rootdir: %s).", xscd->arg,
syslog(LOG_NOTICE, _("Installed `%s' successfully "
"(rootdir: %s)."), xscd->arg,
xscd->xhp->rootdir);
}
break;
case XBPS_STATE_UPDATE_DONE:
printf("%s: updated successfully.\n", xscd->arg);
printf(_("%s: updated successfully.\n"), xscd->arg);
if (slog) {
syslog(LOG_NOTICE, "Updated `%s' successfully "
"(rootdir: %s).", xscd->arg,
syslog(LOG_NOTICE, _("Updated `%s' successfully "
"(rootdir: %s)."), xscd->arg,
xscd->xhp->rootdir);
}
break;
case XBPS_STATE_REMOVE_DONE:
printf("%s: removed successfully.\n", xscd->arg);
printf(_("%s: removed successfully.\n"), xscd->arg);
if (slog) {
syslog(LOG_NOTICE, "Removed `%s' successfully "
"(rootdir: %s).", xscd->arg,
syslog(LOG_NOTICE, _("Removed `%s' successfully "
"(rootdir: %s)."), xscd->arg,
xscd->xhp->rootdir);
}
break;
case XBPS_STATE_PKGDB_DONE:
printf("The pkgdb file has been upgraded successfully, please reexec "
"the command again.\n");
printf(_("The pkgdb file has been upgraded successfully, please reexec "
"the command again.\n"));
break;
case XBPS_STATE_REPO_KEY_IMPORT:
printf("%s\n", xscd->desc);
printf("Fingerprint: %s\n", xscd->arg);
rv = yesno("Do you want to import this public key?");
printf(_("Fingerprint: %s\n"), xscd->arg);
rv = yesno(_("Do you want to import this public key?"));
break;
case XBPS_STATE_UNPACK_FILE_PRESERVED:
printf("%s\n", xscd->desc);
Expand Down Expand Up @@ -190,7 +194,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
if (xscd->desc)
printf("%s\n", xscd->desc);
else
xbps_dbg_printf("%s: unknown state %d\n", xscd->arg, xscd->state);
xbps_dbg_printf(_("%s: unknown state %d\n"), xscd->arg, xscd->state);

break;
}
Expand Down
Loading