|
Packit Service |
48484a |
/*
|
|
Packit Service |
48484a |
tre-stack.h: Stack definitions
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
Copyright (c) 2001-2006 Ville Laurikari <vl@iki.fi>
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
This library is free software; you can redistribute it and/or
|
|
Packit Service |
48484a |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
48484a |
License as published by the Free Software Foundation; either
|
|
Packit Service |
48484a |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
This library is distributed in the hope that it will be useful,
|
|
Packit Service |
48484a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
48484a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
48484a |
Lesser General Public License for more details.
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
48484a |
License along with this library; if not, write to the Free Software
|
|
Packit Service |
48484a |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
*/
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
#ifndef TRE_STACK_H
|
|
Packit Service |
48484a |
#define TRE_STACK_H 1
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
#include "regex.h"
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
typedef struct tre_stack_rec tre_stack_t;
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* Creates a new stack object. `size' is initial size in bytes, `max_size'
|
|
Packit Service |
48484a |
is maximum size, and `increment' specifies how much more space will be
|
|
Packit Service |
48484a |
allocated with realloc() if all space gets used up. Returns the stack
|
|
Packit Service |
48484a |
object or NULL if out of memory. */
|
|
Packit Service |
48484a |
tre_stack_t *
|
|
Packit Service |
48484a |
tre_stack_new(int size, int max_size, int increment);
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* Frees the stack object. */
|
|
Packit Service |
48484a |
void
|
|
Packit Service |
48484a |
tre_stack_destroy(tre_stack_t *s);
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* Returns the current number of objects in the stack. */
|
|
Packit Service |
48484a |
int
|
|
Packit Service |
48484a |
tre_stack_num_objects(tre_stack_t *s);
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* Each tre_stack_push_*(tre_stack_t *s, <type> value) function pushes
|
|
Packit Service |
48484a |
`value' on top of stack `s'. Returns REG_ESPACE if out of memory.
|
|
Packit Service |
48484a |
This tries to realloc() more space before failing if maximum size
|
|
Packit Service |
48484a |
has not yet been reached. Returns REG_OK if successful. */
|
|
Packit Service |
48484a |
#define declare_pushf(typetag, type) \
|
|
Packit Service |
48484a |
reg_errcode_t tre_stack_push_ ## typetag(tre_stack_t *s, type value)
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
declare_pushf(voidptr, void *);
|
|
Packit Service |
48484a |
declare_pushf(int, int);
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* Each tre_stack_pop_*(tre_stack_t *s) function pops the topmost
|
|
Packit Service |
48484a |
element off of stack `s' and returns it. The stack must not be
|
|
Packit Service |
48484a |
empty. */
|
|
Packit Service |
48484a |
#define declare_popf(typetag, type) \
|
|
Packit Service |
48484a |
type tre_stack_pop_ ## typetag(tre_stack_t *s)
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
declare_popf(voidptr, void *);
|
|
Packit Service |
48484a |
declare_popf(int, int);
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* Just to save some typing. */
|
|
Packit Service |
48484a |
#define STACK_PUSH(s, typetag, value) \
|
|
Packit Service |
48484a |
do \
|
|
Packit Service |
48484a |
{ \
|
|
Packit Service |
48484a |
status = tre_stack_push_ ## typetag(s, value); \
|
|
Packit Service |
48484a |
} \
|
|
Packit Service |
48484a |
while (0)
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
#define STACK_PUSHX(s, typetag, value) \
|
|
Packit Service |
48484a |
{ \
|
|
Packit Service |
48484a |
status = tre_stack_push_ ## typetag(s, value); \
|
|
Packit Service |
48484a |
if (status != REG_OK) \
|
|
Packit Service |
48484a |
break; \
|
|
Packit Service |
48484a |
}
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
#define STACK_PUSHR(s, typetag, value) \
|
|
Packit Service |
48484a |
{ \
|
|
Packit Service |
48484a |
reg_errcode_t _status; \
|
|
Packit Service |
48484a |
_status = tre_stack_push_ ## typetag(s, value); \
|
|
Packit Service |
48484a |
if (_status != REG_OK) \
|
|
Packit Service |
48484a |
return _status; \
|
|
Packit Service |
48484a |
}
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
#endif /* TRE_STACK_H */
|
|
Packit Service |
48484a |
|
|
Packit Service |
48484a |
/* EOF */
|