It's a skeleton of a program.
Soon it will have organs, but not yet...
This commit is contained in:
parent
856215f728
commit
449db6ba0a
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// BSD-style usage prompt
|
||||||
|
function help() {
|
||||||
|
echo <<<HELP
|
||||||
|
Usage: gemtext-html infile.gem [outfile.html]
|
||||||
|
HELP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "no such file" is actually unhelpful and likely untrue, but this seems to be the standard *nix behaviour so 🤷
|
||||||
|
function fileHandleingError(string $file) {
|
||||||
|
fwrite(STDERR, "$file: no such file");
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there aren't exactly 2 or 3 arguments, politely tell the user they're a dolt
|
||||||
|
if ($argc != 2 && $argc != 3) {
|
||||||
|
var_dump($argc);
|
||||||
|
help();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let's name our arguments some actually meaningful names
|
||||||
|
$infilePath = $argv[1];
|
||||||
|
// If there are more than 2 args, use the second arg as our outfile path,
|
||||||
|
// otherwise, make a .html file with the same name as the .gmi file
|
||||||
|
if ($argc > 2){
|
||||||
|
$outfilePath = $argv[2];
|
||||||
|
} else {
|
||||||
|
$outfilePath = basename($infilePath, '.gmi') . '.html';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally actually opening the satandamned files
|
||||||
|
$infile = fopen($infilePath, 'r') or fileHandleingError($infilePath);
|
||||||
|
$outfile = fopen($outfilePath, 'w') or fileHandleingError($outfilePath);
|
||||||
|
|
||||||
|
|
||||||
|
// Remember to close your files at the end of the script so the kernel doesn't do something stupid
|
||||||
|
fclose($infile);
|
||||||
|
fclose($outfile);
|
||||||
|
?>
|
Loading…
Reference in New Issue