21 static char *defaultconfig
[] =
36 "bind joyright +right",
41 "bind 1 \"set saveslot 1\"",
42 "bind 2 \"set saveslot 2\"",
43 "bind 3 \"set saveslot 3\"",
44 "bind 4 \"set saveslot 4\"",
45 "bind 5 \"set saveslot 5\"",
46 "bind 6 \"set saveslot 6\"",
47 "bind 7 \"set saveslot 7\"",
48 "bind 8 \"set saveslot 8\"",
49 "bind 9 \"set saveslot 9\"",
50 "bind 0 \"set saveslot 0\"",
60 printf("\ngnuboy " VERSION
"\n");
63 static void copyright()
67 "Copyright (C) 2000-2001 Laguna and Gilgamesh\n"
68 "Portions contributed by other authors; see CREDITS for details.\n"
70 "This program is free software; you can redistribute it and/or modify\n"
71 "it under the terms of the GNU General Public License as published by\n"
72 "the Free Software Foundation; either version 2 of the License, or\n"
73 "(at your option) any later version.\n"
75 "This program is distributed in the hope that it will be useful,\n"
76 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
77 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
78 "GNU General Public License for more details.\n"
80 "You should have received a copy of the GNU General Public License\n"
81 "along with this program; if not, write to the Free Software\n"
82 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
86 static void usage(char *name
)
89 printf("Type %s --help for detailed help.\n\n", name
);
99 static void help(char *name
)
102 printf("Usage: %s [options] romfile\n", name
);
104 " --source FILE read rc commands from FILE\n"
105 " --bind KEY COMMAND bind KEY to perform COMMAND\n"
106 " --VAR=VALUE set rc variable VAR to VALUE\n"
107 " --VAR set VAR to 1 (turn on boolean options)\n"
108 " --no-VAR set VAR to 0 (turn off boolean options)\n"
109 " --showvars list all available rc variables\n"
110 " --help display this help and exit\n"
111 " --version output version information and exit\n"
112 " --copying show copying permissions\n"
118 static void version(char *name
)
120 printf("%s-" VERSION
"\n", name
);
131 while (ev_getevent(&ev
))
133 if (ev
.type
!= EV_PRESS
&& ev
.type
!= EV_RELEASE
)
135 st
= (ev
.type
!= EV_RELEASE
);
136 rc_dokey(ev
.code
, st
);
143 static void shutdown()
149 void die(char *fmt
, ...)
154 vfprintf(stderr
, fmt
, ap
);
159 static int bad_signals
[] =
161 /* These are all standard, so no need to #ifdef them... */
162 SIGINT
, SIGSEGV
, SIGTERM
, SIGFPE
, SIGABRT
, SIGILL
,
172 static void fatalsignal(int s
)
174 die("Signal %d\n", s
);
177 static void catch_signals()
180 for (i
= 0; bad_signals
[i
]; i
++)
181 signal(bad_signals
[i
], fatalsignal
);
186 static char *base(char *s
)
195 int main(int argc
, char *argv
[])
198 char *opt
, *arg
, *cmd
, *s
, *rom
= 0;
200 /* Avoid initializing video if we don't have to */
201 for (i
= 1; i
< argc
; i
++)
203 if (!strcmp(argv
[i
], "--help"))
205 else if (!strcmp(argv
[i
], "--version"))
206 version(base(argv
[0]));
207 else if (!strcmp(argv
[i
], "--copying"))
209 else if (!strcmp(argv
[i
], "--bind")) i
+= 2;
210 else if (!strcmp(argv
[i
], "--source")) i
++;
211 else if (!strcmp(argv
[i
], "--showvars"))
216 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-');
217 else if (argv
[i
][0] == '-' && argv
[i
][1]);
221 if (!rom
) usage(base(argv
[0]));
223 /* If we have special perms, drop them ASAP! */
232 for (i
= 0; defaultconfig
[i
]; i
++)
233 rc_command(defaultconfig
[i
]);
235 cmd
= malloc(strlen(rom
) + 11);
236 sprintf(cmd
, "source %s", rom
);
237 s
= strchr(cmd
, '.');
242 for (i
= 1; i
< argc
; i
++)
244 if (!strcmp(argv
[i
], "--bind"))
246 if (i
+ 2 >= argc
) die("missing arguments to bind\n");
247 cmd
= malloc(strlen(argv
[i
+1]) + strlen(argv
[i
+2]) + 9);
248 sprintf(cmd
, "bind %s \"%s\"", argv
[i
+1], argv
[i
+2]);
253 else if (!strcmp(argv
[i
], "--source"))
255 if (i
+ 1 >= argc
) die("missing argument to source\n");
256 cmd
= malloc(strlen(argv
[i
+1]) + 6);
257 sprintf(cmd
, "source %s", argv
[++i
]);
261 else if (!strncmp(argv
[i
], "--no-", 5))
263 opt
= strdup(argv
[i
]+5);
264 while ((s
= strchr(opt
, '-'))) *s
= '_';
265 cmd
= malloc(strlen(opt
) + 7);
266 sprintf(cmd
, "set %s 0", opt
);
271 else if (argv
[i
][0] == '-' && argv
[i
][1] == '-')
273 opt
= strdup(argv
[i
]+2);
274 if ((s
= strchr(opt
, '=')))
280 while ((s
= strchr(opt
, '-'))) *s
= '_';
281 while ((s
= strchr(arg
, ','))) *s
= ' ';
283 cmd
= malloc(strlen(opt
) + strlen(arg
) + 6);
284 sprintf(cmd
, "set %s %s", opt
, arg
);
290 /* short options not yet implemented */
291 else if (argv
[i
][0] == '-' && argv
[i
][1]);
294 /* FIXME - make interface modules responsible for atexit() */