2018-05-29

tcl-opencc: Tcl bindings for OpenCC (libopencc)

Open Chinese Convert (OpenCC, 開放中文轉換) is an opensource project for conversion between Traditional Chinese and Simplified Chinese, supporting character-level conversion, phrase-level conversion, variant conversion and regional idioms among Mainland China, Taiwan and Hong kong.

OpenCC 是一個優秀的開源專案,以 C++ 開發,支援 Linux、Mac OS X、Windows、iOS、Android 等平台,同時有 Node.js bindings,可以用來做中文繁簡轉換的工作。OpenCC 已經提供了一個命令列工具,可以用來指定輸入檔案、輸出檔案與指定設定檔,然後就可以利用這個命令列工具來做中文繁簡轉換。

一個更好的地方是,OpenCC 將核心函式庫獨立出來,所以我們可以使用 OpenCC 提供的函式庫來開發一些工具,或者是與自己的程式結合產生更多的功能。

所以 tcl-opencc 就是這樣寫出來的,這樣子如果我需要在 Tcl 進行繁簡轉換的工作,就可以使用 OpenCC 的函式庫,而不用呼叫外部的執行檔。

2018-05-28

openSUSE Leap 15.0 and OpenAL Soft

升級到 openSUSE Leap 15.0 以後,使用 tclopenal 播放音樂,都會跑出來下面的錯誤訊息:

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started



一開始我沒有搞清楚狀況,所以以為是沒有安裝 Jack Audio Server,但是後來我又想,Linux 一般的預設應該是 ALSA/PulseAudio,所以不應該是沒有安裝 Jack Audio Server 的問題。最後才想到,可能是 OpenAL Soft 的設定問題。

OpenAL Soft 是有支援 Jack 的,所以可能是我之前使用的版本不用設定,或者是之前的版本已經有設定好。但是不管如何,這個錯誤訊息在 openSUSE Leap 15.0 跑出來,所以我需要消除掉這個錯誤訊息。

接下來我發現 /etc/openal 目錄下沒有 alsoft.conf 這個檔案。這給了我提示,所以在搜尋以後,找到答案,我需要建立 alsoft.conf 檔案,並且設定如下:
[general]
drivers = -jack,


經過測試,這樣確實可以消除無法連接到 Jack 的錯誤訊息。

2018-05-24

tcl-cairo: Tcl bindings for Cairo library

tcl-cairo


使用 SWIG。資訊來自於 tclcairo。我只是透過範例來學習 SWIG 該如何使用,而剛好 tclcairo 網頁有範例可以用來測試,所以就嘗試看看。

Tcl and SWIG as a C/C++ Development Tool

