Git init
[external/mawk.git] / examples / eatc.awk
1 #!/usr/bin/mawk -f
2
3 #  eatc.awk
4 #  another program to remove comments
5 #
6
7
8 {  while( t = index($0 , "/*") )
9    {
10      printf "%s" , substr($0,1,t-1)
11      $0 = eat_comment( substr($0, t+2) )
12    }
13
14    print 
15 }
16
17
18 function eat_comment(s,         t)
19 {
20   #replace comment by one space
21   printf " "
22
23   while ( (t = index(s, "*/")) == 0 )
24         if ( getline s == 0 )
25         { # input error -- unterminated comment
26           system("/bin/sh -c 'echo unterminated comment' 1>&2")
27           exit 1
28         }
29
30   return  substr(s,t+2)
31 }
32