-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
45 lines (39 loc) · 1.54 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <string>
#include <tuple>
#include <gst/gst.h>
#include "utils.h"
[[nodiscard]] std::tuple<std::string, std::string, bool> parse_args(int argc, char** argv) {
std::string inputFile;
std::string outputFile;
// Checking if the correct number of arguments is provided, exiting otherwise
if (argc < 3 || argc > 4) {
g_printerr("Usage: %s <input_file> <output_file> --verbose[optional]\n", argv[0]);
exit(static_cast<int>(error_codes::WrongNumberOfArguments));
}
// Reading the command line arguments
bool verbose = false;
inputFile = argv[1];
outputFile = argv[2];
if (argc == 4) {
if (std::string(argv[3]) == std::string("--verbose")) {
verbose = true;
} else {
g_printerr("Usage: %s <input_file> <output_file> --verbose[optional]\n", argv[0]);
exit(static_cast<int>(error_codes::WrongNumberOfArguments));
}
}
// Checking output file extension: must be .mkv
{
auto point_iter = outputFile.find('.');
if (point_iter == std::string::npos || point_iter == outputFile.size() - 1) {
g_printerr("No output file extension\n");
exit(static_cast<int>(error_codes::WrongOutputFileExt));
}
auto extension = outputFile.substr(point_iter + 1);
if (extension != "mkv") {
g_printerr("Bad output file extension (must be .mkv)\n");
exit(static_cast<int>(error_codes::WrongOutputFileExt));
}
}
return std::tuple(inputFile, outputFile, verbose);
}