Compare commits

..

No commits in common. "caf47e87ea47571b8203a9f4ba16d8b93098eeb3" and "57d8b13f196b18d5f047ea75394a1d38d41dc0a9" have entirely different histories.

6 changed files with 206 additions and 452 deletions

View File

@ -1,8 +1,8 @@
# Compiler and flags # Compiler and flags
CPPC = g++ CPPC = g++
CPPC_FLAGS = -std=c++23 -s -O3 -Wall -Wextra -lncurses -lmenu -lform -lcups CPPC_FLAGS = -std=c++23 -s -O3 -Wall -Wextra -Wno-write-strings -lncurses -lmenu -lform -lcups
DEBUG_FLAGS = -ggdb -std=c++23 -Wall -lncurses -lmenu -lform -lcups DEBUG_FLAGS = -ggdb -std=c++23 -Wall -Wextra -Wno-write-strings -lncurses -lmenu -lform -lcups
DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer -std=c++23 -lncurses -lmenu -lcups -Wall -Wextra DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer -std=c++23 -lncurses -lmenu -lcups -Wall -Wextra -Wno-write-strings
SRC_PATH := src SRC_PATH := src

View File

@ -1,21 +1,16 @@
#include <form.h>
#include <ncurses.h>
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <format> #include <form.h>
#include <format> // C++20/C++23 feature
#include <ncurses.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include "gameske_funkce.h"
#include "memory.h"
#define HEADER_COLOR_PAIR COLOR_RED #define WHITE_ON_BLUE 9
#define FIELD_NAME_COLOR_PAIR 10 #define BLACK_ON_WHITE 10
#define INPUT_COLOR_PAIR 11
std::vector<allocation> editor_easy_allocated;
[[nodiscard]] std::string vytvorTrestniOznameni() { [[nodiscard]] std::string vytvorTrestniOznameni() {
current_allocated = &editor_easy_allocated; // Pomocná funkce pro ořezání mezer (ncurses vyplňuje pole mezerami)
auto trim = [](const char *str) -> std::string { auto trim = [](const char *str) -> std::string {
std::string s(str); std::string s(str);
if (s.empty()) if (s.empty())
@ -27,181 +22,168 @@ std::vector<allocation> editor_easy_allocated;
return s.substr(start, end - start + 1); return s.substr(start, end - start + 1);
}; };
curs_set(1); init_pair(WHITE_ON_BLUE, COLOR_WHITE, COLOR_BLUE);
init_pair(BLACK_ON_WHITE, COLOR_BLACK, COLOR_WHITE);
// Minimální velikost terminálu // Velikost terminalu
const int MIN_WIDTH = 90; int max_y, max_x;
const int MIN_HEIGHT = 28; getmaxyx(stdscr, max_y, max_x);
if (COLS < MIN_WIDTH || LINES < MIN_HEIGHT) {
endwin();
throw std::runtime_error("Minimální velikost terminálu: 90x28");
}
// Nastavení barev echo();
start_color();
init_pair(FIELD_NAME_COLOR_PAIR, COLOR_BLACK, COLOR_CYAN); // Popisky
init_pair(INPUT_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK); // Vstupní pole
// Hlavní okno s rámečkem // Nadpis
WINDOW* main_win = newwin(LINES - 4, COLS - 4, 2, 2); attron(COLOR_PAIR(WHITE_ON_BLUE));
box(main_win, 0, 0); mvprintw(0, 0, "TRESTNÍ OZNÁMENÍ - ZADÁNÍ ÚDAJŮ");
wrefresh(main_win); for (int i = strlen("TRESTNÍ OZNÁMENÍ - ZADÁNÍ ÚDAJŮ"); i < max_x; i++)
addch(' ');
attroff(COLOR_PAIR(WHITE_ON_BLUE));
// Okno pro popisky // Vytvoření polí formuláře
WINDOW* label_win = derwin(main_win, LINES - 8, 30, 1, 1); const int NUM_FIELDS = 10;
wbkgd(label_win, COLOR_PAIR(FIELD_NAME_COLOR_PAIR)); FIELD *fields[NUM_FIELDS + 1]; // +1 pro NULL terminátor
// Okno pro vstupní pole // Definice popisků a vlastností polí
WINDOW* field_win = derwin(main_win, LINES - 8, COLS - 38, 1, 32); struct FieldInfo {
wbkgd(field_win, COLOR_PAIR(INPUT_COLOR_PAIR));
keypad(field_win, TRUE);
// Definice polí
struct FieldConfig {
const char *label; const char *label;
int height; int height;
int width; int width;
bool multiline; bool multiline;
}; };
FieldConfig field_configs[] = {{"Jméno podavatele:", 1, 40, false}, FieldInfo field_info[NUM_FIELDS] = {
{"Adresa podavatele:", 1, 50, false}, {"Jméno a příjmení:", 1, 40, false},
{"Telefon podavatele:", 1, 20, false}, {"Adresa:", 1, 50, false},
{"Email podavatele:", 1, 30, false}, {"Telefon:", 1, 20, false},
{"Email:", 1, 30, false},
{"Jméno pachatele:", 1, 40, false},
{"Adresa pachatele:", 1, 50, false},
{"Telefon pachatele:", 1, 20, false},
{"Email pachatele:", 1, 30, false},
{"Místo činu:", 1, 40, false}, {"Místo činu:", 1, 40, false},
{"Datum činu (dd.mm.rrrr):", 1, 15, false}, {"Datum činu (dd.mm.rrrr):", 1, 15, false},
{"Popis činu:", 4, 60, true}, {"Popis činu:", 5, 60, true},
{"Jméno pachatele (pokud známo):", 1, 40, false},
{"Důkazy:", 4, 60, true}, {"Důkazy:", 4, 60, true},
{"Další informace:", 4, 60, true}}; {"Další informace:", 3, 60, true}};
// Vykreslení popisků // Vytvoření polí
int label_row = 0; int row = 2;
for (const FieldConfig& cfg : field_configs) { for (int i = 0; i < NUM_FIELDS; i++) {
mvwprintw(label_win, label_row, 0, "%s", cfg.label); mvprintw(row, 2, "%s", field_info[i].label);
label_row += cfg.height + 1;
fields[i] = new_field(field_info[i].height, field_info[i].width, row,
30, // Začátek pole po popisku
0, 0);
// Nastavení vlastností pole
set_field_back(fields[i], A_UNDERLINE);
field_opts_off(fields[i], O_AUTOSKIP);
// Pro víceřádková pole
if (field_info[i].multiline) {
field_opts_off(fields[i], O_STATIC);
field_opts_on(fields[i], O_WRAP);
} }
wrefresh(label_win);
row += field_info[i].height + 1;
}
fields[NUM_FIELDS] = NULL;
// Vytvoření formuláře // Vytvoření formuláře
std::vector<FIELD*> fields; FORM *form = new_form(fields);
int field_row = 0;
for (const FieldConfig& cfg : field_configs) { // Vytvoření oken pro formulář
FIELD* field = new_field(cfg.height, cfg.width, field_row, 0, 0, 0); WINDOW *win_body = newwin(max_y, max_x, 0, 0);
set_field_back(field, A_UNDERLINE | COLOR_PAIR(INPUT_COLOR_PAIR)); WINDOW *win_form = derwin(win_body, max_y - 5, max_x - 4, 1, 2);
field_opts_off(field, O_AUTOSKIP | O_STATIC);
if (cfg.multiline) { // Přiřazení oken k formuláři
field_opts_on(field, O_WRAP); set_form_win(form, win_body);
set_max_field(field, 500); set_form_sub(form, win_form);
}
fields.push_back(field);
field_row += cfg.height + 1;
}
fields.push_back(nullptr);
FORM* form = new_form(&fields[0]);
set_form_win(form, field_win);
set_form_sub(form, derwin(field_win, LINES - 10, COLS - 40, 1, 1));
// Zobrazení formuláře
post_form(form); post_form(form);
form_driver(form, REQ_FIRST_FIELD);
// Hlavička // Zobrazení instrukcí
attron(COLOR_PAIR(HEADER_COLOR_PAIR)); mvprintw(max_y - 3, 2,
mvprintw(0, (COLS - 40) / 2, "TRESTNÍ OZNÁMENÍ - ZADÁNÍ ÚDAJŮ"); "Navigace: šipky - pohyb | Tab - další pole | Enter - nový řádek | "
mvprintw(1, 2, "Vyplňte všechny údaje a stiskněte F10 pro dokončení"); "F10 - uložit");
refresh(); refresh();
wrefresh(win_body);
// Hlavní smyčka // Zpracování vstupu od uživatele
int ch; int ch;
bool exit_loop = false; while ((ch = getch()) != KEY_F(10)) {
while (!exit_loop && (ch = wgetch(field_win))) {
switch (ch) { switch (ch) {
case KEY_F(10):
exit_loop = true;
break;
case KEY_DOWN: case KEY_DOWN:
form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_END_LINE); form_driver(form, REQ_END_LINE);
break; break;
case KEY_UP: case KEY_UP:
form_driver(form, REQ_PREV_FIELD); form_driver(form, REQ_PREV_FIELD);
form_driver(form, REQ_END_LINE); form_driver(form, REQ_END_LINE);
break; break;
case KEY_LEFT: case KEY_LEFT:
form_driver(form, REQ_PREV_CHAR); form_driver(form, REQ_PREV_CHAR);
break; break;
case KEY_RIGHT: case KEY_RIGHT:
form_driver(form, REQ_NEXT_CHAR); form_driver(form, REQ_NEXT_CHAR);
break; break;
case KEY_BACKSPACE: case KEY_BACKSPACE:
case 127: case 127:
form_driver(form, REQ_DEL_PREV); form_driver(form, REQ_DEL_PREV);
break; break;
case KEY_DC: case KEY_DC:
form_driver(form, REQ_DEL_CHAR); form_driver(form, REQ_DEL_CHAR);
break; break;
case 10: // Enter key
case 10: // Enter case KEY_ENTER: {
if (field_configs[current_field(form)->index].multiline) { int idx = field_index(current_field(form));
if (field_info[idx].multiline) {
form_driver(form, REQ_NEW_LINE); form_driver(form, REQ_NEW_LINE);
} else { } else {
form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_END_LINE);
} }
break; } break;
case '\t': case '\t':
form_driver(form, REQ_NEXT_FIELD); form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_END_LINE);
break; break;
case KEY_BTAB: case KEY_BTAB:
form_driver(form, REQ_PREV_FIELD); form_driver(form, REQ_PREV_FIELD);
form_driver(form, REQ_END_LINE);
break;
case KEY_HOME:
form_driver(form, REQ_BEG_LINE);
break;
case KEY_END:
form_driver(form, REQ_END_LINE);
break; break;
default: default:
form_driver(form, ch); form_driver(form, ch);
break; break;
} }
// Ruční aktualizace všech oken wrefresh(win_form);
touchwin(main_win); wrefresh(win_body);
wrefresh(main_win);
wrefresh(label_win);
wrefresh(field_win);
} }
// Získání dat // Validace před čtením dat (důležité pro získání aktuálních hodnot)[1][5]
form_driver(form, REQ_VALIDATION); form_driver(form, REQ_VALIDATION);
// Sběr dat z formuláře
std::vector<std::string> field_values; std::vector<std::string> field_values;
for (size_t i = 0; i < ARRAY_SIZE(field_configs); i++) { for (int i = 0; i < NUM_FIELDS; i++) {
field_values.push_back(trim(field_buffer(fields[i], 0))); char *buffer = field_buffer(fields[i], 0);
field_values.push_back(trim(buffer));
} }
// Úklid // Uvolnění prostředků
unpost_form(form); unpost_form(form);
free_form(form); free_form(form);
for (fieldnode*& f : fields) for (int i = 0; i < NUM_FIELDS; i++) {
if (f) free_field(fields[i]);
free_field(f); }
delwin(label_win); delwin(win_form);
delwin(field_win); delwin(win_body);
delwin(main_win); endwin();
curs_set(0);
clear();
// Aktuální datum // Aktuální datum
std::time_t t = std::time(nullptr); std::time_t t = std::time(nullptr);
@ -210,31 +192,29 @@ std::vector<allocation> editor_easy_allocated;
std::strftime(date_str, sizeof(date_str), "%d.%m.%Y", now); std::strftime(date_str, sizeof(date_str), "%d.%m.%Y", now);
// Formátování trestního oznámení pomocí std::format (C++20/C++23) // Formátování trestního oznámení pomocí std::format (C++20/C++23)
std::string complaint = std::format( std::string complaint =
R"( std::format(R"(
VÝZVA K UPUŠTĚNÍ OD PROTIPRÁVNÍHO JEDNÁNÍ TRESTNÍ OZNÁMENÍ
Policie České republiky
Krajské ředitelství policie
Obvodní oddělení
V {} dne {} V {} dne {}
Adresát: Oznamovatel:
Jméno a příjmení: {} Jméno a příjmení: {}
Adresa: {} Adresa: {}
Telefon: {} Telefon: {}
Email: {} Email: {}
Odesílatel: Věc: Oznámení o skutečnostech nasvědčujících tomu, že byl spáchán trestný čin
Jméno a příjmení: {}
Adresa: {}
Telefon: {}
Email: {}
Věc: Výzva k okamžitému upuštění od protiprávního jednání
{} {}
K protiprávnímu jednání došlo dne {} v {}. K trestnému činu došlo dne {} v {}.
Popis protiprávního jednání: Popis skutku:
{} {}
Důkazy: Důkazy:
@ -243,36 +223,24 @@ Důkazy:
Další informace: Další informace:
{} {}
Pokud neupustíte od výše uvedeného jednání, budu nucen/a podniknout další právní kroky, včetně podání trestního oznámení a vymáhání náhrady škody. S úctou,
S pozdravem,
............................ ............................
{} {}
(podpis) (podpis oznamovatele)
*Toto není právní dokument, ale pouze vzor pro informativní účely. Pro právní poradenství se obraťte na kvalifikovaného právníka.*
)", )",
field_values[4], // Místo field_values[4], // Místo
date_str, // Aktuální datum date_str, // Aktuální datum
field_values[7], // Jméno a příjmení adresáta field_values[0], // Jméno a příjmení
field_values[10], // Adresa adresáta (přidejte do pole) field_values[1], // Adresa
field_values[11], // Telefon adresáta (přidejte do pole) field_values[2], // Telefon
field_values[12], // Email adresáta (přidejte do pole) field_values[3], // Email
// Odesílatel
field_values[0], // Jméno a příjmení odesílatele
field_values[1], // Adresa odesílatele
field_values[2], // Telefon odesílatele
field_values[3], // Email odesílatele
field_values[7].empty() field_values[7].empty()
? "Tímto Vás vyzývám, abyste okamžitě upustil/a od protiprávního " ? "Tímto podávám trestní oznámení na neznámého pachatele "
"jednání." "pro podezření ze spáchání trestného činu."
: std::format("Tímto Vás, {}, vyzývám, abyste okamžitě upustil/a od " : std::format("Tímto podávám trestní oznámení na: {} pro "
"protiprávního jednání.", "podezření ze spáchání trestného činu.",
field_values[7]), field_values[7]),
field_values[5], // Datum činu field_values[5], // Datum činu
field_values[4], // Místo činu field_values[4], // Místo činu
field_values[6], // Popis činu field_values[6], // Popis činu
@ -280,6 +248,6 @@ S pozdravem,
field_values[9], // Další informace field_values[9], // Další informace
field_values[0] // Jméno pro podpis field_values[0] // Jméno pro podpis
); );
noecho();
return complaint; return complaint;
} }

