aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-06-03 21:18:55 +0000
committerRichard M. Stallman1996-06-03 21:18:55 +0000
commitcbe39279d3203a26cd13f9d2d935c6c242187f18 (patch)
tree04792ba8a0336c3310ddbb3812eeb3998f27373c /src
parent0c04091e600fd02cc01c5f735f033ad81924eaed (diff)
downloademacs-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.
Diffstat (limited to 'src')
-rw-r--r--src/w32.c75
1 files changed, 63 insertions, 12 deletions
diff --git a/src/w32.c b/src/w32.c
index 845203a774e..e3045236465 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -122,6 +122,8 @@ static HANDLE dir_find_handle = INVALID_HANDLE_VALUE;
122static int dir_is_fat; 122static int dir_is_fat;
123static char dir_pathname[MAXPATHLEN+1]; 123static char dir_pathname[MAXPATHLEN+1];
124 124
125extern Lisp_Object Vwin32_downcase_file_names;
126
125DIR * 127DIR *
126opendir (char *filename) 128opendir (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
396static void
397normalize_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. */
382void 443void
383dostounix_filename (p) 444dostounix_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
396unixtodos_filename (p) 452unixtodos_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.