primo commit
This commit is contained in:
commit
405963cf5d
3 files changed
+202
No files matched your search
@@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* [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 <ncurses.h>
|
||||||
|
|
||||||
|
// Prototipi
|
||||||
|
int runMainMenu();
|
||||||
|
WINDOW *create_newwin(int height, int width, int starty, int startx);
|
||||||
|
void destroy_win(WINDOW *local_win);
|
||||||
|
void print_menu(WINDOW *menu_win, int highlight);
|
||||||
|
int getCount();
|
||||||
|
void changeFile();
|
||||||
|
int checkIfFileExists();
|
||||||
|
|
||||||
|
// Costanti
|
||||||
|
char productPricesFileLocation[64]="./productPricesSetting.txt";
|
||||||
|
char countFileLocation[64]="./count.txt";
|
||||||
|
FILE *productPrices;
|
||||||
|
FILE *count;
|
||||||
|
|
||||||
|
char *mainMenu[] = {
|
||||||
|
"Segna vendita",
|
||||||
|
"Vedi vendite",
|
||||||
|
"Vedi prodotti",
|
||||||
|
"Gestisci prodotti",
|
||||||
|
"Opzioni",
|
||||||
|
"Exit"
|
||||||
|
};
|
||||||
|
int n_mainMenu = sizeof(mainMenu) / sizeof(char *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Funzioni
|
||||||
|
int main(){
|
||||||
|
initscr();
|
||||||
|
noecho();
|
||||||
|
curs_set(0);
|
||||||
|
raw();
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
int running = 0;
|
||||||
|
while(running != 6){
|
||||||
|
running = runMainMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
endwin();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int runMainMenu(){
|
||||||
|
WINDOW *mainWin;
|
||||||
|
int startx, starty, width, height;
|
||||||
|
height = LINES / 2;
|
||||||
|
width = COLS / 2;
|
||||||
|
starty = 0;
|
||||||
|
startx = 0;
|
||||||
|
mainWin = create_newwin(height, width, starty, startx);
|
||||||
|
|
||||||
|
int highlight = 1;
|
||||||
|
int choice = 0;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
keypad(mainWin, TRUE);
|
||||||
|
mvwprintw(mainWin, 1, 2, "Usa le freccette ed invio per scegliere un'opzione!");
|
||||||
|
refresh();
|
||||||
|
print_menu(mainWin, highlight);
|
||||||
|
while(1)
|
||||||
|
{ c = wgetch(mainWin);
|
||||||
|
switch(c)
|
||||||
|
{ case KEY_UP:
|
||||||
|
if(highlight == 1)
|
||||||
|
highlight = n_mainMenu;
|
||||||
|
else
|
||||||
|
--highlight;
|
||||||
|
break;
|
||||||
|
case KEY_DOWN:
|
||||||
|
if(highlight == n_mainMenu)
|
||||||
|
highlight = 1;
|
||||||
|
else
|
||||||
|
++highlight;
|
||||||
|
break;
|
||||||
|
case 10:
|
||||||
|
choice = highlight;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mvwprintw(mainWin, height - 2, 2, "Hai premuto il tasto '%c'", c, c);
|
||||||
|
refresh();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
print_menu(mainWin, highlight);
|
||||||
|
if(choice != 0) /* User did a choice come out of the infinite loop */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mvprintw( LINES - 1 , 0, "Hai premuto il tasto %s\n . . .", mainMenu[choice - 1]);
|
||||||
|
clrtoeol();
|
||||||
|
refresh();
|
||||||
|
destroy_win(mainWin);
|
||||||
|
|
||||||
|
return choice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WINDOW *create_newwin(int height, int width, int starty, int startx)
|
||||||
|
{ WINDOW *local_win;
|
||||||
|
|
||||||
|
local_win = newwin(height, width, starty, startx);
|
||||||
|
box(local_win, 0 , 0);
|
||||||
|
wrefresh(local_win);
|
||||||
|
|
||||||
|
return local_win;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy_win(WINDOW *local_win)
|
||||||
|
{
|
||||||
|
wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
|
||||||
|
wrefresh(local_win);
|
||||||
|
delwin(local_win);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_menu(WINDOW *menu_win, int highlight)
|
||||||
|
{
|
||||||
|
int x, y, i;
|
||||||
|
|
||||||
|
x = 3;
|
||||||
|
y = 3;
|
||||||
|
box(menu_win, 0, 0);
|
||||||
|
for(i = 0; i < n_mainMenu; ++i)
|
||||||
|
{ if(highlight == i + 1) /* High light the present choice */
|
||||||
|
{ wattron(menu_win, A_REVERSE);
|
||||||
|
mvwprintw(menu_win, y, x, "%s", mainMenu[i]);
|
||||||
|
wattroff(menu_win, A_REVERSE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mvwprintw(menu_win, y, x, "%s", mainMenu[i]);
|
||||||
|
++y;
|
||||||
|
}
|
||||||
|
wrefresh(menu_win);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int checkIfFileExists(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void changeFile(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int getCount(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Makefile per un programma C con ncurses su Linux x64
|
||||||
|
|
||||||
|
# Variabili
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -Wall -g -std=c11
|
||||||
|
NCLUDE_DIRS = ./
|
||||||
|
LDLIBS = -lncurses -lncursesw
|
||||||
|
|
||||||
|
# Nome del programma
|
||||||
|
TARGET = newCounter
|
||||||
|
|
||||||
|
# File sorgente
|
||||||
|
SRC_FILES = main.c
|
||||||
|
|
||||||
|
# Nome dell'eseguibile
|
||||||
|
EXECUTABLE = $(TARGET)
|
||||||
|
|
||||||
|
# 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
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
Executable
BIN
Binary file not shown.
Reference in new issue
Block a user