src/dllist.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  dllist_node_t
struct  dllist_t

Typedefs

typedef dllist_node_t dllist_node
typedef dllist_t dllist

Functions

dllistdllist_create_list ()
dllist_nodedllist_create_node (void *data)
int dllist_destroy_list (dllist *ddlist)
void * dllist_destroy_node (dllist_node *node)
void dllist_insert_after (dllist *dllist, dllist_node *node, dllist_node *newnode)
void dllist_insert_before (dllist *dllist, dllist_node *node, dllist_node *newnode)
void dllist_insert_beginning (dllist *dllist, dllist_node *newnode)
void dllist_insert_end (dllist *dllist, dllist_node *newnode)
void * dllist_remove (dllist *dllist, dllist_node *node)
void * dllist_remove_node_at_pos (dllist *dllist, int pos)
dllist_nodedllist_head (dllist *dllist)
dllist_nodedllist_tail (dllist *dllist)
dllist_nodedllist_next (dllist_node *node)
dllist_nodedllist_prev (dllist_node *node)
void * dllist_data (dllist_node *node)
int dllist_size (dllist *dllist)
void * dllist_get_node (dllist *dllist, int pos)


Typedef Documentation

typedef struct dllist_t dllist

typedef struct dllist_node_t dllist_node


Function Documentation

dllist* dllist_create_list (  ) 

Definition at line 12 of file dllist.c.

Referenced by auto_astar_generate_path(), auto_load_commands(), auto_newautopilot(), and load_autopilot_data().

00013 {
00014 
00015     dllist *temp;
00016 
00017     temp = malloc(sizeof(dllist));
00018     if (temp == NULL) {
00019         return NULL;
00020     }
00021 
00022     memset(temp, 0, sizeof(temp));
00023     temp->head = NULL;
00024     temp->tail = NULL;
00025     temp->size = 0;
00026 
00027     return temp;
00028 }

dllist_node* dllist_create_node ( void *  data  ) 

Definition at line 31 of file dllist.c.

References dllist_node_t::data, dllist_node_t::next, and dllist_node_t::prev.

Referenced by auto_addcommand(), auto_astar_generate_path(), and auto_load_commands().

00032 {
00033 
00034     dllist_node *temp;
00035 
00036     temp = malloc(sizeof(dllist_node));
00037     if (temp == NULL) {
00038         return NULL;
00039     }
00040 
00041     memset(temp, 0, sizeof(dllist_node));
00042     temp->prev = NULL;
00043     temp->next = NULL;
00044     temp->data = data;
00045 
00046     return temp;
00047 }

void* dllist_data ( dllist_node node  ) 

Definition at line 320 of file dllist.c.

References dllist_node_t::data.

Referenced by dllist_get_node().

00321 {
00322 
00323     if (!node)
00324         return NULL;
00325 
00326     return node->data;
00327 }

int dllist_destroy_list ( dllist ddlist  ) 

Definition at line 50 of file dllist.c.

References dllist_t::head, dllist_t::size, and dllist_t::tail.

Referenced by auto_destroy_astar_path(), auto_destroy_weaplist(), auto_newautopilot(), and newfreemech().

00051 {
00052 
00053     if (!dllist)
00054         return 1;
00055 
00056     /* Check the size */
00057     if (dllist->size != 0) {
00058         return 0;
00059     } else {
00060         dllist->head = NULL;
00061         dllist->tail = NULL;
00062         free(dllist);
00063         return 1;
00064     }
00065 
00066 }

void* dllist_destroy_node ( dllist_node node  ) 

Definition at line 69 of file dllist.c.

References dllist_node_t::data, dllist_node_t::next, and dllist_node_t::prev.

Referenced by dllist_remove().

00070 {
00071 
00072     void *data;
00073 
00074     if (!node)
00075         return NULL;
00076 
00077     data = node->data;
00078     node->prev = NULL;
00079     node->next = NULL;
00080     node->data = NULL;
00081     free(node);
00082 
00083     return data;
00084 
00085 }

void* dllist_get_node ( dllist dllist,
int  pos 
)

Definition at line 341 of file dllist.c.

