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


很有趣的事情。