mirror of
https://git.zap.org.au/git/trader.git
synced 2024-09-01 17:14:15 -04:00
First pass at adding _() and N_() to allow string translation
This commit is contained in:
parent
36b1a13254
commit
9251ca0463
28
src/fileio.c
28
src/fileio.c
@ -52,15 +52,15 @@ static const unsigned char game_file_crypt_key[] = {
|
|||||||
#define load_game_scanf(_fmt, _var, _cond) \
|
#define load_game_scanf(_fmt, _var, _cond) \
|
||||||
do { \
|
do { \
|
||||||
if (fgets(buf, BUFSIZE, file) == NULL) { \
|
if (fgets(buf, BUFSIZE, file) == NULL) { \
|
||||||
err_exit("%s: missing field on line %d", filename, lineno); \
|
err_exit(_("%s: missing field on line %d"), filename, lineno); \
|
||||||
} \
|
} \
|
||||||
if (sscanf(unscramble(crypt_key, buf, BUFSIZE), _fmt "\n", \
|
if (sscanf(unscramble(crypt_key, buf, BUFSIZE), _fmt "\n", \
|
||||||
&(_var)) != 1) { \
|
&(_var)) != 1) { \
|
||||||
err_exit("%s: illegal field on line %d: `%s'", \
|
err_exit(_("%s: illegal field on line %d: `%s'"), \
|
||||||
filename, lineno, buf); \
|
filename, lineno, buf); \
|
||||||
} \
|
} \
|
||||||
if (! (_cond)) { \
|
if (! (_cond)) { \
|
||||||
err_exit("%s: illegal value on line %d: `%s'", \
|
err_exit(_("%s: illegal value on line %d: `%s'"), \
|
||||||
filename, lineno, buf); \
|
filename, lineno, buf); \
|
||||||
} \
|
} \
|
||||||
lineno++; \
|
lineno++; \
|
||||||
@ -87,10 +87,10 @@ static const unsigned char game_file_crypt_key[] = {
|
|||||||
int len; \
|
int len; \
|
||||||
\
|
\
|
||||||
if (fgets(buf, BUFSIZE, file) == NULL) { \
|
if (fgets(buf, BUFSIZE, file) == NULL) { \
|
||||||
err_exit("%s: missing field on line %d", filename, lineno); \
|
err_exit(_("%s: missing field on line %d"), filename, lineno); \
|
||||||
} \
|
} \
|
||||||
if (strlen(unscramble(crypt_key, buf, BUFSIZE)) == 0) { \
|
if (strlen(unscramble(crypt_key, buf, BUFSIZE)) == 0) { \
|
||||||
err_exit("%s: illegal value on line %d", filename, lineno); \
|
err_exit(_("%s: illegal value on line %d"), filename, lineno); \
|
||||||
} \
|
} \
|
||||||
lineno++; \
|
lineno++; \
|
||||||
\
|
\
|
||||||
@ -205,16 +205,16 @@ bool load_game (int num)
|
|||||||
|
|
||||||
// Read the game file header
|
// Read the game file header
|
||||||
if (fgets(buf, BUFSIZE, file) == NULL) {
|
if (fgets(buf, BUFSIZE, file) == NULL) {
|
||||||
err_exit("%s: missing header in game file", filename);
|
err_exit(_("%s: missing header in game file"), filename);
|
||||||
}
|
}
|
||||||
if (strcmp(buf, GAME_FILE_HEADER "\n") != 0) {
|
if (strcmp(buf, GAME_FILE_HEADER "\n") != 0) {
|
||||||
err_exit("%s: not a valid game file", filename);
|
err_exit(_("%s: not a valid game file"), filename);
|
||||||
}
|
}
|
||||||
if (fgets(buf, BUFSIZE, file) == NULL) {
|
if (fgets(buf, BUFSIZE, file) == NULL) {
|
||||||
err_exit("%s: missing subheader in game file", filename);
|
err_exit(_("%s: missing subheader in game file"), filename);
|
||||||
}
|
}
|
||||||
if (strcmp(buf, GAME_FILE_API_VERSION "\n") != 0) {
|
if (strcmp(buf, GAME_FILE_API_VERSION "\n") != 0) {
|
||||||
err_exit("%s: saved under a different version of Star Traders",
|
err_exit(_("%s: saved under a different version of Star Traders"),
|
||||||
filename);
|
filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ bool load_game (int num)
|
|||||||
|
|
||||||
// Read in the game file encryption key
|
// Read in the game file encryption key
|
||||||
if (fscanf(file, "%i\n", &crypt_key) != 1) {
|
if (fscanf(file, "%i\n", &crypt_key) != 1) {
|
||||||
err_exit("%s: illegal or missing field on line %d", filename, lineno);
|
err_exit(_("%s: illegal or missing field on line %d"), filename, lineno);
|
||||||
}
|
}
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ bool load_game (int num)
|
|||||||
|
|
||||||
// Read in company data
|
// Read in company data
|
||||||
for (i = 0; i < MAX_COMPANIES; i++) {
|
for (i = 0; i < MAX_COMPANIES; i++) {
|
||||||
company[i].name = company_name[i];
|
company[i].name = strdup(gettext(company_name[i]));
|
||||||
load_game_read_double(company[i].share_price, company[i].share_price >= 0.0);
|
load_game_read_double(company[i].share_price, company[i].share_price >= 0.0);
|
||||||
load_game_read_double(company[i].share_return, true);
|
load_game_read_double(company[i].share_return, true);
|
||||||
load_game_read_long(company[i].stock_issued, company[i].stock_issued >= 0);
|
load_game_read_long(company[i].stock_issued, company[i].stock_issued >= 0);
|
||||||
@ -262,10 +262,10 @@ bool load_game (int num)
|
|||||||
// Read in galaxy map
|
// Read in galaxy map
|
||||||
for (int x = 0; x < MAX_X; x++) {
|
for (int x = 0; x < MAX_X; x++) {
|
||||||
if (fgets(buf, BUFSIZE, file) == NULL) {
|
if (fgets(buf, BUFSIZE, file) == NULL) {
|
||||||
err_exit("%s: missing field on line %d", filename, lineno);
|
err_exit(_("%s: missing field on line %d"), filename, lineno);
|
||||||
}
|
}
|
||||||
if (strlen(unscramble(crypt_key, buf, BUFSIZE)) != MAX_Y + 1) {
|
if (strlen(unscramble(crypt_key, buf, BUFSIZE)) != MAX_Y + 1) {
|
||||||
err_exit("%s: illegal field on line %d", filename, lineno);
|
err_exit(_("%s: illegal field on line %d"), filename, lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < MAX_Y; y++) {
|
for (int y = 0; y < MAX_Y; y++) {
|
||||||
@ -274,7 +274,7 @@ bool load_game (int num)
|
|||||||
|| (c >= MAP_A && c <= MAP_LAST)) {
|
|| (c >= MAP_A && c <= MAP_LAST)) {
|
||||||
galaxy_map[x][y] = (map_val_t) c;
|
galaxy_map[x][y] = (map_val_t) c;
|
||||||
} else {
|
} else {
|
||||||
err_exit("%s: illegal value on line %d", filename, lineno);
|
err_exit(_("%s: illegal value on line %d"), filename, lineno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ void init_game (void)
|
|||||||
|
|
||||||
// Initialise company data
|
// Initialise company data
|
||||||
for (i = 0; i < MAX_COMPANIES; i++) {
|
for (i = 0; i < MAX_COMPANIES; i++) {
|
||||||
company[i].name = company_name[i];
|
company[i].name = strdup(gettext(company_name[i]));
|
||||||
company[i].share_price = 0.0;
|
company[i].share_price = 0.0;
|
||||||
company[i].share_return = INITIAL_RETURN;
|
company[i].share_return = INITIAL_RETURN;
|
||||||
company[i].stock_issued = 0;
|
company[i].stock_issued = 0;
|
||||||
@ -552,7 +552,7 @@ void end_game (void)
|
|||||||
for (i = 0; i < number_players; i++) {
|
for (i = 0; i < number_players; i++) {
|
||||||
l_strfmon(buf, BUFSIZE, "%!18n", player[i].sort_value);
|
l_strfmon(buf, BUFSIZE, "%!18n", player[i].sort_value);
|
||||||
mvwprintw(curwin, i + 7, 2, "%5s %-*.*s %18s ",
|
mvwprintw(curwin, i + 7, 2, "%5s %-*.*s %18s ",
|
||||||
ordinal[i + 1], w, w, player[i].name, buf);
|
gettext(ordinal[i + 1]), w, w, player[i].name, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
|
wait_for_key(curwin, getmaxy(curwin) - 2, attr_waitforkey);
|
||||||
|
@ -37,28 +37,28 @@
|
|||||||
|
|
||||||
// Company names
|
// Company names
|
||||||
const char *company_name[MAX_COMPANIES] = {
|
const char *company_name[MAX_COMPANIES] = {
|
||||||
"Altair Starways",
|
N_("Altair Starways"),
|
||||||
"Betelgeuse, Ltd",
|
N_("Betelgeuse, Ltd"),
|
||||||
"Capella Freight Co",
|
N_("Capella Freight Co"),
|
||||||
"Denebola Shippers",
|
N_("Denebola Shippers"),
|
||||||
"Eridani Expediters",
|
N_("Eridani Expediters"),
|
||||||
"Fornax Express",
|
N_("Fornax Express"),
|
||||||
"Gemeni Inc",
|
N_("Gemeni Inc"),
|
||||||
"Hercules and Co"
|
N_("Hercules and Co")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Ordinal strings
|
// Ordinal strings
|
||||||
const char *ordinal[MAX_PLAYERS + 1] = {
|
const char *ordinal[MAX_PLAYERS + 1] = {
|
||||||
"0th",
|
N_("0th"),
|
||||||
"1st",
|
N_("1st"),
|
||||||
"2nd",
|
N_("2nd"),
|
||||||
"3rd",
|
N_("3rd"),
|
||||||
"4th",
|
N_("4th"),
|
||||||
"5th",
|
N_("5th"),
|
||||||
"6th",
|
N_("6th"),
|
||||||
"7th",
|
N_("7th"),
|
||||||
"8th"
|
N_("8th")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ void init_screen (void)
|
|||||||
initscr();
|
initscr();
|
||||||
|
|
||||||
if (COLS < MIN_COLS || LINES < MIN_LINES) {
|
if (COLS < MIN_COLS || LINES < MIN_LINES) {
|
||||||
err_exit("terminal size is too small (%d x %d required)",
|
err_exit(_("terminal size is too small (%d x %d required)"),
|
||||||
MIN_COLS, MIN_LINES);
|
MIN_COLS, MIN_LINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
src/trader.c
36
src/trader.c
@ -232,7 +232,7 @@ void process_cmdline (int argc, char *argv[])
|
|||||||
option_max_turn = strtol(optarg, &p, 10);
|
option_max_turn = strtol(optarg, &p, 10);
|
||||||
|
|
||||||
if (option_max_turn < MIN_MAX_TURN || p == NULL || *p != '\0') {
|
if (option_max_turn < MIN_MAX_TURN || p == NULL || *p != '\0') {
|
||||||
fprintf(stderr, "%s: invalid value for --max-turn: `%s'\n",
|
fprintf(stderr, _("%s: invalid value for --max-turn: `%s'\n"),
|
||||||
program_name(), optarg);
|
program_name(), optarg);
|
||||||
show_usage(EXIT_FAILURE);
|
show_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -248,7 +248,7 @@ void process_cmdline (int argc, char *argv[])
|
|||||||
|
|
||||||
if (optind < argc && argv[optind] != NULL) {
|
if (optind < argc && argv[optind] != NULL) {
|
||||||
if (*argv[optind] == '-') {
|
if (*argv[optind] == '-') {
|
||||||
fprintf(stderr, "%s: invalid operand `%s'\n", program_name(),
|
fprintf(stderr, _("%s: invalid operand `%s'\n"), program_name(),
|
||||||
argv[optind]);
|
argv[optind]);
|
||||||
show_usage(EXIT_FAILURE);
|
show_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ void process_cmdline (int argc, char *argv[])
|
|||||||
&& *argv[optind] >= '1' && *argv[optind] <= '9') {
|
&& *argv[optind] >= '1' && *argv[optind] <= '9') {
|
||||||
game_num = *argv[optind] - '0';
|
game_num = *argv[optind] - '0';
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: invalid game number `%s'\n",
|
fprintf(stderr, _("%s: invalid game number `%s'\n"),
|
||||||
program_name(), argv[optind]);
|
program_name(), argv[optind]);
|
||||||
show_usage(EXIT_FAILURE);
|
show_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ void process_cmdline (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (optind < argc && argv[optind] != NULL) {
|
if (optind < argc && argv[optind] != NULL) {
|
||||||
fprintf(stderr, "%s: extra operand `%s'\n", program_name(),
|
fprintf(stderr, _("%s: extra operand `%s'\n"), program_name(),
|
||||||
argv[optind]);
|
argv[optind]);
|
||||||
show_usage(EXIT_FAILURE);
|
show_usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ void process_cmdline (int argc, char *argv[])
|
|||||||
|
|
||||||
void show_version (void)
|
void show_version (void)
|
||||||
{
|
{
|
||||||
printf("\
|
printf(_("\
|
||||||
" PACKAGE_NAME " (%s) %s\n\
|
" PACKAGE_NAME " (%s) %s\n\
|
||||||
Copyright (C) %s, John Zaitseff.\n\
|
Copyright (C) %s, John Zaitseff.\n\
|
||||||
\n\
|
\n\
|
||||||
@ -290,7 +290,7 @@ This program is free software that is distributed under the terms of the\n\
|
|||||||
GNU General Public License, version 3 or later. You are welcome to\n\
|
GNU General Public License, version 3 or later. You are welcome to\n\
|
||||||
modify and/or distribute it under certain conditions. This program has\n\
|
modify and/or distribute it under certain conditions. This program has\n\
|
||||||
NO WARRANTY, to the extent permitted by law; see the License for details.\n\
|
NO WARRANTY, to the extent permitted by law; see the License for details.\n\
|
||||||
", program_name(), PACKAGE_VERSION, "1990-2011");
|
"), program_name(), PACKAGE_VERSION, "1990-2011");
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
@ -305,35 +305,35 @@ void show_usage (int status)
|
|||||||
|
|
||||||
|
|
||||||
if (status != EXIT_SUCCESS) {
|
if (status != EXIT_SUCCESS) {
|
||||||
fprintf(stderr, "%s: Try `%s --help' for more information.\n",
|
fprintf(stderr, _("%s: Try `%s --help' for more information.\n"),
|
||||||
pn, pn);
|
pn, pn);
|
||||||
} else {
|
} else {
|
||||||
printf("Usage: %s [OPTION ...] [GAME]\n", pn);
|
printf(_("Usage: %s [OPTION ...] [GAME]\n"), pn);
|
||||||
printf("\
|
printf(_("\
|
||||||
Play Star Traders, a simple game of interstellar trading.\n\n\
|
Play Star Traders, a simple game of interstellar trading.\n\n\
|
||||||
");
|
"));
|
||||||
printf("\
|
printf(_("\
|
||||||
Options:\n\
|
Options:\n\
|
||||||
-V, --version output version information and exit\n\
|
-V, --version output version information and exit\n\
|
||||||
-h, --help display this help and exit\n\
|
-h, --help display this help and exit\n\
|
||||||
--no-color don't use colour for displaying text\n\
|
--no-color don't use colour for displaying text\n\
|
||||||
--max-turn=NUM set the number of turns to NUM\n\n\
|
--max-turn=NUM set the number of turns to NUM\n\n\
|
||||||
");
|
"));
|
||||||
printf("\
|
printf(_("\
|
||||||
If GAME is specified as a number between 1 and 9, load and continue\n\
|
If GAME is specified as a number between 1 and 9, load and continue\n\
|
||||||
playing that game. If GAME is not specified, start a new game.\n\n\
|
playing that game. If GAME is not specified, start a new game.\n\n\
|
||||||
");
|
"));
|
||||||
|
|
||||||
#ifdef PACKAGE_AUTHOR
|
#ifdef PACKAGE_AUTHOR
|
||||||
printf("Report bugs to %s <%s>.\n", PACKAGE_AUTHOR, PACKAGE_BUGREPORT);
|
printf(_("Report bugs to %s <%s>.\n"), PACKAGE_AUTHOR, PACKAGE_BUGREPORT);
|
||||||
#else
|
#else
|
||||||
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
|
printf(_("Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
|
||||||
#endif
|
#endif
|
||||||
#ifdef PACKAGE_PACKAGER_BUG_REPORTS
|
#ifdef PACKAGE_PACKAGER_BUG_REPORTS
|
||||||
printf("Report %s bugs to <%s>.\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
|
printf(_("Report %s bugs to <%s>.\n"), PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
|
||||||
#endif
|
#endif
|
||||||
#ifdef PACKAGE_URL
|
#ifdef PACKAGE_URL
|
||||||
printf(PACKAGE_NAME " home page: <%s>.\n", PACKAGE_URL);
|
printf(_(PACKAGE_NAME " home page: <%s>.\n"), PACKAGE_URL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ void err_exit (const char *restrict format, ...)
|
|||||||
|
|
||||||
end_screen();
|
end_screen();
|
||||||
|
|
||||||
fprintf(stderr, "%s: ", program_name());
|
fprintf(stderr, _("%s: "), program_name());
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vfprintf(stderr, format, args);
|
vfprintf(stderr, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
@ -227,12 +227,12 @@ void errno_exit (const char *restrict format, ...)
|
|||||||
|
|
||||||
end_screen();
|
end_screen();
|
||||||
|
|
||||||
fprintf(stderr, "%s: ", program_name());
|
fprintf(stderr, _("%s: "), program_name());
|
||||||
if (format != NULL) {
|
if (format != NULL) {
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vfprintf(stderr, format, args);
|
vfprintf(stderr, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
fputs(": ", stderr);
|
fputs(_(": "), stderr);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "%s\n", strerror(saved_errno));
|
fprintf(stderr, "%s\n", strerror(saved_errno));
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ void errno_exit (const char *restrict format, ...)
|
|||||||
|
|
||||||
void err_exit_nomem (void)
|
void err_exit_nomem (void)
|
||||||
{
|
{
|
||||||
err_exit("out of memory");
|
err_exit(_("out of memory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user