Índice
I provide some pointers for people to learn programming on the Debian system enough to trace the packaged source code. Here are notable packages and corresponding documentation packages for programing.
Tabela 12.1. Lista de pacotes para ajudar a programar
pacote | popcon | tamanho | documentação |
---|---|---|---|
autoconf *
|
V:4, I:25 | 2256 |
"info autoconf " disponibilizado por
autoconf-doc
|
automake *
|
V:3, I:21 | 1812 |
"info automake " disponibilizado por
automake1.10-doc
|
bash
*
|
V:91, I:99 | 3536 |
"info bash " disponibilizado por
bash-doc
|
bison
*
|
V:2, I:15 | 1504 |
"info bison " disponibilizado por
bison-doc
|
cpp
*
|
V:38, I:82 | 32 |
"info cpp " disponibilizado por cpp-doc
|
ddd
*
|
V:0.3, I:2 | 3852 |
"info ddd " disponibilizado por ddd-doc
|
exuberant-ctags *
|
V:1.2, I:5 | 284 |
exuberant-ctags (1)
|
flex
*
|
V:2, I:15 | 1352 |
"info flex " disponibilizado por
flex-doc
|
gawk
*
|
V:28, I:32 | 2172 |
"info gawk " disponibilizado por
gawk-doc
|
gcc
*
|
V:17, I:67 | 28 |
"info gcc " disponibilizado por gcc-doc
|
gdb
*
|
V:4, I:22 | 4812 |
"info gdb " disponibilizado por gdb-doc
|
gettext *
|
V:8, I:46 | 7272 |
"info gettext " disponibilizado por
gettext-doc
|
gfortran *
|
V:0.9, I:6 | 8 |
"info gfortran " disponibilizado por
gfortran-doc (Fortran 95)
|
gpc
*
|
V:0.07, I:0.5 | 8 |
"info gpc " disponibilizado por gpc-doc
(Pascal)
|
fpc
*
|
I:0.4 | 40 |
fpc (1) e html por fp-docs (Pascal)
|
glade
*
|
V:0.3, I:2 | 1652 | ajuda disponibilizada via menu (UI Builder) |
glade-gnome *
|
V:0.09, I:1.2 | 508 | ajuda disponibilizada via menu (UI Builder) |
libc6
*
|
V:97, I:99 | 10012 |
"info libc " disponibilizado por
glibc-doc e glibc-doc-reference
|
make
*
|
V:21, I:72 | 1220 |
"info make " disponibilizado por
make-doc
|
xutils-dev *
|
V:1.7, I:15 | 1728 |
imake (1), xmkmf (1), etc.
|
mawk
*
|
V:66, I:99 | 244 |
mawk (1)
|
perl
*
|
V:88, I:99 | 18528 |
perl (1) e páginas html disponibilizadas por
perl-doc e perl-doc-html
|
python *
|
V:62, I:97 | 736 |
python (1) e páginas html disponibilizadas por
python-doc
|
tcl8.4 *
|
V:8, I:46 | 3332 |
tcl (3) and detail manual pages provided by
tcl8.4-doc
|
tk8.4
*
|
V:5, I:34 | 2712 |
tk (3) and detail manual pages provided by
tk8.4-doc
|
ruby
*
|
V:9, I:24 | 120 |
ruby (1) and interactive reference provided by
ri
|
vim
*
|
V:15, I:33 | 1792 |
help(F1) menu disponibilizado por vim-doc
|
susv2
*
|
I:0.03 | 48 | fetch "The Single Unix Specifications v2" |
susv3
*
|
I:0.07 | 48 | fetch "The Single Unix Specifications v3" |
Online references are available by typing "man name
"
after installing manpages
and
manpages-dev
packages. Online references for the GNU
tools are available by typing "info program_name
" after
installing the pertinent documentation packages. You may need to include
the contrib
and non-free
archives in
addition to the main
archive since some GFDL
documentations are not considered to be DSFG compliant.
![]() |
Atenção |
---|---|
Do not use " |
![]() |
Cuidado |
---|---|
You should install software programs directly compiled from source into
" |
![]() |
Dica |
---|---|
Code examples of creating "Song 99 Bottles of Beer" should give you good idea of practically all the programming languages. |
The shell script is a text file with the execution bit set and contains the commands in the following format.
#!/bin/sh ... linhas de comando
The first line specifies the shell interpreter which read and execute this file contents.
Reading shell scripts is the best way to understand how a Unix-like system works. Here, I give some pointers and reminders for shell programming. See "Shell Mistakes" (http://www.greenend.org.uk/rjk/2001/04/shell.html) to learn from mistakes.
Unlike shell interactive mode (see Secção 1.5, “O simples comando de shell” and Secção 1.6, “Processamento de texto estilo Unix”), shell scripts frequently use parameters, conditionals, and loops.
Many system scripts may be interpreted by any one of POSIX shells (see Tabela 1.13, “Lista de programas da shell”). The default shell for the system is
"/bin/sh
" which is a symlink pointing to the actual
program.
bash
(1) para lenny
ou mais antigo
dash
(1) para squeeze
ou mais recente
Avoid writing a shell script with bashisms or zshisms to make it portable among all POSIX
shells. You can check it using checkbashisms
(1).
Tabela 12.2. Lista dos bashisms típicos
Bom: POSIX | Evitar: 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() { … }
|
formato octal: "\377 "
|
formato hexadecimal: "\xff "
|
The "echo
" command must be used with following cares
since its implementation differs among shell builtin and external commands.
-e
" and
"-E
".
-n
".
![]() |
Nota |
---|---|
Although " |
![]() |
Dica |
---|---|
Use the " |
Parâmetros de shell especiais são frequentemente usados no script shell.
Tabela 12.3. Lista de parâmetros da shel
parâmetro da shell | valor |
---|---|
$0
|
nome da shell ou script de shell |
$1
|
primeiro(1) argumento shell |
$9
|
nono(9) argumento shell |
$#
|
número de parâmetros de posição |
"$*"
|
"$1 $2 $3 $4 … "
|
"$@"
|
"$1" "$2" "$3" "$4" …
|
$?
|
estado de saída do comando mais recente |
$$
|
PID deste script shell |
$!
|
PID of most recently started background job |
Basic parameter expansions to remember are followings.
Tabela 12.4. Lista de expansões de parâmetros de shell
formato da expressão do parâmetro |
valor se var estiver definido
|
valor se var não estiver definido
|
---|---|---|
${var:-string}
|
"$var "
|
"string "
|
${var:+string}
|
"string "
|
"null "
|
${var:=string}
|
"$var "
|
"string " (e corra "var=string ")
|
${var:?string}
|
"$var "
|
echo "string " para stderr (e termina com erro)
|
Aqui, os o caractere dois pontos ":
" em todas estas
operações é na realidade opcional.
:
" = operator
test for exist and not null
:
" = operator
test for exist only
Tabela 12.5. Lista de substituições de parâmetros de shell chave
formato de substituição de parâmetro | resultado |
---|---|
${var%suffix}
|
remover o padrão de sufixo menor |
${var%%suffix}
|
remover o padrão de sufixo maior |
${var#prefix}
|
remover o padrão de prefixo menor |
${var##prefix}
|
remover o padrão de prefixo maior |
Each command returns an exit status which can be used for conditional expressions.
![]() |
Nota |
---|---|
"0" in the shell conditional context means "True", while "0" in the C conditional context means "False". |
![]() |
Nota |
---|---|
" |
Basic conditional idioms to remember are followings.
<command> && <if_success_run_this_command_too>
|| true
"
<command> || <if_not_success_run_this_command_too> ||
true
"
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.
Tabela 12.6. Lista de operadores de comparação de ficheiros na expressão condicional
equação | condição para retornar o verdadeiro lógico |
---|---|
-e <ficheiro>
|
<ficheiro> existe |
-d <ficheiro>
|
<ficheiro> existe e é um directório |
-f <ficheiro>
|
<ficheiro> existe e é um ficheiro normal |
-w <ficheiro>
|
<ficheiro> existe e pode-se escrever nele |
-x <ficheiro>
|
<ficheiro> existe e é executável |
<ficheiro1> -nt <ficheiro2>
|
<ficheiro1> é mais recente que <ficheiro2> (modificação) |
<ficheiro1> -ot <ficheiro2>
|
<ficheiro1> é mais antigo que <ficheiro2> (modificação) |
<ficheiro1> -ef <ficheiro2>
|
<ficheiro1> e <ficheiro2> estão no mesmo dispositivo e no mesmo número de inode |
Tabela 12.7. Lista de operadores de comparação de strings na expressão condicional
equação | condição para retornar o verdadeiro lógico |
---|---|
-z <str>
|
o comprimento de <str> é zero |
-n <str>
|
o comprimento de <str> não é zero |
<str1> = <str2>
|
<str1> and <str2> são iguais |
<str1> != <str2>
|
<str1> and <str2> não são iguais |
<str1> < <str2>
|
<str1> sorts before <str2> (locale dependent) |
<str1> > <str2>
|
<str1> sorts after <str2> (locale dependent) |
Arithmetic integer comparison operators
in the conditional expression are "-eq
",
"-ne
", "-lt
",
"-le
", "-gt
", and
"-ge
".
There are several loop idioms to use in POSIX shell.
for x in foo1 foo2 … ; do command ; done
" loops by
assigning items from the list "foo1 foo2 …
" to variable
"x
" and executing "command
".
while condition ; do command ; done
" repeats
"command
" while "condition
" is true.
until condition ; do command ; done
" repeats
"command
" while "condition
" is not
true.
break
" permite sair do ciclo.
continue
" enables to resume the next iteration of the
loop.
![]() |
Dica |
---|---|
The C-language like numeric iteration can be
realized by using |
The shell processes a script roughly as the following sequence.
"…"
or
'…'
.
The shell splits other part of a line into tokens by the following.
<space> <tab> <newline>
< > | ; & ( )
The shell checks the reserved word for
each token to adjust its behavior if not within "…"
or
'…'
.
if then elif else
fi for in while unless do done case esac
"…"
or '…'
.
The shell expands tilde if not within
"…"
or '…'
.
~
" → current user's home directory
~<user>
" → <user>
's home
directory
The shell expands parameter to its value
if not within '…'
.
$PARAMETER
" or "${PARAMETER}
"
The shell expands command substitution if
not within '…'
.
$( command )
" → the output of
"command
"
` command `
" → the output of
"command
"
The shell expands pathname glob to
matching file names if not within "…"
or
'…'
.
*
→ quaisquer caracteres
?
→ um caractere
[…]
→ any one of the characters in "…
"
The shell looks up command from the following and execute it.
$PATH
"
Single quotes within double quotes have no effect.
Executing "set -x
" in the shell or invoking the shell
with "-x
" option make the shell to print all of commands
executed. This is quite handy for debugging.
In order to make your shell program as portable as possible across Debian system, it is good idea to limit utility programs to ones provided by essential packages.
aptitude search ~E
" lists essential packages.
dpkg -L <package_name> |grep '/man/man.*/'
" lists
manpages for commands offered by <package_name>
package.
Tabela 12.8. List of packages containing small utility programs for shell scripts
pacote | popcon | tamanho | descrição |
---|---|---|---|
coreutils *
|
V:92, I:99 | 13828 | utilitários de núcleo GNU |
debianutils *
|
V:93, I:99 | 260 | utilitários variados específicos da Debian |
bsdmainutils *
|
V:81, I:99 | 768 | colecção de mais utilitários do FreeBSD |
bsdutils *
|
V:77, I:99 | 196 | utilitários básicos do 4.4BSD-Lite |
moreutils *
|
V:0.3, I:1.5 | 220 | utilitários Unix adicionais |
![]() |
Dica |
---|---|
Although |
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.
Tabela 12.9. Lista de programas de interface de utilizador
pacote | popcon | tamanho | descrição |
---|---|---|---|
x11-utils *
|
V:26, I:53 | 652 |
xmessage (1): display a message or query in a window (X)
|
whiptail *
|
V:42, I:99 | 104 | displays user-friendly dialog boxes from shell scripts (newt) |
dialog *
|
V:4, I:25 | 1592 | displays user-friendly dialog boxes from shell scripts (ncurses) |
zenity *
|
V:8, I:41 | 4992 | display graphical dialog boxes from shell scripts (gtk2.0) |
ssft
*
|
V:0.01, I:0.11 | 152 | Shell Scripts Frontend Tool (wrapper for zenity, kdialog, and dialog with gettext) |
gettext *
|
V:8, I:46 | 7272 |
"/usr/bin/gettext.sh ": traduz mensagem
|
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.
A regra de sintaxe do ficheiro é a seguinte.
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.
Tabela 12.10. Lista de variáveis automáticas do make
variável automática | valor |
---|---|
$@
|
alvo |
$<
|
primeiro pre-requisito |
$?
|
todos os novos pre-requisitos |
$^
|
todos os pre-requisitos |
$*
|
"% " matched stem in the target pattern
|
Tabela 12.11. Lista de expansões da variável do make
expansão da variável | descrição |
---|---|
foo1 := bar
|
expansão de uma vez |
foo2 = bar
|
expansão recursiva |
foo3 += bar
|
acrescentar |
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.
Veja referências para C nos seguintes.
info libc
" (Referência de funções da biblioteca C)
gcc
(1) e "info gcc
"
each_C_library_function_name
(3)
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.
O depurador principal em Debian é o
gdb
(1) que lhe permite inspeccionar um programa enquanto
ele é executado.
Vamos instalar o gdb
e programas relacionados com o
seguinte.
# 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
![]() |
Dica |
---|---|
Many |
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 nome_do_pacote_fonte $ apt-get source nome_do_pacote $ cd nome_do_pacote*
Corrigir bugs se necessário
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 e instale pacotes com símbolos de depuração com o seguinte.
$ export DEB_BUILD_OPTIONS=nostrip,noopt $ debuild $ cd .. $ sudo debi nome_do_pacote*.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.
gdb
(1).
Reproduzir o erro (crash).
gdb
prompt.
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.
![]() |
Dica |
---|---|
Often, you see a backtrace where one or more of the top lines are in
" |
$ MALLOC_CHECK_=2 gdb hello
Tabela 12.12. Lista de comandos gdb avançados
comando | descrição dos objectivos do comando |
---|---|
(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.
O programa 'preview1' recebeu um erro do X Window System.
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.
Aqui estão várias ferramentas de detecção de fugas de memória em Debian.
Tabela 12.13. Lista de ferramentas de detecção de fugas de memória
pacote | popcon | tamanho | descrição |
---|---|---|---|
libc6-dev *
|
V:46, I:68 | 11292 |
mtrace (1): funcionalidades de depuração do malloc em
glibc
|
valgrind *
|
V:1.3, I:6 | 136416 | depurador e perfilador de memória |
kmtrace *
|
V:0.3, I:2 | 324 |
Rastreador de fugas de memória do KDE que usa o mtrace (1)
da glibc
|
alleyoop *
|
V:0.05, I:0.3 | 596 | Frontend do GNOME para o verificador de memória Valgrind |
electric-fence *
|
V:0.05, I:0.8 | 120 | o depurador malloc (3)
|
leaktracer *
|
V:0.01, I:0.11 | 116 | rastreador de fugas de memória para programas C++ |
libdmalloc5 *
|
V:0.01, I:0.2 | 356 | biblioteca de depuração de alocação de memória |
mpatrolc2 *
|
V:0.00, I:0.01 | 3592 | biblioteca para depurar alocações de memória |
There are lint like tools for static code analysis.
Tabela 12.14. Lista de ferramentas para análise de código estático
pacote | popcon | tamanho | descrição |
---|---|---|---|
splint *
|
V:0.06, I:0.5 | 1836 | ferramenta para verificação estática de programas C para bugs |
rats
*
|
V:0.06, I:0.2 | 876 | rough Auditing Tool for Security (C, C++, PHP, Perl, and Python code) |
flawfinder *
|
V:0.01, I:0.15 | 192 | ferramenta para examinar código fonte C/C++ e procurar por fraquezas na segurança |
perl
*
|
V:88, I:99 | 18528 |
interpreter with internal static code checker:
B::Lint (3perl)
|
pylint *
|
V:0.2, I:0.7 | 576 | Verificador estático de código Python |
jlint
*
|
V:0.01, I:0.09 | 156 | Verificador de programa Java |
weblint-perl *
|
V:0.10, I:0.7 | 28 | Verificado de sintaxe e estilo mínimo para HTML |
linklint *
|
V:0.05, I:0.3 | 432 | fast link checker and web site maintenance tool |
libxml2-utils *
|
V:3, I:49 | 160 |
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.
Tabela 12.15. List of Yacc-compatible LALR parser generators
pacote | popcon | tamanho | descrição |
---|---|---|---|
bison
*
|
V:2, I:15 | 1504 | GNU LALR parser generator |
byacc
*
|
V:0.09, I:1.2 | 168 | Berkeley LALR parser generator |
btyacc *
|
V:0.00, I:0.07 | 248 |
backtracking parser generator based on byacc
|
O tutorial para o bison
(1) pode ser encontrado em
"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.
![]() |
Atenção |
---|---|
Não substitua ficheiros do sistema com os seus programas compilados quando os instalar. |
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 "todas-as-opções-que-fornecer" # 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 }' |
Isto é equivalente a qualquer uma das seguintes linhas.
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' |
Este último é um enigma. Aproveitei-me das seguintes funcionalidades do Perl.
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.
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.
QUERY_STRING="VAR1=VAL1
VAR2=VAL2 VAR3=VAL3"
".
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.
For more, see the Common Gateway Interface, The Apache Software Foundation, and 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.
Existem programas para converter códigos fonte.
Tabela 12.16. Lista de ferramentas de tradução de código fonte
pacote | popcon | tamanho | palavra chave | descrição |
---|---|---|---|---|
perl
*
|
V:88, I:99 | 18528 | AWK→PERL |
convert source codes from AWK to PERL: a2p (1)
|
f2c
*
|
V:0.12, I:1.2 | 448 | FORTRAN→C |
convert source codes from FORTRAN 77 to C/C++: f2c (1)
|
protoize *
|
V:0.00, I:0.09 | 100 | ANSI C | Cria/remove protótipos ANSI de código C |
intel2gas *
|
V:0.01, I:0.07 | 344 | intel→gas | converter from NASM (Intel format) to the GNU Assembler (GAS) |
Se você deseja criar um pacote debian, leia o seguinte.
debuild
(1), pbuilder
(1) e
pdebuild
(1)
maint-guide
)
developers-reference
)
debian-policy
)
Existem pacotes como os dh-make
,
dh-make-perl
, etc., que ajudam no processo em
empacotamento.