Skip to content

Instantly share code, notes, and snippets.

@darealshinji
Created December 4, 2017 17:52
Show Gist options
  • Select an option

  • Save darealshinji/1ba37a2ae506c7d1fca30b13788aa3e8 to your computer and use it in GitHub Desktop.

Select an option

Save darealshinji/1ba37a2ae506c7d1fca30b13788aa3e8 to your computer and use it in GitHub Desktop.
/**
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
*
* In jurisdictions that recognize copyright laws, the author or authors
* of this software dedicate any and all copyright interest in the
* software to the public domain. We make this dedication for the benefit
* of the public at large and to the detriment of our heirs and
* successors. We intend this dedication to be an overt act of
* relinquishment in perpetuity of all present and future rights to this
* software under copyright law.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to <http://unlicense.org/>
*/
#include <iostream>
#include <errno.h>
#include <libgen.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
std::string cmd, arg, fullcmd;
char *pfx;
char *argv_child[argc + 1] = {0};
int i, j = 1, errsv, rv = 0;
cmd = "mkvtoolnix-gui";
if (argc > 1 && strncmp(argv[1], "mkv", 3) == 0) {
arg = std::string(argv[1]);
if (arg == "mkvinfo-gui") {
cmd = "mkvinfo";
argv_child[1] = (char *)"-g";
j = 2;
} else if (arg == "mkvinfo" || arg == "mkvinfo-text")
cmd = "mkvinfo";
else if (arg == "mkvextract")
cmd = "mkvextract";
else if (arg == "mkvmerge")
cmd = "mkvmerge";
else if (arg == "mkvpropedit")
cmd = "mkvpropedit";
}
if (!(pfx = realpath("/proc/self/exe", NULL))) {
std::cerr << "error: could not resolve /proc/self/exe" << std::endl;
return 1;
} else {
fullcmd = std::string(dirname(pfx)) + "/" + cmd;
free(pfx);
}
argv_child[0] = (char *)fullcmd.c_str();
if (argc > 1) {
for (i = 2; i < argc; i++, j++) {
argv_child[j] = argv[i];
}
}
rv = execvp(fullcmd.c_str(), argv_child);
errsv = errno;
if (rv == -1) {
std::cerr << "execvp() failed to run `" << fullcmd << "': " << strerror(errsv) << std::endl;
return errsv;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment