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

Annotation of src/usr.bin/cvs/config.c, Revision 1.2

1.2     ! joris       1: /*     $OpenBSD: config.c,v 1.1 2006/05/27 18:04:46 joris Exp $        */
1.1       joris       2: /*
                      3:  * Copyright (c) 2006 Joris Vink <joris@openbsd.org>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17:
                     18: #include "includes.h"
                     19:
                     20: #include "cvs.h"
                     21: #include "config.h"
                     22: #include "diff.h"
                     23: #include "log.h"
                     24: #include "proto.h"
                     25:
                     26: void
                     27: cvs_parse_configfile(void)
                     28: {
                     29:        int i;
                     30:        FILE *fp;
                     31:        size_t len;
                     32:        const char *errstr;
1.2     ! joris      33:        char *p, *buf, *lbuf, *opt, *val, fpath[MAXPATHLEN];
1.1       joris      34:
                     35:        i = snprintf(fpath, sizeof(fpath), "%s/%s", current_cvsroot->cr_dir,
                     36:            CVS_PATH_CONFIG);
                     37:        if (i == -1 || i >= (int)sizeof(fpath))
                     38:                fatal("cvs_parse_configfile: overflow");
                     39:
                     40:        if ((fp = fopen(fpath, "r")) == NULL)
                     41:                fatal("cvs_config_parse: %s: %s",
                     42:                    CVS_PATH_CONFIG, strerror(errno));
                     43:
                     44:        lbuf = NULL;
                     45:        while ((buf = fgetln(fp, &len))) {
                     46:                if (buf[len - 1] == '\n') {
                     47:                        buf[len - 1] = '\0';
                     48:                } else {
                     49:                        lbuf = xmalloc(len + 1);
                     50:                        strlcpy(lbuf, buf, len);
                     51:                        buf = lbuf;
                     52:                }
                     53:
1.2     ! joris      54:                p = buf;
        !            55:                while (*p == ' ')
        !            56:                        p++;
        !            57:
        !            58:                if (p[0] == '#' || p[0] == '\0') {
        !            59:                        if (lbuf != NULL)
        !            60:                                xfree(lbuf);
        !            61:                        continue;
        !            62:                }
        !            63:
        !            64:                opt = p;
1.1       joris      65:                if ((val = strrchr(opt, '=')) == NULL)
                     66:                        fatal("cvs_parse_configfile: bad option '%s'", opt);
                     67:
                     68:                *(val++) = '\0';
                     69:
                     70:                if (!strcmp(opt, "tag")) {
                     71:                        cvs_tagname = xstrdup(val);
                     72:                } else if (!strcmp(opt, "umask")) {
                     73:                        cvs_umask = (int)strtonum(val, 0, INT_MAX, &errstr);
                     74:                        if (errstr != NULL)
                     75:                                fatal("cvs_parse_configfile: %s: %s", val,
                     76:                                    errstr);
                     77:                } else {
                     78:                        cvs_log(LP_ERR, "ignoring unknown option '%s'", opt);
                     79:                }
                     80:
                     81:                if (lbuf != NULL)
                     82:                        xfree(lbuf);
                     83:        }
                     84:
                     85:        (void)fclose(fp);
                     86: }