From: hackbard Date: Sun, 27 Jun 2004 21:06:17 +0000 (+0000) Subject: output to stder, added list.* api which is still in work X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=7a01a093081adee6313dc0805f91fb84548e092e;p=my-code%2Fapi.git output to stder, added list.* api which is still in work --- diff --git a/audio/audio.c b/audio/audio.c index 9c8ca4a..57eb6d8 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -8,7 +8,7 @@ int audio_init(t_audio *audio) { - puts("[audio] initializing audio ..."); + fprintf(stderr,"[audio] initializing audio ..."); if((audio->dsp_fd=open(audio->dsp_dev,O_RDWR))==-1) { perror("[audio] open call"); @@ -21,7 +21,7 @@ int audio_init(t_audio *audio) { } if(!(audio->dsp_cap&DSP_CAP_DUPLEX)) { - puts("[audio] no duplex support"); + fprintf(stderr,"[audio] no duplex support"); return A_ERROR; } @@ -32,7 +32,7 @@ int audio_setup(t_audio *audio) { int tmp; - puts("[audio] setting up sound device & allocating record/playback buffer"); + fprintf(stderr,"[audio] setting up sound device & allocating record/playback buffer"); tmp=audio->fmt; if(ioctl(audio->dsp_fd,SNDCTL_DSP_SETFMT,&tmp)==-1) { @@ -40,7 +40,7 @@ int audio_setup(t_audio *audio) { return A_ERROR; } if(tmp!=audio->fmt) { - puts("[audio] FMT not supported"); + fprintf(stderr,"[audio] FMT not supported"); return A_ERROR; } @@ -50,7 +50,7 @@ int audio_setup(t_audio *audio) { return A_ERROR; } if(tmp!=audio->speed) { - puts("[audio] SPEED not supported"); + fprintf(stderr,"[audio] SPEED not supported"); return A_ERROR; } @@ -73,7 +73,7 @@ int audio_setup(t_audio *audio) { int audio_shutdown(t_audio *audio) { - puts("[audio] shutdown"); + fprintf(stderr,"[audio] shutdown"); free(audio->play_data); free(audio->rec_data); diff --git a/display/display.c b/display/display.c index a925e3a..cf09a93 100644 --- a/display/display.c +++ b/display/display.c @@ -6,7 +6,7 @@ #include "display.h" -// #define USE_NCURSES +#define USE_NCURSES int display_init(t_display *display) { @@ -20,8 +20,8 @@ int display_init(t_display *display) { display->max_x=ws.ws_col; display->max_y=ws.ws_row; - printf("[display] initializing display, width: %02d / height: %02d ...\n", - ws.ws_col,ws.ws_row); + fprintf(stderr,"[display] initializing display, width: %02d / height: %02d \n" + ,ws.ws_col,ws.ws_row); /* allocating 'screen' buffer */ if((display->screen=(unsigned char *)malloc(display->max_x*display->max_y)) @@ -56,8 +56,8 @@ int display_draw(t_display *display) { #else for(y=0;ymax_y;y++) { for(x=0;xmax_x;x++) - printf("%c",*(display->screen+y*display->max_x+x)); - printf("\n"); + fprintf(stderr,"%c",*(display->screen+y*display->max_x+x)); + fprintf(stderr,"\n"); } #endif @@ -77,8 +77,8 @@ int display_draw_until_line(t_display *display,int line) { #else for(y=0;ymax_x;x++) - printf("%c",*(display->screen+y*display->max_x+x)); - printf("\n"); + fprintf(stderr,"%c",*(display->screen+y*display->max_x+x)); + fprintf(stderr,"\n"); } #endif @@ -110,7 +110,7 @@ int display_shutdown(t_display *display) { free(display->screen); - puts("[display] shutdown"); + fprintf(stderr,"[display] shutdown"); return D_SUCCESS; } diff --git a/event/event.c b/event/event.c index 455921d..748ea83 100644 --- a/event/event.c +++ b/event/event.c @@ -8,7 +8,7 @@ int event_init(t_event *event) { - write(2,"[event] initializing event system ...",37); + fprintf(stderr,"[event] initializing event system ..."); event->maxfd=0; @@ -32,8 +32,8 @@ int event_math(int fd,t_event *event,char rw,char ar) { if(fd==event->maxfd) event->maxfd-=1; } - printf("[event] %c fd %d to %c file descriptor set\n",ar==ADD?'+':'-',fd, - rw==READ?'r':'w'); + fprintf(stderr,"[event] %c fd %d to %c file descriptor set\n",ar==ADD?'+':'-', + fd,rw==READ?'r':'w'); return E_SUCCESS; } @@ -63,14 +63,14 @@ int event_start(t_event *event,void *ptr, if(s_ret) { /* 1+ fd(s) available for reading/writing */ if(callback0(event,ptr)==CALLBACK_ERROR) { - write(2,"[event] callback0 returned error",32); + fprintf(stderr,"[event] callback0 returned error"); return E_ERROR; } } /* usual stuff to be executed */ if(callback1(event,ptr)==CALLBACK_ERROR) { - write(2,"[event] callback returned error",31); + fprintf(stderr,"[event] callback returned error"); return E_ERROR; } @@ -81,7 +81,7 @@ int event_start(t_event *event,void *ptr, int event_stop(t_event *event) { - write(2,"[event] shutdown",16); + fprintf(stderr,"[event] shutdown"); event->status=DISABLED; return E_SUCCESS; diff --git a/input/input.c b/input/input.c index 86dac62..c734a5b 100644 --- a/input/input.c +++ b/input/input.c @@ -11,10 +11,9 @@ int input_init(t_input *input) { struct termios tios; int size; - puts("[input] initializing input system ..."); + fprintf(stderr,"[input] initializing input system ..."); - // size=((input->mode&CONTENT_BUFFER)?MAX_CONTENT:1); <- ??? - size=MAX_CONTENT; + size=((input->mode&CONTENT_BUFFER)?MAX_CONTENT:1); if((input->content=(char *)malloc(size))==NULL) { perror("[input] malloc call"); @@ -45,7 +44,7 @@ int input_shutdown(t_input *input) { free(input->content); tcsetattr(0,TCSANOW,&(input->tios)); - puts("[input] shutdown"); + fprintf(stderr,"[input] shutdown"); return I_SUCCESS; } @@ -65,7 +64,7 @@ int input_get_event(t_input *input,int (*callback)(t_input *input,void *ptr), } if(input->c_count>=MAX_CONTENT) { - puts("[input] max input length reached"); + fprintf(stderr,"[input] max input length reached"); return I_ERROR; } diff --git a/list/list.c b/list/list.c index 681db53..221b2fb 100644 --- a/list/list.c +++ b/list/list.c @@ -8,5 +8,21 @@ int list_init(t_list *list) { - if(list->type==SINGLE) { - list->start + list-> + list->current=&(list->start); + + return L_SUCCESS; +} + +int list_add_element(t_list *list,int nr,void *data,int len) { + + if(list->method&C_NUMBER) { + while(list->current->next!=NULL) { + if(list->current->number==nr) return L_EXISTS; + else list->current=list->current->next; + } + if(list->current->number==nr) return L_EXISTS; + + /* new element */ + if((list->current->next=(t_list *)malloc(sizeof(t_list)))==NULL) { + fprintf(stderr,"[list] diff --git a/list/list.h b/list/list.h index c500c1a..b415f90 100644 --- a/list/list.h +++ b/list/list.h @@ -2,9 +2,11 @@ #include +#define L_SUCCESS 1 +#define L_ERROR -1 -#define SINGLE 'S' -#define DOUBLE 'D' +#define C_NUMBER (1<<0) +#define C_DATA (1<<1) typedef struct s_list_element { struct s_list_element *next; @@ -14,4 +16,6 @@ typedef struct s_list_element { typedef struct s_list { t_list_element start; + unsigned char method; + t_list_element *current; } t_list; diff --git a/network/network.c b/network/network.c index 053e309..2bd7ce3 100644 --- a/network/network.c +++ b/network/network.c @@ -11,7 +11,7 @@ int network_init(t_net *net) { struct sockaddr_in addr; int true; - puts("[network] initializing network ..."); + fprintf(stderr,"[network] initializing network ..."); memset(net->connection,0,MAX_CONNECTIONS*sizeof(t_connection)); net->c_count=0; @@ -35,7 +35,7 @@ int network_init(t_net *net) { perror("[network] setsockopt call"); return N_ERROR; } - puts("[network] reused address"); + fprintf(stderr,"[network] reused address"); } if(listen(net->l_fd,MAX_LISTEN_QUEUE)==-1) { @@ -43,8 +43,8 @@ int network_init(t_net *net) { return N_ERROR; } - printf("[network] listen on %s port %d\n",inet_ntoa(addr.sin_addr), - net->l_port); + fprintf(stderr,"[network] listen on %s port %d\n",inet_ntoa(addr.sin_addr), + net->l_port); return N_SUCCESS; } @@ -62,7 +62,7 @@ int network_shutdown(t_net *net) { return N_ERROR; } - puts("[network] shutdown"); + fprintf(stderr,"[network] shutdown"); return N_SUCCESS; } @@ -88,7 +88,7 @@ int network_manage_connection(t_net *net) { perror("[network] close call"); return N_E_CLOSE; } - printf("[network] connection %d closed\n",i); + fprintf(stderr,"[network] connection %d closed\n",i); net->connection[i].status=0; } @@ -119,9 +119,9 @@ int network_manage_connection(t_net *net) { return N_E_CONNECT; } - printf("[network] established connection to "); - printf("%s port %d on channel %d\n",net->connection[i].ip, - net->connection[i].port,i); + fprintf(stderr,"[network] established connection to "); + fprintf(stderr,"%s port %d on channel %d\n",net->connection[i].ip, + net->connection[i].port,i); net->connection[i].status|=C_ESTABL; } @@ -138,12 +138,11 @@ int network_manage_connection(t_net *net) { int network_connect(t_net *net,int channel) { if(net->connection[channel].status&C_IN_USE) { - printf("[network] connect failed, channel %02d in use\n",channel); + fprintf(stderr,"[network] connect failed, channel %02d in use\n",channel); return N_E_IN_USE; } if(!(net->connection[channel].status&C_INFO_A)) { - printf("[network] connect failed, missing configuration for channel %02d\n", - channel); + fprintf(stderr,"[network] connect failed, missing configuration for channel %02d\n",channel); return N_E_NO_INFO; } @@ -155,7 +154,7 @@ int network_connect(t_net *net,int channel) { int network_close(t_net *net,int channel) { if(!(net->connection[channel].status&C_ESTABL)) { - printf("[network] close failed, channel %02d not active\n",channel); + fprintf(stderr,"[network] close failed, channel %02d not active\n",channel); return N_E_NC; } @@ -176,7 +175,8 @@ int network_close_all(t_net *net) { int network_set_connection_info(t_net *net,int channel,char *ip,int port) { if(net->connection[channel].status&C_IN_USE) { - printf("[network] set connection failed, channel %02d in use\n",channel); + fprintf(stderr,"[network] set connection failed, channel %02d in use\n", + channel); return N_E_IN_USE; } @@ -226,13 +226,12 @@ int network_manage_incoming(t_net *net) { strncpy(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS); net->connection[channel].port=ntohs(addr.sin_port); net->connection[channel].status=C_IN_USE|C_INFO_A|C_SOCKET|C_ESTABL; - printf("[network] established connection from %s port %d on channel %d\n", - net->connection[channel].ip,net->connection[channel].port,channel); + fprintf(stderr,"[network] established connection from %s port %d on channel %d\n",net->connection[channel].ip,net->connection[channel].port,channel); return channel; } } - puts("[network] maximum connections reached"); + fprintf(stderr,"[network] maximum connections reached"); return N_E_MAXC; } @@ -288,10 +287,10 @@ int network_udp_listen_init(t_net *net) { perror("[network] setsockopt call (udp)"); return N_ERROR; } - puts("[network] reused address (udp)"); + fprintf(stderr,"[network] reused address (udp)"); } - printf("[network] listening on port %d (udp)\n",net->l_udp_port); + fprintf(stderr,"[network] listening on port %d (udp)\n",net->l_udp_port); if((net->s_udp_fd=socket(AF_INET,SOCK_DGRAM,0))==-1) { perror("[network] socket call (udp-send)"); @@ -313,7 +312,8 @@ int network_udp_receive(t_net *net,int channel, unsigned char *data,int count) { } if(strncmp(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS)) { - printf("[network] packet from unknown: %s\n",inet_ntoa(addr.sin_addr)); + fprintf(stderr,"[network] packet from unknown: %s\n", + inet_ntoa(addr.sin_addr)); return N_UDP_WRONG_SENDER; }