From 43fda0a3928b7da4f047a9d93f435129b0c2519b Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Tue, 15 Aug 2023 00:15:16 +0200 Subject: [PATCH] Added support for glob thanks to tsoding/glob.h --- Password_manager/Password_manager.vcxproj | 2 + .../Password_manager.vcxproj.filters | 6 ++ Password_manager/include/glob.h | 13 +++ Password_manager/source/func.cpp | 5 +- Password_manager/source/glob.cpp | 94 +++++++++++++++++++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 Password_manager/include/glob.h create mode 100644 Password_manager/source/glob.cpp diff --git a/Password_manager/Password_manager.vcxproj b/Password_manager/Password_manager.vcxproj index 1dc1207..c2cbe6d 100644 --- a/Password_manager/Password_manager.vcxproj +++ b/Password_manager/Password_manager.vcxproj @@ -135,6 +135,7 @@ + @@ -142,6 +143,7 @@ + diff --git a/Password_manager/Password_manager.vcxproj.filters b/Password_manager/Password_manager.vcxproj.filters index 0186117..9ee8c2a 100644 --- a/Password_manager/Password_manager.vcxproj.filters +++ b/Password_manager/Password_manager.vcxproj.filters @@ -30,6 +30,9 @@ Source Files + + Source Files + @@ -44,5 +47,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/Password_manager/include/glob.h b/Password_manager/include/glob.h new file mode 100644 index 0000000..89dfe74 --- /dev/null +++ b/Password_manager/include/glob.h @@ -0,0 +1,13 @@ +#pragma once + + +enum class Glob_Result { + OOM_ERROR, + ENCODING_ERROR, + SYNTAX_ERROR, + UNMATCHED, + MATCHED, +} ; + +// https://github.com/tsoding/glob.h +Glob_Result glob(const char* pattern, const char* text); \ No newline at end of file diff --git a/Password_manager/source/func.cpp b/Password_manager/source/func.cpp index b226bcd..98751f4 100644 --- a/Password_manager/source/func.cpp +++ b/Password_manager/source/func.cpp @@ -1,4 +1,5 @@ #include "func.h" +#include "glob.h" Pass* find_password(Buffer* buff, char* label) { @@ -6,7 +7,7 @@ Pass* find_password(Buffer* buff, char* label) for (int i = 0; i < buff->taken / sizeof(Pass); i++) { - if (!strcmp(passwords[i].label, label)) + if (glob(label, passwords[i].label) == Glob_Result::MATCHED) { return &passwords[i]; } @@ -66,7 +67,7 @@ void print_usage() printf_s(" Note: