Ristrutturato in più file

This commit is contained in:
admin committed 2025-10-31 14:34:27 +01:00
1 parent 499b3787c6
commit 5508532619
19 files changed
+280 -103

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
{
"makefile.configureOnOpen": false,
"files.associations": {
"ncurses.h": "c",
"logic.h": "c",
"stdio.h": "c",
"globals.h": "c",
"windows.h": "c",
"stdlib.h": "c"
}
}
+2
View File
@@ -0,0 +1,2 @@
build/globals.o: src/globals.c src/../include/globals.h
src/../include/globals.h:
BIN
View File
Binary file not shown.
+4
View File
@@ -0,0 +1,4 @@
build/logic.o: src/logic.c src/../include/logic.h \
src/../include/globals.h
src/../include/logic.h:
src/../include/globals.h:
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
build/main.o: src/main.c include/windows.h include/logic.h
include/windows.h:
include/logic.h:
BIN
View File
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
build/windows.o: src/windows.c src/../include/windows.h \
src/../include/logic.h src/../include/globals.h
src/../include/windows.h:
src/../include/logic.h:
src/../include/globals.h:
BIN
View File
Binary file not shown.
+11
View File
@@ -0,0 +1,11 @@
#ifndef GLOBALS_H
#define GLOBALS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
extern char productPricesFileLocation[64]; // Dichiarazione extern
#endif
+15
View File
@@ -0,0 +1,15 @@
#ifndef LOGIC_H
#define LOGIC_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
// TODO: QUI CI VA LA STRUCT DATI
int getCount();
void changeFile();
int exists(const char *fname);
#endif
+20
View File
@@ -0,0 +1,20 @@
#ifndef WINDOWS_H
#define WINDOWS_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
int runMainMenu();
void runOptionsMenu();
void warningf(const char *fmt, ...);
void warning(char *string);
void statusf(const char *fmt, ...);
void status(char *msg);
WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win);
void print_menu(WINDOW *menu_win, int y, int x, int highlight);
void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const char *str);
#endif
+18 -25
View File
@@ -1,33 +1,26 @@
# Makefile per un programma C con ncurses su Linux x64
# Variabili
CC = gcc
CFLAGS = -Wall -g -std=c11
NCLUDE_DIRS = ./
LDLIBS = -lncurses -lncursesw
CFLAGS = -I./include -Wall -Wextra -MMD -MP
LDLIBS = -lncurses
SRC_DIR = src
BUILD_DIR = build
SOURCES = $(wildcard $(SRC_DIR)/*.c)
OBJECTS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SOURCES))
EXEC = newCounter
# Nome del programma
TARGET = newCounter
DEPS = $(OBJECTS:.o=.d)
# File sorgente
SRC_FILES = main.c
all: $(EXEC)
# Nome dell'eseguibile
EXECUTABLE = $(TARGET)
$(EXEC): $(OBJECTS)
$(CC) $^ -o $@ $(LDLIBS)
# Default target
all: $(EXECUTABLE)
# Regole di compilazione
$(EXECUTABLE): $(SRC_FILES)
$(CC) $(CFLAGS) $(SRC_FILES) -o $(EXECUTABLE) $(LDLIBS)
# Regole per la pulizia (rimuove l'eseguibile e i file oggetto)
clean:
rm -f $(EXECUTABLE) *.o
# Regole per la creazione di file oggetto (opzionale, ma consigliata per una compilazione più veloce)
%.o: %.c
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c $< -o $@
-include $(DEPS)
clean:
rm -rf $(BUILD_DIR) $(EXEC)
.PHONY: all clean
BIN
View File
Binary file not shown.
View File
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
#include "../include/globals.h"
char productPricesFileLocation[64]="./productPricesSettings.txt";
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include "../include/logic.h"
#include "../include/globals.h"
FILE *products;
int exists(const char *fname) {
FILE *file;
if ((file = fopen(fname, "r")))
{
fclose(file);
return 1;
}
return 0;
}
void changeFile(){
}
int getCount(){
return 0;
}
+66
View File
@@ -0,0 +1,66 @@
/*
* [Guida NCURSES](https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html)
* Product Manager
*
* Controllare se file esiste
* Listare prodotti con prezzo da file
* Aggiungere prodotto con prezzo a file
* Listare copie vendute di prodotto da file
* Aggiungere copie venduto di prodotto a file
* Cambiare nome dei file con interagisce
* Calcolare la somma delle entrate dati i file
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include <windows.h>
#include <logic.h>
int main(){
initscr();
if(has_colors() == FALSE)
{ endwin();
warning("Your terminal does not support color");
exit(1);
}
start_color();
//initialize options
noecho();
curs_set(0);
raw();
mvprintw(LINES -1, COLS / 2 - 25, "Product Manager by Vincenzo Nikodem Cesqui Podiani");
refresh();
//initialize colors
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_BLACK, COLOR_BLUE);
init_pair(3, COLOR_BLACK, COLOR_YELLOW);
statusf("");
int running = 0;
while(running != 6){
running = runMainMenu();
switch(running) {
case 1:
warning("Questa e' una stringa molto lunga . . . Ma anche un test, che ti devo dire, ci proviamo a fare cose che non sono mai state fatte, oltretutto che divertimento ci sarebbe senza esperienze nuove?");
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
runOptionsMenu();
break;
case 6:
break;
}
}
endwin();
return 0;
}
+94 -78
View File
@@ -1,37 +1,12 @@
/*
* [Guida NCURSES](https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/intro.html)
* Product Manager
*
* Controllare se file esiste
* Listare prodotti con prezzo da file
* Aggiungere prodotto con prezzo a file
* Listare copie vendute di prodotto da file
* Aggiungere copie venduto di prodotto a file
* Cambiare nome dei file con interagisce
* Calcolare la somma delle entrate dati i file
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
// Prototipi
int runMainMenu();
void warning(char *string);
WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win);
void print_menu(WINDOW *menu_win, int y, int x, int highlight);
void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const char *str);
int getCount();
void changeFile();
int checkIfFileExists();
// Globali
char productPricesFileLocation[64]="./productPricesSetting.txt";
char countFileLocation[64]="./count.txt";
FILE *productPrices;
FILE *count;
#include "../include/windows.h"
#include "../include/logic.h"
#include "../include/globals.h"
#define MAX_LEN 64
char *mainMenu[] = {
"Segna vendita",
@@ -44,36 +19,6 @@ char *mainMenu[] = {
int n_mainMenu = sizeof(mainMenu) / sizeof(char *);
// Funzioni
int main(){
initscr();
//initialize options
noecho();
curs_set(0);
raw();
refresh();
int running = 0;
while(running != 6){
running = runMainMenu();
switch(running) {
case 5:
warning("Questa è una stringa molto lunga . . . Ma anche un test, che ti devo dire, ci proviamo a fare cose che non sono mai state fatte, oltretutto che divertimento ci sarebbe senza esperienze nuove?");
break;
case 6:
break;
}
}
endwin();
return 0;
}
int runMainMenu(){
WINDOW *mainWin;
int startx, starty, width, height;
@@ -114,7 +59,7 @@ int runMainMenu(){
choice = highlight;
break;
default:
mvprintw(LINES - 2, 1, "Il tasto '%c' non e' un tasto valido . . .", c);
statusf("Il tasto '%c' non e' un tasto valido", c);
refresh();
break;
}
@@ -122,7 +67,7 @@ int runMainMenu(){
if(choice != 0) /* User did a choice come out of the infinite loop */
break;
}
mvprintw( LINES - 2 , 1, "Avvio opzione '%s' . . . ", mainMenu[choice - 1]);
statusf("Avvio opzione '%s'", mainMenu[choice - 1]);
clrtoeol();
refresh();
destroy_win(mainWin);
@@ -130,24 +75,109 @@ int runMainMenu(){
return choice;
}
void runOptionsMenu(){
WINDOW *optionsWin;
int startx, starty, width, height;
height = LINES / 2;
width = COLS / 2;
starty = 0;
startx = COLS / 2;
optionsWin = create_newwin(height, width, starty, startx);
char input[MAX_LEN + 1];
strcpy(input, productPricesFileLocation);
int ch, pos = strlen(input);
mvwprintw(optionsWin, 1, 2, "Posizione file prodotti:");
wattron(optionsWin, COLOR_PAIR(2));
for (int i = 0; i < MAX_LEN; i++) {
mvwaddch(optionsWin, 2, 2 + i, ' ');
}
mvwprintw(optionsWin, 2, 2, "%s", input);
wmove(optionsWin, 2, 2 + strlen(input));
wrefresh(optionsWin);
pos = strlen(input);
// Input nella finestra
curs_set(1);
while ((ch = wgetch(optionsWin)) != '\n') {
if (ch == KEY_BACKSPACE || ch == 127 || ch == '\b') {
if (pos > 0) {
pos--;
input[pos] = '\0';
mvwaddch(optionsWin, 2, 2 + pos, ' ');
wmove(optionsWin, 2, 2 + pos);
}
} else if (pos < MAX_LEN && ch >= 32 && ch <= 126) {
input[pos++] = ch;
input[pos] = '\0';
mvwaddch(optionsWin, 2, 2 + pos - 1, ch);
}
wrefresh(optionsWin);
}
curs_set(0);
wattroff(optionsWin, COLOR_PAIR(2));
if (exists(input)) {
statusf("Il file '%s' esiste e verra' utilizzato al posto di '%s'", input, productPricesFileLocation);
strcpy(productPricesFileLocation, input);
}
else {
warningf("Il file '%s' non esiste, utilizzo il vecchio file '%s'", input, productPricesFileLocation);
}
werase(optionsWin);
destroy_win(optionsWin);
}
void warningf(const char *fmt, ...) {
char buf[256];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
warning(buf);
}
void warning(char *string){
WINDOW *warningWin;
int startx, starty, width, height;
height = LINES / 2 - 2;
height = LINES / 2 - 3;
width = COLS / 2;
starty = LINES / 2;
startx = 0;
warningWin = create_newwin(height, width, starty, startx);
wbkgd(warningWin, COLOR_PAIR(1));
mvwprintw(warningWin, 2, 2, "ATTENZIONE! E' avvenuto un errore . . . ");
mvwprintw(warningWin, 2, 2, "ATTENZIONE!!! E' avvenuto un errore! ");
word_wrap_print(warningWin, 4, 3, width - 5, string);
mvwprintw(warningWin, height - 1, width /2, " Premi un tasto per continuare . . . ");
wrefresh(warningWin);
getch();
werase(warningWin);
destroy_win(warningWin);
}
void statusf(const char *fmt, ...) {
char buf[256];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
status(buf);
}
void status(char *msg) {
attron(COLOR_PAIR(3));
mvprintw(LINES -2, 0, " %-*s", COLS -1, msg);
attroff(COLOR_PAIR(3));
refresh();
}
WINDOW *create_newwin(int height, int width, int starty, int startx)
{ WINDOW *local_win;
@@ -160,7 +190,7 @@ WINDOW *create_newwin(int height, int width, int starty, int startx)
void destroy_win(WINDOW *local_win)
{
wborder(local_win, ':', ':', '.', '.', '+', '+', '+', '+');
wborder(local_win, ':', ':', '.', '.', ' ', ' ', ' ', ' ');
wrefresh(local_win);
delwin(local_win);
}
@@ -240,17 +270,3 @@ void word_wrap_print(WINDOW *win, int start_y, int start_x, int max_width, const
mvwprintw(win, y, x, "%s", word_start);
}
int checkIfFileExists(){
return 0;
}
void changeFile(){
}
int getCount(){
return 0;
}