#include #include #include #include #include "cards.h" extern const char *__progname; static char *deckdir; static char *path; static char *tmp; /* last char of cvec is used for nonexistent colors */ static char cvec_[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?"; #define MAXCOLORS ((sizeof(cvec_)/sizeof(cvec_[0]))-2) static char *cvec; static const char card_vals[] = "A23456789TJQK"; static const char card_suit[] = "CDHSRB"; static const char *card_xdeck[] = { "j" }; static void alloctemp(void) { int len; len = strlen(deckdir); path = malloc(len+64); tmp = path + len; strcpy(path,deckdir); *tmp++ = '/'; } static FILE *xfopen(const char *path, const char *mode) { FILE *rv; rv = fopen(path,mode); if (rv) return(rv); fprintf(stderr,"%s: can't open %s for %s\n",__progname,path,('w'==*mode)?"write":"read"); exit(1); } static void nlscan(FILE *f) { int c; while (1) { c = getc(f); if (c == '\n') break; if (c == EOF) { fprintf(stderr,"%s: premature EOF on %s\n",__progname,path); exit(1); } } } static void make_bw(void) { FILE *f; int x; int y; int c; int b; f = xfopen(path,"r"); for (y=0;y= i) { i += 8; cvec = realloc(cvec,i+1); colors = realloc(colors,i*sizeof(*colors)); } cvec[nc] = c; if (fscanf(f,"%x%x%x",&r,&g,&b) != 3) break; colors[nc][0] = r; colors[nc][1] = g; colors[nc][2] = b; nc ++; nlscan(f); } fclose(f); cvec[nc] = '\0'; if (nc < 1) { fprintf(stderr,"%s: no colors\n",__progname); exit(1); } nb = 0; while (1) { sprintf(tmp,"bb%d",nb+1); if (access(path,R_OK) < 0) break; nb ++; } if (nb < 1) { fprintf(stderr,"%s: no backs\n",__progname); exit(1); } putchar(nc); putchar(nb); for (i=0;i>8); putchar(colors[i][c]&0xff); } } for (i=0;i>= 1; } putc('\n',f); } fclose(f); } static void split_col(int ncol) { FILE *f; int x; int y; int c; f = xfopen(path,"w"); for (y=0;y MAXCOLORS) { fprintf(stderr,"%s: can't handle decks with more than %d colors\n",__progname,(int)MAXCOLORS); exit(1); } colors = malloc(ncol*sizeof(*colors)); for (i=0;i