Debian Codegraph @

plugins/symbolbrowser/symbols/parsers/vstring.h

raw symbols SCIP
1 /***************************************************************************
2 A SymbolBrowser plugin for JuffEd editor.
3
4 Copyright: 2010 Aleksander Sokoloff <[email protected]>
5
6 Some of the code based on a ctags project http://ctags.sourceforge.net/
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License.
10 version 2 as published by the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 ***************************************************************************/
21
22
23 #ifndef _VSTRING_H
24 #define _VSTRING_H
25
26 /*
27 * INCLUDE FILES
28 */
29 //#include "general.h" /* must always come first */
30 #include <assert.h>
31 #include <QString>
32 #include <QDebug>
33
34 typedef bool boolean;
35
36 #if defined(HAVE_STDLIB_H)
37 # include <stdlib.h> /* to define size_t */
38 #endif
39
40 /*
41 * MACROS
42 */
43
44
45 /***********************
46 ***********************/
47 #ifdef DEBUG
48 #include <assert.h>
49 # define debug(level) ((Option.debugLevel & (long)(level)) != 0)
50 # define DebugStatement(x) x
51 # define PrintStatus(x) if (debug(DEBUG_STATUS)) printf x;
52 # define Assert(c) assert(c)
53 # define verbose(format, ...) fprintf(stderr, __VA_ARGS__)
54 #else
55 # define DebugStatement(x)
56 # define PrintStatus(x)
57 # define Assert(c)
58 # define verbose(format, ...)
59 # ifndef NDEBUG
60 # define NDEBUG
61 # endif
62 #endif
63
64
65 #define xMalloc(n,Type) (Type *)eMalloc((size_t)(n) * sizeof (Type))
66 #define xCalloc(n,Type) (Type *)eCalloc((size_t)(n), sizeof (Type))
67 #define xRealloc(p,n,Type) (Type *)eRealloc((p), (n) * sizeof (Type))
68
69
70 #ifndef DEBUG
71 # define VSTRING_PUTC_MACRO 1
72 #endif
73 #ifdef VSTRING_PUTC_MACRO
74 #define vStringPut(s,c) \
75 (void)(((s)->length + 1 == (s)->size ? vStringAutoResize (s) : 0), \
76 ((s)->buffer [(s)->length] = (c)), \
77 ((c) == '\0' ? 0 : ((s)->buffer [++(s)->length] = '\0')))
78 #endif
79
80 #define vStringValue(vs) ((vs)->buffer)
81 #define vStringItem(vs,i) ((vs)->buffer[i])
82 #define vStringLast(vs) ((vs)->buffer[(vs)->length - 1])
83 #define vStringLength(vs) ((vs)->length)
84 #define vStringSize(vs) ((vs)->size)
85 #define vStringCat(vs,s) vStringCatS((vs), vStringValue((s)))
86 #define vStringNCat(vs,s,l) vStringNCatS((vs), vStringValue((s)), (l))
87 #define vStringCopy(vs,s) vStringCopyS((vs), vStringValue((s)))
88 #define vStringNCopy(vs,s,l) vStringNCopyS((vs), vStringValue((s)), (l))
89 #define vStringChar(vs,i) ((vs)->buffer[i])
90 #define vStringTerminate(vs) vStringPut(vs, '\0')
91 #define vStringLower(vs) toLowerString((vs)->buffer)
92 #define vStringUpper(vs) toUpperString((vs)->buffer)
93
94 /*
95 * DATA DECLARATIONS
96 */
97
98 typedef struct sVString {
99 size_t length; /* size of buffer used */
100 size_t size; /* allocated size of buffer */
101 char *buffer; /* location of buffer */
102 } vString;
103
104 /*
105 * FUNCTION PROTOTYPES
106 */
107 extern boolean vStringAutoResize (vString *const string);
108 extern void vStringClear (vString *const string);
109 extern vString *vStringNew (void);
110 extern void vStringDelete (vString *const string);
111 #ifndef VSTRING_PUTC_MACRO
112 extern void vStringPut (vString *const string, const int c);
113 #endif
114 extern void vStringStripNewline (vString *const string);
115 extern void vStringStripLeading (vString *const string);
116 extern void vStringChop (vString *const string);
117 extern void vStringStripTrailing (vString *const string);
118 extern void vStringCatS (vString *const string, const char *const s);
119 extern void vStringNCatS (vString *const string, const char *const s, const size_t length);
120 extern vString *vStringNewCopy (const vString *const string);
121 extern vString *vStringNewInit (const char *const s);
122 extern void vStringCopyS (vString *const string, const char *const s);
123 extern void vStringNCopyS (vString *const string, const char *const s, const size_t length);
124 extern void vStringCopyToLower (vString *const dest, const vString *const src);
125 extern void vStringSetLength (vString *const string);
126
127 extern QString vStringToQString(const vString *const string);
128
129
130
131
132 /* Memory allocation functions */
133 #ifdef NEED_PROTO_MALLOC
134 extern void *malloc (size_t);
135 extern void *realloc (void *ptr, size_t);
136 #endif
137 extern void *eMalloc (const size_t size);
138 extern void *eCalloc (const size_t count, const size_t size);
139 extern void *eRealloc (void *const ptr, const size_t size);
140 extern void eFree (void *const ptr);
141
142
143 QDebug& operator<< (QDebug &debug, const vString *v);
144
145
146
147
148 #endif /* _VSTRING_H */
149
150