From c475681b0ec5fdb183a31a0c553c06b976adcb8e Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Fri, 22 Dec 2023 20:46:23 -0800 Subject: [PATCH] Dropped js replace tool. --- Makefile | 163 ++++++++++++++++++------------------------- site/ESP32forth.html | 10 +-- site/classic.html | 4 +- site/index.html | 4 +- site/internals.html | 4 +- site/linux.html | 12 ++-- site/pico-ice.html | 6 +- site/web.html | 4 +- site/windows.html | 10 +-- tools/configure.py | 2 +- tools/importation.py | 22 +++--- tools/replace.js | 69 ------------------ 12 files changed, 105 insertions(+), 205 deletions(-) delete mode 100755 tools/replace.js diff --git a/Makefile b/Makefile index f81599a..ca6ca94 100644 --- a/Makefile +++ b/Makefile @@ -240,94 +240,81 @@ $(GEN): mkdir -p $@ $(GEN)/posix_boot.h: posix/posix_boot.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name boot --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/posix_boot.h.dd $(GEN)/windows_boot_extra.h: windows/windows_boot_extra.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name boot_extra --header win --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/windows_boot_extra.h.dd $(GEN)/windows_boot.h: windows/windows_boot.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name boot --header win --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/windows_boot.h.dd $(GEN)/pico_ice_boot.h: pico-ice/pico_ice_boot.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name boot --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/pico_ice_boot.h.dd $(GEN)/esp32_boot.h: esp32/esp32_boot.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name boot --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_boot.h.dd $(GEN)/esp32_assembler.h: common/assembler.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name assembler_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_assembler.h.dd $(GEN)/esp32_xtensa-assembler.h: esp32/optional/assemblers/xtensa-assembler.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name xtensa_assembler_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_xtensa-assembler.h.dd $(GEN)/esp32_riscv-assembler.h: esp32/optional/assemblers/riscv-assembler.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name riscv_assembler_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_riscv-assembler.h.dd $(GEN)/esp32_camera.h: esp32/optional/camera/camera_server.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name camera_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_camera.h.dd $(GEN)/esp32_interrupts.h: esp32/optional/interrupts/timers.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name interrupts_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_interrupts.h.dd $(GEN)/esp32_oled.h: esp32/optional/oled/oled.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name oled_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_oled.h.dd $(GEN)/esp32_spi-flash.h: esp32/optional/spi-flash/spi-flash.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name spi_flash_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_spi-flash.h.dd $(GEN)/esp32_serial-bluetooth.h: esp32/optional/serial-bluetooth/serial-bluetooth.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name serial_blueooth_source --header cpp --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_serial-bluetooth.h.dd OPTIONAL_MODULES = \ @@ -361,10 +348,9 @@ $(GEN)/web_sys.js: $(GEN)/dump_web_opcodes | $(GEN) $< sys >$@ $(GEN)/web_boot.js: web/web_boot.fs | $(GEN) - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ -I . -I $(GEN) --name boot --header web --depsout $@.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/web_boot.js.dd # ---- RESOURCES ---- @@ -464,7 +450,7 @@ $(WINDOWS)/uEf32.obj: \ windows/main.c \ $(GEN)/windows_boot_extra.h \ $(GEN)/windows_boot.h | $(WINDOWS) - ./tools/importation.py $< $@ --no-out -I . -I $(GEN) --depsout $@.dd + ./tools/importation.py -i $< -o $@ --no-out -I . -I $(GEN) --depsout $@.dd $(CL32) /c /Fo$@ $(WIN_CFLAGS) $< -include $(WINDOWS)/uEf32.obj.dd @@ -477,7 +463,7 @@ $(WINDOWS)/uEf64.obj: \ windows/main.c \ $(GEN)/windows_boot_extra.h \ $(GEN)/windows_boot.h | $(WINDOWS) - ./tools/importation.py $< $@ --no-out -I . -I $(GEN) --depsout $@.dd + ./tools/importation.py -i $< -o $@ --no-out -I . -I $(GEN) --depsout $@.dd $(CL64) /c /Fo$@ $(WIN_CFLAGS) $< -include $(WINDOWS)/uEf64.obj.dd @@ -523,91 +509,81 @@ $(ESP32)/ESP32forth/optional: $(ESP32)/ESP32forth/ESP32forth.ino: \ esp32/ESP32forth.ino \ $(GEN)/esp32_boot.h | $(ESP32)/ESP32forth - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32.dd $(ESP32)/ESP32forth/README.txt: esp32/README.txt | $(ESP32)/ESP32forth - ./tools/importation.py $< $@ \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + ./tools/importation.py -i $< -o $@ \ + -DVERSION=$(VERSION) -DREVISION=$(REVISION) $(ESP32)/ESP32forth/optional/README-optional.txt: \ esp32/optional/README-optional.txt | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + ./tools/importation.py -i $< -o $@ \ + -DVERSION=$(VERSION) -DREVISION=$(REVISION) $(ESP32)/ESP32forth/optional/assemblers.h: \ esp32/optional/assemblers/assemblers.h \ $(GEN)/esp32_assembler.h \ $(GEN)/esp32_xtensa-assembler.h \ $(GEN)/esp32_riscv-assembler.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32_optional_assemblers.h.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_optional_assemblers.h.dd $(ESP32)/ESP32forth/optional/camera.h: \ esp32/optional/camera/camera.h \ $(GEN)/esp32_camera.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32_optional_camera.h.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_optional_camera.h.dd $(ESP32)/ESP32forth/optional/interrupts.h: \ esp32/optional/interrupts/interrupts.h \ $(GEN)/esp32_interrupts.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32_optional_interrupts.h.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_optional_interrupts.h.dd $(ESP32)/ESP32forth/optional/oled.h: \ esp32/optional/oled/oled.h \ $(GEN)/esp32_oled.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32_optional_oled.h.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_optional_oled.h.dd $(ESP32)/ESP32forth/optional/rmt.h: \ esp32/optional/rmt.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) $(ESP32)/ESP32forth/optional/serial-bluetooth.h: \ esp32/optional/serial-bluetooth/serial-bluetooth.h \ $(GEN)/esp32_serial-bluetooth.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32_optional_serial-bluetooth.h.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_optional_serial-bluetooth.h.dd $(ESP32)/ESP32forth/optional/spi-flash.h: \ esp32/optional/spi-flash/spi-flash.h \ $(GEN)/esp32_spi-flash.h | $(ESP32)/ESP32forth/optional - ./tools/importation.py $< $@ \ + ./tools/importation.py -i $< -o $@ \ --keep-first-comment \ -I . -I $(GEN) --depsout $(GEN)/esp32_optional_spi-flash.h.dd \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + -DVERSION=$(VERSION) -DREVISION=$(REVISION) -include $(GEN)/esp32_optional_spi-flash.h.dd # ---- ESP32 ARDUINO BUILD AND FLASH ---- @@ -712,9 +688,8 @@ pico-ice/pico-ice-sdk/README.md: git submodule update --init pico-ice/pico-ice-sdk $(PICO_ICE)/ueforth-pico-ice/README.txt: pico-ice/README.txt | $(PICO_ICE)/ueforth-pico-ice - ./tools/importation.py $< $@ \ - --set-version $(VERSION) \ - --set-revision $(REVISION) + ./tools/importation.py -i $< -o $@ \ + -DVERSION=$(VERSION) -DREVISION=$(REVISION) $(PICO_ICE)/ueforth-pico-ice/LICENSE: LICENSE cp $< $@ @@ -830,18 +805,12 @@ publish: publish-esp32 publish-pico-ice publish-linux publish-web publish-window $(DEPLOY): mkdir -p $@ -REPLACE = tools/replace.js \ - HEAD=@site/head.html \ - COMMON=@site/common.html \ - FILES_COMMON=@site/files_common.html \ - POSIX_COMMON=@site/posix_common.html \ - DESKTOP_COMMON=@site/desktop_common.html \ - MENU=@site/menu.html \ - VERSION=${VERSION} \ - STABLE_VERSION=${STABLE_VERSION} \ - OLD_STABLE_VERSION=${OLD_STABLE_VERSION} -UE_REPLACE = $(REPLACE) FORTH=uEForth -ESP_REPLACE = $(REPLACE) FORTH=ESP32forth +REPLACE = ./tools/importation.py -I site \ + -DVERSION=${VERSION} \ + -DSTABLE_VERSION=${STABLE_VERSION} \ + -DOLD_STABLE_VERSION=${OLD_STABLE_VERSION} +UE_REPLACE = $(REPLACE) -DFORTH=uEForth +ESP_REPLACE = $(REPLACE) -DFORTH=ESP32forth $(DEPLOY)/app.yaml: $(RES)/eforth.ico \ $(wildcard site/*.html) \ @@ -857,14 +826,14 @@ $(DEPLOY)/app.yaml: $(RES)/eforth.ico \ cp site/*.yaml $(DEPLOY)/ cp site/.gcloudignore $(DEPLOY) cp out/web/ueforth.js $(DEPLOY)/ - cat site/web.html | $(ESP_REPLACE) >$(DEPLOY)/web.html - cat site/ESP32forth.html | $(ESP_REPLACE) >$(DEPLOY)/ESP32forth.html - cat site/pico-ice.html | $(UE_REPLACE) >$(DEPLOY)/pico-ice.html - cat site/index.html | $(UE_REPLACE) >$(DEPLOY)/index.html - cat site/linux.html | $(UE_REPLACE) >$(DEPLOY)/linux.html - cat site/windows.html | $(UE_REPLACE) >$(DEPLOY)/windows.html - cat site/internals.html | $(UE_REPLACE) >$(DEPLOY)/internals.html - cat site/classic.html | $(UE_REPLACE) >$(DEPLOY)/classic.html + $(ESP_REPLACE) -i site/web.html -o $(DEPLOY)/web.html + $(ESP_REPLACE) -i site/ESP32forth.html -o $(DEPLOY)/ESP32forth.html + $(UE_REPLACE) -i site/pico-ice.html -o $(DEPLOY)/pico-ice.html + $(UE_REPLACE) -i site/index.html -o $(DEPLOY)/index.html + $(UE_REPLACE) -i site/linux.html -o $(DEPLOY)/linux.html + $(UE_REPLACE) -i site/windows.html -o $(DEPLOY)/windows.html + $(UE_REPLACE) -i site/internals.html -o $(DEPLOY)/internals.html + $(UE_REPLACE) -i site/classic.html -o $(DEPLOY)/classic.html deploy: all cd out/deploy && gcloud app deploy -q --project esp32forth *.yaml diff --git a/site/ESP32forth.html b/site/ESP32forth.html index 998f316..507ef53 100644 --- a/site/ESP32forth.html +++ b/site/ESP32forth.html @@ -16,13 +16,13 @@ limitations under the License. --> - {{HEAD}} +#include "head.html" ESP32forth

