misc/myfifo.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "myfifo.h"

Include dependency graph for myfifo.c:

Go to the source code of this file.

Defines

#define PFOO   (*foo)

Functions

void check_fifo (myfifo **foo)
int myfifo_length (myfifo **foo)
void * myfifo_pop (myfifo **foo)
void myfifo_push (myfifo **foo, void *data)
void myfifo_trav (myfifo **foo, void(*func)())
void myfifo_trav_r (myfifo **foo, void(*func)())


Define Documentation

#define PFOO   (*foo)

Definition at line 21 of file myfifo.c.

Referenced by check_fifo(), myfifo_length(), myfifo_pop(), myfifo_push(), myfifo_trav(), and myfifo_trav_r().


Function Documentation

void check_fifo ( myfifo **  foo  ) 

Definition at line 23 of file myfifo.c.

References PFOO.

Referenced by myfifo_length(), myfifo_pop(), myfifo_push(), myfifo_trav(), and myfifo_trav_r().

00024 {
00025     if (PFOO == NULL) {
00026         PFOO = (myfifo *) malloc(sizeof(myfifo));
00027         PFOO->first = NULL;
00028         PFOO->last = NULL;
00029         PFOO->count = 0;
00030     }
00031 }

int myfifo_length ( myfifo **  foo  ) 

Definition at line 33 of file myfifo.c.

References check_fifo(), and PFOO.

00034 {
00035     check_fifo(foo);
00036     return PFOO->count;
00037 }

void* myfifo_pop ( myfifo **  foo  ) 

Definition at line 39 of file myfifo.c.

References check_fifo(), myfifo_entry_struct::data, myfifo_entry_struct::next, PFOO, and myfifo_entry_struct::prev.

00040 {
00041     void *tmpd;
00042     myfifo_e *tmp;
00043 
00044     check_fifo(foo);
00045     tmp = PFOO->last;
00046     /* Is the list empty? */
00047     if (tmp != NULL) {
00048         /* Are we removeing the only element? */
00049         if (PFOO->first == PFOO->last) {
00050             PFOO->first = NULL;
00051             PFOO->last = NULL;
00052         } else
00053             tmp->prev->next = NULL;
00054         PFOO->last = tmp->prev;
00055         /* Are we going down to only one element? */
00056         if (PFOO->last->prev == NULL)
00057             PFOO->first = PFOO->last;
00058         PFOO->count--;
00059         tmpd = tmp->data;
00060         free(tmp);
00061         return tmpd;
00062     } else
00063         return NULL;
00064 }

void myfifo_push ( myfifo **  foo,
void *  data 
)

Definition at line 66 of file myfifo.c.

References check_fifo(), myfifo_entry_struct::data, myfifo_entry_struct::next, PFOO, and myfifo_entry_struct::prev.

00067 {
00068     myfifo_e *tmp;
00069 
00070     check_fifo(foo);
00071     tmp = (myfifo_e *) malloc(sizeof(myfifo_e));
00072     tmp->data = data;
00073     tmp->next = PFOO->first;
00074     tmp->prev = NULL;
00075     PFOO->count++;
00076     if (PFOO->first == NULL) {
00077         PFOO->first = tmp;
00078         PFOO->last = tmp;
00079     } else
00080         PFOO->first->prev = tmp;
00081     PFOO->first = tmp;
00082 }

void myfifo_trav ( myfifo **  foo,
void(*)()  func 
)

Definition at line 84 of file myfifo.c.

References check_fifo(), myfifo_entry_struct::data, myfifo_entry_struct::next, and PFOO.

00085 {
00086     myfifo_e *tmp;
00087 
00088     check_fifo(foo);
00089     for (tmp = PFOO->first; tmp != NULL; tmp = tmp->next)
00090         func(tmp->data);
00091 }

void myfifo_trav_r ( myfifo **  foo,
void(*)()  func 
)

Definition at line 93 of file myfifo.c.

References check_fifo(), myfifo_entry_struct::data, PFOO, and myfifo_entry_struct::prev.

00094 {
00095     myfifo_e *tmp;
00096 
00097     check_fifo(foo);
00098     for (tmp = PFOO->last; tmp != NULL; tmp = tmp->prev)
00099         func(tmp->data);
00100 }


Generated on Mon May 28 04:25:26 2007 for BattletechMUX by  doxygen 1.4.7