dvbscan_structutils.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. dvbscan utility
  3. Copyright (C) 2006 Andrew de Quincey (adq_dvb@lidskialf.net)
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include "dvbscan.h"
  20. void append_transponder(struct transponder *t, struct transponder **tlist, struct transponder **tlist_end)
  21. {
  22. if (*tlist_end == NULL) {
  23. *tlist = t;
  24. } else {
  25. (*tlist_end)->next = t;
  26. }
  27. *tlist_end = t;
  28. t->next = NULL;
  29. }
  30. struct transponder *new_transponder(void)
  31. {
  32. struct transponder *t = (struct transponder *) malloc(sizeof(struct transponder));
  33. if (t == NULL) {
  34. fprintf(stderr, "Out of memory\n");
  35. exit(1);
  36. }
  37. memset(t, 0, sizeof(struct transponder));
  38. return t;
  39. }
  40. void free_transponder(struct transponder *t)
  41. {
  42. if (t->frequencies)
  43. free(t->frequencies);
  44. // FIXME: free services
  45. free(t);
  46. }
  47. int seen_transponder(struct transponder *t, struct transponder *checklist)
  48. {
  49. uint32_t i;
  50. struct transponder *cur_check = checklist;
  51. while(cur_check) {
  52. uint32_t freq1 = cur_check->params.frequency / 2000;
  53. for(i=0; i < t->frequency_count; i++) {
  54. uint32_t freq2 = t->frequencies[i] / 2000;
  55. if (freq1 == freq2) {
  56. return 1;
  57. }
  58. }
  59. cur_check = cur_check->next;
  60. }
  61. return 0;
  62. }
  63. void add_frequency(struct transponder *t, uint32_t frequency)
  64. {
  65. uint32_t *tmp;
  66. tmp = (uint32_t*) realloc(t->frequencies, sizeof(uint32_t) * (t->frequency_count + 1));
  67. if (tmp == NULL) {
  68. fprintf(stderr, "Out of memory\n");
  69. exit(1);
  70. }
  71. tmp[t->frequency_count++] = frequency;
  72. t->frequencies = tmp;
  73. }
  74. struct transponder *first_transponder(struct transponder **tlist, struct transponder **tlist_end)
  75. {
  76. struct transponder *t = *tlist;
  77. *tlist = t->next;
  78. if (*tlist == NULL)
  79. *tlist_end = NULL;
  80. return t;
  81. }