Tcl and SWIG as a C/C++ Development Tool
SWIG and Tcl (3.0 doc)
Swig (Tcler's Wiki)


接下來我會花一點時間使用看看 SWIG,然後看能不能成功的將我需要的 C library 部份轉成 Tcl interface。因為不是很急迫,所以我只是開始收集資料而已。

2018-05-20

GNOCL: Tcl/GTk Bindings

tcl-gnocl-spec


GNOCL 可以讓你在 Tcl 使用 Gtk+ 2 library。這個 spec 目前使用 2018/05/10 的 Gnocl-Nightly-Build。

因為版本更替的關係,所以一開始的時候我以為 Label 的 markup 功能是失效的,後來才發現要使用 -useMarkup 來開啟功能。

再來是有個地方造成了一些困擾,就是如果直接按 x 想要離開,會發生無法離開的狀況,這需要使用 -onDestroy 並且指定 exit 才行。

所以下面就是一個修改上面二點以後的範例:
#!/usr/bin/tclsh

package require Gnocl
# create submenu for menu "File" with standard items "New" and 
# "Quit" (text, icon and accelerator). 'N', 'Q' respectively, 
# are underlined and are used as mnemonics.
set menu [gnocl::menu]
$menu add [gnocl::menuItem -text "%#New" -tooltip "Make new" \
      -onClicked {puts "That's new"}]
$menu add [gnocl::menuSeparator]
$menu add [gnocl::menuItem -text "%#Quit" -onClicked exit \
      -tooltip "Quit program"]

# create menu "File", 'F' is underlined and used as mnemonic
set file [gnocl::menuItem -text "%__File" -submenu $menu]

# create menu "Help" with item "About" 
set menu [gnocl::menu]
$menu add [gnocl::menuItem -text "%__About" \
      -tooltip "Show about dialog" \
      -onClicked {puts "Mini example (c) 2001 - 2003 P.G. Baum"}]
set help [gnocl::menuItem -text "%__Help" -submenu $menu]

# create toolbar with standard items "Quit" and "New"
set toolBar [gnocl::toolBar -style both]
$toolBar add item -text "%#Quit" -tooltip "Tooltip Quit" \
      -onClicked exit
$toolBar add space
$toolBar add item -text "%#New" -tooltip "Tooltip new" \
      -onClicked {puts "That's new"}

# create GTK+ application with menu, toolBar, statusbar 
# and a label as main widget
set box [gnocl::box -orientation vertical -borderWidth 0 -spacing 0]
set win [gnocl::window -child $box -title "Test Application" -onDestroy { exit } ]
$box add [gnocl::menuBar -children [list $file $help]]
$box add $toolBar 
$box add [gnocl::label -useMarkup 1 -text \
      {%<<span foreground="blue" size="large">Hello</span>\
      <span foreground="red" size="large">World</span>}] -expand 1
$box add [gnocl::statusBar] 

# enter GTK+ main loop
gnocl::mainLoop

2018-05-12

XQilla library 2.3.4: compatibility issue

我發現 XQilla 2.3.4 這個版本需要 Xerces-C++ 3.2.0 以上的版本。然後當我處理完相依性問題編譯成功以後,我發現 XQilla .so 的副檔名有改變(從 .so.3 變成 .so.2)。

結果重新編譯 tclxqilla 以後,會出現找不到 .so.3 的問題。我感覺 XQilla library 在 2.3.4 有相容性問題沒有處理好,所以在測試過以後,我決定跳過這個版本。

這也讓我的 openSUSE build service 上面的相關項目發生問題,因為我要重新編譯的關係,所以刪除項目以後重建一次,版本號沒有改變,但是 md5 變了,如果使用 zypper 安裝會出現警告和問題。

更新:
我稍微修改了 openSUSE build service 上面的 tclxqilla RPM spec,讓 build version 往上增加,這樣就不會同版本比對而可以消除使用 zypper 安裝會出現警告和問題。

2018-05-09

Tcl: identity function

identity function: The identity function accepts one value and simply returns that value.

Tcl 8.6 可以使用下列的方式:
string cat $var

或者是比較短的寫法:
lindex $var


很有趣的事情。

2018-04-30

NaviServer and Markdown

naviserver-markdown


還是記錄一下這件事。和之前寫的東西類似,也就是 Markdown 檔案輸出為 HTML 格式。在研究 NaviServer 目前的 code 以後,我發現在 NaviServer tcl 目錄下加上 markdown.tcl,就可以用來處理 /*.md。

下面是 markdown.tcl 檔案的內容:
#
# markdown.tcl --
#
#   Add tclllib markdown support to NaviServer
#

#
# Register the ns_markdownfie handler for .md files
#

package require Markdown

ns_register_proc GET  /*.md ns_markdownfie

#
# ns_markdownfie --
#
#   Callback for Makrdown file.
#

proc ns_markdownfie {args} {

    set path [ns_url2file [ns_conn url]]
    if {![ns_filestat $path stat]} {
        ns_returnnotfound
        return
    }

    set infile [open $path]
    set md [read $infile]
    close $infile
    set data [::Markdown::convert $md]

    ns_headers 200 "text/html;charset=utf-8"
    ns_write $data
}

# EOF

重開 NaviServer 以後測試,我發現這個寫法是可行的。

Tclunqlite v0.3.4

檔案放置網頁


Tclunqlite

About

This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL (Key/Value store and Document-store) database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.

Main Change

  1. Update UnQLite to 1.1.9

說明


這是一個小更新版本,整合 UnQLite 的版本更新。

2018-04-27

Apache Rivet and mod_actions

mod_actions


雖然 mod_actions 的文件是寫 CGI script,但是你可以使用 Apache Rivet, PHP 或者是類似的工具來撰寫。

下面是測試用的程式,用來將 markdown 檔案 (*.md) 轉換為 HTML 格式以後輸出:
package require Markdown

::rivet::load_env

if {[info exists ::request::env(PATH_TRANSLATED)]==0} {
    ::rivet::headers numeric 400
    return
}

if {[file exists $::request::env(PATH_TRANSLATED)]==0} {
    ::rivet::headers numeric 404
    return
}

set in [open $::request::env(PATH_TRANSLATED)]
set md [read $in]
close $in
set data [::Markdown::convert $md]

::rivet::headers type "text/html;charset=utf-8"
puts $data

再來加上設定(我加在 VirtualHost configure file):
Action markdown /mdhandler.tcl
AddHandler markdown .md

最後重開 Apache HTTP server 然後進行測試。我把程式放在 Github 上。