yaffs working on the timothy_tests. just need to save the current state of the program.
[yaffs2.git] / direct / timothy_tests / message_buffer.c
1 #include "message_buffer.h"
2
3
4 void add_to_buffer(buffer *p_Buffer, char message[],char message_level){
5         unsigned int x=0;
6
7         p_Buffer->head++;
8
9         printf("p_Buffer->tail=%d\n",p_Buffer->tail);
10         printf("p_Buffer->head=%d\n",p_Buffer->head);
11         if (p_Buffer->head >=BUFFER_SIZE) {
12                 printf("buffer overflow\n");
13                 p_Buffer->head -= BUFFER_SIZE;  /*wrap the head around the buffer*/
14                 printf("new p_Buffer->head=%d\n",p_Buffer->head);
15                 
16         /*if the buffer is full then delete last entry by moving the tail*/
17         if (p_Buffer->head==p_Buffer->tail){
18                 printf("moving buffer tail from %d to ",p_Buffer->tail);
19                 p_Buffer->tail++;
20                 printf("%d\n",p_Buffer->tail);
21                 if (p_Buffer->tail >=BUFFER_SIZE) p_Buffer->tail -= BUFFER_SIZE;/*wrap the tail around the buffer*/
22         }
23
24         /*move the head up one. the head always points at the last written data*/
25
26
27         
28         }
29
30         p_Buffer->message_level[p_Buffer->head]=message_level; /*copy the message level*/
31         x=p_Buffer->head;
32
33
34         
35         strcpy(p_Buffer->message[p_Buffer->head],message); /*copy the message*/
36 /*      
37         //convert the message into a string so it can be printed cleanly
38         if (message[length_of_message-1]!='\0') p_Buffer->message[p_Buffer->head][x+1]='\0';    
39 */
40         if (p_Buffer->message_level[p_Buffer->head]<=DEBUG_LEVEL){
41 //              printf("printing buffer 1\n");
42                  print_buffer(p_Buffer,1); /*if the debug level is higher enough then print the new message*/
43         }
44 }
45 void print_buffer(buffer *p_Buffer, int number_of_messages_to_print){   
46 /*      printf("print buffer\n");
47         printf("buffer head:%d\n",p_Buffer->head);
48         printf("buffer tail:%d\n",p_Buffer->tail);
49 */      int x;
50         int i;
51         if (number_of_messages_to_print==PRINT_ALL) number_of_messages_to_print=BUFFER_SIZE;
52 //      printf("number_of_messages_to_print=%d\n",number_of_messages_to_print);
53         for (i=0,x=p_Buffer->head; (x>=p_Buffer->tail) && (i<number_of_messages_to_print); i++, x--){
54 //              printf("printing bufer\n");
55                 //printf("x:%d\n",x);
56                 if (x<0) x = BUFFER_SIZE;               /*wrap x around buffer*/
57                 printf("%s\n",p_Buffer->message[x]);
58         }
59
60 }
61