<commit_before>#!/usr/bin/perl
# vim: set noet: 
use strict;
use warnings;

use YAML;

sub captext ($);

BEGIN {
	eval {
		require Text::Capitalize;
		import Text::Capitalize;
	};
	if ($@) {
		*captext = sub ($) {
			my $t = shift;
			$t =~ s/^([a-z])/uc $1/e;
			return $t;
		};
	} else {
		*captext = sub ($) {
			return capitalize_title($_[0]);
		};
	}
}

sub esc ($) {
	my $t = shift;
	$t =~ s/\W/_/g;
	return $t;
}

my $data = YAML::LoadFile('commandinfo.yml');

my %catsort;
foreach my $key (sort keys %{$data->{ops}}) {
	$data->{ops}{$key}{key} = $key;
	push @{$catsort{$data->{ops}{$key}{category}}}, $data->{ops}{$key};
}

foreach my $key (keys %catsort) {
	$catsort{$key} = [
		map { $_->[0] }
		sort { $a->[1] cmp $b->[1] }
		map { [ $_, $_->{name} ] }
		@{$catsort{$key}}
	];
}

my @catl = map { { name => captext($_), ents => $catsort{$_}, anchor => esc($_) } } sort keys %catsort;
print <<END;
<html>
	<head>
		<title>CAOS command reference - openc2e</title>
		<link rel="stylesheet" type="text/css" href="docs.css" />
	</head>
	<body>
		<h1>CAOS command reference - openc2e dev build</h1>
		<div id="index"><ul>
END

foreach my $c (@catl) {
	print "<li><a href=\"#c_", $c->{anchor}, "\">", $c->{name}, "</a></li>\n";
}
print "</ul></div>\n";

my %st_insert = (
	todo => ['st_todo', 'This command is not yet implemented.'],
	probablyok => ['st_maybe', 'This command probably works, but it has not been annotated with its status.'],
	maybe => ['st_maybe', 'This command is believed to work, but has not yet been thoroughly tested.'],
	broken => ['st_todo', 'This command is partially implemented but missing large amounts of functionality, or is nonconformant in some vital way.'],
	ok => ['st_ok', 'This command works properly.'],
);

$st_insert{stub} = $st_insert{todo};


