/[rdesktop]/sourceforge.net/trunk/rdesktop/xkeymap.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/xkeymap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 957 by astrand, Wed Aug 3 08:25:32 2005 UTC revision 962 by astrand, Wed Aug 3 09:56:17 2005 UTC
# Line 30  Line 30 
30  #include <ctype.h>  #include <ctype.h>
31  #include <limits.h>  #include <limits.h>
32  #include <time.h>  #include <time.h>
33    #include <string.h>
34  #include "rdesktop.h"  #include "rdesktop.h"
35  #include "scancodes.h"  #include "scancodes.h"
36    
# Line 155  add_sequence(char *rest, char *mapname) Line 156  add_sequence(char *rest, char *mapname)
156          DEBUG_KBD(("\n"));          DEBUG_KBD(("\n"));
157  }  }
158    
159    void
160    xkeymap_from_locale(const char *locale)
161    {
162            char *str, *ptr;
163            FILE *fp;
164    
165            /* Create a working copy */
166            str = strdup(locale);
167            if (str == NULL)
168            {
169                    perror("strdup");
170                    exit(1);
171            }
172    
173            /* Truncate at dot and at */
174            ptr = strrchr(str, '.');
175            if (ptr)
176                    *ptr = '\0';
177            ptr = strrchr(str, '@');
178            if (ptr)
179                    *ptr = '\0';
180    
181            /* Replace _ with - */
182            ptr = strrchr(str, '_');
183            if (ptr)
184                    *ptr = '-';
185    
186            /* Convert to lowercase */
187            ptr = str;
188            while (*ptr)
189            {
190                    *ptr = tolower((int) *ptr);
191                    ptr++;
192            }
193    
194            /* Try to open this keymap (da-dk) */
195            fp = xkeymap_open(str);
196            if (fp == NULL)
197            {
198                    /* Truncate at dash */
199                    ptr = strrchr(str, '-');
200                    if (ptr)
201                            *ptr = '\0';
202    
203                    /* Try the short name (da) */
204                    fp = xkeymap_open(str);
205            }
206    
207            if (fp)
208            {
209                    fclose(fp);
210                    STRNCPY(keymapname, str, sizeof(keymapname));
211                    fprintf(stderr, "Autoselected keyboard map %s.\n", keymapname);
212            }
213    }
214    
215    
216  /* Joins two path components. The result should be freed with  /* Joins two path components. The result should be freed with
217     xfree(). */     xfree(). */
218  static char *  static char *
# Line 184  xkeymap_open(const char *filename) Line 242  xkeymap_open(const char *filename)
242          char *home;          char *home;
243          FILE *fp;          FILE *fp;
244    
         /* Try KEYMAP_PATH */  
         path1 = pathjoin(KEYMAP_PATH, filename);  
         fp = fopen(path1, "r");  
         xfree(path1);  
         if (fp)  
                 return fp;  
   
245          /* Try ~/.rdesktop/keymaps */          /* Try ~/.rdesktop/keymaps */
246          home = getenv("HOME");          home = getenv("HOME");
247          if (home)          if (home)
# Line 204  xkeymap_open(const char *filename) Line 255  xkeymap_open(const char *filename)
255                          return fp;                          return fp;
256          }          }
257    
258            /* Try KEYMAP_PATH */
259            path1 = pathjoin(KEYMAP_PATH, filename);
260            fp = fopen(path1, "r");
261            xfree(path1);
262            if (fp)
263                    return fp;
264    
265          /* Try current directory, in case we are running from the source          /* Try current directory, in case we are running from the source
266             tree */             tree */
267          path1 = pathjoin("keymaps", filename);          path1 = pathjoin("keymaps", filename);
# Line 358  void Line 416  void
416  xkeymap_init(void)  xkeymap_init(void)
417  {  {
418          unsigned int max_keycode;          unsigned int max_keycode;
         char *mapname_ptr;  
   
         /* Make keymapname lowercase */  
         mapname_ptr = keymapname;  
         while (*mapname_ptr)  
         {  
                 *mapname_ptr = tolower((int) *mapname_ptr);  
                 mapname_ptr++;  
         }  
419    
420          if (strcmp(keymapname, "none"))          if (strcmp(keymapname, "none"))
421          {          {

Legend:
Removed from v.957  
changed lines
  Added in v.962

  ViewVC Help
Powered by ViewVC 1.1.26