merge_ctxt.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @file merge_ctxt.c
  3. */
  4. /*
  5. * This program is free software: you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation, either vers* ion 3 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see
  17. * <http://www.gnu.org/licenses/>.
  18. */
  19. #include "stdlib.h"
  20. #include "string.h"
  21. #include "config.h"
  22. #include "gl_list.h"
  23. #include "gl_array_list.h"
  24. #include "smerger.h"
  25. #include "merge_ctxt.h"
  26. size_t default_priorities_count = 3;
  27. const char *default_priorities[] = { "A", "B", "C" };
  28. /**
  29. * @brief Create the default set of accepted priorities.
  30. */
  31. static gl_list_t merge_ctxt_create_default_priorities ();
  32. void
  33. merge_ctxt_init (merge_ctxt *ctxt)
  34. {
  35. ctxt->strategy = NO_STRATEGY;
  36. ctxt->global_smerger = NULL;
  37. ctxt->priorities = NULL;
  38. return;
  39. }
  40. void
  41. merge_ctxt_free (merge_ctxt *ctxt)
  42. {
  43. smerger_free (ctxt->global_smerger);
  44. gl_list_free (ctxt->priorities);
  45. return;
  46. }
  47. void
  48. merge_ctxt_set_defaults (merge_ctxt *ctxt)
  49. {
  50. if (ctxt->global_smerger == NULL)
  51. {
  52. ctxt->global_smerger = smerger_create ();
  53. }
  54. if (ctxt->priorities == NULL)
  55. {
  56. ctxt->priorities = merge_ctxt_create_default_priorities ();
  57. }
  58. return;
  59. }
  60. static gl_list_t
  61. merge_ctxt_create_default_priorities ()
  62. {
  63. gl_list_t list =
  64. gl_list_nx_create_empty (GL_ARRAY_LIST, NULL, NULL, NULL, true);
  65. int i = 0;
  66. for (i = 0; i < default_priorities_count; i++)
  67. {
  68. gl_list_nx_add_last (list, default_priorities[i]);
  69. }
  70. return list;
  71. }