References dllist_data(), dllist_head(), dllist_next(), and dllist_size().

Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_astar_roam_event(), auto_get_command_arg(), auto_get_command_enum(), auto_listcommands(), and auto_save_commands().

00342 {
00343 
00344     int counter = 1;
00345     dllist_node *temp;
00346 
00347     if (!dllist) {
00348         return NULL;
00349     }
00350 
00351     if (dllist_size(dllist) < pos) {
00352         return NULL;
00353     }
00354 
00355     if (pos < counter) {
00356         return NULL;
00357     }
00358 
00359     /* Start at the head */
00360     temp = dllist_head(dllist);
00361 
00362     while (counter != pos) {
00363 
00364         temp = dllist_next(temp);
00365         counter++;
00366 
00367     }
00368 
00369     return dllist_data(temp);
00370 
00371 }

dllist_node* dllist_head ( dllist dllist  ) 

Definition at line 281 of file dllist.c.

References dllist_t::head.

Referenced by auto_delcommand(), auto_goto_next_command(), auto_newautopilot(), dllist_get_node(), dllist_remove_node_at_pos(), and newfreemech().

00282 {
00283 
00284     if (!dllist)
00285         return NULL;
00286 
00287     return dllist->head;
00288 }

void dllist_insert_after ( dllist dllist,
dllist_node node,
dllist_node newnode 
)

Definition at line 88 of file dllist.c.

References dllist_node_t::next, dllist_node_t::prev, dllist_t::size, and dllist_t::tail.

Referenced by dllist_insert_end().

00090 {
00091 
00092     /* Bad node to insert */
00093     if (!node) {
00094         return;
00095     }
00096 
00099     newnode->prev = node;
00100     newnode->next = node->next;
00101     if (node->next == NULL) {
00102         dllist->tail = newnode;
00103     } else {
00104         (node->next)->prev = newnode;
00105     }
00106     node->next = newnode;
00107 
00108     /* Increment */
00109     dllist->size++;
00110 
00111     return;
00112 }

void dllist_insert_before ( dllist dllist,
dllist_node node,
dllist_node newnode 
)

Definition at line 115 of file dllist.c.

References dllist_t::head, hlist_node::next, dllist_node_t::next, dllist_node_t::prev, and dllist_t::size.

Referenced by dllist_insert_beginning().

00117 {
00118 
00119     /* Bad node to insert */
00120     if (!node) {
00121         return;
00122     }
00123 
00126     newnode->prev = node->prev;
00127     newnode->next = node;
00128     if (node->prev == NULL) {
00129         dllist->head = newnode;
00130     } else {
00131         (node->prev)->next = newnode;
00132     }
00133     node->prev = newnode;
00134 
00135     /* Increment */
00136     dllist->size++;
00137 
00138     return;
00139 }

void dllist_insert_beginning ( dllist dllist,
dllist_node newnode 
)

Definition at line 142 of file dllist.c.

References dllist_insert_before(), dllist_t::head, dllist_node_t::next, dllist_node_t::prev, dllist_t::size, and dllist_t::tail.

Referenced by auto_astar_generate_path(), and dllist_insert_end().

00143 {
00144 
00145     /* Bad node to insert */
00146     if (!newnode) {
00147         return;
00148     }
00149 
00152     /* If there is no head it means empty list */
00153     if (dllist->head == NULL) {
00154         dllist->head = newnode;
00155         dllist->tail = newnode;
00156         newnode->prev = NULL;
00157         newnode->next = NULL;
00158 
00159         /* Increment */
00160         dllist->size++;
00161 
00162     } else {
00163         dllist_insert_before(dllist, dllist->head, newnode);
00164     }
00165 
00166     return;
00167 }

void dllist_insert_end ( dllist dllist,
dllist_node newnode 
)

Definition at line 170 of file dllist.c.

References dllist_insert_after(), dllist_insert_beginning(), and dllist_t::tail.

Referenced by auto_addcommand(), and auto_load_commands().

00171 {
00172 
00173     /* Bad node to insert */
00174     if (!newnode) {
00175         return;
00176     }
00177 
00180     /* If there is no tail means empty list */
00181     if (dllist->tail == NULL) {
00182         dllist_insert_beginning(dllist, newnode);
00183     } else {
00184         dllist_insert_after(dllist, dllist->tail, newnode);
00185     }
00186 
00187     return;
00188 
00189 }

