Debian Codegraph @

doc/c_lib.tex

raw
1 %%*** c_lib.tex ***************************************************************
2 %%
3 %% This file is part of BibTool.
4 %% It is distributed under the Creative Commons Attribution-Share
5 %% Alike 3.0 License.
6 %%
7 %% (c) 1997-2020 Gerd Neugebauer
8 %%
9 %% Net: [email protected]
10 %%
11 %%-----------------------------------------------------------------------------
12 %% Usage: latex c_lib
13 %% makeindex -s bibtool.ist bibtool
14 %% latex c_lib
15 %%****************************************************************************
16
17 \NeedsTeXFormat{LaTeX2e}
18 \documentclass[11pt,a4paper]{scrbook}
19
20 \usepackage{array,shortvrb,makeidx}
21 \usepackage[colorlinks=true,
22 linkcolor=blue,
23 citecolor=blue]{hyperref}
24
25 \input{config}
26
27 \hypersetup{pdftitle={BibTool C Programmer's Manual}}
28 \hypersetup{pdfauthor={Gerd Neugebauer}}
29 \hypersetup{pdfsubject={Version \Version}}
30
31 \makeindex
32
33 \parindent=0pt
34 \parskip=1ex
35
36 \makeatletter
37 \newcommand\ClassFont{\scriptsize\sffamily}
38 \newcommand\File[2]{\section{The File \texttt{#1}}\label{sec:#2}}
39 \newcommand\Header[2]{\section{The Header File \texttt{#1}}\label{sec:#2}}
40 \newcommand\Module[2]{\section{The Module \texttt{#1}}\label{sec:#2}}
41 \newcommand\Fct[1]{\textbf{\large #1}}
42 \newcommand\Mac[1]{\textbf{\large #1}}
43 \newcommand\Var[1]{\textbf{#1}}
44 \newcommand\Type[1]{\textbf{#1}}
45 \newenvironment{Function}[2]{%
46 \begin{description}\item[\texttt{#1()}]\index{#2()|tt}\
47 \hfill{\ClassFont Function}\\%
48 }{\end{description}}
49 \newenvironment{Macro}[2]{%
50 \begin{description}\item[\texttt{#1()}]\index{#2()|sf}\
51 \hfill{\ClassFont Macro}\\%
52 }{\end{description}}
53 \newenvironment{Constant}[2]{%
54 \begin{description}\item[\texttt{#1}]\index{#2|sf}\
55 \hfill{\ClassFont Macro}\\%
56 }{\end{description}}
57 \newenvironment{Variable}[2]{%
58 \begin{description}\item[\texttt{#1}]\index{#2|tt}\
59 \hfill{\ClassFont Variable}\\%
60 }{\end{description}}
61 \newenvironment{Result}{%
62 \begin{description}\item[\textmd{Returns:}] }{\end{description}}
63 \newenvironment{Arguments}[1]{\begingroup\ttfamily\tabcolsep=0pt
64 \begin{tabular*}{.925\textwidth}%
65 {ll@{\extracolsep{\fill}}>{\normalfont\itshape\small}p{.55\textwidth}}
66 #1%
67 }{\end{tabular*}\endgroup\par}
68
69 \newenvironment{Typedef}[2]{\begin{description}%
70 \item[#1]\ \hfill{\ClassFont Type}\\}{}
71 \newcommand\STRUCT[1]{\par
72 \texttt{typedef struct}%
73 \textbf{\ #1 }
74 \texttt{\char123}\par
75 \begingroup\ttfamily\tabcolsep=0pt\rule{1em}{0pt}%
76 \begin{tabular*}{.9\textwidth}%
77 {ll@{\extracolsep{\fill}}>{\itshape\small}p{.55\textwidth}}%
78 }
79
80 \newcommand\EndSTRUCT[1]{\end{tabular*}\endgroup\par
81 \texttt{\char125}
82 #1;
83 \end{description}
84 }
85 \newcommand\Member[1]{\textbf{#1}}
86 \makeatother
87
88 \MakeShortVerb{|}
89
90 \newcommand\Ccomment[1]{\hfill\parbox[t]{.5\textwidth}{\textit{/* #1\hfill*/}}}
91
92 \newcommand\BibTool{\textsc{Bib\hskip-.1em\-%
93 \mbox{T\hskip-.15emo\hskip-.05emo\hskip-.05eml}}}
94 \newcommand\BibTeX{\textrm{B\kern-.05em\textsc{i\kern-.025em b}\kern-.08em
95 T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
96
97 \makeatletter%>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
98 \def\ps@headings{\let\@mkboth\markboth
99 \def\@oddfoot{}\def\@evenfoot{}
100 \def\@evenhead{\vbox{\vss\hbox to \textwidth{\textrm{\thepage} \hss
101 {\scriptsize\textsc{\ \leftmark}}}\kern 1.5mm\hrule depth 0.2 true pt}}
102 \def\@oddhead{\vbox{\vss\hbox to \textwidth{\textrm{\scriptsize\textsc{\rightmark\ }}
103 \hss \thepage}\kern 1.5mm\hrule depth 0.2 true pt}}
104 \def\chaptermark##1{\markboth {\ifnum \c@secnumdepth>\m@ne
105 \thechapter. \ \fi ##1}{}}
106 \def\sectionmark##1{\markright
107 {\ifnum \c@secnumdepth >\z@ \thesection. \ \fi ##1}}}
108
109 \pagestyle{headings}
110 \addtolength{\headheight}{2pt}
111 \makeatother
112
113 \newfont\cminch{cminch}
114 \ifx\chaptername\relax\else
115 \renewcommand\chaptername{\cminch}
116 \renewcommand\appendixname{\cminch}
117 \fi
118 \newcommand\rfill[1]{\leaders\hrule height #1\hfill}
119
120 \newcommand\Link[2]{\texttt{#2}}
121 \newcommand\email[1]{\texttt{#1}}
122
123 \newcommand\INCOMPLETE{\begin{center}
124 \unitlength=1mm\framebox(80,10)\textsf{To be completed.}
125 \end{center}}
126
127 \begin{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129 \thispagestyle{empty}
130 \null\vfill
131 {\begin{center}
132 \rule{\textwidth}{5pt}%
133 \bigskip\par
134 \hbox to \textwidth{\cminch \hss B\hss I\hss B\hss T\hss O\hss O\hss L\hss}
135 \medskip\par\normalsize
136 \mbox{}\rfill{5pt}\ A Tool to Manipulate \BibTeX\ Files\ \rfill{5pt}\null
137 %\medskip\par\normalsize Version \Version
138 \vfill \textbf{\Huge C Programmer's Manual}\vfill
139 \textit{\LARGE $\cal G$\kern-.1emerd $\cal N$\kern-.2emeugebauer}
140 \vfill\vfill
141 \begin{minipage}{.8\textwidth}\small
142 \begin{center}\textbf{Abstract}\end{center}
143
144 \BibTool{} provides a library of useful C functions to manipulate
145 \BibTeX{} files. This library has been used to implement the
146 \BibTool{} program. This document describes This library and allows
147 you to write C programs dealing with \BibTeX{} files.
148 \end{minipage}\vfill\vfill
149
150 \textsf{\small --- This documentation is still in a rudimentary form and
151 needs additional efforts. ---}
152 \end{center}}
153 %------------------------------------------------------------------------------
154 \newpage
155 \noindent
156 \begin{minipage}{\textwidth}\parskip=1ex
157 This file is part of \BibTool{} Version \Version
158 \medskip
159
160 Copyright \copyright{} \Year{} Gerd Neugebauer
161 \medskip
162
163 \BibTool{} is free software; you can redistribute it and/or modify it under
164 the terms of the GNU General Public License as published by the Free Software
165 Foundation; either version 1, or (at your option) any later version.
166
167 \BibTool{} is distributed in the hope that it will be useful, but WITHOUT ANY
168 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
169 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
170
171 You should have received a copy of the GNU General Public License along with
172 this documentation; see the file COPYING. If not, write to the Free Software
173 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
174 \end{minipage}
175 \vfill\par\noindent
176 Gerd Neugebauer\\
177 Im Lerchelsb\"ohl 5\\
178 64521 Gro\ss-Gerau (Germany)\smallskip\par\noindent
179 WWW: \Link{http://www.gerd-neugebauer.de/}{http://www.gerd-neugebauer.de/}
180 \smallskip\par\noindent
181 Net: \email{[email protected]}
182 %------------------------------------------------------------------------------
183 \tableofcontents
184
185 \chapter{Introduction}
186
187 The \BibTool{} C library provides functions to deal with \BibTeX{}
188 files. These functions are described in this document. Thus it should
189 be fairly easy to write new C program which handle \BibTeX{}
190 files. The reader is assumed to be familiar with \BibTeX{} files. this
191 documentation will not repeat an introduction into \BibTeX.
192
193 This documentation can not only be used to write new C programs
194 dealing with \BibTeX{} files but also to understand \BibTool---The
195 Program which serves as one example for using the \BibTool C library.
196 In any case it is essential to understand some of the underlying
197 concepts. Thus it is vital to read some sections very carefully.
198 %Especially the section
199
200
201 The \BibTool{} program uses the \BibTool{} C library. Well, in fact it
202 is the other way round. Historically the \BibTool{} program was first
203 and then the library has been extracted from it. Nevertheless the
204 \BibTool{} program can serve as an example how the \BibTool{} C
205 libary can be used.
206
207 \input c_main
208
209 \chapter{The \BibTool{} C Library}
210
211 \input c
212
213
214 \chapter{Creating and Using the \BibTool{} C Library}
215
216 \section{Creating the \BibTool{} C Library}
217
218 Creating the \BibTool{} library should not be too hard. Mainly make
219 \BibTool{} in the main directory according to the instructions given
220 there. As a side effect various object files are created. These object
221 files---except the one for main.c---have to be put into the library.
222
223 For UNIX this is prepared in the makefile. Usually an invocation of
224 make should be enough:
225
226 \begin{verbatim}
227 make libbibtool.a
228 \end{verbatim}
229
230 This invocation of make is in fact the same as the following two
231 commands:
232
233 \begin{verbatim}
234 ar r libbibtool.a $OFILES
235 ranlib libbibtool.a
236 \end{verbatim}
237
238 Here |$OFILES| denotes the list of object files as described above. On
239 some systems no ranlib program is present and needed. In this case the
240 second command can be omitted.
241
242 For other operating systems I simply do not know how things work
243 there. I would be grateful to receive descriptions what to do there.
244
245
246 \section{Using the \BibTool{} C Library}
247
248 %First of all you need to include the appropriate header file which
249 %provides all
250
251 If you have written a program which uses the \BibTool{} C Library you
252 have to include the library into the linking list. In addition the
253 directory where the library can be found has to be specified. On UNIX
254 this can be done with the compiler switches |-l| and |-L|
255 respectively. Thus consider you have a program named |mybib.c| and
256 you have created the object file |mybib.o| for it. The linking step
257 can be performed with the following command:
258
259 \begin{verbatim}
260 cc mybib.o -L$DIR -lbib -o mybib
261 \end{verbatim}
262
263 Here |$DIR| denotes the path containing the file |libbibtool.a|. This path
264 can be omitted if the library has been installed in a ``standard''
265 place like |/usr/lib|.
266
267
268 \chapter{Coding Standards}
269
270 Several tools are used for the development of \BibTool. Mostly they are home
271 grown---maybe they will be replaced by some wider used tools some day. Among
272 those tools are indentation routines for Emacs to format the comments
273 contained in the source. There is also a Lisp function to generate the
274 function prototypes contained in the header files and sometimes in the C files
275 as well. And finally there is a Program to extract the documentation from the
276 source files and generate a printable manual.
277
278 All those support programs rely on standards for coding. Some of those
279 standards have been develped independantly but should be used for consistency.
280 In the following sections these coding standards are described.
281
282
283 \section{K\&R-C vs. ANSI-C}
284
285 \BibTool{} tries hard to be portable to wide variety of C systems. Thus it can
286 not be assumed that an ANSI C compiler is at hand. As a consequence the
287 function heads are written in the old style which is also tolerated by ANSI
288 compliant compilers. This means that the argument types are given after the
289 argument list.
290
291 Here it is essential that the arguments type declarations are given in the
292 same order as the arguments of the function. Each type variable must have a
293 new type declaration in a line by it's own. This feature is used by the
294 program which extracts the function prototypes.
295
296 Those function heads are use to generate function prototypes which can be
297 understood by ANSI-C compilers as well as by of K\&R compilers. This is
298 achieved by the old trick to introduce a macro which expands to nothing on the
299 old compilers and to its aregument on ANSI compilers. This macro is defined
300 appropriately according to the existence of the macro \verb|__STDC__| which
301 should indicate an ANSI compliant compiler.
302
303
304 %\section{Indentation}
305
306
307 \printindex
308
309 \end{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 %
311 % Local Variables:
312 % mode: latex
313 % TeX-master: nil
314 % End: