/* table.c - by Daniel Rice, 11/91.
    Permission is granted for any use of this code. */

/* Print out a table, given a starting position and a line length,
   as in the book _Ha-Meymad ha-Nosaf_ by Doron Witztum. */

#include <stdio.h>

#define NUMROWS 30
#define NUMCOLUMNS 39

#define min(a,b) ((a) < (b) ? (a) : (b))

main (argc, argv)
char **argv;

{
	int c;
	int skip;
	int offset;
	int pos;
	int row, column;

	if (argc < 3) {
	  fprintf (stderr, "usage %s offset skip\n", argv[0]);
	  exit(0);
	}

	offset = atoi(argv[1]);
	skip = atoi(argv[2]);

	for (pos = 0; pos < offset; ++pos)
		(void) getchar();

	for (row = 0; row < NUMROWS; ++row) {
		for (column = 0; column < min(NUMCOLUMNS, skip); ++column) {
			if ((c = getchar ()) != EOF) {
				putchar(c);
				putchar(' ');
				++pos;
			}
			else
				exit(0);
		}

		putchar('\n');

		while ((pos - offset) % skip) {
			c = getchar();
			if (c == EOF)
				exit(0);
			++pos;
		}

	}
}
