mirror of
https://git.zap.org.au/git/trader.git
synced 2025-01-03 14:57:41 -05:00
Be stricter about saved game numbers
This commit is contained in:
parent
ee94d86b57
commit
ba721ced10
@ -50,6 +50,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
|
52
src/trader.c
52
src/trader.c
@ -67,6 +67,15 @@ int main (int argc, char *argv[])
|
||||
keypad(stdscr, true);
|
||||
raw();
|
||||
|
||||
if (has_colors() == true) {
|
||||
start_color();
|
||||
init_pair(1, COLOR_WHITE, COLOR_BLACK);
|
||||
init_pair(2, COLOR_WHITE, COLOR_BLUE);
|
||||
bkgd(COLOR_PAIR(1));
|
||||
}
|
||||
clear();
|
||||
move(0, 0);
|
||||
|
||||
printw(_("Program name: %s\n"), program_name());
|
||||
printw(_("Home directory: %s\n"), home_directory());
|
||||
printw(_("Data directory: %s\n"), data_directory());
|
||||
@ -75,22 +84,44 @@ int main (int argc, char *argv[])
|
||||
printw(_("Cols x Lines: %d x %d\n"), COLS, LINES);
|
||||
printw(_("Colours, pairs: %d, %d\n"), COLORS, COLOR_PAIRS);
|
||||
|
||||
printw(_("Type some keys (^C to exit):\n\n"));
|
||||
refresh();
|
||||
|
||||
curs_set(CURS_VERYVISIBLE);
|
||||
|
||||
WINDOW *w1, *w2;
|
||||
|
||||
w1 = newwin(0, 0, 7, 0);
|
||||
wbkgd(w1, COLOR_PAIR(2));
|
||||
box(w1, 0, 0);
|
||||
wrefresh(w1);
|
||||
|
||||
w2 = newwin(LINES - 9, COLS - 8, 8, 4);
|
||||
wbkgd(w2, COLOR_PAIR(2));
|
||||
|
||||
mvwprintw(w2, 0, 0, _("Type some keys (^C to exit):\n\n"));
|
||||
wrefresh(w2);
|
||||
|
||||
keypad(w2, true);
|
||||
meta(w2, true);
|
||||
wtimeout(w2, -1);
|
||||
|
||||
int c = 0;
|
||||
while ((c = getch()) != 3) {
|
||||
while ((c = wgetch(w2)) != 3) {
|
||||
if ((c >= 0) && (c < 32)) {
|
||||
printw("0%03o ^%c ", c, c + '@');
|
||||
} else if ((c >= 32) && (c <= 127)) {
|
||||
printw("0%03o %c ", c, c);
|
||||
wprintw(w2, "0%03o ^%c ", c, c + '@');
|
||||
} else if ((c >= 32) && (c < 127)) {
|
||||
wprintw(w2, "0%03o %c ", c, c);
|
||||
} else {
|
||||
printw("0%05o ", c);
|
||||
wprintw(w2, "0%05o ", c);
|
||||
}
|
||||
refresh();
|
||||
wrefresh(w2);
|
||||
}
|
||||
|
||||
delwin(w2);
|
||||
delwin(w1);
|
||||
|
||||
clear();
|
||||
refresh();
|
||||
endwin();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
@ -160,6 +191,13 @@ static void process_cmdline (int argc, char *argv[])
|
||||
}
|
||||
|
||||
game_filename = strto_game_filename(argv[optind]);
|
||||
|
||||
if (game_filename == NULL) {
|
||||
fprintf(stderr, _("%s: invalid game number `%s'\n"),
|
||||
program_name(), argv[optind]);
|
||||
show_usage(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
optind++;
|
||||
}
|
||||
|
||||
|
13
src/utils.c
13
src/utils.c
@ -158,9 +158,7 @@ const char *data_directory (void)
|
||||
This function returns the full game filename as a malloc()ed string.
|
||||
If game_num is a string between "1" and "9" inclusive, the string
|
||||
returned is in the form data_directory() + "/" + GAME_FILENAME(game_num),
|
||||
eg, "/home/test/.trader/game7". If game_num is any other string, that
|
||||
string is returned as the game filename. If game_num is NULL, NULL is
|
||||
returned.
|
||||
eg, "/home/test/.trader/game7". Otherwise, NULL is returned.
|
||||
*/
|
||||
|
||||
char *strto_game_filename (const char *game_num)
|
||||
@ -169,15 +167,10 @@ char *strto_game_filename (const char *game_num)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((strlen(game_num) == 1) &&
|
||||
(game_num[0] >= '1') && (game_num[0] <= '9')) {
|
||||
if ((strlen(game_num) == 1) && isdigit(game_num[0])) {
|
||||
return intto_game_filename(game_num[0] - '0');
|
||||
} else {
|
||||
char *p = malloc(strlen(game_num) + 1);
|
||||
if (p != NULL) {
|
||||
strcpy(p, game_num);
|
||||
}
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user