X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftimothy_tests%2Fmessage_buffer.c;h=58c3038934c4eba0afa1525901ad452126ca52e4;hp=fe64a6b0215dd1383ff8a731bc56cc2e0ecac5ce;hb=1006cb30d2977365c64e4dd544b445b088750061;hpb=b708f76c6a03f86058236dbd529e8c3623571325 diff --git a/direct/timothy_tests/message_buffer.c b/direct/timothy_tests/message_buffer.c index fe64a6b..58c3038 100644 --- a/direct/timothy_tests/message_buffer.c +++ b/direct/timothy_tests/message_buffer.c @@ -1,49 +1,72 @@ +/* + * YAFFS: Yet another FFS. A NAND-flash specific file system. + * + * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Timothy Manning + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * message_buffer.c contains code for a message buffer . + */ + #include "message_buffer.h" +void append_to_buffer(buffer *p_Buffer, char *message,char message_level,char print){ + /*wrapper function for add_to_buffer_root_function*/ + add_to_buffer_root_function(p_Buffer,message, message_level,APPEND_MESSAGE,print); +} -void add_to_buffer(buffer *p_Buffer, char *message,char message_level){ - unsigned int x=0; - /*move the head up one. the head always points at the last written data*/ - p_Buffer->head++; +void add_to_buffer(buffer *p_Buffer, char *message,char message_level,char print){ + /*wrapper function for add_to_buffer_root_function*/ + add_to_buffer_root_function(p_Buffer,message, message_level,DO_NOT_APPEND_MESSAGE,print); +} -// printf("p_Buffer->tail=%d\n",p_Buffer->tail); -// printf("p_Buffer->head=%d\n",p_Buffer->head); - if (p_Buffer->head >=BUFFER_SIZE-1) { -// printf("buffer overflow\n"); - p_Buffer->head -= (BUFFER_SIZE-1); /*wrap the head around the buffer*/ -// printf("new p_Buffer->head=%d\n",p_Buffer->head); - } - /*if the buffer is full then delete last entry by moving the tail*/ - if (p_Buffer->head==p_Buffer->tail){ -// printf("moving buffer tail from %d to ",p_Buffer->tail); - p_Buffer->tail++; - if (p_Buffer->tail >=BUFFER_SIZE) p_Buffer->tail -= BUFFER_SIZE;/*wrap the tail around the buffer*/ -// printf("%d\n",p_Buffer->tail); +void add_to_buffer_root_function(buffer *p_Buffer, char *message,char message_level,char append,char print){ + if (append==APPEND_MESSAGE){ /* append current message*/ + strncat(p_Buffer->message[p_Buffer->head],message,BUFFER_MESSAGE_LENGTH); } + else { + /*move the head up one. the head always points at the last written data*/ + p_Buffer->head++; + /*printf("p_Buffer->tail=%d\n",p_Buffer->tail);*/ + /*printf("p_Buffer->head=%d\n",p_Buffer->head);*/ + if (p_Buffer->head >=BUFFER_SIZE-1) { + /*printf("buffer overflow\n");*/ + p_Buffer->head -= (BUFFER_SIZE-1); /*wrap the head around the buffer*/ + /*printf("new p_Buffer->head=%d\n",p_Buffer->head);*/ + } + /*if the buffer is full then delete last entry by moving the tail*/ + if (p_Buffer->head==p_Buffer->tail){ + /*printf("moving buffer tail from %d to ",p_Buffer->tail);*/ + p_Buffer->tail++; + if (p_Buffer->tail >=BUFFER_SIZE) p_Buffer->tail -= BUFFER_SIZE;/*wrap the tail around the buffer*/ + /*printf("%d\n",p_Buffer->tail);*/ + } - - - - p_Buffer->message_level[p_Buffer->head]=message_level; /*copy the message level*/ - x=p_Buffer->head; - - - - strcpy(p_Buffer->message[p_Buffer->head],message); /*copy the message*/ -// printf("copied %s into p_Buffer->message[p_Buffer->head]: %s\n",message,p_Buffer->message[p_Buffer->head]); -// printf("extra %s\n",p_Buffer->message[p_Buffer->head]); - - if (p_Buffer->message_level[p_Buffer->head]<=DEBUG_LEVEL){ -// printf("printing buffer 1\n"); - /* the print buffer sfunction is not working this is just a quick fix*/ -// print_buffer(p_Buffer,1); /*if the debug level is higher enough then print the new message*/ + p_Buffer->message_level[p_Buffer->head]=message_level; /*copy the message level*/ + strncpy(p_Buffer->message[p_Buffer->head],message,BUFFER_MESSAGE_LENGTH); /*copy the message*/ + /*printf("copied %s into p_Buffer->message[p_Buffer->head]: %s\n",message,p_Buffer->message[p_Buffer->head]); + printf("extra %s\n",p_Buffer->message[p_Buffer->head]);*/ + } + if ((p_Buffer->message_level[p_Buffer->head]<=DEBUG_LEVEL)&& (print==PRINT)){ + /*printf("printing buffer 1\n"); + // the print buffer function is not working this is just a quick fix + print_buffer(p_Buffer,1); //if the debug level is higher enough then print the new message + */ printf("%s\n",p_Buffer->message[p_Buffer->head]); } } + + + void print_buffer(buffer *p_Buffer, int number_of_messages_to_print){ int x=0; int i=0;