Skip to content
Open
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)



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");
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;
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