home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / ifdef < prev    next >
Text File  |  2020-01-01  |  771b  |  40 lines

  1. #!/usr/local/bin/kermit +
  2. #
  3. # ifdef
  4. #
  5. # A simple tool to check big C source files for #if/#ifdef/#ifndef..#endif
  6. # structure, handy for finding mismatches.
  7. #
  8. # F. da Cruz, Columbia University, October 2009
  9. #
  10. define display {
  11.     .\%9 ::= (\m(depth) * 2) - 2
  12.     echo "\flpad(\m(n),6). [\m(depth)] \frepeat(\32,\%9)\m(line)"
  13. }
  14. if not def \%1 exit 1 "usage: \%0 filename"
  15. fopen /read \%c \%1
  16. if fail exit 1
  17. .depth = 0
  18. .n = 0
  19. while 1 {
  20.     fread /line \%c line
  21.     if fail break
  22.     incr n
  23.     .line := \fleft(\funtabify(\m(line)),40)
  24.     if < \flen(\m(line)) 6 continue
  25.     switch \m(line) {
  26.       :#if*
  27.         incr depth
  28.         display
  29.         break
  30.       :#endif*
  31.         display
  32.         decr depth
  33.         break
  34.       :default
  35.         continue
  36.     }
  37. }
  38. fclose \%c
  39. exit
  40.