board = initboard (xsize, ysize);
memcpy (board->tab, tab, xsize * ysize);
}
- if ((board != NULL) && (*pname != NULL)) {
+ if ((board != NULL) && (pname != NULL)) {
*pname = strdup (name);
}
return board;
}
+board_t *processfile (char *filename, char **pname)
+{
+ char *buffer = readdata (filename);
+ if (buffer == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "can't read file (%s)\n", filename));
+ return NULL;
+ }
+
+ board_t *board = loadboard (buffer, pname);
+ if (board == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", filename));
+ }
+
+ free (buffer);
+
+ return board;
+}
+
+library_t *processlibrary (char *libname)
+{
+ int n = 0;
+ library_t *lib = (library_t *) malloc ((n + 2) * sizeof (library_t));
+ CHECKALLOC (lib);
+
+ (lib + n)->board = initboard (3, 3);
+ (lib + n)->board->tab[4] = 'X';
+ (lib + n)->name = strdup ("Cell");
+ memset (lib + n + 1, 0, sizeof (library_t));
+ n++;
+
+ if (libname) {
+ char *saveptr;
+ char *filename = strtok_r (libname, ":", &saveptr);
+ while (filename) {
+ char *name;
+ lib = (library_t *) realloc (lib, (n + 2) * sizeof (library_t));
+ CHECKALLOC (lib);
+
+ (lib + n)->board = processfile (filename, &name);
+ if ((lib + n)->board != NULL) {
+ (lib + n)->name = name;
+ memset (lib + n + 1, 0, sizeof (library_t));
+ n++;
+ }
+
+ filename = strtok_r (NULL, ":", &saveptr);
+ }
+ }
+
+ return lib;
+}
+
+void freelibrary (library_t *lib)
+{
+ int n = 0;
+
+ while ((lib + n)->board) {
+ freeboard ((lib + n)->board);
+ free ((lib + n)->name);
+ n++;
+ }
+
+ free (lib);
+}
+
/* vim: set ts=4 sw=4 et: */
return ret;
}
-board_t *processfile (char *filename, char **pname)
-{
- char *buffer = readdata (filename);
- if (buffer == NULL) {
- VERBOSE (ERROR, fprintf (stderr, "can't read file (%s)\n", filename));
- return NULL;
- }
-
- board_t *board = loadboard (buffer, pname);
- if (board == NULL) {
- VERBOSE (ERROR, fprintf (stderr, "incorrect file (%s)\n", filename));
- }
-
- free (buffer);
-
- return board;
-}
-
-library_t *processlibrary (char *libname)
-{
- int n = 0;
- library_t *lib = (library_t *) malloc ((n + 2) * sizeof (library_t));
- CHECKALLOC (lib);
-
- (lib + n)->board = initboard (3, 3);
- (lib + n)->board->tab[4] = 'X';
- (lib + n)->name = strdup ("Cell");
- memset (lib + n + 1, 0, sizeof (library_t));
- n++;
-
- if (libname) {
- char *saveptr;
- char *filename = strtok_r (libname, ":", &saveptr);
- while (filename) {
- char *name;
- lib = (library_t *) realloc (lib, (n + 2) * sizeof (library_t));
- CHECKALLOC (lib);
-
- (lib + n)->board = processfile (filename, &name);
- if ((lib + n)->board != NULL) {
- (lib + n)->name = name;
- memset (lib + n + 1, 0, sizeof (library_t));
- n++;
- }
-
- filename = strtok_r (NULL, ":", &saveptr);
- }
- }
-
- return lib;
-}
-
/* main function */
int main (int argc, char *argv[])
{
return 1;
}
- /* load library */
- library_t *lib = processlibrary (listoffilename);
- int n = 0;
- board_t *element = (lib + n)->board;
-
/* load playground */
board_t *playground = NULL;
if (playname) {
}
}
+ /* load library */
+ library_t *lib = processlibrary (listoffilename);
+ int n = 0;
+ board_t *element = (lib + n)->board;
+
/* init curses window */
initscr ();
noecho ();
endwin ();
- n = 0;
- while ((lib + n)->board) {
- freeboard ((lib + n)->board);
- free ((lib + n)->name);
- }
- free (lib);
+ freelibrary (lib);
freeboard (board);
return 0;
}
/* test: gameoflife.exe -e 2>&1 | grep 'no board' */
-/* 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: echo -n q | gameoflife.exe -e nofile.gol 2>&1 | grep "can't read file" */
+/* test: echo -n q | gameoflife.exe -e bogus.gol 2>&1 | grep 'incorrect file' */
/* test: gameoflife.exe -h | grep usage */
/* test: gameoflife.exe -p 2>&1 | grep 'no playground' */
/* test: gameoflife.exe -p nofile.gol 2>&1 | grep "can't read file" */
/* test: gameoflife.exe -x 2>&1 | grep 'no width' */
/* test: gameoflife.exe -y 2>&1 | grep 'no height' */
/* 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 -s 2 */
+/* test: echo -n q | gameoflife.exe */
+/* test: { echo oclllldckkkrcjjjjcxfcilililecs; sleep 5; echo -n q; } | gameoflife.exe -e glider.gol -s 2 */
/* test: { echo icklckcjcjckjs; sleep 2; echo; sleep 1; echo -n q; } | gameoflife.exe -x 10 -y 10 -v 2 */
/* test: { sleep 4; echo -n q; } | gameoflife.exe -p board.gol -s 1 */
-/* test: { echo cllllrckkkkjjd; sleep 3; echo -n q; } | gameoflife.exe -e beehive.gol -s 1 */
+/* test: { echo uucllllrckkkkjjd; sleep 3; echo -n q; } | gameoflife.exe -e beehive.gol:block.gol -s 1 */
/* vim: set ts=4 sw=4 et: */