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
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 #include <X11/Xos_r.h>
75 * Convert tick to m, d, y string. e.g. May 1, 1988
78 format_date(Tick t, OrderingType order, char *buf, int day_and_date,
79 int and_date, int full_day)
83 _Xltimeparams localtime_buf;
86 tm = _XLocaltime(&t, localtime_buf);
89 y = tm->tm_year + 1900;
94 /* STRING_EXTRACTION SUNW_DESKSET_CM_MSG :
96 * %s, %d %s %4d is a form of the date format.
97 * Change this to reflect your local convention.
98 * eg. In the German locale, "%s, %d %s %4d" may be changed
103 (void)sprintf(buf, "%s, %d %s %4d",
104 days2[wd], d, months[m], y);
106 (void)sprintf(buf, "%s, %d %s %4d",
107 days[wd], d, months[m], y);
109 (void)sprintf(buf, "%d %s %4d", d, months[m], y);
112 (void) sprintf(buf, "%s %4d", months[m], y);
117 (void)sprintf(buf, "%s, %4d %s %d",
118 days2[wd], y, months[m], d);
120 (void)sprintf(buf, "%s, %4d %s %d",
121 days[wd], y, months[m], d);
123 (void)sprintf(buf, "%4d %s %d", y, months[m], d);
125 (void) sprintf(buf, "%4d %s", y, months[m]);
131 (void)sprintf(buf, "%s, %s %d %4d",
132 days2[wd], months[m], d, y);
134 (void)sprintf(buf, "%s, %s %d %4d",
135 days[wd], months[m], d, y);
137 (void)sprintf(buf, "%s %d %4d",
140 (void) sprintf(buf, "%s %4d", months[m], y);
147 * Convert tick to m/d
150 format_date3(Tick t, OrderingType order, SeparatorType sep, char *buf)
154 char *str = (char *) separator_str(sep);
155 _Xltimeparams localtime_buf;
158 tm = _XLocaltime(&t, localtime_buf);
166 (void) sprintf(buf, "%d%s%.2d", m, str, d);
169 (void) sprintf(buf, "%.2d%s%d", d, str, m);
175 * Format 1 line of appt data. Returns True if begin hour is < 10 - thus
176 * padding needs to be done.
179 format_line(Tick tick,
186 int hr, hr1, mn, mn1;
191 _Xltimeparams localtime_buf;
193 if (buf==NULL) return pad;
195 tm = _XLocaltime(&tick, localtime_buf);
198 if (showtime && !magic_time(tick)) {
199 if (display == HOUR12)
200 am = adjust_hour(&hr);
201 if (end_tick && end_tick != tick) {
202 hr1 = hour(end_tick);
203 mn1 = minute(end_tick);
204 if (display == HOUR12) {
205 am_end = adjust_hour(&hr1);
207 (void) sprintf(buf, "%d:%.2d - %d:%.2d%s ",
209 hr1, mn1, am_end ? "am" : "pm");
211 (void) sprintf(buf, "%d:%.2d - %d:%.2d ",
214 if (hr < 10) pad = TRUE;
217 (void) sprintf(buf, "%02d%02d - %02d%02d ",
221 /* Check to see if there are 2 digits in
222 in initial time format. If so, pad with
223 1 space; if not 2. The font is not fixed
224 width, so I have to line it up myself.. */
225 if (display == HOUR12) {
227 (char *)sprintf(buf, "%2d:%.2d%s ",
228 hr, mn, am ? "a" : "p");
230 (char *)sprintf(buf, "%d:%.2d%s ",
231 hr, mn, am ? "a" : "p");
236 (char *)sprintf(buf, "%02d%02d ", hr, mn);
240 (void) cm_strcat(buf, what);
246 * Format 2 lines of appt data
249 format_maxchars(Dtcm_appointment *appt, char *buf1, int maxchars,
250 DisplayType display) {
251 Tick tick, end_tick = 0;
252 int hour1, min1, hour2, min2;
256 _Xltimeparams localtime_buf;
258 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
260 _csa_iso8601_to_tick(appt->end_time->value->item.string_value,
263 if (appt == NULL || appt->what->value->item.string_value == NULL) return;
264 tm = _XLocaltime(&tick, localtime_buf);
267 if (showtime_set(appt) && !magic_time(tick)) {
269 if (display == HOUR12 && !adjust_hour(&hour1))
273 hour2 = hour(end_tick);
274 if (display == HOUR12 && !adjust_hour(&hour2))
277 min2 = minute(end_tick);
280 if (end_tick == 0 || hour1 == hour2 && min1 == min2) {
281 if (display == HOUR24)
282 sprintf(buf1, "%02d%02d ", hour1, min1);
284 sprintf(buf1, "%d:%.2d%s ", hour1, min1, s1);
287 if (display == HOUR12)
288 sprintf(buf1, "%d:%.2d%s-%d:%.2d%s ",
289 hour1, min1, s1, hour2, min2, s2);
291 sprintf(buf1, "%02d%02d-%02d%02d ",
292 hour1, min1, hour2, min2);
296 lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 10);
298 while (lines != NULL) {
299 if ((cm_strlen(buf1) + cm_strlen(lines->s)) < (maxchars-2)) {
300 cm_strcat(buf1, lines->s);
303 cm_strcat(buf1, " - ");
306 strncat(buf1, lines->s, (maxchars - cm_strlen(buf1)-1));
310 destroy_lines(lines);
315 * Format 2 lines of appt data
318 format_line2(Dtcm_appointment *appt, char *buf1, char *buf2,
319 DisplayType display) {
320 Tick tick, end_tick = 0;
321 int hour1, min1, hour2, min2;
325 _Xltimeparams localtime_buf;
327 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
329 _csa_iso8601_to_tick(appt->end_time->value->item.string_value,
333 * Extract an appointment and format it into 2 lines of no more
336 *buf1 = *buf2 = NULL;
337 if (appt == NULL || appt->what->value->item.string_value == NULL) return;
338 tm = _XLocaltime(&tick, localtime_buf);
342 if (!showtime_set(appt) || magic_time(tick)) {
343 lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1);
344 if (lines==NULL) return;
345 strncpy(buf2, lines->s, 256);
346 destroy_lines(lines);
351 if (display == HOUR12 && !adjust_hour(&hour1))
355 hour2 = hour(end_tick);
356 min2 = minute(end_tick);
357 if (display == HOUR12 && !adjust_hour(&hour2))
362 (hour1 == hour2 && min1 == min2 && (strcmp(s1, s2) == 0))) {
363 if (display == HOUR24)
364 sprintf(buf1, "%02d%.2d", hour1, min1);
366 sprintf(buf1, "%d:%.2d%s", hour1, min1, s1);
369 if (display == HOUR12)
370 sprintf(buf1, "%d:%.2d%s-%d:%.2d%s", hour1, min1, s1,
373 sprintf(buf1, "%02d%02d-%02d%02d", hour1, min1,
378 lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1);
380 if (lines == NULL || lines->s == NULL ||
381 (cm_strlen(lines->s) == 1 && lines->s[0] == ' '))
384 sprintf(buf2, " %s", lines->s);
385 destroy_lines(lines);
390 format_abbrev_appt(Dtcm_appointment *appt, char *b, Boolean show_am,
398 _Xltimeparams localtime_buf;
400 if(appt==NULL || b==NULL) return;
401 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
402 tm = _XLocaltime(&tick, localtime_buf);
405 if (showtime_set(appt) && !magic_time(tick)) {
406 if (display == HOUR12) {
407 am = adjust_hour(&hr);
409 sprintf(b, "%2d:%02d%s ", hr, mn, am ?
412 sprintf(b, "%2d:%02d ", hr, mn);
415 sprintf(b, "%02d%02d ", hr, mn);
417 lines = text_to_lines(appt->what->value->item.string_value, 1);
418 if (lines != NULL && lines->s != NULL) {
419 (void) cm_strcat(b, lines->s);
420 destroy_lines(lines);
425 * Format the appointment in the character array passed (assumed to be pointing
426 * to allocated space) to contain the time followed by the what string. The
427 * appointment string is truncated at "max" chars or at DEFAULT_APPT_LEN if
431 format_appt(Dtcm_appointment *appt, char *b, DisplayType display, int max) {
432 int hr, mn, len, i = 0, j = 0;
435 register char *what_ptr;
436 _Xltimeparams localtime_buf;
441 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
442 tm = _XLocaltime(&tick, localtime_buf);
446 if (showtime_set(appt) && !magic_time(tick)) {
447 if (display == HOUR12) {
449 sprintf(b, "%2d:%02d ", hr, mn);
451 sprintf(b, "%02d%02d ", hr, mn);
455 if (appt->what->value->item.string_value) {
457 max = DEFAULT_APPT_LEN;
459 what_ptr = appt->what->value->item.string_value;
460 while ((i < len) && *what_ptr != '\n' && *what_ptr)
461 b[i++] = *what_ptr++;
467 * Format the appointment in the character array passed (assumed to be pointing
468 * to allocated space) to contain the formatted string for the group
469 * appointment editor. The string is truncated at "max" chars or at
470 * DEFAULT_GAPPT_LEN if max is 0.
473 format_gappt(Dtcm_appointment *appt, char *name, char *b, DisplayType display,
479 _Xltimeparams localtime_buf;
484 _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick);
485 if ((tick > 0) && !magic_time(tick) &&
486 showtime_set(appt)) {
487 tm = _XLocaltime(&tick, localtime_buf);
491 if (display == HOUR12) {
493 sprintf(b, "%2d:%02d ", hr, mn);
495 sprintf(b, "%02d%02d ", hr, mn);
497 sprintf(b, "%6s", " ");
500 max = DEFAULT_GAPPT_LEN;
504 while (j < 10 && i < max && name && name[j])
506 while (j < 11 && i < max)
515 if (appt->what->value->item.string_value) {
516 what_ptr = appt->what->value->item.string_value;
517 while (i < max && *what_ptr != '\n' && *what_ptr)
518 b[i++] = *what_ptr++;