From: Nicolas Boisselier Date: Tue, 8 May 2018 16:56:39 +0000 (+0100) Subject: lib/php/out.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=3395b03b3c0cff4288079fbf1b7929ce058a5db8;p=nb.git lib/php/out.php --- diff --git a/etc/vim/source/debian.vim b/etc/vim/source/debian.vim deleted file mode 100644 index 1d64115d..00000000 --- a/etc/vim/source/debian.vim +++ /dev/null @@ -1,82 +0,0 @@ -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" -" Take from the Debian package and the exemple on $VIM/vim_exemples -" AUGROUP -" -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -if has("autocmd") - - """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - " Set some sensible defaults for editing C-files - " - augroup cprog - " Remove all cprog autocommands - au! - - " When starting to edit a file: - " For *.c and *.h files set formatting of comments and set C-indenting on. - " For other files switch it off. - " Don't change the order, it's important that the line with * comes first. - autocmd BufRead * set formatoptions=tcql nocindent comments& - autocmd BufRead *.c,*.h set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,:// - augroup END - - """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - "" Gzip and Bzip2 files support - " Also, support editing of gzip-compressed files. DO NOT REMOVE THIS! - " This is also used when loading the compressed helpfiles. - " - augroup gzip - " Remove all gzip autocommands - au! - - " Enable editing of gzipped files - " read: set binary mode before reading the file - " uncompress text in buffer after reading - " write: compress file after writing - " append: uncompress file, append, compress file - autocmd BufReadPre,FileReadPre *.gz set bin - autocmd BufReadPre,FileReadPre *.gz let ch_save = &ch|set ch=2 - autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip - autocmd BufReadPost,FileReadPost *.gz set nobin - autocmd BufReadPost,FileReadPost *.gz let &ch = ch_save|unlet ch_save -" NB 19.07.14 autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " . %:r - - autocmd BufWritePost,FileWritePost *.gz !mv :r - autocmd BufWritePost,FileWritePost *.gz !gzip -9 :r - - autocmd FileAppendPre *.gz !gunzip - autocmd FileAppendPre *.gz !mv :r - autocmd FileAppendPost *.gz !mv :r - autocmd FileAppendPost *.gz !gzip :r - augroup END - - """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - " BZIP2 - " - augroup bzip2 - " Remove all bzip2 autocommands - au! - - " Enable editing of bzipped files - " read: set binary mode before reading the file - " uncompress text in buffer after reading - " write: compress file after writing - " append: uncompress file, append, compress file - autocmd BufReadPre,FileReadPre *.bz2 set bin - autocmd BufReadPre,FileReadPre *.bz2 let ch_save = &ch|set ch=2 - autocmd BufReadPost,FileReadPost *.bz2 set cmdheight=2|'[,']!bunzip2 - autocmd BufReadPost,FileReadPost *.bz2 set cmdheight=1 nobin|execute ":doautocmd BufReadPost " . %:r - autocmd BufReadPost,FileReadPost *.bz2 let &ch = ch_save|unlet ch_save - - autocmd BufWritePost,FileWritePost *.bz2 !mv :r - autocmd BufWritePost,FileWritePost *.bz2 !bzip2 :r - - autocmd FileAppendPre *.bz2 !bunzip2 - autocmd FileAppendPre *.bz2 !mv :r - autocmd FileAppendPost *.bz2 !mv :r - autocmd FileAppendPost *.bz2 !bzip2 -9 --repetitive-best :r - augroup END - -endif " has ("autocmd") - diff --git a/etc/vim/source/debian.vim.disable b/etc/vim/source/debian.vim.disable new file mode 100644 index 00000000..1d64115d --- /dev/null +++ b/etc/vim/source/debian.vim.disable @@ -0,0 +1,82 @@ +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" +" Take from the Debian package and the exemple on $VIM/vim_exemples +" AUGROUP +" +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if has("autocmd") + + """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + " Set some sensible defaults for editing C-files + " + augroup cprog + " Remove all cprog autocommands + au! + + " When starting to edit a file: + " For *.c and *.h files set formatting of comments and set C-indenting on. + " For other files switch it off. + " Don't change the order, it's important that the line with * comes first. + autocmd BufRead * set formatoptions=tcql nocindent comments& + autocmd BufRead *.c,*.h set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,:// + augroup END + + """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + "" Gzip and Bzip2 files support + " Also, support editing of gzip-compressed files. DO NOT REMOVE THIS! + " This is also used when loading the compressed helpfiles. + " + augroup gzip + " Remove all gzip autocommands + au! + + " Enable editing of gzipped files + " read: set binary mode before reading the file + " uncompress text in buffer after reading + " write: compress file after writing + " append: uncompress file, append, compress file + autocmd BufReadPre,FileReadPre *.gz set bin + autocmd BufReadPre,FileReadPre *.gz let ch_save = &ch|set ch=2 + autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip + autocmd BufReadPost,FileReadPost *.gz set nobin + autocmd BufReadPost,FileReadPost *.gz let &ch = ch_save|unlet ch_save +" NB 19.07.14 autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " . %:r + + autocmd BufWritePost,FileWritePost *.gz !mv :r + autocmd BufWritePost,FileWritePost *.gz !gzip -9 :r + + autocmd FileAppendPre *.gz !gunzip + autocmd FileAppendPre *.gz !mv :r + autocmd FileAppendPost *.gz !mv :r + autocmd FileAppendPost *.gz !gzip :r + augroup END + + """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + " BZIP2 + " + augroup bzip2 + " Remove all bzip2 autocommands + au! + + " Enable editing of bzipped files + " read: set binary mode before reading the file + " uncompress text in buffer after reading + " write: compress file after writing + " append: uncompress file, append, compress file + autocmd BufReadPre,FileReadPre *.bz2 set bin + autocmd BufReadPre,FileReadPre *.bz2 let ch_save = &ch|set ch=2 + autocmd BufReadPost,FileReadPost *.bz2 set cmdheight=2|'[,']!bunzip2 + autocmd BufReadPost,FileReadPost *.bz2 set cmdheight=1 nobin|execute ":doautocmd BufReadPost " . %:r + autocmd BufReadPost,FileReadPost *.bz2 let &ch = ch_save|unlet ch_save + + autocmd BufWritePost,FileWritePost *.bz2 !mv :r + autocmd BufWritePost,FileWritePost *.bz2 !bzip2 :r + + autocmd FileAppendPre *.bz2 !bunzip2 + autocmd FileAppendPre *.bz2 !mv :r + autocmd FileAppendPost *.bz2 !mv :r + autocmd FileAppendPost *.bz2 !bzip2 -9 --repetitive-best :r + augroup END + +endif " has ("autocmd") + diff --git a/etc/vim/source/vars.vim b/etc/vim/source/vars.vim index dd574a75..a22460fb 100644 --- a/etc/vim/source/vars.vim +++ b/etc/vim/source/vars.vim @@ -4,20 +4,21 @@ " Command to check files per file types " " rows.fields=id,cmd_check -">SHELL_REPLACE echo "let mimeCheck = {"; nb_api '/pub/meta/ls/key,val.csv?cat=file.check' | tail -n +2 | sort -k 1 | sed -E -e "s/'/''/g" -e "s/^(.*?)\t(.*)$/ \\\,'\1' : '\2'/" -e "0,/,/s/,//"; echo "\}" +">SHELL_REPLACE nb_api '/nb/meta/ls/key,val.vim_hash?cat=file.check&preff=%09&name=mimeCheck' let mimeCheck = { - \'bash' : 'bash -c' - \,'erb' : 'sh -c "cat | erb -x - | ruby -c" <' - \,'haproxy' : 'haproxy -c -f' - \,'html' : 'xmllint --noout --html' - \,'json' : 'ruby -rjson -e ''puts JSON.parse(File.read(ARGV[0]))''' - \,'perl' : 'perl -c -w' - \,'php' : 'php --define error_reporting=22519 --define display_errors=1 --define log_errors=1 --define html_errors=0' - \,'puppet' : 'perl -e ''system qq/puppet parser validate $ARGV[0] && puppet-lint --no-selector_inside_resource-check --no-autoloader_layout-check --no-hard_tabs-check --no-80chars-check $ARGV[0]/''' - \,'python' : 'python -m py_compile' - \,'ruby' : 'ruby -c' - \,'sh' : 'sh -c' - \,'xml' : 'xmllint --noout' - \,'yaml' : 'ruby -ryaml -e ''''puts YAML.dump(YAML.load_file(ARGV[0]))''' + \ 'bash' : 'bash -c' + \,'erb' : 'sh -c "cat | erb -x - | ruby -c" <' + \,'haproxy': 'haproxy -c -f' + \,'html' : 'xmllint --noout --html' + \,'json' : 'ruby -rjson -e ''puts JSON.parse(File.read(ARGV[0]))''' + \,'lua' : 'lua' + \,'perl' : 'perl -c -w' + \,'php' : 'php --define error_reporting=22519 --define display_errors=1 --define log_errors=1 --define html_errors=0' + \,'puppet' : 'perl -e ''system qq/puppet parser validate $ARGV[0] && puppet-lint --no-selector_inside_resource-check --no-autoloader_layout-check --no-hard_tabs-check --no-80chars-check $ARGV[0]/''' + \,'python' : 'python -m py_compile' + \,'ruby' : 'ruby -c' + \,'sh' : 'sh -c' + \,'xml' : 'xmllint --noout' + \,'yaml' : 'ruby -ryaml -e ''puts YAML.dump(YAML.load_file(ARGV[0]))''' \} ")","%1") -- end + -- Fix markdown module content = content:gsub(" +()","%1") content = content:gsub("() +","%1") content = content:gsub(" +()","%1") diff --git a/lib/php/out.php b/lib/php/out.php index cf0b29f7..296cf251 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -166,6 +166,8 @@ Class Out extends Nb { if (is_scalar($v) and self::is_binary($v)) $row[$k] = base64_encode($v); } + if (!empty($o['quote'])) $row = self::quote($row,$o); + # buffering if (!empty($o['align'])) { if (!isset($o['sep'])) $o['sep'] = $o['align']; @@ -175,7 +177,7 @@ Class Out extends Nb { $tmp_row = $row; foreach ($tmp_row as $k => $v) { if (!isset($o['length'][$k])) $o['length'][$k] = 0; - if (!empty($o['quote'])) $tmp_row[$k] = $v = self::quote($v,$o['quote'],isset($o['quote_escape']) ? $o['quote_escape'] : null); +# NB 08.05.18 if (!empty($o['quote'])) $tmp_row[$k] = $v = self::quote($v,$o); $l = mb_strlen($v,self::charset()); if ($l > $o['length'][$k]) $o['length'][$k] = $l; } @@ -183,8 +185,10 @@ Class Out extends Nb { $o['rows'][] = $tmp_row; return true; + } + # user function - } elseif (self::type_call('row',$o,$row)) { + if (self::type_call('row',$o,$row)) { $ret = true; # html/xml tag style @@ -379,8 +383,21 @@ Class Out extends Nb { } public static function quote($str,$quote='"',$quote_escape='\\') { - if ($quote === null or $quote == true) $quote = '"'; + if (is_array($str)) { + foreach ($str as $k=>$v) { + $str[$k] = self::quote($v,$quote,$quote_escape); + } + return $str; + } + + if (is_array($quote)) { + if (isset($quote['quote_escape'])) $quote_escape = $quote['quote_escape']; + $quote = $quote['quote']; + } + + if ($quote === null or $quote === true) $quote = '"'; if ($quote_escape === null) $quote_escape = '\\'; + $str = str_replace($quote,$quote_escape.$quote,$str); $str = $quote . $str . $quote; return $str; @@ -427,13 +444,7 @@ Class Out extends Nb { $values = []; foreach (array_values($row) as $k=>$v) { -# NB 14.12.17 if (self::is_binary($v)) { -# NB 14.12.17 $values[] = $v; -# NB 14.12.17 break; -# NB 14.12.17 } - if (!empty($o['quote'])) $v = $o['quote'] . - str_replace($o['quote'],$o['quote_escape'].$o['quote'],$v) - . $o['quote']; +# NB 08.05.18 if (!empty($o['quote'])) $v = self::quote($v,$o); $values[] = str_replace("\n",'\\n',str_replace("\r","",self::scalar($v))); } diff --git a/lib/php/out/php_hash.php b/lib/php/out/php_hash.php index f56823c4..79cd584f 100644 --- a/lib/php/out/php_hash.php +++ b/lib/php/out/php_hash.php @@ -6,6 +6,7 @@ return [ 'preff' => self::p('preff',''), 'row' => function (&$o,&$r) { if ($o['preff']) echo $o['preff']; + $keys = array_keys($r); for ($i=2;$i self::p('sep',':'), 'eol' => "\n", 'quote' => "'", -'row' => function (&$o,&$r) { - static $count; - echo '\\'.( empty($count) ? ' ' : ',' ); - $count++; +return [ + 'align' => self::p('sep',': '), + 'eol' => "\n", + 'quote' => "'", + 'quote_escape' => "'", + 'preff' => self::p('preff',''), + 'name' => self::p('name','CHANGEME'), + 'head' => function (&$o,&$r) { + echo 'let '.$o['name'].' = {'; + }, + 'end' => function (&$o,&$r) { + echo '\\}'.$o['eol']; + }, + 'row' => function (&$o,&$r) { + static $count; + if ($o['preff']) echo $o['preff']; + echo '\\'.( empty($count) ? ' ' : ',' ); + $count++; - $keys = array_keys($r); - for ($i=2;$i diff --git a/share/db/nb.db b/share/db/nb.db index 165daab6..820cbfc2 100644 Binary files a/share/db/nb.db and b/share/db/nb.db differ diff --git a/share/db/update.sh b/share/db/update.sh index 04a510e1..9fa408e7 100755 --- a/share/db/update.sh +++ b/share/db/update.sh @@ -9,8 +9,7 @@ cd "$(dirname "$0")" && ( echo 'PRAGMA encoding="UTF-8";' echo 'PRAGMA foreign_keys=OFF;' - #dbq2sqlite db=pub 'table-name=!~^(zipcode|geo)' - nb_api '/pub/dump/sqlite?table-name=!~^(zipcode|geo)' + nb_api '/pub/dump/sqlite?table-name=!~^(zipcode|geo|meta)' echo 'VACUUM;' ) | sqlite3 "nb.db"