v|V, select zf or any other command ( fold in visual mode )
:20,101 fo[ld]: fold selected lines
zf/string: fold until the first match of "string" .
:mkview : save folds.
:loadview : load folds.
zf/string creates a fold from the cursor to string . Try within an "#ifdef" and "#endif".
zf#j creates a fold from the cursor down # lines.
zj moves the cursor to the next fold.
zk moves the cursor to the previous fold.
zo opens a fold at the cursor.
zO opens all folds at the cursor.
zm increases the foldlevel by one.
zM closes all open folds.
zr decreases the foldlevel by one.
zR decreases the foldlevel to zero -- all folds will be open.
zd deletes the fold at the cursor.
zE deletes all folds.
[z move to start of open fold.
]z move to end of open fold.
Tuesday, 15 January 2008
Folding with vim, a cheat sheet
Monday, 7 January 2008
A C pointer FAQ ( kind of ) [ as of now for me ]
Of course, pointers are not limited to ints. It's quite common to use pointers to other types, especially char. Here is the innards of the mystrcmp function we saw in a previous chapter, rewritten to use pointers. (mystrcmp, you may recall, compares two strings, character by character.)
// p1, p2 point to the address of the first character in str1, str2 respectively
char *p1 = &str1[0], *p2 = &str2[0];
while(1)
{
// compare the values of str1[x], str[x] at the position x. Not equal
if(*p1 != *p2)
return *p1 - *p2;
// we reached the end of both str1, str2 -> they are equal.
if(*p1 == '\0' || *p2 == '\0')
return 0;
// p1++ and p2++ do the increment of p1 and p2.
// i.e., the next characters in str1 ( str[x + 1] and str2 ( str2[ x + 1]
p1++;
p2++;
}
As another example, here is the strcpy (string copy) loop from a previous chapter, rewritten to use pointers:
char *dp = &dest[0], *sp = &src[0];
while(*sp != '\0')
// *dp++ means *(dp++), i.e., the value of the pointer next to dp.
// to access the address of the next pointer of dp, use (*dp)++
*dp++ = *sp++;
*dp = '\0';
(One question that comes up is whether the expression *dp++ increments p or what it points to. The answer is that it increments p. To increment what p points to, you can use (*dp)++.)
ref: http://www.eskimo.com/~scs/cclass/notes/sx10b.html
Os type detection with uname
[vuhung@test_make]$make vh
SunOs
[vuhung@test_make]$cat Makefile
uname=$(shell uname)
ifeq ($(uname), Linux)
APP_OSTYPE = Linux
endif
ifeq ($(uname), SunOS)
APP_OSTYPE = SunOs
endif
vh:
@echo $(APP_OSTYPE)
Thursday, 20 December 2007
C pointer FAQ :D
Of course, pointers are not limited to ints. It's quite common to use pointers to other types, especially char. Here is the innards of the mystrcmp function we saw in a previous chapter, rewritten to use pointers. (mystrcmp, you may recall, compares two strings, character by character.)
// p1, p2 point to the address of the first character in str1, str2 respectively
char *p1 = &str1[0], *p2 = &str2[0];
while(1)
{
// compare the values of str1[x], str[x] at the position x. Not equal
if(*p1 != *p2)
return *p1 - *p2;
// we reached the end of both str1, str2 -> they are equal.
if(*p1 == '\0' || *p2 == '\0')
return 0;
// p1++ and p2++ do the increment of p1 and p2.
// i.e., the next characters in str1 ( str[x + 1] and str2 ( str2[ x + 1]
p1++;
p2++;
}
As another example, here is the strcpy (string copy) loop from a previous chapter, rewritten to use pointers:
char *dp = &dest[0], *sp = &src[0];
while(*sp != '\0')
// *dp++ means *(dp++), i.e., the value of the pointer next to dp.
// to access the address of the next pointer of dp, use (*dp)++
*dp++ = *sp++;
*dp = '\0';
(One question that comes up is whether the expression *dp++ increments p or what it points to. The answer is that it increments p. To increment what p points to, you can use (*dp)++.)
ref: http://www.eskimo.com/~scs/cclass/notes/sx10b.html
Read and write png files bytes by bytes
#include
#include
#include
#define WIDTH (3)
#define HEIGHT (3)
int main()
{
unsigned char **image; // image[HEIGHT][WIDTH]の形式です
int i, j;
image = (png_bytepp)malloc(HEIGHT * sizeof(png_bytep)); // 以下3行は2次元配列を確保します
for (j = 0; j < HEIGHT; j++)
image[j] = (png_bytep)malloc(WIDTH * sizeof(png_byte));
for (i = 0; i < WIDTH; i++) { // 以下5行は単純なテストパターンを作ります
for (j = 0; j < HEIGHT; j++) {
image[j][i] = (unsigned char)i;
}
}
unsigned char *image2;
image2 = (png_bytep) malloc( HEIGHT * WIDTH * sizeof(png_byte));
for (i = 0; i < WIDTH; i++) { // 以下5行は単純なテストパターンを作ります
for (j = 0; j < HEIGHT; j++) {
//printf("%d ", image[j][i]);
image2[j * WIDTH + i] = image[j][i];
printf("%d ", image2[j * WIDTH + i]);
}
}
// TODO: write image2 to png stream
// http://www.jah.ne.jp/~naoyuki/Writings/MngPng.html
return 0;
}
Solaris 10: vim 7.1 color
Solaris 10 vim71 color
wget vim-7.1.tar.gz
tar xzvf vim-7.1.tar.gz
cd vim71
./configure --prefix=$HOME CC=gcc
make; make install
echo "syntax on" > .vimrc
export TERM=sun-color ( or echo "export TERM=sun-color" >> $HOME/.bash_profile
or TERM=xterm
or TERM=xtermc
Solars 10: Graphics Magick 1.10 installation
/bin/bash ../../libtool --silent --mode=link g++ -D_REENTRANT -pthreads -version-info 1:3:0 -L/usr/sfw/lib -L/usr/lib -o libGraphicsMagick++.la -rpath /export/home/vuhung/lib Blob.lo BlobRef.lo CoderInfo.lo Color.lo Drawable.lo Exception.lo Functions.lo Geometry.lo Image.lo ImageRef.lo Montage.lo Options.lo Pixels.lo STL.lo Thread.lo TypeMetric.lo ../../magick/libGraphicsMagick.la
libtool: link: `/usr/sfw/lib/libstdc++.la' is not a valid libtool archive
make[3]: *** [libGraphicsMagick++.la] Error 1
make[3]: Leaving directory `/export/home/vuhung/usr/src/GraphicsMagick-1.1.10/Magick++/lib'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/export/home/vuhung/usr/src/GraphicsMagick-1.1.10/Magick++/lib'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/export/home/vuhung/usr/src/GraphicsMagick-1.1.10/Magick++'
make: *** [all-recursive] Error 1
232 ~/bin/tar xjvf GraphicsMagick-1.1.10.tar.bz2
233 cd GraphicsMagick-1.1.10
257 ./configure --prefix=$HOME CC=gcc CXX=g++ --enable-ccmalloc -without-perl
258 ~/bin/make
269 make install
bash-3.00# diff /usr/sfw/lib/libstdc++.la /usr/sfw/lib/libstdc++.la.original.2007-12-19.vh
1,32d0
< # libstdc++.la - a libtool library file
< # Generated by ltmain.sh - GNU libtool 1.4a-GCC3.0 (1.641.2.256 2001/05/28 20:09:07 with GCC-local changes)
< #
< # Please DO NOT delete this file!
< # It is necessary for linking the library.
<
< # The name that we can dlopen(3).
< dlname='libstdc++.so.6'
<
< # Names of this library.
< library_names='libstdc++.so.6.0.3 libstdc++.so.6 libstdc++.so'
<
< # The name of the static archive.
< old_library='libstdc++.a'
<
< # Libraries that this one depends upon.
< dependency_libs='-lc -lm -L/usr/sfw/lib -lgcc_s'
<
< # Version information for libstdc++.
< current=6
< age=0
< revision=3
<
< # Is this an already installed library?
< installed=yes
<
< # Files to dlopen/dlpreopen
< dlopen=''
< dlpreopen=''
<
< # Directory that this library needs to be installed in:
< libdir='/usr/sfw/lib'
bash-3.00# cat /etc/release
Solaris 10 6/06 s10s_u2wos_09a SPARC
Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 09 June 2006
Preinstall P/N 259-4616-01
Built 13 August 2006
bash-3.00# uname -a
SunOS soltest01 5.10 Generic_118833-22 sun4u sparc SUNW,Sun-Fire-V215
bash-3.00#
http://forum.java.sun.com/thread.jspa?threadID=5073150
Subscribe to:
Posts (Atom)