File: sharpline

package info (click to toggle)
noweb 2.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,540 kB
  • sloc: sh: 2,580; ansic: 1,829; makefile: 903; perl: 781; lisp: 757; awk: 174; csh: 3
file content (31 lines) | stat: -rwxr-xr-x 655 bytes parent folder | download | duplicates (11)
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
31
#!/bin/sh
#
# noweb filter to handle #line directives in noweb input
#
# sample usage:
#
#  preprocessor files | notangle -L -filter sharpline - > result.c
#

nawk '
BEGIN { linestart = 1 }
/^(@nl|@index nl)$/ { linestart = 1; print; next }
/^@text #line +[0-9]+$/ {
  if (linestart)
    printf "@line %d\n", $3
  else
    print
  linestart = 0; next
}
/^@text #line +[0-9]+ +".*"$/ {
  if (linestart) {
    thisline = $3
    sub(/^@text #line +[0-9]+ +/, "")
    thisfile = substr($0, 2, length($0) - 2)
    printf "@file %s\n@line %d\n", thisfile, thisline
  } else
    print
  linestart = 0; next
}
/^@(text |quote )/ { linestart = 0 }
{ print }' "$@"