[BACK]Return to varname.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/varname.c, Revision 1.1

1.1     ! espie       1: /*     $OpenPackages$ */
        !             2: /*     $OpenBSD: var.c,v 1.12 1999/09/28 21:57:04 espie Exp $  */
        !             3: /*
        !             4:  * Copyright (c) 2001 Marc Espie.
        !             5:  *
        !             6:  * Redistribution and use in source and binary forms, with or without
        !             7:  * modification, are permitted provided that the following conditions
        !             8:  * are met:
        !             9:  * 1. Redistributions of source code must retain the above copyright
        !            10:  *    notice, this list of conditions and the following disclaimer.
        !            11:  * 2. Redistributions in binary form must reproduce the above copyright
        !            12:  *    notice, this list of conditions and the following disclaimer in the
        !            13:  *    documentation and/or other materials provided with the distribution.
        !            14:  *
        !            15:  * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
        !            16:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
        !            17:  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
        !            18:  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OPENBSD
        !            19:  * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
        !            20:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
        !            21:  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            22:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            23:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            24:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        !            25:  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            26:  */
        !            27:
        !            28: #include <stdlib.h>
        !            29: #include "config.h"
        !            30: #include "defines.h"
        !            31: #include "var.h"
        !            32: #include "buf.h"
        !            33: #include "varname.h"
        !            34:
        !            35: const char *
        !            36: VarName_Get(start, name, ctxt, err, cont)
        !            37:        const char      *start;
        !            38:        struct Name     *name;
        !            39:        SymTable        *ctxt;
        !            40:        bool            err;
        !            41:        const char *(*cont)(const char *);
        !            42: {
        !            43:        const char *p;
        !            44:        size_t len;
        !            45:
        !            46:        p = cont(start);
        !            47:        /* If we don't want recursive variables, we skip over '$' */
        !            48:        if (!FEATURES(FEATURE_RECVARS)) {
        !            49:                while (*p == '$')
        !            50:                    p = cont(p);
        !            51:        }
        !            52:        if (*p != '$') {
        !            53:                name->s = start;
        !            54:                name->e = p;
        !            55:                name->tofree = false;
        !            56:                return p;
        !            57:        } else {
        !            58:                BUFFER buf;
        !            59:                Buf_Init(&buf, MAKE_BSIZE);
        !            60:                for (;;) {
        !            61:                        Buf_Addi(&buf, start, p);
        !            62:                        if (*p != '$') {
        !            63:                                name->s = (const char *)Buf_Retrieve(&buf);
        !            64:                                name->e = name->s + Buf_Size(&buf);
        !            65:                                name->tofree = true;
        !            66:                                return p;
        !            67:                        }
        !            68:                        start = p;
        !            69:                        Var_ParseBuffer(&buf, start, ctxt, err, &len);
        !            70:                        start += len;
        !            71:                        p = cont(start);
        !            72:                }
        !            73:        }
        !            74: }
        !            75:
        !            76: void
        !            77: VarName_Free(name)
        !            78:        struct Name *name;
        !            79: {
        !            80:        if (name->tofree)
        !            81:                free((char *)name->s);
        !            82: }
        !            83: