From 7cc33550c4d0c96d43aa2058800c8776b441dd9a Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Tue, 27 Aug 2024 15:35:55 +0200 Subject: [PATCH] up -l tag to supoort input its used to filter witch labels to show --- include/arg_func.hpp | 2 +- source/arg_func.cpp | 31 ++++++++++++++++++++++++------- source/main.cpp | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/include/arg_func.hpp b/include/arg_func.hpp index 03ec946..f8ec314 100644 --- a/include/arg_func.hpp +++ b/include/arg_func.hpp @@ -34,7 +34,7 @@ void arg_username(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, std::string &key); -void arg_list(Buffer &decrypted_buffer); +void arg_list(Buffer &decrypted_buffer, const char *label_filter); void arg_delete(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const char *label, std::string &key); diff --git a/source/arg_func.cpp b/source/arg_func.cpp index 1298544..a97217a 100644 --- a/source/arg_func.cpp +++ b/source/arg_func.cpp @@ -38,6 +38,8 @@ void print_args() Arg get_args(int argc, char **argv, char **label) { + Arg ret = Arg::Error; + if (argc < 2) { print_args(); @@ -56,15 +58,22 @@ Arg get_args(int argc, char **argv, char **label) print_args(); return Arg::Error; case 'l': - return Arg::List; + ret = Arg::List; + break; case 'p': - return Arg::Print_all_p; + ret = Arg::Print_all_p; + break; case 'c': - return Arg::Change; + ret = Arg::Change; + break; case 'z': - return Arg::Size; + ret = Arg::Size; + break; } + if (argc == 2) + return ret; + if (argc != 3) return Arg::Error; @@ -90,7 +99,7 @@ Arg get_args(int argc, char **argv, char **label) return Arg::Editor; default: - return Arg::Error; + return ret; break; } @@ -217,7 +226,7 @@ void arg_label_name(Buffer &decrypted_buffer, Buffer &encrypted_buffer, const ch encrypted_buffer.save_to_file(); } -void arg_list(Buffer &decrypted_buffer) +void arg_list(Buffer &decrypted_buffer, const char *label_filter) { Index *index = (Index *)decrypted_buffer.buffer; LoginInfo *pass = (LoginInfo *)(decrypted_buffer.buffer + sizeof(Index)); @@ -226,7 +235,15 @@ void arg_list(Buffer &decrypted_buffer) for (size_t i = 0; i < index->count; i++) { - list.emplace_back(std::string((char *)decrypted_buffer.buffer + pass[i].label + index->offset)); + const char *str = (const char *)decrypted_buffer.buffer + pass[i].label + index->offset; + if (!label_filter) + { + list.emplace_back(std::string(str)); + } + else if (label_filter[0] == str[0]) + { + list.emplace_back(std::string(str)); + } } std::sort(list.begin(), list.end()); diff --git a/source/main.cpp b/source/main.cpp index caa751b..2aa97bf 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -102,7 +102,7 @@ int main(int argc, char **argv) break; case Arg::List: - arg_list(decrypted_buffer); + arg_list(decrypted_buffer, label); break; case Arg::Delete: