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.

68 lines
1.8KB

  1. /*
  2. Functions to manage the format_specific_data chain
  3. Copyright (C) 2005 Ron Parker and Robert Lipe.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  15. */
  16. #include "defs.h"
  17. format_specific_data* fs_chain_copy(format_specific_data* source)
  18. {
  19. format_specific_data* result = NULL;
  20. format_specific_data** copy = &result;
  21. while (source) {
  22. source->copy((void**)copy, (void*)source);
  23. /* prevent segfaults from badly-behaved copy functions */
  24. (*copy)->next = NULL;
  25. copy = &((*copy)->next);
  26. source = source->next;
  27. }
  28. return result;
  29. }
  30. void fs_chain_destroy(format_specific_data* chain)
  31. {
  32. format_specific_data* cur = chain;
  33. format_specific_data* next = NULL;
  34. while (cur) {
  35. next = cur->next;
  36. cur->destroy(cur);
  37. cur = next;
  38. }
  39. }
  40. format_specific_data* fs_chain_find(format_specific_data* chain, long type)
  41. {
  42. format_specific_data* cur = chain;
  43. while (cur) {
  44. if (cur->type == type) {
  45. return cur;
  46. }
  47. cur = cur->next;
  48. }
  49. return NULL;
  50. }
  51. void fs_chain_add(format_specific_data** chain, format_specific_data* data)
  52. {
  53. data->next = *chain;
  54. *chain = data;
  55. }