ESP32forth

-{{MENU}} +#include "menu.html"

Download

@@ -322,9 +322,9 @@ On boot, ESP32forth configures PIN 2 (typically an LED) to be an output and brin

ESP32forth Specific Words

-{{COMMON}} -{{FILES_COMMON}} -{{POSIX_COMMON}} +#include "common.html" +#include "files_common.html" +#include "posix_common.html"

ESP32forth Bindings

diff --git a/site/classic.html b/site/classic.html index fd70c59..29d5c8d 100644 --- a/site/classic.html +++ b/site/classic.html @@ -15,13 +15,13 @@ See the License for the specific language governing permissions and limitations under the License. --> - {{HEAD}} +#include "head.html" Classic EForth

Classic EForth

-{{MENU}} +#include "menu.html"

diff --git a/site/index.html b/site/index.html index c672978..359c5ec 100644 --- a/site/index.html +++ b/site/index.html @@ -16,7 +16,7 @@ limitations under the License. --> -{{HEAD}} +#include "head.html" EForth @@ -26,7 +26,7 @@ limitations under the License. window.location.replace('./ESP32forth.html'); -{{MENU}} +#include "menu.html"

diff --git a/site/internals.html b/site/internals.html index e44beec..c97e8d8 100644 --- a/site/internals.html +++ b/site/internals.html @@ -16,13 +16,13 @@ limitations under the License. --> - {{HEAD}} +#include "head.html" µEforth Internals

