diff options
Diffstat (limited to 'bm/seed.pl')
| -rw-r--r-- | bm/seed.pl | 69 |
1 files changed, 50 insertions, 19 deletions
@@ -13,20 +13,53 @@ if (!defined $total_files || !defined $max_depth) { my $target_root = "sandbox"; my $files_created = 0; -# Helper to generate random "code-like" text sub generate_content { - my $size_kb = 5 + int(rand(21)); # 5-25 KB - my $bytes = $size_kb * 1024; + my $size_kb = 5 + int(rand(21)); + my $target_bytes = $size_kb * 1024; my $content = ""; - my @chars = ('a'..'z', 'A'..'Z', '0'..'9'); - - while (length($content) < $bytes) { - my $line_len = 20 + int(rand(60)); - $content .= "\t" if rand() > 0.5; # Random indentation - for (1..$line_len) { $content .= $chars[rand @chars]; } - $content .= (rand() > 0.7) ? " " : ""; # Random spaces - $content .= "\n"; + + my @types = qw(int char void float double uint32_t bool); + my @ops = qw(= += -= == != < >); + my @vars = qw(count index status buffer ptr limit offset); + + $content .= "#include <stdio.h>\n#include <stdlib.h>\n\n"; + + while (length($content) < $target_bytes) { + my $roll = rand(); + + if ($roll < 0.15) { + # Function definition (no indent) + my $type = $types[rand @types]; + my $name = "process_data_" . int(rand(100)); + $content .= "\n$type $name() {\n"; + } + elsif ($roll < 0.60) { + # Standard assignment (1 tab) + my $type = $types[rand @types]; + my $var = $vars[rand @vars] . "_" . int(rand(50)); + my $val = int(rand(1000)); + $content .= "\t$type $var = $val;\n"; + } + elsif ($roll < 0.80) { + # If block with nested logic (1-2 tabs) + my $var = $vars[rand @vars]; + $content .= "\tif ($var > " . int(rand(100)) . ") {\n"; + $content .= "\t\t$var " . $ops[rand @ops] . " 1;\n"; + $content .= "\t\treturn $var;\n"; + $content .= "\t}\n"; + } + elsif ($roll < 0.95) { + # Closing brace (no indent) + $content .= "}\n\n"; + } + else { + # Comment line (1 tab) + $content .= "\t/* Update state " . int(rand(1000)) . " */\n"; + } } + + # Cleanup: Ensure we close the last function block + $content .= "\n}\n" unless $content =~ /}\n\s*$/; return $content; } @@ -34,8 +67,6 @@ sub seed_tree { my ($current_path, $depth, $files_left) = @_; return if $files_left <= 0; - # Determine how many files to put in THIS directory - # Heuristic: Spread them out, but ensure at least 1 if depth remains my $files_here = ($depth == $max_depth) ? $files_left : int($files_left / ($max_depth - $depth + 1)) + int(rand(3)); @@ -45,20 +76,20 @@ sub seed_tree { make_path($current_path) unless -d $current_path; for (1..$files_here) { - my $filename = "file_" . sprintf("%04d", ++$files_created) . ".txt"; + my $filename = "src_" . sprintf("%04d", ++$files_created) . ".c"; my $full_path = File::Spec->catfile($current_path, $filename); - open(my $fh, '>', $full_path) or die $!; + open(my $fh, '>', $full_path) or die "Could not open $full_path: $!"; print $fh generate_content(); close($fh); } - # If we have depth and files remaining, go deeper if ($depth < $max_depth && ($files_left - $files_here) > 0) { - my $next_dir = File::Spec->catdir($current_path, "depth_" . ($depth + 1)); + my $next_dir = File::Spec->catdir($current_path, "subdir_" . ($depth + 1)); seed_tree($next_dir, $depth + 1, $files_left - $files_here); } } -print "Seeding $total_files files across $max_depth levels...\n"; +print "Seeding $total_files files (C-style) with tab indents...\n"; seed_tree($target_root, 1, $total_files); -print "Done. Created $files_created files in '$target_root'.\n"; +print "Success. Created $files_created files in '$target_root'.\n"; + |
