import less(1)
[unleashed/tickless.git] / usr / src / lib / libast / common / tm / tmzone.c
blob30cac0e37ed5c21bdd1a5bc074cc4ae26d5a297e
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * Glenn Fowler
25 * AT&T Research
27 * time conversion support
30 #include <ast.h>
31 #include <tm.h>
34 * return timezone pointer given name and type
36 * if type==0 then all time zone types match
37 * otherwise type must be one of tm_info.zone[].type
39 * if end is non-null then it will point to the next
40 * unmatched char in name
42 * if dst!=0 then it will point to 0 for standard zones
43 * and the offset for daylight zones
45 * 0 returned for no match
48 Tm_zone_t*
49 tmzone(register const char* name, char** end, const char* type, int* dst)
51 register Tm_zone_t* zp;
52 register char* prev;
53 char* e;
55 static Tm_zone_t fixed;
56 static char off[16];
58 tmset(tm_info.zone);
59 if ((*name == '+' || *name == '-') && (fixed.west = tmgoff(name, &e, TM_LOCALZONE)) != TM_LOCALZONE && !*e)
61 fixed.standard = fixed.daylight = strncpy(off, name, sizeof(off) - 1);
62 if (end)
63 *end = e;
64 if (dst)
65 *dst = 0;
66 return &fixed;
68 zp = tm_info.local;
69 prev = 0;
72 if (zp->type)
73 prev = zp->type;
74 if (!type || type == prev || !prev)
76 if (tmword(name, end, zp->standard, NiL, 0))
78 if (dst)
79 *dst = 0;
80 return zp;
82 if (zp->dst && zp->daylight && tmword(name, end, zp->daylight, NiL, 0))
84 if (dst)
85 *dst = zp->dst;
86 return zp;
89 if (zp == tm_info.local)
90 zp = tm_data.zone;
91 else
92 zp++;
93 } while (zp->standard);
94 return 0;