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");
}
if(!(audio->dsp_cap&DSP_CAP_DUPLEX)) {
- puts("[audio] no duplex support");
+ fprintf(stderr,"[audio] no duplex support");
return A_ERROR;
}
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) {
return A_ERROR;
}
if(tmp!=audio->fmt) {
- puts("[audio] FMT not supported");
+ fprintf(stderr,"[audio] FMT not supported");
return A_ERROR;
}
return A_ERROR;
}
if(tmp!=audio->speed) {
- puts("[audio] SPEED not supported");
+ fprintf(stderr,"[audio] SPEED not supported");
return A_ERROR;
}
int audio_shutdown(t_audio *audio) {
- puts("[audio] shutdown");
+ fprintf(stderr,"[audio] shutdown");
free(audio->play_data);
free(audio->rec_data);
#include "display.h"
-// #define USE_NCURSES
+#define USE_NCURSES
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))
#else
for(y=0;y<display->max_y;y++) {
for(x=0;x<display->max_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
#else
for(y=0;y<line;y++) {
for(x=0;x<display->max_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
free(display->screen);
- puts("[display] shutdown");
+ fprintf(stderr,"[display] shutdown");
return D_SUCCESS;
}
int event_init(t_event *event) {
- write(2,"[event] initializing event system ...",37);
+ fprintf(stderr,"[event] initializing event system ...");
event->maxfd=0;
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;
}
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;
}
int event_stop(t_event *event) {
- write(2,"[event] shutdown",16);
+ fprintf(stderr,"[event] shutdown");
event->status=DISABLED;
return E_SUCCESS;
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");
free(input->content);
tcsetattr(0,TCSANOW,&(input->tios));
- puts("[input] shutdown");
+ fprintf(stderr,"[input] shutdown");
return I_SUCCESS;
}
}
if(input->c_count>=MAX_CONTENT) {
- puts("[input] max input length reached");
+ fprintf(stderr,"[input] max input length reached");
return I_ERROR;
}
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]
#include <stdio.h>
+#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;
typedef struct s_list {
t_list_element start;
+ unsigned char method;
+ t_list_element *current;
} t_list;
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;
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) {
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;
}
return N_ERROR;
}
- puts("[network] shutdown");
+ fprintf(stderr,"[network] shutdown");
return N_SUCCESS;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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)");
}
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;
}