token.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* This file is part of the software similarity tester SIM.
  2. Written by Dick Grune, Vrije Universiteit, Amsterdam.
  3. $Id: token.h,v 2.4 2001/11/13 12:55:59 dick Exp $
  4. */
  5. /*
  6. Token interface.
  7. Since the definition of a token has been a continual source of
  8. problems, it is now defined as an Abstract Data Type.
  9. To allow stronger type checking, there is a special version for use
  10. by lint.
  11. */
  12. #include <stdio.h>
  13. #ifndef TOKEN
  14. #ifdef lint
  15. #define TESTTOKEN
  16. #endif
  17. #ifdef TESTTOKEN /* strict version */
  18. struct cccc {
  19. int cccc;
  20. };
  21. typedef struct cccc *lintTOKEN;
  22. #define TOKEN lintTOKEN
  23. #define TOKEN2int(c) ((int)(c))
  24. #define int2TOKEN(i) ((TOKEN)(i))
  25. extern int TOKEN_EQ(TOKEN t1, TOKEN t2);
  26. #else /* production version */
  27. #define TOKEN unsigned char
  28. #define TOKEN2int(c) ((c)&0377)
  29. #define int2TOKEN(i) ((TOKEN)(i))
  30. #define TOKEN_EQ(t1,t2) (TOKEN2int(t1) == TOKEN2int(t2))
  31. #endif /* TESTTOKEN */
  32. #endif /* TOKEN */
  33. /* Macros for the composition of tokens */
  34. #define NORM(ch) int2TOKEN((ch)&0377)
  35. #define CTRL(ch) int2TOKEN((ch)&0037)
  36. #define META(ch) int2TOKEN((ch)|0200)
  37. #define MTCT(ch) int2TOKEN(((ch)&0037)|0200)
  38. #define NOTOKEN int2TOKEN(0)
  39. extern void print_token(FILE *ofile, TOKEN tk); /* in two characters */