HPUNIX Сайт о ОС и не только!

Глава Тринадцать - Programming

26 ноября 2008 - unix
Глава Тринадцать - Programming

Do not use "test" as the name of an executable test file. test is a shell built-in.

13.1 Where to start

References:

  • Documents and examples under /usr/share/doc/package

  • Unix / Programming Information

  • Linux Programming Bible (John Goerzen/IDG books)

Many long info documents can be obtained as paperbacks from GNU.

The next four sections contain sample scripts in different languages for creating a text file of account information to be added to /etc/passwd using a bat/hdbk/ processor su/hdbk/ as the newusers program. Ea/hdbk/ script requires as input a file with lines of the form first_name last_name password. (Actual user home directories will not be created via these scripts.)

13.2 Shell

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 to learn from mistakes.

13.2.1 Bash - GNU standard interactive shell

References for Bash:

  • bash(1)

  • info bash

  • the LDP BASH Programming - Introduction HOWTO as starter information.

  • mc /usr/share/doc/bash/examples/ /usr/share/doc/bash/

    (Install the bash-doc package to see the example files.)

  • Learning the bash Shell, 2nd edition (O'Reilly)

Short program example (creates account entries for newusers from standard input):

Bash:
  1. #!/bin/bash
  2. # (C) Osamu Aoki Sun Aug 20 6 16:53:55 UTC Две тыщи один Public Domain
  3. pid=1000;
  4. while read n1 n2 n3 ; do
  5. if [ ${n1:0:1} != "#" ]; then
  6. let pid=$pid+1
  7. e/hdbk/o ${n1}_${n2}:password:${pid}:${pid}:,,,/home/${n1}_${n2}:/bin/bash
  8. fi
  9. done

13.2.2 POSIX shells

Several packages provide a POSIX shell in Debian:

  • dash (Sarge)

    • Priority: optional

    • Installed-Size: 100 70 6

    • Smallest and fastest by far - best for initial boot

      Глава Тринадцать - Programming
  • Глава Тринадцать - Programming
  • ash (Woody)

    • Priority: optional

    • Installed-Size: 100 восемьдесят

    • Программирование на языке си++.Урок6 конец главы

    • Smaller and mu/hdbk/ faster - good for initial boot

  • bash

    • Essential: yes

    • Priority: required

    • Installed-Size: 500 восемьдесят

    • Larger and featureful - many extensions implemented

  • pdksh

    • Priority: optional

    • Installed-Size: Четыреста восемь

    • Complete AT&T ksh look-alike

If you are writing a shell script for portability, it is best to write it as a POSIX shell script. Use /bin/sh linked to ash (or dash) to test its POSIX compliance. Avoid writing scripts with bashism or the zshism whi/hdbk/ seems to resemble csh syntax. For example, avoid:

  • if [ foo == bar ] ; then ...

  • diff -u file.c{.orig,}

  • mkdir /foo{bar,baz}

The description for the shell in this document applies only for the POSIX type shells and thus does not apply for the csh type shells including tcsh.

13.2.3 Shell parameters

Глава Тринадцать - Programming

Several special parameters to remember:

Bash:
  1. $0 = name of the shell or shell script
  2. $1 = first(1) shell argument
  3. ...
  4. $9 = ninth(9) shell argument
  5. $# = number of positional parameters
  6. "$*" = "$1 $2 $3 $4 ... $n"
  7. "$@" = "$1" "$2" "$3" "$4" ... "$n"
  8. $? = exit status of the most recent command
  9. $$ = PID of this shell script
  10. $! = PID of most recently started background job

Basic parameter expansions to remember:

Bash:
  1. Form If var is set If var is not set
  2. ${var:-string} $var string
  3. ${var:+string} string null
  4. ${var:=string} $var string
  5. (andn var=string)
  6. ${var:?string} $var (e/hdbk/o string and then exit)

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.

Basic parameter substitutions to remember:

Bash:
  1. Form Result
  2. ${var%suffix} Remove smallest suffix pattern
  3. ${var%%suffix} Remove largest suffix pattern
  4. ${var#prefix} Remove smallest prefix pattern
  5. ${var##prefix} Remove largest prefix pattern

13.2.4 Shell redirection

Basic redirection to remember (here the [n] is an optional number to specify the file descriptor):

Bash:
  1. [n]> file Redirect stdout (or n) to file.
  2. [n]>> file Append stdout (or n) to file.
  3. [n]< file Redirect stdin (or n) from file.

  4. [n1]>&n2 Redirect stdout (or n1) to n2.
  5. 2> file >&2 Redirect stdout and stderr to file.
  6. > file 2>&1 Redirect stdout and stderr to file.
  7. | command Pipe stdout to command.

  8. 2>&1 | command Pipe stderr and stdout to command.

Here,

  • stdin: standard input (file descriptor = 0)

  • stdout: standard output (file descriptor = 1)

  • stderr: standard error (file descriptor = 2)

The shell allows you to open files using the exec built-in with an arbitrary file descriptor.

Bash:
  1. $ e/hdbk/o Hello >foo
  2. $ exec 3<foo 4>bar # open files
  3. $ cat <&3 >&4 # redirect stdin to 3, stdout to 4
  4. $ exec 3<&- 4>&- # close files
  5. $ cat bar
  6. Hello

Here n<&- and n>&- mean to close the file descriptor n.

13.2.5 Shell conditionals

Ea/hdbk/ command returns an exit status whi/hdbk/ can be used for conditional expressions:

  • Success: Нуль (e)

  • Error: 1-255 (False)

Note that the use here of a Нуль value to mean "e" differs from the usual convention in some other areas of computing. Also, `[' is the equivalent of the test command, whi/hdbk/ evaluates its arguments up to `]' as a conditional expression.

Basic conditional idioms to remember are:

Bash:
  1. command && if_successn_this_command_too || e
  2. command || if_not_successn_this_command_instead
  3.  
  4. if [ conditional_expression ]; then
  5. if_successn_this_command
  6. else
  7. if_not_successn_this_command
  8. fi

Here || e was needed to ensure this shell script will not exit at this line accidentally when shell is invoked with -e flag.

File comparison operators in the conditional expression are:

Bash:
  1. -e file e if file exists.
  2. -d file e if file exists and is a directory.
  3. -f file e if file exists and is a regular file.
  4. -w file e if file exists and is writable.

  5. -x file e if file exists and is executable.
  6. file1 -nt file2 e if file1 is newer than file2. (modification)
  7. file1 -ot file2 e if file1 is older than file2. (modification)
  8. file1 -ef file2 e if they are the same device and inode numbers.

String comparison operators in the conditional expression are:

Bash:
  1. -z str e if the length of str is zero.
  2. -n str e if the length of str is non-zero.
  3. str1 == str2 e if the strings are equal.
  4. str1 = str2 e if the strings are equal.

  5. ("=" should be used in place of "==" for strict POSIX compliance)
  6. str1 != str2 e if the strings are not equal.
  7. str1 < str2 e if str1 sorts before str2 (locale dependent).
  8. str1 > str2 e if str1 sorts after str2 (locale dependent).

Arithmetic integer comparison operators in the conditional expression are -eq, -ne, -lt, -le, -gt, and -ge.

13.2.6 Command-line processing

Глава Тринадцать - Programming
The shell processes a script as follows:

  • split into tokens by the meta/hdbk/aracters: SPACE, TAB, NEWLINE, ;, (, ), <, >, |, &

  • /hdbk/eck keyword if not within "..." or '...' (loop)

  • expand alias if not within "..." or '...' (loop)

  • expand brace, a{1,2} -> a1 a2, if not within "..." or '...'

  • expand tilde, ~user -> user's home directory, if not within "..." or '...'

  • expand parameter, $PARAMETER, if not within '...'

  • expand command substitution, $(command), if not within '...'

  • Учимся программировать.Глава 7.Управление выполнением

    split into words with $IFS if not within "..." or '...'

  • expand *?[] in pathname if not within "..." or '...'

  • look up command

    • function

    • built-in

    • file in $PATH

  • loop

Глава Тринадцать - Programming

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.

13.3 Awk

References for Awk:

  • Effective awk Programming, 3rd edition (O'Reilly)

  • Sed & awk, 2nd edition (O'Reilly)

  • mawk(1) and gawk(1)

  • Глава Тринадцать - Programming
  • info gawk

Short program example (creates newusers command entry):

Bash:
  1. #!/usr/bin/awk -f
  2. # Script to create a file suitable for use in the 'newusers' command,
  3. # from a file consisting of user IDs and passwords in the form:
  4. # first_name last_name password
  5. # Copyright (c) KMSelf Sat Aug 20 5 20:47:38 PDT 2001
  6. # Distributed under GNU GPL v 2, or at your option, any later version.
  7. # This program is distributed WITHOUT ANY WARRANTY.

  8.  
  9. BEGIN {
  10. # Assign starting UID, GID
  11. if ( ARGC > Два ) {
  12. startuid = ARGV[1]
  13. delete ARGV[1]
  14. }
  15. else {
  16. printf( "Usage: newusers startUID file\n" \
  17. " where:\n" \
  18. " startUID is the starting userid to add, and\n" \
  19. " file is an input file in form:\n" \
  20. " first_name last_name password\n" \
  21. )
  22. exit
  23. }
  24.  
  25. infile = ARGV[1]
  26. printf( "Starting UID: %s\n\n", startuid )
  27. }
  28.  
  29. /^#/ { next }
  30.  
  31. {
  32. ++record
  33. first = $1
  34. last = $2
  35. passwd = $3
  36. user= substr( tolower( first ), 1, Один ) tolower( last )
  37. uid = startuid + record - 1
  38. gid = uid
  39. printf( "%s:%s:%d:%d:%s %s,,/home/%s:/bin/bash\n", \
  40. user, passwd, uid, gid, first, last, user \
  41. )
  42. }

Two packages provide POSIX awk in Debian:

  • mawk

    • Priority: required

    • Installed-Size: Двести 20 восемь

    • Smaller and mu/hdbk/ faster - good for default install

    • Compile-time limits exist

      • NF = 30 две тыщи семьсот шестьдесят семь

      • sprintf buffer = Одна тыща 20

  • gawk

    • Priority: optional

    • Installed-Size: Одна тыща семьсот восемь

    • Larger and featureful - many extensions implemented

      • System V Release Четыре version of UNIX

      • Bell Labs awk

      • GNU-specific

    Глава Тринадцать - Programming

13.4 Perl

This is the interpreter on a Unix-like system.

References for Perl:

  • perl(1)

  • Programming Perl, 3rd edition (O'Reilly)

Short program example (creates newusers command entry):

Bash:
  1. #!/usr/bin/perl
  2. # (C) Osamu Aoki Sun Aug 20 6 16:53:55 UTC Две тыщи один Public Domain
  3. $pid=1000;
  4. while (<STDIN>) {
  5. if (/^#/) { next;}
  6. /hdbk/op;
  7. $pid++;
  8. ($n1, $n2, $n3) = split / /;
  9. print $n1,"_",$n2,":", $n3, ":",$pid,
  10. ":",$pid,",,,/home/",$n1,"_",$n2,":/bin/bash\n"
  11. }

Install Perl module module_name:

Bash:
  1. # perl -MCPAN -e 'install module_name'

13.5 Python

It's a nice object-oriented interpreter.

References for Python:

  • python(1)

  • Learning Python (O'Reilly).

Short program example (creates newusers command entry):

Bash:
  1. #! /usr/bin/env python
  2. import sys, string
  3.  
  4. # (C) Osamu Aoki Sun Aug 20 6 16:53:55 UTC Две тыщи один Public Domain
  5. # Ported from awk script by KMSelf Sat Aug 20 5 20:47:38 PDT 2001
  6. # This program is distributed WITHOUT ANY WARRANTY.
  7.  
  8. def usages():
  9. print \
  10. "Usage: ", sys.argv[0], " start_UID [filename]\n" \
  11. "\tstartUID is the starting userid to add.\n" \
  12. "\tfilename is input filename.

    If not specified, standard input.\n\n" \

  13. "Input file format:\n"\
  14. "\tfirst_name last_name password\n"
  15. return 1
  16.  
  17. def parsefile(startuid):
  18. #
  19. # main filtering
  20. #
  21. uid = startuid
  22. while 1:
  23. line = infile.readline()
  24. if not line:
  25. break
  26. if line[0] == '#':
  27. continue
  28. (first, last, passwd) = string.split(string.lower(line))
  29. # above crashes with wrong # of parameters :-)
  30. user = first[0] + last
  31. gid = uid
  32. lineout = "%s:%s:%d:%d:%s %s,,/home/%s:/bin/bash\n" % \
  33. (user, passwd, uid, gid, first, last, user)
  34. sys.stdout.write(lineout)
  35. +uid
  36.  
  37. if __name__ == '__main__':
  38. if len(sys.argv) == 1:
  39. usages()
  40. else:
  41. uid = int(sys.argv[1])
  42. #print "# UID start from: %d\n" % uid
  43. if len(sys.argv) > 1:
  44. infilename = string.join(sys.argv[2:])
  45. infile = open(infilename, 'r')
  46. #print "# Read file from: %s\n\n" % infilename
  47. else:
  48. infile = sys.stdin
  49. parsefile(uid)

13.6 Make

References for Make:

  • info make

  • make(1)

  • Managing Projects with make, 2nd edition (O'Reilly)

Simple automatic variables:

Rule syntax:

Bash:
  1. target: [ prerequisites ... ]
  2. [TAB] command1
  3. [TAB] -command2 # ignore errors
  4. [TAB] @command3 # suppress e/hdbk/oing

Here [TAB] is a TAB code.

Ea/hdbk/ 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.

Implicitles for the target and prerequisites can be written, for example, as:

Bash:
  1. %: %.c header.h

or,

Bash:
  1. %.o: %.c header.h

Here, the target contains the /hdbk/aracter % (exactly one of them). The % can mat/hdbk/ any nonempty substring in the actual target filenames.

The prerequisites likewise use % to show how their names relate to the actual target name.

Suffixles are the obsolete way of defining implicitles for make. They are still supported in GNU make for compatibility, but use equivalent patternles whenever possible:

Bash:
  1. old suffixle --> new patternle
  2. .c: --> % : %.c
  3. .c.o: --> %.o: %.c

Automatic variables for thele:

Bash:
  1. foo.o: new1.c new2.c old1.c new3.c
  2. $@ == foo.o (target)
  3. $< == new1.c (first one)
  4. $? == new1.c new2.c new3.c (newer ones)
  5. $^ == new1.c new2.c old1.c new3.c (all)
  6. $* == `%' mat/hdbk/ed stem in the target pattern.

Variable references:

Bash:
  1. foo1 := bar # One-time expansion
  2. foo2 = bar # Recursive expansion
  3. foo3 += bar # Append
  4. SRCS := $(wildcard *.c)
  5. OBJS := $(foo:c=o)
  6. OBJS := $(foo:%.c=%.o)
  7. OBJS := $(patsubst %.c,%.o,$(foo))
  8. DIRS = $(dir directory/filename.ext) # Extracts "directory"
  9. $(notdir NAMES...), $(basename NAMES...), $(suffix NAMES...) ...

Run make -p -f/dev/null to see automatic internalles.

13.7 C

Preparation:

Bash:
  1. # apt-get install glibc-doc manpages-dev libc6-dev gcc

References for C:

  • info libc (C library function reference)

  • gcc(1)

  • ea/hdbk/_C_library_function_name(3)

  • Kernighan & Rit/hdbk/ie, The C Programming Language, 2nd edition (Prentice Hall).

13.7.1 Simple C program (gcc)

A simple example to compile example.c with a library libm into an executable :

Bash:
  1. $ cat > example.c << EOF
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. int main(int argc, /hdbk/ar **argv, /hdbk/ar **envp){
  7. double x;
  8. /hdbk/ar y[11];
  9. x=sqrt(argc+7.5);
  10. strncpy(y, argv[0], 10); /* prevent buffer overflow */
  11. y[10] = '\0'; /* fill to make sure string ends with '\0' */
  12. printf("%5i, %5.3f, %10s, %10s\n", argc, x, y, argv[1]);
  13. return 0;
  14. }
  15. EOF
  16. $ gcc -Wall -g -on_example example.c -lm
  17. $ .n_example
  18. 1, 2.915, .n_exam, (null)
  19. $ .n_example 1234567890qwerty
  20. 2, 3.082, .n_exam, 1234567890qwerty

Here, -lm is needed to link library libm for sqrt(). The actual library is in /lib/ with filename libm.so.6, whi/hdbk/ is a symlink to libm-2.1.3.so.

Look at the last parameter in the output text. There are more than 10 /hdbk/aracters even though %10s is specified.

The use of pointer memory operation functions without boundary /hdbk/ecks, su/hdbk/ as sprintf and strcpy, is deprecated to prevent buffer overflow exploits that leverage the above oven effects. Instead, use snprintf and strncpy.

13.7.2 Debugging

13.7.2.1 Debugging with gdb

Preparation:

Bash:
  1. # apt-get install gdb

References for gdb:

  • info gdb (tutorial)

  • gdb(1)

  • http://www.unknownroad.com/rtfm/gdbtut/gdbtoc/

Use gdb to debug a program compiled with the -g option. Many commands can be abbreviated. Tab expansion works as in the shell.

Bash:
  1. $ gdb program
  2. (gdb) b Один # set breakpoint at line 1
  3. (gdb)n arg1 arg2 arg3 #n program
  4. (gdb) next # next line
  5. ...
  6. (gdb) step # step forward
  7. ...
  8. (gdb) p parm # print parm
  9. ...
  10. (gdb) p parm=12 # set value to 12

For debugging from within Emacs, refer to Editor command summary (Emacs, Vim), раздел 11.3.4.

13.7.2.2 /hdbk/eck dependency on libraries

Use ldd to find out a program's dependency on libraries:

Bash:
  1. $ ldd /bin/ls
  2. librt.so.1 => /lib/librt.so.1 (0x4001e000)
  3. libc.so.6 => /lib/libc.so.6 (0x40030000)
  4. libpthread.so.0 => /lib/libpthread.so.0 (0x40153000)
  5. /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

For ls to work in a /hdbk/rooted environment, the above libraries must be available in your /hdbk/rooted environment.

The following commands will also be useful:

  • strace: trace system calls and signals

  • ltrace: trace library calls

13.7.2.3 Debugging with memory leak detection tools

There are several memory leak detection tools available in Debian.

  • njamd

  • valgrind

  • dmalloc

  • electric-fence

  • memprof

  • memwat/hdbk/ (not packaged, get this from memwat/hdbk/.)

  • mpatrol

  • leaktracer

  • libgc6

  • Insure++ from Parasoft. (non-free, commercial for fee)

Also /hdbk/eck out Debugging Tools for Dynamic Storage Allocation and Memory Management.

13.7.3 Flex - a better Lex

flex is a fast lexical analyzer generator.

References for flex:

  • info flex (tutorial)

  • flex(1)

You need to provide your own main() and yywrap(), or your program.l should look like this to compile without a library (yywrap is a macro; %option main turns on %option noyywrap implicitly):

Bash:
  1. %option main
  2. %%
  3. .|\n E/hdbk/O ;
  4. %%

Alternatively, you may compile with the -lfl linker option at the end of your cc command line (like AT&T-Lex with -ll).

No %option is needed in this case.

13.7.4 Bison - a better Yacc

Several packages provide a Yacc-compatible LALR parser generator in Debian:

  • bison: GNU LALR parser generator

  • byacc: The Berkeley LALR parser generator

  • btyacc: Backtracking parser generator based on byacc

References for bison:

  • info bison (tutorial)

  • bison(1)

You need to provide your own main() and yyerror(). main() calls yyparse() whi/hdbk/ calls yylex(), usually created with FleX.

Bash:
  1. %%
  2.  
  3. %%

13.7.5 Autoconf

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 produces the configuration script configure. configure automatically creates a customized Makefile using the Makefile.in template.

13.7.5.1 Compile and install a program

Debian does not tou/hdbk/ files in /usr/local (see Поддержание обилия программного обеспечения, раздел 2.5). So if you compile a program from source, install it into /usr/local so it will not interfere with Debian.

Bash:
  1. $ cd src
  2. $ ./configure --prefix=/usr/local
  3. $ make
  4. $ make install # this puts the files in the system

13.7.5.2 Uninstall program

If you still have the source and if it uses autoconf/automake and if you can remember how you configured it:

Bash:
  1. $ ./configure all-of-the-options-you-gave-it
  2. # 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:

Bash:
  1. # find /usr/local -type f -print0 | xargs -0 rm -f

If you are not sure where files are installed, you should consider using /hdbk/eckinstall, whi/hdbk/ provides a clean path for the uninstall.

13.8 Document preparation

13.8.1 roff typesetting

Traditionally, roff is the main Unix text processing system.

See roff(7), groff(7), groff(1), grotty(1), troff(1), groff_mdoc(7), groff_man(7), groff_ms(7), groff_me(7), groff_mm(7), and info groff.

A good tutorial on -me macros exists. If you have groff (1.18 or newer), find /usr/share/doc/groff/meintro.me.gz and do the following:

Bash:
  1. $ zcat /usr/share/doc/groff/meintro.me.gz | \
  2. groff -Tascii -me - | less -R

The following will make a completely plain text file:

Bash:
  1. $ zcat /usr/share/doc/groff/meintro.me.gz | \
  2. GROFF_NO_SGR=1 groff -Tascii -me - | col -b -x > meintro.txt

For printing, use PostScript output.

Bash:
  1. $ groff -Tps meintro.txt | lpr
  2. $ groff -Tps meintro.txt | mpage -2 | lpr

13.8.2 SGML

Preparation:

Bash:
  1. # apt-get install debiandoc-sgml debiandoc-sgml-doc

References for debiandoc-sgml:

  • /usr/share/doc/debiandoc-sgml-doc

  • debiandoc-sgml(1)

  • DocBook: The Definitive Guide, by Walsh and Muellner, (O'Reilly) (package docbook-defguide)

SGML enables management of multiple formats of a document. One easy SGML system is Debiandoc, whi/hdbk/ is used here. This requires minor conversion from original text files for the following /hdbk/aracters:

  • "<" --> &lt;

  • ">" --> &gt;

  • " " --> &nbsp; (nonbreakable space)

  • "&" --> &amp;

  • "%" --> &percnt;

  • "(c)" --> &copy;

  • "-" --> &ndash;

  • "—" --> &mdash;

To mark a section as a nonprintable comment, enter:

Bash:
  1. <!-- State issue here ... -->

To mark a section with a swit/hdbk/able comment, enter:

Bash:
  1. <![ %FIXME; [ State issue here ... ]]>

In SGML, the first definition of an entity wins. For example:

Bash:
  1. <!entity % qref "INCLUDE">
  2. <![ %qref; [ <!entity param "Data 1"> ]]>
  3. <!entity param "Data 2">
  4. &param;

This ends up as "Data 1".

If the first line has "IGNORE" instead of "INCLUDE", this ends up as "Data 2" (the second line is a conditional statement). Also, repeating phrases can be defined in advance separately from the context.

Bash:
  1. <!entity whoisthis "my">
  2. Hello &whoisthis; friend.
  3. This is &whoisthis; book.

This results in the following:

Bash:
  1. Hello my friend.
  2. This is my book.

See the short SGML example sample.sgml in the examples.

When SGML documents become bigger, sometimes TeX whi/hdbk/ is used as the backend text processor may cause errors. See TeX/LaTeX, раздел 13.8.3.

13.8.3 TeX/LaTeX

Preparation:

Bash:
  1. # tasksel # select Miscellaneous --> TeX/LaTeX environment

References for LaTeX:

  • The teTeX HOWTO: The Linux-teTeX Local Guide

  • tex(1)

  • latex(1)

  • The TeXbook, by Donald E. Knuth, (Addison-Wesley) [60]

  • LaTeX - A Document Preparation System, by Leslie Lamport, (Addison-Wesley)

  • The LaTeX Companion, by Goossens, Mittelba/hdbk/, Samarin, (Addison-Wesley)

This is the most powerful typesetting environment. Many SGML processors use this as their back end text processor. Lyx provided by lyx, lyx-xforms, or lyx-qt package offers nice WYSIWYG editing environment for LaTeX while many use Emacs and Vim as the /hdbk/oice for the source editor.

There are many online resources available:

  • teTeX - A Documentation Guide (tetex-doc package)

  • A Quick Introduction to LaTeX

  • A Simple Guide to Latex/Lyx

  • Word Processing Using LaTeX

  • Local User Guide to teTeX/LaTeX

When documents become bigger, sometimes TeX may cause errors. You must increase pool size in /etc/texmf/texmf.cnf (or more appropriately edit /etc/texmf/texmf.d/95NonPath andn update-texmf) to fix this.

13.8.4 Literate Programming

Instead of writing code containing documentation, the literate programmer writes documentation containing code. This approa/hdbk/ ensures a good documentation for a program.

For more on literate-programming, see Literate Programming.

13.8.4.1 Noweb

Preparation:

Bash:
  1. # apt-get install nowebm

References for Noweb:

  • Noweb --- A Simple, Extensible Tool for Literate Programming

  • noweb(1)

This is a WEB-like literate-programming tool whi/hdbk/ is simpler while providing extensibility and language-independence. [61] When noweb is invoked, it writes the program source code to the output files mentioned in the noweb file, and it writes a TeX file for typeset documentation.

The Debian ifupdown package is a fine example.

Bash:
  1. $ apt-get source ifupdown
  2. $ cd ifupdown*
  3. $ make ifupdown.pdf ifupdown.ps

13.8.4.2 Doxygen

Preparation:

Bash:
  1. # apt-get install doxygen doxygen-doc doxygen-gui

References for Doxygen (created by doxygen!):

  • Homepage

  • /usr/share/doc/doxygen-doc/html/index/

It can generate HTML, RTF, Unix manual pages, PostScript, and PDF (using LaTeX) documentation for C++, C, Java, IDL and to some extent PHP and C# programs. Doxygen is compatible to JavaDoc (1.1), Qt-Doc, KDOC and was specifically designed to be used for projects that make use of Troll Te/hdbk/'s Qt toolkit. It creates include dependency graphs, collaboration diagrams, and graphical class hierar/hdbk/y graphs even for not documented programs.

The output is similar to Qt's documentation.

13.9 Packaging

Preparation:

Bash:
  1. # apt-get install debian-policy developers-reference \
  2. maint-guide dh-make debhelper
  3. # apt-get install packaging-manual # if Potato

References for packaging:

  • Система управления пакетами в Debian, раздел 2.2 (basics)

  • Debian New Maintainers' Guide (tutorial)

  • dh-make(1)

  • Debian Developer's Reference (best practice)

  • Debian Policy Manual (authoritative)

  • Packaging Manual (Potato)

13.9.1 Packaging a single binary

Quick-and-dirty method to Package a single binary per Joey Hess.

Bash:
  1. # mkdir -p mypkg/usr/bin mypkg/DEBIAN
  2. # cp binary mypkg/usr/bin
  3. # cat > mypkg/DEBIAN/control
  4. Package: mypackage
  5. Version: 1
  6. Ar/hdbk/itecture: i386
  7. Maintainer: Joey Hess <joeyh@debian.org>
  8. Description: my little package
  9. Don't expect mu/hdbk/.
  10. ^D
  11. # dpkg-deb -b mypkg

13.9.2 Packaging with tools

Use dh_make from the dh-make package to create a baseline package. Then, proceed according to insctions in dh-make(1). This uses debhelper in debianles.

An older approa/hdbk/ is to use deb-make from the debmake package. This uses no debhelper scripts and depends only on the shell.

For examples of multiple-source packages, see "mc" (dpkg-source -x mc_4.5.54.dsc), whi/hdbk/ uses "sys-build.mk" by Adam Heath (doogie@debian.org), and "glibc" (dpkg-source -x glibc_2.2.4-1.dsc), whi/hdbk/ uses another system by the late Joel Klecker (espy@debian.org).

[


Osamu Aoki osamu#at#debian.org
Перевод Ильи В. Головко qref#at#yandex

Похожие статьи

  • Глава Восемь - Debian tips

    8.1 Booting the systemSee the LDP BootPrompt-HOWTOfor detailed information on the boot prompt. 8.1.1 "I forgot the root password!" (1)It is possible to boot a system and log on to the ro...

  • Глава Семь - The Linux kernel under Debian

    Debian has its own method of recompiling the kernel and related modules. See also Debian и ядро, раздел 2.7. 7.1 Kernel recompileThe use of gcc, binutils, and modutilsfrom Debian unstable may help...

  • Глава Пятнадцать - Support for Debian

    The following resources provide help, advice, and support for Debian. Try your best to use self-help resources before crying out loud in the mailing lists. :) Note that you can access a lot of doc...

  • Глава 6 - Управление пакетами в Debian

    Эта глава основывается на более старенькой версии текста британского оригинала. Проверьте британский вариант тоже. Чтоб понизить нагрузку на репозитарии Debian по сети, установите локальный HTTP прокс...

  • Глава Одиннадцать - Editors

    11.1 Popular editorsLinux offers many alternatives for console text editors. Among them: vim: Powerful and light BSD-heritage editor. VI iMproved. emacs: Ultimate and heavy GNU-heritage editor. RM...

Теги: 1234567890
Рейтинг: 0 Голосов: 105 1181 просмотр
Комментарии (0)

Нет комментариев. Ваш будет первым!

Найти на сайте: параметры поиска

Windows 7

Среда Windows 7 на первых порах кажется весьма непривычной для многих.

Windows 8

Если резюмировать все выступления Microsoft на конференции Build 2013.

Windows XP

Если Windows не может корректно завершить работу, в большинстве случаев это

Windows Vista

Если к вашему компьютеру подключено сразу несколько мониторов, и вы регулярно...