svg2png: fixing the args interpretation (#760)

The background color was misinterpreted and its value was treated
as an svg file name (warning was returned).
The color format can not be passed in a `#ffffff` format, since
the '#' sign is used in bash to comment a line and nothiing after
it is loaded.
This commit is contained in:
Mira Grudzinska 2021-08-31 11:14:16 +02:00 committed by GitHub
parent c6becf4ec6
commit a1480bedb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -177,7 +177,7 @@ public:
const char* p = argv[i];
if (*p == '-') {
//flags
const char* p_arg = (i + 1 < argc) ? argv[i] : nullptr;
const char* p_arg = (i + 1 < argc) ? argv[++i] : nullptr;
if (p[1] == 'r') {
//image resolution
if (!p_arg) {
@ -198,12 +198,11 @@ public:
} else if (p[1] == 'b') {
//image background color
if (!p_arg) {
cout << "Error: Missing background color attribute. Expected eg. -b #fa7410." << endl;
cout << "Error: Missing background color attribute. Expected eg. -b fa7410." << endl;
return 1;
}
if (*p_arg == '#') ++p_arg;
bgColor = (uint32_t) strtol(p, NULL, 16);
bgColor = (uint32_t) strtol(p_arg, NULL, 16);
} else {
cout << "Warning: Unknown flag (" << p << ")." << endl;