#include #include #include "buf.h" #include "buf_misc.h" #include "debug.h" void blow_if_error(int err) { if (err < 0) { printf("Should be no error but there is\n"); exit(1); } } //#define B(X) PNL();blow_if_error(X); #define B(X) blow_if_error(X); void error_is_good(int err) { if (err >= 0) { printf("Should be error but there is no\n"); exit(1); } } #define E(X) error_is_good(X); int main() { bbuf_circ *bc=NULL; bbuf *b1=NULL; char ch; int i; B(bbuf_circ_new(&bc, 8)); bbuf_print(bc->buf); printf("\r\n"); B(bbuf_circ_put(bc, 'A')); bbuf_print(bc->buf); printf("\r\n"); B(bbuf_circ_put(bc, 'B')); bbuf_print(bc->buf); printf("\r\n"); B(bbuf_circ_put(bc, 'C')); B(bbuf_circ_put(bc, 'D')); B(bbuf_circ_put(bc, 'E')); B(bbuf_circ_put(bc, 'F')); B(bbuf_circ_put(bc, 'G')); B(bbuf_circ_put(bc, 'H')); bbuf_print(bc->buf); printf("\r\n"); B(bbuf_circ_put(bc, 'I')); bbuf_print(bc->buf); printf("\r\n"); B(bbuf_circ_reset(bc)); E(bbuf_circ_get(bc, &ch)); B(bbuf_circ_put(bc, 'M')); B(bbuf_circ_put(bc, 'O')); B(bbuf_circ_put(bc, 'S')); B(bbuf_circ_put(bc, 'S')); B(bbuf_circ_put(bc, 'A')); B(bbuf_circ_put(bc, 'D')); for (i=0;i<10;i++) { if (0 == bbuf_circ_get(bc, &ch)) { printf("%c",ch); } } printf("\r\n"); bbuf_circ_reset(bc); char name1[] = "FREDOME"; b1 = bbuf_new(strlen(name1)); bbuf_set(b1, name1, strlen(name1)); bbuf_print(b1); printf("\r\n"); printf("Added =%d\r\n",bbuf_circ_add(bc, b1)); for (i=0;i<10;i++) { if (0 == bbuf_circ_get(bc, &ch)) { printf("!%c",ch); } } printf("\r\n"); bbuf_circ_free(bc); bbuf_free(b1); return 0; }