From 883576beb858ccc2a1721c6f788ff43c4f39853e Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 30 Jul 2024 13:40:09 -0400 Subject: [PATCH] examples: Improve source code output when there are multiple files. --- build-scripts/build-web-examples.pl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/build-scripts/build-web-examples.pl b/build-scripts/build-web-examples.pl index 516fe853ea..7b07f999aa 100755 --- a/build-scripts/build-web-examples.pl +++ b/build-scripts/build-web-examples.pl @@ -80,12 +80,13 @@ sub handle_example_dir { opendir(my $dh, "$examples_dir/$category/$example") or die("Couldn't opendir '$examples_dir/$category/$example': $!\n"); my $spc = ''; while (readdir($dh)) { - next if not /\.c\Z/; # only care about .c files. my $path = "$examples_dir/$category/$example/$_"; next if not -f $path; # only care about files. - push @files, $path; - $files_str .= "$spc$path"; - $spc = ' '; + push @files, $path if /\.[ch]\Z/; # add .c and .h files to source code. + if (/\.c\Z/) { # only care about .c files for compiling. + $files_str .= "$spc$path"; + $spc = ' '; + } } closedir($dh); @@ -124,7 +125,7 @@ sub handle_example_dir { my $pid = open2(my $child_out, my $child_in, $highlight_cmd); my $htmlified_source_code = ''; - foreach (@files) { + foreach (sort(@files)) { my $path = $_; open my $srccode, '<', $path or die("Couldn't open '$path': $!\n"); my $fname = "$path"; @@ -133,6 +134,7 @@ sub handle_example_dir { while (<$srccode>) { print $child_in $_; } + print $child_in "\n\n\n"; close($srccode); }