Computer Scientist

Sunday, 2 June 2013

libssh remove directory using sftp

In libssh, trying to remove an non-empty directory on a remote host will get a SSH_FX_FAILURE error.

Friday, 24 May 2013

SFSlite output stream system and Chord logging

In Chord source code, there are a great number of "warn", "warnx", "warnt", "fatal" and "panic". They are the output stream part of sfslite library and are used to replace the error output mechanics in standard C++ library in a asynchronous way. According to the tutorial of libasync from David and Frank, et al., these stream makes efforts to accumulate and write data to the terminal in chunks with reasonable boundaries.

This mechanic is defined in err.h and err.C in sfslite/async/ directory. There are some derivations for "warn":
    warn:
      - vwarn: invoke the underlying vfmt of strbuf.
      - warnx: the program name and pid are shown in each message.
      - warnt: a time stamp is shown in each message.
      - vwarnx: invoke the underlying vfmt of strbuf with program name
                      and pid shown

    fatal: message start with "fatal", exit program after messaging
    panic: message start with "PANIC", exit and dump core after messaging.

    assert: this is an replacement of C assert using the panic.

Here is what I found from the sfslite source code.

Actually, there is a quite similar mechanic in Chord called modlogger in chord/utils/modlogger.*, which is labelled an employed idea from sfslite. The modlogger is actually a small logging system with logging levels (CRIT, WARNING, INFO, TRACE) and logging target (standard output or a file descriptor).

Saturday, 23 March 2013

C/C++ Programming Tips

Here, some useful tips or unknowns of C/C++ programming are listed for further reference:

1. Stand alone curly brackets in code.
Sometimes a pair of curly brackets can be found in a C/C++ code file. It seems to be useless:

Configurator::only ().dump();

{
    strbuf x = strbuf ("starting: ");
    for (int i = 0; i < argc; i++) {
        x << argv[i] << " ";
    }
    x << "\n";
    info << x;
}

Here, the curly brackets is not necessarily to exist. However, they have their meanings from two different point of views: Scope perspective and Legacy perspective.
In scope perspective, the codes in the pair of curly brackets is in a new sub scope.
In legacy perspective, the legacy C standard needs variable declarations to be in the very front of the code. The curly brackets are able to make a new "beginning".
I am working on a C++ project. So the original coder considered in a scope perspective.

Monday, 22 October 2012

How to use and tweak Emacs Code Browser

Emacs is one of the most featured text editor in Linux/Unix like systems. The users don't need to move over the fingers to achieve almost all operations to edit text files or to code. It would be a quite efficient multi-function text editor if the horrible beginning start time of using it is neglected. Some keyboard companies produce specific customised keyboard such as HHKB for the ease of Emacs' using.

One of the Emacs' feature is to browser a program project with a large number of source files. More windows and tools are provided to navigate through the whole project. However, the installation and settings of ECB (Emacs Code Browser) is very complicated with a lot of works involved in its long manual. Here I record my short settings of a usable ECB. Not all of the features of either Emacs or ECB are exploited according to my settings, because I am also a newbie of Emacs and ECB. All of my efforts contribute on the usable version of working Emacs and ECB.

Setting the ECB to work in Emacs.

Find out the location of the installed ECB. I installed it by using yum tools. In this case, the location is /usr/share/emacs/site-lisp/ecb. Put this path into the list of emacs' load-path. Then require the ecb after that. However, an error message would be shown up saying that something wrong with the stack-trace-on-error. Then toggle on the stack-trace-on-error before load the ecb to the load-path in .emacs, the configuration file of Emacs.

ECB would ask you to insert some other setting to Emacs' configuration file. Just accept it is fine.

How to use the ECB:

1. navigation among different windows:
    use the C-c . g (x) command, where (x) can be:
        d: directory window
        s: source files window
        m: class and function names window
        h: history window

2. Show any working directory in directory window.
    When I open the ECB mode by using M-x ecb-activate, the directory window have nothing displayed. In order to set the working directory in the directory window the following steps are required:
    M-x customize-option RET ecb-source-path RET
    Choose the INS button in the opening custom buffer in order to insert a directory as a source path.
    Choose to save for current session or for future sessions by type a number for specific type saving. Then the working directory should be shown in the directory window.

3. Customise the layout of ECB
    There are several predefined layout available to users in ECB. The method used to change to these layouts is to set the option "ecb-layout-name". This is quite similar with the method used to set the working path of current session. The local tool of Emacs: M-x customize-option is employed to accomplish these sort of tasks.
    The command M-x ecb-show-layout-help can be used to check the details of a predefined layout through it text-type picture.
 

Sunday, 21 October 2012

Thread-local storage

Thread-local storage (TLS) is a programming method that is used to make static and global variables be local to a thread. The '"errno" is a canonical example of TLS method. Actually, a "errno" should be a static variable used by all functions to determine the error status. However, in each thread of a running process, there should be a separated one in order to prevent the infection from other threads in the same process.

The comparing method to achieve the similar function with the TLS is the thread lock for a static or global variable. However, a carelessness of requiring the lock in any threads in the process would affect other threads.

Saturday, 1 September 2012

Code counting program

For some reasons, I just want to count the number of lines of code which I have already completed locally. There are several methods to achieve this task, such as the Doxygen and the Git tools. They can all produce a rather good report on the program's physical statistics, for example the lines of code. What I was looking for, however, is a lightweight solution which could only count the number of code lines.

SLOCCount is just this kind of tool which is available in the Fedora's package repository. It can also convert the number of code into a financial metric base according to some unknown theory. I am not expect how accurate it would be. It is just quite interesting.

If someone have the similar demands with mine, just have a try on this tool.

Wednesday, 15 August 2012

Deploy Latex writing environment in Fedora 17

At the end of my PhD, a thesis writing with Latex is inevitable. However the Latex is not my primary writing tool during the whole process of my PhD. The Microsoft word seems more easy and intuitive when some small pieces of work are required. In this case, I am going to construct the Latex writing environment before any composing are produced. The last time when I used the Latex for writing was three years ago for the first year long report. It was all accomplished in an apple Mac environment with simple installation process and intuitive user interface. As for this time, I will complete all works in Linux environment. Here I will review how to produce a work using Latex in Linux firstly.

Simple work process:
  1. Composing the latex document.
  2. Compile the latex document: latex <filename.tex>
  3. Review the dvi file: xdvi <filename.dvi>
  4. Produce the pdf file: pdflatex <filename.tex>
The work process mentioned above is just a fairly simple one without other excessive works. It is enough if it is treated as an hello world testing.

In order to use the Latex in Fedora, some packages should be installed at the first place. Here is a collection of install packages which are available in Fedora 17 's yum package installation tool:
  • texlive: for latex environment.
  • texlive-latex: for latex command for front end program.
  • xdvik: for dvi viewer.
This is all the packages that can handle most situations of latex writing. At least those are all needed by the hello work one mentioned.

Using a light-weight text editor to manipulate a latex document is really painful, at least for me. So I found another package available in yum repository:
  • texmaker
This is a convenient IDE to edit latex document.