Mercurial > emacs
comparison src/w32.c @ 15326:ea444efb0b95
(normalize_filename): New function.
(dostounix_filename, unixtodos_filename): Use it.
(readdir): Convert upper case file names to lower case
if win32-downcase-file-names is non-nil.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 03 Jun 1996 21:18:55 +0000 |
parents | a073669046b1 |
children | e64bd8310edc |
comparison
equal
deleted
inserted
replaced
15325:5c8e4ef3137c | 15326:ea444efb0b95 |
---|---|
120 struct direct dir_static; /* simulated directory contents */ | 120 struct direct dir_static; /* simulated directory contents */ |
121 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE; | 121 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE; |
122 static int dir_is_fat; | 122 static int dir_is_fat; |
123 static char dir_pathname[MAXPATHLEN+1]; | 123 static char dir_pathname[MAXPATHLEN+1]; |
124 | 124 |
125 extern Lisp_Object Vwin32_downcase_file_names; | |
126 | |
125 DIR * | 127 DIR * |
126 opendir (char *filename) | 128 opendir (char *filename) |
127 { | 129 { |
128 DIR *dirp; | 130 DIR *dirp; |
129 | 131 |
195 | 197 |
196 dir_static.d_namlen = strlen (find_data.cFileName); | 198 dir_static.d_namlen = strlen (find_data.cFileName); |
197 strcpy (dir_static.d_name, find_data.cFileName); | 199 strcpy (dir_static.d_name, find_data.cFileName); |
198 if (dir_is_fat) | 200 if (dir_is_fat) |
199 _strlwr (dir_static.d_name); | 201 _strlwr (dir_static.d_name); |
202 else if (!NILP (Vwin32_downcase_file_names)) | |
203 { | |
204 register char *p; | |
205 for (p = dir_static.d_name; *p; p++) | |
206 if (*p >= 'a' && *p <= 'z') | |
207 break; | |
208 if (!*p) | |
209 _strlwr (dir_static.d_name); | |
210 } | |
200 | 211 |
201 return &dir_static; | 212 return &dir_static; |
202 } | 213 } |
203 | 214 |
204 /* Emulate getpwuid, getpwnam and others. */ | 215 /* Emulate getpwuid, getpwnam and others. */ |
376 srandom (int seed) | 387 srandom (int seed) |
377 { | 388 { |
378 srand (seed); | 389 srand (seed); |
379 } | 390 } |
380 | 391 |
392 /* Normalize filename by converting all path separators to | |
393 the specified separator. Also conditionally convert upper | |
394 case path name components to lower case. */ | |
395 | |
396 static void | |
397 normalize_filename (fp, path_sep) | |
398 register char *fp; | |
399 char path_sep; | |
400 { | |
401 char sep; | |
402 char *elem; | |
403 | |
404 if (NILP (Vwin32_downcase_file_names)) | |
405 { | |
406 while (*fp) | |
407 { | |
408 if (*fp == '/' || *fp == '\\') | |
409 *fp = path_sep; | |
410 fp++; | |
411 } | |
412 return; | |
413 } | |
414 | |
415 sep = path_sep; /* convert to this path separator */ | |
416 elem = fp; /* start of current path element */ | |
417 | |
418 do { | |
419 if (*fp >= 'a' && *fp <= 'z') | |
420 elem = 0; /* don't convert this element */ | |
421 | |
422 if (*fp == 0 || *fp == ':') | |
423 { | |
424 sep = *fp; /* restore current separator (or 0) */ | |
425 *fp = '/'; /* after conversion of this element */ | |
426 } | |
427 | |
428 if (*fp == '/' || *fp == '\\') | |
429 { | |
430 if (elem && elem != fp) | |
431 { | |
432 *fp = 0; /* temporary end of string */ | |
433 _strlwr (elem); /* while we convert to lower case */ | |
434 } | |
435 *fp = sep; /* convert (or restore) path separator */ | |
436 elem = fp + 1; /* next element starts after separator */ | |
437 sep = path_sep; | |
438 } | |
439 } while (*fp++); | |
440 } | |
441 | |
381 /* Destructively turn backslashes into slashes. */ | 442 /* Destructively turn backslashes into slashes. */ |
382 void | 443 void |
383 dostounix_filename (p) | 444 dostounix_filename (p) |
384 register char *p; | 445 register char *p; |
385 { | 446 { |
386 while (*p) | 447 normalize_filename (p, '/'); |
387 { | |
388 if (*p == '\\') | |
389 *p = '/'; | |
390 p++; | |
391 } | |
392 } | 448 } |
393 | 449 |
394 /* Destructively turn slashes into backslashes. */ | 450 /* Destructively turn slashes into backslashes. */ |
395 void | 451 void |
396 unixtodos_filename (p) | 452 unixtodos_filename (p) |
397 register char *p; | 453 register char *p; |
398 { | 454 { |
399 while (*p) | 455 normalize_filename (p, '\\'); |
400 { | |
401 if (*p == '/') | |
402 *p = '\\'; | |
403 p++; | |
404 } | |
405 } | 456 } |
406 | 457 |
407 /* Remove all CR's that are followed by a LF. | 458 /* Remove all CR's that are followed by a LF. |
408 (From msdos.c...probably should figure out a way to share it, | 459 (From msdos.c...probably should figure out a way to share it, |
409 although this code isn't going to ever change.) */ | 460 although this code isn't going to ever change.) */ |