src/stringlist.h
author Krista Grothoff <krista@pep-project.org>
Mon, 11 Jul 2016 09:07:31 +0200
changeset 826 51b1d46df1ae
parent 523 afaf34a57cc6
child 836 8e7dac747b49
permissions -rw-r--r--
Added caveat for explicit next NULL in new_stringlist
     1 #pragma once
     2 
     3 #include "dynamic_api.h"
     4 
     5 #ifdef __cplusplus
     6 extern "C" {
     7 #endif
     8 
     9 
    10 typedef struct _stringlist_t {
    11     char *value;
    12     struct _stringlist_t *next;
    13 } stringlist_t;
    14 
    15 
    16 // new_stringlist() - allocate a new stringlist
    17 //
    18 //  parameters:
    19 //      value (in)        initial value as C string or NULL for empty list
    20 //
    21 //  return value:
    22 //      pointer to stringlist_t object or NULL if out of memory
    23 //
    24 //  caveat:
    25 //      the value is being copied before being added to the list
    26 //      the original string is still being owned by the caller
    27 //      the "next" pointer of the returned object is explicitly set to NULL
    28 
    29 DYNAMIC_API stringlist_t *new_stringlist(const char *value);
    30 
    31 
    32 // stringlist_dup() - duplicate a stringlist
    33 //
    34 //  parameters:
    35 //      src (in)            stringlist to copy
    36 //
    37 //  return value:
    38 //      pointer to stringlist_t object or NULL if out of memory
    39 
    40 DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
    41 
    42 
    43 // stringlist_add() - add key to stringlist
    44 //
    45 //  parameters:
    46 //      stringlist (in)     stringlist struct or NULL to create a new one
    47 //      value (in)          value as C string
    48 //
    49 //  return value:
    50 //      pointer to last element in stringlist or NULL if out of memory
    51 //
    52 //  caveat:
    53 //      the value is being copied before being added to the list
    54 //      the original string is still being owned by the caller
    55 
    56 DYNAMIC_API stringlist_t *stringlist_add(
    57         stringlist_t *stringlist,
    58         const char *value
    59     );
    60 
    61 
    62 // stringlist_append() - append stringlist to stringlist
    63 //
    64 //  parameters:
    65 //      stringlist (in)     stringlist struct to append to
    66 //      second (in)         stringlist struct to append
    67 //
    68 //  return value:
    69 //      pointer to last element in stringlist or NULL if out of memory
    70 //
    71 //  caveat:
    72 //      all values are being copied before being added to the list
    73 //      the original values are still being owned by the caller
    74 
    75 DYNAMIC_API stringlist_t *stringlist_append(
    76         stringlist_t *stringlist,
    77         stringlist_t *second
    78     );
    79 
    80 
    81 // stringlist_length() - get length of stringlist
    82 //
    83 //  parameters:
    84 //      stringlist (in)     stringlist struct to determine length of
    85 //
    86 //  return value:
    87 //      length of stringlist in number of elements
    88 
    89 DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
    90 
    91 
    92 // stringlist_delete() - delete entry from stringlist
    93 //
    94 //  parameters:
    95 //      stringlist (in)     stringlist struct to delete from
    96 //      value (in)          data to delete
    97 //
    98 //  return value:
    99 //      modified stringlist
   100 
   101 DYNAMIC_API stringlist_t *stringlist_delete(
   102         stringlist_t *stringlist,
   103         const char *value
   104     );
   105 
   106 
   107 // free_stringlist() - free memory occupied by stringlist
   108 //
   109 //  parameters:
   110 //      stringlist (in)    stringlist to free
   111 
   112 DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
   113 
   114 
   115 #ifdef __cplusplus
   116 }
   117 #endif
   118