From: hackbard Date: Fri, 4 Jun 2004 23:08:48 +0000 (+0000) Subject: changes in display method -> ncurses (strange *printf probs :/) X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99e577ce594ed343397276ac6c2dd9729ac10d6d;p=my-code%2Fivac.git changes in display method -> ncurses (strange *printf probs :/) --- diff --git a/src/Makefile b/src/Makefile index 22c8045..6ea10fd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,12 +3,12 @@ INCLUDEDIR = /usr/include CFLAGS = -DDISPLAY -DDEBUG -O3 -Wall -LIBS = +LIBS = -lncurses OBJS = network.o event.o input.o display.o audio.o ivac: $(OBJS) - $(CC) -o $@ $(OBJS) ivac.c $(LIBS) + $(CC) $(CFLAGS) -o $@ $(OBJS) ivac.c $(LIBS) all: ivac clean: diff --git a/src/display.c b/src/display.c index c46c11c..e42c30b 100644 --- a/src/display.c +++ b/src/display.c @@ -6,6 +6,8 @@ #include "display.h" +#define USE_NCURSES + int display_init(t_display *display) { struct winsize ws; @@ -30,6 +32,14 @@ int display_init(t_display *display) { /* space as display pixel default */ memset(display->screen,0x20,display->max_x*display->max_y); +#ifdef USE_NCURSES + initscr(); + nonl(); + noecho(); + cbreak(); + curs_set(0); +#endif + return D_SUCCESS; } @@ -37,11 +47,19 @@ int display_draw(t_display *display) { int x,y; +#ifdef USE_NCURSES + mvprintw(0,0,"%s",display->screen); + for(y=0;ymax_y;y++) + for(x=0;xmax_x;x++) + mvaddch(y,x,*(display->screen+y*display->max_x+x)); + refresh(); +#else for(y=0;ymax_y;y++) { for(x=0;xmax_x;x++) printf("%c",*(display->screen+y*display->max_x+x)); printf("\n"); } +#endif return D_SUCCESS; } @@ -50,11 +68,29 @@ int display_draw_until_line(t_display *display,int line) { int x,y; +#ifdef USE_NCURSES + for(y=0;ymax_x;x++) + mvaddch(y,x,*(display->screen+y*display->max_x+x)); + refresh(); + } +#else for(y=0;ymax_x;x++) printf("%c",*(display->screen+y*display->max_x+x)); printf("\n"); } +#endif + + return D_SUCCESS; +} + +int display_set_cursor(t_display *display,int x,int y) { + +#ifdef USE_NCURSES + move(y,x); + refresh(); +#endif return D_SUCCESS; } @@ -68,6 +104,10 @@ int display_clear_screen(t_display *display) { int display_shutdown(t_display *display) { +#ifdef USE_NCURSES + endwin(); +#endif + free(display->screen); puts("[display] shutdown"); diff --git a/src/display.h b/src/display.h index 4d89b63..29cf6c9 100644 --- a/src/display.h +++ b/src/display.h @@ -5,6 +5,7 @@ #include #include #include +#include /* defines */ #define D_SUCCESS 1 @@ -28,6 +29,7 @@ typedef struct s_display { int display_init(t_display *display); int display_draw(t_display *display); int display_draw_until_line(t_display *display,int line); +int display_set_cursor(t_display *display,int x,int y); int display_clear_screen(t_display *display); int display_shutdown(t_display *display); int display_line(t_display *display,int X,int Y,int X_,int Y_,char sym); diff --git a/src/ivac.c b/src/ivac.c index 55188ec..281b1a5 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -98,11 +98,18 @@ int main(int argc,char **argv) { ivac.event.timeout.tv_sec=IVAC_S_SEC; ivac.event.timeout.tv_usec=IVAC_S_USEC; /* event init */ - event_init(&(ivac.event)); + if(event_init(&(ivac.event))==E_ERROR) { + ivac_shutdown(&ivac); + return ERROR; + } /* input init */ ivac.input.mode=CONTENT_BUFFER; - input_init(&(ivac.input)); + ivac.input.c_count=0; + if(input_init(&(ivac.input))==I_ERROR) { + ivac_shutdown(&ivac); + return ERROR; + } /* network init */ if(network_init(&(ivac.net))==N_ERROR) { @@ -111,6 +118,8 @@ int main(int argc,char **argv) { ivac_shutdown(&ivac); return ERROR; } + + /* network udp init */ network_udp_listen_init(&(ivac.net)); /* add listening port(s) + stdin to (read) event system */ @@ -118,19 +127,21 @@ int main(int argc,char **argv) { event_math(ivac.net.l_udp_fd,&(ivac.event),READ,ADD); event_math(0,&(ivac.event),READ,ADD); - /* display init */ - display_init(&(ivac.display)); - /* use hardcoded audio settings by now */ ivac.audio.fmt=BIT_8; ivac.audio.channels=MONO; ivac.audio.speed=8000; /* audio init */ audio_init(&(ivac.audio)); + /* audio setup */ audio_setup(&(ivac.audio)); + /* display init */ + display_init(&(ivac.display)); + /* display */ ivac_display(&ivac); + ivac_display_content(&ivac); ivac_display_draw(&ivac); /* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */ @@ -141,12 +152,12 @@ int main(int argc,char **argv) { int ivac_shutdown(t_ivac *ivac) { + display_shutdown(&(ivac->display)); network_shutdown(&(ivac->net)); network_udp_shutdown(&(ivac->net)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); audio_shutdown(&(ivac->audio)); - display_shutdown(&(ivac->display)); return SUCCESS; } @@ -216,7 +227,7 @@ int ivac_receive_info(int channel,t_ivac *ivac) { switch(data[count]) { case IVAC_SEND_NAME: strncpy(ivac->challenger[channel].name,data+count+2,data[count+1]); - ivac->challenger[channel].name[data[count+1]]='\0'; + ivac->challenger[channel].name[(int)data[count+1]]='\0'; count+=(data[count+1]+2); break; case IVAC_SEND_G_CAP: @@ -318,6 +329,7 @@ int ivac_parse_command(t_input *input,void *ptr) { char *data,valid; char c_str[IVAC_CONSOLE_STRING_LEN]; char arg[IVAC_ARG_COUNT][IVAC_ARG_LEN]; + char debug_string[128]; ivac=(t_ivac *)ptr; data=input->content; @@ -325,9 +337,28 @@ int ivac_parse_command(t_input *input,void *ptr) { /* refresh prompt content only */ ivac_display_prompt_content(ivac); + ivac_display_draw(ivac); + +#ifdef DEBUG + ivac_add_to_monitor(ivac,"nach display refresh"); +#endif + +#ifdef DEBUG + ivac_add_to_monitor(ivac,"nach display refresh"); +#endif + +#ifdef DEBUG + + strcpy(debug_string,"hahahaha!"); + ivac_add_to_monitor(ivac,debug_string); +#endif /* parse command routines */ - if(data[input->c_count-1]=='\n') { + if(data[input->c_count-1]=='\n' || data[input->c_count-1]=='\r') { + +#ifdef DEBUG + ivac_add_to_monitor(ivac,"got newline or carriage return!"); +#endif /* delete console string + args */ memset(c_str,0,IVAC_CONSOLE_STRING_LEN); @@ -350,6 +381,7 @@ int ivac_parse_command(t_input *input,void *ptr) { i+=k; } + /* parse command aka arg[0] */ if(!(strncmp(arg[0],"quit",4))) { valid=1; @@ -425,7 +457,7 @@ int ivac_parse_command(t_input *input,void *ptr) { network_select(&(ivac->net),channel); sprintf(c_str,"selected channel %d",channel); } - else if(arg[1][0]='*') { + else if(arg[1][0]=='*') { network_select(&(ivac->net),MAX_CONNECTIONS); strcpy(c_str,"selected all channels"); } @@ -439,7 +471,7 @@ int ivac_parse_command(t_input *input,void *ptr) { network_deselect(&(ivac->net),channel); sprintf(c_str,"deselected channel %d",channel); } - else if(arg[1][0]='*') { + else if(arg[1][0]=='*') { network_deselect(&(ivac->net),MAX_CONNECTIONS); strcpy(c_str,"deselected all channels"); } @@ -459,12 +491,14 @@ int ivac_parse_command(t_input *input,void *ptr) { ivac_display_content(ivac); ivac_display_draw(ivac); - /* delete content buffer + reset counter */ + /* delete input content buffer + reset counter */ memset(input->content,0,input->c_count-1); input->c_count=0; } + ivac_add_to_monitor(ivac,"debug: end of parse function"); + return SUCCESS; } @@ -481,8 +515,6 @@ int ivac_display_head(t_ivac *ivac) { int ivac_display_box(t_ivac *ivac) { display_line(&(ivac->display),0,3,ivac->display.max_x,3,'-'); - printf("username: %s, capabilities: %02x|%04x\n",ivac->username,ivac->g_cap, - ivac->av_cap); display_line(&(ivac->display),0,5,ivac->display.max_x,5,'-'); display_string(&(ivac->display),0,6,"connections:",12); display_line(&(ivac->display), @@ -503,6 +535,10 @@ int ivac_display_box_content(t_ivac *ivac) { if(ivac->challenger[channel].name[0]==0) strcpy(ivac->challenger[channel].name,""); + sprintf(string,"username: %s, capabilities: %02x|%04x", + ivac->username,ivac->g_cap,ivac->av_cap); + display_string(&(ivac->display),0,4,string,strlen(string)); + for(channel=0;channelnet.connection[channel].status&C_INFO_A) { snprintf(string,MAX_BOX_CHARS, @@ -545,19 +581,22 @@ int ivac_display_console_content(t_ivac *ivac) { int ivac_display_prompt(t_ivac *ivac) { - /* simply a printf - dirty! */ - printf("prompt: "); - fflush(NULL); + display_string(&(ivac->display),0,ivac->display.max_y-1,"prompt: ",8); return SUCCESS; } int ivac_display_prompt_content(t_ivac *ivac) { - /* simply a printf - dirty! */ - printf("%c",ivac->input.content[ivac->input.c_count-1]); - fflush(NULL); + char string[IVAC_CONSOLE_STRING_LEN]; + int count; + for(count=0;countinput.c_count;count++) + string[count]=ivac->input.content[count]; + for(;countdisplay.max_x-8;count++) string[count]=' '; + display_string(&(ivac->display),8,ivac->display.max_y-1, + string,ivac->display.max_x); + return SUCCESS; } @@ -569,13 +608,14 @@ int ivac_display_content(t_ivac *ivac) { /* display console content */ ivac_display_console_content(ivac); + /* display prompt content */ + ivac_display_prompt_content(ivac); + return SUCCESS; } int ivac_display(t_ivac *ivac) { - int x,y; - /* display static head */ ivac_display_head(ivac); @@ -593,8 +633,9 @@ int ivac_display(t_ivac *ivac) { int ivac_display_draw(t_ivac *ivac) { - display_draw_until_line(&(ivac->display),ivac->display.max_y-1); - ivac_display_prompt(ivac); + display_draw(&(ivac->display)); + display_set_cursor(&(ivac->display),ivac->input.c_count+8, + ivac->display.max_y-1); return SUCCESS; } @@ -607,5 +648,8 @@ int ivac_add_to_monitor(t_ivac *ivac,char *msg) { memcpy(ivac->console[i],ivac->console[i+1],IVAC_CONSOLE_STRING_LEN); memcpy(ivac->console[IVAC_CONSOLE_LEN-1],msg,IVAC_CONSOLE_STRING_LEN); + ivac_display_console_content(ivac); + ivac_display_draw(ivac); + return SUCCESS; }