#include #include #include #include extern const char *__progname; static int npuzzles; static char **filenames; static char (*puzzles)[9][9]; static int load_puzzle(const char *name, char (*puzzle)[9][9]) { int y; int x; int ch; FILE *f; f = fopen(name,"r"); if (f == 0) { fprintf(stderr,"%s: %s: %s\n",__progname,name,strerror(errno)); return(1); } for (y=0;y<9;y++) { for (x=0;x<9;x++) { while <"cell"> (1) { ch = getc(f); if (ch == EOF) { fprintf(stderr,"%s: %s: EOF in mid-puzzle\n",__progname,name); fclose(f); return(1); } switch (ch) { case '.': ch = 0; break <"cell">; case '1': ch = 1; break <"cell">; case '2': ch = 2; break <"cell">; case '3': ch = 3; break <"cell">; case '4': ch = 4; break <"cell">; case '5': ch = 5; break <"cell">; case '6': ch = 6; break <"cell">; case '7': ch = 7; break <"cell">; case '8': ch = 8; break <"cell">; case '9': ch = 9; break <"cell">; } } puzzle[0][x][y] = ch; } } fclose(f); return(0); } static void load_puzzles(void) { int errs; int i; puzzles = malloc(npuzzles*sizeof(*puzzles)); errs = 0; for (i=0;i [ix..ix+216] is centred around 306 (ix=198); .5*252+k=198 gives k=72. */ ix = (atx * 252) + 72; /* Puzzles are placed 252 (10.5*24) from one another; aty=1 -> [iy..iy-216] is centred around 396 (iy=504); k-1*252=504 gives k=756. */ iy = 756 - (aty * 252); for (i=0;i<9;i+=3) { for (j=1;j<=2;j++) { printf("%d %d drmt %d %d drlt\n", ix+((i+j)*24),iy,ix+((i+j)*24),iy-216); printf("%d %d drmt %d %d drlt\n", ix,iy-((i+j)*24),ix+216,iy-((i+j)*24)); } } printf(".1 setlinewidth stroke\n"); printf("%d %d drmt %d %d drlt %d %d drlt %d %d drlt closepath\n", ix,iy,ix+216,iy,ix+216,iy-216,ix,iy-216); printf("%d %d drmt %d %d drlt %d %d drmt %d %d drlt\n", ix+72,iy,ix+72,iy-216,ix+144,iy,ix+144,iy-216); printf("%d %d drmt %d %d drlt %d %d drmt %d %d drlt\n", ix,iy-72,ix+216,iy-72,ix,iy-144,ix+216,iy-144); printf(".75 setlinewidth stroke\n"); for (x=0;x<9;x++) { for (y=0;y<9;y++) { c = puzzles[inx][x][y]; if (c == 0) continue; printf("%d %d drmt (%d) show\n",ix+(x*24)+6,iy-((y*24)+19),c); } } } static void pagetail(void) { printf("showpage\n"); } static void jobtail(void) { } static void page1(int inx) { pagehead(); genplot(.5,1,inx); pagetail(); } static void page2(int inx) { pagehead(); genplot(.5,.25,inx); genplot(.5,1.75,inx+1); pagetail(); } static void page3(int inx) { pagehead(); genplot(.5,0,inx); genplot(.5,1,inx+1); genplot(.5,2,inx+2); pagetail(); } static void page4(int inx) { pagehead(); genplot(0,.5,inx); genplot(1,.5,inx+1); genplot(0,1.5,inx+2); genplot(1,1.5,inx+3); pagetail(); } static void page5(int inx) { pagehead(); genplot(0,0,inx); genplot(1,0,inx+1); genplot(.5,1,inx+2); genplot(0,2,inx+3); genplot(1,2,inx+4); pagetail(); } static void page6(int inx) { pagehead(); genplot(0,0,inx); genplot(1,0,inx+1); genplot(0,1,inx+2); genplot(1,1,inx+3); genplot(0,2,inx+4); genplot(1,2,inx+5); pagetail(); } static void plot_them(void) { int left; int inx; jobhead(); left = npuzzles; inx = 0; while (left >= 12) { page6(inx); inx += 6; left -= 6; } switch (left) { case 0: break; case 1: page1(inx); break; case 2: page2(inx); break; case 3: page3(inx); break; case 4: page4(inx); break; case 5: page5(inx); break; case 6: page6(inx); break; case 7: page4(inx); page3(inx+4); break; case 8: page4(inx); page4(inx+4); break; case 9: page6(inx); page3(inx+6); break; case 10: page6(inx); page4(inx+6); break; case 11: page6(inx); page5(inx+6); break; } jobtail(); } static void handleargs(int ac, char **av) { npuzzles = ac - 1; filenames = av + 1; } int main(int, char **); int main(int ac, char **av) { npuzzles = 0; handleargs(ac,av); load_puzzles(); plot_them(); exit(0); }