Annotation of embedaddon/libpdel/tmpl/tmpl_mem.c, revision 1.1
1.1 ! misho 1:
! 2: /*
! 3: * Copyright (c) 2001-2002 Packet Design, LLC.
! 4: * All rights reserved.
! 5: *
! 6: * Subject to the following obligations and disclaimer of warranty,
! 7: * use and redistribution of this software, in source or object code
! 8: * forms, with or without modifications are expressly permitted by
! 9: * Packet Design; provided, however, that:
! 10: *
! 11: * (i) Any and all reproductions of the source or object code
! 12: * must include the copyright notice above and the following
! 13: * disclaimer of warranties; and
! 14: * (ii) No rights are granted, in any manner or form, to use
! 15: * Packet Design trademarks, including the mark "PACKET DESIGN"
! 16: * on advertising, endorsements, or otherwise except as such
! 17: * appears in the above copyright notice or in the software.
! 18: *
! 19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
! 20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
! 21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
! 22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
! 23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
! 24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
! 25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
! 26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
! 27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
! 28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
! 29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
! 30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
! 31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
! 32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
! 33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
! 35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
! 36: * THE POSSIBILITY OF SUCH DAMAGE.
! 37: *
! 38: * Author: Archie Cobbs <archie@freebsd.org>
! 39: */
! 40:
! 41: #include "tmpl_internal.h"
! 42:
! 43: /*
! 44: * Free an array of parse elements.
! 45: */
! 46: void
! 47: _tmpl_free_elems(const char *mtype, void *eblock,
! 48: struct tmpl_elem *elems, int num)
! 49: {
! 50: int i;
! 51:
! 52: if (eblock != NULL) {
! 53: FREE(mtype, eblock);
! 54: return;
! 55: }
! 56: for (i = 0; i < num; i++) {
! 57: if ((elems[i].flags & TMPL_ELEM_MMAP_TEXT) == 0)
! 58: FREE(mtype, elems[i].text);
! 59: _tmpl_free_call(mtype, &elems[i].call);
! 60: }
! 61: FREE(mtype, elems);
! 62: }
! 63:
! 64: /*
! 65: * Free a run-time function structure.
! 66: */
! 67: void
! 68: _tmpl_free_func(struct tmpl_ctx *ctx, struct exec_func *func)
! 69: {
! 70: /* Free name */
! 71: FREE(ctx->mtype, func->name);
! 72:
! 73: /* Free elements */
! 74: _tmpl_free_elems(ctx->mtype, func->eblock, func->elems, func->num_elems);
! 75: }
! 76:
! 77: /*
! 78: * Free a parsed function call structure.
! 79: */
! 80: void
! 81: _tmpl_free_call(const char *mtype, struct func_call *call)
! 82: {
! 83: int i;
! 84:
! 85: for (i = 0; i < call->nargs; i++)
! 86: _tmpl_free_arg(mtype, &call->args[i]);
! 87: FREE(mtype, call->args);
! 88: FREE(mtype, call->funcname);
! 89: memset(call, 0, sizeof(*call));
! 90: }
! 91:
! 92: /*
! 93: * Free a parsed function argument.
! 94: */
! 95: void
! 96: _tmpl_free_arg(const char *mtype, struct func_arg *arg)
! 97: {
! 98: if (arg->is_literal) {
! 99: FREE(mtype, arg->u.literal);
! 100: arg->u.literal = NULL;
! 101: } else
! 102: _tmpl_free_call(mtype, &arg->u.call);
! 103: memset(arg, 0, sizeof(*arg));
! 104: }
! 105:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>