µEforth Internals

-{{MENU}} +#include "menu.html"

diff --git a/site/linux.html b/site/linux.html index 86efdad..901b50d 100644 --- a/site/linux.html +++ b/site/linux.html @@ -16,13 +16,13 @@ limitations under the License. --> - {{HEAD}} +#include "head.html" µEforth for Linux

µEforth for Linux

-{{MENU}} +#include "menu.html"

Download

@@ -63,9 +63,9 @@ limitations under the License.

µEforth Words

-{{COMMON}} -{{FILES_COMMON}} -{{POSIX_COMMON}} +#include "common.html" +#include "files_common.html" +#include "posix_common.html"

Linux

@@ -101,4 +101,4 @@ In addition, TYPE and KEY are connected to stdin and stdout.

-{{DESKTOP_COMMON}} +#include "desktop_common.html" diff --git a/site/pico-ice.html b/site/pico-ice.html index 8f53d10..f547c91 100644 --- a/site/pico-ice.html +++ b/site/pico-ice.html @@ -16,13 +16,13 @@ limitations under the License. --> - {{HEAD}} +#include "head.html" pico-ice

pico-ice

-{{MENU}} +#include "menu.html"

Download

@@ -103,7 +103,7 @@ Be sure to config the serial port to: baud rate = 115200, data bits = 8, s

