Skip to content

Added ability to output to screen #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ $ vsd2svg-conv -i ./my.VSD -o ./out/ -s 7
$ ls out/
Page-1.svg Page-2.svg Page-3.svg Page-4.svg

# output to screen
$ vsd2svg-conv -i ./my.VSD

# help
$ vsd2svg-conv --help
```
Expand Down
40 changes: 21 additions & 19 deletions src/conv/vsd2svg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ static char doc[] = "vsd2svg -- Visio VSD to SVG converter";

static struct argp_option options[] = {
{"input", 'i', "FILE", 0, "Input Visio .vsd file"},
{"output", 'o', "DIR", 0, "Output directory"},
{"output", 'o', "DIR", 0, "Write SVGs to output directory"},
{"scaling", 's', "FLOAT", 0, "Scaling factor"},
{"version", 'V', 0, 0, "Print vsd2svg version"},
{0}};

/* A description of the arguments we accept. */
static char args_doc[] = "[options] -i <in vsd> -o <out dir>";
static char args_doc[] = "[options] -i <in vsd>";

struct arguments {
char *args[2]; /* arg1 & arg2 */
Expand Down Expand Up @@ -120,11 +120,10 @@ int main(int argc, char *argv[]) {
<< "Missing --input=FILE argument\n";
return 1;
}

if (arguments.output == NULL) {
std::cerr << "[ERROR] "
<< "Missing --output=DIR argument\n";
return 1;
std::string outputdir("");
if (arguments.output != NULL) {
std::string outputdir(arguments.output);
mkdir(arguments.output, S_IRWXU);
}

std::ifstream stin(arguments.input);
Expand All @@ -143,27 +142,30 @@ int main(int argc, char *argv[]) {

ret = converter.vsd2svg(in, out, scaling);

std::string outputdir(arguments.output);
mkdir(arguments.output, S_IRWXU);

for (const auto &rule_pair : out) {
ofstream myfile;
#ifdef SAFE_FILENAME
std::regex e("[^A-Za-z0-9-]");
std::basic_string<char> newfilename =
outputdir + "/" + std::regex_replace(rule_pair.first, e, "_") +
".svg";
outputdir + (arguments.output != NULL ? "/" : "") + std::regex_replace(rule_pair.first, e, "_") + ".svg";
#else
std::basic_string<char> newfilename =
outputdir + rule_pair.first + ".svg";
#endif
myfile.open(newfilename);
myfile << rule_pair.second << std::endl;
myfile.close();
if (!myfile) {
std::cerr << "[ERROR] "
<< "Failed to write file '" << rule_pair.first << "'\n";
ret = 1;
if (arguments.output != NULL) {
myfile.open(newfilename);
myfile << rule_pair.second << std::endl;
myfile.close();
if (!myfile) {
std::cerr << "[ERROR] "
<< "Failed to write file '" << rule_pair.first << "'\n";
ret = 1;
}
}
else
{
std::cout << rule_pair.second << std::endl;
std::cout << "\n######################################\n";
}
}

Expand Down