File: nocomment.awk

package info (click to toggle)
mawk 1.3.3-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,244 kB
  • ctags: 1,512
  • sloc: ansic: 13,008; sh: 1,337; yacc: 994; awk: 629; makefile: 150
file content (30 lines) | stat: -rw-r--r-- 571 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# remove C comments  from a list of files
# using a comment as the record separator
#
# this is trickier than I first thought
# The first version in .97-.9993 was wrong

BEGIN {
 # RS is set to  a comment (this is mildly tricky, I blew it here
 RS = "/\*([^*]|\*+[^*/])*\*+/"
 ORS = " "
 getline hold
 filename = FILENAME
}

# if changing files
filename != FILENAME {
  filename = FILENAME
  printf "%s" , hold
  hold = $0
  next
}

{ # hold one record because we don't want ORS on the last
  #  record in each file
  print hold
  hold = $0
}

END { printf "%s", hold }