cmsdata.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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: cmsdata.c /main/1 1996/04/21 19:22:08 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 <stdio.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include "csa.h"
  35. #include "cmsdata.h"
  36. #include "nametbl.h"
  37. #include "attr.h"
  38. /* standard calendar attr name and entry attr name table */
  39. _DtCmNameTable *_DtCm_cal_name_tbl = NULL;
  40. _DtCmNameTable *_DtCm_entry_name_tbl = NULL;
  41. /*
  42. * allocate a cms_entry structure and initialized with
  43. * all the library defined attribute names
  44. */
  45. extern cms_entry *
  46. _DtCm_make_cms_entry(_DtCmNameTable *tbl)
  47. {
  48. int i;
  49. cms_entry *ptr;
  50. if ((ptr = (cms_entry *)calloc(1, sizeof(cms_entry))) == NULL)
  51. return (NULL);
  52. /* initialize the entry with attribute names */
  53. if ((ptr->attrs = (cms_attribute *)calloc(1,
  54. sizeof(cms_attribute)*(tbl->size + 1))) == NULL) {
  55. free(ptr);
  56. return (NULL);
  57. }
  58. for (i = 1; i <= tbl->size; i++) {
  59. if ((ptr->attrs[i].name.name = strdup(tbl->names[i])) == NULL) {
  60. /* clean up */
  61. ptr->num_attrs = i - 1;
  62. _DtCm_free_cms_entry(ptr);
  63. return (NULL);
  64. }
  65. ptr->attrs[i].name.num = i;
  66. }
  67. ptr->num_attrs = tbl->size;
  68. return (ptr);
  69. }
  70. extern CSA_return_code
  71. _DtCm_copy_cms_entry(cms_entry *e, cms_entry **e_r)
  72. {
  73. cms_entry *ptr;
  74. CSA_return_code stat;
  75. if (e == NULL || e_r == NULL)
  76. return (CSA_E_INVALID_PARAMETER);
  77. if ((ptr = (cms_entry *)calloc(1, sizeof(cms_entry))) == NULL)
  78. return (CSA_E_INSUFFICIENT_MEMORY);
  79. if ((stat = _DtCm_copy_cms_attributes(e->num_attrs, e->attrs,
  80. &ptr->num_attrs, &ptr->attrs)) != CSA_SUCCESS) {
  81. free(ptr);
  82. return (stat);
  83. } else {
  84. ptr->key = e->key;
  85. *e_r = ptr;
  86. return (CSA_SUCCESS);
  87. }
  88. }
  89. extern void
  90. _DtCm_free_cms_entry(cms_entry *entry)
  91. {
  92. if (entry == NULL)
  93. return;
  94. if (entry->num_attrs > 0) {
  95. _DtCm_free_cms_attributes(entry->num_attrs + 1, entry->attrs);
  96. free(entry->attrs);
  97. }
  98. free(entry);
  99. }
  100. extern void
  101. _DtCm_free_cms_entries(cms_entry *entry)
  102. {
  103. cms_entry *ptr;
  104. while (entry) {
  105. ptr = entry->next;
  106. _DtCm_free_cms_entry(entry);
  107. entry = ptr;
  108. }
  109. }
  110. extern void
  111. _DtCm_init_hash(void)
  112. {
  113. static boolean_t done = B_FALSE;
  114. if (done == B_FALSE) {
  115. /* need to check whether table is actually created */
  116. _DtCm_cal_name_tbl = _DtCm_make_name_table(
  117. _DtCM_DEFINED_CAL_ATTR_SIZE,
  118. _CSA_calendar_attribute_names);
  119. _DtCm_entry_name_tbl = _DtCm_make_name_table(
  120. _DtCM_DEFINED_ENTRY_ATTR_SIZE,
  121. _CSA_entry_attribute_names);
  122. done = B_TRUE;
  123. }
  124. }
  125. /*
  126. * attr->name.num contains the correct index for the attribute
  127. */
  128. extern CSA_return_code
  129. _DtCmGrowAttrArray(uint *num_attrs, cms_attribute **attrs, cms_attribute *attr)
  130. {
  131. cms_attribute *newptr;
  132. CSA_return_code stat;
  133. int index;
  134. index = attr->name.num;
  135. if ((newptr = (cms_attribute *)realloc(*attrs,
  136. sizeof(cms_attribute) * (index + 1))) == NULL)
  137. return (CSA_E_INSUFFICIENT_MEMORY);
  138. else {
  139. *attrs = newptr;
  140. memset((void *)&(*attrs)[*num_attrs+1], 0,
  141. sizeof(cms_attribute) * (index - *num_attrs));
  142. }
  143. if ((stat = _DtCm_copy_cms_attribute(&(*attrs)[index], attr, B_TRUE))
  144. == CSA_SUCCESS) {
  145. *num_attrs = index;
  146. }
  147. return (stat);
  148. }