1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 08:18:51 -05:00

Clean up pacman.c, add localize function

* Add a localize function to do what was done before in main wrt i18n
  initialization.
* Added Doxygen comments to all functions in pacman.c.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-03-28 16:14:42 -04:00
parent b8602adee9
commit 8fd16d0dcb

View File

@ -81,9 +81,11 @@ pmdb_t *db_local;
/* list of targets specified on command line */ /* list of targets specified on command line */
static alpm_list_t *pm_targets; static alpm_list_t *pm_targets;
/* Display usage/syntax for the specified operation. /**
* op: the operation code requested * @brief Display usage/syntax for the specified operation.
* myname: basename(argv[0]) *
* @param op the operation code requested
* @param myname basename(argv[0])
*/ */
static void usage(int op, char *myname) static void usage(int op, char *myname)
{ {
@ -174,7 +176,8 @@ static void usage(int op, char *myname)
} }
} }
/* Version /**
* @brief Output pacman version and copyright.
*/ */
static void version() static void version()
{ {
@ -188,6 +191,31 @@ static void version()
printf("\n"); printf("\n");
} }
/**
* @brief Sets up gettext localization.
* Safe to call multiple times.
*/
/* Inspired by the monotone function localize_monotone. */
static void localize()
{
static int init = 0;
if (!init) {
printf("debug: PACKAGE: %s\n", PACKAGE);
printf("debug: LOCALEDIR: %s\n", LOCALEDIR);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
init = 1;
}
}
/**
* @brief Catches thrown signals.
* Performs necessary cleanup to ensure database is in a consistant
* state.
*
* @param signum the thrown signal
*/
static void cleanup(int signum) static void cleanup(int signum)
{ {
if(signum==SIGSEGV) if(signum==SIGSEGV)
@ -219,11 +247,13 @@ static void cleanup(int signum)
exit(signum); exit(signum);
} }
/* Parse command-line arguments for each operation /**
* argc: argc * @brief Parse command-line arguments for each operation
* argv: argv *
* * @param argc argc
* Returns: 0 on success, 1 on error * @param argv argv
*
* @return 0 on success, 1 on error
*/ */
static int parseargs(int argc, char *argv[]) static int parseargs(int argc, char *argv[])
{ {
@ -421,10 +451,17 @@ static int parseargs(int argc, char *argv[])
return(0); return(0);
} }
/**
* @brief Main function.
*
* @param argc argc
* @param argv argv
*
* @return A return code indicating success, failure, etc.
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int ret = 0; int ret = 0;
char *lang = NULL;
#ifndef CYGWIN #ifndef CYGWIN
uid_t myuid; uid_t myuid;
#endif #endif
@ -439,21 +476,7 @@ int main(int argc, char *argv[])
signal(SIGSEGV, cleanup); signal(SIGSEGV, cleanup);
/* i18n init */ /* i18n init */
lang = setlocale(LC_ALL, ""); localize();
/* if setlocale returns null, the locale was invalid- override it */
if (lang == NULL) {
lang = "C";
setlocale(LC_ALL, "C");
setenv("LC_ALL", lang, 1);
MSG(NL, _("warning: current locale is invalid; using default \"C\" locale"));
}
/* workaround for tr_TR */
if(lang && !strcmp(lang, "tr_TR")) {
setlocale(LC_CTYPE, "C");
}
bindtextdomain("pacman", "/usr/share/locale");
textdomain("pacman");
/* init config data */ /* init config data */
config = config_new(); config = config_new();