Skip to content

Commit 01afac3

Browse files
Bug fixes
1 parent 95756b6 commit 01afac3

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ project(BinEdit LANGUAGES CXX)
44

55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_STANDARD_REQUIRED True)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
79
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O1")
10+
811
add_executable(binedit src/bin_editor.cpp)

src/bin_editor.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <iostream>
22
#include <cstdlib>
3+
#include <cctype>
4+
#include <filesystem>
35
#include <fstream>
46
#include <bitset>
57
#include <sstream>
@@ -58,12 +60,38 @@ void write_to_file(std::string &insiders, const char *filename) {
5860
}
5961
output.close();
6062
}
63+
unsigned int show_all(const std::string arg) {
64+
unsigned int counter = 0;
65+
for (const char c : arg) {
66+
if (c == ' ') {
67+
counter++;
68+
}
69+
}
70+
return counter;
71+
}
72+
std::string remove_special_chars(const std::string name) {
73+
std::string name_copy;
74+
name_copy.reserve(name.length());
75+
for (const char c : name) {
76+
if (std::isalnum(c)) {
77+
name_copy += c;
78+
}
79+
}
80+
return name_copy;
81+
}
6182
int main(int argc, char *argv[]) {
6283
std::ifstream file(argv[1], std::ios::binary);
6384
if (argc != 2 || !file.good()) {
64-
std::cout << "Only 2 arguments, example: " << argv[0] << " <file>" << std::endl;
65-
return 0;
85+
std::cerr << "Only 2 arguments, example: " << argv[0] << " <file>" << std::endl;
86+
return 1;
6687
}
88+
std::filesystem::path file_ext1(argv[0]);
89+
std::filesystem::path file_ext2(argv[1]);
90+
if (remove_special_chars(file_ext1.replace_extension("").string()) == file_ext2.string()) {
91+
std::cerr << "Error: incorrect input file" << std::endl;
92+
return 1;
93+
}
94+
6795
std::string insiders = "";
6896
std::string word = "";
6997
unsigned char byte;
@@ -82,7 +110,8 @@ int main(int argc, char *argv[]) {
82110
int bit_i = 0;
83111
std::cout << "press 's' to see a bits, press 'e' to edit this bits, press 'a' to see all values at once, press 'w' to write edited values in the file\n";
84112
enable(true);
85-
while (true) {
113+
while (true) {
114+
std::cout << iteration << '/' << show_all(insiders) << std::endl;
86115
out_of_the_bounds(insiders[index]);
87116
iteration++;
88117
key = _getch();

0 commit comments

Comments
 (0)