X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fmisc.c;h=7f6bc4bc7ef705f72ebda309f7c825053990a360;hb=209871b6f17880f98d41cf7d7953f6bf2227a16c;hp=19c90ac508010a6cc72d3b5c9a30e104294bceda;hpb=0a87fde47bcff35f196024766f8d0d00319a28d1;p=rocksndiamonds.git diff --git a/src/misc.c b/src/misc.c index 19c90ac5..7f6bc4bc 100644 --- a/src/misc.c +++ b/src/misc.c @@ -26,7 +26,7 @@ #include "sound.h" #include "random.h" #include "joystick.h" - +#include "files.h" #ifdef MSDOS volatile unsigned long counter = 0; @@ -337,15 +337,15 @@ void GetOptions(char *argv[]) char *option_arg = NULL; int option_len = strlen(option); + if (option_len >= MAX_OPTION_LEN) + Error(ERR_EXIT_HELP, "unrecognized option '%s'", option); + strcpy(option_str, option); /* copy argument into buffer */ option = option_str; if (strcmp(option, "--") == 0) /* stop scanning arguments */ break; - if (option_len >= MAX_OPTION_LEN) - Error(ERR_EXIT_HELP, "unrecognized option '%s'", option); - if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */ option++; @@ -384,8 +384,6 @@ void GetOptions(char *argv[]) options.display_name = option_arg; if (option_arg == next_option) options_left++; - - printf("--display == '%s'\n", options.display_name); } else if (strncmp(option, "-basepath", option_len) == 0) { @@ -396,8 +394,6 @@ void GetOptions(char *argv[]) if (option_arg == next_option) options_left++; - printf("--basepath == '%s'\n", options.base_directory); - /* adjust path for level directory accordingly */ options.level_directory = getPath2(options.base_directory, LEVELS_DIRECTORY); @@ -410,42 +406,32 @@ void GetOptions(char *argv[]) options.level_directory = option_arg; if (option_arg == next_option) options_left++; - - printf("--levels == '%s'\n", options.level_directory); } else if (strncmp(option, "-network", option_len) == 0) { - printf("--network\n"); - options.network = TRUE; } else if (strncmp(option, "-serveronly", option_len) == 0) { - printf("--serveronly\n"); - options.serveronly = TRUE; } else if (strncmp(option, "-verbose", option_len) == 0) { - printf("--verbose\n"); - options.verbose = TRUE; } else if (*option == '-') + { Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str); + } else if (options.server_host == NULL) { options.server_host = *options_left; - - printf("server.name == '%s'\n", options.server_host); } else if (options.server_port == 0) { options.server_port = atoi(*options_left); if (options.server_port < 1024) Error(ERR_EXIT_HELP, "bad port number '%d'", options.server_port); - - printf("port == %d\n", options.server_port); } else Error(ERR_EXIT_HELP, "too many arguments"); @@ -457,6 +443,19 @@ void GetOptions(char *argv[]) void Error(int mode, char *format, ...) { char *process_name = ""; + FILE *error = stderr; + + /* display warnings only when running in verbose mode */ + if (mode & ERR_WARN && !options.verbose) + return; + +#ifdef MSDOS + if ((error = openErrorFile()) == NULL) + { + printf("Cannot write to error output file!\n"); + CloseAllAndExit(1); + } +#endif if (mode & ERR_SOUND_SERVER) process_name = " sound server"; @@ -469,26 +468,30 @@ void Error(int mode, char *format, ...) { va_list ap; - fprintf(stderr, "%s%s: ", program_name, process_name); + fprintf(error, "%s%s: ", program_name, process_name); if (mode & ERR_WARN) - fprintf(stderr, "warning: "); + fprintf(error, "warning: "); va_start(ap, format); - vfprintf(stderr, format, ap); + vfprintf(error, format, ap); va_end(ap); - fprintf(stderr, "\n"); + fprintf(error, "\n"); } if (mode & ERR_HELP) - fprintf(stderr, "%s: Try option '--help' for more information.\n", + fprintf(error, "%s: Try option '--help' for more information.\n", program_name); if (mode & ERR_EXIT) - { - fprintf(stderr, "%s%s: aborting\n", program_name, process_name); + fprintf(error, "%s%s: aborting\n", program_name, process_name); + + if (error != stderr) + fclose(error); + if (mode & ERR_EXIT) + { if (mode & ERR_FROM_SERVER) exit(1); /* child process: normal exit */ else @@ -578,21 +581,53 @@ void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode) { XK_End, "XK_End", "end" }, { XK_Page_Up, "XK_Page_Up", "page up" }, { XK_Page_Down, "XK_Page_Down", "page down" }, - { XK_space, "XK_space", "space" }, - /* even more special keys */ - { XK_adiaeresis, "XK_adiaeresis", "ä" }, - { XK_odiaeresis, "XK_odiaeresis", "ö" }, - { XK_udiaeresis, "XK_udiaeresis", "ü" }, + + /* ASCII 0x20 to 0x40 keys (except numbers) */ + { XK_space, "XK_space", "space" }, + { XK_exclam, "XK_exclam", "!" }, + { XK_quotedbl, "XK_quotedbl", "\"" }, + { XK_numbersign, "XK_numbersign", "#" }, + { XK_dollar, "XK_dollar", "$" }, + { XK_percent, "XK_percent", "%" }, + { XK_ampersand, "XK_ampersand", "&" }, { XK_apostrophe, "XK_apostrophe", "'" }, + { XK_parenleft, "XK_parenleft", "(" }, + { XK_parenright, "XK_parenright", ")" }, + { XK_asterisk, "XK_asterisk", "*" }, { XK_plus, "XK_plus", "+" }, - { XK_minus, "XK_minus", "-" }, { XK_comma, "XK_comma", "," }, + { XK_minus, "XK_minus", "-" }, { XK_period, "XK_period", "." }, - { XK_numbersign, "XK_numbersign", "#" }, + { XK_slash, "XK_slash", "/" }, + { XK_colon, "XK_colon", ":" }, + { XK_semicolon, "XK_semicolon", ";" }, { XK_less, "XK_less", "less" }, + { XK_equal, "XK_equal", "equal" }, { XK_greater, "XK_greater", "greater" }, + { XK_question, "XK_question", "?" }, + { XK_at, "XK_at", "@" }, + + /* more ASCII keys */ + { XK_bracketleft, "XK_bracketleft", "[" }, + { XK_backslash, "XK_backslash", "backslash" }, + { XK_bracketright, "XK_bracketright", "]" }, { XK_asciicircum, "XK_asciicircum", "circumflex" }, + { XK_underscore, "XK_underscore", "_" }, + { XK_grave, "XK_grave", "grave" }, + { XK_quoteleft, "XK_quoteleft", "quote left" }, + { XK_braceleft, "XK_braceleft", "brace left" }, + { XK_bar, "XK_bar", "bar" }, + { XK_braceright, "XK_braceright", "brace right" }, + { XK_asciitilde, "XK_asciitilde", "ascii tilde" }, + + /* special (non-ASCII) keys */ + { XK_Adiaeresis, "XK_Adiaeresis", "Ä" }, + { XK_Odiaeresis, "XK_Odiaeresis", "Ö" }, + { XK_Udiaeresis, "XK_Udiaeresis", "Ü" }, + { XK_adiaeresis, "XK_adiaeresis", "ä" }, + { XK_odiaeresis, "XK_odiaeresis", "ö" }, + { XK_udiaeresis, "XK_udiaeresis", "ü" }, { XK_ssharp, "XK_ssharp", "sharp s" }, /* end-of-array identifier */ @@ -849,7 +884,29 @@ int getJoySymbolFromJoyName(char *name) return joysymbol; } +int getJoystickNrFromDeviceName(char *device_name) +{ + char c; + int joystick_nr = 0; + + if (device_name == NULL || device_name[0] == '\0') + return 0; + + c = device_name[strlen(device_name) - 1]; + + if (c >= '0' && c <= '9') + joystick_nr = (int)(c - '0'); + + if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS) + joystick_nr = 0; + + return joystick_nr; +} + +/* ----------------------------------------------------------------- */ /* the following is only for debugging purpose and normally not used */ +/* ----------------------------------------------------------------- */ + #define DEBUG_NUM_TIMESTAMPS 3 void debug_print_timestamp(int counter_nr, char *message) @@ -867,28 +924,3 @@ void debug_print_timestamp(int counter_nr, char *message) counter[counter_nr][1] = Counter(); } - -void print_debug(char *s) -{ - FILE *f; - - if (!s) - { - if ((f = fopen("debug.asc", "w")) == NULL) - { - printf("Cannot write to debug file!\n"); - exit(1); - } - fclose(f); - return; - } - - if ((f = fopen("debug.asc", "a")) == NULL) - { - printf("Cannot append to debug file!\n"); - exit(1); - } - - fprintf(f, "%s\r\n", s); - fclose(f); -}