2 * Copyright (c)2004 The DragonFly Project. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * Neither the name of the DragonFly Project nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Installer Function : Parse /usr/share/zoneinfo/zone.tab.
37 * $Id: fn_zonetab.c,v 1.3 2004/07/16 21:04:20 adonijah Exp $
40 #include <sys/types.h>
46 #include "fn_zonetab.h"
49 zt_readfile(char *buf, int len, FILE *f) {
53 /* XXX this is kinda ugly */
55 while (--len > 0 && (i = getc(f)) != EOF)
58 return((i == EOF && buf == cs) ? NULL : buf);
62 zt_get_token(struct zt_parse *zp) {
65 while (*(zp->buf) != '\0' && *(zp->buf) != '\n' && *(zp->buf) != '\t') {
68 while (*(zp->buf) != '\n')
73 while (*(zp->buf) != '\n' && *(zp->buf) != '\t' &&
75 if (*(zp->buf) == '/' && zp->state == ZT_REGION) {
79 zp->tok[i++] = *(zp->buf++);
82 if (zp->state == ZT_LOCALE && *(zp->buf) == '\n')
83 zp->state = ZT_LOCALE_ENDL;
84 else if (*(zp->buf) == '\0')
92 zt_parse(struct zonetab *head) {
99 zone_tab = fopen(ZONETAB_FILE, "r");
100 stat(ZONETAB_FILE, &sb);
101 file = malloc(sb.st_size + 1);
102 file = zt_readfile(file, sb.st_size, zone_tab);
112 c->zt_cc = strdup(zp.tok);
113 zp.state = ZT_COORDS;
116 c->zt_coords = strdup(zp.tok);
117 zp.state = ZT_REGION;
120 c->zt_region = strdup(zp.tok);
121 zp.state = ZT_LOCALE;
124 c->zt_locale = strdup(zp.tok);
125 zp.state = ZT_COMMENTS;
128 c->zt_locale = strdup(zp.tok);
129 c->zt_comments = NULL;
130 c->next = malloc(sizeof(struct zonetab));
135 c->zt_comments = strdup(zp.tok);
136 c->next = malloc(sizeof(struct zonetab));