Debian Codegraph @

README

raw
1
2 `headache`
3 **********
4 Vincent Simonet
5 ===============
6 November, 2002
7 ==============
8
9 This manual is also available in plain text (1), PostScript (2) and
10 PDF (3).
11
12
13 1 Overview
14 *=*=*=*=*=
15
16
17 It is a common usage to put at the beginning of source code files a
18 short header giving, for instance, some copyright informations.
19 `headache` is a simple and lightweight tool for managing easily these
20 headers. Among its functionalities, one may mention:
21
22 - Headers must generally be generated as comments in source code
23 files. `headache` deals with different file types and generates for
24 each of them headers in an appropriate format.
25 - `headache` automatically detects existing headers and removes them.
26 Thus, you can use it to update headers in a set of files.
27
28 `headache` is distributed under the terms of the GNU Library General
29 Public License. See file `LICENSE` of the distribution for more
30 information.
31
32
33 2 Compilation and installation
34 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
35
36
37 Building `headache` requires Objective Caml (available at
38 http://caml.inria.fr/) and GNU Make. In addition, from version
39 1.03-utf8, the build requires the Unicode library Camomile and, from
40 version 1.04, Dune.
41
42 Instructions
43
44 `headache` is available through OPAM (available at
45 http://opam.ocaml.org/), the OCaml Package Manager. This is the
46 preferred installation method. Then the following sequence of commands
47 should install the package:
48 <<
49 opam init
50 opam install headache
51 >>
52
53 Alternatively, you can use these commands (Dune must be installed):
54 <<
55 make && sudo make INSTALLDIR=/usr/local/bin install
56 >>
57 Build the executable and install it into the specified directory.
58
59
60 3 Usage
61 *=*=*=*
62
63
64 Let us illustrate the use of this tool with a small example. Assume
65 you have a small project mixing C and Caml code consisting in three
66 files `foo.c`, `bar.ml` and `bar.mli`, and you want to equip them with
67 some header. First of all, write a header file, i.e. a plain text file
68 including the information headers must mention. An example of such a
69 file is given in figure 1. In the following, we assume this file is
70 named `myheader` and is in the same directory as source files.
71 Then, in order to generate headers, just run the command:
72 <<
73 headache -h myheader foo.c bar.ml bar.mli
74 >>
75 Each file is equipped with a header including the text given in the
76 header file `myheader`, surrounded by some extra characters depending on
77 its format making it a comment (e.g. `(*` and `*)` in `.ml` files). If
78 you update informations in the header file `myheader`, you simply need
79 to re-run the above command to update headers in source code files:
80 existing ones are automatically removed.
81 Similarly, running:
82 <<
83 headache -r foo.c bar.ml bar.mli
84 >>
85 removes any existing in files `foo.c`, `bar.ml` and `bar.mli`. Files
86 which do not have a header are kept unchanged.
87 The current headers of files can be extracted:
88 <<
89 headache -e foo.c bar.ml bar.mli
90 >>
91 prints on the standard output the current headers of the files
92 `foo.c`, `bar.ml` and `bar.mli`. All files are kept unchanged.
93 --------------------------------------------------------------------
94
95 <<
96 Headache
97 Automatic generation of files headers
98
99 Vincent Simonet, Projet Cristal, INRIA Rocquencourt
100
101 Copyright 2002
102 Institut National de Recherche en Informatique et en Automatique.
103 All rights reserved. This file is distributed under the terms of
104 the GNU Library General Public License.
105
106 [email protected]
107 http://cristal.inria.fr/~simonet/
108 >>
109
110 Figure 1: An example of header file
111
112 --------------------------------------------------------------------
113
114
115
116 4 Configuration file
117 *=*=*=*=*=*=*=*=*=*=
118
119
120 File types and format of header may be specified by a configuration
121 file. By default, the default builtin configuration file given in
122 figure 2 is used. You can also use your own configuration file thanks to
123 the `-c` option:
124 <<
125 headache -c myconfig -h myheader foo.c bar.ml bar.mli
126 >>
127
128 In order to write your own configuration, you can follow the example
129 given in figure 2. A configuration file consists in a list of entries
130 separated by the character `|`. Each of them is made of two parts
131 separated by an `->`:
132
133 - The first one is a regular expression. Regular expression are
134 enclosed within double quotes and have the same syntax as in Gnu
135 Emacs. `headache` determines file types according to file basenames;
136 thus, each file is dealt with using the first line its name matches.
137 - The second one describes the format of headers for files of this
138 type. It consists of the name of a model (e.g. `frame`), possibly
139 followed by a list of arguments. Arguments are named: `open:"(*"`
140 means that the value of the argument `open` is `(*`.
141 `headache` currently supports three models:
142
143 - `frame`. With this model, headers are generated in a frame. This
144 model requires three arguments: `open` and `close` (the opening and
145 closing sequences for comments) and `line` (the character used to
146 make the horizontal lines of the frame). Two optional arguments may
147 be used: `margin` (a string printed between the left and right side
148 of the frame and the border, by default two spaces) and `width` (the
149 width of the inside of the frame, default is 68).
150 - `lines`. Headers are typeset between two lines. Three arguments
151 must be provided: `open` and `close` (the opening and closing
152 sequences for comments), `line` (the character used to make the
153 horizontal lines). Three optional arguments are allowed: `begin` (a
154 string typeset at the beginning of each line, by default two spaces),
155 `last` (a string typeset at the beginning of the last line) and
156 `width` (the width of the lines, default is 70).
157 - `no`. This model generates no header and has no argument.
158
159 It is possible to change the default builtin configuration file at
160 compile time. For this, just edit the file `config_builtin.txt` present
161 in the source distribution before building the software.
162 --------------------------------------------------------------------
163
164 <<
165 # Objective Caml source
166 ".*\\.ml[il]?" -> frame open:"(*" line:"*" close:"*)"
167 | ".*\\.fml[i]?" -> frame open:"(*" line:"*" close:"*)"
168 | ".*\\.mly" -> frame open:"/*" line:"*" close:"*/"
169 # C source
170 | ".*\\.[chy]" -> frame open:"/*" line:"*" close:"*/"
171 # Latex
172 | ".*\\.tex" -> frame open:"%" line:"%" close:"%"
173 # Misc
174 | ".*Makefile.*" -> frame open:"#" line:"#" close:"#"
175 | ".*README.*" -> frame open:"*" line:"*" close:"*"
176 | ".*LICENSE.*" -> frame open:"*" line:"*" close:"*"
177 >>
178
179 Figure 2: The default builtin configuration file
180
181 --------------------------------------------------------------------
182
183 It is also possible to add entries into your own configuration file
184 that specify when the initial lines of the processed file have to be
185 skipped. As previously, these entries are separated by the character `|`
186 and each of them is made of two parts separated by an `->`:
187
188 - Again, the first part is a regular expression used by `headache` to
189 determine the file type. But here, it is according to its full
190 filename (including the pathname).
191 - The second part specifies when the initial lines must be skipped.
192 It consists of the keyword `skip` followed by one of the named
193 arguments `multiline_match:` or `match:`, then a regular expression.
194 As long as the lines match a `multiline_match` parameter, `headache`
195 skips them and checks the next line. If the current line matches only
196 a `match` parameter, `headache` skips the current line and breaks the
197 iteration there (of course, if nothing matches, `headache` puts the
198 header before the current line).
199
200 --------------------------------------------------------------------
201
202 <<# Script file
203 | ".*\\.sh" -> frame open:"#" line:"#" close:"#"
204 | ".*\\.sh" -> skip match:"#!.*"
205 >>
206
207 Figure 3: Example of a configuration file for skipping the shebang
208 line of shell scripts
209
210 --------------------------------------------------------------------
211
212 Figure 3 shows an example of configuration file that can used to skip
213 the shebang line of shell scripts: when the first line of `.sh` files
214 starts with `#!`, `headache` does not modify that line and considers
215 that the header must start at the second line.
216 --------------------------------------------------------------------
217
218 <<# SWI Prolog file
219 | ".*\\.pl" -> frame open:"%" line:"%" close:"%"
220 | ".*\\.pl" -> skip multiline_match:"#!.*" multiline_match:":-.*"
221 >>
222
223 Figure 4: Example of a configuration file for skipping the shebang
224 line, as well as lines containing Prolog directives, such as Unicode
225 usage.
226
227 --------------------------------------------------------------------
228
229 Figure 4 shows an example of configuration file that can used for `SWI
230 prolog` files: for a `.pl` file starting with the following three first
231 lines, `headache` considers that the header must start just after the
232 first two lines:
233 <<
234 #!/usr/bin/env swipl
235 :- encoding(utf8).
236 % remainder of the file, that can be after the header
237 >>
238
239 -----------------------------------------------------------------------
240 This document was translated from LaTeX by HeVeA (4).
241 -----------------------------------
242
243
244 (1) manual.txt
245 (2) manual.ps.gz
246 (3) manual.pdf
247 (4) http://hevea.inria.fr/index.html