Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.6 KiB

  1. /* @(#)CM_VerSion xcf_da.c atm08 1.6 16343.eco sum= 41325 atm08.005 */
  2. /***********************************************************************/
  3. /* */
  4. /* Copyright 1990-1994 Adobe Systems Incorporated. */
  5. /* All rights reserved. */
  6. /* */
  7. /* Patents Pending */
  8. /* */
  9. /* NOTICE: All information contained herein is the property of Adobe */
  10. /* Systems Incorporated. Many of the intellectual and technical */
  11. /* concepts contained herein are proprietary to Adobe, are protected */
  12. /* as trade secrets, and are made available only to Adobe licensees */
  13. /* for their internal use. Any reproduction or dissemination of this */
  14. /* software is strictly forbidden unless prior written permission is */
  15. /* obtained from Adobe. */
  16. /* */
  17. /* PostScript and Display PostScript are trademarks of Adobe Systems */
  18. /* Incorporated or its subsidiaries and may be registered in certain */
  19. /* jurisdictions. */
  20. /* */
  21. /***********************************************************************
  22. * SCCS Id: %W%
  23. * Changed: %G% %U%
  24. ***********************************************************************/
  25. /* This code was taken from Jerry Hall by John Felton on 3/26/96 */
  26. /*
  27. * Dynamic array support.
  28. */
  29. /* #include "lstdio.h" */
  30. #include "xcf_da.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Dynamic array object template */
  35. typedef da_DCL(void, DA);
  36. /* Initialize dynamic array */
  37. void xcf_da_Init (void PTR_PREFIX * object, ULONG_PTR intl, unsigned long incr, AllocFunc alloc, void PTR_PREFIX *clientHook)
  38. {
  39. DA PTR_PREFIX *da = (DA PTR_PREFIX *)object;
  40. da->array = (void *)intl;
  41. da->cnt = 0;
  42. da->size = 0;
  43. da->incr = incr;
  44. da->init = (int (*)(void PTR_PREFIX*))NULL;
  45. da->alloc = alloc;
  46. da->hook = clientHook;
  47. }
  48. /* Grow dynamic array to accomodate index */
  49. void xcf_da_Grow (void PTR_PREFIX *object, size_t element, unsigned long index)
  50. {
  51. DA PTR_PREFIX *da = (DA PTR_PREFIX *)object;
  52. unsigned long newSize;
  53. if (da->size == 0)
  54. {
  55. /* Initial allocation */
  56. unsigned long intl = (unsigned long)(ULONG_PTR)da->array;
  57. da->array = NULL;
  58. newSize = (index < intl)? intl:
  59. intl + ((index - intl) + da->incr) / da->incr * da->incr;
  60. }
  61. else
  62. {
  63. /* Incremental allocation */
  64. newSize = da->size +
  65. ((index - da->size) + da->incr) / da->incr * da->incr;
  66. }
  67. (*da->alloc)((void PTR_PREFIX * PTR_PREFIX *)&da->array, newSize * element, da->hook);
  68. if (da->init != (int (*)(void PTR_PREFIX*))NULL &&
  69. da->array != NULL)
  70. {
  71. /* Initialize new elements */
  72. char *p;
  73. for (p = &((char *)da->array)[da->size * element];
  74. p < &((char *)da->array)[newSize * element];
  75. p += element)
  76. if (da->init(p))
  77. break; /* Client function wants to stop */
  78. }
  79. da->size = newSize;
  80. }
  81. /* Free dynamic array */
  82. void xcf_da_Free(void PTR_PREFIX * object)
  83. {
  84. DA PTR_PREFIX *da = (DA PTR_PREFIX *)object;
  85. if (da->size != 0)
  86. {
  87. da->alloc((void PTR_PREFIX * PTR_PREFIX *)&da->array, 0, da->hook); /* Free array storage */
  88. da->size = 0;
  89. }
  90. }
  91. #ifdef __cplusplus
  92. }
  93. #endif