Skip to content

Commit 5ede59f

Browse files
committed
refactor OBCViewer
1 parent b27d6d7 commit 5ede59f

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

tools/OBCViewer/OBCViewer.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace fs = std::filesystem;
1515

16-
const std::string versionNumber = "1.6";
16+
const std::string versionNumber = "1.7";
1717

1818
void printHeader() {
1919
std::cout << "======================" << std::endl;
@@ -41,7 +41,6 @@ int main(int argc, char* argv[]) {
4141
return 1;
4242
}
4343

44-
// Here are listed the strings for OBC itself.
4544
std::string inputOBC = argv[1];
4645

4746
#ifdef __unix__
@@ -52,73 +51,73 @@ int main(int argc, char* argv[]) {
5251
#endif
5352

5453
// Check if the input file is an OBC Script.
55-
fs::path inputScript(inputOBC);
56-
if (inputScript.extension() != ".obc") {
57-
std::cerr << "Error: This File is not an OBC Script!" << std::endl;
54+
fs::path inputFile(inputOBC);
55+
if (inputFile.extension() != ".obc") {
56+
fprintf(stderr, "Error: This File is not an OBC Script!");
5857
return 1;
5958
}
6059

6160
// Use the OBC Script for Input
6261
std::ifstream OBCInput(inputOBC);
6362

6463
if (!OBCInput) {
65-
std::cerr << "Error: Unable to find OBC Script." << std::endl;
64+
fprintf(stderr, "Error: Unable to load OBC Script.");
6665
return 1;
6766
}
6867

69-
std::string checkEntrypointOBC;
68+
std::string checkEntrypoint;
7069
char c;
7170
for (int i = 0; i < 25 && OBCInput.get(c); ++i) {
72-
checkEntrypointOBC += c;
71+
checkEntrypoint += c;
7372
}
7473

7574
// Uses the OBC Copyright MDO as Entrypoint adds automatically also the last four number of the Year.
7675
// (usually it is 1999, due to OBCEditor it is possible to change this Year so this Change is made so the modified Scripts are always compatible with OBCViewer)
7776
int number;
78-
if (sscanf(checkEntrypointOBC.c_str(), "OBC Copyright MDO %d", &number) != 1) {
79-
printf("Error: Unable to find the number of the Entrypoint!");
77+
if (sscanf(checkEntrypoint.c_str(), "OBC Copyright MDO %d", &number) != 1) {
78+
fprintf(stderr, "Error: Unable to find the Entrypoint!");
8079
return 1;
8180
}
8281

8382
// Rewind the OBC Script back to the beginning
8483
OBCInput.seekg(0);
8584

8685
// Open the output file for the OBC Script
87-
std::ofstream OBCOutput(inputScript.stem().string() + ".txt");
86+
std::ofstream outputScript(inputFile.stem().string() + ".txt");
8887

89-
if (!OBCOutput) {
90-
printf("Error: Unable to create a text output of the OBC Script");
88+
if (!outputScript) {
89+
fprintf(stderr, "Error: Unable to create a text output of the OBC Script");
9190
return 1;
9291
}
9392

9493
// Adds the Date when Output file was created to the Output file
9594
time_t current_time = time(nullptr);
96-
char obc_timedate[100];
97-
strftime(obc_timedate, sizeof(obc_timedate), "%Y-%m-%d %H:%M:%S", localtime(&current_time));
95+
char timedate[100];
96+
strftime(timedate, sizeof(timedate), "%Y-%m-%d %H:%M:%S", localtime(&current_time));
9897

9998
// Read from input and write to output, keeping track of the offset
10099
std::streampos offset = OBCInput.tellg();
101100
while (OBCInput.get(c)) {
102101
if (std::isprint(static_cast<unsigned char>(c))) {
103-
OBCOutput.put(c);
102+
outputScript.put(c);
104103
offset = OBCInput.tellg(); // Update the offset after each character is processed
105104
}
106105
}
107106

108107
// Close input & output for OBC Script
109108
OBCInput.close();
110-
OBCOutput.close();
109+
outputScript.close();
111110

112111
// Create a separate file for Debug Infos
113-
std::ofstream DebugInfoOutput(inputScript.stem().string() + "_debuginfo.txt");
112+
std::ofstream DebugInfoOutput(inputFile.stem().string() + "_debuginfo.txt");
114113
if (!DebugInfoOutput) {
115-
printf("Error: Unable to create Debug Infos file.");
114+
fprintf(stderr, "Error: Unable to create Debug Infos file.");
116115
return 1;
117116
}
118117

119118
// Write Debug Infos to the separate file
120119
DebugInfoOutput << "Debug Infos:" << std::endl;
121-
DebugInfoOutput << "Output of " << inputScript.stem().string() << ".obc" << " created at " << obc_timedate << std::endl;
120+
DebugInfoOutput << "Output of " << inputFile.stem().string() << ".obc" << " created at " << timedate << std::endl;
122121
#ifdef __unix__
123122
DebugInfoOutput << "Created by " << username << std::endl;
124123
#elif __APPLE__
@@ -133,7 +132,7 @@ int main(int argc, char* argv[]) {
133132
// Display the full path of the output file of the OBC Script
134133
ConsoleUtils::printNewLine();
135134
printf("Output created at:");
136-
printf("%s", fs::absolute(inputScript.stem().string() + ".txt").c_str());
135+
printf("%s", fs::absolute(inputFile.stem().string() + ".txt").c_str());
137136
ConsoleUtils::printNewLine();
138137

139138
// Exit message for OBCViewer

0 commit comments

Comments
 (0)