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