char *progname = NULL;
char *version = "0.1";
-char *file = NULL;
+char *filename = NULL;
+char *playname = NULL;
char mode = 'e';
int speed = 5;
int xsize = 0;
{
FILE *fd = ret ? stderr : stdout;
fprintf (fd, "usage: %s [-e file] [-h] [-p file] [-s tens] [-v level] [-x int] [-y int]\n", progname);
- fprintf (fd, " -e: edit file (%s)\n", (file) ? file : "none");
+ fprintf (fd, " -e: edit file (%s)\n", (filename) ? filename : "none");
fprintf (fd, " -h: help message\n");
- fprintf (fd, " -p: play file (%s)\n", (file) ? file : "none");
+ fprintf (fd, " -p: play file (%s)\n", (playname) ? playname : "none");
fprintf (fd, " -s: speed ĭn tens/sec (%d)\n", speed);
fprintf (fd, " -v: verbose level (%d)\n", verbose);
fprintf (fd, " -x: board height (%d)\n", xsize);
return usage (1);
}
mode = 'e';
- file = arg;
+ filename = arg;
break;
case 'p':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
return usage (1);
}
mode = 'p';
- file = arg;
+ playname = arg;
break;
case 's':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
return 1;
}
- /* load data */
+ /* load element */
char *buffer = NULL;
board_t *element = NULL;
int xelement = 0;
int yelement = 0;
- if (file) {
- buffer = readdata (file);
+ if (filename) {
+ buffer = readdata (filename);
if (buffer) {
element = loadboard (buffer);
if (element == NULL) {
- VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", file));
+ VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", filename));
return 1;
}
free (buffer);
} else {
- VERBOSE (ERROR, fprintf (stderr, "can't read file (%s)\n", file));
+ VERBOSE (ERROR, fprintf (stderr, "can't read file (%s)\n", filename));
return 1;
}
} else { /* mono cell */
element->tab[0] = 'X';
}
+ /* load playground */
+ board_t *playground = NULL;
+ if (playname) {
+ buffer = readdata (playname);
+ if (buffer) {
+ playground = loadboard (buffer);
+ if (playground == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", playname));
+ return 1;
+ }
+ free (buffer);
+ } else {
+ VERBOSE (ERROR, fprintf (stderr, "can't read file (%s)\n", playname));
+ return 1;
+ }
+ }
+
/* init curses window */
initscr ();
noecho ();
if (ysize <= 0) {
ysize = ymax - 2 * (yoffset + 1);
}
- board_t *board = initboard (xsize, ysize);
+ board_t *board = (playground) ? resizeboard (playground, xsize, ysize) : initboard (xsize, ysize);
/* window positions */
int xboard = xoffset + 1;
char *ptr = NULL;
boardwindow (board, xboard, yboard, 1);
- if (mode == 'e') {
+ switch (mode) {
+ case 'e':
+ halfdelay (0);
rotateelement (element, rotate);
mirrorelement (element, mirror);
elementwindow (board, xboard, yboard, element, xelement, yelement);
+ break;
+ case 'p':
+ halfdelay (speed);
+ break;
}
+
rotate = 0;
mirror = 0;
case '\n':
case '\r':
mode = 'p';
- halfdelay (speed);
break;
case 'c':
putelement (board, element, xelement, yelement, 1);
case '\n':
case '\r':
mode = 'e';
- halfdelay (0);
break;
case 'q':
stop = 1;
/* test: gameoflife.exe -e nofile.gol 2>&1 | grep "can't read file" */
/* test: gameoflife.exe -e bogus.gol 2>&1 | grep 'incorrect file' */
/* test: gameoflife.exe -h | grep usage */
-/* test--: gameoflife.exe -p file.gol 2>&1 | grep 'not found' */
+/* test: gameoflife.exe -p 2>&1 | grep 'no play' */
+/* test: gameoflife.exe -p nofile.gol 2>&1 | grep "can't read file" */
+/* test: gameoflife.exe -p bogus.gol 2>&1 | grep 'incorrect file' */
/* test: gameoflife.exe -s 2>&1 | grep 'no speed' */
/* test: gameoflife.exe -s 0 2>&1 | grep 'incorrect speed' */
/* test: gameoflife.exe -v 2>&1 | grep missing */
/* test: gameoflife.exe _ 2>&1 | grep invalid */
/* test: echo -n q | gameoflife.exe -e glider.gol */
/* test: { echo clllldckkkrcjjjjcxfcilililecs; sleep 5; echo -n q; } | gameoflife.exe -e glider.gol -v 2 -s 2 */
-/* test: { echo icklckcjcjckjs; sleep 2; echo; sleep 1; echo -n q; } | gameoflife.exe -x 5 -y 5 */
+/* test: { echo icklckcjcjckjs; sleep 2; echo; sleep 1; echo -n q; } | gameoflife.exe -x 10 -y 10 */
+/* test: { echo; sleep 4; echo -n q; } | gameoflife -p board.gol -s 1 */
/* test: { echo cllllrckkkkjjd; sleep 3; echo -n q; } | gameoflife.exe -e beehive.gol -s 1 */
/* vim: set ts=4 sw=4 et: */