/[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 956 by astrand, Wed Aug 3 07:08:48 2005 UTC revision 957 by astrand, Wed Aug 3 08:25:32 2005 UTC
# Line 155  add_sequence(char *rest, char *mapname) Line 155  add_sequence(char *rest, char *mapname)
155          DEBUG_KBD(("\n"));          DEBUG_KBD(("\n"));
156  }  }
157    
158    /* Joins two path components. The result should be freed with
159       xfree(). */
160    static char *
161    pathjoin(const char *a, const char *b)
162    {
163            char *result;
164            result = xmalloc(PATH_MAX * 2 + 1);
165    
166            if (b[0] == '/')
167            {
168                    strncpy(result, b, PATH_MAX);
169            }
170            else
171            {
172                    strncpy(result, a, PATH_MAX);
173                    strcat(result, "/");
174                    strncat(result, b, PATH_MAX);
175            }
176            return result;
177    }
178    
179    /* Try to open a keymap with fopen() */
180    FILE *
181    xkeymap_open(const char *filename)
182    {
183            char *path1, *path2;
184            char *home;
185            FILE *fp;
186    
187            /* Try KEYMAP_PATH */
188            path1 = pathjoin(KEYMAP_PATH, filename);
189            fp = fopen(path1, "r");
190            xfree(path1);
191            if (fp)
192                    return fp;
193    
194            /* Try ~/.rdesktop/keymaps */
195            home = getenv("HOME");
196            if (home)
197            {
198                    path1 = pathjoin(home, ".rdesktop/keymaps");
199                    path2 = pathjoin(path1, filename);
200                    xfree(path1);
201                    fp = fopen(path2, "r");
202                    xfree(path2);
203                    if (fp)
204                            return fp;
205            }
206    
207            /* Try current directory, in case we are running from the source
208               tree */
209            path1 = pathjoin("keymaps", filename);
210            fp = fopen(path1, "r");
211            xfree(path1);
212            if (fp)
213                    return fp;
214    
215            return NULL;
216    }
217    
218  static BOOL  static BOOL
219  xkeymap_read(char *mapname)  xkeymap_read(char *mapname)
220  {  {
221          FILE *fp;          FILE *fp;
222          char line[KEYMAP_MAX_LINE_LENGTH];          char line[KEYMAP_MAX_LINE_LENGTH];
         char path[PATH_MAX], inplace_path[PATH_MAX];  
223          unsigned int line_num = 0;          unsigned int line_num = 0;
224          unsigned int line_length = 0;          unsigned int line_length = 0;
225          char *keyname, *p;          char *keyname, *p;
# Line 168  xkeymap_read(char *mapname) Line 227  xkeymap_read(char *mapname)
227          uint8 scancode;          uint8 scancode;
228          uint16 modifiers;          uint16 modifiers;
229    
230            fp = xkeymap_open(mapname);
         strcpy(path, KEYMAP_PATH);  
         strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH));  
   
         fp = fopen(path, "r");  
231          if (fp == NULL)          if (fp == NULL)
232          {          {
233                  /* in case we are running from the source tree */                  error("Failed to open keymap %s\n", mapname);
234                  strcpy(inplace_path, "keymaps/");                  return False;
                 strncat(inplace_path, mapname, sizeof(inplace_path) - sizeof("keymaps/"));  
   
                 fp = fopen(inplace_path, "r");  
                 if (fp == NULL)  
                 {  
                         error("Failed to open keymap %s\n", path);  
                         return False;  
                 }  
235          }          }
236    
237          /* FIXME: More tolerant on white space */          /* FIXME: More tolerant on white space */

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

  ViewVC Help
Powered by ViewVC 1.1.26