View File

@ -2,13 +2,10 @@
#include <csignal> #include <csignal>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <locale>
#include <regex>
#include "color.h" #include "color.h"
#include "const.h" #include "const.h"
#include "menu.h" #include "menu.h"
#include "signal.h" #include "signal.h"
#include "strings.h"
void PrintHelp() { void PrintHelp() {
std::cout << RED R"( ____ ____ std::cout << RED R"( ____ ____
@ -40,19 +37,6 @@ int main(int argc, char* argv[]) {
// error signal handlers // error signal handlers
signal(SIGSEGV, safe_exit); signal(SIGSEGV, safe_exit);
// set locale
{
std::locale loc("");
std::regex czech_regex("czech|cz", std::regex_constants::icase |
std::regex_constants::ECMAScript);
if (std::regex_search(loc.name(), czech_regex)) {
loc_strings = &czech_strings;
} else {
loc_strings = &english_strings;
}
}
int opt; int opt;
while ((opt = getopt(argc, argv, "hV")) != -1) { while ((opt = getopt(argc, argv, "hV")) != -1) {
switch (opt) { switch (opt) {

View File

@ -1,17 +1,16 @@
#include <curses.h>
#include <menu.h>
#include <ncurses.h>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <locale>
#include "const.h" #include "const.h"
#include "cups.h" #include "cups.h"
#include "editor_easy.h" #include "editor_easy.h"
#include "gameske_funkce.h" #include "gameske_funkce.h"
#include "memory.h" #include "memory.h"
#include "types.h" #include "types.h"
#include <clocale>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <curses.h>
#include <menu.h>
#include <ncurses.h>
std::vector<allocation> main_menu_allocated; std::vector<allocation> main_menu_allocated;
@ -22,7 +21,6 @@ const char* choices2[] = {"PRINT", "EDIT", "DELETE", "Žena"};
void menu() { void menu() {
current_allocated = &main_menu_allocated; current_allocated = &main_menu_allocated;
/* Initialize curses */ /* Initialize curses */
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
initscr(); initscr();
start_color(); start_color();
@ -97,7 +95,7 @@ void menu() {
break; break;
case "easy_edit"_sh: case "easy_edit"_sh:
case "ee"_sh: case "ee"_sh:
std::clog << vytvorTrestniOznameni(); vytvorTrestniOznameni();
break; break;
default: default:
print_in_middle(main_menu.win, 10, 0, 40, "Unknown command", print_in_middle(main_menu.win, 10, 0, 40, "Unknown command",
@ -105,9 +103,7 @@ void menu() {
break; break;
} }
} }
redrawwin(main_menu.win);
wrefresh(main_menu.win); wrefresh(main_menu.win);
refresh();
} }
unpost_menu(main_menu.menu); unpost_menu(main_menu.menu);

View File

@ -1,151 +0,0 @@
#include "strings.h"
strings english_strings{
.invalid_option = "Invalid option:",
.usage = "Usage:",
.options = "OPTIONS",
.print_this_help = "Print this help",
.print_version = "Print version",
.version = "Version:",
.main_menu = "Main menu",
.unknown_command = "Unknown command:",
.min_terminal_size = "Minimum terminal size: 90x28",
.name_of_submiter = "Name of submiter:",
.address_of_submiter = "Address of submiter:",
.phone_of_submiter = "Phone of submiter:",
.email_of_submiter = "Email of submiter:",
.name_of_recipient = "Name of recipient:",
.address_of_recipient = "Address of recipient:",
.phone_of_recipient = "Phone of recipient:",
.email_of_recipient = "Email of recipient:",
.place_of_incident = "Place of incident:",
.date_of_incident = "Date of incident (dd.mm.rrrr):",
.description_of_incident = "Description of incident:",
.evidence_of_incident = "Evidence of incident:",
.additional_info = "Additional info:",
.cease_and_desist_entry_of_information =
"CEASE AND DESIST - ENTRY OF INFORMATION",
.enter_all_information_and_press_f10 =
"Enter all information and press F10 to finish",
.cease_and_desist_template = R"(
CEASE AND DESIST NOTICE
In {} on {}
Recipient:
First and last name: {}
Address: {}
Phone: {}
Email: {}
Sender:
First and last name: {}
Address: {}
Phone: {}
Email: {}
Subject: Notice to immediately cease unlawful conduct
{}
The unlawful conduct occurred on {} in {}.
Description of the unlawful conduct:
{}
Evidence:
{}
Additional information:
{}
If you do not cease the above-mentioned conduct, I will be forced to take further legal action, including filing a criminal complaint and seeking compensation for damages.
Sincerely,
............................
{}
(signature)
*This is not a legal document, but only a template for informational purposes. For legal advice, please consult a qualified attorney.*
)",
.call_to_stop_illegal_activity =
"I hereby call upon you to immediately cease the unlawful conduct.",
.call_to_stop_illegal_activity_with_name =
"I hereby call upon you, {}, to immediately cease the unlawful "
"conduct."};
strings czech_strings{
.invalid_option = "Neplatná volba: ",
.usage = "Použití:",
.options = "MOŽNOSTI",
.print_this_help = "Zobrazit tuto nápovědu",
.print_version = "Zobrazit verzi",
.version = "Verze: ",
.main_menu = "Hlavní nabídka",
.unknown_command = "Neznámý příkaz: ",
.min_terminal_size = "Minimální velikost terminálu: 90x28",
.name_of_submiter = "Jméno podavatele: ",
.address_of_submiter = "Adresa podavatele: ",
.phone_of_submiter = "Telefon podavatele: ",
.email_of_submiter = "Email podavatele: ",
.name_of_recipient = "Jméno adresáta: ",
.address_of_recipient = "Adresa adresáta: ",
.phone_of_recipient = "Telefon adresáta: ",
.email_of_recipient = "Email adresáta: ",
.place_of_incident = "Místo činu: ",
.date_of_incident = "Datum činu (dd.mm.rrrr):",
.description_of_incident = "Popis činu:",
.evidence_of_incident = "Důkazy:",
.additional_info = "Další informace:",
.cease_and_desist_entry_of_information = "TRESTNÍ OZNÁMENÍ - ZADÁNÍ ÚDAJŮ",
.enter_all_information_and_press_f10 =
"Zadejte všechny údaje a stiskněte F10 pro dokončení",
.cease_and_desist_template = R"(
VÝZVA K UPUŠTĚNÍ OD PROTIPRÁVNÍHO JEDNÁNÍ
V {} dne {}
Adresát:
Jméno a příjmení: {}
Adresa: {}
Telefon: {}
Email: {}
Odesílatel:
Jméno a příjmení: {}
Adresa: {}
Telefon: {}
Email: {}
Věc: Výzva k okamžitému upuštění od protiprávního jednání
{}
K protiprávnímu jednání došlo dne {} v {}.
Popis protiprávního jednání:
{}
Důkazy:
{}
Další informace:
{}
Pokud neupustíte od výše uvedeného jednání, budu nucen/a podniknout další právní kroky, včetně podání trestního oznámení a vymáhání náhrady škody.
S pozdravem,
............................
{}
(podpis)
*Toto není právní dokument, ale pouze vzor pro informativní účely. Pro právní poradenství se obraťte na kvalifikovaného právníka.*
)",
.call_to_stop_illegal_activity =
"Tímto Vás vyzývám, abyste okamžitě upustil/a od protiprávního "
"jednání.",
.call_to_stop_illegal_activity_with_name =
"Tímto Vás, {}, vyzývám, abyste okamžitě upustil/a od protiprávního "
"jednání."};

View File

@ -1,43 +0,0 @@
#ifndef PARADOCS_STRINGS_H_
#define PARADOCS_STRINGS_H_
typedef struct {
const char* invalid_option;
const char* usage;
const char* options;
const char* print_this_help;
const char* print_version;
const char* version;
const char* main_menu;
const char* unknown_command;
const char* min_terminal_size;
const char* name_of_submiter;
const char* address_of_submiter;
const char* phone_of_submiter;
const char* email_of_submiter;
const char* name_of_recipient;
const char* address_of_recipient;
const char* phone_of_recipient;
const char* email_of_recipient;
const char* place_of_incident;
const char* date_of_incident;
const char* description_of_incident;
const char* evidence_of_incident;
const char* additional_info;
const char* cease_and_desist_entry_of_information;
const char* enter_all_information_and_press_f10;
const char* cease_and_desist_template;
const char* call_to_stop_illegal_activity;
const char* call_to_stop_illegal_activity_with_name;
} strings;
extern strings english_strings;
extern strings czech_strings;
extern strings* loc_strings;
#endif