#! /usr/bin/original-awk -f
# Recursive file inclusion for AT&T AWK
# Copyright (C) 2008 Matous J. Fialka,
# Released under the terms of The MIT License
# Usage: include.awk [ [ ... ] ]
BEGIN {
Statement = "@include"
resetStack(StackOfFilenames)
}
{
proceedLine()
}
function popFromStack(_Stack)
{
if (_Stack[0] > 0) {
return _Stack[_Stack[0]--]
}
}
function proceedLine()
{
if (Statement == $1 && NF == 2) {
pushOnStack(StackOfFilenames, FILENAME)
FILENAME = $2
while ((getline < FILENAME) > 0) {
proceedLine()
}
close(FILENAME)
FILENAME = popFromStack(StackOfFilenames)
return ""
}
print
}
function pushOnStack(_Stack, _Value)
{
_Stack[++_Stack[0]] = _Value
}
function resetStack(_Stack)
{
_Stack[0] = 0
}