l_comment.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Header$ */
  6. /* Lint-specific comment handling */
  7. #include "lint.h"
  8. #ifdef LINT
  9. #include "arith.h"
  10. #include "l_state.h"
  11. static int NOTREACHED;
  12. static int VARARGSn = -1;
  13. static int ARGSUSED;
  14. int LINTLIB;
  15. int s_NOTREACHED;
  16. int f_VARARGSn;
  17. int f_ARGSUSED;
  18. set_not_reached()
  19. {
  20. NOTREACHED = 1;
  21. }
  22. move_NOT2s()
  23. {
  24. s_NOTREACHED = NOTREACHED;
  25. NOTREACHED = 0;
  26. }
  27. set_varargs(n)
  28. {
  29. VARARGSn = n;
  30. }
  31. move_VAR2f()
  32. {
  33. f_VARARGSn = VARARGSn;
  34. VARARGSn = -1;
  35. }
  36. set_argsused(n)
  37. {
  38. ARGSUSED = n;
  39. }
  40. move_ARG2f()
  41. {
  42. f_ARGSUSED = ARGSUSED;
  43. ARGSUSED = 0;
  44. }
  45. set_lintlib()
  46. {
  47. LINTLIB = 1;
  48. }
  49. #define IN_SPACE 0
  50. #define IN_WORD 1
  51. #define IN_COMMENT 2
  52. lint_comment(c)
  53. int c;
  54. {
  55. /* This function is called with every character between /_* and *_/ (the
  56. * _underscores are used because comment in C doesn't nest).
  57. * It looks for pseudocomments.
  58. * In this version it is allowed that 'keyword' is followed by rubbish.
  59. * At the start of each comment the function should be initialized by
  60. * calling it with c = -2.
  61. * I am not sure if this way of information hiding is a good solution.
  62. */
  63. static int position; /* IN_SPACE, IN_WORD, IN_COMMENT */
  64. static char buf[12];
  65. static int i; /* next free position in buf */
  66. if (c == -2) {
  67. position = IN_SPACE;
  68. i = 0;
  69. return;
  70. }
  71. if (position == IN_COMMENT)
  72. return;
  73. if (position == IN_SPACE) {
  74. if (c == ' ' || c == '\t')
  75. return;
  76. position = IN_WORD;
  77. }
  78. /* position == IN_WORD */
  79. if (c == ' ' || c == '\t' || c == '*') {
  80. position = IN_COMMENT;
  81. check_pseudo(buf, i);
  82. }
  83. else
  84. if (i < 12)
  85. buf[i++] = (char)c;
  86. else
  87. position = IN_COMMENT;
  88. }
  89. #include <ctype.h>
  90. check_pseudo(buf, i)
  91. char *buf;
  92. {
  93. /* Look if the i characters in buf are aequivalent with one of the
  94. * strings N_OTREACHED, V_ARARGS[n], A_RGSUSED, L_INTLIBRARY
  95. * (the u_nderscores are there to not confuse (UNIX) lint)
  96. */
  97. buf[i++] = '\0';
  98. if (!strcmp(buf, "NOTREACHED"))
  99. set_not_reached();
  100. else if (!strcmp(buf, "ARGSUSED"))
  101. set_argsused(1);
  102. else if (!strcmp(buf, "LINTLIBRARY"))
  103. set_lintlib();
  104. else if (!strncmp(buf, "VARARGS", 7)) {
  105. if (i == 8)
  106. set_varargs(0);
  107. else if (i == 9 && isdigit(buf[7]))
  108. set_varargs(atoi(&buf[7]));
  109. }
  110. }
  111. #endif LINT