| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
#include <stdlib.h> |
|---|
| 18 |
#include <unistd.h> |
|---|
| 19 |
#include <string.h> |
|---|
| 20 |
#include <stdio.h> |
|---|
| 21 |
#include <time.h> |
|---|
| 22 |
|
|---|
| 23 |
#include "gemmes.h" |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#ifdef GEMMES_TXT |
|---|
| 28 |
|
|---|
| 29 |
#include "font_text.h" |
|---|
| 30 |
extern font_t * font; |
|---|
| 31 |
|
|---|
| 32 |
#endif |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
void usage(const char * pname, int ev) |
|---|
| 36 |
{ |
|---|
| 37 |
fprintf(stderr, "usage: %s [option]\n" |
|---|
| 38 |
" Accepted options:\n" |
|---|
| 39 |
#ifdef GEMMES_TXT |
|---|
| 40 |
" -b big display\n" |
|---|
| 41 |
" -f big display (ASCII Art)\n" |
|---|
| 42 |
" -g big display (colored ASCII Art, does not pretend to be fully portable.\n" |
|---|
| 43 |
" you can use -gg for another color disposition)\n" |
|---|
| 44 |
#endif |
|---|
| 45 |
" -h print this help string\n" |
|---|
| 46 |
" -q quiet, only the dump command will display something\n" |
|---|
| 47 |
" -s randseq use randseq as random sequence\n" |
|---|
| 48 |
" -x <number>, -y <number> change the board dimensions\n" |
|---|
| 49 |
" -c <number> change amount of colors\n" |
|---|
| 50 |
, pname); |
|---|
| 51 |
exit(ev); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
int main(int argc, char ** argv) |
|---|
| 55 |
{ |
|---|
| 56 |
char * pname = strrchr(argv[0], '/'); |
|---|
| 57 |
if( !pname ) |
|---|
| 58 |
pname = argv[0]; |
|---|
| 59 |
else |
|---|
| 60 |
pname++; |
|---|
| 61 |
|
|---|
| 62 |
int optch; |
|---|
| 63 |
|
|---|
| 64 |
int x = 8; |
|---|
| 65 |
int y = 8; |
|---|
| 66 |
int ncolor = 7; |
|---|
| 67 |
char * s = NULL; |
|---|
| 68 |
int silent = 0; |
|---|
| 69 |
|
|---|
| 70 |
while( (optch = getopt(argc, argv, "bfghqs:x:y:c:")) != -1 ) |
|---|
| 71 |
{ |
|---|
| 72 |
switch(optch) |
|---|
| 73 |
{ |
|---|
| 74 |
#ifdef GEMMES_TXT |
|---|
| 75 |
case 'f': |
|---|
| 76 |
font = &FANCY_FONT; |
|---|
| 77 |
break; |
|---|
| 78 |
case 'b': |
|---|
| 79 |
font = &BIG_FONT; |
|---|
| 80 |
break; |
|---|
| 81 |
case 'g': |
|---|
| 82 |
if(font == &COLORED_FONT) |
|---|
| 83 |
font = &COLORED_FONT2; |
|---|
| 84 |
else |
|---|
| 85 |
font = &COLORED_FONT; |
|---|
| 86 |
break; |
|---|
| 87 |
#endif |
|---|
| 88 |
case 'h': |
|---|
| 89 |
usage(pname, EXIT_SUCCESS); |
|---|
| 90 |
break; |
|---|
| 91 |
case 'q': |
|---|
| 92 |
silent = 1; |
|---|
| 93 |
break; |
|---|
| 94 |
case 's': |
|---|
| 95 |
s = optarg; |
|---|
| 96 |
break; |
|---|
| 97 |
case 'x': |
|---|
| 98 |
x = atoi(optarg); |
|---|
| 99 |
break; |
|---|
| 100 |
case 'y': |
|---|
| 101 |
y = atoi(optarg); |
|---|
| 102 |
break; |
|---|
| 103 |
case 'c': |
|---|
| 104 |
ncolor = atoi(optarg); |
|---|
| 105 |
break; |
|---|
| 106 |
default: |
|---|
| 107 |
usage(pname, EXIT_FAILURE); |
|---|
| 108 |
break; |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
if(argc - optind) |
|---|
| 113 |
usage(pname, EXIT_FAILURE); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
if(y <= 0 || y >= 27 || x <= 0 || x >= 27) |
|---|
| 117 |
{ |
|---|
| 118 |
fprintf(stderr, "%s: invalid size, max 26x26\n", pname); |
|---|
| 119 |
return EXIT_FAILURE; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
if((s && strlen(s) <= 2) || (!s && (ncolor <= 2 || ncolor > 16 ) )) |
|---|
| 123 |
{ |
|---|
| 124 |
fprintf(stderr, "%s: invalid number of color (must be between 2 and 16)\n", pname); |
|---|
| 125 |
return EXIT_FAILURE; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
srand(time(0)); |
|---|
| 129 |
gemmes_start_loop(y, x, ncolor, s, silent); |
|---|
| 130 |
|
|---|
| 131 |
return EXIT_SUCCESS; |
|---|
| 132 |
} |
|---|