"Fossies" - the Fresh Open Source Software Archive

Member "mlr-5.6.2/c/containers/rslls.c" (25 Aug 2019, 2405 Bytes) of package /linux/misc/mlr-5.6.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rslls.c" see the Fossies "Dox" file reference documentation.

    1 #include <string.h>
    2 #include <stdlib.h>
    3 #include "lib/mlrutil.h"
    4 #include "containers/rslls.h"
    5 
    6 // ----------------------------------------------------------------
    7 rslls_t* rslls_alloc() {
    8     rslls_t* plist = mlr_malloc_or_die(sizeof(rslls_t));
    9     plist->phead  = NULL;
   10     plist->ptail  = NULL;
   11     plist->length = 0;
   12     return plist;
   13 }
   14 
   15 // ----------------------------------------------------------------
   16 void rslls_reset(rslls_t* plist) {
   17     if (plist == NULL)
   18         return;
   19     if (plist->phead == NULL)
   20         return;
   21     rsllse_t* pnode = plist->phead;
   22     while (pnode != NULL) {
   23         if (pnode->free_flag & FREE_ENTRY_VALUE)
   24             free(pnode->value);
   25         pnode->value = NULL;
   26         pnode = pnode->pnext;
   27     }
   28     plist->ptail = plist->phead;
   29     plist->length = 0;
   30 }
   31 
   32 // ----------------------------------------------------------------
   33 void rslls_free(rslls_t* plist) {
   34     if (plist == NULL)
   35         return;
   36     rsllse_t* pnode = plist->phead;
   37     while (pnode != NULL) {
   38         rsllse_t* pdel = pnode;
   39         pnode = pnode->pnext;
   40         if (pdel->free_flag & FREE_ENTRY_VALUE)
   41             free(pdel->value);
   42         free(pdel);
   43     }
   44     plist->phead  = NULL;
   45     plist->ptail  = 0;
   46     plist->length = 0;
   47     free(plist);
   48 }
   49 
   50 // ----------------------------------------------------------------
   51 void rslls_append(rslls_t* plist, char* value, char free_flag, char quote_flag) {
   52     if (plist->ptail == NULL) {
   53         // First add on new list
   54         rsllse_t* pnode = mlr_malloc_or_die(sizeof(rsllse_t));
   55         pnode->value = value;
   56         pnode->free_flag = free_flag;
   57         pnode->quote_flag = quote_flag;
   58         pnode->pnext = NULL;
   59         plist->phead = pnode;
   60         plist->ptail = pnode;
   61     } else if (plist->ptail->value == NULL) {
   62         // Subsequent add on reused list
   63         plist->ptail->value = value;
   64         plist->ptail->free_flag = free_flag;
   65         plist->ptail->quote_flag = quote_flag;
   66         if (plist->ptail->pnext != NULL)
   67             plist->ptail = plist->ptail->pnext;
   68     } else {
   69         // Append at end of list
   70         rsllse_t* pnode = mlr_malloc_or_die(sizeof(rsllse_t));
   71         pnode->value = value;
   72         pnode->free_flag = free_flag;
   73         pnode->quote_flag = quote_flag;
   74         pnode->pnext = NULL;
   75         plist->ptail->pnext = pnode;
   76         plist->ptail = pnode;
   77     }
   78     plist->length++;
   79 }
   80 
   81 void rslls_print(rslls_t* plist) {
   82     if (plist == NULL) {
   83         printf("NULL");
   84     } else {
   85         unsigned long long i = 0;
   86         for (rsllse_t* pe = plist->phead; pe != NULL; pe = pe->pnext, i++) {
   87             if (i > 0)
   88                 printf(",");
   89             if (pe->value == NULL)
   90                 printf("NULL");
   91             else
   92                 printf("%s", pe->value);
   93         }
   94     }
   95 }