forked from rmyorston/busybox-w32
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This topic branch adds the `cygpath` applet that closely imitates MSYS2's tool of the same name. Further, the `PATH` variable is special-cased to get the `cygpath` treatment automagically: whenever a user sets it to a Unix-style path list, we now try to convert that automatically to a Windows-style path list (albeit with forward-slashes). Signed-off-by: Johannes Schindelin <[email protected]>
- Loading branch information
Showing
11 changed files
with
381 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Convert MSYS-style paths to Win32-style ones | ||
* | ||
* Copyright (C) 2022 Johannes Schindelin <[email protected]> | ||
* | ||
* Licensed under GPLv2, see file LICENSE in this source tree. | ||
*/ | ||
//config:config CYGPATH | ||
//config: bool "cygpath" | ||
//config: default y | ||
//config: depends on PLATFORM_MINGW32 | ||
//config: help | ||
//config: Convert Unix and Windows format paths | ||
|
||
//applet:IF_CYGPATH(APPLET_NOEXEC(cygpath, cygpath, BB_DIR_USR_BIN, BB_SUID_DROP, cygpath)) | ||
|
||
//kbuild:lib-$(CONFIG_CYGPATH) += cygpath.o | ||
|
||
//usage:#define cygpath_trivial_usage | ||
//usage: "ARG|ARGS" | ||
//usage:#define cygpath_full_usage "\n\n" | ||
//usage: "Convert Unix and Windows format paths" | ||
|
||
#include "libbb.h" | ||
#include "path-convert.h" | ||
|
||
enum { | ||
OPT_absolute = (1 << 0), | ||
OPT_mixed = (1 << 1), | ||
OPT_unix = (1 << 2), | ||
OPT_windows = (1 << 3), | ||
OPT_path_list = (1 << 4), | ||
}; | ||
|
||
int cygpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
int cygpath_main(int argc UNUSED_PARAM, char **argv) | ||
{ | ||
int i; | ||
enum path_convert_flag flags = 0; | ||
#if ENABLE_LONG_OPTS | ||
static const char cygpath_longopts[] ALIGN1 = | ||
"absolute\0" No_argument "a" | ||
"mixed\0" No_argument "m" | ||
"unix\0" No_argument "u" | ||
"windows\0" No_argument "w" | ||
"path\0" No_argument "p" | ||
; | ||
#endif | ||
int opt = getopt32long(argv, "amuwp", cygpath_longopts); | ||
argv += optind; | ||
argc -= optind; | ||
|
||
if (opt & OPT_absolute) | ||
flags |= PATH_CONVERT_ABSOLUTE; | ||
if (opt & OPT_mixed) | ||
flags |= PATH_CONVERT_MIXED; | ||
if (opt & OPT_unix) | ||
flags |= PATH_CONVERT_UNIX; | ||
if (opt & OPT_windows) | ||
flags |= PATH_CONVERT_WINDOWS; | ||
|
||
for (i = 0; i < argc; i++) { | ||
char *to_free = NULL; | ||
const char *path = argv[i], *result; | ||
char buffer[PATH_MAX_LONG]; | ||
|
||
if (!*argv[i]) { | ||
bb_error_msg("can't convert empty path"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
if (opt & OPT_path_list) | ||
result = to_free = path_convert_path_list(path, flags); | ||
else | ||
result = path_convert(path, buffer, sizeof(buffer), flags); | ||
|
||
if (!result) | ||
return EXIT_FAILURE; | ||
|
||
printf("%s\n", result); | ||
|
||
free(to_free); | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
set -x | ||
|
||
# Copyright 2022 by Johannes Schindelin <[email protected]> | ||
# Licensed under GPLv2, see file LICENSE in this source tree. | ||
|
||
. ./testing.sh | ||
|
||
# testing "description" "command" "result" "infile" "stdin" | ||
pseudo_root="$(cygpath -am /)" | ||
res=$? | ||
case "$pseudo_root" in */) s="ends in a slash";; *) s=;; esac | ||
|
||
testing "pseudo root" 'echo $res,$s,"$pseudo_root"' "0,,$pseudo_root | ||
" "" "" | ||
|
||
testing "cygpath -aw" "cygpath -aw /c/ /c/123 /c/324" 'C:\\ | ||
C:\\123 | ||
C:\\324 | ||
' "" "" | ||
|
||
testing "cygpath -am" "cygpath -am /c/ /c/123 /c/324 / /lib" "C:/ | ||
C:/123 | ||
C:/324 | ||
$pseudo_root | ||
${pseudo_root}/lib | ||
" "" "" | ||
|
||
testing "cygpath -u" 'cygpath -u C:\\ abc' '/c/ | ||
abc | ||
' "" "" | ||
|
||
testing "cygpath and dots" 'cygpath -am . ./. ../. ./..' "$PWD | ||
$PWD | ||
${PWD%/*} | ||
${PWD%/*} | ||
" "" "" | ||
|
||
testing "cygpath ''" '! cygpath "" abc 2>&1' "cygpath: can't convert empty path | ||
" "" "" | ||
|
||
testing "cygpath -p" 'cygpath -pam .:./.:/c/' "$PWD;$PWD;C:/ | ||
" "" "" | ||
|
||
testing "cygpath -p" 'cygpath -pam .:' "$PWD;$PWD | ||
" "" "" | ||
|
||
testing "cygpath -u" "cygpath -pau \"$pseudo_root;${pseudo_root}/lib\"" "/:/lib | ||
" "" "" | ||
|
||
testing "cygpath -m <unix-style-path>" "cygpath -m /lib" "$pseudo_root/lib | ||
" "" "" | ||
|
||
exit $FAILCOUNT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.