xor.c 782 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. #include "globals.h"
  4. #include "expression.h"
  5. #include "func_proto.h"
  6. /****************************************************************
  7. or(a,b,c,...) = a || b || c || ...
  8. ****************************************************************/
  9. int f_or(int argc, const int *argt, void **args)
  10. {
  11. CELL *res = args[0];
  12. int i, j;
  13. if (argc < 1)
  14. return E_ARG_LO;
  15. if (argt[0] != CELL_TYPE)
  16. return E_RES_TYPE;
  17. for (i = 1; i <= argc; i++)
  18. if (argt[i] != argt[0])
  19. return E_ARG_TYPE;
  20. for (i = 0; i < columns; i++) {
  21. res[i] = 0;
  22. for (j = 1; j <= argc; j++) {
  23. CELL *arg = args[j];
  24. if (IS_NULL_C(&arg[i])) {
  25. SET_NULL_C(&res[i]);
  26. break;
  27. }
  28. if (arg[i])
  29. res[i] = 1;
  30. }
  31. }
  32. return 0;
  33. }