diff options
| author | Richard M. Stallman | 1996-06-03 21:18:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-06-03 21:18:55 +0000 |
| commit | cbe39279d3203a26cd13f9d2d935c6c242187f18 (patch) | |
| tree | 04792ba8a0336c3310ddbb3812eeb3998f27373c | |
| parent | 0c04091e600fd02cc01c5f735f033ad81924eaed (diff) | |
| download | emacs-cbe39279d3203a26cd13f9d2d935c6c242187f18.tar.gz emacs-cbe39279d3203a26cd13f9d2d935c6c242187f18.zip | |
(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.
| -rw-r--r-- | src/w32.c | 75 |
1 files changed, 63 insertions, 12 deletions
| @@ -122,6 +122,8 @@ 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 | { |
| @@ -197,6 +199,15 @@ readdir (DIR *dirp) | |||
| 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 | } |
| @@ -378,17 +389,62 @@ srandom (int seed) | |||
| 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. */ |
| @@ -396,12 +452,7 @@ 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. |