-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjss.php
More file actions
67 lines (58 loc) · 1.5 KB
/
jss.php
File metadata and controls
67 lines (58 loc) · 1.5 KB
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
67
<?php
function jss_parse_file(string $file_name) : void
{
$file = fopen($file_name, "r");
if ($file === false)
{
die("Failed to open file\n");
}
$json_data = NULL;
$val = NULL;
try
{
while ($line = fgets($file, 1024))
{
if (strchr($line, '#')) continue;
if (strstr($line, "END")) break;
if (strstr($line, "FILE") !== false)
{
preg_match_all('/"([^"]*)"/', $line, $matches);
if (isset($matches[1][0]))
{
$data_buffer = file_get_contents($matches[1][0]);
$json_data = json_decode($data_buffer, true);
}
else
{
die("No json file found\n");
}
}
if (strstr($line, "GET") !== false)
{
preg_match_all('/"([^"]*)"/', $line, $matches);
$key = $matches[1][0];
if (isset($key))
{
$val = $json_data[$key];
}
else
{
die("Key not found\n");
}
}
if (strstr($line, "PRINT") !== false)
{
echo $val . "\n";
}
}
}
finally
{
fclose($file);
}
}
if ($GLOBALS["argc"] < 2)
{
die("Usage: php jss.php [file_name]\n");
}
jss_parse_file($GLOBALS["argv"][1]);