2019-09-11 22:16:07 +04:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?php # -*- coding: utf-8 mode: php -*- vim:sw=2:sts=2:et:ai:si:sta:fenc=utf-8
|
|
|
|
|
|
|
|
function fix_value($value) {
|
2019-10-10 10:24:07 +04:00
|
|
|
if ($value === "true") return true;
|
|
|
|
elseif ($value === "false") return false;
|
|
|
|
elseif ($value === "null") return null;
|
|
|
|
else return $value;
|
|
|
|
}
|
|
|
|
function setp(&$array, $keys, $value) {
|
|
|
|
if (is_array($keys)) $keys = implode(".", $keys);
|
|
|
|
$keys = explode(".", $keys);
|
|
|
|
$last = count($keys) - 1;
|
|
|
|
$i = 0;
|
|
|
|
if ($array === null) $array = array();
|
|
|
|
$current =& $array;
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
if ($i == $last) break;
|
|
|
|
if (!array_key_exists($key, $current)) $current[$key] = array();
|
|
|
|
if (!is_array($current[$key])) $current[$key] = array($current[$key]);
|
|
|
|
$current =& $current[$key];
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
if ($key === "") {
|
|
|
|
$current[] = $value;
|
|
|
|
} else {
|
|
|
|
$current[$key] = $value;
|
|
|
|
}
|
2019-09-11 22:16:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$empty = true;
|
|
|
|
for ($i = 1; $i < $argc; $i++) {
|
|
|
|
$namevalue = $argv[$i];
|
|
|
|
if (preg_match('/(.*?)=(.*)/', $namevalue, $ms)) {
|
|
|
|
$name = $ms[1];
|
|
|
|
$value = fix_value($ms[2]);
|
2019-10-10 10:24:07 +04:00
|
|
|
setp($data, $name, $value);
|
2019-09-11 22:16:07 +04:00
|
|
|
} else {
|
2019-10-10 10:24:07 +04:00
|
|
|
$value = fix_value($namevalue);
|
|
|
|
$data[] = $value;
|
2019-09-11 22:16:07 +04:00
|
|
|
}
|
|
|
|
$empty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$options = JSON_NUMERIC_CHECK;
|
|
|
|
if ($empty) $options += JSON_FORCE_OBJECT;
|
|
|
|
echo json_encode($data, $options);
|