Browse Source

php - convert TAB to tabs in ckdb.php - optionally on by default

master
kanoi 8 years ago
parent
commit
c94a57f311
  1. 27
      src/ckdb.php

27
src/ckdb.php

@ -19,10 +19,12 @@ function getsock2($fun, $tmo)
return _getsock($fun, "$socket_dir$socket_name/$socket_file", $tmo); return _getsock($fun, "$socket_dir$socket_name/$socket_file", $tmo);
} }
# #
function msg($line, $tmo = false) function msg($line, $tabs, $tmo = false)
{ {
global $fld_sep, $val_sep; global $fld_sep, $val_sep;
if ($tabs)
$line = str_replace("TAB", "\t", $line);
$fun = 'stdin'; $fun = 'stdin';
$ret = false; $ret = false;
$socket = getsock2($fun, $tmo); $socket = getsock2($fun, $tmo);
@ -40,7 +42,8 @@ function msg($line, $tmo = false)
function usAge($a0) function usAge($a0)
{ {
global $socket_name_def, $socket_dir_def, $socket_file_def; global $socket_name_def, $socket_dir_def, $socket_file_def;
echo "usAge: php $a0 [name [dir [socket]]]\n"; echo "usAge: php $a0 [-t] [name [dir [socket]]]\n";
echo " -t = don't convert 'TAB' to a tab character\n";
echo " default name = $socket_name_def\n"; echo " default name = $socket_name_def\n";
echo " default dir = $socket_dir_def\n"; echo " default dir = $socket_dir_def\n";
echo " default socket = $socket_file_def\n"; echo " default socket = $socket_file_def\n";
@ -48,18 +51,26 @@ function usAge($a0)
exit(1); exit(1);
} }
# #
$tabs = true;
#
if (count($argv) > 1) if (count($argv) > 1)
{ {
if ($argv[1] == '-?' || $argv[1] == '-h' || $argv[1] == '-help' if ($argv[1] == '-?' || $argv[1] == '-h' || $argv[1] == '-help'
|| $argv[1] == '--help') || $argv[1] == '--help')
usAge($argv[0]); usAge($argv[0]);
$socket_name = $argv[1]; $a = 1;
if (count($argv) > 2) if ($argv[$a] == '-t')
{
$tabs = false;
$a++;
}
$socket_name = $argv[$a++];
if (count($argv) > $a)
{ {
$socket_dir = $argv[2]; $socket_dir = $argv[$a++];
if (count($argv) > 3) if (count($argv) > $a)
$socket_file = $argv[3]; $socket_file = $argv[$a];
} }
} }
# #
@ -68,7 +79,7 @@ while ($line = fgets(STDIN))
$line = trim($line); $line = trim($line);
if (strlen($line) > 0) if (strlen($line) > 0)
{ {
$rep = msg($line); $rep = msg($line, $tabs);
if ($rep === false) if ($rep === false)
echo "Failed\n"; echo "Failed\n";
else else

Loading…
Cancel
Save