MSYSで変換される引数を元に戻すラッパー(不完全)
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 <cstdio> | |
#include <vector> | |
#include <string> | |
#include <process.h> | |
using namespace std; | |
string root1 = "C:/MinGW/msys/1.0/"; | |
string replace(const string &a, const string &b, const string &c) { | |
string ret = a; | |
int p; | |
while ((p = ret.find(b)) >= 0) | |
ret.replace(p, b.length(), c); | |
return ret; | |
} | |
string root2 = replace(root1, "/", "\\"); | |
bool prefix(const string &a, const string &b) { | |
return a.substr(0, b.length()) == b; | |
} | |
int main(int argc, char *argv[]) { | |
vector<string> args(argc - 1); | |
vector<const char *> cargs(argc); | |
for (int i = 1; i < argc; i++) { | |
string arg = argv[i]; | |
if (prefix(arg, root1) || prefix(arg, root2)) { | |
string arg2 = replace(arg.substr(root1.length()), ";", ":"); | |
int p1 = arg2.find('\\'); | |
int p2 = arg2.find(':'); | |
if (p1 < 0 || (p2 >= 0 && p2 < p1)) { | |
arg = "/" + arg2; | |
} | |
} else if (arg.length() > 1 && arg[1] == ':') { | |
if (arg.length() < 3 || arg[2] != '\\') | |
arg = "/" + arg; | |
} | |
args[i - 1] = arg; | |
} | |
for (int i = 1; i < argc; i++) { | |
cargs[i - 1] = args[i - 1].c_str(); | |
printf("%d: %s -> %s\n", i, argv[i], cargs[i - 1]); | |
} | |
return _spawnv(_P_WAIT, cargs[0], &cargs[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment