flag.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef __FLAG_H__
  2. #define __FLAG_H__
  3. /* flag.[ch] is a set of routines which will set up an array of bits
  4. ** that allow the programmer to "flag" cells in a raster map.
  5. **
  6. ** FLAG *
  7. ** flag_create(nrows,ncols)
  8. ** int nrows, ncols;
  9. ** opens the structure flag.
  10. ** The flag structure will be a two dimensional array of bits the
  11. ** size of nrows by ncols. Will initalize flags to zero (unset).
  12. **
  13. ** flag_destroy(flags)
  14. ** FLAG *flags;
  15. ** closes flags and gives the memory back to the system.
  16. **
  17. ** flag_clear_all(flags)
  18. ** FLAG *flags;
  19. ** sets all values in flags to zero.
  20. **
  21. ** flag_unset(flags, row, col)
  22. ** FLAG *flags;
  23. ** int row, col;
  24. ** sets the value of (row, col) in flags to zero.
  25. **
  26. ** flag_set(flags, row, col)
  27. ** FLAG *flags;
  28. ** int row, col;
  29. ** will set the value of (row, col) in flags to one.
  30. **
  31. ** int
  32. ** flag_get(flags, row, col)
  33. ** FLAG *flags;
  34. ** int row, col;
  35. ** returns the value in flags that is at (row, col).
  36. **
  37. ** idea by Michael Shapiro
  38. ** code by Chuck Ehlschlaeger
  39. ** April 03, 1989
  40. */
  41. #define FLAG struct _flagsss_
  42. FLAG {
  43. int nrows, ncols, leng;
  44. unsigned char **array;
  45. };
  46. #define FLAG_UNSET(flags,row,col) \
  47. (flags)->array[(row)][(col)>>3] &= ~(1<<((col) & 7))
  48. #define FLAG_SET(flags,row,col) \
  49. (flags)->array[(row)][(col)>>3] |= (1<<((col) & 7))
  50. #define FLAG_GET(flags,row,col) \
  51. (flags)->array[(row)][(col)>>3] & (1<<((col) & 7))
  52. /* flag.c */
  53. FLAG *flag_create(int, int);
  54. int flag_destroy(FLAG *);
  55. int flag_clear_all(FLAG *);
  56. #endif /* __FLAG_H__ */