Skip to content

Instantly share code, notes, and snippets.

@7shi
Created May 5, 2012 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/2603273 to your computer and use it in GitHub Desktop.
Save 7shi/2603273 to your computer and use it in GitHub Desktop.
MSYSで変換される引数を元に戻すラッパー(不完全)
#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