dllist_node* dllist_next ( dllist_node node  ) 

Definition at line 301 of file dllist.c.

References dllist_node_t::next.

Referenced by dllist_get_node(), and dllist_remove_node_at_pos().

00302 {
00303 
00304     if (!node)
00305         return NULL;
00306 
00307     return node->next;
00308 }

dllist_node* dllist_prev ( dllist_node node  ) 

Definition at line 311 of file dllist.c.

References dllist_node_t::prev.

00312 {
00313     if (!node)
00314         return NULL;
00315 
00316     return node->prev;
00317 }

void* dllist_remove ( dllist dllist,
dllist_node node 
)

Definition at line 192 of file dllist.c.

References dllist_destroy_node(), dllist_t::head, hlist_node::next, dllist_node_t::next, dllist_node_t::prev, dllist_t::size, and dllist_t::tail.

Referenced by auto_delcommand(), auto_goto_next_command(), auto_newautopilot(), dllist_remove_node_at_pos(), and newfreemech().

00193 {
00194 
00195     void *data;
00196 
00197     /* Invalid node? */
00198     if (!node) {
00199         return NULL;
00200     }
00201 
00202     /* Invalid list? */
00203     if (!dllist) {
00204 
00205         /* Try and return the data */
00206         data = dllist_destroy_node(node);
00207         return data;
00208     }
00209 
00213     /* Somehow the list has nothing in it yet it thinks it does */
00214     if (dllist->head == NULL && dllist->tail == NULL) {
00215 
00216         /* Try and return the data */
00217         data = dllist_destroy_node(node);
00218         return data;
00219     }
00220 
00221     /* We're checking if this first node */
00222     if (node->prev == NULL) {
00223         dllist->head = node->next;
00224     } else {
00225         (node->prev)->next = node->next;
00226     }
00227 
00228     /* Check if end of list */
00229     if (node->next == NULL) {
00230         dllist->tail = node->prev;
00231     } else {
00232         (node->next)->prev = node->prev;
00233     }
00234 
00235     /* Destroy Node */
00236     data = dllist_destroy_node(node);
00237 
00238     /* De-Increment */
00239     dllist->size--;
00240 
00241     return data;
00242 
00243 }

void* dllist_remove_node_at_pos ( dllist dllist,
int  pos 
)

Definition at line 246 of file dllist.c.

References dllist_head(), dllist_next(), dllist_remove(), and dllist_size().

Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_astar_roam_event(), auto_delcommand(), auto_destroy_astar_path(), and auto_destroy_weaplist().

00247 {
00248 
00249     int counter = 1;
00250     dllist_node *temp;
00251     void *data;
00252 
00253     if (!dllist) {
00254         return NULL;
00255     }
00256 
00257     if (dllist_size(dllist) < pos) {
00258         return NULL;
00259     }
00260 
00261     /* Start at the head */
00262     temp = dllist_head(dllist);
00263 
00264     while (counter != pos) {
00265 
00266         temp = dllist_next(temp);
00267         counter++;
00268 
00269     }
00270 
00271     /* Remove the node */
00272     data = dllist_remove(dllist, temp);
00273 
00274     return data;
00275 
00276 }

int dllist_size ( dllist dllist  ) 

Definition at line 330 of file dllist.c.

References dllist_t::size.

Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_astar_roam_event(), auto_delcommand(), auto_destroy_astar_path(), auto_destroy_weaplist(), auto_get_command_arg(), auto_get_command_enum(), auto_goto_next_command(), auto_listcommands(), auto_newautopilot(), auto_save_commands(), dllist_get_node(), dllist_remove_node_at_pos(), and newfreemech().

00331 {
00332 
00333     if (!dllist) {
00334         return 0;
00335     }
00336 
00337     return dllist->size;
00338 }

dllist_node* dllist_tail ( dllist dllist  ) 

Definition at line 291 of file dllist.c.

References dllist_t::tail.

00292 {
00293     
00294     if (!dllist)
00295         return NULL;
00296 
00297     return dllist->tail;
00298 }


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