This commit is contained in:
Davide Fiori 2018-01-04 15:07:31 +01:00
parent cd2751adcc
commit 13c736e040

101
client.c
View file

@ -1,7 +1,7 @@
#include <stdio.h> // prova adesso lezione lab 10 UA3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -14,7 +14,97 @@
#define SERVER_PORT 1313 // numero di porta del server
#define MAXSIZE 10
static int menu();
static struct termios old, new;
/* Initialize new terminal i/o settings */
void initTermios(int echo)
{
tcgetattr(0, &old); /* grab old terminal i/o settings */
new = old; /* make new settings same as old settings */
new.c_lflag &= ~ICANON; /* disable buffered i/o */
new.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
tcsetattr(0, TCSANOW, &new); /* use these new terminal i/o settings now */
}
/* Restore old terminal i/o settings */
void resetTermios(void)
{
tcsetattr(0, TCSANOW, &old);
}
/* Read 1 character - echo defines echo mode */
char getch_(int echo)
{
char ch;
initTermios(echo);
ch = getchar();
resetTermios();
return ch;
}
/* Read 1 character without echo */
char getch(void)
{
return getch_(0);
}
static void titolo(){
printf(" _ _ _ _ _____ _ _ _ \n| | | | (_) | | | __ \\(_) | | (_)\n| | | | _ __ _ __ __ ___ _ __ ___ __ _ | | | |__) |_ ____ ____ ___ ___ ___ | |__ ___ _ __ _ \n| | | || '_ \\ | |\\ \\ / // _ \\| '__|/ __| / _` || | | ___/| ||_ /|_ // _ \\ / __|/ __|| '_ \\ / _ \\| '__|| |\n| |__| || | | || | \\ V /| __/| | \\__ \\| (_| || | | | | | / / / /| (_) || (__| (__ | | | || __/| | | |\n \\____/ |_| |_||_| \\_/ \\___||_| |___/ \\__,_||_| |_| |_|/___|/___|\\___/ \\___|\\___||_| |_| \\___||_| |_|\n---------------------------------------------------------------------------------------------------------------\n\n");
}
int menu() {
int c,x=0;
do{
printf( "\e[2J\e[H" );
titolo();
printf("+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +\n");
printf("| |\n");
printf("| Decidi cosa fare |\n");
printf("| |\n");
printf("+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +\n");
printf("| |\n");
printf("| |\n");
if(x==0) printf("| (1) Fare i pizzocheri |\n| -----------------");
else printf("| 1 Fare i pizzocheri |\n| ");
printf(" |\n");
if(x==1) printf("| (2) Vendere i pizzocheri |\n| --------------------");
else printf("| 2 Vendere i pizzocheri |\n| ");
printf(" |\n");
if(x==2) printf("| (3) Cambiare prezzo |\n| ---------------");
else printf("| 3 Cambiare prezzo |\n| ");
printf(" |\n");
if(x==3) printf("| (4) Comprare il bitto |\n| -----------------");
else printf("| 4 Comprare il bitto |\n| ");
printf(" |\n");
if(x==4) printf("| (5) Comprare la farina |\n| ------------------");
else printf("| 5 Comprare la farina |\n| ");
printf(" |\n");
if(x==5) printf("| (6) Esci |\n| ----");
else printf("| 6 Esci |\n| ");
printf(" |\n");
for(int i=0;i<4;i++)printf("| |\n");
printf("+-------------------------------------------------------------------------------------------------------------+\n");
printf(" Usa '+' per salire, '-' per scendere e 'INVIO' per selezionare la voce");
c = (int)getch();
if(c>=49 && c<=53) x=c-49;
if(c==45 && x<6) x++;
if(c==45 && x==6) x=0;
if(c==43 && x>=0) x--;
if(c==43 && x==-1) x=5;
}while(c!=10);
return c;
}
int main(int argc, char *argv[])
{
@ -121,8 +211,3 @@ int main(int argc, char *argv[])
return(0);
}
static int menu(){
int i=0;
//fare menu
return i;
}