Thursday, August 27, 2009

Fedora 11 ADSL

1. Download RP-PPPoE.
http://www.roaringpenguin.com/products/pppoe

2. Compile the package.

3. Setup
> pppoe-setup

Seednet DNS servers:
139.175.55.244
139.175.252.16

4. Start ADSL
> pppoe-start

5. Stop ADSL
> pppoe-stop

Tuesday, August 25, 2009

My X Window Applications

X Server on Win32 => Xming

SlickEdit => KScope
/usr/bin/kscope

UltraEdit => Kate
/usr/bin/kate

WinMerge => Meld
/opt/meld-1.3.1/meld

SVN Client => kdesvn
/usr/local/bin/kdesvn

Sunday, August 23, 2009

Vim Cscope

1. Generate filelist
> find -name '*.c' > cscope.files
> find -name '*.h' >> cscope.files
> find -name '*.cc' >> cscope.files
> find -name '*.cpp' >> cscope.files

2. Build Cscope database
> cscope -b -q -k

3. Use Vim to open source file. It's possible to use Cscope inside Vim.
: cs (help)
: cs find c aim_config_set_int (find all functions that call aim_config_set_int)

Vim Function List

[Source]

ShowFunc.vim : Creates a list of all tags / functions from a window, all windows or buffers.

Default Key Mappings:
Run scan and open cwindow.

To reassign add the following to your .vimrc:
map NewKey ShowFunc
map! NewKey ShowFunc
For example to change the mapping to
map ShowFunc
map! ShowFunc

ShowFunc Window commands:
c Close cwindow.
h Display help dialog.
r Refresh.
s Change file sort, results will appear in either alphabetical or file order. (Default: file order)
t Change scan type, results will be from either the current file, all open windows or all open buffers. (Default: all open buffers)

install details
Put this file in the vim plugins directory (~/.vim/plugin/) to load it automatically, or load it with :so ShowFunc.vim.

Vim CTags

[Source]

[建立 tag 檔]
在所解開的 source code 目錄下,下以下指令:
> ctags -R *

[一般的 tag 使用]
如果就照上一節的方式產生 tag files,那麼只要在 source code 目錄下由 vim 去開啟檔案的話,會自動載入 tags 這個檔案,無需另行載入,否則要由 :set tags=your.tags 來指定 tags 檔。然後就是照一般使用 Vim 線上說明一樣,游標移到識別字或函數名上,按 Ctrl+],要回到原處就按 Ctrl+T。

請注意,Vim 啟動時,工作目錄(vim 啟動時的所在目錄)名為 tags 的檔案會自動載入,$VIMRUNTIME/doc 及 $HOME/.vim/doc 目錄下的 tags 檔也會自動載入。而且,凡是載入的 tags 檔裡頭所有標誌文字都可以使用補全鍵來補全,別忘了這個好用的功能。

Friday, March 13, 2009

Lifebook U1010 Drivers

http://www.pc-ap.fujitsu.com/support/drv_lb_xptpc_u1010.html

Friday, February 20, 2009

RedHat Version

> cat /etc/redhat-release

Sunday, February 15, 2009

Build DLL with Cygwin

[source]

[Building and Using DLLs]

> Could you please tell me where I might read more on
> __declspec(dllexport) and __declspec(dllimport)
>
> I do not understand how to use these....

That's a complicated question. Essentially, the MS engineers were on crack
when they designed Windows DLLs. When compiling code to become a DLL, you
must explicitly tell the compiler which symbols(1) will be exported(2) from
the DLL in the declarations(3) of the symbols. When compiling code that
will use a DLL, you must explicitly tell the compiler which symbols will be
imported from DLLs as opposed to statically linked into your program. At
first this doesn't sound so bad, but essentially it means you need three
different versions of all of your declarations for:
1. compiling code to become the DLL
2. compiling code to use the DLL
3. compiling code that will be statically linked

Consider the case of function "foo()" defined in "foo.c" that will be used
in the "main()" of a program "bar.exe" that is defined in "bar.c" . If foo()
is statically linked into bar.exe, your files might look like this:

--- foo.c ---
/* declaration (AKA prototype) of foo(), usually found in .h file */
int foo();

/* definition of foo() */
int foo() { return 1; }
-------------

