2013-06-16

Check Tcl support Thread or not

proc is_threaded {} {
 return [expr {[info exists ::tcl_platform(threaded)] && $::tcl_platform(threaded)}]
}


然後就可以使用 is_threaded 來判斷是否有支援 Thread.


如果要共用資料,可以使用 tsv command。下面是改寫以後的備份程式:
#!/usr/local/bin/tclsh
#
# This file is used to backup my homepage
#


proc is_threaded {} {
 return [expr {[info exists ::tcl_platform(threaded)] && $::tcl_platform(threaded)}]
}

set support [is_threaded]

proc backup_to_7z {} {
  set backupfile $::env(HOME)
  append backupfile "/Homepage-"
  append backupfile [clock format [clock seconds] -format %Y%m%d]
  append backupfile ".7z"

  set backupdir $::env(HOME)
  append backupdir "/public_html"

  set fileExist [file exists $backupfile]
  if {$fileExist > 0} {
      puts "Now try to remove old backup file."
      file delete $backupfile
  }

  set var [list 7z -p12345 a $backupfile $backupdir]
  exec {*}$var
}


if {$support == 1} {
  package require Tk
  package require Thread

  set ::gThread [thread::create {thread::wait} ]
  tsv::set body_backup_to_7z shared [info body backup_to_7z]


  label .greetings -text "Now backup my homepage..." -bd 4 -relief ridge
  pack .greetings -fill both

  wm title . "Backup"

  thread::send -async $::gThread { 
    set command [tsv::get body_backup_to_7z shared]
    eval $command
  } result  

  vwait result
} else {
  puts "No thread support..., so this script can't use Thread."

  backup_to_7z
}

exit

利用 Tcl 的特性,所以可以取得 proc body 以後當成是共用資料傳遞,如果資料量很小的時候,這是個很好玩的做法。

2013-06-15

Build snack 2.2.10 on openSUSE 12.3

如果是從 Snack 下載 source code 自己 build,會遇到二個問題。

1. math.h compilation error: expected declaration specifiers or '…' before '('

解決方法參考: http://stackoverflow.com/questions/9503473/math-h-compilation-error-expected-declaration-specifiers-or-before

找到 math.h,然後放到 roundf 函式的宣告的前面(這是只有 GCC 才有的問題) ,所以要做的就是修正 ./jkFormatMP3.c,

#include
#include
#include "snack.h"
#include "jkFormatMP3.h"


2. 因為要在 Linux 上使用 ALSA,所以要這樣下(在 x86_64 版本上):
./configure --enable-alsa --enable-shared --with-tcl=/usr/lib64 --with-tk=/usr/lib64

如果是 x86 的版本:
./configure --enable-alsa --enable-shared --with-tcl=/usr/lib --with-tk=/usr/lib


但是因為 _snd_pcm_mmap_hw_ptr 已經是過時的 function,所以要使用 snack-alsa.patch 裡面的內容來修正,下面是修正的地方:

Index: unix/jkAudIO_alsa.c
===================================================================
--- unix/jkAudIO_alsa.c.orig
+++ unix/jkAudIO_alsa.c
@@ -49,6 +49,8 @@ static int littleEndian = 0;

 static int minNumChan = 1;

+static snd_pcm_uframes_t hw_bufsize = 0;
+
 int
 SnackAudioOpen(ADesc *A, Tcl_Interp *interp, char *device, int mode, int freq,
            int nchannels, int encoding)
@@ -135,6 +137,9 @@ SnackAudioOpen(ADesc *A, Tcl_Interp *int
     Tcl_AppendResult(interp, "Failed setting HW params.", NULL);
     return TCL_ERROR;
   }
