<commit_before>#!/usr/bin/perl

# todo: handle XYX# as well as XYX:

my @files = <../caosVM_*.cpp>;

my %doublecmds;
my %doublefuncs;

my $parsingdoc = 0;
my $doclines;

my %funcs;
my %voids;

my $data;

sub writedata {
	my ($name, $docline, $type, $newname) = @_;

	my @sp = split(/\(/, $docline);
  my $count = int(@sp) - 2;

	die("unknown type $type passed to writedata") if ($type != 1) && ($type != 2);
	
	if ($newname eq $name) {
		$data = $data . "CMDDEF(" . $name if ($type == 1);
		$data = $data . "FUNCDEF(" . $name if ($type == 2);
		$count = 0 if $docline =~ /condition/;
    $data = $data . ", " . $count . ")\n";
		if ($docline =~ /condition/) {
			die("only commands can have conditions while processing " . $name) unless ($type == 1);
			$data = $data . 'cmds[phash_cmd(*(int *)"' . $name . '")].needscondition = true;' . "\n";
		}				
	} else {
		my $firstname = $newname;
		$firstname =~ s/(.*) .*/$1/;
														
	  if ($type == 1) {
			if (!$doublecmds{$firstname}) {
				$data = $data . "DBLCMDDEF(\"" . $firstname . "\")\n";
				$doublecmds{$firstname} = 1;
			}
			$data = $data . "DBLCMD(\"";
		} elsif ($type == 2) {
			if (!$doublefuncs{$firstname}) {
				$data = $data . "DBLFUNCDEF(\"" . $firstname . "\")\n";
				$doublefuncs{$firstname} = 1;
			}
			$data = $data . "DBLFUNC(\"";
		}
		$data = $data . $newname . "\", " . $name . ", " . $count . ")\n";
  }
}

sub writedocsanddata {
	my ($name, $type) = @_;

	my $newname = $name;
	if ($name =~ /_/) {
		my $one = $name;
		$one =~ s/(.*)_(.*)/$1/;
		my $two = $name;
		$two =~ s/(.*)_(.*)/$2/;
		if (length($one) == 3) {
			$one = $one . ":";
		}
		$newname = $one . " " . $two;
	}
	if ($doclines) {
    my $firstline = (split(/\n/, $doclines))[0];
		$firstline =~ s/^\s*(.*)\s*$/$1/;
		writedata($name, $firstline, $type, $newname);
		
		$doclines =~ s/\n/<br>/;
		print docfile "<h2>", $newname, "</h2>";
		print docfile "<p>", $doclines, "</p>\n";
	} else {
	  print "command/function '", $newname, "' wasn't processed because it has no documentation. add at least a prototype.\n";
	}
	
	$doclines = "";
}

open(docfile, ">caosdocs.html");

foreach my $fname (@files) {<commit_msg>fix tabs in makedocs.pl<commit_after>#!/usr/bin/perl

# todo: handle XYX# as well as XYX:

my @files = <../caosVM_*.cpp>;

my %doublecmds;
my %doublefuncs;

my $parsingdoc = 0;
my $doclines;

my %funcs;
my %voids;

my $data;

sub writedata {
	my ($name, $docline, $type, $newname) = @_;

	my @sp = split(/\(/, $docline);
	my $count = int(@sp) - 2;

	die("unknown type $type passed to writedata") if ($type != 1) && ($type != 2);
	
	if ($newname eq $name) {
		$data = $data . "CMDDEF(" . $name if ($type == 1);
		$data = $data . "FUNCDEF(" . $name if ($type == 2);
		$count = 0 if $docline =~ /condition/;
		$data = $data . ", " . $count . ")\n";
		if ($docline =~ /condition/) {
			die("only commands can have conditions while processing " . $name) unless ($type == 1);
			$data = $data . 'cmds[phash_cmd(*(int *)"' . $name . '")].needscondition = true;' . "\n";
		}				
	} else {
		my $firstname = $newname;
		$firstname =~ s/(.*) .*/$1/;
														
	  if ($type == 1) {
			if (!$doublecmds{$firstname}) {
				$data = $data . "DBLCMDDEF(\"" . $firstname . "\")\n";
				$doublecmds{$firstname} = 1;
			}
			$data = $data . "DBLCMD(\"";
		} elsif ($type == 2) {
			if (!$doublefuncs{$firstname}) {
				$data = $data . "DBLFUNCDEF(\"" . $firstname . "\")\n";
				$doublefuncs{$firstname} = 1;
			}
			$data = $data . "DBLFUNC(\"";
		}
		$data = $data . $newname . "\", " . $name . ", " . $count . ")\n";
  }
}

sub writedocsanddata {
	my ($name, $type) = @_;

	my $newname = $name;
	if ($name =~ /_/) {
		my $one = $name;
		$one =~ s/(.*)_(.*)/$1/;
		my $two = $name;
		$two =~ s/(.*)_(.*)/$2/;
		if (length($one) == 3) {
			$one = $one . ":";
		}
		$newname = $one . " " . $two;
	}
	if ($doclines) {
		my $firstline = (split(/\n/, $doclines))[0];
		$firstline =~ s/^\s*(.*)\s*$/$1/;
		writedata($name, $firstline, $type, $newname);
		
		$doclines =~ s/\n/<br>/;
		print docfile "<h2>", $newname, "</h2>";
		print docfile "<p>", $doclines, "</p>\n";
	} else {
	  print "command/function '", $newname, "' wasn't processed because it has no documentation. add at least a prototype.\n";
	}
	
	$doclines = "";
}

open(docfile, ">caosdocs.html");

foreach my $fname (@files) {
{'fraction_non_alphanumeric': 0.25408891960377794, 'fraction_numerical': 0.009214466712739, 'mean_word_length': 2.692176870748299, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6302690', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1821, 'n_words': 439}