Compile foo.c:
gcc -c foo.c -o foo.o

--- bar.c ---
/* declaration (AKA prototype) of foo(), usually found in .h file */
int foo();

int main() { return foo(); }
--------------

Compile bar.c and link foo.o into bar.exe statically:

gcc -c bar.c -o bar.o
gcc foo.o bar.o -o bar.exe

However, if foo() should go into a DLL, your files need to look like this:

--- foo.c ---
/* declaration (AKA prototype) of foo(), usually found in .h file */
__declspec(dllexport) int foo(); /* exporting foo() from this DLL */

/* definition of foo() */
int foo() { return 1; }
-------------

Make a DLL from foo.c:

gcc -c foo.c -o foo.o
gcc -Wl,--out-implib,libfoo.import.a -shared -o foo.dll foo.o

This will create the DLL (foo.dll) and the import library for the DLL
(libfoo.import.a).

--- bar.c ---
/* declaration (AKA prototype) of foo(), usually found in .h file */
__declspec(dllimport) int foo(); /* importing foo() from DLL */

int main() { return foo(); }
--------------

Compile and link bar.exe to use foo.dll (via its import library):

gcc -c bar.c -o bar.o
gcc bar.o libfoo.import.a -o bar.exe

bar.exe now uses foo.dll.

So we have three different possible declarations of the function foo():
1. int foo(); /* static linking */
2. __declspec(dllexport) int foo(); /* making DLL with foo() in it */
3. __declspec(dllimport) int foo(); /* importing foo() from DLL */

Which one we use depends on how we are using foo(). The real problem is
that most people don't want to deal with three sets of declarations but want
to just have one header file which is used in all cases. To solve this you
could do something like this:

--- foo.h ---
#if defined(MAKEDLL)
# define INTERFACE __declspec(dllexport)
#elif defined(USEDLL)
# define INTERFACE __declspec(dllimport)
#else
# define INTERFACE
#endif

INTERFACE int foo();
-------------

--- foo.c ---
#include "foo.h"

int foo() { return 1; }
-------------

--- bar.c ---
#include "foo.h"

int main() { return foo(); }
--------------

Now you are only maintaining the declaration of foo() in one place: foo.h.

To compile bar.exe to statically link in foo():

gcc -c foo.c -o foo.o
gcc -c bar.c -o bar.o
gcc foo.o bar.o -o bar.exe

To compile foo() into a DLL:

gcc -DMAKEDLL -c foo.c -o foo.o
gcc -Wl,--out-implib,libfoo.import.a -shared -o foo.dll foo.o

To compile bar.exe to use the DLL:

gcc -DUSEDLL -c bar.c -o bar.exe
gcc bar.o libfoo.import.a -o bar.exe

That's all there is to it.

(1)functions, methods and variables in structs / classes, external
variables
(2)available to programs that use the DLL
(3)function prototypes, class definitions, etc.-- the stuff found in
your header files

Hope this helps,
Carl Thompson

PS: for structs / classes instead of doing this:

class foo {
public:
INTERFACE int bar;
INTERFACE int baz;
}

You can do this:

class INTERFACE foo {
public:
int bar;
int baz;
}

They are both equivalent, but the second way is cleaner.

PPS: I've heard you can do the same thing using separate ".DEF" files,
but I don't know about that.

PPPS: None of this is necessary with reasonable operating systems, such
as Unix or Linux. The compiler and linker automatically export
and import all externally visible symbols when building or using
DLLs (shared libraries). You don't even need a separate import
library.

> ...

Creating a shared and static library with GCC

[source]

Here's a summary on how to create a shared and a static library with gcc. The goal is to show the basic steps. I do not want to go into the hairy details. It should be possible to use this page as a reference.
These examples were tested and run on cygwin/Windows.
The code for the library
This is the code that goes into the library. It exhibits one single function that takes two doubles and calculates their mean value and returns it.
calc_mean.c

//#include

double mean(double a, double b) {
return (a+b) / 2;
}

The header file
Of course, we need a header file.
calc_mean.h

double mean(double, double);

Creating the static library
A static library is basically a set of object files that were copied into a single file. This single file is the static library. The static file is created with the archiver (ar).
First, calc_mean.c is turned into an object file:

gcc -c calc_mean.c -o calc_mean.o

