Version.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 <https://www.gnu.org/licenses/>.
  14. */
  15. #include "util/Js.h"
  16. #define Version_COMPAT(one, twoRange) Js({ \
  17. this.Version_COMPAT = this.Version_COMPAT || []; \
  18. this.Version_COMPAT[one] = twoRange; \
  19. })
  20. #include "util/version/Version.h"
  21. static const uint8_t VERSION_MATRIX[Version_CURRENT_PROTOCOL+1][Version_CURRENT_PROTOCOL+1] =
  22. Js_or({
  23. var matrix = [];
  24. for (var i = 0; i <= Version_CURRENT_PROTOCOL; i++) {
  25. var row = matrix[matrix.length] = [];
  26. for (var j = 0; j <= Version_CURRENT_PROTOCOL; j++) {
  27. if (j == i) {
  28. row[j] = 1;
  29. } else {
  30. row[j] =
  31. (this.Version_COMPAT[Math.max(i, j)].indexOf(Math.min(i,j)) > -1) ? 1 : 0;
  32. }
  33. }
  34. }
  35. return JSON.stringify(matrix).replace(/\[/g,'{').replace(/\]/g,'}');
  36. }, {});
  37. int Version_isCompatible(uint32_t one, uint32_t two)
  38. {
  39. if (one > Version_CURRENT_PROTOCOL) { one = Version_CURRENT_PROTOCOL; }
  40. if (two > Version_CURRENT_PROTOCOL) { two = Version_CURRENT_PROTOCOL; }
  41. return VERSION_MATRIX[one][two];
  42. }