aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/main.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-06-05 23:33:44 +0200
committerjaseg <git@jaseg.de>2021-06-05 23:33:44 +0200
commit4ffb4c65825ab0a5ded00ff799b494097e7bd143 (patch)
tree68791213543bd330a094c67469a1de745c36867a /svg-flatten/src/main.cpp
parentf2f0ac241672bbaac4ccb9eaa369c501951de949 (diff)
downloadgerbolyze-4ffb4c65825ab0a5ded00ff799b494097e7bd143.tar.gz
gerbolyze-4ffb4c65825ab0a5ded00ff799b494097e7bd143.tar.bz2
gerbolyze-4ffb4c65825ab0a5ded00ff799b494097e7bd143.zip
Make svg-flatten auto-search for cargo dependencies in all call sites
Diffstat (limited to 'svg-flatten/src/main.cpp')
-rw-r--r--svg-flatten/src/main.cpp70
1 files changed, 3 insertions, 67 deletions
diff --git a/svg-flatten/src/main.cpp b/svg-flatten/src/main.cpp
index 1fce67b..d89da7c 100644
--- a/svg-flatten/src/main.cpp
+++ b/svg-flatten/src/main.cpp
@@ -1,18 +1,16 @@
#include <cstdlib>
#include <cstdio>
-#include <sys/types.h>
-#include <pwd.h>
#include <filesystem>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <argagg.hpp>
-#include <subprocess.h>
#include <gerbolyze.hpp>
#include "vec_core.h"
#include <base64.h>
+#include "util.h"
using argagg::parser_results;
using argagg::parser;
@@ -354,70 +352,8 @@ int main(int argc, char **argv) {
}
string dpi_str = to_string(dpi);
- const char *homedir;
- if ((homedir = getenv("HOME")) == NULL) {
- homedir = getpwuid(getuid())->pw_dir;
- }
- string homedir_s(homedir);
- string loc_in_home = homedir_s + "/.cargo/bin/usvg";
-
- const char *command_line[] = {nullptr, "--keep-named-groups", "--dpi", dpi_str.c_str(), barf.c_str(), frob.c_str(), NULL};
- bool found_usvg = false;
- int usvg_rc=-1;
- for (int i=0; i<3; i++) {
- const char *usvg_envvar;
- switch (i) {
- case 0:
- if ((usvg_envvar = getenv("USVG")) == NULL) {
- continue;
- } else {
- command_line[0] = "usvg";
- }
- break;
-
- case 1:
- command_line[0] = "usvg";
- break;
-
- case 2:
- command_line[0] = loc_in_home.c_str();
- break;
- }
-
- struct subprocess_s subprocess;
- int rc = subprocess_create(command_line, subprocess_option_inherit_environment, &subprocess);
- if (rc) {
- cerr << "Error calling usvg!" << endl;
- return EXIT_FAILURE;
- }
-
- usvg_rc = -1;
- rc = subprocess_join(&subprocess, &usvg_rc);
- if (rc) {
- cerr << "Error calling usvg!" << endl;
- return EXIT_FAILURE;
- }
-
- rc = subprocess_destroy(&subprocess);
- if (rc) {
- cerr << "Error calling usvg!" << endl;
- return EXIT_FAILURE;
- }
-
- if (usvg_rc == 255) {
- continue;
- }
- found_usvg = true;
- break;
- }
-
- if (!found_usvg) {
- cerr << "Error: Cannot find usvg. Is it installed and in $PATH?" << endl;
- return EXIT_FAILURE;
- }
-
- if (usvg_rc) {
- cerr << "usvg returned an error code: " << usvg_rc << endl;
+ const char *command_line[] = {nullptr, "--keep-named-groups", "--dpi", dpi_str.c_str(), barf.c_str(), frob.c_str(), nullptr};
+ if (run_cargo_command("usvg", command_line, "USVG")) {
return EXIT_FAILURE;
}
}