isdlink.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $TOG: isdlink.c /main/4 1999/09/29 15:03:15 mgreess $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isdlink.c
  33. *
  34. * Description:
  35. * Double link list functions
  36. */
  37. #include "isam_impl.h"
  38. /* _isdln_base_insert () - Insert element into list (at the front) -----------*/
  39. void _isdln_base_insert (char *base, struct dlink *l,
  40. struct dlink *e)
  41. {
  42. e->dln_forward = l->dln_forward;
  43. l->dln_forward = (char *)e - base;
  44. e->dln_backward = (char *)l - base;
  45. ((struct dlink *)(base + e->dln_forward))->dln_backward = (char *)e - base;
  46. }
  47. /* _isdln_base_append () - Append element to list (at the end) -------------*/
  48. void _isdln_base_append (char *base, struct dlink *l,
  49. struct dlink *e)
  50. {
  51. e->dln_backward = l->dln_backward;
  52. l->dln_backward = (char *)e - base;
  53. e->dln_forward = (char *)l - base;
  54. ((struct dlink *)(base + e->dln_backward))->dln_forward = (char *)e - base;
  55. }
  56. /* _isdln_base_remove () - Remove element from list -------------------------*/
  57. void _isdln_base_remove (char *base, struct dlink *e)
  58. {
  59. ((struct dlink *)(base + e->dln_backward))->dln_forward = e->dln_forward;
  60. ((struct dlink *)(base + e->dln_forward))->dln_backward = e->dln_backward;
  61. }
  62. /* _isdln_base_first () - Return first element of the list -------------------*/
  63. struct dlink * _isdln_base_first(char *base, struct dlink *l)
  64. {
  65. struct dlink *val = (struct dlink *)(base + l->dln_forward);
  66. if (val == NULL) {
  67. if (NULL == (struct dlink *)(base + l->dln_forward) &&
  68. NULL == (struct dlink *)(base + l->dln_backward))
  69. _isdln_base_makeempty(base, l);
  70. val = l;
  71. }
  72. return(val);
  73. }
  74. /* _isdln_base_next () - Return next element in the list --------------------*/
  75. struct dlink * _isdln_base_next(char *base, struct dlink *l)
  76. {
  77. return (((struct dlink *)(base + l->dln_forward)));
  78. }
  79. /* _isdln_base_prev () - Return previous element in the list ----------------*/
  80. struct dlink * _isdln_base_prev(char *base, struct dlink *l)
  81. {
  82. return (((struct dlink *)(base + l->dln_backward)));
  83. }
  84. /* _isdln_base_makeempty () - Make head of empty list -----------------------*/
  85. void _isdln_base_makeempty(char *base, struct dlink *l)
  86. {
  87. l->dln_forward = l->dln_backward = (char *)l - base;
  88. }
  89. /* _isdln_base_isempty () - Test if list is empty---------------------------*/
  90. int _isdln_base_isempty(char *base, struct dlink *l)
  91. {
  92. return (l->dln_forward == (char *)l - base &&
  93. l->dln_backward == (char *)l - base);
  94. }