-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhs2lhs.php
executable file
·55 lines (49 loc) · 1.47 KB
/
hs2lhs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env php
<?php
/**
* Print a green success message to the console
* @var string $message
**/
function success($message)
{
echo "\033[0;32m" . $message . "\033[0m" . PHP_EOL;
}
/**
* Print a red error message to the console
* @var string $message
**/
function error($message)
{
echo "\033[0;31m" . $message . "\033[0m" . PHP_EOL;
}
/**
* Print a red error message to the console
* @var string $inputFile
* @var string $outputFile
**/
function convert($inputFile, $outputFile)
{
$input = fopen($inputFile, "r");
$output = fopen($outputFile, "w");
if ($input && $output) {
while (($line = fgets($input)) !== false) {
if (!empty($line) && trim($line) != '') {
if (strpos($line, '--') === 0) {
$line = substr($line, 2);
} else if (strpos($line, '>') !== 0) {
$line = '>' . $line;
}
}
fwrite($output, $line);
}
fclose($input);
fclose($output);
success('Succeeded to convert "'.$inputFile.'" to "'.$outputFile.'".');
} else {
error('Failed to convert "'.$inputFile.'" to "'.$outputFile.'".');
}
}
$argument1 = $argv[1];
$argument2 = $argv[2];
convert($argument1, $argument2);
?>