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.

validate.cc 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. validate internal data structures.
  3. Copyright (C) 2013 Robert Lipe robertlipe+source@gpsbabel.org
  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. #include "filterdefs.h"
  18. #include <stdio.h>
  19. #if FILTERS_ENABLED
  20. #define MYNAME "validate"
  21. static char* opt_debug;
  22. bool debug;
  23. static char* opt_checkempty;
  24. bool checkempty;
  25. static unsigned int point_ct;
  26. static unsigned int head_ct;
  27. static unsigned int segment_ct_start;
  28. static const char* segment_type;
  29. static
  30. arglist_t validate_args[] = {
  31. {
  32. "checkempty", &opt_checkempty, "Check for empty input",
  33. "0", ARGTYPE_BOOL, ARG_NOMINMAX
  34. } ,
  35. {
  36. "debug", &opt_debug, "Output debug messages instead of possibly issuing a fatal error",
  37. "0", ARGTYPE_BOOL, ARG_NOMINMAX
  38. } ,
  39. ARG_TERMINATOR
  40. };
  41. static void validate_head(const route_head* header)
  42. {
  43. head_ct += 1;
  44. segment_ct_start = point_ct;
  45. }
  46. static void validate_head_trl(const route_head* header)
  47. {
  48. int segment_waypt_ct = point_ct - segment_ct_start;
  49. if (debug) {
  50. fprintf(stderr, "%s %d ct: %d, waypt_count: %d\n", segment_type, header->rte_num, segment_waypt_ct, header->rte_waypt_ct);
  51. }
  52. if (!debug && (segment_waypt_ct != header->rte_waypt_ct)) {
  53. fatal(MYNAME ":%s %d count mismatch, expected %d, actual %d\n", segment_type, header->rte_num, header->rte_waypt_ct, segment_waypt_ct);
  54. }
  55. }
  56. static void validate_point(const Waypoint* waypointp)
  57. {
  58. point_ct += 1;
  59. }
  60. static void
  61. validate_process(void)
  62. {
  63. debug = *opt_debug == '1';
  64. checkempty = *opt_checkempty == '1';
  65. point_ct = 0;
  66. if (debug) {
  67. fprintf(stderr, "\nProcessing waypts\n");
  68. }
  69. waypt_disp_all(validate_point);
  70. if (debug) {
  71. fprintf(stderr, "point ct: %d, waypt_count: %d\n", point_ct, waypt_count());
  72. }
  73. if (!debug && (point_ct != waypt_count())) {
  74. fatal(MYNAME ":Waypoint count mismatch, expected %d, actual %d\n", waypt_count(), point_ct);
  75. }
  76. head_ct = 0;
  77. point_ct = 0;
  78. segment_type = "route";
  79. if (debug) {
  80. fprintf(stderr, "\nProcessing routes\n");
  81. }
  82. route_disp_all(validate_head, validate_head_trl, validate_point);
  83. if (debug) {
  84. fprintf(stderr, "route head ct: %d, route_count: %d\n", head_ct, route_count());
  85. fprintf(stderr, "total route point ct: %d, route_waypt_count: %d\n", point_ct, route_waypt_count());
  86. }
  87. if (!debug && (head_ct != route_count())) {
  88. fatal(MYNAME ":Route count mismatch, expected %d, actual %d\n", route_count(), head_ct);
  89. }
  90. if (!debug && (point_ct != route_waypt_count())) {
  91. fatal(MYNAME ":Total route waypoint count mismatch, expected %d, actual %d\n", route_waypt_count(), point_ct);
  92. }
  93. head_ct = 0;
  94. point_ct = 0;
  95. segment_type = "track";
  96. if (debug) {
  97. fprintf(stderr, "\nProcessing tracks\n");
  98. }
  99. track_disp_all(validate_head, validate_head_trl, validate_point);
  100. if (debug) {
  101. fprintf(stderr, "track head ct: %d, track_count: %d\n", head_ct, track_count());
  102. fprintf(stderr, "total track point ct: %d, track_waypt_count: %d\n", point_ct, track_waypt_count());
  103. }
  104. if (!debug && (head_ct != track_count())) {
  105. fatal(MYNAME ":Track count mismatch, expected %d, actual %d\n", track_count(), head_ct);
  106. }
  107. if (!debug && (point_ct != track_waypt_count())) {
  108. fatal(MYNAME ":Total track waypoint count mismatch, expected %d, actual %d\n", track_waypt_count(), point_ct);
  109. }
  110. if (checkempty) {
  111. if (waypt_count()==0 && route_waypt_count()==0 && track_waypt_count()==0) {
  112. fatal(MYNAME ":No input\n");
  113. }
  114. }
  115. }
  116. filter_vecs_t validate_vecs = {
  117. NULL,
  118. validate_process,
  119. NULL,
  120. NULL,
  121. validate_args
  122. };
  123. #endif