convert4-2.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $XConsortium: convert4-2.c /main/1 1996/04/21 19:22:37 drk $ */
  24. /*
  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.
  29. */
  30. #include <EUSCompat.h>
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include "rtable2.h"
  34. #include "rtable4.h"
  35. #include "convert4-2.h"
  36. /*
  37. * forward declaration of static functions
  38. */
  39. static void free_excpt2(Except_2 *e);
  40. static Buffer_2 buffer4_to_buffer2(Buffer_4 b);
  41. static Period_2 period4_to_period2(Period_4 *p);
  42. static Tag_2 tag4_to_tag2(Tag_4 *t);
  43. static Attribute_2 * attr4_to_attr2(Attribute_4 *a4);
  44. static Except_2 * except4_to_except2(Except_4 *e4);
  45. static Abb_Appt_2 * abb4_to_abb2(Abb_Appt_4 *a4);
  46. static Reminder_2 * reminder4_to_reminder2(Reminder_4 *r4);
  47. static Table_Res_Type_2 tablerestype4_to_tablerestype2(Table_Res_Type_4 t);
  48. static void tablereslist4_to_tablereslist2(Table_Res_List_4 *from,
  49. Table_Res_List_2 *to);
  50. static Table_Args_Type_2 argstag4_to_argstag2(Table_Args_Type_4 t);
  51. static void args4_to_args2(Args_4 *from, Args_2 *to);
  52. static Table_Args_2 * tableargs4_to_tableargs2(Table_Args_4 *a4);
  53. static Registration_2 * reg4_to_reg2(Registration_4 *r4);
  54. /**************** DATA TYPE (4->2) CONVERSION ROUTINES **************/
  55. extern void
  56. _DtCm_id4_to_id2(Id_4 *from, Id_2 *to)
  57. {
  58. if ((from==NULL) || (to==NULL)) return;
  59. to->tick = from->tick;
  60. to->key = from->key;
  61. }
  62. extern Uid_2 *
  63. _DtCm_uid4_to_uid2(Uid_4 *ui4)
  64. {
  65. Uid_2 *ui2, *head, *prev;
  66. prev = head = NULL;
  67. while (ui4 != NULL) {
  68. ui2 = (Uid_2 *)calloc(1, sizeof(Uid_2));
  69. _DtCm_id4_to_id2(&(ui4->appt_id), &(ui2->appt_id));
  70. ui2->next = NULL;
  71. if (head == NULL)
  72. head = ui2;
  73. else
  74. prev->next = ui2;
  75. prev = ui2;
  76. ui4 = ui4->next;
  77. }
  78. return(head);
  79. }
  80. extern Appt_2 *
  81. _DtCm_appt4_to_appt2(Appt_4 *a4)
  82. {
  83. Appt_2 *a2, *head, *prev;
  84. struct Attribute_4 *item;
  85. prev = head = NULL;
  86. while (a4 != NULL) {
  87. a2 = (Appt_2 *)calloc(1, sizeof(Appt_2));
  88. _DtCm_id4_to_id2(&(a4->appt_id), &(a2->appt_id));
  89. a2->tag = tag4_to_tag2(a4->tag);
  90. a2->duration = a4->duration;
  91. a2->ntimes = a4->ntimes;
  92. a2->what = buffer4_to_buffer2(a4->what);
  93. a2->script = "";
  94. a2->period = period4_to_period2(&(a4->period));
  95. a2->author = buffer4_to_buffer2(a4->author);
  96. a2->client_data = buffer4_to_buffer2(a4->client_data);
  97. a2->attr = attr4_to_attr2(a4->attr);
  98. /* Pick the mailto field out of the attribute list
  99. client data field; put it back into the appt struct
  100. proper.
  101. */
  102. item = a4->attr;
  103. while(item!=NULL) {
  104. if (strcmp(item->attr, "ml")==0) {
  105. a2->mailto=buffer4_to_buffer2(item->clientdata);
  106. break;
  107. }
  108. item=item->next;
  109. }
  110. a2->exception = except4_to_except2(a4->exception);
  111. a2->next = NULL;
  112. if (head == NULL)
  113. head = a2;
  114. else
  115. prev->next = a2;
  116. prev = a2;
  117. a4 = a4->next;
  118. }
  119. return(head);
  120. }
  121. extern Access_Status_2
  122. _DtCm_accstat4_to_accstat2(Access_Status_4 s)
  123. {
  124. switch(s) {
  125. case access_ok_4:
  126. return(access_ok_2);
  127. case access_added_4:
  128. return(access_added_2);
  129. case access_removed_4:
  130. return(access_removed_2);
  131. case access_failed_4:
  132. return(access_failed_2);
  133. case access_exists_4:
  134. return(access_exists_2);
  135. case access_partial_4:
  136. return(access_partial_2);
  137. case access_other_4:
  138. default:
  139. return(access_other_2);
  140. }
  141. }
  142. extern Table_Res_2 *
  143. _DtCm_tableres4_to_tableres2(Table_Res_4 *r4)
  144. {
  145. Table_Res_2 *r2;
  146. if (r4==NULL) return((Table_Res_2 *)NULL);
  147. r2 = (Table_Res_2 *)calloc(1, sizeof(Table_Res_2));
  148. r2->status = _DtCm_accstat4_to_accstat2(r4->status);
  149. tablereslist4_to_tablereslist2(&(r4->res), &(r2->res));
  150. return(r2);
  151. }
  152. extern Access_Entry_2 *
  153. _DtCm_acclist4_to_acclist2(Access_Entry_4 *l4)
  154. {
  155. Access_Entry_2 *l2, *head, *prev;
  156. prev = head = NULL;
  157. while (l4 != NULL) {
  158. l2 = (Access_Entry_2 *)calloc(1, sizeof(Access_Entry_2));
  159. l2->who = buffer4_to_buffer2(l4->who);
  160. l2->access_type = l4->access_type;
  161. l2->next = NULL;
  162. if (head == NULL)
  163. head = l2;
  164. else
  165. prev->next = l2;
  166. prev = l2;
  167. l4 = l4->next;
  168. }
  169. return(head);
  170. }
  171. extern Access_Args_2 *
  172. _DtCm_accargs4_to_accargs2(Access_Args_4 *a4)
  173. {
  174. Access_Args_2 *a2;
  175. if (a4==NULL) return((Access_Args_2 *)NULL);
  176. a2 = (Access_Args_2 *)calloc(1, sizeof(Access_Args_2));
  177. a2->target = buffer4_to_buffer2(a4->target);
  178. a2->access_list = _DtCm_acclist4_to_acclist2(a4->access_list);
  179. return(a2);
  180. }
  181. extern Range_2 *
  182. _DtCm_range4_to_range2(Range_4 *r4)
  183. {
  184. Range_2 *r2, *head, *prev;
  185. prev = head = NULL;
  186. while (r4 != NULL) {
  187. r2 = (Range_2 *)calloc(1, sizeof(Range_2));
  188. r2->key1 = r4->key1;
  189. r2->key2 = r4->key2;
  190. r2->next = NULL;
  191. if (head == NULL)
  192. head = r2;
  193. else
  194. prev->next = r2;
  195. prev = r2;
  196. r4 = r4->next;
  197. }
  198. return(head);
  199. }
  200. extern Registration_Status_2
  201. _DtCm_regstat4_to_regstat2(Registration_Status_4 s)
  202. {
  203. switch (s) {
  204. case registered_4:
  205. return(registered_2);
  206. case failed_4:
  207. return(failed_2);
  208. case deregistered_4:
  209. return(deregistered_2);
  210. case confused_4:
  211. return(confused_2);
  212. case reg_notable_4:
  213. default:
  214. return(failed_2);
  215. }
  216. }
  217. extern Table_Status_2
  218. _DtCm_tablestat4_to_tablestat2(Table_Status_4 s)
  219. {
  220. switch(s) {
  221. case ok_4:
  222. return(ok_2);
  223. case duplicate_4:
  224. return(duplicate_2);
  225. case badtable_4:
  226. return(badtable_2);
  227. case notable_4:
  228. return(notable_2);
  229. case denied_4:
  230. return(denied_2);
  231. case other_4:
  232. default:
  233. return(other_2);
  234. }
  235. }
  236. extern Uid_2 *
  237. _DtCm_uidopt4_to_uid2(Uidopt_4 *uidopt)
  238. {
  239. Uid_2 *uid2, *head, *prev;
  240. prev = head = NULL;
  241. while (uidopt != NULL) {
  242. uid2 = (Uid_2 *)calloc(1, sizeof(Uid_2));
  243. _DtCm_id4_to_id2(&(uidopt->appt_id), &(uid2->appt_id));
  244. uid2->next = NULL;
  245. if (head == NULL)
  246. head = uid2;
  247. else
  248. prev->next = uid2;
  249. prev = uid2;
  250. uidopt = uidopt->next;
  251. }
  252. return(head);
  253. }
  254. extern void
  255. _DtCm_free_attr2(Attribute_2 *a)
  256. {
  257. Attribute_2 *ptr;
  258. while (a != NULL) {
  259. ptr = a->next;
  260. if (a->attr != NULL)
  261. free(a->attr);
  262. if (a->value != NULL)
  263. free(a->value);
  264. free(a);
  265. a = ptr;
  266. }
  267. }
  268. extern void
  269. _DtCm_free_appt2(Appt_2 *a)
  270. {
  271. Appt_2 *ptr;
  272. while (a != NULL) {
  273. ptr = a->next;
  274. if (a->what != NULL)
  275. free(a->what);
  276. if (a->mailto != NULL)
  277. free(a->mailto);
  278. if (a->script != NULL)
  279. free(a->script);
  280. if (a->author != NULL)
  281. free(a->author);
  282. if (a->client_data != NULL)
  283. free(a->client_data);
  284. if (a->attr != NULL)
  285. _DtCm_free_attr2(a->attr);
  286. if (a->exception != NULL)
  287. free_excpt2(a->exception);
  288. free(a);
  289. a = ptr;
  290. }
  291. }
  292. static void
  293. free_excpt2(Except_2 *e)
  294. {
  295. Except_2 *ptr;
  296. while (e != NULL) {
  297. ptr = e->next;
  298. free(e);
  299. e = ptr;
  300. }
  301. }
  302. static Buffer_2
  303. buffer4_to_buffer2(Buffer_4 b)
  304. {
  305. Buffer_2 copy;
  306. if (b!=NULL)
  307. copy = strdup(b);
  308. else
  309. copy = calloc(1, 1);
  310. return(copy);
  311. }
  312. /*
  313. * Repeating event types beyond "yearly" are mapped to "single"
  314. * because the old front end does not recognize any other types
  315. * Worse yet it uses Period_2 to index into an array which
  316. * contains strings up to "yearly", any period types beyond that
  317. * would index beyond the array and cause the front end to dump core.
  318. */
  319. static Period_2
  320. period4_to_period2(Period_4 *p)
  321. {
  322. if (p==NULL) return(otherPeriod_2);
  323. switch (p->period) {
  324. case single_4:
  325. return(single_2);
  326. case daily_4:
  327. return(daily_2);
  328. case weekly_4:
  329. return(weekly_2);
  330. case biweekly_4:
  331. return(biweekly_2);
  332. case monthly_4:
  333. return(monthly_2);
  334. case yearly_4:
  335. return(yearly_2);
  336. default:
  337. return(single_2);
  338. }
  339. }
  340. static Tag_2
  341. tag4_to_tag2(Tag_4 *t)
  342. {
  343. if (t==NULL) return(otherTag_2);
  344. switch(t->tag) {
  345. case appointment_4:
  346. return(appointment_2);
  347. case reminder_4:
  348. return(reminder_2);
  349. case otherTag_4:
  350. case holiday_4:
  351. case toDo_4:
  352. default:
  353. return(otherTag_2);
  354. }
  355. }
  356. static Attribute_2 *
  357. attr4_to_attr2(Attribute_4 *a4)
  358. {
  359. Attribute_2 *a2, *head, *prev;
  360. prev = head = NULL;
  361. while (a4 != NULL) {
  362. a2 = (Attribute_2 *)calloc(1, sizeof(Attribute_2));
  363. a2->next = NULL;
  364. a2->attr = strdup(a4->attr);
  365. a2->value = strdup(a4->value);
  366. if (head == NULL)
  367. head = a2;
  368. else
  369. prev->next = a2;
  370. prev = a2;
  371. a4 = a4->next;
  372. }
  373. return(head);
  374. }
  375. static Except_2 *
  376. except4_to_except2(Except_4 *e4)
  377. {
  378. Except_2 *e2, *head, *prev;
  379. prev = head = NULL;
  380. while (e4 != NULL) {
  381. e2 = (Except_2 *)calloc(1, sizeof(Except_2));
  382. e2->ordinal = e4->ordinal;
  383. e2->next=NULL;
  384. if (head == NULL)
  385. head = e2;
  386. else
  387. prev->next = e2;
  388. prev = e2;
  389. e4 = e4->next;
  390. }
  391. return(head);
  392. }
  393. static Abb_Appt_2 *
  394. abb4_to_abb2(Abb_Appt_4 *a4)
  395. {
  396. Abb_Appt_2 *a2, *head, *prev;
  397. prev = head = NULL;
  398. while (a4 != NULL) {
  399. a2 = (Abb_Appt_2 *)calloc(1, sizeof(Abb_Appt_2));
  400. _DtCm_id4_to_id2(&(a4->appt_id), &(a2->appt_id));
  401. a2->what = buffer4_to_buffer2(a4->what);
  402. a2->duration = a4->duration;
  403. a2->period = period4_to_period2(&(a4->period));
  404. a2->next = NULL;
  405. if (head == NULL)
  406. head = a2;
  407. else
  408. prev->next = a2;
  409. prev = a2;
  410. a4 = a4->next;
  411. }
  412. return(head);
  413. }
  414. static void
  415. apptid4_to_apptid2(Apptid_4 *from, Apptid_2 *to)
  416. {
  417. if (from==NULL || to==NULL) return;
  418. _DtCm_id4_to_id2(from->oid, to->oid);
  419. to->new_appt = _DtCm_appt4_to_appt2(from->new_appt);
  420. }
  421. static Reminder_2 *
  422. reminder4_to_reminder2(Reminder_4 *r4)
  423. {
  424. Reminder_2 *r2, *head, *prev;
  425. Attribute_2 *attr2;
  426. prev = head = NULL;
  427. while (r4 != NULL) {
  428. r2 = (Reminder_2 *)calloc(1, sizeof(Reminder_2));
  429. _DtCm_id4_to_id2(&(r4->appt_id), &(r2->appt_id));
  430. r2->tick = r4->tick;
  431. attr2 = attr4_to_attr2(&(r4->attr));
  432. r2->attr = *attr2;
  433. free(attr2);
  434. r2->next = NULL;
  435. if (head == NULL)
  436. head = r2;
  437. else
  438. prev->next = r2;
  439. prev = r2;
  440. r4 = r4->next;
  441. }
  442. return(head);
  443. }
  444. static Table_Res_Type_2
  445. tablerestype4_to_tablerestype2(Table_Res_Type_4 t)
  446. {
  447. switch(t) {
  448. case AP_4:
  449. return(AP_2);
  450. case RM_4:
  451. return(RM_2);
  452. case AB_4:
  453. return(AB_2);
  454. case ID_4:
  455. return(ID_2);
  456. default:
  457. return(AP_2);
  458. }
  459. }
  460. static void
  461. tablereslist4_to_tablereslist2(Table_Res_List_4 *from, Table_Res_List_2 *to)
  462. {
  463. if (from==NULL || to==NULL) return;
  464. to->tag = tablerestype4_to_tablerestype2(from->tag);
  465. switch (from->tag) {
  466. case AP_4:
  467. to->Table_Res_List_2_u.a = _DtCm_appt4_to_appt2(
  468. from->Table_Res_List_4_u.a);
  469. break;
  470. case RM_4:
  471. to->Table_Res_List_2_u.r = reminder4_to_reminder2(
  472. from->Table_Res_List_4_u.r);
  473. break;
  474. case AB_4:
  475. to->Table_Res_List_2_u.b = abb4_to_abb2(
  476. from->Table_Res_List_4_u.b);
  477. break;
  478. case ID_4:
  479. to->Table_Res_List_2_u.i = _DtCm_uid4_to_uid2(
  480. from->Table_Res_List_4_u.i);
  481. default:
  482. return;
  483. }
  484. }
  485. static Table_Args_Type_2
  486. argstag4_to_argstag2(Table_Args_Type_4 t)
  487. {
  488. switch(t) {
  489. case TICK_4:
  490. return(TICK_2);
  491. case APPTID_4:
  492. return(APPTID_2);
  493. case UID_4:
  494. return(UID_2);
  495. case APPT_4:
  496. return(APPT_2);
  497. case RANGE_4:
  498. return(RANGE_2);
  499. default:
  500. return(TICK_2);
  501. }
  502. }
  503. static void
  504. args4_to_args2(Args_4 *from, Args_2 *to)
  505. {
  506. if (from==NULL || to==NULL) return;
  507. to->tag = argstag4_to_argstag2(from->tag);
  508. switch(from->tag) {
  509. case TICK_4:
  510. to->Args_2_u.tick = from->Args_4_u.tick;
  511. break;
  512. case APPTID_4:
  513. to->Args_2_u.apptid.oid = (Id_2 *)calloc(1, sizeof(Id_2));
  514. apptid4_to_apptid2(
  515. &(from->Args_4_u.apptid),
  516. &(to->Args_2_u.apptid));
  517. break;
  518. case UID_4:
  519. to->Args_2_u.key = _DtCm_uid4_to_uid2(from->Args_4_u.key);
  520. break;
  521. case APPT_4:
  522. to->Args_2_u.appt = _DtCm_appt4_to_appt2(from->Args_4_u.appt);
  523. break;
  524. case RANGE_4:
  525. to->Args_2_u.range = _DtCm_range4_to_range2(from->Args_4_u.range);
  526. break;
  527. default:
  528. break;
  529. }
  530. }
  531. static Table_Args_2 *
  532. tableargs4_to_tableargs2(Table_Args_4 *a4)
  533. {
  534. Table_Args_2 *a2;
  535. if (a4==NULL) return((Table_Args_2 *)NULL);
  536. a2 = (Table_Args_2 *)calloc(1, sizeof(Table_Args_2));
  537. a2->target = buffer4_to_buffer2(a4->target);
  538. args4_to_args2(&(a4->args), &(a2->args));
  539. return(a2);
  540. }
  541. static Registration_2 *
  542. reg4_to_reg2(Registration_4 *r4)
  543. {
  544. Registration_2 *r2, *head, *prev;
  545. prev = head = NULL;
  546. while (r4 != NULL) {
  547. r2 = (Registration_2 *)calloc(1, sizeof(Registration_2));
  548. r2->target = buffer4_to_buffer2(r4->target);
  549. r2->prognum = r4->prognum;
  550. r2->versnum = r4->versnum;
  551. r2->procnum = r4->procnum;
  552. r2->next = NULL;
  553. if (head == NULL)
  554. head = r2;
  555. else
  556. prev->next = r2;
  557. prev = r2;
  558. r4 = r4->next;
  559. }
  560. return(head);
  561. }