Then, the archiver (ar) is invoked to produce a static library (named libmean.a) out of the object file calc_mean.o.

ar rcs libmean.a calc_mean.o

Note: the library must start with the three letters lib and have the suffix .a.
Creating the shared library
As with static libraries, an object file is created. The -fPIC option tells gcc to create position independant code which is necessary for shared libraries. Note also, that the object file created for the static library will be overwritten. That's not bad, however, because we have a static library that already contains the needed object file.

gcc -c -fPIC calc_mean.c -o calc_mean.o

For some reason, gcc says:

cc1: warning: -fPIC ignored for target (all code is position independent)

It looks like -fPIC is not necessary on x86, but all manuals say, it's needed, so I use it too.
Now, the shared library is created

gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so.1.0.1 calc_mean.o

Note: the library must start with the three letter lib.
The programm using the library
This is the program that uses the calc_mean library. Once, we will link it against the static library and once against the shared library.
main.c

#include
#include "calc_mean.h"

int main(int argc, char* argv[]) {

double v1, v2, m;
v1 = 5.2;
v2 = 7.9;

m = mean(v1, v2);

printf("The mean of %3.2f and %3.2f is %3.2f\n", v1, v2, m);

return 0;
}

Linking against static library

gcc -static main.c -L. -lmean -o statically_linked

Note: the first three letters (the lib) must not be specified, as well as the suffix (.a)
Linking against shared library

gcc main.c -o dynamically_linked -L. -lmean

Note: the first three letters (the lib) must not be specified, as well as the suffix (.so)
Executing the dynamically linked programm

LD_LIBRARY_PATH=.
./dynamically_linked

Monday, January 26, 2009

Find Files in Linux

find -name 'mypage.htm'

In the above command the system would search for any file named mypage.htm in the current directory and any subdirectory.

find / -name 'mypage.htm'

In the above example the system would search for any file named mypage.htm on the root and all subdirectories from the root.

find -name 'file*'

In the above example the system would search for any file beginning with file in the current directory and any subdirectory.

find -name '*' -size +1000k

In the above example the system would search for any file that is larger then 1000k.



( expression )
True if expression is true.
! expression
Negation of a primary; the unary NOT operator.
expression [-a] expression
Conjunction of primaries; the AND operator is implied by the juxtaposition of two primaries or made explicit by the optional -a operator. The second expression shall not be evaluated if the first expression is false.
expression -o expression
Alternation of primaries; the OR operator. The second expression shall not be evaluated if the first expression is true.

find \( -name 'hello*' -a -name '*.sh' \)
find \( -name '*.sh' -o -name '*.txt' \)




對找到檔案做處理: -exec

有時我們會把找到的特定檔做特別的處理 ,像是刪除和移動就可以用 exec來處理
請看範例。請注意指令的後面要加 \; 來做結束

而此範例是把找到的檔案cp 到user的家目錄下的txt目錄裡面,在這裡的重點是 {}就是找到檔案的代號, 而exec 後面就是要操作的命令
find /tmp/ -type f -name "*.txt" -exec cp {} ~/txt \;

My First Makefile

[Makefile]
# Makefile Test
include FileList
CC = gcc
CFG = release
OBJS = $(addsuffix .o, $(basename $(SOURCE)))
EXE = hello

# release
CFLAGS_RELEASE = -O2
DFLAGS_RELEASE = LINUX OS_POSIX

# debug
CFLAGS_DEBUG =
DFLAGS_DEBUG = _DEBUG LINUX OS_POSIX

# switch CFG
ifeq ($(CFG), release)
CFLAGS = $(CFLAGS_RELEASE)
DFLAGS = $(addprefix -D, $(DFLAGS_RELEASE))
else
CFLAGS = $(CFLAGS_DEBUG)
DFLAGS = $(addprefix -D, $(DFLAGS_DEBUG))
endif

# make rules
all: $(EXE)

$(EXE): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^

%.o: %.c
$(CC) $(CFLAGS) $(DFLAGS) -c $<

clean:
rm -f $(EXE) $(OBJS)

[filelist.sh]
#!/bin/sh
FileList=`find -name '*.c'`

echo "SOURCE =" '\'
for i in $FileList; do
echo $i '\'
done
echo