# SPDX-License-Identifier: CC0-1.0
#
# Process javascript files and resolve dependencies between them
#
# This file is part of Haketilo
#
# Copyright (C) 2021, Wojtek Kosior
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
# the Creative Commons Corporation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# CC0 1.0 Universal License for more details.
function read_file(filename,
imports_state, exports_state, line, record, result) {
imports_state = "not_started"
exports_state = "not_started"
do {
result = (getline line < filename)
if (result < 0) {
printf "error reading %s", filename
exit 1
}
if (imports_state == "started" &&
line ~ /^([[:space:]]*\*[[:space:]]+)?IMPORT[[:space:]]+[_a-zA-Z][_a-zA-Z0-9]*[[:space:]]*$/) {
record = line
sub(/^([[:space:]]*\*[[:space:]]+)?IMPORT[[:space:]]+/, "", record)
sub(/([[:space:]]+$)/, "", record)
imports[filename,++import_counts[filename]] = record
}
if (imports_state == "started" &&
line ~ /^([