| 1 |
#!/usr/bin/env php |
| 2 |
<?php |
| 3 |
/** |
| 4 |
* Used in the unit test for src/config_file_spoof.c |
| 5 |
*/ |
| 6 |
|
| 7 |
$file = dirname(dirname(__FILE__)) . '/etc/detoxrc'; |
| 8 |
|
| 9 |
if (!file_exists($file)) { |
| 10 |
printf("can't load %s\n", $file); |
| 11 |
exit(1); |
| 12 |
} |
| 13 |
|
| 14 |
$maxLength = 72; |
| 15 |
|
| 16 |
$output = []; |
| 17 |
$build = ''; |
| 18 |
$lines = file($file); |
| 19 |
foreach ($lines as $line) { |
| 20 |
$line = trim($line); |
| 21 |
if (empty($line)) { |
| 22 |
continue; |
| 23 |
} |
| 24 |
if ($line[0] == '#') { |
| 25 |
continue; |
| 26 |
} |
| 27 |
$line = preg_replace('/ *{ */', '{', $line); |
| 28 |
$line = preg_replace('/ *}; */', '};', $line); |
| 29 |
$line = str_replace('"', '\"', $line); |
| 30 |
if (strlen($build) + strlen($line) > $maxLength) { |
| 31 |
$output[] = $build; |
| 32 |
$build = ''; |
| 33 |
} |
| 34 |
|
| 35 |
$build .= $line; |
| 36 |
} |
| 37 |
$output[] = $build; |
| 38 |
printf("static char *detoxrc =\n"); |
| 39 |
foreach ($output as $line) { |
| 40 |
printf(" \"%s\"\n", $line); |
| 41 |
} |
| 42 |
printf(" ;\n"); |