token.c 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* This file is part of the software similarity tester SIM.
  2. Written by Dick Grune, Vrije Universiteit, Amsterdam.
  3. $Id: token.c,v 2.4 2001/11/13 12:55:58 dick Exp $
  4. */
  5. /*
  6. Token interface, implementation part.
  7. */
  8. #include <stdio.h>
  9. #include "token.h"
  10. void
  11. print_token(FILE *ofile, TOKEN tk) {
  12. /* prints a token, in two characters:
  13. normal char meta (bit 8 set)
  14. ^A cntl $A meta-cntl
  15. A printable #A meta
  16. ^? DEL $? meta-DEL
  17. */
  18. register int ch = TOKEN2int(tk) & 0177;
  19. register int meta = TOKEN2int(tk) & 0200;
  20. if (' ' <= ch && ch <= '~') {
  21. fprintf(ofile, "%c%c", (meta ? '#' : ' '), ch);
  22. }
  23. else {
  24. fprintf(ofile, "%c%c",
  25. (meta ? '$' : '^'),
  26. (ch == 0177 ? '?' : ch + '@')
  27. );
  28. }
  29. }
  30. #ifdef TESTTOKEN
  31. int
  32. TOKEN_EQ(TOKEN t1, TOKEN t2) {
  33. /* to make sure TOKEN_EQ is indeed called with two TOKEN parameters */
  34. return TOKEN2int(t1) == TOKEN2int(t2);
  35. }
  36. #endif /* TESTTOKEN */