rnd-19981108-2
[rocksndiamonds.git] / src / misc.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  misc.c                                                  *
12 ***********************************************************/
13
14 #include <pwd.h>
15 #include <unistd.h>
16 #include <time.h>
17 #include <sys/time.h>
18 #include <sys/param.h>
19 #include <sys/types.h>
20 #include <stdarg.h>
21
22 #include "misc.h"
23 #include "init.h"
24 #include "tools.h"
25 #include "sound.h"
26 #include "random.h"
27 #include "joystick.h"
28
29 static unsigned long mainCounter(int mode)
30 {
31   static struct timeval base_time = { 0, 0 };
32   struct timeval current_time;
33   unsigned long counter_ms;
34
35   gettimeofday(&current_time, NULL);
36
37   if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec)
38     base_time = current_time;
39
40   counter_ms = (current_time.tv_sec  - base_time.tv_sec)  * 1000
41              + (current_time.tv_usec - base_time.tv_usec) / 1000;
42
43   return counter_ms;            /* return milliseconds since last init */
44 }
45
46 void InitCounter()              /* set counter back to zero */
47 {
48   mainCounter(INIT_COUNTER);
49 }
50
51 unsigned long Counter() /* get milliseconds since last call of InitCounter() */
52 {
53   return(mainCounter(READ_COUNTER));
54 }
55
56 static void sleep_milliseconds(unsigned long milliseconds_delay)
57 {
58   if (milliseconds_delay < 5)
59   {
60     /* we want to wait only a few ms -- if we assume that we have a
61        kernel timer resolution of 10 ms, we would wait far to long;
62        therefore it's better to do a short interval of busy waiting
63        to get our sleeping time more accurate */
64
65     unsigned long base_counter = Counter(), actual_counter = Counter();
66
67     while (actual_counter < base_counter + milliseconds_delay &&
68            actual_counter >= base_counter)
69       actual_counter = Counter();
70   }
71   else
72   {
73     struct timeval delay;
74
75     delay.tv_sec  = milliseconds_delay / 1000;
76     delay.tv_usec = 1000 * (milliseconds_delay % 1000);
77
78     if (select(0, NULL, NULL, NULL, &delay) != 0)
79       Error(ERR_WARN, "sleep_milliseconds(): select() failed");
80   }
81 }
82
83 void Delay(unsigned long delay) /* Sleep specified number of milliseconds */
84 {
85   sleep_milliseconds(delay);
86 }
87
88 boolean FrameReached(unsigned long *frame_counter_var,
89                      unsigned long frame_delay)
90 {
91   unsigned long actual_frame_counter = FrameCounter;
92
93   if (actual_frame_counter < *frame_counter_var+frame_delay &&
94       actual_frame_counter >= *frame_counter_var)
95     return(FALSE);
96
97   *frame_counter_var = actual_frame_counter;
98   return(TRUE);
99 }
100
101 boolean DelayReached(unsigned long *counter_var,
102                      unsigned long delay)
103 {
104   unsigned long actual_counter = Counter();
105
106   if (actual_counter < *counter_var + delay &&
107       actual_counter >= *counter_var)
108     return(FALSE);
109
110   *counter_var = actual_counter;
111   return(TRUE);
112 }
113
114 void WaitUntilDelayReached(unsigned long *counter_var, unsigned long delay)
115 {
116   unsigned long actual_counter;
117
118   while(1)
119   {
120     actual_counter = Counter();
121
122     if (actual_counter < *counter_var + delay &&
123         actual_counter >= *counter_var)
124       sleep_milliseconds((*counter_var + delay - actual_counter) / 2);
125     else
126       break;
127   }
128
129   *counter_var = actual_counter;
130 }
131
132 char *int2str(int number, int size)
133 {
134   static char s[40];
135
136   if (size > 20)
137     size = 20;
138
139   if (size)
140   {
141     sprintf(s, "                    %09d", number);
142     return &s[strlen(s) - size];
143   }
144   else
145   {
146     sprintf(s, "%d", number);
147     return s;
148   }
149 }
150
151 unsigned int SimpleRND(unsigned int max)
152 {
153   static unsigned long root = 654321;
154   struct timeval current_time;
155
156   gettimeofday(&current_time,NULL);
157   root = root * 4253261 + current_time.tv_sec + current_time.tv_usec;
158   return (root % max);
159 }
160
161 unsigned int RND(unsigned int max)
162 {
163   return (random_linux_libc() % max);
164 }
165
166 unsigned int InitRND(long seed)
167 {
168   struct timeval current_time;
169
170   if (seed == NEW_RANDOMIZE)
171   {
172     gettimeofday(&current_time,NULL);
173     srandom_linux_libc((unsigned int) current_time.tv_usec);
174     return (unsigned int)current_time.tv_usec;
175   }
176   else
177   {
178     srandom_linux_libc((unsigned int) seed);
179     return (unsigned int)seed;
180   }
181 }
182
183 char *getLoginName()
184 {
185   struct passwd *pwd;
186
187   if (!(pwd = getpwuid(getuid())))
188     return "ANONYMOUS";
189   else
190     return pwd->pw_name;
191 }
192
193 char *getHomeDir()
194 {
195   static char *home_dir = NULL;
196
197   if (!home_dir)
198   {
199     if (!(home_dir = getenv("HOME")))
200     {
201       struct passwd *pwd;
202
203       if ((pwd = getpwuid(getuid())))
204         home_dir = pwd->pw_dir;
205       else
206         home_dir = ".";
207     }
208   }
209
210   return home_dir;
211 }
212
213 void MarkTileDirty(int x, int y)
214 {
215   int xx = redraw_x1 + x;
216   int yy = redraw_y1 + y;
217
218   if (!redraw[xx][yy])
219     redraw_tiles++;
220
221   redraw[xx][yy] = TRUE;
222   redraw_mask |= REDRAW_TILES;
223 }
224
225 void GetOptions(char *argv[])
226 {
227   char **options_left = &argv[1];
228
229   /* initialize global program options */
230   options.display_name = NULL;
231   options.server_host = NULL;
232   options.server_port = 0;
233   options.base_directory = BASE_PATH;
234   options.level_directory = BASE_PATH "/" LEVELS_DIRECTORY;
235   options.serveronly = FALSE;
236   options.network = FALSE;
237   options.verbose = FALSE;
238
239   while (*options_left)
240   {
241     char option_str[MAX_OPTION_LEN];
242     char *option = options_left[0];
243     char *next_option = options_left[1];
244     char *option_arg = NULL;
245     int option_len = strlen(option);
246
247     strcpy(option_str, option);                 /* copy argument into buffer */
248     option = option_str;
249
250     if (strcmp(option, "--") == 0)              /* stop scanning arguments */
251       break;
252
253     if (option_len >= MAX_OPTION_LEN)
254       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
255
256     if (strncmp(option, "--", 2) == 0)          /* treat '--' like '-' */
257       option++;
258
259     option_arg = strchr(option, '=');
260     if (option_arg == NULL)                     /* no '=' in option */
261       option_arg = next_option;
262     else
263     {
264       *option_arg++ = '\0';                     /* cut argument from option */
265       if (*option_arg == '\0')                  /* no argument after '=' */
266         Error(ERR_EXIT_HELP, "option '%s' has invalid argument", option_str);
267     }
268
269     option_len = strlen(option);
270
271     if (strcmp(option, "-") == 0)
272       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option);
273     else if (strncmp(option, "-help", option_len) == 0)
274     {
275       printf("Usage: %s [options] [server.name [port]]\n"
276              "Options:\n"
277              "  -d, --display machine:0       X server display\n"
278              "  -b, --basepath directory      alternative base directory\n"
279              "  -l, --levels directory        alternative level directory\n"
280              "  -s, --serveronly              only start network server\n"
281              "  -n, --network                 network multiplayer game\n"
282              "  -v, --verbose                 verbose mode\n",
283              program_name);
284       exit(0);
285     }
286     else if (strncmp(option, "-display", option_len) == 0)
287     {
288       if (option_arg == NULL)
289         Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
290
291       options.display_name = option_arg;
292       if (option_arg == next_option)
293         options_left++;
294
295       printf("--display == '%s'\n", options.display_name);
296     }
297     else if (strncmp(option, "-basepath", option_len) == 0)
298     {
299       if (option_arg == NULL)
300         Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
301
302       options.base_directory = option_arg;
303       if (option_arg == next_option)
304         options_left++;
305
306       printf("--basepath == '%s'\n", options.base_directory);
307
308       /* adjust path for level directory accordingly */
309       options.level_directory = checked_malloc(strlen(options.base_directory) +
310                                                strlen(LEVELS_DIRECTORY) + 2);
311       sprintf(options.level_directory, "%s/%s",
312               options.base_directory, LEVELS_DIRECTORY);
313     }
314     else if (strncmp(option, "-levels", option_len) == 0)
315     {
316       if (option_arg == NULL)
317         Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str);
318
319       options.level_directory = option_arg;
320       if (option_arg == next_option)
321         options_left++;
322
323       printf("--levels == '%s'\n", options.level_directory);
324     }
325     else if (strncmp(option, "-network", option_len) == 0)
326     {
327       printf("--network\n");
328
329       options.network = TRUE;
330     }
331     else if (strncmp(option, "-serveronly", option_len) == 0)
332     {
333       printf("--serveronly\n");
334
335       options.serveronly = TRUE;
336     }
337     else if (strncmp(option, "-verbose", option_len) == 0)
338     {
339       printf("--verbose\n");
340
341       options.verbose = TRUE;
342     }
343     else if (*option == '-')
344       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
345     else if (options.server_host == NULL)
346     {
347       options.server_host = *options_left;
348
349       printf("server.name == '%s'\n", options.server_host);
350     }
351     else if (options.server_port == 0)
352     {
353       options.server_port = atoi(*options_left);
354       if (options.server_port < 1024)
355         Error(ERR_EXIT_HELP, "bad port number '%d'", options.server_port);
356
357       printf("port == %d\n", options.server_port);
358     }
359     else
360       Error(ERR_EXIT_HELP, "too many arguments");
361
362     options_left++;
363   }
364 }
365
366 void Error(int mode, char *format_str, ...)
367 {
368   FILE *output_stream = stderr;
369   char *process_name = "";
370
371   if (mode & ERR_SOUNDSERVER)
372     process_name = " sound server";
373
374   if (format_str)
375   {
376     va_list ap;
377     char *format_ptr;
378     char *s_value;
379     int i_value;
380     double d_value;
381
382     fprintf(output_stream, "%s%s: ", program_name, process_name);
383
384     if (mode & ERR_WARN)
385       fprintf(output_stream, "warning: ");
386
387     va_start(ap, format_str);   /* ap points to first unnamed argument */
388   
389     for(format_ptr=format_str; *format_ptr; format_ptr++)
390     {
391       if (*format_ptr != '%')
392       {
393         fprintf(output_stream, "%c", *format_ptr);
394         continue;
395       }
396   
397       switch(*++format_ptr)
398       {
399         case 'd':
400           i_value = va_arg(ap, int);
401           fprintf(output_stream, "%d", i_value);
402           break;
403   
404         case 'f':
405           d_value = va_arg(ap, double);
406           fprintf(output_stream, "%f", d_value);
407           break;
408   
409         case 's':
410           s_value = va_arg(ap, char *);
411           fprintf(output_stream, "%s", s_value);
412           break;
413   
414         default:
415           fprintf(stderr, "\n%s: Error(): invalid format string: %s\n",
416                   program_name, format_str);
417           CloseAllAndExit(10);
418       }
419     }
420
421     va_end(ap);
422   
423     fprintf(output_stream, "\n");
424   }
425   
426   if (mode & ERR_HELP)
427     fprintf(output_stream, "%s: Try option '--help' for more information.\n",
428             program_name);
429
430   if (mode & ERR_EXIT)
431   {
432     fprintf(output_stream, "%s%s: aborting\n", program_name, process_name);
433     CloseAllAndExit(1);
434   }
435 }
436
437 void *checked_malloc(unsigned long size)
438 {
439   void *ptr;
440
441   ptr = malloc(size);
442
443   if (ptr == NULL)
444     Error(ERR_EXIT, "cannot allocate %d bytes -- out of memory", size);
445
446   return ptr;
447 }
448
449 #define TRANSLATE_KEYSYM_TO_KEYNAME     0
450 #define TRANSLATE_KEYSYM_TO_X11KEYNAME  1
451 #define TRANSLATE_X11KEYNAME_TO_KEYSYM  2
452
453 void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode)
454 {
455   static struct
456   {
457     KeySym keysym;
458     char *x11name;
459     char *name;
460   } translate_key[] =
461   {
462     /* normal cursor keys */
463     { XK_Left,          "XK_Left",              "cursor left" },
464     { XK_Right,         "XK_Right",             "cursor right" },
465     { XK_Up,            "XK_Up",                "cursor up" },
466     { XK_Down,          "XK_Down",              "cursor down" },
467
468     /* keypad cursor keys */
469 #ifdef XK_KP_Left
470     { XK_KP_Left,       "XK_KP_Left",           "keypad left" },
471     { XK_KP_Right,      "XK_KP_Right",          "keypad right" },
472     { XK_KP_Up,         "XK_KP_Up",             "keypad up" },
473     { XK_KP_Down,       "XK_KP_Down",           "keypad down" },
474 #endif
475
476     /* other keypad keys */
477 #ifdef XK_KP_Enter
478     { XK_KP_Enter,      "XK_KP_Enter",          "keypad enter" },
479     { XK_KP_Add,        "XK_KP_Add",            "keypad +" },
480     { XK_KP_Subtract,   "XK_KP_Subtract",       "keypad -" },
481     { XK_KP_Multiply,   "XK_KP_Multiply",       "keypad mltply" },
482     { XK_KP_Divide,     "XK_KP_Divide",         "keypad /" },
483     { XK_KP_Separator,  "XK_KP_Separator",      "keypad ," },
484 #endif
485
486     /* modifier keys */
487     { XK_Shift_L,       "XK_Shift_L",           "left shift" },
488     { XK_Shift_R,       "XK_Shift_R",           "right shift" },
489     { XK_Control_L,     "XK_Control_L",         "left control" },
490     { XK_Control_R,     "XK_Control_R",         "right control" },
491     { XK_Meta_L,        "XK_Meta_L",            "left meta" },
492     { XK_Meta_R,        "XK_Meta_R",            "right meta" },
493     { XK_Alt_L,         "XK_Alt_L",             "left alt" },
494     { XK_Alt_R,         "XK_Alt_R",             "right alt" },
495     { XK_Mode_switch,   "XK_Mode_switch",       "mode switch" },
496     { XK_Multi_key,     "XK_Multi_key",         "multi key" },
497
498     /* some special keys */
499     { XK_BackSpace,     "XK_BackSpace",         "backspace" },
500     { XK_Delete,        "XK_Delete",            "delete" },
501     { XK_Insert,        "XK_Insert",            "insert" },
502     { XK_Tab,           "XK_Tab",               "tab" },
503     { XK_Home,          "XK_Home",              "home" },
504     { XK_End,           "XK_End",               "end" },
505     { XK_Page_Up,       "XK_Page_Up",           "page up" },
506     { XK_Page_Down,     "XK_Page_Down",         "page down" },
507     { XK_space,         "XK_space",             "space" },
508
509     /* even more special keys */
510     { XK_adiaeresis,    "XK_adiaeresis",        "ä" },
511     { XK_odiaeresis,    "XK_odiaeresis",        "ö" },
512     { XK_udiaeresis,    "XK_udiaeresis",        "ü" },
513     { XK_apostrophe,    "XK_apostrophe",        "'" },
514     { XK_plus,          "XK_plus",              "+" },
515     { XK_minus,         "XK_minus",             "-" },
516     { XK_comma,         "XK_comma",             "," },
517     { XK_period,        "XK_period",            "." },
518     { XK_numbersign,    "XK_numbersign",        "#" },
519     { XK_less,          "XK_less",              "less" },
520     { XK_greater,       "XK_greater",           "greater" },
521     { XK_asciicircum,   "XK_asciicircum",       "circumflex" },
522     { XK_ssharp,        "XK_ssharp",            "sharp s" },
523
524     /* end-of-array identifier */
525     { 0,                NULL,                   NULL }
526   };
527
528   int i;
529
530   if (mode == TRANSLATE_KEYSYM_TO_KEYNAME)
531   {
532     static char name_buffer[30];
533     KeySym key = *keysym;
534
535     if (key >= XK_A && key <= XK_Z)
536       sprintf(name_buffer, "%c", 'A' + (char)(key - XK_A));
537     else if (key >= XK_a && key <= XK_z)
538       sprintf(name_buffer, "%c", 'a' + (char)(key - XK_a));
539     else if (key >= XK_0 && key <= XK_9)
540       sprintf(name_buffer, "%c", '0' + (char)(key - XK_0));
541     else if (key >= XK_KP_0 && key <= XK_KP_9)
542       sprintf(name_buffer, "keypad %c", '0' + (char)(key - XK_KP_0));
543     else if (key >= XK_F1 && key <= XK_F24)
544       sprintf(name_buffer, "function F%d", (int)(key - XK_F1 + 1));
545     else if (key == KEY_UNDEFINDED)
546       strcpy(name_buffer, "(undefined)");
547     else
548     {
549       i = 0;
550
551       do
552       {
553         if (key == translate_key[i].keysym)
554         {
555           strcpy(name_buffer, translate_key[i].name);
556           break;
557         }
558       }
559       while (translate_key[++i].name);
560
561       if (!translate_key[i].name)
562         strcpy(name_buffer, "(unknown)");
563     }
564
565     *name = name_buffer;
566   }
567   else if (mode == TRANSLATE_KEYSYM_TO_X11KEYNAME)
568   {
569     static char name_buffer[30];
570     KeySym key = *keysym;
571
572     if (key >= XK_A && key <= XK_Z)
573       sprintf(name_buffer, "XK_%c", 'A' + (char)(key - XK_A));
574     else if (key >= XK_a && key <= XK_z)
575       sprintf(name_buffer, "XK_%c", 'a' + (char)(key - XK_a));
576     else if (key >= XK_0 && key <= XK_9)
577       sprintf(name_buffer, "XK_%c", '0' + (char)(key - XK_0));
578     else if (key >= XK_KP_0 && key <= XK_KP_9)
579       sprintf(name_buffer, "XK_KP_%c", '0' + (char)(key - XK_KP_0));
580     else if (key >= XK_F1 && key <= XK_F24)
581       sprintf(name_buffer, "XK_F%d", (int)(key - XK_F1 + 1));
582     else if (key == KEY_UNDEFINDED)
583       strcpy(name_buffer, "[undefined]");
584     else
585     {
586       i = 0;
587
588       do
589       {
590         if (key == translate_key[i].keysym)
591         {
592           strcpy(name_buffer, translate_key[i].x11name);
593           break;
594         }
595       }
596       while (translate_key[++i].x11name);
597
598       if (!translate_key[i].x11name)
599         sprintf(name_buffer, "0x%04lx", (unsigned long)key);
600     }
601
602     *x11name = name_buffer;
603   }
604   else if (mode == TRANSLATE_X11KEYNAME_TO_KEYSYM)
605   {
606     KeySym key = XK_VoidSymbol;
607     char *name_ptr = *x11name;
608
609     if (strncmp(name_ptr, "XK_", 3) == 0 && strlen(name_ptr) == 4)
610     {
611       char c = name_ptr[3];
612
613       if (c >= 'A' && c <= 'Z')
614         key = XK_A + (KeySym)(c - 'A');
615       else if (c >= 'a' && c <= 'z')
616         key = XK_a + (KeySym)(c - 'a');
617       else if (c >= '0' && c <= '9')
618         key = XK_0 + (KeySym)(c - '0');
619     }
620     else if (strncmp(name_ptr, "XK_KP_", 6) == 0 && strlen(name_ptr) == 7)
621     {
622       char c = name_ptr[6];
623
624       if (c >= '0' && c <= '9')
625         key = XK_0 + (KeySym)(c - '0');
626     }
627     else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6)
628     {
629       char c1 = name_ptr[4];
630       char c2 = name_ptr[5];
631       int d = 0;
632
633       if ((c1 >= '0' && c1 <= '9') &&
634           ((c2 >= '0' && c1 <= '9') || c2 == '\0'))
635         d = atoi(&name_ptr[4]);
636
637       if (d >=1 && d <= 24)
638         key = XK_F1 + (KeySym)(d - 1);
639     }
640     else if (strncmp(name_ptr, "XK_", 3) == 0)
641     {
642       i = 0;
643
644       do
645       {
646         if (strcmp(name_ptr, translate_key[i].x11name) == 0)
647         {
648           key = translate_key[i].keysym;
649           break;
650         }
651       }
652       while (translate_key[++i].x11name);
653     }
654     else if (strncmp(name_ptr, "0x", 2) == 0)
655     {
656       unsigned long value = 0;
657
658       name_ptr += 2;
659
660       while (name_ptr)
661       {
662         char c = *name_ptr++;
663         int d = -1;
664
665         if (c >= '0' && c <= '9')
666           d = (int)(c - '0');
667         else if (c >= 'a' && c <= 'f')
668           d = (int)(c - 'a' + 10);
669         else if (c >= 'A' && c <= 'F')
670           d = (int)(c - 'A' + 10);
671
672         if (d == -1)
673         {
674           value = -1;
675           break;
676         }
677
678         value = value * 16 + d;
679       }
680
681       if (value != -1)
682         key = (KeySym)value;
683     }
684
685     *keysym = key;
686   }
687 }
688
689 char *getKeyNameFromKeySym(KeySym keysym)
690 {
691   char *name;
692
693   translate_keyname(&keysym, NULL, &name, TRANSLATE_KEYSYM_TO_KEYNAME);
694   return name;
695 }
696
697 char *getX11KeyNameFromKeySym(KeySym keysym)
698 {
699   char *x11name;
700
701   translate_keyname(&keysym, &x11name, NULL, TRANSLATE_KEYSYM_TO_X11KEYNAME);
702   return x11name;
703 }
704
705 KeySym getKeySymFromX11KeyName(char *x11name)
706 {
707   KeySym keysym;
708
709   translate_keyname(&keysym, &x11name, NULL, TRANSLATE_X11KEYNAME_TO_KEYSYM);
710   return keysym;
711 }
712
713 #define TRANSLATE_JOYSYMBOL_TO_JOYNAME  0
714 #define TRANSLATE_JOYNAME_TO_JOYSYMBOL  1
715
716 void translate_joyname(int *joysymbol, char **name, int mode)
717 {
718   static struct
719   {
720     int joysymbol;
721     char *name;
722   } translate_joy[] =
723   {
724     { JOY_LEFT,         "joystick_left" },
725     { JOY_RIGHT,        "joystick_right" },
726     { JOY_UP,           "joystick_up" },
727     { JOY_DOWN,         "joystick_down" },
728     { JOY_BUTTON_1,     "joystick_button_1" },
729     { JOY_BUTTON_2,     "joystick_button_2" },
730   };
731
732   int i;
733
734   if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME)
735   {
736     *name = "[undefined]";
737
738     for (i=0; i<6; i++)
739     {
740       if (*joysymbol == translate_joy[i].joysymbol)
741       {
742         *name = translate_joy[i].name;
743         break;
744       }
745     }
746   }
747   else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL)
748   {
749     *joysymbol = 0;
750
751     for (i=0; i<6; i++)
752     {
753       if (strcmp(*name, translate_joy[i].name) == 0)
754       {
755         *joysymbol = translate_joy[i].joysymbol;
756         break;
757       }
758     }
759   }
760 }
761
762 char *getJoyNameFromJoySymbol(int joysymbol)
763 {
764   char *name;
765
766   translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME);
767   return name;
768 }
769
770 int getJoySymbolFromJoyName(char *name)
771 {
772   int joysymbol;
773
774   translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
775   return joysymbol;
776 }