diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-08-09 08:33:08 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-08-09 08:33:08 +0200 |
| commit | 5d34aff5888d3f0c624251f15bedb96c347978d6 (patch) | |
| tree | 69a49651271d645ca7eaa114cb1830bf759c0930 | |
| parent | b94a7ae06b20d550c727d5192cea8baf3e8fb641 (diff) | |
refactors
| -rw-r--r-- | include/administration.hpp (renamed from src/administration.hpp) | 0 | ||||
| -rw-r--r-- | include/config.hpp (renamed from src/config.hpp) | 0 | ||||
| -rw-r--r-- | include/locales.hpp (renamed from src/locales/locales.hpp) | 0 | ||||
| -rw-r--r-- | include/strops.hpp | 3 | ||||
| -rw-r--r-- | include/ui.hpp (renamed from src/views/views.hpp) | 6 | ||||
| -rw-r--r-- | run.bat | 9 | ||||
| -rw-r--r-- | simclist-1.5/simclist.c | 4 | ||||
| -rw-r--r-- | src/administration.cpp | 11 | ||||
| -rw-r--r-- | src/locales.cpp (renamed from src/locales/locales.cpp) | 0 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/strops.cpp | 18 | ||||
| -rw-r--r-- | src/ui/helpers.cpp (renamed from src/views/views.cpp) | 4 | ||||
| -rw-r--r-- | src/ui/ui_contacts.cpp (renamed from src/views/contacts.cpp) | 17 | ||||
| -rw-r--r-- | src/ui/ui_main.cpp (renamed from src/views/dashboard.cpp) | 12 | ||||
| -rw-r--r-- | src/ui/ui_projects.cpp (renamed from src/views/projects.cpp) | 14 |
15 files changed, 64 insertions, 38 deletions
diff --git a/src/administration.hpp b/include/administration.hpp index 9506246..9506246 100644 --- a/src/administration.hpp +++ b/include/administration.hpp diff --git a/src/config.hpp b/include/config.hpp index 3279e2e..3279e2e 100644 --- a/src/config.hpp +++ b/include/config.hpp diff --git a/src/locales/locales.hpp b/include/locales.hpp index 78bb682..78bb682 100644 --- a/src/locales/locales.hpp +++ b/include/locales.hpp diff --git a/include/strops.hpp b/include/strops.hpp new file mode 100644 index 0000000..daa1d71 --- /dev/null +++ b/include/strops.hpp @@ -0,0 +1,3 @@ +#pragma once + +size_t strops_copy(char *dst, const char *src, size_t size);
\ No newline at end of file diff --git a/src/views/views.hpp b/include/ui.hpp index f47bf3a..827980c 100644 --- a/src/views/views.hpp +++ b/include/ui.hpp @@ -10,6 +10,6 @@ typedef enum void view_draw_required_tag(); -void views_draw_dashboard(); -void views_draw_contacts(); -void views_draw_projects();
\ No newline at end of file +void ui_draw_main(); +void ui_draw_contacts(); +void ui_draw_projects();
\ No newline at end of file @@ -1,11 +1,12 @@ call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 @set OUT_DIR=build\\ @set OUT_EXE=accounting -@set SOURCES=src\*.cpp imgui-1.92.1\backends\imgui_impl_dx11.cpp imgui-1.92.1\backends\imgui_impl_win32.cpp imgui-1.92.1\imgui*.cpp src\views\*.cpp src\locales\*.cpp simclist-1.5\simclist.c +@set LIB_SOURCES=imgui-1.92.1\backends\imgui_impl_dx11.cpp imgui-1.92.1\backends\imgui_impl_win32.cpp imgui-1.92.1\imgui*.cpp simclist-1.5\simclist.c +@set SOURCES= src\*.cpp src\ui\*.cpp src\locales\*.cpp @set LIBS=opengl32.lib Advapi32.lib Shell32.lib Ole32.lib User32.lib Pathcch.lib D3D11.lib -@set FLAGS=/DMODE_DEBUG /DEBUG:FULL /Ob0 /MT /Oy- /Zi +@set FLAGS= /std:c11 /nologo /Ob0 /MT /Oy- /Zi /FS /W4 /EHsc /utf-8 +@set INCLUDE_DIRS=/I"imgui-1.92.1" /I"imgui-1.92.1/backends" /I"/" /I"simclist-1.5" /Iinclude - -cl /std:c11 /nologo %FLAGS% /I"imgui-1.92.1" /I"imgui-1.92.1/backends" /I"/" /I"simclist-1.5" /w /EHsc /Isrc /utf-8 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fd%OUT_DIR%/vc140.pdb /Fo%OUT_DIR%/ /link %LIBS% +cl %FLAGS% %INCLUDE_DIRS% %SOURCES% %LIB_SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fd%OUT_DIR%/vc140.pdb /Fo%OUT_DIR%/ /link %LIBS% if "%1"=="-r" call "%OUT_DIR%/%OUT_EXE%.exe" if "%1"=="-d" call devenv "%OUT_DIR%/%OUT_EXE%.exe" diff --git a/simclist-1.5/simclist.c b/simclist-1.5/simclist.c index edae4bb..0c34786 100644 --- a/simclist-1.5/simclist.c +++ b/simclist-1.5/simclist.c @@ -1430,8 +1430,8 @@ list_hash_t list_hashcomputer_string(const void *el) { char plus; for (l = 0; str[l] != '\0'; l++) { - if (l) plus = hash ^ str[l]; - else plus = hash ^ (str[l] - str[0]); + if (l) plus = (char)(hash ^ str[l]); + else plus = (char)(hash ^ (str[l] - str[0])); hash += (plus << (CHAR_BIT * (l % sizeof(list_hash_t)))); } diff --git a/src/administration.cpp b/src/administration.cpp index 9362b8d..fb8bd21 100644 --- a/src/administration.cpp +++ b/src/administration.cpp @@ -3,6 +3,7 @@ #include <assert.h> #include <time.h> +#include "strops.hpp" #include "administration.hpp" administration g_administration; @@ -11,7 +12,7 @@ void administration_create() { list_init(&g_administration.contacts); list_init(&g_administration.projects); - strncpy(g_administration.path, "[unsaved project]", sizeof(g_administration.path)); // @localize + strops_copy(g_administration.path, "[unsaved project]", sizeof(g_administration.path)); // @localize } void administration_destroy() @@ -140,10 +141,12 @@ char* administration_project_get_status_string(project data) { switch(data.state) { - case project_state::RUNNING: return "project.state.running"; break; - case project_state::PAUSED: return "project.state.paused"; break; - case project_state::CANCELLED: return "project.state.cancelled"; break; + case project_state::RUNNING: return "project.state.running"; + case project_state::PAUSED: return "project.state.paused"; + case project_state::CANCELLED: return "project.state.cancelled"; + default: assert(0); break; } + return ""; } bool administration_create_project(project data) diff --git a/src/locales/locales.cpp b/src/locales.cpp index 6ec1233..6ec1233 100644 --- a/src/locales/locales.cpp +++ b/src/locales.cpp diff --git a/src/main.cpp b/src/main.cpp index 3f6cf03..c1eb694 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ #include <d3d11.h> #include <tchar.h> -#include "views/views.hpp" +#include "ui.hpp" #include "administration.hpp" // Data @@ -128,7 +128,7 @@ int main() ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - views_draw_dashboard(); + ui_draw_main(); // Rendering ImGui::Render(); diff --git a/src/strops.cpp b/src/strops.cpp new file mode 100644 index 0000000..42042cb --- /dev/null +++ b/src/strops.cpp @@ -0,0 +1,18 @@ +#include <string.h> + +#include "strops.hpp" + +size_t strops_copy(char *dst, const char *src, size_t size) +{ + size_t srclen; + size --; + srclen = strlen(src); + + if (srclen > size) + srclen = size; + + memcpy(dst, src, srclen); + dst[srclen] = '\0'; + + return (srclen); +}
\ No newline at end of file diff --git a/src/views/views.cpp b/src/ui/helpers.cpp index 47eff34..74876c0 100644 --- a/src/views/views.cpp +++ b/src/ui/helpers.cpp @@ -1,6 +1,6 @@ -#include "views.hpp" +#include "ui.hpp" #include "imgui.h" -#include "../locales/locales.hpp" +#include "locales.hpp" void view_draw_required_tag() { diff --git a/src/views/contacts.cpp b/src/ui/ui_contacts.cpp index 31f95e3..3115a77 100644 --- a/src/views/contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -1,9 +1,10 @@ #include <stdio.h> -#include "views.hpp" +#include "strops.hpp" +#include "ui.hpp" #include "imgui.h" -#include "../administration.hpp" -#include "../locales/locales.hpp" +#include "administration.hpp" +#include "locales.hpp" static view_state current_view_state = LIST; static contact selected_for_removal; @@ -70,7 +71,7 @@ static void draw_contact_form() ImGui::EndCombo(); } if (selected_country) { - strncpy(active_contact.country, selected_country, IM_ARRAYSIZE(active_contact.country)); + strops_copy(active_contact.country, selected_country, IM_ARRAYSIZE(active_contact.country)); } ImGui::SameLine();view_draw_required_tag(); @@ -172,7 +173,7 @@ static void draw_contact_list() ImGui::TableSetColumnIndex(3); char btn_name[20]; - sprintf(btn_name, "%s##%d", localize("form.view"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.view"), i); if (ImGui::Button(btn_name)) { active_contact = c; current_view_state = view_state::VIEW; @@ -180,7 +181,7 @@ static void draw_contact_list() ImGui::SameLine(); - sprintf(btn_name, "%s##%d", localize("form.change"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.change"), i); if (ImGui::Button(btn_name)) { active_contact = c; current_view_state = view_state::EDIT; @@ -189,7 +190,7 @@ static void draw_contact_list() ImGui::SameLine(); // TODO check to make sure no invoices are connected to this contact. - sprintf(btn_name, "%s##%d", localize("form.delete"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); @@ -215,7 +216,7 @@ static void draw_contact_list() } } -void views_draw_contacts() +void ui_draw_contacts() { switch(current_view_state) { diff --git a/src/views/dashboard.cpp b/src/ui/ui_main.cpp index dcfd002..f6661b8 100644 --- a/src/views/dashboard.cpp +++ b/src/ui/ui_main.cpp @@ -1,7 +1,7 @@ -#include "views.hpp" +#include "ui.hpp" #include "imgui.h" -#include "../administration.hpp" -#include "../locales/locales.hpp" +#include "administration.hpp" +#include "locales.hpp" typedef enum { @@ -19,13 +19,13 @@ static dashboard_view_state dashboard_state = dashboard_view_state::INVOICES; void (*drawcalls[dashboard_view_state::END])(void) = { 0, 0, - views_draw_contacts, + ui_draw_contacts, 0, 0, - views_draw_projects, + ui_draw_projects, }; -void views_draw_dashboard() +void ui_draw_main() { // @localize if (ImGui::BeginMainMenuBar()) diff --git a/src/views/projects.cpp b/src/ui/ui_projects.cpp index 14f99c9..9490254 100644 --- a/src/views/projects.cpp +++ b/src/ui/ui_projects.cpp @@ -1,9 +1,9 @@ #include <stdio.h> -#include "views.hpp" +#include "ui.hpp" #include "imgui.h" -#include "../administration.hpp" -#include "../locales/locales.hpp" +#include "administration.hpp" +#include "locales.hpp" static view_state current_view_state = LIST; static project selected_for_cancellation; @@ -118,7 +118,7 @@ static void draw_project_list() ImGui::TableSetColumnIndex(3); char btn_name[20]; - sprintf(btn_name, "%s##%d", localize("form.view"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.view"), i); if (ImGui::Button(btn_name)) { active_project = c; current_view_state = view_state::VIEW; @@ -127,14 +127,14 @@ static void draw_project_list() if (c.state == project_state::RUNNING) { ImGui::SameLine(); - sprintf(btn_name, "%s##%d", localize("form.change"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.change"), i); if (ImGui::Button(btn_name)) { active_project = c; current_view_state = view_state::EDIT; } ImGui::SameLine(); - sprintf(btn_name, "%s##%d", localize("form.cancel"), i); + snprintf(btn_name, sizeof(btn_name), "%s##%d", localize("form.cancel"), i); if (ImGui::Button(btn_name)) { selected_for_cancellation = c; ImGui::OpenPopup("ConfirmCancelProject"); @@ -161,7 +161,7 @@ static void draw_project_list() } } -void views_draw_projects() +void ui_draw_projects() { switch(current_view_state) { |
