#!/usr/bin/perl use strict; use warnings; use File::Spec; use File::Path qw(make_path); my ($total_files, $max_depth) = @ARGV; if (!defined $total_files || !defined $max_depth) { die "Usage: perl seed.pl \nExample: perl seed.pl 200 20\n"; } my $target_root = "sandbox"; my $files_created = 0; sub generate_content { my $size_kb = 5 + int(rand(21)); my $target_bytes = $size_kb * 1024; my $content = ""; 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 \n#include \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; } sub seed_tree { my ($current_path, $depth, $files_left) = @_; return if $files_left <= 0; my $files_here = ($depth == $max_depth) ? $files_left : int($files_left / ($max_depth - $depth + 1)) + int(rand(3)); $files_here = $files_left if $files_here > $files_left; make_path($current_path) unless -d $current_path; for (1..$files_here) { my $filename = "src_" . sprintf("%04d", ++$files_created) . ".c"; my $full_path = File::Spec->catfile($current_path, $filename); open(my $fh, '>', $full_path) or die "Could not open $full_path: $!"; print $fh generate_content(); close($fh); } if ($depth < $max_depth && ($files_left - $files_here) > 0) { 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 (C-style) with tab indents...\n"; seed_tree($target_root, 1, $total_files); print "Success. Created $files_created files in '$target_root'.\n";