Replaced occurrences of long long int with standardized int64_t

This commit is contained in:
Andrew S. Rightenburg 2023-04-02 13:30:22 -04:00
parent a8fddc2ac0
commit 1624a2078f
6 changed files with 57 additions and 57 deletions

View file

@ -175,7 +175,7 @@ bool editor::file::add_instruction(instruction &input_instruction) {
if (input_instruction.get_operation_type() == insert_operation) {
file_length_after_last_instruction = (file_length_after_last_instruction + input_instruction.get_text().length());
} else if (input_instruction.get_operation_type() == remove_operation) {
long long int remove_length = (input_instruction.get_end_position() - input_instruction.get_start_position());
int64_t remove_length = (input_instruction.get_end_position() - input_instruction.get_start_position());
file_length_after_last_instruction = (file_length_after_last_instruction - remove_length);
}
@ -198,7 +198,7 @@ int editor::file::get_block_size() {
return block_size;
}
long long int editor::file::get_file_length() {
int64_t editor::file::get_file_length() {
return file_length;
}
@ -210,9 +210,9 @@ string editor::file::get_error_message() {
return error_message;
}
void editor::file::replace(long long int start_position, string replacement_text) {
void editor::file::replace(int64_t start_position, string replacement_text) {
/***
void editor::file::replace(long long int start_position, string replacement_text):
void editor::file::replace(int64_t start_position, string replacement_text):
Execute a "REPLACE" instruction
Opens a file stream & replaces text inside the file, starting from start_position, with replacement_text
***/
@ -235,9 +235,9 @@ void editor::file::replace(long long int start_position, string replacement_text
}
}
void editor::file::insert(long long int start_position, string text_to_insert) {
void editor::file::insert(int64_t start_position, string text_to_insert) {
/***
void editor::file::insert(long long int start_position, string text_to_insert):
void editor::file::insert(int64_t start_position, string text_to_insert):
Execute an "INSERT" instruction
Opens a file stream & inserts text_to_insert into the file at position start_position, without replacing
***/
@ -246,9 +246,9 @@ void editor::file::insert(long long int start_position, string text_to_insert) {
return;
}
long long int insert_length = text_to_insert.length();
int64_t insert_length = text_to_insert.length();
long long int new_file_length = file_length + insert_length;
int64_t new_file_length = file_length + insert_length;
bool creating_new_file = (start_position == 0 && file_length == 0);
@ -302,10 +302,10 @@ void editor::file::insert(long long int start_position, string text_to_insert) {
file_stream.seekp(new_file_length - 1, ios::beg);
file_stream.write("\n", 1);
for (long long int i = (new_file_length - 1); i > start_position; i = (i - amount_to_store)) {
for (int64_t i = (new_file_length - 1); i > start_position; i = (i - amount_to_store)) {
long long int copy_to_this_position = (i - (amount_to_store - 1)) - 1;
long long int copy_from_this_position = (copy_to_this_position - insert_length);
int64_t copy_to_this_position = (i - (amount_to_store - 1)) - 1;
int64_t copy_from_this_position = (copy_to_this_position - insert_length);
// Final iteration:
// If we discover that our "copy_from" position is before our start_position,
@ -317,7 +317,7 @@ void editor::file::insert(long long int start_position, string text_to_insert) {
// And set i = start_position to make sure the loop doesn't run again after this
if (copy_from_this_position < start_position) {
long long int difference = start_position - copy_from_this_position;
int64_t difference = start_position - copy_from_this_position;
copy_from_this_position = start_position;
@ -364,9 +364,9 @@ void editor::file::insert(long long int start_position, string text_to_insert) {
}
}
void editor::file::remove(long long int start_position, long long int end_position) {
void editor::file::remove(int64_t start_position, int64_t end_position) {
/***
void editor::file::remove(long long int start_position, long long int end_position):
void editor::file::remove(int64_t start_position, int64_t end_position):
Execute a "REMOVE" instruction
Opens a file stream & removes text from start_position to end_position,
shifting everything after end_position to the left
@ -376,9 +376,9 @@ void editor::file::remove(long long int start_position, long long int end_positi
return;
}
long long int remove_length = (end_position - start_position);
int64_t remove_length = (end_position - start_position);
long long int new_file_length = (file_length - remove_length);
int64_t new_file_length = (file_length - remove_length);
int amount_to_store = block_size;
@ -408,11 +408,11 @@ void editor::file::remove(long long int start_position, long long int end_positi
}
// Before EOF
for (long long int i = start_position; i < (new_file_length - 1); i = (i + amount_to_store)) {
for (int64_t i = start_position; i < (new_file_length - 1); i = (i + amount_to_store)) {
long long int copy_to_this_position = i;
int64_t copy_to_this_position = i;
long long int copy_from_this_position = (i + remove_length);
int64_t copy_from_this_position = (i + remove_length);
// Final iteration:
// If we discover that our block_size is more than all the data that's left,

View file

@ -33,7 +33,7 @@ void editor::instruction::process_special_chars() {
}
bool editor::instruction::set_replace_instruction(long long int start, string text) {
bool editor::instruction::set_replace_instruction(int64_t start, string text) {
/***
bool set_replace_instruction():
- Sets the current instruction to type "replace"
@ -70,7 +70,7 @@ bool editor::instruction::set_replace_instruction(long long int start, string te
return true;
}
bool editor::instruction::set_insert_instruction(long long int start, string text) {
bool editor::instruction::set_insert_instruction(int64_t start, string text) {
/***
bool set_insert_instruction():
- Sets the current instruction to type "insert"
@ -107,7 +107,7 @@ bool editor::instruction::set_insert_instruction(long long int start, string tex
return true;
}
bool editor::instruction::set_remove_instruction(long long int start, long long int end) {
bool editor::instruction::set_remove_instruction(int64_t start, int64_t end) {
/***
bool set_remove_instruction():
- Sets the current instruction to type "remove"
@ -174,11 +174,11 @@ int editor::instruction::get_operation_type() {
return operation;
}
long long int editor::instruction::get_start_position() {
int64_t editor::instruction::get_start_position() {
return start_position;
}
long long int editor::instruction::get_end_position() {
int64_t editor::instruction::get_end_position() {
return end_position;
}
@ -186,7 +186,7 @@ string editor::instruction::get_text() {
return text_input;
}
editor::instruction create_replace_instruction(long long int start_position, string text) {
editor::instruction create_replace_instruction(int64_t start_position, string text) {
editor::instruction new_instruction;
new_instruction.set_replace_instruction(start_position, text);
@ -194,7 +194,7 @@ editor::instruction create_replace_instruction(long long int start_position, str
return new_instruction;
}
editor::instruction create_insert_instruction(long long int start_position, string text) {
editor::instruction create_insert_instruction(int64_t start_position, string text) {
editor::instruction new_instruction;
new_instruction.set_insert_instruction(start_position, text);
@ -202,7 +202,7 @@ editor::instruction create_insert_instruction(long long int start_position, stri
return new_instruction;
}
editor::instruction create_remove_instruction(long long int start_position, int end_position) {
editor::instruction create_remove_instruction(int64_t start_position, int end_position) {
editor::instruction new_instruction;
new_instruction.set_remove_instruction(start_position, end_position);
@ -320,21 +320,21 @@ editor::instruction parse_instruction_string(string instruction_string) {
Now, to actually create the 'instruction' object
*/
if (is_replace_instruction) {
long long int start_position = (long long int)stol(instruction_vector[1]);
int64_t start_position = (int64_t)stol(instruction_vector[1]);
return create_replace_instruction(start_position, instruction_vector[2]);
}
if (is_insert_instruction) {
long long int start_position = (long long int)stol(instruction_vector[1]);
int64_t start_position = (int64_t)stol(instruction_vector[1]);
return create_insert_instruction(start_position, instruction_vector[2]);
}
if (is_remove_instruction) {
long long int start_position = (long long int)stol(instruction_vector[1]);
int64_t start_position = (int64_t)stol(instruction_vector[1]);
long long int end_position = (long long int)stol(instruction_vector[2]);
int64_t end_position = (int64_t)stol(instruction_vector[2]);
return create_remove_instruction(start_position, end_position);
}

View file

@ -22,32 +22,32 @@ namespace editor {
3 = remove
*/
long long int start_position = -1;
long long int end_position = -1;
int64_t start_position = -1;
int64_t end_position = -1;
string text_input = "";
string error_message = "";
public:
void clear_instruction();
void process_special_chars();
bool set_replace_instruction(long long int start, string text);
bool set_insert_instruction(long long int start, string text);
bool set_remove_instruction(long long int start, long long int end);
bool set_replace_instruction(int64_t start, string text);
bool set_insert_instruction(int64_t start, string text);
bool set_remove_instruction(int64_t start, int64_t end);
void set_error_message(string message);
string get_error_message();
bool is_initialized();
int get_operation_type();
long long int get_start_position();
long long int get_end_position();
int64_t get_start_position();
int64_t get_end_position();
string get_text();
};
instruction create_replace_instruction(long long int start_position, string text);
instruction create_insert_instruction(long long int start_position, string text);
instruction create_remove_instruction(long long int start_position, long long int end_position);
instruction create_replace_instruction(int64_t start_position, string text);
instruction create_insert_instruction(int64_t start_position, string text);
instruction create_remove_instruction(int64_t start_position, int64_t end_position);
instruction parse_instruction_string(string instruction_string);
@ -60,7 +60,7 @@ namespace editor {
string file_name;
string file_directory;
long long int file_length = 0;
int64_t file_length = 0;
fstream file_stream;
FILE* c_type_file;
@ -69,7 +69,7 @@ namespace editor {
int block_size = 1024;
vector<instruction> instruction_set;
long long int file_length_after_last_instruction = 0;
int64_t file_length_after_last_instruction = 0;
string error_message = "";
@ -79,9 +79,9 @@ namespace editor {
void set_block_size(int specified_blocksize);
void replace(long long int start_position, string replacement_text);
void insert(long long int start_position, string text_to_insert);
void remove(long long int start_position, long long int end_position);
void replace(int64_t start_position, string replacement_text);
void insert(int64_t start_position, string text_to_insert);
void remove(int64_t start_position, int64_t end_position);
bool add_instruction(instruction &input_instruction);
@ -96,7 +96,7 @@ namespace editor {
int get_block_size();
long long int get_file_length();
int64_t get_file_length();
vector<instruction> get_instruction_set();

View file

@ -29,7 +29,7 @@ bool reader::file::init(string path) {
return true;
}
string reader::file::read(long long int start_position, long long int amount_to_read) {
string reader::file::read(int64_t start_position, int64_t amount_to_read) {
if (!initialized) {
string error = "Error reading file";
@ -47,7 +47,7 @@ string reader::file::read(long long int start_position, long long int amount_to_
}
// Now check the end position
long long int end_position = (start_position + amount_to_read);
int64_t end_position = (start_position + amount_to_read);
if (end_position > file_length) {
// Just set it to read till the end of the file & not further
@ -75,6 +75,6 @@ string reader::file::get_init_error_message() {
return init_error_message;
}
long long int reader::file::get_file_length() {
int64_t reader::file::get_file_length() {
return file_length;
}

View file

@ -30,8 +30,8 @@ int main(int argc, char* argv[]) {
"amount_to_read" == -1 will result in reading from the start position to the end of the file
*/
string file_to_read = "";
long long int start_position = 0;
long long int amount_to_read = -1;
int64_t start_position = 0;
int64_t amount_to_read = -1;
/*
GETOPT
@ -60,7 +60,7 @@ int main(int argc, char* argv[]) {
cerr << program_name << ": '" << optarg << "' is not an integer" << endl << "Use -h for help" << endl;
return 1;
}
start_position = (long long int)atol(optarg);
start_position = (int64_t)atol(optarg);
break;
case 'l':
@ -68,7 +68,7 @@ int main(int argc, char* argv[]) {
cerr << program_name << ": '" << optarg << "' is not an integer" << endl << "Use -h for help" << endl;
return 1;
}
amount_to_read = (long long int)atol(optarg);
amount_to_read = (int64_t)atol(optarg);
break;
case 'V':

View file

@ -7,12 +7,12 @@ namespace reader {
bool initialized = false;
string file_name;
string init_error_message = "unknown";
long long int file_length = 0;
int64_t file_length = 0;
public:
bool init(string path);
string read(long long int start_position, long long int amount_to_read);
string read(int64_t start_position, int64_t amount_to_read);
string get_init_error_message();
long long int get_file_length();
int64_t get_file_length();
};
}