目录
这里我给出一些 Debian 系统中的信息,帮助学习编程的人找出打包的源代码。下面是值得关注的软件包和与之对应的文档。
表 12.1. 帮助编程的软件包清单
软件包 | 流行度 | 大小 | 包 |
---|---|---|---|
autoconf
|
V:25, I:221 | 1868 |
由 autoconf-doc 包提供的“info autoconf ”
|
automake
|
V:23, I:213 | 1707 |
由 automake1.10-doc 包提供的“info automake ”
|
bash
|
V:859, I:999 | 5786 |
由 bash-doc 包提供的“info bash ”
|
bison
|
V:11, I:114 | 2051 |
由 bison-doc 包提供的“info bison ”
|
cpp
|
V:407, I:815 | 41 |
由 cpp-doc 包提供的“info cpp ”
|
ddd
|
V:1, I:13 | 3692 |
由 ddd-doc 包提供的“info ddd ”
|
exuberant-ctags
|
V:7, I:37 | 333 | exuberant-ctags(1) |
flex
|
V:10, I:101 | 1077 |
由 flex-doc 包提供的“info flex ”
|
gawk
|
V:352, I:468 | 2029 |
由 gawk-doc 包提供的“info gawk ”
|
gcc
|
V:163, I:611 | 41 |
由 gcc-doc 包提供的“info gcc ”
|
gdb
|
V:23, I:142 | 7307 |
由 gdb-doc 包提供的“info gdb ”
|
gettext
|
V:53, I:371 | 7035 |
由 gettext-doc 包提供的“info gettext ”
|
gfortran
|
V:22, I:62 | 16 |
由 gfortran-doc 包提供的“info
gfortran ”(Fortran 95)
|
fpc
|
I:4 | 113 | fpc(1)
和由 fp-docs 包提供的 html 文档(Pascal)
|
glade
|
V:1, I:12 | 2212 | 通过 UI Builder 菜单提供的文档 |
libc6
|
V:927, I:998 | 10670 |
通过 glibc-doc 和 glibc-doc-reference
提供的“info libc ”
|
make
|
V:164, I:626 | 1195 |
通过 make-doc 包提供的“info make ”
|
xutils-dev
|
V:2, I:19 | 1465 | imake(1),xmkmf(1) 等。 |
mawk
|
V:402, I:997 | 198 | mawk(1) |
perl
|
V:617, I:995 | 674 | perl(1)
以及通过 perl-doc 和 perl-doc-html 提供的 html
文档
|
python
|
V:674, I:988 | 647 | python(1)
以及通过 python-doc 包提供的 html 文档 |
tcl8.4
|
V:4, I:66 | 184 | tcl(3)
以及通过 tcl8.4-doc 包提供的更详细的手册页文档 |
tk8.4
|
V:2, I:42 | 185 | tk(3)
以及通过 tk8.4-doc 包提供的更详细的手册页文档 |
ruby
|
V:87, I:316 | 37 | ruby(1)
以及通过 ri 包提供的交互式参考手册 |
vim
|
V:127, I:390 | 2366 |
通过 vim-doc 包提供的帮助(F1)菜单
|
susv2
|
I:0 | 15 | 通过“单一UNIX规范(版本2)”获取(英语文档) |
susv3
|
I:0 | 15 | 通过“单一UNIX规范(版本3)”获取(英语文档) |
安装 manpages
和 manpages-dev
包之后,可以通过运行“man 名称
”查看手册页中的参考信息。安装了 GNU
工具的相关文档包之后,可以通过运行“info 程序名称
”查看参考文档。某些 GFDL 协议的文档与 DFSG
并不兼容,所以你可能需要在 main
仓库中包含 contrib
和
non-free
才能下载并安装它们。
![]() |
警告 |
---|---|
不要用“ |
![]() |
小心 |
---|---|
你可以把从源代码编译得到的程序直接放到“ |
![]() |
提示 |
---|---|
“歌曲:99瓶啤酒”的代码示例可以给你提供实践各种语言的好范本。 |
Shell 脚本 是指包含有下面格式的可执行的文本文件。
#!/bin/sh …… 命令
第一行指明了读取并执行这个文件的 shell 解释器。
读懂 shell 脚本的最好 办法是先理解类 UNIX 系统是如何工作的。这里有一些 shell 编程的提示。看看“Shell 错误”(http://www.greenend.org.uk/rjk/2001/04/shell.html),可以从错误中学习。
不像 shell 交互模式(参见第 1.5 节 “简单 shell 命令” 和 第 1.6 节 “类 Unix 的文本处理”),shell 脚本会频繁使用参数、条件和循环等。
系统中的许多脚本都可以通过任意 POSIX shell(参见 表 1.13 “shell 程序列表”)来执行。系统的默认 shell
是“/bin/sh
”,它是某个实际 shell 程序的链接。
对 lenny
或更老的系统来说,它是
bash(1)
对 squeeze
或更新的系统来说,它是
dash(1)
Avoid writing a shell script with bashisms or zshisms to make it portable among all POSIX shells. You can check it using checkbashisms(1).
表 12.2. List of typical bashisms
Good: POSIX | Avoid: bashism |
---|---|
if [ "$foo" = "$bar" ] ; then …
|
if [ "$foo" == "$bar" ] ; then …
|
diff -u file.c.orig file.c
|
diff -u file.c{.orig,}
|
mkdir /foobar /foobaz
|
mkdir /foo{bar,baz}
|
funcname() { … }
|
function funcname() { … }
|
octal format: "\377 "
|
hexadecimal format: "\xff "
|
The "echo
" command must be used with following cares
since its implementation differs among shell builtin and external commands.
Avoid using any command options except "-n
".
Avoid using escape sequences in the string since their handling varies.
![]() |
注意 |
---|---|
Although " |
![]() |
提示 |
---|---|
Use the " |
特殊的 shell 参数经常在 shell 脚本里面被用到。
表 12.3. shell 参数列表
shell 参数 | 值 |
---|---|
$0
|
shell 或 shell 脚本的名称 |
$1
|
第一个 shell 参数 |
$9
|
第 9 个 shell 参数 |
$#
|
位置参数数量 |
"$*"
|
"$1 $2 $3 $4 … "
|
"$@"
|
"$1" "$2" "$3" "$4" …
|
$?
|
最近一次命令的退出状态码 |
$$
|
这个 shell 脚本的 PID |
$!
|
最近开始的后台任务 PID |
Basic parameter expansions to remember are as follows.
表 12.4. List of shell parameter expansions
parameter expression form |
value if var is set
|
value if var is not set
|
---|---|---|
${var:-string}
|
"$var "
|
"string "
|
${var:+string}
|
"string "
|
"null "
|
${var:=string}
|
"$var "
|
"string " (and run "var=string ")
|
${var:?string}
|
"$var "
|
echo "string " to stderr (and exit with error)
|
Here, the colon ":
" in all of these operators is actually
optional.
with ":
" = operator
test for exist and not null
without ":
" = operator
test for exist only
表 12.5. List of key shell parameter substitutions
parameter substitution form | result |
---|---|
${var%suffix}
|
remove smallest suffix pattern |
${var%%suffix}
|
remove largest suffix pattern |
${var#prefix}
|
remove smallest prefix pattern |
${var##prefix}
|
remove largest prefix pattern |
Each command returns an exit status which can be used for conditional expressions.
Success: 0 ("True")
Error: non 0 ("False")
![]() |
注意 |
---|---|
"0" in the shell conditional context means "True", while "0" in the C conditional context means "False". |
![]() |
注意 |
---|---|
" |
Basic conditional idioms to remember are the following.
"<command> && <if_success_run_this_command_too>
|| true
"
"<command> || <if_not_success_run_this_command_too> ||
true
"
A multi-line script snippet as the following
if [ <conditional_expression> ]; then <if_success_run_this_command> else <if_not_success_run_this_command> fi
Here trailing "|| true
" was needed to ensure this shell
script does not exit at this line accidentally when shell is invoked with
"-e
" flag.
表 12.6. 在条件表达式中进行文件比较
表达式 | 返回逻辑真所需的条件 |
---|---|
-e <file>
|
<file> 存在 |
-d <file>
|
<file> 存在并且是一个目录 |
-f <file>
|
<file> 存在并且是一个普通文件 |
-w <file>
|
<file> 存在并且可写 |
-x <file>
|
<file> 存在并且可执行 |
<file1> -nt <file2>
|
<file1> is newer than <file2> (modification) |
<file1> -ot <file2>
|
<file1> is older than <file2> (modification) |
<file1> -ef <file2>
|
<file1> 和 <file2> 位于相同的设备上并且有相同的 inode 编号 |
表 12.7. 在条件表达式中进行字符串比较
表达式 | 返回逻辑真所需的条件 |
---|---|
-z <str>
|
<str> 的长度为零 |
-n <str>
|
<str> 的长度不为零 |
<str1> = <str2>
|
<str1> 和 <str2> 相等 |
<str1> != <str2>
|
<str1> 和 <str2> 不相等 |
<str1> < <str2>
|
<str1> 排列在 <str2> 之前(取决于语言环境) |
<str1> > <str2>
|
<str1> 排列在 <str2> 之后(取决于语言环境) |
算术整数的比较在条件表达式中为
"-eq
","-ne
","-lt
","-le
","-gt
"
和 "-ge
"。
这里有几种可用于 POSIX shell 的循环形式。
"for x in foo1 foo2 … ; do command ; done
",该循环会将
"foo1 foo2 …
" 赋予变量 "x
" 并执行
"command
"。
"while condition ; do command ; done
",当
"condition
" 为真时,会重复执行 "command
"。
"until condition ; do command ; done
",当
"condition
" 为假时,会重复执行 "command
"。
"break
" 可以用来退出循环。
"continue
" 可以用来重新开始下一次循环。
![]() |
提示 |
---|---|
The C-language like numeric iteration can be
realized by using
seq(1)
as the " |
![]() |
提示 |
---|---|
shell 大致以下列的顺序来处理一个脚本。
shell 读取一行。
The shell groups a part of the line as one
token if it is within "…"
or
'…'
.
shell 通过下列方式将行中的其它部分分隔进 tokens。
空白字符:<空格> <tab> <换行符>
元字符:< > | ; & ( )
shell 会检查每一个不位于 "…"
或 '...'
的 token 中的
关键字 来调整它的行为。
关键字:if then elif else fi for in
while unless do done case esac
shell 展开不位于 "…"
或 '...'
中的 别名。
shell 展开不位于 "…"
或 '...'
中的 波浪线。
"~
" → 当前用户的家目录
"~<user>
" → <user>
的家目录
shell 将不位于 '...'
中的 变量
展开为它的值。
变量:"$PARAMETER
" 或
"${PARAMETER}
"
shell 展开不位于 '...'
中的 命令替换。
"$( command )
" → "command
" 的输出
"` command `
" → "command
" 的输出
shell 将不位于 "…"
或 '...'
中的 glob 路径 展开为匹配的文件名。
*
→ 任何字符
?
→ 一个字符
[…]
→ 任何位于 "…
" 中的字符
shell 从下列几方面查找 命令 并执行。
函数 定义
内建命令
“$PATH
” 中的可执行文件
shell 前往下一行,并按照这个顺序从头再次进行处理。
双引号中的单引号是没有效果的。
在 shell 中执行 “set -x
” 或使用 “-x
” 选项启动
shell 可以让 shell 显示出所有执行的命令。这对调试来说是非常方便的。
为了使你的 shell 程序在 Debian 系统上尽可能地具有可移植性,你应该只使用 必要的 软件包所提供的应用程序。
"aptitude search ~E
",列出 必要的 软件包。
"dpkg -L <package_name> |grep '/man/man.*/'
",列出
<package_name>
软件包所提供的 man 手册。
表 12.8. 包含用于 shell 脚本的小型应用程序的软件包
软件包 | 流行度 | 大小 | 说明 |
---|---|---|---|
coreutils
|
V:876, I:999 | 14783 | GNU 核心工具 |
debianutils
|
V:930, I:999 | 213 | miscellaneous utilities specific to Debian |
bsdmainutils
|
V:861, I:998 | 558 | 来自 FreeBSD 更多的工具集合 |
bsdutils
|
V:843, I:999 | 230 | 来自 4.4BSD-Lite 的基础工具 |
moreutils
|
V:4, I:18 | 184 | 额外的 Unix 工具 |
![]() |
提示 |
---|---|
尽管 |
The user interface of a simple shell program can be improved from dull
interaction by echo
and read
commands
to more interactive one by using one of the so-called dialog program etc.
表 12.9. List of user interface programs
软件包 | 流行度 | 大小 | 说明 |
---|---|---|---|
x11-utils
|
V:305, I:637 | 603 | xmessage(1): display a message or query in a window (X) |
whiptail
|
V:431, I:996 | 68 | displays user-friendly dialog boxes from shell scripts (newt) |
dialog
|
V:25, I:145 | 1099 | displays user-friendly dialog boxes from shell scripts (ncurses) |
zenity
|
V:108, I:432 | 349 | display graphical dialog boxes from shell scripts (gtk2.0) |
ssft
|
V:0, I:0 | 129 | Shell Scripts Frontend Tool (wrapper for zenity, kdialog, and dialog with gettext) |
gettext
|
V:53, I:371 | 7035 |
"/usr/bin/gettext.sh ": translate message
|
Here is a simple script which creates ISO image with RS02 data supplemented by dvdisaster(1).
#!/bin/sh -e # gmkrs02 : Copyright (C) 2007 Osamu Aoki <osamu@debian.org>, Public Domain #set -x error_exit() { echo "$1" >&2 exit 1 } # Initialize variables DATA_ISO="$HOME/Desktop/iso-$$.img" LABEL=$(date +%Y%m%d-%H%M%S-%Z) if [ $# != 0 ] && [ -d "$1" ]; then DATA_SRC="$1" else # Select directory for creating ISO image from folder on desktop DATA_SRC=$(zenity --file-selection --directory \ --title="Select the directory tree root to create ISO image") \ || error_exit "Exit on directory selection" fi # Check size of archive xterm -T "Check size $DATA_SRC" -e du -s $DATA_SRC/* SIZE=$(($(du -s $DATA_SRC | awk '{print $1}')/1024)) if [ $SIZE -le 520 ] ; then zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \ --text="The data size is good for CD backup:\\n $SIZE MB" elif [ $SIZE -le 3500 ]; then zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \ --text="The data size is good for DVD backup :\\n $SIZE MB" else zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \ --text="The data size is too big to backup : $SIZE MB" error_exit "The data size is too big to backup :\\n $SIZE MB" fi # only xterm is sure to have working -e option # Create raw ISO image rm -f "$DATA_ISO" || true xterm -T "genisoimage $DATA_ISO" \ -e genisoimage -r -J -V "$LABEL" -o "$DATA_ISO" "$DATA_SRC" # Create RS02 supplemental redundancy xterm -T "dvdisaster $DATA_ISO" -e dvdisaster -i "$DATA_ISO" -mRS02 -c zenity --info --title="Dvdisaster RS02" --width 640 --height 400 \ --text="ISO/RS02 data ($SIZE MB) \\n created at: $DATA_ISO" # EOF
You may wish to create launcher on the desktop with command set something
like "/usr/local/bin/gmkrs02 %d
".
Make is a utility to maintain groups of
programs. Upon execution of
make(1),
make
read the rule file, "Makefile
",
and updates a target if it depends on prerequisite files that have been
modified since the target was last modified, or if the target does not
exist. The execution of these updates may occur concurrently.
The rule file syntax is the following.
target: [ prerequisites ... ] [TAB] command1 [TAB] -command2 # ignore errors [TAB] @command3 # suppress echoing
Here "[TAB]
" is a TAB code. Each line is interpreted by
the shell after make variable substitution. Use "\
" at
the end of a line to continue the script. Use "$$
" to
enter "$
" for environment values for a shell script.
Implicit rules for the target and prerequisites can be written, for example, by the following.
%.o: %.c header.h
Here, the target contains the character "%
" (exactly one
of them). The "%
" can match any nonempty substring in the
actual target filenames. The prerequisites likewise use
"%
" to show how their names relate to the actual target
name.
表 12.10. List of make automatic variables
automatic variable | 值 |
---|---|
$@
|
target |
$<
|
first prerequisite |
$?
|
all newer prerequisites |
$^
|
all prerequisites |
$*
|
"% " matched stem in the target pattern
|
表 12.11. List of make variable expansions
variable expansion | 说明 |
---|---|
foo1 := bar
|
one-time expansion |
foo2 = bar
|
recursive expansion |
foo3 += bar
|
append |
Run "make -p -f/dev/null
" to see automatic internal
rules.
You can set up proper environment to compile programs written in the C programming language by the following.
# apt-get install glibc-doc manpages-dev libc6-dev gcc build-essential
The libc6-dev
package, i.e., GNU C Library, provides
C standard library which is
collection of header files and library routines used by the C programming
language.
See references for C as the following.
"info libc
" (C library function reference)
gcc(1)
and "info gcc
"
each_C_library_function_name(3)
Kernighan & Ritchie, "The C Programming Language", 2nd edition (Prentice Hall)
A simple example "example.c
" can compiled with a library
"libm
" into an executable
"run_example
" by the following.
$ cat > example.c << EOF #include <stdio.h> #include <math.h> #include <string.h> int main(int argc, char **argv, char **envp){ double x; char y[11]; x=sqrt(argc+7.5); strncpy(y, argv[0], 10); /* prevent buffer overflow */ y[10] = '\0'; /* fill to make sure string ends with '\0' */ printf("%5i, %5.3f, %10s, %10s\n", argc, x, y, argv[1]); return 0; } EOF $ gcc -Wall -g -o run_example example.c -lm $ ./run_example 1, 2.915, ./run_exam, (null) $ ./run_example 1234567890qwerty 2, 3.082, ./run_exam, 1234567890qwerty
Here, "-lm
" is needed to link library
"/usr/lib/libm.so
" from the libc6
package for
sqrt(3).
The actual library is in "/lib/
" with filename
"libm.so.6
", which is a symlink to
"libm-2.7.so
".
Look at the last parameter in the output text. There are more than 10
characters even though "%10s
" is specified.
The use of pointer memory operation functions without boundary checks, such as sprintf(3) and strcpy(3), is deprecated to prevent buffer overflow exploits that leverage the above overrun effects. Instead, use snprintf(3) and strncpy(3).
Debug is important part of programing activities. Knowing how to debug programs makes you a good Debian user who can produce meaningful bug reports.
Primary debugger on Debian is gdb(1) which enables you to inspect a program while it executes.
Let's install gdb
and related programs by the following.
# apt-get install gdb gdb-doc build-essential devscripts
Good tutorial of gdb
is provided by "info
gdb
" or found elsewhere on the
web. Here is a simple example of using
gdb(1)
on a "program
" compiled with the "-g
"
option to produce debugging information.
$ gdb program (gdb) b 1 # set break point at line 1 (gdb) run args # run program with args (gdb) next # next line ... (gdb) step # step forward ... (gdb) p parm # print parm ... (gdb) p parm=12 # set value to 12 ... (gdb) quit
![]() |
提示 |
---|---|
Many gdb(1) commands can be abbreviated. Tab expansion works as in the shell. |
Since all installed binaries should be stripped on the Debian system by
default, most debugging symbols are removed in the normal package. In order
to debug Debian packages with
gdb(1),
corresponding *-dbg
packages need to be installed
(e.g. libc6-dbg
in the case of libc6
).
If a package to be debugged does not provide its *-dbg
package, you need to install it after rebuilding it by the following.
$ mkdir /path/new ; cd /path/new $ sudo apt-get update $ sudo apt-get dist-upgrade $ sudo apt-get install fakeroot devscripts build-essential $ sudo apt-get build-dep source_package_name $ apt-get source package_name $ cd package_name*
Fix bugs if needed.
Bump package version to one which does not collide with official Debian
versions, e.g. one appended with "+debug1
" when
recompiling existing package version, or one appended with
"~pre1
" when compiling unreleased package version by the
following.
$ dch -i
Compile and install packages with debug symbols by the following.
$ export DEB_BUILD_OPTIONS=nostrip,noopt $ debuild $ cd .. $ sudo debi package_name*.changes
You need to check build scripts of the package and ensure to use
"CFLAGS=-g -Wall
" for compiling binaries.
When you encounter program crash, reporting bug report with cut-and-pasted backtrace information is a good idea.
The backtrace can be obtained by the following steps.
Run the program under gdb(1).
Reproduce crash.
It causes you to be dropped back to the gdb
prompt.
Type "bt
" at the gdb
prompt.
In case of program freeze, you can crash the program by pressing
Ctrl-C
in the terminal running gdb
to
obtain gdb
prompt.
![]() |
提示 |
---|---|
Often, you see a backtrace where one or more of the top lines are in
" |
$ MALLOC_CHECK_=2 gdb hello
表 12.12. List of advanced gdb commands
命令 | description for command objectives |
---|---|
(gdb) thread apply all bt
|
get a backtrace for all threads for multi-threaded program |
(gdb) bt full
|
get parameters came on the stack of function calls |
(gdb) thread apply all bt full
|
get a backtrace and parameters as the combination of the preceding options |
(gdb) thread apply all bt full 10
|
get a backtrace and parameters for top 10 calls to cut off irrelevant output |
(gdb) set logging on
|
write log of gdb output to a file (the default is
"gdb.txt ")
|
If a GNOME program preview1
has received an X error, you
should see a message as follows.
The program 'preview1' received an X Window System error.
If this is the case, you can try running the program with
"--sync
", and break on the
"gdk_x_error
" function in order to obtain a backtrace.
Use ldd(1) to find out a program's dependency on libraries by the followings.
$ ldd /bin/ls librt.so.1 => /lib/librt.so.1 (0x4001e000) libc.so.6 => /lib/libc.so.6 (0x40030000) libpthread.so.0 => /lib/libpthread.so.0 (0x40153000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
For ls(1) to work in a `chroot`ed environment, the above libraries must be available in your `chroot`ed environment.
See 第 9.3.6 节 “跟踪程序活动”.
There are several memory leak detection tools available in Debian.
表 12.13. List of memory leak detection tools
软件包 | 流行度 | 大小 | 说明 |
---|---|---|---|
libc6-dev
|
V:266, I:619 | 15620 | mtrace(1): malloc debugging functionality in glibc |
valgrind
|
V:8, I:57 | 64044 | memory debugger and profiler |
kmtrace
|
V:1, I:19 | 310 | KDE memory leak tracer using glibc's mtrace(1) |
alleyoop
|
V:0, I:1 | 948 | GNOME front-end to the Valgrind memory checker |
electric-fence
|
V:0, I:6 | 49 | malloc(3) debugger |
leaktracer
|
V:0, I:3 | 56 | memory-leak tracer for C++ programs |
libdmalloc5
|
V:0, I:3 | 307 | debug memory allocation library |
There are lint like tools for static code analysis.
表 12.14. List of tools for static code analysis
软件包 | 流行度 | 大小 | 说明 |
---|---|---|---|
splint
|
V:0, I:5 | 1801 | tool for statically checking C programs for bugs |
flawfinder
|
V:0, I:0 | 175 | tool to examine C/C++ source code and looks for security weaknesses |
perl
|
V:617, I:995 | 674 | interpreter with internal static code checker: B::Lint(3perl) |
pylint
|
V:5, I:15 | 876 | Python code static checker |
weblint-perl
|
V:0, I:2 | 34 | syntax and minimal style checker for HTML |
linklint
|
V:0, I:1 | 343 | fast link checker and web site maintenance tool |
libxml2-utils
|
V:23, I:324 | 176 | utilities with xmllint(1) to validate XML files |
Flex is a Lex-compatible fast lexical analyzer generator.
Tutorial for
flex(1)
can be found in "info flex
".
You need to provide your own "main()
" and
"yywrap()
". Otherwise, your flex program should look
like this to compile without a library. This is because that
"yywrap
" is a macro and "%option main
"
turns on "%option noyywrap
" implicitly.
%option main %% .|\n ECHO ; %%
Alternatively, you may compile with the "-lfl
" linker
option at the end of your
cc(1)
command line (like AT&T-Lex with "-ll
"). No
"%option
" is needed in this case.
Several packages provide a Yacc-compatible lookahead LR parser or LALR parser generator in Debian.
表 12.15. List of Yacc-compatible LALR parser generators
软件包 | 流行度 | 大小 | 说明 |
---|---|---|---|
bison
|
V:11, I:114 | 2051 | GNU LALR parser generator |
byacc
|
V:0, I:7 | 166 | Berkeley LALR parser generator |
btyacc
|
V:0, I:0 | 248 |
backtracking parser generator based on byacc
|
Tutorial for
bison(1)
can be found in "info bison
".
You need to provide your own "main()
" and
"yyerror()
". "main()
" calls
"yyparse()
" which calls "yylex()
",
usually created with Flex.
%% %%
Autoconf is a tool for producing shell scripts that automatically configure software source code packages to adapt to many kinds of Unix-like systems using the entire GNU build system.
autoconf(1)
produces the configuration script
"configure
". "configure
" automatically
creates a customized "Makefile
" using the
"Makefile.in
" template.
![]() |
警告 |
---|---|
Do not overwrite system files with your compiled programs when installing them. |
Debian does not touch files in "/usr/local/
" or
"/opt
". So if you compile a program from source, install
it into "/usr/local/
" so it does not interfere with
Debian.
$ cd src $ ./configure --prefix=/usr/local $ make $ make install # this puts the files in the system
If you have the original source and if it uses autoconf(1)/automake(1) and if you can remember how you configured it, execute as follows to uninstall the program.
$ ./configure "all-of-the-options-you-gave-it" # make uninstall
Alternatively, if you are absolutely sure that the install process puts
files only under "/usr/local/
" and there is nothing
important there, you can erase all its contents by the following.
# find /usr/local -type f -print0 | xargs -0 rm -f
If you are not sure where files are installed, you should consider using
checkinstall(8)
from the checkinstall
package, which provides a clean
path for the uninstall. It now supports to create a Debian package with
"-D
" option.
Although any AWK scripts can be automatically rewritten in Perl using a2p(1), one-liner AWK scripts are best converted to one-liner Perl scripts manually.
Let's think following AWK script snippet.
awk '($2=="1957") { print $3 }' |
This is equivalent to any one of the following lines.
perl -ne '@f=split; if ($f[1] eq "1957") { print "$f[2]\n"}' |
perl -ne 'if ((@f=split)[1] eq "1957") { print "$f[2]\n"}' |
perl -ne '@f=split; print $f[2] if ( $f[1]==1957 )' |
perl -lane 'print $F[2] if $F[1] eq "1957"' |
perl -lane 'print$F[2]if$F[1]eq+1957' |
The last one is a riddle. It took advantage of following Perl features.
The whitespace is optional.
The automatic conversion exists from number to the string.
See perlrun(1) for the command-line options. For more crazy Perl scripts, Perl Golf may be interesting.
Basic interactive dynamic web pages can be made as follows.
Queries are presented to the browser user using HTML forms.
Filling and clicking on the form entries sends one of the following URL string with encoded parameters from the browser to the web server.
"http://www.foo.dom/cgi-bin/program.pl?VAR1=VAL1&VAR2=VAL2&VAR3=VAL3
"
"http://www.foo.dom/cgi-bin/program.py?VAR1=VAL1&VAR2=VAL2&VAR3=VAL3
"
"http://www.foo.dom/program.php?VAR1=VAL1&VAR2=VAL2&VAR3=VAL3
"
"%nn
" in URL is replaced with a character with
hexadecimal nn
value.
The environment variable is set as: "QUERY_STRING="VAR1=VAL1
VAR2=VAL2 VAR3=VAL3"
".
CGI program (any one of
"program.*
") on the web server executes itself with the
environment variable "$QUERY_STRING
".
stdout
of CGI program is sent to the web browser and is
presented as an interactive dynamic web page.
For security reasons it is better not to hand craft new hacks for parsing CGI parameters. There are established modules for them in Perl and Python. PHP comes with these functionalities. When client data storage is needed, HTTP cookies are used. When client side data processing is needed, Javascript is frequently used.
更多信息,参见 通用网关接口, Apache 软件基金会, 和 JavaScript.
Searching "CGI tutorial" on Google by typing encoded URL http://www.google.com/search?hl=en&ie=UTF-8&q=CGI+tutorial directly to the browser address is a good way to see the CGI script in action on the Google server.
如果你想制作一个 Debian 包,阅读下面内容。
第 2 章 Debian 软件包管理 理解基本的包管理系统
第 2.7.13 节 “移植一个软件包到 stable 系统” 理解基本的移植过程
第 9.10.4 节 “Chroot system” 理解基本的 chroot 技术
debuild(1), pbuilder(1) 和 pdebuild(1)
Debian 新维护者指引
作为一个教程(maint-guide
包)
Debian 开发者参考手册
(developers-reference
包)
Debian 策略手册
(debian-policy
包)
Debian 维护者指引
(debmake-doc
包)
debmake
, dh-make
,
dh-make-perl
等软件包,对软件包打包过程,也有帮助。