char *version = "0.1";
char *filename = NULL;
+int maxnbrecords = 0;
int scale = 1;
char *boardname = "6x10";
int usage (int ret)
{
FILE *fd = ret ? stderr : stdout;
- fprintf (fd, "usage: %s [-b] [-f file] [-h] [-s int] [-v int]\n", progname);
+ fprintf (fd, "usage: %s [-b] [-f file] [-h] [-r] [-s int] [-v int]\n", progname);
fprintf (fd, " -b: board form [6x10, 5x12, 4x15, 3x20] (%s)\n", boardname);
fprintf (fd, " -f: file name (%s)\n", (filename) ? filename : "none");
fprintf (fd, " -h: help message\n");
+ fprintf (fd, " -r: max nb records (%d)\n", maxnbrecords);
fprintf (fd, " -s: scale [0..3] (%d)\n", scale);
fprintf (fd, " -v: verbose level (%d)\n", verbose);
fprintf (fd, "%s version %s\n", progname, version);
}
filename = arg;
break;
+ case 'r':
+ arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ VERBOSE (ERROR, fprintf (stderr, "%s: missing max number of records\n", progname));
+ return usage (1);
+ }
+ maxnbrecords = atoi (arg);
+ break;
case 's':
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
}
setscale (board, scale);
+ /* init recorder */
+ int *rec = NULL;
+ if (maxnbrecords) {
+ rec = (int *) calloc (maxnbrecords, sizeof (int));
+ CHECKALLOC (rec);
+ }
+ int nbrecords = 0;
+
/* gets blocks */
blocks_t *blocks = getblocks ("std");
}
int ch = getch ();
+ if (maxnbrecords) {
+ if (nbrecords < maxnbrecords) {
+ rec[nbrecords++] = ch;
+ } else {
+ int i;
+ for (i = 0; i < nbrecords - 1; i++) {
+ rec[i] = rec[i + 1];
+ }
+ //memmove (rec, rec + 1, nbrecords - 1);
+ rec[nbrecords - 1] = ch;
+ }
+ }
/* general controls */
switch (ch) {
/* cleaning before quiting */
endwin ();
+ if (nbrecords) {
+ int i;
+ printf ("records: ");
+ for (i = 0; i < nbrecords; i++) {
+ if ((rec[i] > 31) && (rec[i] < 128)) {
+ printf ("%c", rec[i]);
+ } else {
+ printf ("0x%x", rec[i]);
+ }
+ }
+ printf ("\n");
+ }
+
+ free (rec);
freeboard (board);
freeblocks (blocks);
/* test: pentomino.exe -f nofile.pen 2>&1 | grep "can't read file" */
/* test: pentomino.exe -f bogus.pen 2>&1 | grep 'incorrect file' */
/* test: pentomino.exe -h | grep usage */
+/* test: pentomino.exe -r 2>&1 | grep 'missing max' */
/* test: pentomino.exe -s 2>&1 | grep 'no scale' */
/* test: pentomino.exe -s 4 2>&1 | grep incorrect */
/* test: pentomino.exe -v 2>&1 | grep missing */