]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_dbuff.h
Added constructor, destructor and always_inline attributes to the uLUt definitions.
[ulut.git] / ulut / ul_dbuff.h
1 /*******************************************************************
2   uLan Utilities Library - C library of basic reusable constructions
3
4   ul_dbuff.c    - dynamic buffer
5
6   (C) Copyright 2001-2004 by Pavel Pisa - Originator
7   (C) Copyright 2003-2004 by Frantisek Vacek - Originator
8
9   The uLan utilities library can be used, copied and modified under
10   next licenses
11     - GPL - GNU General Public License
12     - LGPL - GNU Lesser General Public License
13     - MPL - Mozilla Public License
14     - and other licenses added by project originators
15   Code can be modified and re-distributed under any combination
16   of the above listed licenses. If contributor does not agree with
17   some of the licenses, he/she can delete appropriate line.
18   Warning, if you delete all lines, you are not allowed to
19   distribute source code and/or binaries utilizing code.
20   
21   See files COPYING and README for details.
22
23  *******************************************************************/
24
25 #ifndef _UL_DBUFF_H
26 #define _UL_DBUFF_H
27
28 #include "ul_utdefs.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #define UL_DBUFF_SLEN 8
35
36 #define UL_DBUFF_IS_STATIC 1 
37 /* use only sbuf or reserved data space (no dynamic allocation) */
38
39 /**
40  * struct ul_dbuff - Generic Buffer for Dynamic Data
41  * @len:        actual length of stored data
42  * @capacity:   capacity of allocated buffer
43  * @flags:      only one flag (%UL_DBUFF_IS_STATIC) used now
44  * @data:       pointer to dynamically allocated buffer
45  * @sbuff:      static buffer for small data sizes
46  */
47 typedef struct ul_dbuff {       /* generic buffer for dynamic data */
48   unsigned long len;            /* actual length of stored data */
49   unsigned long capacity;       /* capacity of allocated buffer */
50   int flags;                /* only one flag (UL_DBUFF_IS_STATIC) exists*/
51   unsigned char *data;          /* pointer to dynamically allocated buffer */
52   unsigned char sbuff[UL_DBUFF_SLEN]; /* static buffer */
53 } ul_dbuff_t;
54
55 /* Basic routines */
56
57 int ul_dbuff_init(ul_dbuff_t *buf, int flags);
58 void ul_dbuff_destroy(ul_dbuff_t *buf);
59 int ul_dbuff_prep(ul_dbuff_t *buf, int new_len);
60
61 /* Extended set of routines */
62
63 int ul_dbuff_set_capacity(ul_dbuff_t *buf, int new_capacity);
64 int ul_dbuff_set_len(ul_dbuff_t *buf, int new_len);
65 int ul_dbuff_set(ul_dbuff_t *buf, unsigned char b, int len);
66 int ul_dbuff_cpy(ul_dbuff_t *buf, const void *b, int len);
67 int ul_dbuff_cat(ul_dbuff_t *buf, const void *b, int len);
68 int ul_dbuff_pos(const ul_dbuff_t *buf, unsigned char what, unsigned char quote);
69 int ul_dbuff_strcpy(ul_dbuff_t *buf, const char *str);
70 int ul_dbuff_strcat(ul_dbuff_t *buf, const char *str);
71 int ul_dbuff_append_byte(ul_dbuff_t *buf, unsigned char b);
72 int ul_dbuff_export(ul_dbuff_t *srcdb, void *dest, int maxlen);
73
74 void ul_dbuff_cut_pos(ul_dbuff_t *fromdb, ul_dbuff_t *todb, int n);
75 void ul_dbuff_cut_delimited(ul_dbuff_t *fromdb, ul_dbuff_t *todb, char delimiter, char quote);
76 void ul_dbuff_cut_token(ul_dbuff_t *fromdb, ul_dbuff_t *todb);
77
78 /*
79  * ul_dbuff_ltrim - removes all white spaces from left of dbuff.
80  *
81  * Return Value: new len of dbuff (including terminating zero, if present)
82  */
83 int ul_dbuff_ltrim(ul_dbuff_t *buf);
84 /*
85  * ul_dbuff_rtrim - removes all white spaces from right of dbuff.
86  *                  If dbuff is zero terminated, trimmed dbuff is also zero terminated
87  *
88  * Return Value: new len of dbuff (including terminating zero, if present)
89  */
90 int ul_dbuff_rtrim(ul_dbuff_t *buf);
91 /*
92  * ul_dbuff_trim - removes all white spaces from left and right of dbuff.
93  *                 If dbuff is zero terminated, trimmed dbuff is also zero terminated
94  *
95  * Return Value: new len of dbuff (including terminating zero, if present)
96  */
97 int ul_dbuff_trim(ul_dbuff_t *buf);
98
99 void ul_dbuff_log_hex(ul_dbuff_t *buf, int log_level);
100
101 int ul_str_pos(const unsigned char *str, const unsigned char *what, unsigned char quote);
102 int ul_str_cpos(const unsigned char *str, unsigned char what, unsigned char quote);
103 int ul_str_ncpy(unsigned char *to, const unsigned char *from, int buff_size);
104
105 #ifdef __cplusplus
106 } /* extern "C"*/
107 #endif
108
109 #endif /* _UL_DBUFF_H */