1 /***********************************************************
2 * Artsoft Retro-Game Library *
3 *----------------------------------------------------------*
4 * (c) 1994-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
16 #include <sys/types.h>
24 #if !defined(PLATFORM_WIN32)
26 #include <sys/param.h>
35 #if defined(PLATFORM_MSDOS)
36 volatile unsigned long counter = 0;
38 void increment_counter()
43 END_OF_FUNCTION(increment_counter);
47 /* maximal allowed length of a command line option */
48 #define MAX_OPTION_LEN 256
51 static unsigned long mainCounter(int mode)
53 static unsigned long base_ms = 0;
54 unsigned long current_ms;
55 unsigned long counter_ms;
57 current_ms = SDL_GetTicks();
59 /* reset base time in case of counter initializing or wrap-around */
60 if (mode == INIT_COUNTER || current_ms < base_ms)
63 counter_ms = current_ms - base_ms;
65 return counter_ms; /* return milliseconds since last init */
68 #else /* !TARGET_SDL */
70 #if defined(PLATFORM_UNIX)
71 static unsigned long mainCounter(int mode)
73 static struct timeval base_time = { 0, 0 };
74 struct timeval current_time;
75 unsigned long counter_ms;
77 gettimeofday(¤t_time, NULL);
79 /* reset base time in case of counter initializing or wrap-around */
80 if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec)
81 base_time = current_time;
83 counter_ms = (current_time.tv_sec - base_time.tv_sec) * 1000
84 + (current_time.tv_usec - base_time.tv_usec) / 1000;
86 return counter_ms; /* return milliseconds since last init */
88 #endif /* PLATFORM_UNIX */
89 #endif /* !TARGET_SDL */
91 void InitCounter() /* set counter back to zero */
93 #if !defined(PLATFORM_MSDOS)
94 mainCounter(INIT_COUNTER);
96 LOCK_VARIABLE(counter);
97 LOCK_FUNCTION(increment_counter);
98 install_int_ex(increment_counter, BPS_TO_TIMER(100));
102 unsigned long Counter() /* get milliseconds since last call of InitCounter() */
104 #if !defined(PLATFORM_MSDOS)
105 return mainCounter(READ_COUNTER);
107 return (counter * 10);
111 static void sleep_milliseconds(unsigned long milliseconds_delay)
113 boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE);
116 #if defined(PLATFORM_MSDOS)
117 /* don't use select() to perform waiting operations under DOS
118 environment; always use a busy loop for waiting instead */
119 do_busy_waiting = TRUE;
125 /* we want to wait only a few ms -- if we assume that we have a
126 kernel timer resolution of 10 ms, we would wait far to long;
127 therefore it's better to do a short interval of busy waiting
128 to get our sleeping time more accurate */
130 unsigned long base_counter = Counter(), actual_counter = Counter();
132 while (actual_counter < base_counter + milliseconds_delay &&
133 actual_counter >= base_counter)
134 actual_counter = Counter();
138 #if defined(TARGET_SDL)
139 SDL_Delay(milliseconds_delay);
140 #elif defined(TARGET_ALLEGRO)
141 rest(milliseconds_delay);
143 struct timeval delay;
145 delay.tv_sec = milliseconds_delay / 1000;
146 delay.tv_usec = 1000 * (milliseconds_delay % 1000);
148 if (select(0, NULL, NULL, NULL, &delay) != 0)
149 Error(ERR_WARN, "sleep_milliseconds(): select() failed");
154 void Delay(unsigned long delay) /* Sleep specified number of milliseconds */
156 sleep_milliseconds(delay);
159 boolean FrameReached(unsigned long *frame_counter_var,
160 unsigned long frame_delay)
162 unsigned long actual_frame_counter = FrameCounter;
164 if (actual_frame_counter < *frame_counter_var + frame_delay &&
165 actual_frame_counter >= *frame_counter_var)
168 *frame_counter_var = actual_frame_counter;
173 boolean DelayReached(unsigned long *counter_var,
176 unsigned long actual_counter = Counter();
178 if (actual_counter < *counter_var + delay &&
179 actual_counter >= *counter_var)
182 *counter_var = actual_counter;
187 void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
189 unsigned long actual_counter;
193 actual_counter = Counter();
195 if (actual_counter < *counter_var + delay &&
196 actual_counter >= *counter_var)
197 sleep_milliseconds((*counter_var + delay - actual_counter) / 2);
202 *counter_var = actual_counter;
205 /* int2str() returns a number converted to a string;
206 the used memory is static, but will be overwritten by later calls,
207 so if you want to save the result, copy it to a private string buffer;
208 there can be 10 local calls of int2str() without buffering the result --
209 the 11th call will then destroy the result from the first call and so on.
212 char *int2str(int number, int size)
214 static char shift_array[10][40];
215 static int shift_counter = 0;
216 char *s = shift_array[shift_counter];
218 shift_counter = (shift_counter + 1) % 10;
225 sprintf(s, " %09d", number);
226 return &s[strlen(s) - size];
230 sprintf(s, "%d", number);
235 unsigned int SimpleRND(unsigned int max)
237 #if defined(TARGET_SDL)
238 static unsigned long root = 654321;
239 unsigned long current_ms;
241 current_ms = SDL_GetTicks();
242 root = root * 4253261 + current_ms;
245 static unsigned long root = 654321;
246 struct timeval current_time;
248 gettimeofday(¤t_time, NULL);
249 root = root * 4253261 + current_time.tv_sec + current_time.tv_usec;
255 static unsigned int last_RND_value = 0;
257 unsigned int last_RND()
259 return last_RND_value;
263 unsigned int RND(unsigned int max)
266 return (last_RND_value = random_linux_libc() % max);
268 return (random_linux_libc() % max);
272 unsigned int InitRND(long seed)
274 #if defined(TARGET_SDL)
275 unsigned long current_ms;
277 if (seed == NEW_RANDOMIZE)
279 current_ms = SDL_GetTicks();
280 srandom_linux_libc((unsigned int) current_ms);
281 return (unsigned int) current_ms;
285 srandom_linux_libc((unsigned int) seed);
286 return (unsigned int) seed;
289 struct timeval current_time;
291 if (seed == NEW_RANDOMIZE)
293 gettimeofday(¤t_time, NULL);
294 srandom_linux_libc((unsigned int) current_time.tv_usec);
295 return (unsigned int) current_time.tv_usec;
299 srandom_linux_libc((unsigned int) seed);
300 return (unsigned int) seed;
307 #if defined(PLATFORM_WIN32)
308 return ANONYMOUS_NAME;
310 static char *login_name = NULL;
312 if (login_name == NULL)
316 if ((pwd = getpwuid(getuid())) == NULL)
317 login_name = ANONYMOUS_NAME;
319 login_name = getStringCopy(pwd->pw_name);
328 #if defined(PLATFORM_UNIX)
331 if ((pwd = getpwuid(getuid())) == NULL || strlen(pwd->pw_gecos) == 0)
332 return ANONYMOUS_NAME;
335 static char real_name[1024];
336 char *from_ptr = pwd->pw_gecos, *to_ptr = real_name;
338 if (strchr(pwd->pw_gecos, 'ß') == NULL)
339 return pwd->pw_gecos;
341 /* the user's real name contains a 'ß' character (german sharp s),
342 which has no equivalent in upper case letters (which our fonts use) */
343 while (*from_ptr != '\0' && (long)(to_ptr - real_name) < 1024 - 2)
345 if (*from_ptr != 'ß')
346 *to_ptr++ = *from_ptr++;
358 #else /* !PLATFORM_UNIX */
359 return ANONYMOUS_NAME;
365 #if defined(PLATFORM_UNIX)
366 static char *home_dir = NULL;
368 if (home_dir == NULL)
370 if ((home_dir = getenv("HOME")) == NULL)
374 if ((pwd = getpwuid(getuid())) == NULL)
377 home_dir = getStringCopy(pwd->pw_dir);
387 char *getPath2(char *path1, char *path2)
389 char *complete_path = checked_malloc(strlen(path1) + 1 +
392 sprintf(complete_path, "%s/%s", path1, path2);
393 return complete_path;
396 char *getPath3(char *path1, char *path2, char *path3)
398 char *complete_path = checked_malloc(strlen(path1) + 1 +
402 sprintf(complete_path, "%s/%s/%s", path1, path2, path3);
403 return complete_path;
406 static char *getStringCat2(char *s1, char *s2)
408 char *complete_string = checked_malloc(strlen(s1) + strlen(s2) + 1);
410 sprintf(complete_string, "%s%s", s1, s2);
411 return complete_string;
414 char *getStringCopy(char *s)
421 s_copy = checked_malloc(strlen(s) + 1);
427 char *getStringToLower(char *s)
429 char *s_copy = checked_malloc(strlen(s) + 1);
430 char *s_ptr = s_copy;
433 *s_ptr++ = tolower(*s++);
439 static void printUsage()
442 "Usage: %s [OPTION]... [HOSTNAME [PORT]]\n"
445 " -d, --display HOSTNAME[:SCREEN] specify X server display\n"
446 " -b, --basepath DIRECTORY alternative base DIRECTORY\n"
447 " -l, --level DIRECTORY alternative level DIRECTORY\n"
448 " -g, --graphics DIRECTORY alternative graphics DIRECTORY\n"
449 " -s, --sounds DIRECTORY alternative sounds DIRECTORY\n"
450 " -m, --music DIRECTORY alternative music DIRECTORY\n"
451 " -n, --network network multiplayer game\n"
452 " --serveronly only start network server\n"
453 " -v, --verbose verbose mode\n"
454 " --debug display debugging information\n"
455 " -e, --execute COMMAND execute batch COMMAND:\n"
457 "Valid commands for '--execute' option:\n"
458 " \"print graphicsinfo.conf\" print default graphics config\n"
459 " \"print soundsinfo.conf\" print default sounds config\n"
460 " \"print musicinfo.conf\" print default music config\n"
461 " \"dump tape FILE\" dump tape data from FILE\n"
462 " \"autoplay LEVELDIR\" play level tapes for LEVELDIR\n"
464 program.command_basename);
467 void GetOptions(char *argv[])
469 char **options_left = &argv[1];
471 /* initialize global program options */
472 options.display_name = NULL;
473 options.server_host = NULL;
474 options.server_port = 0;
475 options.ro_base_directory = RO_BASE_PATH;
476 options.rw_base_directory = RW_BASE_PATH;
477 options.level_directory = RO_BASE_PATH "/" LEVELS_DIRECTORY;
478 options.graphics_directory = RO_BASE_PATH "/" GRAPHICS_DIRECTORY;
479 options.sounds_directory = RO_BASE_PATH "/" SOUNDS_DIRECTORY;
480 options.music_directory = RO_BASE_PATH "/" MUSIC_DIRECTORY;
481 options.execute_command = NULL;
482 options.serveronly = FALSE;
483 options.network = FALSE;
484 options.verbose = FALSE;
485 options.debug = FALSE;
487 while (*options_left)
489 char option_str[MAX_OPTION_LEN];
490 char *option = options_left[0];
491 char *next_option = options_left[1];
492 char *option_arg = NULL;
493 int option_len = strlen(option);
495 if (option_len >= MAX_OPTION_LEN)
496 Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
498 strcpy(option_str, option); /* copy argument into buffer */
501 if (strcmp(option, "--") == 0) /* stop scanning arguments */
504 if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */
507 option_arg = strchr(option, '=');
508 if (option_arg == NULL) /* no '=' in option */
509 option_arg = next_option;
512 *option_arg++ = '\0'; /* cut argument from option */
513 if (*option_arg == '\0') /* no argument after '=' */
514 Error(ERR_EXIT_HELP, "option '%s' has invalid argument", option_str);
517 option_len = strlen(option);
519 if (strcmp(option, "-") == 0)
520 Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
521 else if (strncmp(option, "-help", option_len) == 0)
527 else if (strncmp(option, "-display", option_len) == 0)
529 if (option_arg == NULL)
530 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
532 options.display_name = option_arg;
533 if (option_arg == next_option)
536 else if (strncmp(option, "-basepath", option_len) == 0)
538 if (option_arg == NULL)
539 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
541 /* this should be extended to separate options for ro and rw data */
542 options.ro_base_directory = option_arg;
543 options.rw_base_directory = option_arg;
544 if (option_arg == next_option)
547 /* adjust path for level directory accordingly */
548 options.level_directory =
549 getPath2(options.ro_base_directory, LEVELS_DIRECTORY);
551 else if (strncmp(option, "-levels", option_len) == 0)
553 if (option_arg == NULL)
554 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
556 options.level_directory = option_arg;
557 if (option_arg == next_option)
560 else if (strncmp(option, "-graphics", option_len) == 0)
562 if (option_arg == NULL)
563 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
565 options.graphics_directory = option_arg;
566 if (option_arg == next_option)
569 else if (strncmp(option, "-sounds", option_len) == 0)
571 if (option_arg == NULL)
572 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
574 options.sounds_directory = option_arg;
575 if (option_arg == next_option)
578 else if (strncmp(option, "-music", option_len) == 0)
580 if (option_arg == NULL)
581 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
583 options.music_directory = option_arg;
584 if (option_arg == next_option)
587 else if (strncmp(option, "-network", option_len) == 0)
589 options.network = TRUE;
591 else if (strncmp(option, "-serveronly", option_len) == 0)
593 options.serveronly = TRUE;
595 else if (strncmp(option, "-verbose", option_len) == 0)
597 options.verbose = TRUE;
599 else if (strncmp(option, "-debug", option_len) == 0)
601 options.debug = TRUE;
603 else if (strncmp(option, "-execute", option_len) == 0)
605 if (option_arg == NULL)
606 Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
608 options.execute_command = option_arg;
609 if (option_arg == next_option)
612 else if (*option == '-')
614 Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
616 else if (options.server_host == NULL)
618 options.server_host = *options_left;
620 else if (options.server_port == 0)
622 options.server_port = atoi(*options_left);
623 if (options.server_port < 1024)
624 Error(ERR_EXIT_HELP, "bad port number '%d'", options.server_port);
627 Error(ERR_EXIT_HELP, "too many arguments");
633 /* used by SetError() and GetError() to store internal error messages */
634 static char internal_error[1024]; /* this is bad */
636 void SetError(char *format, ...)
640 va_start(ap, format);
641 vsprintf(internal_error, format, ap);
647 return internal_error;
650 void Error(int mode, char *format, ...)
652 char *process_name = "";
653 FILE *error = stderr;
654 char *newline = "\n";
656 /* display warnings only when running in verbose mode */
657 if (mode & ERR_WARN && !options.verbose)
660 #if defined(PLATFORM_MSDOS)
663 if ((error = openErrorFile()) == NULL)
665 printf("Cannot write to error output file!%s", newline);
666 program.exit_function(1);
670 if (mode & ERR_SOUND_SERVER)
671 process_name = " sound server";
672 else if (mode & ERR_NETWORK_SERVER)
673 process_name = " network server";
674 else if (mode & ERR_NETWORK_CLIENT)
675 process_name = " network client **";
681 fprintf(error, "%s%s: ", program.command_basename, process_name);
684 fprintf(error, "warning: ");
686 va_start(ap, format);
687 vfprintf(error, format, ap);
690 fprintf(error, "%s", newline);
694 fprintf(error, "%s: Try option '--help' for more information.%s",
695 program.command_basename, newline);
698 fprintf(error, "%s%s: aborting%s",
699 program.command_basename, process_name, newline);
706 if (mode & ERR_FROM_SERVER)
707 exit(1); /* child process: normal exit */
709 program.exit_function(1); /* main process: clean up stuff */
713 void *checked_malloc(unsigned long size)
720 Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size);
725 void *checked_calloc(unsigned long size)
729 ptr = calloc(1, size);
732 Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size);
737 void *checked_realloc(void *ptr, unsigned long size)
739 ptr = realloc(ptr, size);
742 Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size);
747 inline void swap_numbers(int *i1, int *i2)
755 inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2)
767 short getFile16BitInteger(FILE *file, int byte_order)
769 if (byte_order == BYTE_ORDER_BIG_ENDIAN)
770 return ((fgetc(file) << 8) |
772 else /* BYTE_ORDER_LITTLE_ENDIAN */
773 return ((fgetc(file) << 0) |
777 void putFile16BitInteger(FILE *file, short value, int byte_order)
779 if (byte_order == BYTE_ORDER_BIG_ENDIAN)
781 fputc((value >> 8) & 0xff, file);
782 fputc((value >> 0) & 0xff, file);
784 else /* BYTE_ORDER_LITTLE_ENDIAN */
786 fputc((value >> 0) & 0xff, file);
787 fputc((value >> 8) & 0xff, file);
791 int getFile32BitInteger(FILE *file, int byte_order)
793 if (byte_order == BYTE_ORDER_BIG_ENDIAN)
794 return ((fgetc(file) << 24) |
795 (fgetc(file) << 16) |
798 else /* BYTE_ORDER_LITTLE_ENDIAN */
799 return ((fgetc(file) << 0) |
801 (fgetc(file) << 16) |
802 (fgetc(file) << 24));
805 void putFile32BitInteger(FILE *file, int value, int byte_order)
807 if (byte_order == BYTE_ORDER_BIG_ENDIAN)
809 fputc((value >> 24) & 0xff, file);
810 fputc((value >> 16) & 0xff, file);
811 fputc((value >> 8) & 0xff, file);
812 fputc((value >> 0) & 0xff, file);
814 else /* BYTE_ORDER_LITTLE_ENDIAN */
816 fputc((value >> 0) & 0xff, file);
817 fputc((value >> 8) & 0xff, file);
818 fputc((value >> 16) & 0xff, file);
819 fputc((value >> 24) & 0xff, file);
823 boolean getFileChunk(FILE *file, char *chunk_name, int *chunk_size,
826 const int chunk_name_length = 4;
828 /* read chunk name */
829 fgets(chunk_name, chunk_name_length + 1, file);
831 if (chunk_size != NULL)
833 /* read chunk size */
834 *chunk_size = getFile32BitInteger(file, byte_order);
837 return (feof(file) || ferror(file) ? FALSE : TRUE);
840 void putFileChunk(FILE *file, char *chunk_name, int chunk_size,
843 /* write chunk name */
844 fputs(chunk_name, file);
848 /* write chunk size */
849 putFile32BitInteger(file, chunk_size, byte_order);
853 int getFileVersion(FILE *file)
855 int version_major, version_minor, version_patch;
857 version_major = fgetc(file);
858 version_minor = fgetc(file);
859 version_patch = fgetc(file);
860 fgetc(file); /* not used */
862 return VERSION_IDENT(version_major, version_minor, version_patch);
865 void putFileVersion(FILE *file, int version)
867 int version_major = VERSION_MAJOR(version);
868 int version_minor = VERSION_MINOR(version);
869 int version_patch = VERSION_PATCH(version);
871 fputc(version_major, file);
872 fputc(version_minor, file);
873 fputc(version_patch, file);
874 fputc(0, file); /* not used */
877 void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes)
879 while (bytes-- && !feof(file))
883 void WriteUnusedBytesToFile(FILE *file, unsigned long bytes)
890 /* ------------------------------------------------------------------------- */
891 /* functions to translate key identifiers between different format */
892 /* ------------------------------------------------------------------------- */
894 #define TRANSLATE_KEYSYM_TO_KEYNAME 0
895 #define TRANSLATE_KEYSYM_TO_X11KEYNAME 1
896 #define TRANSLATE_KEYNAME_TO_KEYSYM 2
897 #define TRANSLATE_X11KEYNAME_TO_KEYSYM 3
899 void translate_keyname(Key *keysym, char **x11name, char **name, int mode)
908 /* normal cursor keys */
909 { KSYM_Left, "XK_Left", "cursor left" },
910 { KSYM_Right, "XK_Right", "cursor right" },
911 { KSYM_Up, "XK_Up", "cursor up" },
912 { KSYM_Down, "XK_Down", "cursor down" },
914 /* keypad cursor keys */
916 { KSYM_KP_Left, "XK_KP_Left", "keypad left" },
917 { KSYM_KP_Right, "XK_KP_Right", "keypad right" },
918 { KSYM_KP_Up, "XK_KP_Up", "keypad up" },
919 { KSYM_KP_Down, "XK_KP_Down", "keypad down" },
922 /* other keypad keys */
924 { KSYM_KP_Enter, "XK_KP_Enter", "keypad enter" },
925 { KSYM_KP_Add, "XK_KP_Add", "keypad +" },
926 { KSYM_KP_Subtract, "XK_KP_Subtract", "keypad -" },
927 { KSYM_KP_Multiply, "XK_KP_Multiply", "keypad mltply" },
928 { KSYM_KP_Divide, "XK_KP_Divide", "keypad /" },
929 { KSYM_KP_Separator,"XK_KP_Separator", "keypad ," },
933 { KSYM_Shift_L, "XK_Shift_L", "left shift" },
934 { KSYM_Shift_R, "XK_Shift_R", "right shift" },
935 { KSYM_Control_L, "XK_Control_L", "left control" },
936 { KSYM_Control_R, "XK_Control_R", "right control" },
937 { KSYM_Meta_L, "XK_Meta_L", "left meta" },
938 { KSYM_Meta_R, "XK_Meta_R", "right meta" },
939 { KSYM_Alt_L, "XK_Alt_L", "left alt" },
940 { KSYM_Alt_R, "XK_Alt_R", "right alt" },
941 { KSYM_Super_L, "XK_Super_L", "left super" }, /* Win-L */
942 { KSYM_Super_R, "XK_Super_R", "right super" }, /* Win-R */
943 { KSYM_Mode_switch, "XK_Mode_switch", "mode switch" }, /* Alt-R */
944 { KSYM_Multi_key, "XK_Multi_key", "multi key" }, /* Ctrl-R */
946 /* some special keys */
947 { KSYM_BackSpace, "XK_BackSpace", "backspace" },
948 { KSYM_Delete, "XK_Delete", "delete" },
949 { KSYM_Insert, "XK_Insert", "insert" },
950 { KSYM_Tab, "XK_Tab", "tab" },
951 { KSYM_Home, "XK_Home", "home" },
952 { KSYM_End, "XK_End", "end" },
953 { KSYM_Page_Up, "XK_Page_Up", "page up" },
954 { KSYM_Page_Down, "XK_Page_Down", "page down" },
955 { KSYM_Menu, "XK_Menu", "menu" }, /* Win-Menu */
957 /* ASCII 0x20 to 0x40 keys (except numbers) */
958 { KSYM_space, "XK_space", "space" },
959 { KSYM_exclam, "XK_exclam", "!" },
960 { KSYM_quotedbl, "XK_quotedbl", "\"" },
961 { KSYM_numbersign, "XK_numbersign", "#" },
962 { KSYM_dollar, "XK_dollar", "$" },
963 { KSYM_percent, "XK_percent", "%" },
964 { KSYM_ampersand, "XK_ampersand", "&" },
965 { KSYM_apostrophe, "XK_apostrophe", "'" },
966 { KSYM_parenleft, "XK_parenleft", "(" },
967 { KSYM_parenright, "XK_parenright", ")" },
968 { KSYM_asterisk, "XK_asterisk", "*" },
969 { KSYM_plus, "XK_plus", "+" },
970 { KSYM_comma, "XK_comma", "," },
971 { KSYM_minus, "XK_minus", "-" },
972 { KSYM_period, "XK_period", "." },
973 { KSYM_slash, "XK_slash", "/" },
974 { KSYM_colon, "XK_colon", ":" },
975 { KSYM_semicolon, "XK_semicolon", ";" },
976 { KSYM_less, "XK_less", "<" },
977 { KSYM_equal, "XK_equal", "=" },
978 { KSYM_greater, "XK_greater", ">" },
979 { KSYM_question, "XK_question", "?" },
980 { KSYM_at, "XK_at", "@" },
982 /* more ASCII keys */
983 { KSYM_bracketleft, "XK_bracketleft", "[" },
984 { KSYM_backslash, "XK_backslash", "backslash" },
985 { KSYM_bracketright,"XK_bracketright", "]" },
986 { KSYM_asciicircum, "XK_asciicircum", "circumflex" },
987 { KSYM_underscore, "XK_underscore", "_" },
988 { KSYM_grave, "XK_grave", "grave" },
989 { KSYM_quoteleft, "XK_quoteleft", "quote left" },
990 { KSYM_braceleft, "XK_braceleft", "brace left" },
991 { KSYM_bar, "XK_bar", "bar" },
992 { KSYM_braceright, "XK_braceright", "brace right" },
993 { KSYM_asciitilde, "XK_asciitilde", "ascii tilde" },
995 /* special (non-ASCII) keys */
996 { KSYM_Adiaeresis, "XK_Adiaeresis", "Ä" },
997 { KSYM_Odiaeresis, "XK_Odiaeresis", "Ö" },
998 { KSYM_Udiaeresis, "XK_Udiaeresis", "Ü" },
999 { KSYM_adiaeresis, "XK_adiaeresis", "ä" },
1000 { KSYM_odiaeresis, "XK_odiaeresis", "ö" },
1001 { KSYM_udiaeresis, "XK_udiaeresis", "ü" },
1002 { KSYM_ssharp, "XK_ssharp", "sharp s" },
1004 /* end-of-array identifier */
1010 if (mode == TRANSLATE_KEYSYM_TO_KEYNAME)
1012 static char name_buffer[30];
1015 if (key >= KSYM_A && key <= KSYM_Z)
1016 sprintf(name_buffer, "%c", 'A' + (char)(key - KSYM_A));
1017 else if (key >= KSYM_a && key <= KSYM_z)
1018 sprintf(name_buffer, "%c", 'a' + (char)(key - KSYM_a));
1019 else if (key >= KSYM_0 && key <= KSYM_9)
1020 sprintf(name_buffer, "%c", '0' + (char)(key - KSYM_0));
1021 else if (key >= KSYM_KP_0 && key <= KSYM_KP_9)
1022 sprintf(name_buffer, "keypad %c", '0' + (char)(key - KSYM_KP_0));
1023 else if (key >= KSYM_FKEY_FIRST && key <= KSYM_FKEY_LAST)
1024 sprintf(name_buffer, "function F%d", (int)(key - KSYM_FKEY_FIRST + 1));
1025 else if (key == KSYM_UNDEFINED)
1026 strcpy(name_buffer, "(undefined)");
1033 if (key == translate_key[i].key)
1035 strcpy(name_buffer, translate_key[i].name);
1039 while (translate_key[++i].name);
1041 if (!translate_key[i].name)
1042 strcpy(name_buffer, "(unknown)");
1045 *name = name_buffer;
1047 else if (mode == TRANSLATE_KEYSYM_TO_X11KEYNAME)
1049 static char name_buffer[30];
1052 if (key >= KSYM_A && key <= KSYM_Z)
1053 sprintf(name_buffer, "XK_%c", 'A' + (char)(key - KSYM_A));
1054 else if (key >= KSYM_a && key <= KSYM_z)
1055 sprintf(name_buffer, "XK_%c", 'a' + (char)(key - KSYM_a));
1056 else if (key >= KSYM_0 && key <= KSYM_9)
1057 sprintf(name_buffer, "XK_%c", '0' + (char)(key - KSYM_0));
1058 else if (key >= KSYM_KP_0 && key <= KSYM_KP_9)
1059 sprintf(name_buffer, "XK_KP_%c", '0' + (char)(key - KSYM_KP_0));
1060 else if (key >= KSYM_FKEY_FIRST && key <= KSYM_FKEY_LAST)
1061 sprintf(name_buffer, "XK_F%d", (int)(key - KSYM_FKEY_FIRST + 1));
1062 else if (key == KSYM_UNDEFINED)
1063 strcpy(name_buffer, "[undefined]");
1070 if (key == translate_key[i].key)
1072 strcpy(name_buffer, translate_key[i].x11name);
1076 while (translate_key[++i].x11name);
1078 if (!translate_key[i].x11name)
1079 sprintf(name_buffer, "0x%04lx", (unsigned long)key);
1082 *x11name = name_buffer;
1084 else if (mode == TRANSLATE_KEYNAME_TO_KEYSYM)
1086 Key key = KSYM_UNDEFINED;
1091 if (strcmp(translate_key[i].name, *name) == 0)
1093 key = translate_key[i].key;
1097 while (translate_key[++i].x11name);
1099 if (key == KSYM_UNDEFINED)
1100 Error(ERR_WARN, "getKeyFromKeyName(): not completely implemented");
1104 else if (mode == TRANSLATE_X11KEYNAME_TO_KEYSYM)
1106 Key key = KSYM_UNDEFINED;
1107 char *name_ptr = *x11name;
1109 if (strncmp(name_ptr, "XK_", 3) == 0 && strlen(name_ptr) == 4)
1111 char c = name_ptr[3];
1113 if (c >= 'A' && c <= 'Z')
1114 key = KSYM_A + (Key)(c - 'A');
1115 else if (c >= 'a' && c <= 'z')
1116 key = KSYM_a + (Key)(c - 'a');
1117 else if (c >= '0' && c <= '9')
1118 key = KSYM_0 + (Key)(c - '0');
1120 else if (strncmp(name_ptr, "XK_KP_", 6) == 0 && strlen(name_ptr) == 7)
1122 char c = name_ptr[6];
1124 if (c >= '0' && c <= '9')
1125 key = KSYM_0 + (Key)(c - '0');
1127 else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6)
1129 char c1 = name_ptr[4];
1130 char c2 = name_ptr[5];
1133 if ((c1 >= '0' && c1 <= '9') &&
1134 ((c2 >= '0' && c1 <= '9') || c2 == '\0'))
1135 d = atoi(&name_ptr[4]);
1137 if (d >= 1 && d <= KSYM_NUM_FKEYS)
1138 key = KSYM_F1 + (Key)(d - 1);
1140 else if (strncmp(name_ptr, "XK_", 3) == 0)
1146 if (strcmp(name_ptr, translate_key[i].x11name) == 0)
1148 key = translate_key[i].key;
1152 while (translate_key[++i].x11name);
1154 else if (strncmp(name_ptr, "0x", 2) == 0)
1156 unsigned long value = 0;
1162 char c = *name_ptr++;
1165 if (c >= '0' && c <= '9')
1167 else if (c >= 'a' && c <= 'f')
1168 d = (int)(c - 'a' + 10);
1169 else if (c >= 'A' && c <= 'F')
1170 d = (int)(c - 'A' + 10);
1178 value = value * 16 + d;
1189 char *getKeyNameFromKey(Key key)
1193 translate_keyname(&key, NULL, &name, TRANSLATE_KEYSYM_TO_KEYNAME);
1197 char *getX11KeyNameFromKey(Key key)
1201 translate_keyname(&key, &x11name, NULL, TRANSLATE_KEYSYM_TO_X11KEYNAME);
1205 Key getKeyFromKeyName(char *name)
1209 translate_keyname(&key, NULL, &name, TRANSLATE_KEYNAME_TO_KEYSYM);
1213 Key getKeyFromX11KeyName(char *x11name)
1217 translate_keyname(&key, &x11name, NULL, TRANSLATE_X11KEYNAME_TO_KEYSYM);
1221 char getCharFromKey(Key key)
1223 char *keyname = getKeyNameFromKey(key);
1226 if (strlen(keyname) == 1)
1227 letter = keyname[0];
1228 else if (strcmp(keyname, "space") == 0)
1230 else if (strcmp(keyname, "circumflex") == 0)
1237 /* ------------------------------------------------------------------------- */
1238 /* functions to translate string identifiers to integer or boolean value */
1239 /* ------------------------------------------------------------------------- */
1241 int get_integer_from_string(char *s)
1243 static char *number_text[][3] =
1245 { "0", "zero", "null", },
1246 { "1", "one", "first" },
1247 { "2", "two", "second" },
1248 { "3", "three", "third" },
1249 { "4", "four", "fourth" },
1250 { "5", "five", "fifth" },
1251 { "6", "six", "sixth" },
1252 { "7", "seven", "seventh" },
1253 { "8", "eight", "eighth" },
1254 { "9", "nine", "ninth" },
1255 { "10", "ten", "tenth" },
1256 { "11", "eleven", "eleventh" },
1257 { "12", "twelve", "twelfth" },
1261 char *s_lower = getStringToLower(s);
1264 for (i=0; i<13; i++)
1266 if (strcmp(s_lower, number_text[i][j]) == 0)
1277 boolean get_boolean_from_string(char *s)
1279 char *s_lower = getStringToLower(s);
1280 boolean result = FALSE;
1282 if (strcmp(s_lower, "true") == 0 ||
1283 strcmp(s_lower, "yes") == 0 ||
1284 strcmp(s_lower, "on") == 0 ||
1285 get_integer_from_string(s) == 1)
1294 /* ========================================================================= */
1295 /* functions for generic lists */
1296 /* ========================================================================= */
1298 ListNode *newListNode()
1300 return checked_calloc(sizeof(ListNode));
1303 void addNodeToList(ListNode **node_first, char *key, void *content)
1305 ListNode *node_new = newListNode();
1308 printf("LIST: adding node with key '%s'\n", key);
1311 node_new->key = getStringCopy(key);
1312 node_new->content = content;
1313 node_new->next = *node_first;
1314 *node_first = node_new;
1317 void deleteNodeFromList(ListNode **node_first, char *key,
1318 void (*destructor_function)(void *))
1320 if (node_first == NULL || *node_first == NULL)
1324 printf("[CHECKING LIST KEY '%s' == '%s']\n",
1325 (*node_first)->key, key);
1328 if (strcmp((*node_first)->key, key) == 0)
1331 printf("[DELETING LIST ENTRY]\n");
1334 free((*node_first)->key);
1335 if (destructor_function)
1336 destructor_function((*node_first)->content);
1337 *node_first = (*node_first)->next;
1340 deleteNodeFromList(&(*node_first)->next, key, destructor_function);
1343 ListNode *getNodeFromKey(ListNode *node_first, char *key)
1345 if (node_first == NULL)
1348 if (strcmp(node_first->key, key) == 0)
1351 return getNodeFromKey(node_first->next, key);
1354 int getNumNodes(ListNode *node_first)
1356 return (node_first ? 1 + getNumNodes(node_first->next) : 0);
1359 void dumpList(ListNode *node_first)
1361 ListNode *node = node_first;
1365 printf("['%s' (%d)]\n", node->key,
1366 ((struct ListNodeInfo *)node->content)->num_references);
1370 printf("[%d nodes]\n", getNumNodes(node_first));
1374 /* ========================================================================= */
1375 /* functions for checking filenames */
1376 /* ========================================================================= */
1378 boolean FileIsGraphic(char *filename)
1380 if (strlen(filename) > 4 &&
1381 strcmp(&filename[strlen(filename) - 4], ".pcx") == 0)
1387 boolean FileIsSound(char *basename)
1389 if (strlen(basename) > 4 &&
1390 strcmp(&basename[strlen(basename) - 4], ".wav") == 0)
1396 boolean FileIsMusic(char *basename)
1398 /* "music" can be a WAV (loop) file or (if compiled with SDL) a MOD file */
1400 if (FileIsSound(basename))
1403 #if defined(TARGET_SDL)
1404 if (strlen(basename) > 4 &&
1405 (strcmp(&basename[strlen(basename) - 4], ".mod") == 0 ||
1406 strcmp(&basename[strlen(basename) - 4], ".MOD") == 0 ||
1407 strncmp(basename, "mod.", 4) == 0 ||
1408 strncmp(basename, "MOD.", 4) == 0))
1415 boolean FileIsArtworkType(char *basename, int type)
1417 if ((type == TREE_TYPE_GRAPHICS_DIR && FileIsGraphic(basename)) ||
1418 (type == TREE_TYPE_SOUNDS_DIR && FileIsSound(basename)) ||
1419 (type == TREE_TYPE_MUSIC_DIR && FileIsMusic(basename)))
1425 /* ========================================================================= */
1426 /* functions for loading artwork configuration information */
1427 /* ========================================================================= */
1429 static int get_parameter_value(int type, char *value)
1431 return (type == TYPE_INTEGER ? get_integer_from_string(value) :
1432 type == TYPE_BOOLEAN ? get_boolean_from_string(value) :
1436 struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list,
1437 struct ConfigInfo *suffix_list,
1438 int num_file_list_entries)
1440 struct FileInfo *file_list;
1441 int num_file_list_entries_found = 0;
1442 int num_suffix_list_entries = 0;
1446 file_list = checked_calloc(num_file_list_entries * sizeof(struct FileInfo));
1448 for (i=0; suffix_list[i].token != NULL; i++)
1449 num_suffix_list_entries++;
1451 /* always start with reliable default values */
1452 for (i=0; i<num_file_list_entries; i++)
1454 file_list[i].token = NULL;
1455 file_list[i].default_filename = NULL;
1456 file_list[i].filename = NULL;
1458 if (num_suffix_list_entries > 0)
1460 int parameter_array_size = num_suffix_list_entries * sizeof(int);
1462 file_list[i].default_parameter = checked_calloc(parameter_array_size);
1463 file_list[i].parameter = checked_calloc(parameter_array_size);
1465 for (j=0; j<num_suffix_list_entries; j++)
1467 int default_parameter =
1468 get_parameter_value(suffix_list[j].type, suffix_list[j].value);
1470 file_list[i].default_parameter[j] = default_parameter;
1471 file_list[i].parameter[j] = default_parameter;
1476 for (i=0; config_list[i].token != NULL; i++)
1478 int len_config_token = strlen(config_list[i].token);
1479 int len_config_value = strlen(config_list[i].value);
1480 boolean is_file_entry = TRUE;
1482 for (j=0; suffix_list[j].token != NULL; j++)
1484 int len_suffix = strlen(suffix_list[j].token);
1486 if (len_suffix < len_config_token &&
1487 strcmp(&config_list[i].token[len_config_token - len_suffix],
1488 suffix_list[j].token) == 0)
1490 file_list[list_pos].default_parameter[j] =
1491 get_parameter_value(suffix_list[j].type, config_list[i].value);
1493 is_file_entry = FALSE;
1503 if (list_pos >= num_file_list_entries)
1506 /* simple sanity check if this is really a file definition */
1507 if (strcmp(&config_list[i].value[len_config_value - 4], ".pcx") != 0 &&
1508 strcmp(&config_list[i].value[len_config_value - 4], ".wav") != 0 &&
1509 strcmp(config_list[i].value, UNDEFINED_FILENAME) != 0)
1511 Error(ERR_RETURN, "Configuration directive '%s' -> '%s':",
1512 config_list[i].token, config_list[i].value);
1513 Error(ERR_EXIT, "This seems to be no valid definition -- please fix");
1516 file_list[list_pos].token = config_list[i].token;
1517 file_list[list_pos].default_filename = config_list[i].value;
1521 num_file_list_entries_found = list_pos + 1;
1522 if (num_file_list_entries_found != num_file_list_entries)
1524 Error(ERR_RETURN, "inconsistant config list information:");
1525 Error(ERR_RETURN, "- should be: %d (according to 'src/conf_gfx.h')",
1526 num_file_list_entries);
1527 Error(ERR_RETURN, "- found to be: %d (according to 'src/conf_gfx.c')",
1528 num_file_list_entries_found);
1529 Error(ERR_EXIT, "please fix");
1535 static void LoadArtworkConfig(struct ArtworkListInfo *artwork_info)
1537 struct FileInfo *file_list = artwork_info->file_list;
1538 struct ConfigInfo *suffix_list = artwork_info->suffix_list;
1539 int num_file_list_entries = artwork_info->num_file_list_entries;
1540 int num_suffix_list_entries = artwork_info->num_suffix_list_entries;
1541 char *filename = getCustomArtworkConfigFilename(artwork_info->type);
1542 struct SetupFileList *setup_file_list;
1546 printf("GOT CUSTOM ARTWORK CONFIG FILE '%s'\n", filename);
1549 /* always start with reliable default values */
1550 for (i=0; i<num_file_list_entries; i++)
1552 if (file_list[i].filename != NULL)
1553 free(file_list[i].filename);
1554 file_list[i].filename = NULL;
1556 for (j=0; j<num_suffix_list_entries; j++)
1557 file_list[i].parameter[j] = file_list[i].default_parameter[j];
1560 if (filename == NULL)
1563 if ((setup_file_list = loadSetupFileList(filename)))
1565 for (i=0; i<num_file_list_entries; i++)
1567 char *filename = getTokenValue(setup_file_list, file_list[i].token);
1569 if (filename == NULL)
1570 filename = file_list[i].default_filename;
1571 file_list[i].filename = getStringCopy(filename);
1573 for (j=0; j<num_suffix_list_entries; j++)
1575 char *token = getStringCat2(file_list[i].token, suffix_list[j].token);
1576 char *value = getTokenValue(setup_file_list, token);
1579 file_list[i].parameter[j] =
1580 get_parameter_value(suffix_list[j].type, value);
1586 freeSetupFileList(setup_file_list);
1589 for (i=0; i<num_file_list_entries; i++)
1591 printf("'%s' ", file_list[i].token);
1592 if (file_list[i].filename)
1593 printf("-> '%s'\n", file_list[i].filename);
1595 printf("-> UNDEFINED [-> '%s']\n", file_list[i].default_filename);
1601 static void deleteArtworkListEntry(struct ArtworkListInfo *artwork_info,
1602 struct ListNodeInfo **listnode)
1606 char *filename = (*listnode)->source_filename;
1609 printf("[decrementing reference counter of artwork '%s']\n", filename);
1612 if (--(*listnode)->num_references <= 0)
1615 printf("[deleting artwork '%s']\n", filename);
1618 deleteNodeFromList(&artwork_info->content_list, filename,
1619 artwork_info->free_artwork);
1626 static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info,
1627 struct ListNodeInfo **listnode,
1632 "Loading graphics:",
1638 char *filename = getCustomArtworkFilename(basename, artwork_info->type);
1640 if (filename == NULL)
1642 int error_mode = ERR_WARN;
1644 /* we can get away without sounds and music, but not without graphics */
1645 if (*listnode == NULL && artwork_info->type == ARTWORK_TYPE_GRAPHICS)
1646 error_mode = ERR_EXIT;
1648 Error(error_mode, "cannot find artwork file '%s'", basename);
1652 /* check if the old and the new artwork file are the same */
1653 if (*listnode && strcmp((*listnode)->source_filename, filename) == 0)
1655 /* The old and new artwork are the same (have the same filename and path).
1656 This usually means that this artwork does not exist in this artwork set
1657 and a fallback to the existing artwork is done. */
1660 printf("[artwork '%s' already exists (same list entry)]\n", filename);
1666 /* delete existing artwork file entry */
1667 deleteArtworkListEntry(artwork_info, listnode);
1669 /* check if the new artwork file already exists in the list of artworks */
1670 if ((node = getNodeFromKey(artwork_info->content_list, filename)) != NULL)
1673 printf("[artwork '%s' already exists (other list entry)]\n", filename);
1676 *listnode = (struct ListNodeInfo *)node->content;
1677 (*listnode)->num_references++;
1682 DrawInitText(init_text[artwork_info->type], 120, FC_GREEN);
1683 DrawInitText(basename, 150, FC_YELLOW);
1685 if ((*listnode = artwork_info->load_artwork(filename)) != NULL)
1688 printf("[adding new artwork '%s']\n", filename);
1691 (*listnode)->num_references = 1;
1692 addNodeToList(&artwork_info->content_list, (*listnode)->source_filename,
1697 int error_mode = ERR_WARN;
1699 /* we can get away without sounds and music, but not without graphics */
1700 if (artwork_info->type == ARTWORK_TYPE_GRAPHICS)
1701 error_mode = ERR_EXIT;
1703 Error(error_mode, "cannot load artwork file '%s'", basename);
1708 static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info,
1709 struct ListNodeInfo **listnode,
1713 char *filename = getCustomArtworkFilename(basename, artwork_info->type);
1717 printf("GOT CUSTOM ARTWORK FILE '%s'\n", filename);
1720 if (strcmp(basename, UNDEFINED_FILENAME) == 0)
1722 deleteArtworkListEntry(artwork_info, listnode);
1727 if (filename == NULL)
1729 Error(ERR_WARN, "cannot find artwork file '%s'", basename);
1733 replaceArtworkListEntry(artwork_info, listnode, filename);
1735 replaceArtworkListEntry(artwork_info, listnode, basename);
1739 static void LoadArtworkToList(struct ArtworkListInfo *artwork_info,
1740 char *basename, int list_pos)
1742 if (artwork_info->artwork_list == NULL ||
1743 list_pos >= artwork_info->num_file_list_entries)
1747 printf("loading artwork '%s' ... [%d]\n",
1748 basename, getNumNodes(artwork_info->content_list));
1751 LoadCustomArtwork(artwork_info, &artwork_info->artwork_list[list_pos],
1755 printf("loading artwork '%s' done [%d]\n",
1756 basename, getNumNodes(artwork_info->content_list));
1760 void ReloadCustomArtworkList(struct ArtworkListInfo *artwork_info)
1771 { "Loading graphics:", TRUE },
1772 { "Loading sounds:", TRUE },
1773 { "Loading music:", TRUE }
1777 int num_file_list_entries = artwork_info->num_file_list_entries;
1778 struct FileInfo *file_list = artwork_info->file_list;
1781 LoadArtworkConfig(artwork_info);
1784 if (draw_init[artwork_info->type].do_it)
1785 DrawInitText(draw_init[artwork_info->type].text, 120, FC_GREEN);
1789 printf("DEBUG: reloading %d artwork files ...\n", num_file_list_entries);
1792 for(i=0; i<num_file_list_entries; i++)
1795 if (draw_init[artwork_info->type].do_it)
1796 DrawInitText(file_list[i].token, 150, FC_YELLOW);
1799 LoadArtworkToList(artwork_info, file_list[i].filename, i);
1802 printf("DEBUG: loading artwork file '%s'...\n", file_list[i].filename);
1807 draw_init[artwork_info->type].do_it = FALSE;
1811 printf("list size == %d\n", getNumNodes(artwork_info->content_list));
1815 dumpList(artwork_info->content_list);
1819 void FreeCustomArtworkList(struct ArtworkListInfo *artwork_info)
1823 if (artwork_info == NULL || artwork_info->artwork_list == NULL)
1827 printf("%s: FREEING ARTWORK ...\n",
1828 IS_CHILD_PROCESS(audio.mixer_pid) ? "CHILD" : "PARENT");
1831 for(i=0; i<artwork_info->num_file_list_entries; i++)
1832 deleteArtworkListEntry(artwork_info, &artwork_info->artwork_list[i]);
1835 printf("%s: FREEING ARTWORK -- DONE\n",
1836 IS_CHILD_PROCESS(audio.mixer_pid) ? "CHILD" : "PARENT");
1839 free(artwork_info->artwork_list);
1841 artwork_info->artwork_list = NULL;
1842 artwork_info->num_file_list_entries = 0;
1846 /* ========================================================================= */
1847 /* functions only needed for non-Unix (non-command-line) systems */
1848 /* (MS-DOS only; SDL/Windows creates files "stdout.txt" and "stderr.txt") */
1849 /* ========================================================================= */
1851 #if defined(PLATFORM_MSDOS)
1853 #define ERROR_FILENAME "stderr.txt"
1855 void initErrorFile()
1857 unlink(ERROR_FILENAME);
1860 FILE *openErrorFile()
1862 return fopen(ERROR_FILENAME, MODE_APPEND);
1865 void dumpErrorFile()
1867 FILE *error_file = fopen(ERROR_FILENAME, MODE_READ);
1869 if (error_file != NULL)
1871 while (!feof(error_file))
1872 fputc(fgetc(error_file), stderr);
1880 /* ========================================================================= */
1881 /* some generic helper functions */
1882 /* ========================================================================= */
1884 void printf_line(char line_char, int line_length)
1888 for (i=0; i<line_length; i++)
1889 printf("%c", line_char);
1895 /* ========================================================================= */
1896 /* the following is only for debugging purpose and normally not used */
1897 /* ========================================================================= */
1899 #define DEBUG_NUM_TIMESTAMPS 3
1901 void debug_print_timestamp(int counter_nr, char *message)
1903 static long counter[DEBUG_NUM_TIMESTAMPS][2];
1905 if (counter_nr >= DEBUG_NUM_TIMESTAMPS)
1906 Error(ERR_EXIT, "debugging: increase DEBUG_NUM_TIMESTAMPS in misc.c");
1908 counter[counter_nr][0] = Counter();
1911 printf("%s %.2f seconds\n", message,
1912 (float)(counter[counter_nr][0] - counter[counter_nr][1]) / 1000);
1914 counter[counter_nr][1] = Counter();