1/* src/interfaces/ecpg/preproc/util.c */
13 * Handle preprocessor errors and warnings
18 /* localize the error message string */
37 /* If appropriate, set error code to be inspected by ecpg.c */
48/* Report an error or warning */
59/* Report an error and abandon execution */
80 * Basic memory management support
83/* malloc + error check */
95/* strdup + error check */
99 char *
new = strdup(
string);
109 * "Local" memory management support
111 * These functions manage memory that is only needed for a short time
112 * (processing of one input statement) within the ecpg grammar.
113 * Data allocated with these is not meant to be freed separately;
114 * rather it's freed by calling reclaim_local_storage() at the end
115 * of each statement cycle.
121 unsigned int chunk_used;
/* index of first unused byte in data[] */
126 #define LOC_CHUNK_OVERHEAD MAXALIGN(offsetof(loc_chunk, data))
127 #define LOC_CHUNK_MIN_SIZE 8192
129/* Head of list of loc_chunks */
133 * Allocate local space of the requested size.
143 /* Ensure all allocations are adequately aligned */
146 /* Need a new chunk? */
147 if (cur_chunk == NULL || size > cur_chunk->
chunk_avail)
152 /* Depending on alignment rules, we could waste a bit here */
155 /* New chunk becomes the head of the list */
167 * Copy given string into local storage
172 char *result =
loc_alloc(strlen(
string) + 1);
174 strcpy(result,
string);
179 * Reclaim local storage when appropriate
187 for (cur_chunk =
loc_chunks; cur_chunk; cur_chunk = next_chunk)
189 next_chunk = cur_chunk->
next;
197 * String concatenation support routines. These return "local" (transient)
202 * Concatenate 2 strings, inserting a space between them unless either is empty
207 char *res_str = (
char *)
loc_alloc(strlen(str1) + strlen(str2) + 2);
209 strcpy(res_str, str1);
210 if (strlen(str1) != 0 && strlen(str2) != 0)
211 strcat(res_str,
" ");
212 strcat(res_str, str2);
217 * Concatenate N strings, inserting spaces between them unless they are empty
226 va_start(
args, count);
228 res_str = va_arg(
args,
char *);
230 /* now add all other strings */
231 for (
i = 1;
i < count;
i++)
240 * Concatenate 2 strings, with no space between
245 char *res_str = (
char *)
loc_alloc(strlen(str1) + strlen(str2) + 1);
247 strcpy(res_str, str1);
248 strcat(res_str, str2);
253 * Concatenate 3 strings, with no space between
256 make3_str(
const char *str1,
const char *str2,
const char *str3)
258 char *res_str = (
char *)
loc_alloc(strlen(str1) + strlen(str2) + strlen(str3) + 1);
260 strcpy(res_str, str1);
261 strcat(res_str, str2);
262 strcat(res_str, str3);
#define pg_attribute_printf(f, a)
#define FLEXIBLE_ARRAY_MEMBER
#define fprintf(file, fmt, msg)
void mmfatal(int error_code, const char *error,...)
void * loc_alloc(size_t size)
#define LOC_CHUNK_OVERHEAD
static void vmmerror(int error_code, enum errortype type, const char *error, va_list ap) pg_attribute_printf(3
char * mm_strdup(const char *string)
struct loc_chunk loc_chunk
char * cat_str(int count,...)
static loc_chunk * loc_chunks
char * cat2_str(const char *str1, const char *str2)
void * mm_alloc(size_t size)
char * make3_str(const char *str1, const char *str2, const char *str3)
void reclaim_local_storage(void)
void mmerror(int error_code, enum errortype type, const char *error,...)
char * loc_strdup(const char *string)
#define LOC_CHUNK_MIN_SIZE
char * make2_str(const char *str1, const char *str2)
char data[FLEXIBLE_ARRAY_MEMBER]