| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> |
| 5 |
<meta name="generator" content="hevea 2.36"> |
| 6 |
<style type="text/css"> |
| 7 |
.equationcontainer{position:relative;} |
| 8 |
.equationnumber{float:right;left:auto;position:absolute;right:0} |
| 9 |
.equationnumber-valign{float:right;left:auto;position:absolute;right:0;margin-top:-0.5em;} |
| 10 |
.floatrule{background-color: black; border: none; height: 1px; width: 80%} |
| 11 |
.phantom{display: inline-block; visibility: hidden} |
| 12 |
.hphantom{display: inline-block; height: 0; visibility: hidden} |
| 13 |
.vphantom{display: inline-block; visibility: hidden; width: 0} |
| 14 |
.smash{display: inline-block; height: 0; line-height: 0} |
| 15 |
.li-itemize{margin:1ex 0ex;} |
| 16 |
.li-enumerate{margin:1ex 0ex;} |
| 17 |
.dd-description{margin:0ex 0ex 1ex 4ex;} |
| 18 |
.dt-description{margin:0ex;} |
| 19 |
.toc{list-style:none;} |
| 20 |
.footnotetext{margin:0ex; padding:0ex;} |
| 21 |
div.footnotetext P{margin:0px; text-indent:1em;} |
| 22 |
.thefootnotes{text-align:left;margin:0ex;} |
| 23 |
.dt-thefootnotes{margin:0em;} |
| 24 |
.dd-thefootnotes{margin:0em 0em 0em 2em;} |
| 25 |
.footnoterule{background-color: black; border: none; height: 1px; margin: 1em auto 1em 0px; width: 40%} |
| 26 |
.caption{padding-left:2ex; padding-right:2ex; margin-left:auto; margin-right:auto} |
| 27 |
.title{margin:2ex auto;text-align:center} |
| 28 |
.titlemain{margin:1ex 2ex 2ex 1ex;} |
| 29 |
.titlerest{margin:0ex 2ex;} |
| 30 |
.center{text-align:center;margin-left:auto;margin-right:auto;} |
| 31 |
.flushleft{text-align:left;margin-left:0ex;margin-right:auto;} |
| 32 |
.flushright{text-align:right;margin-left:auto;margin-right:0ex;} |
| 33 |
div table{margin-left:inherit;margin-right:inherit;margin-bottom:2px;margin-top:2px} |
| 34 |
td table{margin:auto;} |
| 35 |
table{border-collapse:collapse;} |
| 36 |
td{padding:0;} |
| 37 |
.cellpadding0 tr td{padding:0;} |
| 38 |
.cellpadding1 tr td{padding:1px;} |
| 39 |
pre{text-align:left;margin-left:0ex;margin-right:auto;} |
| 40 |
blockquote{margin-left:4ex;margin-right:4ex;text-align:left;} |
| 41 |
td p{margin:0px;} |
| 42 |
.quote{margin-left:3em;margin-right:3em;text-align:inherit;text-indent:0pt} |
| 43 |
.quotation{margin-left:3em;margin-right:3em;text-align:inherit;text-indent:1.5em} |
| 44 |
.verse{margin-left:3em;margin-right:3em;text-indent:1.5em hanging each-line} |
| 45 |
.parbox{box-sizing: border-box; |
| 46 |
display: inline-block; |
| 47 |
text-indent: 0; |
| 48 |
} |
| 49 |
.rule-rect{fill: black;} |
| 50 |
.lrbox{box-sizing:border-box;display:inline-block;overflow:visible;white-space:nowrap;} |
| 51 |
.center-lrbox{display:inline-block;margin-left:50%;transform:translateX(-50%);} |
| 52 |
.makebox{} |
| 53 |
.framebox{border:1px solid black;padding:0.25em;} |
| 54 |
.vertical-rule{border:none;width:2px;background-color:black;} |
| 55 |
.horizontal-rule{border:none;background-color:black;} |
| 56 |
.hrule{border:none;height:2px;width:100%;background-color:black;} |
| 57 |
.hfill{border:none;height:1px;width:200%;background-color:black;} |
| 58 |
.vdisplay{border-collapse:separate;border-spacing:2px;line-height:1.1;width:auto; empty-cells:show; border:2px solid red;} |
| 59 |
.vdcell{white-space:nowrap;padding:0px; border:2px solid green;} |
| 60 |
.display{border-collapse:separate;border-spacing:2px;line-height:1.1;width:auto; border:none;} |
| 61 |
.dcell{white-space:nowrap;padding:0px; border:none;} |
| 62 |
.dcenter{margin:0ex auto;} |
| 63 |
.vdcenter{border:solid #FF8000 2px; margin:0ex auto;} |
| 64 |
.minipage{text-align:left; margin-left:0em; margin-right:auto;} |
| 65 |
.marginpar{border:solid thin black; margin-bottom:1ex; width:20%; text-align:left;} |
| 66 |
.marginparleft{float:left; clear:left; margin-left:0ex; margin-right:1ex;} |
| 67 |
.marginparright{float:right; clear:right; margin-left:1ex; margin-right:0ex;} |
| 68 |
.theorem{text-align:left;margin:1ex auto 1ex 0ex;} |
| 69 |
.part{margin:2ex auto;text-align:center} |
| 70 |
</style> |
| 71 |
<title>`headache` |
| 72 |
</title> |
| 73 |
</head> |
| 74 |
<body > |
| 75 |
<!--HEVEA command line is: hevea -o manual.html manual.tex --> |
| 76 |
<!--CUT STYLE article--><!--CUT DEF section 1 --><table class="title"><tr><td style="padding:1ex"><h1 class="titlemain">‘<span style="font-family:monospace">headache</span>‘</h1><h3 class="titlerest">Vincent Simonet</h3><h3 class="titlerest">November, 2002</h3></td></tr> |
| 77 |
</table><p>This manual is also available in <a href="manual.txt">plain text</a>, |
| 78 |
<a href="manual.ps.gz">PostScript</a> and <a href="manual.pdf">PDF</a>.</p> |
| 79 |
<!--TOC section id="sec1" Overview--> |
| 80 |
<h2 id="sec1" class="section">1 Overview</h2><!--SEC END --><p>It is a common usage to put at the beginning of source code files a |
| 81 |
short header giving, for instance, some copyright informations. |
| 82 |
‘<span style="font-family:monospace">headache</span>‘ is a simple and lightweight tool for managing easily these |
| 83 |
headers. Among its functionalities, one may mention: |
| 84 |
</p><ul class="itemize"><li class="li-itemize">Headers must generally be generated as <em>comments</em> in source |
| 85 |
code files. ‘<span style="font-family:monospace">headache</span>‘ deals with different file types and generates |
| 86 |
for each of them headers in an appropriate format. |
| 87 |
</li><li class="li-itemize">‘<span style="font-family:monospace">headache</span>‘ automatically detects existing headers and removes them. |
| 88 |
Thus, you can use it to update headers in a set of files. |
| 89 |
</li></ul><p>‘<span style="font-family:monospace">headache</span>‘ is distributed under the terms of the <em>GNU Library General |
| 90 |
Public License</em>. See file ‘<span style="font-family:monospace">LICENSE</span>‘ of the distribution for |
| 91 |
more information.</p> |
| 92 |
<!--TOC section id="sec2" Compilation and installation--> |
| 93 |
<h2 id="sec2" class="section">2 Compilation and installation</h2><!--SEC END --><p>Building ‘<span style="font-family:monospace">headache</span>‘ requires <em>Objective Caml</em> (available at |
| 94 |
<span style="font-family:monospace">http://caml.inria.fr/</span>) and <em>GNU Make</em>. |
| 95 |
In addition, from version <span style="font-family:monospace">1.03-utf8</span>, the build requires the Unicode library <em>Camomile</em> and, from version <span style="font-family:monospace">1.04</span>, <em>Dune</em>.</p> |
| 96 |
<!--TOC paragraph id="sec3" Instructions--> |
| 97 |
<h4 id="sec3" class="paragraph">Instructions</h4><!--SEC END --><p>‘<span style="font-family:monospace">headache</span>‘ is available through <em>OPAM</em> (available at |
| 98 |
<span style="font-family:monospace">http://opam.ocaml.org/</span>), the <em>OCaml Package Manager</em>. |
| 99 |
This is the preferred installation method. |
| 100 |
Then the following sequence of commands should install the package: |
| 101 |
</p><pre> |
| 102 |
opam init |
| 103 |
opam install headache |
| 104 |
</pre><p>Alternatively, you can use these commands (<em>Dune</em> must be installed):</p><pre> |
| 105 |
make && sudo make INSTALLDIR=/usr/local/bin install |
| 106 |
</pre><p> |
| 107 |
Build the executable and install it into the specified directory.</p> |
| 108 |
<!--TOC section id="sec4" Usage--> |
| 109 |
<h2 id="sec4" class="section">3 Usage</h2><!--SEC END --><p>Let us illustrate the use of this tool with a small example. Assume |
| 110 |
you have a small project mixing C and Caml code consisting in three |
| 111 |
files ‘<span style="font-family:monospace">foo.c</span>‘, ‘<span style="font-family:monospace">bar.ml</span>‘ and ‘<span style="font-family:monospace">bar.mli</span>‘, and you want to |
| 112 |
equip them with some header. First of all, write a <em>header |
| 113 |
file</em>, i.e. a plain text file including the information headers |
| 114 |
must mention. An example of such a file is given in |
| 115 |
figure <a href="#figure%3Aheader">1</a>. In the following, we assume this file is |
| 116 |
named ‘<span style="font-family:monospace">myheader</span>‘ and is in the same directory as source files.</p><p>Then, in order to generate headers, just run the command: |
| 117 |
</p><pre> |
| 118 |
headache -h myheader foo.c bar.ml bar.mli |
| 119 |
</pre><p> |
| 120 |
Each file is equipped with a header including the text given in the |
| 121 |
header file ‘<span style="font-family:monospace">myheader</span>‘, surrounded by some extra characters |
| 122 |
depending on its format making it a comment (e.g. ‘<span style="font-family:monospace">(*</span>‘ and |
| 123 |
‘<span style="font-family:monospace">*)</span>‘ in ‘<span style="font-family:monospace">.ml</span>‘ files). If you update informations in the |
| 124 |
header file ‘<span style="font-family:monospace">myheader</span>‘, you simply need to re-run the above |
| 125 |
command to update headers in source code files: existing ones are |
| 126 |
automatically removed.</p><p>Similarly, running: |
| 127 |
</p><pre> |
| 128 |
headache -r foo.c bar.ml bar.mli |
| 129 |
</pre><p> |
| 130 |
removes any existing in files ‘<span style="font-family:monospace">foo.c</span>‘, ‘<span style="font-family:monospace">bar.ml</span>‘ and |
| 131 |
‘<span style="font-family:monospace">bar.mli</span>‘. Files which do not have a header are kept unchanged.</p><p>The current headers of files can be extracted: |
| 132 |
</p><pre> |
| 133 |
headache -e foo.c bar.ml bar.mli |
| 134 |
</pre><p> |
| 135 |
prints on the standard output the current headers of the files ‘<span style="font-family:monospace">foo.c</span>‘, |
| 136 |
‘<span style="font-family:monospace">bar.ml</span>‘ and ‘<span style="font-family:monospace">bar.mli</span>‘. All files are kept unchanged.</p><blockquote class="figure"><div class="center"><hr class="floatrule"></div> |
| 137 |
<table style="border:1px;border-spacing:0" class="cellpadding1"><tr><td style="text-align:left"><pre class="verbatim"> |
| 138 |
Headache |
| 139 |
Automatic generation of files headers |
| 140 |
|
| 141 |
Vincent Simonet, Projet Cristal, INRIA Rocquencourt |
| 142 |
|
| 143 |
Copyright 2002 |
| 144 |
Institut National de Recherche en Informatique et en Automatique. |
| 145 |
All rights reserved. This file is distributed under the terms of |
| 146 |
the GNU Library General Public License. |
| 147 |
|
| 148 |
[email protected] http://cristal.inria.fr/~simonet/ |
| 149 |
</pre></td></tr> |
| 150 |
</table> |
| 151 |
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 1: An example of header file</td></tr> |
| 152 |
</table></div> |
| 153 |
<a id="figure:header"></a> |
| 154 |
<div class="center"><hr class="floatrule"></div></blockquote> |
| 155 |
<!--TOC section id="sec5" Configuration file--> |
| 156 |
<h2 id="sec5" class="section">4 Configuration file</h2><!--SEC END --><p>File types and format of header may be specified by a |
| 157 |
<em>configuration file</em>. By default, the default builtin |
| 158 |
configuration file given in figure <a href="#figure%3Aconfig">2</a> is used. You |
| 159 |
can also use your own configuration file thanks to the ‘<span style="font-family:monospace">-c</span>‘ |
| 160 |
option: |
| 161 |
</p><pre> |
| 162 |
headache -c myconfig -h myheader foo.c bar.ml bar.mli |
| 163 |
</pre><p>In order to write your own configuration, you can follow the example |
| 164 |
given in figure <a href="#figure%3Aconfig">2</a>. A configuration file consists in |
| 165 |
a list of <em>entries</em> separated by the character ‘<span style="font-family:monospace">|</span>‘. Each |
| 166 |
of them is made of two parts separated by an ‘<span style="font-family:monospace">-></span>‘: |
| 167 |
</p><ul class="itemize"><li class="li-itemize">The first one is a <em>regular expression</em>. Regular |
| 168 |
expression are enclosed within double quotes and have the same |
| 169 |
syntax as in Gnu Emacs. ‘<span style="font-family:monospace">headache</span>‘ determines file types according to |
| 170 |
file basenames; thus, each file is dealt with using the first line |
| 171 |
its name matches. |
| 172 |
</li><li class="li-itemize">The second one describes the format of headers for files of this |
| 173 |
type. It consists of the name of a <em>model</em> (e.g. |
| 174 |
‘<span style="font-family:monospace">frame</span>‘), possibly followed by a list of arguments. Arguments |
| 175 |
are named: ‘<span style="font-family:monospace">open:"(*"</span>‘ means that the value of the argument |
| 176 |
‘<span style="font-family:monospace">open</span>‘ is ‘<span style="font-family:monospace">(*</span>‘. |
| 177 |
</li></ul><p> |
| 178 |
‘<span style="font-family:monospace">headache</span>‘ currently supports three <em>models</em>: |
| 179 |
</p><ul class="itemize"><li class="li-itemize">‘<span style="font-family:monospace">frame</span>‘. With this model, headers are generated in a |
| 180 |
frame. This model requires three arguments: ‘<span style="font-family:monospace">open</span>‘ and |
| 181 |
‘<span style="font-family:monospace">close</span>‘ (the opening and closing sequences for comments) and |
| 182 |
‘<span style="font-family:monospace">line</span>‘ (the character used to make the horizontal lines of the |
| 183 |
frame). Two optional arguments may be used: ‘<span style="font-family:monospace">margin</span>‘ (a string |
| 184 |
printed between the left and right side of the frame and the border, |
| 185 |
by default two spaces) and ‘<span style="font-family:monospace">width</span>‘ (the width of the inside of |
| 186 |
the frame, default is 68). |
| 187 |
</li><li class="li-itemize">‘<span style="font-family:monospace">lines</span>‘. Headers are typeset between two lines. Three |
| 188 |
arguments must be provided: ‘<span style="font-family:monospace">open</span>‘ and ‘<span style="font-family:monospace">close</span>‘ (the |
| 189 |
opening and closing sequences for comments), ‘<span style="font-family:monospace">line</span>‘ (the |
| 190 |
character used to make the horizontal lines). Three optional |
| 191 |
arguments are allowed: ‘<span style="font-family:monospace">begin</span>‘ (a string typeset at the |
| 192 |
beginning of each line, by default two spaces), ‘<span style="font-family:monospace">last</span>‘ (a |
| 193 |
string typeset at the beginning of the last line) and ‘<span style="font-family:monospace">width</span>‘ |
| 194 |
(the width of the lines, default is 70). |
| 195 |
</li><li class="li-itemize">‘<span style="font-family:monospace">no</span>‘. This model generates no header and has no argument. |
| 196 |
</li></ul><p>It is possible to change the default builtin configuration file at |
| 197 |
compile time. For this, just edit the file ‘<span style="font-family:monospace">config_builtin.txt</span>‘ |
| 198 |
present in the source distribution before building the software.</p><blockquote class="figure"><div class="center"><hr class="floatrule"></div> |
| 199 |
<table style="border:1px;border-spacing:0" class="cellpadding1"><tr><td style="text-align:left"><pre class="verbatim"> |
| 200 |
# Objective Caml source |
| 201 |
".*\\.ml[il]?" -> frame open:"(*" line:"*" close:"*)" |
| 202 |
| ".*\\.fml[i]?" -> frame open:"(*" line:"*" close:"*)" |
| 203 |
| ".*\\.mly" -> frame open:"/*" line:"*" close:"*/" |
| 204 |
# C source |
| 205 |
| ".*\\.[chy]" -> frame open:"/*" line:"*" close:"*/" |
| 206 |
# Latex |
| 207 |
| ".*\\.tex" -> frame open:"%" line:"%" close:"%" |
| 208 |
# Misc |
| 209 |
| ".*Makefile.*" -> frame open:"#" line:"#" close:"#" |
| 210 |
| ".*README.*" -> frame open:"*" line:"*" close:"*" |
| 211 |
| ".*LICENSE.*" -> frame open:"*" line:"*" close:"*" |
| 212 |
</pre></td></tr> |
| 213 |
</table> |
| 214 |
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 2: The default builtin configuration file</td></tr> |
| 215 |
</table></div> |
| 216 |
<a id="figure:config"></a> |
| 217 |
<div class="center"><hr class="floatrule"></div></blockquote><p>It is also possible to add entries into your own configuration file that |
| 218 |
specify when the initial lines of the processed file have to be skipped. |
| 219 |
As previously, these <em>entries</em> are separated by the character ‘<span style="font-family:monospace">|</span>‘ |
| 220 |
and each of them is made of two parts separated by an ‘<span style="font-family:monospace">-></span>‘: |
| 221 |
</p><ul class="itemize"><li class="li-itemize">Again, the first part is a <em>regular expression</em> used by ‘<span style="font-family:monospace">headache</span>‘ |
| 222 |
to determine the file type. But here, it is according to |
| 223 |
its full filename (including the pathname). |
| 224 |
</li><li class="li-itemize">The second part specifies when the initial lines must be skipped. |
| 225 |
It consists of the keyword ‘<span style="font-family:monospace">skip</span>‘ followed by one of the named |
| 226 |
arguments ‘<span style="font-family:monospace">multiline_match:</span>‘ or ‘<span style="font-family:monospace">match:</span>‘, then a <em>regular expression</em>. |
| 227 |
As long as the lines match a ‘<span style="font-family:monospace">multiline_match</span>‘ parameter, |
| 228 |
‘<span style="font-family:monospace">headache</span>‘ skips them and checks the next line. |
| 229 |
If the current line matches only a ‘<span style="font-family:monospace">match</span>‘ parameter, |
| 230 |
‘<span style="font-family:monospace">headache</span>‘ skips the current line and breaks the iteration there (of course, |
| 231 |
if nothing matches, ‘<span style="font-family:monospace">headache</span>‘ puts the header before the current line).</li></ul><blockquote class="figure"><div class="center"><hr class="floatrule"></div> |
| 232 |
<table style="border:1px;border-spacing:0" class="cellpadding1"><tr><td style="text-align:left"><pre class="verbatim"># Script file |
| 233 |
| ".*\\.sh" -> frame open:"#" line:"#" close:"#" |
| 234 |
| ".*\\.sh" -> skip match:"#!.*" |
| 235 |
</pre></td></tr> |
| 236 |
</table> |
| 237 |
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 3: Example of a configuration file for skipping the shebang line of shell scripts</td></tr> |
| 238 |
</table></div> |
| 239 |
<a id="figure:example"></a> |
| 240 |
<div class="center"><hr class="floatrule"></div></blockquote><p>Figure <a href="#figure%3Aexample">3</a> shows an example of configuration file |
| 241 |
that can used to skip the shebang line of shell scripts: |
| 242 |
when the first line of ‘<span style="font-family:monospace">.sh</span>‘ files starts with ‘<span style="font-family:monospace">#!</span>‘, |
| 243 |
‘<span style="font-family:monospace">headache</span>‘ does not modify that line and considers that the header must |
| 244 |
start at the second line.</p><blockquote class="figure"><div class="center"><hr class="floatrule"></div> |
| 245 |
<table style="border:1px;border-spacing:0" class="cellpadding1"><tr><td style="text-align:left"><pre class="verbatim"># SWI Prolog file |
| 246 |
| ".*\\.pl" -> frame open:"%" line:"%" close:"%" |
| 247 |
| ".*\\.pl" -> skip multiline_match:"#!.*" multiline_match:":-.*" |
| 248 |
</pre></td></tr> |
| 249 |
</table> |
| 250 |
<div class="caption"><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" >Figure 4: Example of a configuration file for skipping the shebang line, |
| 251 |
as well as lines containing Prolog directives, such as Unicode usage.</td></tr> |
| 252 |
</table></div> |
| 253 |
<a id="figure:python-example"></a> |
| 254 |
<div class="center"><hr class="floatrule"></div></blockquote><p>Figure <a href="#figure%3Apython-example">4</a> shows an example of configuration file |
| 255 |
that can used for ‘<span style="font-family:monospace">SWI prolog</span>‘ files: |
| 256 |
for a ‘<span style="font-family:monospace">.pl</span>‘ file starting with the following three first lines, |
| 257 |
‘<span style="font-family:monospace">headache</span>‘ considers that the header must start just after the first two lines: |
| 258 |
</p><pre> |
| 259 |
#!/usr/bin/env swipl |
| 260 |
:- encoding(utf8). |
| 261 |
% remainder of the file, that can be after the header |
| 262 |
</pre><!--CUT END --> |
| 263 |
<!--HTMLFOOT--> |
| 264 |
<!--ENDHTML--> |
| 265 |
<!--FOOTER--> |
| 266 |
<hr class="horizontal-rule" style="height:2px"><blockquote class="quote"><em>This document was translated from L<sup>A</sup>T<sub>E</sub>X by |
| 267 |
</em><a href="http://hevea.inria.fr/index.html"><em>H</em><em><span style="font-size:small"><sup>E</sup></span></em><em>V</em><em><span style="font-size:small"><sup>E</sup></span></em><em>A</em></a><em>.</em></blockquote></body> |
| 268 |
</html> |