-
-
Save psxdev/e86a53ab5d4115ce25dc to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
#define PSP2LINK_MAX_PATH 1024 | |
void win_to_unix(char *pathname) | |
{ | |
int loop0 = 0; | |
for (loop0=0; loop0<strlen(pathname); loop0++) { if (pathname[loop0] == '\\') { pathname[loop0] = '/'; } } | |
return; | |
} | |
int fix_pathname(char *pathname) | |
{ | |
char new_pathname[PSP2LINK_MAX_PATH]; | |
memset(new_pathname, 0, sizeof(new_pathname)); | |
if (strncmp(pathname, "host0:", 6) == 0) | |
{ | |
if (pathname[6] != '/' && !strchr(pathname + 6, ':')) | |
{ | |
#if defined (__CYGWIN__) || defined (__MINGW32__) | |
_getcwd(new_pathname, PSP2LINK_MAX_PATH); | |
#else | |
getcwd(new_pathname, PSP2LINK_MAX_PATH); | |
strcat(new_pathname,"/"); | |
#endif | |
} | |
strcat(new_pathname, pathname + 6); | |
// Convert \ to / for unix compatibility. | |
win_to_unix(new_pathname); | |
// Remove end-slash | |
int len = strlen(new_pathname); | |
if (len >= 2 && new_pathname[len - 2] != ':' && new_pathname[len - 1] == '/') | |
new_pathname[len - 1] = '\0'; | |
} | |
else | |
{ | |
printf("Path received does not include host0: %s\n", new_pathname); | |
} | |
printf("%s -> %s\n", pathname, new_pathname); | |
strcpy(pathname, new_pathname); | |
return 0; | |
} | |
int main(int argc, char **argv) | |
{ | |
//printf("str return %s\n",strchr(argv[1] + 6, ':')); | |
fix_pathname(argv[1]); | |
return 0; | |
} | |
-----unix ----- | |
$ cat sal.txt | |
host0: | |
host0:foo | |
host0:foo/ | |
host0:../foo | |
host0:foo/bar | |
host0:foo/bar/ | |
host0:c: | |
host0:c:/ | |
host0:/foo/bar | |
host0:../foo/bar | |
host0:/../foo/bar | |
host0:/foo/bar/ | |
host0:c:/foo/bar | |
host0:c:/foo/bar/ | |
$ for i in `cat sal.txt `; do ./a.out $i; done | |
host0: -> /private/tmp | |
host0:foo -> /private/tmp/foo | |
host0:foo/ -> /private/tmp/foo | |
host0:../foo -> /private/tmp/../foo | |
host0:foo/bar -> /private/tmp/foo/bar | |
host0:foo/bar/ -> /private/tmp/foo/bar | |
host0:c: -> c: | |
host0:c:/ -> c:/ | |
host0:/foo/bar -> /foo/bar | |
host0:../foo/bar -> /private/tmp/../foo/bar | |
host0:/../foo/bar -> /../foo/bar | |
host0:/foo/bar/ -> /foo/bar | |
host0:c:/foo/bar -> c:/foo/bar | |
host0:c:/foo/bar/ -> c:/foo/bar | |
----windows---- | |
host0: | |
host0:foo | |
host0:foo/ | |
host0:../foo | |
host0:foo/bar | |
host0:foo/bar/ | |
host0:c: | |
host0:c:/ | |
host0:c:/foo/bar | |
host0:../foo/bar | |
host0:c:/../foo/bar | |
host0:c:/foo/bar/ | |
host0:c:/foo/bar | |
$ for i in `cat sal.txt `; do a.exe $i; done | |
host0: -> c:/ | |
host0:foo -> c:/foo | |
host0:foo/ -> c:/foo | |
Path received does not include host0: | |
host0;..\foo -> | |
host0:foo/bar -> c:/foo/bar | |
host0:foo/bar/ -> c:/foo/bar | |
host0:c: -> c: | |
host0:c:/ -> c:/ | |
host0:c:/foo/bar -> c:/foo/bar | |
Path received does not include host0: | |
host0;..\foo\bar -> | |
host0:c:/../foo/bar -> c:/../foo/bar | |
host0:c:/foo/bar/ -> c:/foo/bar | |
host0:c:/foo/bar -> c:/foo/bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment