File: help-from-md.awk

package info (click to toggle)
rsync 3.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,032 kB
  • sloc: ansic: 43,496; sh: 5,985; python: 1,621; asm: 829; perl: 550; makefile: 367; cpp: 298; awk: 191
file content (40 lines) | stat: -rwxr-xr-x 770 bytes parent folder | download | duplicates (5)
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
32
33
34
35
36
37
38
39
40
#!/usr/bin/awk -f

# The caller must pass args: -v hfile=help-NAME.h NAME.NUM.md

BEGIN {
    heading = "/* DO NOT EDIT THIS FILE!  It is auto-generated from the option list in " ARGV[1] "! */"
    findcomment = hfile
    sub("\\.", "\\.", findcomment)
    findcomment = "\\[comment\\].*" findcomment
    backtick_cnt = 0
    prints = ""
}

/^```/ {
    backtick_cnt  
    next
}

foundcomment {
    if (backtick_cnt > 1) exit
    if (backtick_cnt == 1) {
	gsub(/"/, "\\\"")
	prints = prints "\n  rprintf(F,\"" $0 "\\n\");"
    }
    next
}

$0 ~ findcomment {
    foundcomment = 1
    backtick_cnt = 0
}

END {
    if (foundcomment && backtick_cnt > 1)
	print heading "\n" prints > hfile
    else {
	print "Failed to find " hfile " section in " ARGV[1]
	exit 1
    }
}