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: convert4-2.c /main/1 1996/04/21 19:22:37 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.
31 #include <EUSCompat.h>
36 #include "convert4-2.h"
39 * forward declaration of static functions
41 static void free_excpt2(Except_2 *e);
42 static Buffer_2 buffer4_to_buffer2(Buffer_4 b);
43 static Period_2 period4_to_period2(Period_4 *p);
44 static Tag_2 tag4_to_tag2(Tag_4 *t);
45 static Attribute_2 * attr4_to_attr2(Attribute_4 *a4);
46 static Except_2 * except4_to_except2(Except_4 *e4);
47 static Abb_Appt_2 * abb4_to_abb2(Abb_Appt_4 *a4);
48 static Reminder_2 * reminder4_to_reminder2(Reminder_4 *r4);
49 static Table_Res_Type_2 tablerestype4_to_tablerestype2(Table_Res_Type_4 t);
50 static void tablereslist4_to_tablereslist2(Table_Res_List_4 *from,
51 Table_Res_List_2 *to);
52 static Table_Args_Type_2 argstag4_to_argstag2(Table_Args_Type_4 t);
53 static void args4_to_args2(Args_4 *from, Args_2 *to);
54 static Table_Args_2 * tableargs4_to_tableargs2(Table_Args_4 *a4);
55 static Registration_2 * reg4_to_reg2(Registration_4 *r4);
57 /**************** DATA TYPE (4->2) CONVERSION ROUTINES **************/
60 _DtCm_id4_to_id2(Id_4 *from, Id_2 *to)
62 if ((from==NULL) || (to==NULL)) return;
63 to->tick = from->tick;
68 _DtCm_uid4_to_uid2(Uid_4 *ui4)
70 Uid_2 *ui2, *head, *prev;
74 ui2 = (Uid_2 *)calloc(1, sizeof(Uid_2));
75 _DtCm_id4_to_id2(&(ui4->appt_id), &(ui2->appt_id));
90 _DtCm_appt4_to_appt2(Appt_4 *a4)
92 Appt_2 *a2, *head, *prev;
93 struct Attribute_4 *item;
97 a2 = (Appt_2 *)calloc(1, sizeof(Appt_2));
98 _DtCm_id4_to_id2(&(a4->appt_id), &(a2->appt_id));
99 a2->tag = tag4_to_tag2(a4->tag);
100 a2->duration = a4->duration;
101 a2->ntimes = a4->ntimes;
102 a2->what = buffer4_to_buffer2(a4->what);
104 a2->period = period4_to_period2(&(a4->period));
105 a2->author = buffer4_to_buffer2(a4->author);
106 a2->client_data = buffer4_to_buffer2(a4->client_data);
107 a2->attr = attr4_to_attr2(a4->attr);
109 /* Pick the mailto field out of the attribute list
110 client data field; put it back into the appt struct
115 if (strcmp(item->attr, "ml")==0) {
116 a2->mailto=buffer4_to_buffer2(item->clientdata);
122 a2->exception = except4_to_except2(a4->exception);
136 extern Access_Status_2
137 _DtCm_accstat4_to_accstat2(Access_Status_4 s)
143 return(access_added_2);
144 case access_removed_4:
145 return(access_removed_2);
146 case access_failed_4:
147 return(access_failed_2);
148 case access_exists_4:
149 return(access_exists_2);
150 case access_partial_4:
151 return(access_partial_2);
154 return(access_other_2);
159 _DtCm_tableres4_to_tableres2(Table_Res_4 *r4)
163 if (r4==NULL) return((Table_Res_2 *)NULL);
164 r2 = (Table_Res_2 *)calloc(1, sizeof(Table_Res_2));
165 r2->status = _DtCm_accstat4_to_accstat2(r4->status);
166 tablereslist4_to_tablereslist2(&(r4->res), &(r2->res));
170 extern Access_Entry_2 *
171 _DtCm_acclist4_to_acclist2(Access_Entry_4 *l4)
173 Access_Entry_2 *l2, *head, *prev;
177 l2 = (Access_Entry_2 *)calloc(1, sizeof(Access_Entry_2));
178 l2->who = buffer4_to_buffer2(l4->who);
179 l2->access_type = l4->access_type;
193 extern Access_Args_2 *
194 _DtCm_accargs4_to_accargs2(Access_Args_4 *a4)
198 if (a4==NULL) return((Access_Args_2 *)NULL);
199 a2 = (Access_Args_2 *)calloc(1, sizeof(Access_Args_2));
200 a2->target = buffer4_to_buffer2(a4->target);
201 a2->access_list = _DtCm_acclist4_to_acclist2(a4->access_list);
206 _DtCm_range4_to_range2(Range_4 *r4)
208 Range_2 *r2, *head, *prev;
212 r2 = (Range_2 *)calloc(1, sizeof(Range_2));
228 extern Registration_Status_2
229 _DtCm_regstat4_to_regstat2(Registration_Status_4 s)
233 return(registered_2);
237 return(deregistered_2);
246 extern Table_Status_2
247 _DtCm_tablestat4_to_tablestat2(Table_Status_4 s)
267 _DtCm_uidopt4_to_uid2(Uidopt_4 *uidopt)
269 Uid_2 *uid2, *head, *prev;
272 while (uidopt != NULL) {
273 uid2 = (Uid_2 *)calloc(1, sizeof(Uid_2));
274 _DtCm_id4_to_id2(&(uidopt->appt_id), &(uid2->appt_id));
283 uidopt = uidopt->next;
289 _DtCm_free_attr2(Attribute_2 *a)
297 if (a->value != NULL)
306 _DtCm_free_appt2(Appt_2 *a)
316 if (a->mailto != NULL)
319 if (a->script != NULL)
322 if (a->author != NULL)
325 if (a->client_data != NULL)
326 free(a->client_data);
329 _DtCm_free_attr2(a->attr);
331 if (a->exception != NULL)
332 free_excpt2(a->exception);
341 free_excpt2(Except_2 *e)
353 buffer4_to_buffer2(Buffer_4 b)
364 * Repeating event types beyond "yearly" are mapped to "single"
365 * because the old front end does not recognize any other types
366 * Worse yet it uses Period_2 to index into an array which
367 * contains strings up to "yearly", any period types beyond that
368 * would index beyond the array and cause the front end to dump core.
371 period4_to_period2(Period_4 *p)
373 if (p==NULL) return(otherPeriod_2);
393 tag4_to_tag2(Tag_4 *t)
395 if (t==NULL) return(otherTag_2);
398 return(appointment_2);
410 attr4_to_attr2(Attribute_4 *a4)
412 Attribute_2 *a2, *head, *prev;
416 a2 = (Attribute_2 *)calloc(1, sizeof(Attribute_2));
418 a2->attr = strdup(a4->attr);
419 a2->value = strdup(a4->value);
433 except4_to_except2(Except_4 *e4)
435 Except_2 *e2, *head, *prev;
439 e2 = (Except_2 *)calloc(1, sizeof(Except_2));
440 e2->ordinal = e4->ordinal;
455 abb4_to_abb2(Abb_Appt_4 *a4)
457 Abb_Appt_2 *a2, *head, *prev;
461 a2 = (Abb_Appt_2 *)calloc(1, sizeof(Abb_Appt_2));
462 _DtCm_id4_to_id2(&(a4->appt_id), &(a2->appt_id));
463 a2->what = buffer4_to_buffer2(a4->what);
464 a2->duration = a4->duration;
465 a2->period = period4_to_period2(&(a4->period));
480 apptid4_to_apptid2(Apptid_4 *from, Apptid_2 *to)
482 if (from==NULL || to==NULL) return;
483 _DtCm_id4_to_id2(from->oid, to->oid);
484 to->new_appt = _DtCm_appt4_to_appt2(from->new_appt);
488 reminder4_to_reminder2(Reminder_4 *r4)
490 Reminder_2 *r2, *head, *prev;
495 r2 = (Reminder_2 *)calloc(1, sizeof(Reminder_2));
496 _DtCm_id4_to_id2(&(r4->appt_id), &(r2->appt_id));
498 attr2 = attr4_to_attr2(&(r4->attr));
514 static Table_Res_Type_2
515 tablerestype4_to_tablerestype2(Table_Res_Type_4 t)
532 tablereslist4_to_tablereslist2(Table_Res_List_4 *from, Table_Res_List_2 *to)
534 if (from==NULL || to==NULL) return;
535 to->tag = tablerestype4_to_tablerestype2(from->tag);
538 to->Table_Res_List_2_u.a = _DtCm_appt4_to_appt2(
539 from->Table_Res_List_4_u.a);
542 to->Table_Res_List_2_u.r = reminder4_to_reminder2(
543 from->Table_Res_List_4_u.r);
546 to->Table_Res_List_2_u.b = abb4_to_abb2(
547 from->Table_Res_List_4_u.b);
550 to->Table_Res_List_2_u.i = _DtCm_uid4_to_uid2(
551 from->Table_Res_List_4_u.i);
557 static Table_Args_Type_2
558 argstag4_to_argstag2(Table_Args_Type_4 t)
577 args4_to_args2(Args_4 *from, Args_2 *to)
579 if (from==NULL || to==NULL) return;
580 to->tag = argstag4_to_argstag2(from->tag);
583 to->Args_2_u.tick = from->Args_4_u.tick;
586 to->Args_2_u.apptid.oid = (Id_2 *)calloc(1, sizeof(Id_2));
588 &(from->Args_4_u.apptid),
589 &(to->Args_2_u.apptid));
592 to->Args_2_u.key = _DtCm_uid4_to_uid2(from->Args_4_u.key);
595 to->Args_2_u.appt = _DtCm_appt4_to_appt2(from->Args_4_u.appt);
598 to->Args_2_u.range = _DtCm_range4_to_range2(from->Args_4_u.range);
605 static Table_Args_2 *
606 tableargs4_to_tableargs2(Table_Args_4 *a4)
610 if (a4==NULL) return((Table_Args_2 *)NULL);
611 a2 = (Table_Args_2 *)calloc(1, sizeof(Table_Args_2));
612 a2->target = buffer4_to_buffer2(a4->target);
613 args4_to_args2(&(a4->args), &(a2->args));
617 static Registration_2 *
618 reg4_to_reg2(Registration_4 *r4)
620 Registration_2 *r2, *head, *prev;
624 r2 = (Registration_2 *)calloc(1, sizeof(Registration_2));
625 r2->target = buffer4_to_buffer2(r4->target);
626 r2->prognum = r4->prognum;
627 r2->versnum = r4->versnum;
628 r2->procnum = r4->procnum;