forked from nviet/lingoes-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.php
66 lines (56 loc) · 1.99 KB
/
converter.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
56
57
58
59
60
61
62
63
64
65
66
<?php
if (php_sapi_name() == "cli" || php_sapi_name() == "embed")
{
echo PHP_EOL . "Lingoes Converter v0.1" . PHP_EOL;
echo "> by WindyLea" . PHP_EOL;
echo "---" . PHP_EOL;
$input = isset($_SERVER["argv"][1]) ? trim($_SERVER["argv"][1]) : "";
$output = isset($_SERVER["argv"][2]) ? trim($_SERVER["argv"][2]) : "";
if (empty($input))
{
$line = false;
while(!$line)
{
echo "+ Input file: ";
$cmdHandle = fopen("php://stdin", "r");
$line = trim(fgets($cmdHandle));
}
$input = trim($line, '"');
}
echo "+ Output file (Optional): ";
$line = trim(fgets($cmdHandle));
$output = trim($line, '"');
echo "+ Entry word encoding (Optional / Default is UTF-8): ";
$line = trim(fgets($cmdHandle));
$encodingWord = trim($line, '"');
echo "+ Entry definition encoding (Optional / Default is UTF-16LE): ";
$line = trim(fgets($cmdHandle));
$encodingDef = trim($line, '"');
} else
{
$input = isset($_GET["input"]) ? trim($_GET["input"]) : "";
$output = isset($_GET["output"]) ? trim($_GET["output"]) : "";
$encodingWord = isset($_GET["encodingWord"]) ? trim($_GET["encodingWord"]) : "UTF-8";
$encodingDef = isset($_GET["encodingDef"]) ? trim($_GET["encodingDef"]) : "UTF-16LE";
}
set_time_limit(0);
ini_set("memory_limit", "128M");
include("LingoesConverter.php");
echo PHP_EOL . "Converting..." . PHP_EOL;
$timeStart = microtime(true);
$plc = new LingoesConverter;
$plc->input = $input;
$plc->output = $output;
$plc->encodingDef = $encodingDef;
$plc->encodingWord = $encodingWord;
$convert = $plc->convert();
if (!$convert)
{
$lastMessage = end($plc->logs);
echo "* " . $lastMessage[1] . PHP_EOL;
}
$timeEnd = microtime(true);
echo PHP_EOL . "# Execution time: " . round(($timeEnd - $timeStart), 2) . " (s)";
echo PHP_EOL . "# Memory usage: " . (memory_get_usage(true) / 1024) . " KB";
echo PHP_EOL . "# Peak memory usage: " . (memory_get_peak_usage(true) / 1024) . " KB";
?>