#!/bin/awk -f
#
# SYNOPSIS
#
# split_api_docs OUTPUT-DIR DOC-FILE...
# split_api_docs OUTPUT-DIR < DOC-FILE...
#
# DESCRIPTION
#
# Read documentation from standard input or file arguments. Dump the bodies of
# API entries into separate files in OUTPUT-DIR, which must already exist.
#

BEGIN {
    OUTPUT_DIR = ARGV[1]
    delete ARGV[1]
    OUTPUT = ""
}

/^\#+ API: / {
    if (OUTPUT) {
        close(OUTPUT)
    }
    OUTPUT = OUTPUT_DIR "/" $3
    next
}

/^#/ {
    if (OUTPUT) {
        close(OUTPUT)
        OUTPUT = ""
    }
    next
}

OUTPUT {
    print $0 > OUTPUT
}

# vim: set et:
