Version.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #define Version_COMPAT(one, twoRange) <?js \
  16. file.Version_COMPAT = file.Version_COMPAT || []; \
  17. file.Version_COMPAT[one] = twoRange; \
  18. ?>
  19. #include "util/version/Version.h"
  20. static const uint8_t VERSION_MATRIX[Version_CURRENT_PROTOCOL+1][Version_CURRENT_PROTOCOL+1] =
  21. <?js
  22. var matrix = [];
  23. for (var i = 0; i <= Version_CURRENT_PROTOCOL; i++) {
  24. var row = matrix[matrix.length] = [];
  25. for (var j = 0; j <= Version_CURRENT_PROTOCOL; j++) {
  26. if (j == i) {
  27. row[j] = 1;
  28. } else {
  29. row[j] =
  30. (file.Version_COMPAT[Math.max(i, j)].indexOf(Math.min(i,j)) > -1) ? 1 : 0;
  31. }
  32. }
  33. }
  34. return JSON.stringify(matrix).replace(/\[/g,'{').replace(/\]/g,'}');
  35. ?>;
  36. int Version_isCompatible(uint32_t one, uint32_t two)
  37. {
  38. if (one > Version_CURRENT_PROTOCOL) { one = Version_CURRENT_PROTOCOL; }
  39. if (two > Version_CURRENT_PROTOCOL) { two = Version_CURRENT_PROTOCOL; }
  40. return VERSION_MATRIX[one][two];
  41. }