1 /* $Id: sol.c,v 1.7 2002/03/02 21:02:21 sverrehu Exp $ */
2 /**************************************************************************
3 *
4 * FILE sol.c
5 * MODULE OF Card game.
6 *
7 * WRITTEN BY Sverre H. Huseby <shh@thathost.com>
8 *
9 **************************************************************************/
10
11 #include <shhmsg.h>
12 #include <shhopt.h>
13 #include <xalloc.h>
14
15 #include "win.h"
16 #include "game.h"
17 #include "score.h"
18 #include "suid.h"
19
20 /**************************************************************************
21 * *
22 * P R I V A T E F U N C T I O N S *
23 * *
24 **************************************************************************/
25
26 static void
outOfMemory(void)27 outOfMemory(void)
28 {
29 msgFatal("out of memory\n");
30 }
31
32 static void
version(void)33 version(void)
34 {
35 printf(
36 "%s " VERSION ", by Sverre H. Huseby "
37 "(compiled " COMPILED_DATE " by " COMPILED_BY ")\n",
38 msgGetName()
39 );
40 exit(0);
41 }
42
43 static void
usage(void)44 usage(void)
45 {
46 printf(
47 "usage: %s [options]\n"
48 "\n"
49 " -h, --help display this help and exit\n"
50 " -H, --highscores show highscores and exit\n"
51 " -M, --merge-highscores=FILE merge highscores from FILE and exit\n"
52 " -V, --version output version information and exit\n"
53 "\n"
54 "In addition, `normal' X11 options are allowed.\n",
55 msgGetName()
56 );
57 exit(0);
58 }
59
60 static void
highscores(void)61 highscores(void)
62 {
63 scoreDumpHighscores();
64 exit(0);
65 }
66
67 static void
merge(char * file)68 merge(char *file)
69 {
70 scoreMergeScoreFile(file);
71 scoreDumpHighscores();
72 exit(0);
73 }
74
75
76
77 /**************************************************************************
78 * *
79 * P U B L I C F U N C T I O N S *
80 * *
81 **************************************************************************/
82
83 int
main(int argc,char * argv[])84 main(int argc, char *argv[])
85 {
86 optStruct opt[] = {
87 /* short long type var/func special */
88 { 'h', "help", OPT_FLAG, usage, OPT_CALLFUNC },
89 { 'H', "highscores", OPT_FLAG, highscores, OPT_CALLFUNC },
90 { 'M', "merge-highscores",
91 OPT_STRING, merge, OPT_CALLFUNC },
92 { 'V', "version", OPT_FLAG, version, OPT_CALLFUNC },
93 { 0, 0, OPT_END, 0, 0 } /* no more options */
94 };
95
96 msgSetName(argv[0]);
97 xaSetErrFunc(outOfMemory);
98 suidInit();
99
100 /* to allow showing highscores before connecting to X11 server */
101 if (strcmp(msgGetName(), "solscores") == 0)
102 highscores(); /* exits the program */
103
104 winParseOptions(&argc, argv);
105 optParseOptions(&argc, argv, opt, 0);
106
107 #if 0
108 printf(
109 "\n"
110 " This is still considered BETA software. Please report any bugs,\n"
111 " and if you bother, please tell me if it worked too.\n"
112 " Currently, I may be reached as shh@thathost.com\n"
113 "\n"
114 );
115 #endif
116
117 gameInit();
118
119 winMainLoop();
120
121 gameFinish();
122
123 return 0;
124 }
125