foreach my $cat (@catl) {
	print qq{<div class=category" id="c_$cat->{anchor}">\n};
	print qq{<h2>$cat->{name}</h2><hr/>\n};
	foreach my $op (@{$cat->{ents}}) {
		print qq{<div class="command" id="k_$op->{key}">\n};
		print qq{<div class="header">\n};
		print qq{<span class="cmdname">$op->{name}</span>\n};
		print qq{<span class="cmdtype">$op->{type}</span>\n};
		foreach my $arg (@{$op->{arguments}}) {
			print qq{<span class="argname">$arg->{name}</span>\n};
			print qq{<span class="argtype">$arg->{type}</span>\n};
		}
		print qq{</div><div class="description">};
		unless (defined $op->{docs}) {
			print qq{<div class="nodocs">This command is currently undocumented.</div>\n};
		} else {
			print qq{<div class="docs">$op->{description}</div>\n};
		}
		print qq{</div><div class="status">};
		if (exists $st_insert{$op->{status}}) {
			print qq{<div class="$st_insert{$op->{status}}[0]">};
			print $st_insert{$op->{status}}[1];
			print qq{</div>};
		} else {
			print qq{<div class="st_wtf">This command has an unknown status tag of: $op->{status}.};
			print qq{Please beat whoever set that status with a shovel or some other heavy object.};
			print qq{</div>};
		}
		print qq{</div>};
		print qq{<div class="administrivia"><ul>};
		print qq{<li>Implemented in: $op->{filename}</li>};
		print qq{<li>Implementation functions (may be wrong): $op->{implementation}</li>};
		if ($op->{pragma}) {
			print qq{<li>Pragmas:<ul>};
			foreach my $pk (sort keys %{$op->{pragma}}) {
				print qq{<li>$pk =&gt; $op->{pragma}{$pk}</li>};<commit_msg>Fix writehtml descriptions<commit_after>#!/usr/bin/perl
# vim: set noet: 
use strict;
use warnings;

use YAML;

sub captext ($);

BEGIN {
	eval {
		require Text::Capitalize;
		import Text::Capitalize;
	};
	if ($@) {
		*captext = sub ($) {
			my $t = shift;
			$t =~ s/^([a-z])/uc $1/e;
			return $t;
		};
	} else {
		*captext = sub ($) {
			return capitalize_title($_[0]);
		};
	}
}

sub esc ($) {
	my $t = shift;
	$t =~ s/\W/_/g;
	return $t;
}

my $data = YAML::LoadFile('commandinfo.yml');

my %catsort;
foreach my $key (sort keys %{$data->{ops}}) {
	$data->{ops}{$key}{key} = $key;
	push @{$catsort{$data->{ops}{$key}{category}}}, $data->{ops}{$key};
}

foreach my $key (keys %catsort) {
	$catsort{$key} = [
		map { $_->[0] }
		sort { $a->[1] cmp $b->[1] }
		map { [ $_, $_->{name} ] }
		@{$catsort{$key}}
	];
}

my @catl = map { { name => captext($_), ents => $catsort{$_}, anchor => esc($_) } } sort keys %catsort;
print <<END;
<html>
	<head>
		<title>CAOS command reference - openc2e</title>
		<link rel="stylesheet" type="text/css" href="docs.css" />
	</head>
	<body>
		<h1>CAOS command reference - openc2e dev build</h1>
		<div id="index"><ul>
END

foreach my $c (@catl) {
	print "<li><a href=\"#c_", $c->{anchor}, "\">", $c->{name}, "</a></li>\n";
}
print "</ul></div>\n";

my %st_insert = (
	todo => ['st_todo', 'This command is not yet implemented.'],
	probablyok => ['st_maybe', 'This command probably works, but it has not been annotated with its status.'],
	maybe => ['st_maybe', 'This command is believed to work, but has not yet been thoroughly tested.'],
	broken => ['st_todo', 'This command is partially implemented but missing large amounts of functionality, or is nonconformant in some vital way.'],
	ok => ['st_ok', 'This command works properly.'],
);

$st_insert{stub} = $st_insert{todo};


foreach my $cat (@catl) {
	print qq{<div class=category" id="c_$cat->{anchor}">\n};
	print qq{<h2>$cat->{name}</h2><hr/>\n};
	foreach my $op (@{$cat->{ents}}) {
		print qq{<div class="command" id="k_$op->{key}">\n};
		print qq{<div class="header">\n};
		print qq{<span class="cmdname">$op->{name}</span>\n};
		print qq{<span class="cmdtype">$op->{type}</span>\n};
		foreach my $arg (@{$op->{arguments}}) {
			print qq{<span class="argname">$arg->{name}</span>\n};
			print qq{<span class="argtype">$arg->{type}</span>\n};
		}
		print qq{</div><div class="description">};
		unless (defined $op->{description}) {
			print qq{<div class="nodocs">This command is currently undocumented.</div>\n};
		} else {
			print qq{<div class="docs">$op->{description}</div>\n};
		}
		print qq{</div><div class="status">};
		if (exists $st_insert{$op->{status}}) {
			print qq{<div class="$st_insert{$op->{status}}[0]">};
			print $st_insert{$op->{status}}[1];
			print qq{</div>};
		} else {
			print qq{<div class="st_wtf">This command has an unknown status tag of: $op->{status}.};
			print qq{Please beat whoever set that status with a shovel or some other heavy object.};
			print qq{</div>};
		}
		print qq{</div>};
		print qq{<div class="administrivia"><ul>};
		print qq{<li>Implemented in: $op->{filename}</li>};
		print qq{<li>Implementation functions (may be wrong): $op->{implementation}</li>};
		if ($op->{pragma}) {
			print qq{<li>Pragmas:<ul>};
			foreach my $pk (sort keys %{$op->{pragma}}) {
				print qq{<li>$pk =&gt; $op->{pragma}{$pk}</li>};
{'fraction_non_alphanumeric': 0.23745519713261648, 'fraction_numerical': 0.003882915173237754, 'mean_word_length': 4.195500387897595, 'pattern_counts': {'":': 0, '<': 115, '<?xml version=': 0, '>': 187, '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': '2072883', 'n_tokens_mistral': 2816, 'n_tokens_neox': 2619, 'n_words': 631}