Friday, December 21, 2007

emacs - malloc_jumpstart() error

After upgrade to OS X Leopard (Currently 10.5.1), the default emacs version fails to start. I checked with Google, and find out how to do it.

The problem is because my emacs version is still 21.X, need to update with dumpemacs.


bash-3.2$ sudo mv /usr/bin/emacs-i386 /usr/bin/emacs-i386.orig
bash-3.2$ /usr/libexec/dumpemacs -V
22.1

bash-3.2$ sudo /usr/libexec/dumpemacs -d
Checking if emacs is up-to-date
emacs is not up-to-date. Needs dumping
...
bash-3.2$ emacs --version
GNU Emacs 22.1.1

Wednesday, December 19, 2007

cscope on windows

"cscope -bqR" failed on Windows, it does not prompt any message but when I do a search for a function with cscope, it always doesn't give me a happy message. Because my project is mainly a c++ project!!! It is confusion on Windows "-R" recusive just find c not cpp files.

I need a extra script to generate "cscope.files", then generate cscope database.


find . -name "*.cpp" -o -name "*.[ch]" > cscope.files
cscope -b -q


On linux, there is no such problems.

And I also install "UnxUtils.zip" from here, it provides basic gnu tools for win32.

Tuesday, December 18, 2007

dsfoo - with vcscommand

As I check Google code, it works with vcscommand which is a vim plugin.

For Windows user, to use Google code, has to install svn first, I download "svn-1.4.3-setup.exe" for the Windows version, and it works well with my vim. (Mostly I would like to use svn on Linux or Mac platform, but I also need my vim work on Windows)

using vcscommand with vim is quite simple.

- install vcscommand to vim 7.0
- checkout dsfoo with svn (demonstrates with my previous blog)
- find help :help vcscommand, the document is great!
- :VCSLog, :VCSDiff check the log and difference, use zz to close the buffer.
- :VCSCommit -m "commit..." will commit current file in vim, quite easy!

Note vcscommand is not only work with svn, it also works with cvs, the baseline is after you checkout the source code, you can edit the source code with vim, and commit any changes in vim.

dsfoo on Google Code

Today, I found Google provides hosting for open source project, so I just create a project -- dsfoo, to host some of my programming notes, scripts and code for share in the Internet.

To check out with anonymous...

svn checkout http://dsfoo.googlecode.com/svn/trunk dsfoo-read-only


Myself, to import...
$ svn import -m "import..." ./turing https://dsfoo.googlecode/svn/trunk
Adding turing/turing_first.sed
Adding turing/README.turing_first

Committed revision 2.


to checkout and checkin...

$ svn checkout https://dsfoo.googlecode.com/svn/trunk dsfoo --username dsmarkchen
...
$ svn commit -m "update README..." dsfoo --username dsmarkchen
Sending dsfoo/README.turing_first
Transmitting file data.
Committed revision 3.


And check the log...
$ svn log ./dsfoo

Thursday, December 13, 2007

Mac - Terminal font


The default Terminal font on Mac is Monaco 10pt, but I am a little missed with the font with Linux (xorg 7.0), so I make a little search, to try some other fonts, and find the bitstream Vera Mono 10pt is quite the same with the Linux, and "bitstream-vera" is gnome's free font, so it is free for me to use. Great.

Download font to Mac is not very hard, First download the package of the font and open it which extracts the ttf file (I did it with FireFox), and with the Finder, I can open the ttf file by double click on the file itself, it brings up the font text demo with a button "install the font", so I just click on the button and it will do what it is supposed to do. Super easy!

Then with Terminal Preference, I can select the font to use, and should be enable "antialias text" (the default is disabled that makes the monospaced font ugly), and if I choose black as background, I have to change opacity to 100% as well.

Friday, December 7, 2007

switch to vi

It's been a big decision to switch to vi. I have been using emacs for 10 years, it helps me on all the platforms from Windows, Linux to Mac OS X. Emacs lisp is such a powerful language which makes emacs so extensible. I would be miss the use of calender and diary, eshell, and xcscope with emacs.

Switching does not mean emacs is bad, may be I will change back to emacs if failed on vi, it's more like the personal taste. As I learned in these days, cscope, sed, the LaunchBar instead of QuickSilver, I feel I am more fond of "efficiency" instead of beauty.

I still didn't totally change to vi because of the gap of learning vi. Here is some notes I would like to share.

1. open file in vim. I learn vim from tutor, it shows :r to read file content to current file buffer, but did not show me how to open a file to a buffer compared with emacs's ctrl-x ctrl-f command. Here is the result :e with a file name will open the file.

2. text column. As the first experience, I enter some text, but find a line is more than 80 charactors if I don't hit cr to change to a new line, and it is a little annoying. Here is the result :set tw=80 will set textwidth to 80.

3. vimrc. Where is the location of vimrc? It is different on all the platforms, to find it the best way is use :version. In windows, it $VIM/.vimrc, on Linux it is ~/.vim/.vimrc, while on mac os x, it is "~/.vimrc".

4. The insert mode and the normal mode. Still a long way to get used to the normal mode, why the default is set to the normal mode instead of the insert mode? Also learning key strokes on normal mode, for instance, y is for copy, p is for paste, d is for delete and / for search, blah blah.

Monday, December 3, 2007

gnu sed on mac

I found the default sed tool on my MacBook is a bsd version instead of the gnu version, and my Turing machine script can not run with the bsd sed:-(, there are too many differences, so I have to build gnu sed on my Mac.

First download the source code from here, currently I am using the version 4.1.4, and 4.1.5 is broken for "install_sh" dependency.

Build sed with:

./configure --prefix=/opt/markc
make
sudo make install


Then sed is ready to use, but make sure the path /opt/markc/bin is in PATH environment.

Turing's Very First Example (with sed)

I have fun with sed and Turing Machine. It is pleasure to digg into sed, to find out the powerful features by sed. To me, sed is not just a tool for string find and replacement, but also Turing-Complete, that means sed is programable, the best way to prove it is to construct a Turing Machine. What I choose here is Turing's very first example by Alan Turing, so I can learn Turing Theory.

The following is my coding with seds, I implement the 4 state (b c e f) table, and use "_" to identify the head position, "$" to identify the end of tap cells and "*" for blank symbols on the tap.

# Turing's very first example

# check input
/^_\?[\*]*$/! b error

# start from first
s/^\*/_/
s/\([_\*]\)$/\1\$/

# b blank P0,R c
: b
h
s/^/b /
p
g

/_/ {
# write 0
s/_/0/

# move right
s/0\*/0_/

/0\$$/ b H

b c
}
b error

: c
h
s/^/c /
p
g

/_/ {
# print blank
s/_/ /
# right
s/ \*/ _/

/ \$$/ b H
b e
}
b error

: e
h
s/^/e /
p
g

/_/ {
# print one
s/_/1/
# turn right
s/1\*/1_/

/1\$$/ b H
b f
}
b error

: f

h
s/^/f /
p
g

/_/ {
# print blank
s/_/ /
# right

s/ \*/ _/

/ \$$/ b H
b b
}
b error



: error
s/^/error with turing machine/

q 1

: H
s/^/= /
s/\$$//
q 0


And the output:

# echo "********" | sed -f Turing_first.sed
b _*******$
c 0_******$
e 0 _*****$
f 0 1_****$
b 0 1 _***$
c 0 1 0_**$
e 0 1 0 _*$
f 0 1 0 1_$
= 0 1 0 1