pico-ice Words

-{{COMMON}} +#include "common.html"

pico-ice Bindings

diff --git a/site/web.html b/site/web.html index d3a99f5..40d20ae 100644 --- a/site/web.html +++ b/site/web.html @@ -16,13 +16,13 @@ limitations under the License. --> -{{HEAD}} +#include "head.html" µEforth for Web

µEforth for Web

-{{MENU}} +#include "menu.html"
diff --git a/site/windows.html b/site/windows.html index ba76d62..4b23920 100644 --- a/site/windows.html +++ b/site/windows.html @@ -16,13 +16,13 @@ limitations under the License. --> - {{HEAD}} +#include "head.html" µEforth for Windows

µEforth for Windows

-{{MENU}} +#include "menu.html"

Download

@@ -69,8 +69,8 @@ limitations under the License.

µEforth Words

-{{COMMON}} -{{FILES_COMMON}} +#include "common.html" +#include "files_common.html"

Windows

@@ -110,4 +110,4 @@ In addition, a terminal that responds to ANSI escape codes is created and connec TYPE and KEY.

-{{DESKTOP_COMMON}} +#include "desktop_common.html" diff --git a/tools/configure.py b/tools/configure.py index d7e63ef..3bae333 100755 --- a/tools/configure.py +++ b/tools/configure.py @@ -97,7 +97,7 @@ rule mkdir rule importation description = importation depfile = $out.dd - command = ../tools/importation.py $in $out -I . -I .. --name $name --header $header_mode --depsout $out.dd --set-version $version --set-revision $revision + command = ../tools/importation.py -i $in -o $out -I . -I .. --name $name --header $header_mode --depsout $out.dd -DVERSION=$version -DREVSION=$revision build gen: mkdir diff --git a/tools/importation.py b/tools/importation.py index 0f9a2e5..3ead57c 100755 --- a/tools/importation.py +++ b/tools/importation.py @@ -7,11 +7,10 @@ import sys parser = argparse.ArgumentParser( prog='importation', description='Imports header / fs files') -parser.add_argument('input') -parser.add_argument('output') +parser.add_argument('-i', required=True) +parser.add_argument('-o', required=True) parser.add_argument('-I', action='append') -parser.add_argument('--set-version') -parser.add_argument('--set-revision') +parser.add_argument('-D', action='append') parser.add_argument('--depsout') parser.add_argument('--no-out', action='store_true') parser.add_argument('--keep-first-comment', action='store_true') @@ -19,6 +18,7 @@ parser.add_argument('--name') parser.add_argument('--header') args = parser.parse_args() bases = args.I or [] +replacements = args.D or [] results = [] imported = set([__file__]) @@ -36,6 +36,7 @@ def Import(filename): sfilename = os.path.join(os.path.dirname(filename), sfilename) Import(sfilename) elif (filename.endswith('.h') or + filename.endswith('.html') or filename.endswith('.ino') or filename.endswith('.cc') or filename.endswith('.cpp') or @@ -54,14 +55,13 @@ def Import(filename): results.append(line) def Process(): - Import(args.input) + Import(args.i) # Conversion version tags. output = [] for line in results: - if args.set_version: - line = line.replace('{{VERSION}}', args.set_version) - if args.set_revision: - line = line.replace('{{REVISION}}', args.set_revision) + for r in replacements: + name, value = r.split('=', 1) + line = line.replace('{{' + name + 'VERSION}}', value) output.append(line) # Drop comments. comment1 = False @@ -85,11 +85,11 @@ def Process(): # Emit deps. if args.depsout: with open(args.depsout, 'w') as fh: - fh.write(args.output + ': ' + + fh.write(args.o + ': ' + ' '.join([os.path.relpath(i) for i in imported]) + '\n') # Emit expanded file. if not args.no_out: - with open(args.output, 'w') as fh: + with open(args.o, 'w') as fh: if args.header == 'web': fh.write('const ' + args.name + ' = `\n' + '\n'.join(output) + '\n`;\n') diff --git a/tools/replace.js b/tools/replace.js deleted file mode 100755 index af326fb..0000000 --- a/tools/replace.js +++ /dev/null @@ -1,69 +0,0 @@ -#! /usr/bin/env nodejs -// Copyright 2021 Bradley D. Nelson -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -var fs = require('fs'); - -function DropCopyright(source) { - var lines = source.split('\n'); - var cleaned = []; - for (var i = 0; i < lines.length; ++i) { - if (lines[i] == '') { - ++i; - } - ++i; - } - if (lines[i].search('Copyright') >= 0) { - while (lines[i] != '') { - ++i; - } - } else { - cleaned.push(lines[i]); - } - } - return cleaned.join('\n').trim(); -} - -var source = fs.readFileSync(process.stdin.fd).toString(); -var replacements = []; -for (var i = 2; i < process.argv.length; ++i) { - var item = process.argv[i]; - var m = item.match(/^([^=]+)=@(.+)$/); - if (m) { - var content = DropCopyright(fs.readFileSync(m[2]).toString()); - replacements.push(['{{' + m[1] + '}}', content]); - continue; - } - var m = item.match(/^([^=]+)=(.+)$/); - if (m) { - replacements.push(['{{' + m[1] + '}}', m[2]]); - continue; - } - throw 'Bad replacement ' + item; -} - -for (;;) { - var old_source = source; - for (var i = 0; i < replacements.length; ++i) { - source = source.replace( - replacements[i][0], - function() { return replacements[i][1]}); - } - if (old_source == source) { - break; - } -} - -process.stdout.write(source);