root/main.c

Revision 106, 3.6 kB (checked in by ng, 5 years ago)

mise a jour licence

Line 
1 /***************************************************************************
2  *   This file is part of the 'gemmes' project                             *
3  *                                                                         *
4  *                                                                         *
5  *   Copyright (C) 2007 by                                                 *
6  *         GARCH Soufiane                                                  *
7  *         GUILLAUME Nicolas <ng@ngsoft-fr.com>                            *
8  *                                                                         *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; version 2 of the License only.          *
13  *   See the COPYING file.                                                 *
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 /* compilation conditionnelle seulement utilisée dans ce fichier */
26
27 #ifdef GEMMES_TXT /* on a de police seulement en mode texte */
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 }
Note: See TracBrowser for help on using the browser.