examples: Improve source code output when there are multiple files.

This commit is contained in:
Ryan C. Gordon 2024-07-30 13:40:09 -04:00
parent bc8b768b9a
commit 883576beb8
No known key found for this signature in database
GPG Key ID: FA148B892AB48044

View File

@ -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);
}