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