<commit_before><?php
$template_file = 'template.tex';
if (!file_exists($template_file)) {
  exit(1);
}
$template = file_get_contents($template_file);
if ($template == FALSE)
  exit("template not found");
foreach($_GET as $placeholder=>$replacement) {
//  if ($placeholder == "" || $replacement == "")
//    continue;
  echo "replace '$placeholder' with '$replacement'<br />";
  $template = preg_replace("/". preg_quote("token-" . $placeholder) . "/", preg_quote($replacement), $template);
}
echo "$template";
$dir = sys_get_temp_dir() . "/" . "webletter-" . mt_rand();
mkdir($dir) or exit("failed to make tmpdir");
chdir($dir) or exit("failed to chdir");
$filebase = "letter";
$srcfile = $filebase . ".tex";
$handle = fopen($srcfile, "w") or die("failed to open srcfile");
fwrite($handle, $template);
fclose($handle);
$outfile = $filebase . ".pdf";
exec("pdflatex $srcfile", $output);
foreach ($output as $i => $line) {
  echo "$line<br />";
}
unlink($srcfile);
if (file_exists($outfile)) {
  //echo "writing file";
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');<commit_msg>server: remove backslashes in tokens<commit_after><?php
$template_file = 'template.tex';
if (!file_exists($template_file)) {
  exit(1);
}
$template = file_get_contents($template_file);
if ($template == FALSE)
  exit("template not found");
foreach($_GET as $placeholder=>$replacement) {
//  if ($placeholder == "" || $replacement == "")
//    continue;
  $replacement = preg_replace("/\\\\/", "", $replacement);
  echo "replace '$placeholder' with '$replacement'<br />";
  $template = preg_replace("/". preg_quote("token-" . $placeholder) . "/", preg_quote($replacement), $template);
}
echo "$template";
$dir = sys_get_temp_dir() . "/" . "webletter-" . mt_rand();
mkdir($dir) or exit("failed to make tmpdir");
chdir($dir) or exit("failed to chdir");
$filebase = "letter";
$srcfile = $filebase . ".tex";
$handle = fopen($srcfile, "w") or die("failed to open srcfile");
fwrite($handle, $template);
fclose($handle);
$outfile = $filebase . ".pdf";
exec("pdflatex $srcfile", $output);
foreach ($output as $i => $line) {
  echo "$line<br />";
}
unlink($srcfile);
if (file_exists($outfile)) {
  //echo "writing file";
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
{'fraction_non_alphanumeric': 0.2127568493150685, 'fraction_numerical': 0.0008561643835616438, 'mean_word_length': 5.491666666666666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '185438', 'n_tokens_mistral': 771, 'n_tokens_neox': 769, 'n_words': 184}