ARPDAS_QNX6 1.0
ll_of_str.c
Go to the documentation of this file.
00001 /* llos defines a linked list of strings type */
00002 #include "nortlib.h"
00003 #include "ll_of_str.h"
00004 char rcsid_ll_of_str_c[] =
00005   "$Header: /cvsroot/arp-das/nortlib2/src/ll_of_str.c,v 1.2 1998/01/06 18:28:50 nort Doc $";
00006 
00007 /*
00008 Functionality:
00009   void llos_enq(ll_of_str *ll, const char *str);
00010         duplicates str and places it on the list.
00011         Dies if memory allocation fails.
00012         Accepts NULL in either argument. ll==NULL does nothing.
00013         str == NULL gets mapped into empty string "".
00014   char *llos_deq(ll_of_str *ll);
00015         produces the duplicated string at the head of the list
00016         and deletes it from the list. The string should be
00017         freed (free_memory()) after it is used, since it was
00018         dynamically allocated when enqueued.
00019 
00020 Possible additional functionality: Iteration.
00021     init
00022         next (yielding first after init)
00023         insert_before
00024         insert_after
00025         delete
00026 */
00027 
00028 void llos_enq(ll_of_str *ll, const char *str) {
00029   char *s;
00030   struct llosleaf *lf;
00031 
00032   if (ll != 0) {
00033         { int resp = set_response(3);
00034           lf = new_memory( sizeof( struct llosleaf ) );
00035           if (str == 0) s = nl_strdup("");
00036           else s = nl_strdup(str);
00037           set_response(resp);
00038         }
00039         lf->text = s;
00040         lf->next = 0;
00041         if (ll->last == 0)
00042           ll->first = ll->last = lf;
00043         else {
00044           ll->last->next = lf;
00045           ll->last = lf;
00046         }
00047   }
00048 }
00049 
00050 char *llos_deq(ll_of_str *ll) {
00051   char *s;
00052   struct llosleaf *lf;
00053 
00054   if (ll == 0 || ll->first == 0) return 0;
00055   lf = ll->first;
00056   s = lf->text;
00057   ll->first = lf->next;
00058   if (ll->first == 0)
00059         ll->last = 0;
00060   free_memory(lf);
00061   return s;
00062 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines