1 /* $XConsortium: convert4-2.c /main/1 1996/04/21 19:22:37 drk $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
15 #include "convert4-2.h"
18 * forward declaration of static functions
20 static void free_excpt2(Except_2 *e);
21 static Buffer_2 buffer4_to_buffer2(Buffer_4 b);
22 static Period_2 period4_to_period2(Period_4 *p);
23 static Tag_2 tag4_to_tag2(Tag_4 *t);
24 static Attribute_2 * attr4_to_attr2(Attribute_4 *a4);
25 static Except_2 * except4_to_except2(Except_4 *e4);
26 static Abb_Appt_2 * abb4_to_abb2(Abb_Appt_4 *a4);
27 static Reminder_2 * reminder4_to_reminder2(Reminder_4 *r4);
28 static Table_Res_Type_2 tablerestype4_to_tablerestype2(Table_Res_Type_4 t);
29 static void tablereslist4_to_tablereslist2(Table_Res_List_4 *from,
30 Table_Res_List_2 *to);
31 static Table_Args_Type_2 argstag4_to_argstag2(Table_Args_Type_4 t);
32 static void args4_to_args2(Args_4 *from, Args_2 *to);
33 static Table_Args_2 * tableargs4_to_tableargs2(Table_Args_4 *a4);
34 static Registration_2 * reg4_to_reg2(Registration_4 *r4);
36 /**************** DATA TYPE (4->2) CONVERSION ROUTINES **************/
39 _DtCm_id4_to_id2(Id_4 *from, Id_2 *to)
41 if ((from==NULL) || (to==NULL)) return;
42 to->tick = from->tick;
47 _DtCm_uid4_to_uid2(Uid_4 *ui4)
49 Uid_2 *ui2, *head, *prev;
53 ui2 = (Uid_2 *)calloc(1, sizeof(Uid_2));
54 _DtCm_id4_to_id2(&(ui4->appt_id), &(ui2->appt_id));
69 _DtCm_appt4_to_appt2(Appt_4 *a4)
71 Appt_2 *a2, *head, *prev;
72 struct Attribute_4 *item;
76 a2 = (Appt_2 *)calloc(1, sizeof(Appt_2));
77 _DtCm_id4_to_id2(&(a4->appt_id), &(a2->appt_id));
78 a2->tag = tag4_to_tag2(a4->tag);
79 a2->duration = a4->duration;
80 a2->ntimes = a4->ntimes;
81 a2->what = buffer4_to_buffer2(a4->what);
83 a2->period = period4_to_period2(&(a4->period));
84 a2->author = buffer4_to_buffer2(a4->author);
85 a2->client_data = buffer4_to_buffer2(a4->client_data);
86 a2->attr = attr4_to_attr2(a4->attr);
88 /* Pick the mailto field out of the attribute list
89 client data field; put it back into the appt struct
94 if (strcmp(item->attr, "ml")==0) {
95 a2->mailto=buffer4_to_buffer2(item->clientdata);
101 a2->exception = except4_to_except2(a4->exception);
115 extern Access_Status_2
116 _DtCm_accstat4_to_accstat2(Access_Status_4 s)
122 return(access_added_2);
123 case access_removed_4:
124 return(access_removed_2);
125 case access_failed_4:
126 return(access_failed_2);
127 case access_exists_4:
128 return(access_exists_2);
129 case access_partial_4:
130 return(access_partial_2);
133 return(access_other_2);
138 _DtCm_tableres4_to_tableres2(Table_Res_4 *r4)
142 if (r4==NULL) return((Table_Res_2 *)NULL);
143 r2 = (Table_Res_2 *)calloc(1, sizeof(Table_Res_2));
144 r2->status = _DtCm_accstat4_to_accstat2(r4->status);
145 tablereslist4_to_tablereslist2(&(r4->res), &(r2->res));
149 extern Access_Entry_2 *
150 _DtCm_acclist4_to_acclist2(Access_Entry_4 *l4)
152 Access_Entry_2 *l2, *head, *prev;
156 l2 = (Access_Entry_2 *)calloc(1, sizeof(Access_Entry_2));
157 l2->who = buffer4_to_buffer2(l4->who);
158 l2->access_type = l4->access_type;
172 extern Access_Args_2 *
173 _DtCm_accargs4_to_accargs2(Access_Args_4 *a4)
177 if (a4==NULL) return((Access_Args_2 *)NULL);
178 a2 = (Access_Args_2 *)calloc(1, sizeof(Access_Args_2));
179 a2->target = buffer4_to_buffer2(a4->target);
180 a2->access_list = _DtCm_acclist4_to_acclist2(a4->access_list);
185 _DtCm_range4_to_range2(Range_4 *r4)
187 Range_2 *r2, *head, *prev;
191 r2 = (Range_2 *)calloc(1, sizeof(Range_2));
207 extern Registration_Status_2
208 _DtCm_regstat4_to_regstat2(Registration_Status_4 s)
212 return(registered_2);
216 return(deregistered_2);
225 extern Table_Status_2
226 _DtCm_tablestat4_to_tablestat2(Table_Status_4 s)
246 _DtCm_uidopt4_to_uid2(Uidopt_4 *uidopt)
248 Uid_2 *uid2, *head, *prev;
251 while (uidopt != NULL) {
252 uid2 = (Uid_2 *)calloc(1, sizeof(Uid_2));
253 _DtCm_id4_to_id2(&(uidopt->appt_id), &(uid2->appt_id));
262 uidopt = uidopt->next;
268 _DtCm_free_attr2(Attribute_2 *a)
276 if (a->value != NULL)
285 _DtCm_free_appt2(Appt_2 *a)
295 if (a->mailto != NULL)
298 if (a->script != NULL)
301 if (a->author != NULL)
304 if (a->client_data != NULL)
305 free(a->client_data);
308 _DtCm_free_attr2(a->attr);
310 if (a->exception != NULL)
311 free_excpt2(a->exception);
320 free_excpt2(Except_2 *e)
332 buffer4_to_buffer2(Buffer_4 b)
343 * Repeating event types beyond "yearly" are mapped to "single"
344 * because the old front end does not recognize any other types
345 * Worse yet it uses Period_2 to index into an array which
346 * contains strings up to "yearly", any period types beyond that
347 * would index beyond the array and cause the front end to dump core.
350 period4_to_period2(Period_4 *p)
352 if (p==NULL) return(otherPeriod_2);
372 tag4_to_tag2(Tag_4 *t)
374 if (t==NULL) return(otherTag_2);
377 return(appointment_2);
389 attr4_to_attr2(Attribute_4 *a4)
391 Attribute_2 *a2, *head, *prev;
395 a2 = (Attribute_2 *)calloc(1, sizeof(Attribute_2));
397 a2->attr = strdup(a4->attr);
398 a2->value = strdup(a4->value);
412 except4_to_except2(Except_4 *e4)
414 Except_2 *e2, *head, *prev;
418 e2 = (Except_2 *)calloc(1, sizeof(Except_2));
419 e2->ordinal = e4->ordinal;
434 abb4_to_abb2(Abb_Appt_4 *a4)
436 Abb_Appt_2 *a2, *head, *prev;
440 a2 = (Abb_Appt_2 *)calloc(1, sizeof(Abb_Appt_2));
441 _DtCm_id4_to_id2(&(a4->appt_id), &(a2->appt_id));
442 a2->what = buffer4_to_buffer2(a4->what);
443 a2->duration = a4->duration;
444 a2->period = period4_to_period2(&(a4->period));
459 apptid4_to_apptid2(Apptid_4 *from, Apptid_2 *to)
461 if (from==NULL || to==NULL) return;
462 _DtCm_id4_to_id2(from->oid, to->oid);
463 to->new_appt = _DtCm_appt4_to_appt2(from->new_appt);
467 reminder4_to_reminder2(Reminder_4 *r4)
469 Reminder_2 *r2, *head, *prev;
474 r2 = (Reminder_2 *)calloc(1, sizeof(Reminder_2));
475 _DtCm_id4_to_id2(&(r4->appt_id), &(r2->appt_id));
477 attr2 = attr4_to_attr2(&(r4->attr));
493 static Table_Res_Type_2
494 tablerestype4_to_tablerestype2(Table_Res_Type_4 t)
511 tablereslist4_to_tablereslist2(Table_Res_List_4 *from, Table_Res_List_2 *to)
513 if (from==NULL || to==NULL) return;
514 to->tag = tablerestype4_to_tablerestype2(from->tag);
517 to->Table_Res_List_2_u.a = _DtCm_appt4_to_appt2(
518 from->Table_Res_List_4_u.a);
521 to->Table_Res_List_2_u.r = reminder4_to_reminder2(
522 from->Table_Res_List_4_u.r);
525 to->Table_Res_List_2_u.b = abb4_to_abb2(
526 from->Table_Res_List_4_u.b);
529 to->Table_Res_List_2_u.i = _DtCm_uid4_to_uid2(
530 from->Table_Res_List_4_u.i);
536 static Table_Args_Type_2
537 argstag4_to_argstag2(Table_Args_Type_4 t)
556 args4_to_args2(Args_4 *from, Args_2 *to)
558 if (from==NULL || to==NULL) return;
559 to->tag = argstag4_to_argstag2(from->tag);
562 to->Args_2_u.tick = from->Args_4_u.tick;
565 to->Args_2_u.apptid.oid = (Id_2 *)calloc(1, sizeof(Id_2));
567 &(from->Args_4_u.apptid),
568 &(to->Args_2_u.apptid));
571 to->Args_2_u.key = _DtCm_uid4_to_uid2(from->Args_4_u.key);
574 to->Args_2_u.appt = _DtCm_appt4_to_appt2(from->Args_4_u.appt);
577 to->Args_2_u.range = _DtCm_range4_to_range2(from->Args_4_u.range);
584 static Table_Args_2 *
585 tableargs4_to_tableargs2(Table_Args_4 *a4)
589 if (a4==NULL) return((Table_Args_2 *)NULL);
590 a2 = (Table_Args_2 *)calloc(1, sizeof(Table_Args_2));
591 a2->target = buffer4_to_buffer2(a4->target);
592 args4_to_args2(&(a4->args), &(a2->args));
596 static Registration_2 *
597 reg4_to_reg2(Registration_4 *r4)
599 Registration_2 *r2, *head, *prev;
603 r2 = (Registration_2 *)calloc(1, sizeof(Registration_2));
604 r2->target = buffer4_to_buffer2(r4->target);
605 r2->prognum = r4->prognum;
606 r2->versnum = r4->versnum;
607 r2->procnum = r4->procnum;