xor2.c 875 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include <grass/calc.h>
  4. /****************************************************************
  5. or2(a,b,c,...) = a || b || c || ...
  6. Differs from or() in that the boolean axioms:
  7. true || x == true
  8. x || true == true
  9. hold even when x is null.
  10. ****************************************************************/
  11. int f_or2(int argc, const int *argt, void **args)
  12. {
  13. CELL *res = args[0];
  14. int i, j;
  15. if (argc < 1)
  16. return E_ARG_LO;
  17. if (argt[0] != CELL_TYPE)
  18. return E_RES_TYPE;
  19. for (i = 1; i <= argc; i++)
  20. if (argt[i] != argt[0])
  21. return E_ARG_TYPE;
  22. for (i = 0; i < columns; i++) {
  23. res[i] = 0;
  24. for (j = 1; j <= argc; j++) {
  25. CELL *arg = args[j];
  26. if (!IS_NULL_C(&arg[i]) && arg[i]) {
  27. res[i] = 1;
  28. break;
  29. }
  30. if (IS_NULL_C(&arg[i]))
  31. SET_NULL_C(&res[i]);
  32. }
  33. }
  34. return 0;
  35. }