~lbnz/xr0

3f2abe49f9ea57e0ec81ce26c3fdd249480e7ea2 — Amisi Kiarie 2 months ago 2f7e5ae
chore: fix configure comments, separate awk file
3 files changed, 19 insertions(+), 21 deletions(-)

M configure
M tests/0db/run
A tests/0db/split.awk
M configure => configure +6 -7
@@ 1,8 1,12 @@
#!/bin/bash

# This script generates src.mk, which is included in the Makefile.
TMPL_MKFILE=scripts/tmpl.mk
DEPS_MKFILE=scripts/deps.mk

# This script generates the Makefile from $TMPL_MKFILE and $DEPS_MKFILE,
# the latter of which contains the rules to build the various object files.
#
# src.mk imposes the following module rules:
# $DEPS_MKFILE imposes the following module rules:
#
#	1. Every directory in `/src` and its descendant directories, including
#	`/src` itself, defines a module.


@@ 29,9 33,6 @@

set +x

TMPL_MKFILE=scripts/tmpl.mk
DEPS_MKFILE=scripts/deps.mk

SRCDIR=src
BUILDDIR=build



@@ 52,8 53,6 @@ function listincludes() {
INCLUDEDIRS=$(find $SRCDIR -type d -name "include")
SRCDIRS=$(find $SRCDIR -type d ! -name "include")



# hack in Lex/Yacc files
PARSER_FILES="$SRCDIR/ast/lex.yy.c \
	$SRCDIR/ast/gram.tab.c \

M tests/0db/run => tests/0db/run +2 -14
@@ 4,7 4,7 @@ set +x

XR0=$(pwd)/bin/0v
LIBX=$(pwd)/libx

AWKFILE=$(pwd)/tests/0db/split.awk
TESTDIR=$(pwd)/tests/0db/00-basic

output=$($XR0 -I $LIBX -r@ $TESTDIR/test.x < $TESTDIR/test.cfg 2>&1)


@@ 13,18 13,6 @@ tempdir=$(mktemp -d)

# Split the output by the delimiter "(0db)" and write each part to a file
# Using awk to process the splitting and file writing
echo "$output" | awk -v file_prefix="$tempdir/" '
BEGIN { RS="@"; count=0 }  # Set the record separator and initialize the counter
{
    # trim leading and trailing whitespace
    gsub(/^[ \t\r\n]+|[ \t\r\n]+$/, "", $0)
    
    if (length($0) > 0) {   # Check if the line is non-empty
        filename = file_prefix count  # Generate a filename with incrementing counter
        print > filename                      # write the current record to the gen filename
        close(filename)                       # close the file to flush the output
        count++                               # increment the counter for the next file
    }
}'
echo "$output" | awk -v file_prefix="$tempdir/" -f $AWKFILE

diff -r $tempdir $TESTDIR/expected && rm -rf $tempdir

A tests/0db/split.awk => tests/0db/split.awk +11 -0
@@ 0,0 1,11 @@
BEGIN { RS="@"; count=0 }
{
	# trim leading and trailing whitespace
	gsub(/^[ \t\r\n]+|[ \t\r\n]+$/, "", $0)
	if (length($0) > 0) {			# line must be non-empty
		filename = file_prefix count	# generate current filename
		print > filename		# write current portion to file
		close(filename)
		count++
	}
}