2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * COMPONENT_NAME: austext
26 * FUNCTIONS: is_objdatestr
36 * (C) COPYRIGHT International Business Machines Corp. 1994,1995
38 * Licensed Materials - Property of IBM
39 * US Government Users Restricted Rights - Use, duplication or
40 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
42 /*************************** OBJDATE.C *************************
43 * $XConsortium: objdate.c /main/8 1996/11/21 19:51:44 drk $
45 * Utilites for generic manipulation of austext objdates.
46 * Most of these functions were originally in msgutil.c
49 * Revision 2.5 1996/03/05 18:00:36 miker
50 * Replaced hardcoded strings with refs to NULLDATESTR.
52 * Revision 2.4 1996/02/13 16:44:40 miker
53 * Allow \n to terminate null date string in is_objdatestr.
55 * Revision 2.3 1995/10/25 16:38:10 miker
58 * Revision 2.2 1995/10/02 20:37:30 miker
59 * Cosmetic cleanup only.
61 * Revision 2.1 1995/09/22 21:25:35 miker
62 * Freeze DtSearch 0.1, AusText 2.1.8
64 * Revision 1.3 1995/09/05 18:24:09 miker
65 * Remove refs to usrblk so objdate can be used in offline programs.
66 * Name changes for DtSearch.
70 #define X_INCLUDE_STRING_H
71 #define XOS_USE_NO_LOCKING
72 #include <X11/Xos_r.h>
74 #define PROGNAME "OBJDATE"
76 /************************************************/
80 /************************************************/
81 /* Converts OBJDATESTR formatted string as found in .fzk files
82 * to DtSrObjdate long integer if string is valid.
83 * Returns TRUE if passed string is correctly formatted
84 * and conversion successful. Returns FALSE and
85 * does not alter passed objdate if string is not valid.
86 * String format is: "yy/mm/dd~hh:mm[\n]" (see OBJDATESTR in SearchP.h).
87 * The slashes and tilde are mandatory, the final \n is optional.
88 * Each field maps to an objdate bitfield; bitfields map
89 * to struct tm fields (see fuzzy.h).
90 * Can be used merely to test for valid string format by
91 * passing NULL for objdate pointer.
93 int is_objdatestr (char *string, DtSrObjdate *objdptr)
95 static char parsebuf[24];
98 DtSrObjdate myobjdate = 0L;
99 _Xstrtokparams strtok_buf;
101 /* Test for "null" objdate (which is valid) */
102 if (strncmp (string, NULLDATESTR, 9) == 0) {
103 if (string[9] == 0 || string[9] == '\n') {
110 strncpy (parsebuf, string, sizeof (parsebuf));
111 parsebuf[sizeof (parsebuf) - 1] = '\0';
113 if ((token = _XStrtok(parsebuf, "/", strtok_buf)) == NULL)
116 if (i < 1 || i > 4095) /* yy */
119 myobjdate |= (i << 20);
121 if ((token = _XStrtok(NULL, "/", strtok_buf)) == NULL)
124 if (i < 1 || i > 12) /* mm */
127 myobjdate |= (--i << 16);
129 if ((token = _XStrtok(NULL, "~", strtok_buf)) == NULL)
132 if (i < 1 || i > 31) /* dd */
135 myobjdate |= (i << 11);
137 if ((token = _XStrtok(NULL, ":", strtok_buf)) == NULL)
140 if (i < 0 || i > 23) /* hh */
143 myobjdate |= (i << 6);
145 if ((token = _XStrtok(NULL, "\n", strtok_buf)) == NULL)
148 if (i < 0 || i > 59) /* mm */
154 *objdptr = myobjdate;
156 } /* is_objdatestr() */
160 /************************************************/
164 /************************************************/
165 /* Returns TRUE if passed structure is correctly formatted
166 * for conversion to DtSrObjdate variable, else returns FALSE.
168 int is_objdatetm (struct tm *objdatetm)
170 if (objdatetm->tm_year < 0)
172 if (objdatetm->tm_year > 4095)
174 if (objdatetm->tm_mon < 0)
176 if (objdatetm->tm_mon > 11)
178 if (objdatetm->tm_mday < 1)
180 if (objdatetm->tm_mday > 31)
182 if (objdatetm->tm_hour < 0)
184 if (objdatetm->tm_hour > 23)
186 if (objdatetm->tm_min < 0)
188 if (objdatetm->tm_min > 59)
191 } /* is_objdatetm() */
194 /************************************************/
198 /************************************************/
199 /* Converts DtSrObjdate formatted long int and returns
200 * pointer to static, standard unix tm structure.
201 * Bitfields map to struct tm fields (see fuzzy.h).
202 * The output tm structure is suitable for mktime(),
203 * but may only work for some formats of strftime().
205 struct tm *objdate2tm (DtSrObjdate objdate)
207 static struct tm mytm;
208 memset (&mytm, 0, sizeof (struct tm));
209 mytm.tm_year = objdate >> 20;
210 mytm.tm_mon = (objdate >> 16) & 0xf;
211 mytm.tm_mday = (objdate >> 11) & 0x1f;
212 mytm.tm_hour = (objdate >> 6) & 0x1f;
213 mytm.tm_min = objdate & 0x3f;
219 /************************************************/
223 /************************************************/
224 /* Converts DtSrObjdate formatted long int and returns pointer
225 * to static date string in .fzk format for debugging.
227 char *objdate2fzkstr (DtSrObjdate objdate)
230 static char strbuf[36];
233 tmptr = objdate2tm (objdate);
234 sprintf (strbuf, OBJDATESTR,
235 tmptr->tm_year, tmptr->tm_mon + 1,
236 tmptr->tm_mday, tmptr->tm_hour, tmptr->tm_min);
238 } /* objdate2fzkstr() */
241 /************************************************/
245 /************************************************/
246 /* Converts specific fields in a tm structure to
247 * an DtSrObjdate formatted long int and returns it.
248 * DtSrObjdate bitfields map to struct tm fields (see fuzzy.h).
249 * Does not validate tm fields (use is_objdate() to confirm).
251 DtSrObjdate tm2objdate (struct tm *tmptr)
253 return ((tmptr->tm_year << 20) |
254 (tmptr->tm_mon << 16) |
255 (tmptr->tm_mday << 11) |
256 (tmptr->tm_hour << 6) |
261 /************************************************/
263 /* objdate_in_range */
265 /************************************************/
266 /* Returns TRUE if passed record objdate (presumably read from
267 * an austext record) is within the objdate ranges specified
268 * in usrblk. Returns FALSE if record is in any way disqualified
269 * from inclusion on a hitlist because of date.
270 * Zero in any of the three dates is automatic "in range" qualification.
272 int objdate_in_range (
277 if (recdate == 0L) /* Null dated record always qualifies */
279 if (date1 != 0L && date1 > recdate)
281 if (date2 != 0L && date2 < recdate)
284 } /* objdate_in_range() */
286 /********************** OBJDATE.C *************************/