src/stringlist.h
author Volker Birk <vb@pep-project.org>
Thu, 31 Mar 2016 14:01:45 +0200
changeset 523 afaf34a57cc6
parent 113 4bee48270834
child 826 51b1d46df1ae
permissions -rw-r--r--
delete from 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
vb@98
    27
vb@98
    28
DYNAMIC_API stringlist_t *new_stringlist(const char *value);
vb@98
    29
vb@98
    30
vb@98
    31
// stringlist_dup() - duplicate a stringlist
vb@98
    32
//
vb@98
    33
//  parameters:
vb@98
    34
//      src (in)            stringlist to copy
vb@98
    35
//
vb@98
    36
//  return value:
vb@98
    37
//      pointer to stringlist_t object or NULL if out of memory
vb@98
    38
vb@98
    39
DYNAMIC_API stringlist_t *stringlist_dup(const stringlist_t *src);
vb@98
    40
vb@98
    41
vb@98
    42
// stringlist_add() - add key to stringlist
vb@98
    43
//
vb@98
    44
//  parameters:
vb@98
    45
//      stringlist (in)     stringlist struct or NULL to create a new one
vb@98
    46
//      value (in)          value as C string
vb@98
    47
//
vb@98
    48
//  return value:
vb@98
    49
//      pointer to last element in stringlist or NULL if out of memory
vb@98
    50
//
vb@98
    51
//  caveat:
vb@98
    52
//      the value is being copied before being added to the list
vb@98
    53
//      the original string is still being owned by the caller
vb@98
    54
vb@113
    55
DYNAMIC_API stringlist_t *stringlist_add(
vb@113
    56
        stringlist_t *stringlist,
vb@113
    57
        const char *value
vb@113
    58
    );
vb@98
    59
vb@98
    60
vb@98
    61
// stringlist_append() - append stringlist to stringlist
vb@98
    62
//
vb@98
    63
//  parameters:
vb@98
    64
//      stringlist (in)     stringlist struct to append to
vb@98
    65
//      second (in)         stringlist struct to append
vb@98
    66
//
vb@98
    67
//  return value:
vb@98
    68
//      pointer to last element in stringlist or NULL if out of memory
vb@98
    69
//
vb@98
    70
//  caveat:
vb@98
    71
//      all values are being copied before being added to the list
vb@98
    72
//      the original values are still being owned by the caller
vb@98
    73
vb@113
    74
DYNAMIC_API stringlist_t *stringlist_append(
vb@113
    75
        stringlist_t *stringlist,
vb@113
    76
        stringlist_t *second
vb@113
    77
    );
vb@98
    78
vb@98
    79
vb@98
    80
// stringlist_length() - get length of stringlist
vb@98
    81
//
vb@98
    82
//  parameters:
vb@98
    83
//      stringlist (in)     stringlist struct to determine length of
vb@98
    84
//
vb@98
    85
//  return value:
vb@98
    86
//      length of stringlist in number of elements
vb@98
    87
vb@98
    88
DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
vb@98
    89
vb@98
    90
vb@523
    91
// stringlist_delete() - delete entry from stringlist
vb@523
    92
//
vb@523
    93
//  parameters:
vb@523
    94
//      stringlist (in)     stringlist struct to delete from
vb@523
    95
//      value (in)          data to delete
vb@523
    96
//
vb@523
    97
//  return value:
vb@523
    98
//      modified stringlist
vb@523
    99
vb@523
   100
DYNAMIC_API stringlist_t *stringlist_delete(
vb@523
   101
        stringlist_t *stringlist,
vb@523
   102
        const char *value
vb@523
   103
    );
vb@523
   104
vb@523
   105
vb@98
   106
// free_stringlist() - free memory occupied by stringlist
vb@98
   107
//
vb@98
   108
//  parameters:
vb@98
   109
//      stringlist (in)    stringlist to free
vb@98
   110
vb@98
   111
DYNAMIC_API void free_stringlist(stringlist_t *stringlist);
vb@98
   112
vb@98
   113
vb@98
   114
#ifdef __cplusplus
vb@98
   115
}
vb@98
   116
#endif
vb@98
   117