+
+  snd_pcm_hw_params_get_buffer_size (hw_params, &hw_bufsize);
+
   snd_pcm_hw_params_free(hw_params);
   snd_pcm_prepare(A->handle);
   if (A->mode == RECORD) {
@@ -202,6 +207,8 @@ SnackAudioPost(ADesc *A)
   int i;
   static char buf[64];

+  return;
+     
   if (A->debug > 1) Snack_WriteLog("  Enter SnackAudioPost\n");

   for (i = 0; i < 1000; i++) {
@@ -267,12 +274,14 @@ SnackAudioWriteable(ADesc *A)
 long
 SnackAudioPlayed(ADesc *A)
 {
-  long avail = _snd_pcm_mmap_hw_ptr(A->handle);
+  // FIX Here, _snd_pcm_mmap_hw_ptr is deprecated in new alsalib
+  long played = A->nWritten - (hw_bufsize - SnackAudioWriteable(A));
+  // long avail = _snd_pcm_mmap_hw_ptr(A->handle);
  
-  if (avail < 0)
-    avail = 0;
+  if (played < 0)
+   return 0;

-  return (avail+A->nPlayed);
+  return (played);
 }



在修正過後,就可以編譯出來正確的 Tcl-Snack (Linux-ALSA) 版本。但是我不知道實際上執行的時候是否正常。


剛剛快速測試以後,確定可以撥放 wav 檔,所以是可以正確使用的。



更新:
在將 tclsh 放置在 /usr/bin 以後,即使 snack 在 configure 時設定 prefix ,make install 以後仍然會放置在 /lib64/,需要自己手動放置到 /usr/lib64 (不知道怎麼解決)

Build tDOM-0.8.3 on openSUSE 12.3

錯誤訊息:

./generic/tcldom.c: In function ‘tcldom_EvalLocked’:
./generic/tcldom.c:5937:47: error: ‘Tcl_Interp’ has no member named ‘errorLine’
./generic/tcldom.c: In function ‘tcldom_RegisterDocShared’:
./generic/tcldom.c:5957:9: warning: variable ‘refCount’ set but not used [-Wunused-but-set-variable]
make: *** [tcldom.o] Error 1



解決方法:
http://sourceforge.net/p/modules/bugs/62/

Apparently errorLine is a deprecated feature.

A temporary fix is to enable this deprecated feature - although eventually this will cease to work. To do this configure with a line like this:

bash> CPPFLAGS="-DUSE_INTERP_ERRORLINE" ./configure
Then make && make install as usual.

2013-06-04

Tcl/Tk 8.4.20 RELEASED

Tcl/Tk 8.4.20 RELEASED



文章中寫到:

This is the twentieth and *FINAL*  patch release of Tcl/Tk 8.4.  With this release, support for Tcl/Tk 8.4 comes to an end.

所以如果沒有意外,這將是最後一個 Tcl/Tk 8.4.x 的版本。

2013-06-02

FreeWrap 6.6: both 32 and 64 bit Windows version support

FreeWrap


在隔了一陣子回來看 FreeWrap 的情況以後,發現 FreeWrap 現在 32/64 bit Windows 環境都支援了,我想這是一個好消息,提供了更多的彈性。

How to find out the Tcl version

How to find out the Tcl version


如果我們要知道目前的 Tcl 版本,可以使用 puts $tcl_version 就可以知道目前使用的版本。

2013-06-01

Building Tcl/Tk with Mingw

Building Tcl/Tk with Mingw


Tcler's Wiki 上有說明怎麼使用 Mingw + MSYS build Tcl/Tk,經過測試,Tcl 8.6.0 也 buld 成功。

我主要使用下列的 script:

#!/bin/sh
mkdir -p /src
mkdir -p /opt/tcl
mkdir -p /build/tcl
mkdir -p /build/tk
[ -e /src/tcl ] && {
    cd /build/tcl
    /src/tcl/win/configure --prefix=/opt/tcl --enable-threads && make && make install && {
        [ -e /src/tk ] && {
        cd /build/tk
        /src/tk/win/configure --prefix=/opt/tcl --enable-threads --with-tcl=/build/tcl \
            && make && make install
        }
    }
}