From c19ed5019b55ed603dc10ff6f8ea47bf25058589 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 12 May 2004 07:53:27 +0000 Subject: [PATCH] added usage function, added parsing of argv, some display tests .. --- src/ivac.c | 67 ++++++++++++++++++++++++++++++++++++++++++------------ src/ivac.h | 2 ++ 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/ivac.c b/src/ivac.c index 0a29f21..3aad599 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -25,6 +25,20 @@ #include "ivac.h" +int usage(void) { + + puts(""); + puts("usage: ivac "); + puts(""); + puts("options:"); + puts("-h \t\t show this help"); + puts("-n \t specify your name"); + puts("-p \t specify port to listen for incoming connections"); + puts(""); + + return SUCCESS; +} + int main(int argc,char **argv) { /* TESTING BY NOW */ @@ -32,13 +46,31 @@ int main(int argc,char **argv) { t_ivac ivac; int i; - if(argc!=2) { - printf("\nusage: %s \n\n",argv[0]); - return ERROR; + /* default values */ + strcpy(ivac.username,"ivac"); + ivac.net.l_port=IVAC_LISTEN_PORT; + + /* parse argv and change default values */ + for(i=1;inet)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); - // display_shutdown(&(ivac->display)); +#ifdef USE_NCURSES + display_shutdown(&(ivac->display)); +#endif return SUCCESS; } @@ -131,7 +163,7 @@ int ivac_send_info(int channel,t_ivac *ivac) { int ivac_send_quit(int channel,t_ivac *ivac) { - char data[6]; + char data[7]; /* one more for \0 */ data[0]=IVAC_SEND_QUIT; data[1]=4; @@ -182,7 +214,8 @@ int ivac_receive_info(int channel,t_ivac *ivac) { memset(&(ivac->challenger[channel]),0,sizeof(t_challenger)); count+=6; default: - puts("[ivac] ivac_receive_info, unknown character"); + printf("[ivac] ivac_receive_info, unknown character: (%c,%02x\n", + data[count]); return ERROR; break; } @@ -223,7 +256,7 @@ int ivac_event_cb(t_event *event,void *ptr) { /* remote is sending info */ if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) ivac_receive_info(channel,ivac); - // ivac_display_content(ivac); + ivac_display_content(ivac); } } @@ -286,6 +319,12 @@ int ivac_parse_command(t_input *input,void *ptr) { if(!(strncmp(arg[0],"quit",4))) { valid=1; sprintf(c_str,"ivac shutdown ..."); + for(i=0;inet.connection[i].status&C_ESTABL) { + ivac_send_quit(i,ivac); + network_close(&(ivac->net),i); + } + } ivac_shutdown(ivac); } if(!(strncmp(arg[0],"set",3))) { diff --git a/src/ivac.h b/src/ivac.h index b635160..af64d04 100644 --- a/src/ivac.h +++ b/src/ivac.h @@ -65,8 +65,10 @@ typedef struct s_ivac { } t_ivac; /* function prototypes */ +int usage(void); int ivac_shutdown(t_ivac *ivac); int ivac_send_info(int channel,t_ivac *ivac); +int ivac_send_quit(int channel,t_ivac *ivac); int ivac_receive_info(int channel,t_ivac *ivac); int ivac_event_cb(t_event *event,void *ptr); int ivac_regular_cb(t_event *event,void *ptr); -- 2.39.2