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 /* $XConsortium: appt4.c /main/1 1996/04/21 19:21:34 drk $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
32 * this file contains allocate and free routines for v4 data structures
35 #include <EUSCompat.h>
41 #define FAUX_STRING "Appointment"
44 * forward declaration of static functions used within the file
46 static void free_tag4(Tag_4 *t);
47 static Attribute_4 *copy_attr4(Attribute_4 *a4);
48 static Tag_4 *copy_tag4(Tag_4 *t4);
50 /*****************************************************************************
52 *****************************************************************************/
55 _DtCm_make_appt4(boolean_t alloc)
59 if ((a = (Appt_4 *)calloc(1, sizeof(Appt_4))) == NULL)
62 if ((a->tag = (Tag_4 *)calloc(1, sizeof(Tag_4))) == NULL) {
66 a->tag->tag = appointment_4;
68 a->tag->showtime = B_TRUE;
70 a->period.period = single_4;
71 a->appt_status = active_4;
72 a->privacy = public_4;
75 a->what = calloc(1, sizeof(1));
76 a->author = calloc(1, sizeof(1));
77 a->client_data = calloc(1, sizeof(1));
85 _DtCm_copy_one_appt4(Appt_4 *a4)
95 copy = _DtCm_copy_appt4(a4);
102 _DtCm_copy_appt4(Appt_4 *a4)
104 Appt_4 *a, *head, *prev;
105 boolean_t cleanup = B_FALSE;
109 if ((a = (Appt_4 *)calloc(1, sizeof(Appt_4))) == NULL) {
114 a->appt_id.tick = a4->appt_id.tick;
115 a->appt_id.key = a4->appt_id.key;
117 a->duration = a4->duration;
118 a->ntimes = a4->ntimes;
121 if ((a->what = strdup(a4->what)) == NULL) {
126 } else if ((a->what = (char *)calloc(1, 1)) == NULL) {
132 a->period.period = a4->period.period;
133 a->period.nth = a4->period.nth;
134 a->period.enddate = a4->period.enddate;
137 if ((a->author = strdup(a4->author)) == NULL) {
142 } else if ((a->author = (char *)calloc(1, 1)) == NULL) {
148 if (a4->client_data) {
149 if ((a->client_data = strdup(a4->client_data)) == NULL) {
154 } else if ((a->client_data = (char *)calloc(1, 1)) == NULL) {
161 (a->exception = _DtCm_copy_excpt4(a4->exception)) == NULL) {
167 if (a4->attr && (a->attr = copy_attr4(a4->attr)) == NULL) {
174 if ((a->tag = copy_tag4(a4->tag)) == NULL) {
179 } else if ((a->tag = (Tag_4 *)calloc(1, sizeof(Tag_4))) == NULL) {
184 a->tag->tag = appointment_4;
185 a->tag->showtime = B_TRUE;
189 a->appt_status = a4->appt_status;
190 a->privacy = a4->privacy;
202 if (cleanup == B_TRUE) {
203 _DtCm_free_appt4(head);
211 * Copy one appointment.
212 * The what field is set to "Appointment".
215 _DtCm_copy_semiprivate_appt4(Appt_4 *original)
217 Appt_4 *temp, *copy = NULL;
219 if (original != NULL) {
220 temp = original->next;
221 original->next = NULL;
223 if ((copy = _DtCm_copy_appt4(original)) != NULL) {
224 if (copy->what != NULL)
226 if ((copy->what = (char *)strdup(FAUX_STRING)) == NULL)
228 _DtCm_free_appt4(copy);
233 original->next = temp;
239 _DtCm_appt_to_abbrev4(Appt_4 *original)
241 Abb_Appt_4 *new = NULL;
243 if (original != NULL) {
244 if ((new = (Abb_Appt_4 *)calloc(1, sizeof(Abb_Appt_4))) == NULL)
247 if ((new->tag = copy_tag4(original->tag)) == NULL) {
252 new->appt_id.tick = original->appt_id.tick;
253 new->appt_id.key = original->appt_id.key;
255 if ((new->what = (char *)strdup(original->what)) == NULL) {
256 _DtCm_free_abbrev_appt4(new);
260 new->duration = original->duration;
261 new->period.period = original->period.period;
262 new->period.nth = original->period.nth;
263 new->period.enddate = original->period.enddate;
265 new->appt_status = original->appt_status;
266 new->privacy = original->privacy;
273 * The what field is set to "Appointment".
276 _DtCm_appt_to_semiprivate_abbrev4(Appt_4 *original)
278 Abb_Appt_4 *new = _DtCm_appt_to_abbrev4(original);
280 if (new->what != NULL)
282 if ((new->what = strdup(FAUX_STRING)) == NULL) {
283 _DtCm_free_abbrev_appt4(new);
291 _DtCm_free_appt4(Appt_4 *a)
301 if (a->author != NULL)
308 _DtCm_free_attr4(a->attr);
310 if (a->exception != NULL)
311 _DtCm_free_excpt4(a->exception);
320 _DtCm_free_abbrev_appt4(Abb_Appt_4 *a)
327 if (a->what != NULL) {
331 if (a->tag != NULL) {
342 _DtCm_make_attr4(void)
346 if ((a = (Attribute_4 *)calloc(1, sizeof(Attribute_4))) == NULL)
349 if ((a->attr = (char *)calloc(1, 1)) == NULL) {
354 if ((a->value = (char *)calloc(1, 1)) == NULL) {
359 if ((a->clientdata = (char *)calloc(1, 1)) == NULL) {
368 _DtCm_free_attr4(Attribute_4 *a)
376 if (a->value != NULL)
378 if (a->clientdata != NULL)
387 _DtCm_copy_reminder4(Reminder_4 *r4)
389 Reminder_4 *rem, *head, *prev;
393 rem = (Reminder_4 *)calloc(1, sizeof(Reminder_4));
394 rem->appt_id = r4->appt_id;
395 rem->tick = r4->tick;
396 rem->attr.next = NULL;
397 rem->attr.attr = strdup(r4->attr.attr);
398 rem->attr.value = strdup(r4->attr.value);
399 rem->attr.clientdata = strdup(r4->attr.clientdata);
414 _DtCm_free_reminder4(Reminder_4 *r)
421 if (r->attr.attr != NULL)
423 if (r->attr.value != NULL)
424 free (r->attr.value);
425 if (r->attr.clientdata != NULL)
426 free (r->attr.clientdata);
434 _DtCm_free_keyentry4(Uid_4 *k)
445 extern Access_Entry_4 *
446 _DtCm_make_access_entry4(char *who, int perms)
450 if (who==NULL) return((Access_Entry_4 *)NULL);
451 if ((e = (Access_Entry_4 *)calloc(1, sizeof(Access_Entry_4))) == NULL)
454 if ((e->who = strdup(who)) == NULL) {
459 e->access_type = perms;
465 _DtCm_free_access_list4(Access_Entry_4 *e)
481 _DtCm_free_excpt4(Except_4 *e)
493 _DtCm_copy_excpt4(Except_4 *e4)
495 Except_4 *e, *head, *prev;
496 boolean_t cleanup = B_FALSE;
500 if ((e = (Except_4 *)calloc(1, sizeof(Except_4))) == NULL) {
505 e->ordinal = e4->ordinal;
517 if (cleanup == B_TRUE) {
518 _DtCm_free_excpt4(head);
525 /******************************************************************************
526 * static functions used within the file
527 ******************************************************************************/
541 /* Copy an attribute list recursively */
543 copy_attr4(Attribute_4 *a4)
545 Attribute_4 *a, *head, *prev;
546 boolean_t cleanup = B_FALSE;
550 if ((a = (Attribute_4 *)calloc(1, sizeof(Attribute_4)))
556 if ((a->attr = strdup(a4->attr)) == NULL) {
562 if ((a->value = strdup(a4->value)) == NULL) {
568 if ((a->clientdata = strdup(a4->clientdata)) == NULL) {
583 if (cleanup == B_TRUE) {
584 _DtCm_free_attr4(head);
594 Tag_4 *t, *head, *prev;
595 boolean_t cleanup = B_FALSE;
599 if ((t = (Tag_4 *)calloc(1, sizeof(Tag_4))) == NULL) {
605 t->showtime = t4->showtime;
617 if (cleanup == B_TRUE) {