Mercurial > vim
comparison src/fileio.c @ 19526:22f0dda71638 v8.2.0320
patch 8.2.0320: no Haiku support
Commit: https://github.com/vim/vim/commit/b3f740695a0199d22cd97aee314f06c7ae32d2ea
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Feb 26 16:16:53 2020 +0100
patch 8.2.0320: no Haiku support
Problem: No Haiku support.
Solution: Add support for Haiku. (Emir Sari, closes https://github.com/vim/vim/issues/5605)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 26 Feb 2020 16:30:04 +0100 |
parents | 2bb0e80fcd32 |
children | c32b295af9c5 |
comparison
equal
deleted
inserted
replaced
19525:619eb9bc3249 | 19526:22f0dda71638 |
---|---|
3365 } | 3365 } |
3366 | 3366 |
3367 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ | 3367 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ |
3368 || defined(FEAT_GUI_MSWIN) \ | 3368 || defined(FEAT_GUI_MSWIN) \ |
3369 || defined(FEAT_GUI_MAC) \ | 3369 || defined(FEAT_GUI_MAC) \ |
3370 || defined(FEAT_GUI_HAIKU) \ | |
3370 || defined(PROTO) | 3371 || defined(PROTO) |
3371 /* | 3372 /* |
3372 * Shorten all filenames in "fnames[count]" by current directory. | 3373 * Shorten all filenames in "fnames[count]" by current directory. |
3373 */ | 3374 */ |
3374 void | 3375 void |
4420 garray_T *gap, | 4421 garray_T *gap, |
4421 char_u *path, | 4422 char_u *path, |
4422 void *context, | 4423 void *context, |
4423 int (*checkitem)(void *context, char_u *name)) | 4424 int (*checkitem)(void *context, char_u *name)) |
4424 { | 4425 { |
4425 int failed = FALSE; | 4426 int failed = FALSE; |
4427 char_u *p; | |
4428 | |
4429 ga_init2(gap, (int)sizeof(char *), 20); | |
4430 | |
4426 # ifdef MSWIN | 4431 # ifdef MSWIN |
4427 char_u *buf, *p; | 4432 { |
4428 int ok; | 4433 char_u *buf; |
4429 HANDLE hFind = INVALID_HANDLE_VALUE; | 4434 int ok; |
4430 WIN32_FIND_DATAW wfb; | 4435 HANDLE hFind = INVALID_HANDLE_VALUE; |
4431 WCHAR *wn = NULL; // UTF-16 name, NULL when not used. | 4436 WIN32_FIND_DATAW wfb; |
4432 # endif | 4437 WCHAR *wn = NULL; // UTF-16 name, NULL when not used. |
4433 | 4438 |
4434 ga_init2(gap, (int)sizeof(char *), 20); | 4439 buf = alloc(MAXPATHL); |
4435 | 4440 if (buf == NULL) |
4436 # ifdef MSWIN | 4441 return FAIL; |
4437 buf = alloc(MAXPATHL); | 4442 STRNCPY(buf, path, MAXPATHL-5); |
4438 if (buf == NULL) | 4443 p = buf + STRLEN(buf); |
4439 return FAIL; | 4444 MB_PTR_BACK(buf, p); |
4440 STRNCPY(buf, path, MAXPATHL-5); | 4445 if (*p == '\\' || *p == '/') |
4441 p = buf + STRLEN(buf); | 4446 *p = NUL; |
4442 MB_PTR_BACK(buf, p); | 4447 STRCAT(buf, "\\*"); |
4443 if (*p == '\\' || *p == '/') | 4448 |
4444 *p = NUL; | 4449 wn = enc_to_utf16(buf, NULL); |
4445 STRCAT(buf, "\\*"); | 4450 if (wn != NULL) |
4446 | 4451 hFind = FindFirstFileW(wn, &wfb); |
4447 wn = enc_to_utf16(buf, NULL); | 4452 ok = (hFind != INVALID_HANDLE_VALUE); |
4448 if (wn != NULL) | 4453 if (!ok) |
4449 hFind = FindFirstFileW(wn, &wfb); | 4454 { |
4450 ok = (hFind != INVALID_HANDLE_VALUE); | 4455 failed = TRUE; |
4451 if (!ok) | 4456 smsg(_(e_notopen), path); |
4452 { | 4457 } |
4453 failed = TRUE; | 4458 else |
4454 smsg(_(e_notopen), path); | 4459 { |
4455 } | 4460 while (ok) |
4456 else | |
4457 { | |
4458 while (ok) | |
4459 { | |
4460 int ignore; | |
4461 | |
4462 p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here | |
4463 if (p == NULL) | |
4464 break; // out of memory | |
4465 | |
4466 ignore = p[0] == '.' && (p[1] == NUL | |
4467 || (p[1] == '.' && p[2] == NUL)); | |
4468 if (!ignore && checkitem != NULL) | |
4469 { | 4461 { |
4470 int r = checkitem(context, p); | 4462 int ignore; |
4471 | 4463 |
4472 if (r < 0) | 4464 p = utf16_to_enc(wfb.cFileName, NULL); // p is allocated here |
4465 if (p == NULL) | |
4466 break; // out of memory | |
4467 | |
4468 ignore = p[0] == '.' && (p[1] == NUL | |
4469 || (p[1] == '.' && p[2] == NUL)); | |
4470 if (!ignore && checkitem != NULL) | |
4473 { | 4471 { |
4474 vim_free(p); | 4472 int r = checkitem(context, p); |
4473 | |
4474 if (r < 0) | |
4475 { | |
4476 vim_free(p); | |
4477 break; | |
4478 } | |
4479 if (r == 0) | |
4480 ignore = TRUE; | |
4481 } | |
4482 | |
4483 if (!ignore) | |
4484 { | |
4485 if (ga_grow(gap, 1) == OK) | |
4486 ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p); | |
4487 else | |
4488 { | |
4489 failed = TRUE; | |
4490 vim_free(p); | |
4491 break; | |
4492 } | |
4493 } | |
4494 | |
4495 vim_free(p); | |
4496 ok = FindNextFileW(hFind, &wfb); | |
4497 } | |
4498 FindClose(hFind); | |
4499 } | |
4500 | |
4501 vim_free(buf); | |
4502 vim_free(wn); | |
4503 } | |
4504 # else | |
4505 { | |
4506 DIR *dirp; | |
4507 struct dirent *dp; | |
4508 | |
4509 dirp = opendir((char *)path); | |
4510 if (dirp == NULL) | |
4511 { | |
4512 failed = TRUE; | |
4513 smsg(_(e_notopen), path); | |
4514 } | |
4515 else | |
4516 { | |
4517 for (;;) | |
4518 { | |
4519 int ignore; | |
4520 | |
4521 dp = readdir(dirp); | |
4522 if (dp == NULL) | |
4475 break; | 4523 break; |
4524 p = (char_u *)dp->d_name; | |
4525 | |
4526 ignore = p[0] == '.' && | |
4527 (p[1] == NUL || | |
4528 (p[1] == '.' && p[2] == NUL)); | |
4529 if (!ignore && checkitem != NULL) | |
4530 { | |
4531 int r = checkitem(context, p); | |
4532 | |
4533 if (r < 0) | |
4534 break; | |
4535 if (r == 0) | |
4536 ignore = TRUE; | |
4476 } | 4537 } |
4477 if (r == 0) | 4538 |
4478 ignore = TRUE; | 4539 if (!ignore) |
4479 } | |
4480 | |
4481 if (!ignore) | |
4482 { | |
4483 if (ga_grow(gap, 1) == OK) | |
4484 ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p); | |
4485 else | |
4486 { | 4540 { |
4487 failed = TRUE; | 4541 if (ga_grow(gap, 1) == OK) |
4488 vim_free(p); | 4542 ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p); |
4489 break; | 4543 else |
4544 { | |
4545 failed = TRUE; | |
4546 break; | |
4547 } | |
4490 } | 4548 } |
4491 } | 4549 } |
4492 | 4550 |
4493 vim_free(p); | 4551 closedir(dirp); |
4494 ok = FindNextFileW(hFind, &wfb); | 4552 } |
4495 } | |
4496 FindClose(hFind); | |
4497 } | |
4498 | |
4499 vim_free(buf); | |
4500 vim_free(wn); | |
4501 # else | |
4502 DIR *dirp; | |
4503 struct dirent *dp; | |
4504 char_u *p; | |
4505 | |
4506 dirp = opendir((char *)path); | |
4507 if (dirp == NULL) | |
4508 { | |
4509 failed = TRUE; | |
4510 smsg(_(e_notopen), path); | |
4511 } | |
4512 else | |
4513 { | |
4514 for (;;) | |
4515 { | |
4516 int ignore; | |
4517 | |
4518 dp = readdir(dirp); | |
4519 if (dp == NULL) | |
4520 break; | |
4521 p = (char_u *)dp->d_name; | |
4522 | |
4523 ignore = p[0] == '.' && | |
4524 (p[1] == NUL || | |
4525 (p[1] == '.' && p[2] == NUL)); | |
4526 if (!ignore && checkitem != NULL) | |
4527 { | |
4528 int r = checkitem(context, p); | |
4529 | |
4530 if (r < 0) | |
4531 break; | |
4532 if (r == 0) | |
4533 ignore = TRUE; | |
4534 } | |
4535 | |
4536 if (!ignore) | |
4537 { | |
4538 if (ga_grow(gap, 1) == OK) | |
4539 ((char_u**)gap->ga_data)[gap->ga_len++] = vim_strsave(p); | |
4540 else | |
4541 { | |
4542 failed = TRUE; | |
4543 break; | |
4544 } | |
4545 } | |
4546 } | |
4547 | |
4548 closedir(dirp); | |
4549 } | 4553 } |
4550 # endif | 4554 # endif |
4551 | 4555 |
4552 if (!failed && gap->ga_len > 0) | 4556 if (!failed && gap->ga_len > 0) |
4553 sort_strings((char_u **)gap->ga_data, gap->ga_len); | 4557 sort_strings((char_u **)gap->ga_data, gap->ga_len); |