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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $XConsortium: format.c /main/5 1996/11/21 19:42:52 drk $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
51 static char sccsid[] = "@(#)format.c 1.27 95/01/19 Copyr 1991 Sun Microsystems, Inc.";
54 #include <EUSCompat.h>
57 #if defined(sun) && defined(_XOPEN_SOURCE)
67 #include "datefield.h"
70 #define XOS_USE_XT_LOCKING
71 #define X_INCLUDE_TIME_H
72 #if defined(__linux__)
75 #include <X11/Xos_r.h>
78 * Convert tick to m, d, y string. e.g. May 1, 1988
81 format_date(Tick t, OrderingType order, char *buf, int day_and_date,
82 int and_date, int full_day)
86 _Xltimeparams localtime_buf;
89 tm = _XLocaltime(&t, localtime_buf);
92 y = tm->tm_year + 1900;
97 /* STRING_EXTRACTION SUNW_DESKSET_CM_MSG :
99 * %s, %d %s %4d is a form of the date format.
100 * Change this to reflect your local convention.
101 * eg. In the German locale, "%s, %d %s %4d" may be changed
102 * to "%s. %d %s %4d".
106 (void)sprintf(buf, "%s, %d %s %4d",
107 days2[wd], d, months[m], y);
109 (void)sprintf(buf, "%s, %d %s %4d",
110 days[wd], d, months[m], y);
112 (void)sprintf(buf, "%d %s %4d", d, months[m], y);
115 (void) sprintf(buf, "%s %4d", months[m], y);
120 (void)sprintf(buf, "%s, %4d %s %d",
121 days2[wd], y, months[m], d);
123 (void)sprintf(buf, "%s, %4d %s %d",
124 days[wd], y, months[m], d);
126 (void)sprintf(buf, "%4d %s %d", y, months[m], d);
128 (void) sprintf(buf, "%4d %s", y, months[m]);
134 (void)sprintf(buf, "%s, %s %d %4d",
135 days2[wd], months[m], d, y);
137 (void)sprintf(buf, "%s, %s %d %4d",
138 days[wd], months[m], d, y);
140 (void)sprintf(buf, "%s %d %4d",
143 (void) sprintf(buf, "%s %4d", months[m], y);
150 * Convert tick to m/d
153 format_date3(Tick t, OrderingType order, SeparatorType sep, char *buf)
157 char *str = (char *) separator_str(sep);
158 _Xltimeparams localtime_buf;
161 tm = _XLocaltime(&t, localtime_buf);
169 (void) sprintf(buf, "%d%s%.2d", m, str, d);
172 (void) sprintf(buf, "%.2d%s%d", d, str, m);
178 * Format 1 line of appt data. Returns True if begin hour is < 10 - thus
179 * padding needs to be done.
182 format_line(Tick tick,
189 int hr, hr1, mn, mn1;
194 _Xltimeparams localtime_buf;
196 if (buf==NULL) return pad;
198 tm = _XLocaltime(&tick, localtime_buf);
201 if (showtime && !magic_time(tick)) {
202 if (display == HOUR12)
203 am = adjust_hour(&hr);
204 if (end_tick && end_tick != tick) {
205 hr1 = hour(end_tick);
206 mn1 = minute(end_tick);
207 if (display == HOUR12) {
208 am_end = adjust_hour(&hr1);
210 (void) sprintf(buf, "%d:%.2d - %d:%.2d%s ",
212 hr1, mn1, am_end ? "am" : "pm");
214 (void) sprintf(buf, "%d:%.2d - %d:%.2d ",
217 if (hr < 10) pad = TRUE;
220 (void) sprintf(buf, "%02d%02d - %02d%02d ",
224 /* Check to see if there are 2 digits in
225 in initial time format. If so, pad with
226 1 space; if not 2. The font is not fixed
227 width, so I have to line it up myself.. */
228 if (display == HOUR12) {
230 sprintf(buf, "%2d:%.2d%s ",
231 hr, mn, am ? "a" : "p");
233 sprintf(buf, "%d:%.2d%s ",
234 hr, mn, am ? "a" : "p");
239 sprintf(buf, "%02d%02d ", hr, mn);
243 (void) cm_strcat(buf, what);
249 * Format 2 lines of appt data
252 format_maxchars(Dtcm_appointment *appt, char *buf1, int maxchars,
253 DisplayType display) {
254 Tick tick, end_tick = 0;
255 int hour1, min1, hour2, min2;
259 _Xltimeparams localtime_buf;
261 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
263 _csa_iso8601_to_tick(appt->end_time->value->item.string_value,
266 if (appt == NULL || appt->what->value->item.string_value == NULL) return;
267 tm = _XLocaltime(&tick, localtime_buf);
270 if (showtime_set(appt) && !magic_time(tick)) {
272 if (display == HOUR12 && !adjust_hour(&hour1))
276 hour2 = hour(end_tick);
277 if (display == HOUR12 && !adjust_hour(&hour2))
280 min2 = minute(end_tick);
283 if (end_tick == 0 || hour1 == hour2 && min1 == min2) {
284 if (display == HOUR24)
285 sprintf(buf1, "%02d%02d ", hour1, min1);
287 sprintf(buf1, "%d:%.2d%s ", hour1, min1, s1);
290 if (display == HOUR12)
291 sprintf(buf1, "%d:%.2d%s-%d:%.2d%s ",
292 hour1, min1, s1, hour2, min2, s2);
294 sprintf(buf1, "%02d%02d-%02d%02d ",
295 hour1, min1, hour2, min2);
299 lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 10);
301 while (lines != NULL) {
302 if ((cm_strlen(buf1) + cm_strlen(lines->s)) < (maxchars-2)) {
303 cm_strcat(buf1, lines->s);
306 cm_strcat(buf1, " - ");
309 strncat(buf1, lines->s, (maxchars - cm_strlen(buf1)-1));
313 destroy_lines(lines);
318 * Format 2 lines of appt data
321 format_line2(Dtcm_appointment *appt, char *buf1, char *buf2,
322 DisplayType display) {
323 Tick tick, end_tick = 0;
324 int hour1, min1, hour2, min2;
328 _Xltimeparams localtime_buf;
330 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
332 _csa_iso8601_to_tick(appt->end_time->value->item.string_value,
336 * Extract an appointment and format it into 2 lines of no more
339 *buf1 = *buf2 = '\0';
340 if (appt == NULL || appt->what->value->item.string_value == NULL) return;
341 tm = _XLocaltime(&tick, localtime_buf);
345 if (!showtime_set(appt) || magic_time(tick)) {
346 lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1);
347 if (lines==NULL) return;
348 strncpy(buf2, lines->s, 256);
349 destroy_lines(lines);
354 if (display == HOUR12 && !adjust_hour(&hour1))
358 hour2 = hour(end_tick);
359 min2 = minute(end_tick);
360 if (display == HOUR12 && !adjust_hour(&hour2))
365 (hour1 == hour2 && min1 == min2 && (strcmp(s1, s2) == 0))) {
366 if (display == HOUR24)
367 sprintf(buf1, "%02d%.2d", hour1, min1);
369 sprintf(buf1, "%d:%.2d%s", hour1, min1, s1);
372 if (display == HOUR12)
373 sprintf(buf1, "%d:%.2d%s-%d:%.2d%s", hour1, min1, s1,
376 sprintf(buf1, "%02d%02d-%02d%02d", hour1, min1,
381 lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1);
383 if (lines == NULL || lines->s == NULL ||
384 (cm_strlen(lines->s) == 1 && lines->s[0] == ' '))
387 sprintf(buf2, " %s", lines->s);
388 destroy_lines(lines);
393 format_abbrev_appt(Dtcm_appointment *appt, char *b, Boolean show_am,
401 _Xltimeparams localtime_buf;
403 if(appt==NULL || b==NULL) return;
404 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
405 tm = _XLocaltime(&tick, localtime_buf);
408 if (showtime_set(appt) && !magic_time(tick)) {
409 if (display == HOUR12) {
410 am = adjust_hour(&hr);
412 sprintf(b, "%2d:%02d%s ", hr, mn, am ?
415 sprintf(b, "%2d:%02d ", hr, mn);
418 sprintf(b, "%02d%02d ", hr, mn);
420 lines = text_to_lines(appt->what->value->item.string_value, 1);
421 if (lines != NULL && lines->s != NULL) {
422 (void) cm_strcat(b, lines->s);
423 destroy_lines(lines);
428 * Format the appointment in the character array passed (assumed to be pointing
429 * to allocated space) to contain the time followed by the what string. The
430 * appointment string is truncated at "max" chars or at DEFAULT_APPT_LEN if
434 format_appt(Dtcm_appointment *appt, char *b, DisplayType display, int max) {
435 int hr, mn, len, i = 0, j = 0;
438 register char *what_ptr;
439 _Xltimeparams localtime_buf;
444 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
445 tm = _XLocaltime(&tick, localtime_buf);
449 if (showtime_set(appt) && !magic_time(tick)) {
450 if (display == HOUR12) {
452 sprintf(b, "%2d:%02d ", hr, mn);
454 sprintf(b, "%02d%02d ", hr, mn);
458 if (appt->what->value->item.string_value) {
460 max = DEFAULT_APPT_LEN;
462 what_ptr = appt->what->value->item.string_value;
463 while ((i < len) && *what_ptr != '\n' && *what_ptr)
464 b[i++] = *what_ptr++;
470 * Format the appointment in the character array passed (assumed to be pointing
471 * to allocated space) to contain the formatted string for the group
472 * appointment editor. The string is truncated at "max" chars or at
473 * DEFAULT_GAPPT_LEN if max is 0.
476 format_gappt(Dtcm_appointment *appt, char *name, char *b, DisplayType display,
482 _Xltimeparams localtime_buf;
487 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
488 if ((tick > 0) && !magic_time(tick) &&
489 showtime_set(appt)) {
490 tm = _XLocaltime(&tick, localtime_buf);
494 if (display == HOUR12) {
496 sprintf(b, "%2d:%02d ", hr, mn);
498 sprintf(b, "%02d%02d ", hr, mn);
500 sprintf(b, "%6s", " ");
503 max = DEFAULT_GAPPT_LEN;
507 while (j < 10 && i < max && name && name[j])
509 while (j < 11 && i < max)
518 if (appt->what->value->item.string_value) {
519 what_ptr = appt->what->value->item.string_value;
520 while (i < max && *what_ptr != '\n' && *what_ptr)
521 b[i++] = *what_ptr++;