blob: b67d5a2bf9a3dff44c2578450e2a977b6e3c4bd3 [file] [log] [blame]
Junio C Hamano3dac5042007-12-15 08:40:541<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
Junio C Hamano9d971152012-12-19 00:43:115<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
6<meta name="generator" content="AsciiDoc 8.6.8" />
Junio C Hamano97bcb482010-11-25 03:16:077<title>parse-options API</title>
Junio C Hamano3dac5042007-12-15 08:40:548<style type="text/css">
Junio C Hamano9d971152012-12-19 00:43:119/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
10
11/* Default font. */
12body {
13 font-family: Georgia,serif;
14}
15
16/* Title font. */
17h1, h2, h3, h4, h5, h6,
18div.title, caption.title,
19thead, p.table.header,
20#toctitle,
21#author, #revnumber, #revdate, #revremark,
22#footer {
23 font-family: Arial,Helvetica,sans-serif;
Junio C Hamano3dac5042007-12-15 08:40:5424}
25
26body {
27 margin: 1em 5% 1em 5%;
28}
29
Junio C Hamano4604fe52008-09-19 06:37:1030a {
31 color: blue;
32 text-decoration: underline;
33}
34a:visited {
35 color: fuchsia;
36}
Junio C Hamano3dac5042007-12-15 08:40:5437
38em {
39 font-style: italic;
Junio C Hamano97bcb482010-11-25 03:16:0740 color: navy;
Junio C Hamano3dac5042007-12-15 08:40:5441}
42
43strong {
44 font-weight: bold;
Junio C Hamano97bcb482010-11-25 03:16:0745 color: #083194;
Junio C Hamano3dac5042007-12-15 08:40:5446}
47
Junio C Hamano3dac5042007-12-15 08:40:5448h1, h2, h3, h4, h5, h6 {
49 color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:5450 margin-top: 1.2em;
51 margin-bottom: 0.5em;
52 line-height: 1.3;
53}
54
Junio C Hamano4604fe52008-09-19 06:37:1055h1, h2, h3 {
Junio C Hamano3dac5042007-12-15 08:40:5456 border-bottom: 2px solid silver;
57}
58h2 {
Junio C Hamano3dac5042007-12-15 08:40:5459 padding-top: 0.5em;
60}
Junio C Hamano4604fe52008-09-19 06:37:1061h3 {
62 float: left;
63}
64h3 + * {
65 clear: left;
66}
Junio C Hamano9d971152012-12-19 00:43:1167h5 {
68 font-size: 1.0em;
69}
Junio C Hamano3dac5042007-12-15 08:40:5470
71div.sectionbody {
Junio C Hamano3dac5042007-12-15 08:40:5472 margin-left: 0;
73}
74
75hr {
76 border: 1px solid silver;
77}
78
79p {
80 margin-top: 0.5em;
81 margin-bottom: 0.5em;
82}
83
Junio C Hamano97bcb482010-11-25 03:16:0784ul, ol, li > p {
85 margin-top: 0;
86}
Junio C Hamano9d971152012-12-19 00:43:1187ul > li { color: #aaa; }
88ul > li > * { color: black; }
Junio C Hamano97bcb482010-11-25 03:16:0789
Junio C Hamano9d971152012-12-19 00:43:1190.monospaced, code, pre {
91 font-family: "Courier New", Courier, monospace;
92 font-size: inherit;
93 color: navy;
Junio C Hamano3dac5042007-12-15 08:40:5494 padding: 0;
95 margin: 0;
96}
97
Junio C Hamano9d971152012-12-19 00:43:1198
99#author {
Junio C Hamano3dac5042007-12-15 08:40:54100 color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:54101 font-weight: bold;
Junio C Hamano4604fe52008-09-19 06:37:10102 font-size: 1.1em;
Junio C Hamano3dac5042007-12-15 08:40:54103}
Junio C Hamano9d971152012-12-19 00:43:11104#email {
Junio C Hamano3dac5042007-12-15 08:40:54105}
Junio C Hamano9d971152012-12-19 00:43:11106#revnumber, #revdate, #revremark {
Junio C Hamano3dac5042007-12-15 08:40:54107}
108
Junio C Hamano9d971152012-12-19 00:43:11109#footer {
Junio C Hamano3dac5042007-12-15 08:40:54110 font-size: small;
111 border-top: 2px solid silver;
112 padding-top: 0.5em;
113 margin-top: 4.0em;
114}
Junio C Hamano9d971152012-12-19 00:43:11115#footer-text {
Junio C Hamano3dac5042007-12-15 08:40:54116 float: left;
117 padding-bottom: 0.5em;
118}
Junio C Hamano9d971152012-12-19 00:43:11119#footer-badges {
Junio C Hamano3dac5042007-12-15 08:40:54120 float: right;
121 padding-bottom: 0.5em;
122}
123
Junio C Hamano9d971152012-12-19 00:43:11124#preamble {
Junio C Hamano97bcb482010-11-25 03:16:07125 margin-top: 1.5em;
126 margin-bottom: 1.5em;
127}
Junio C Hamano9d971152012-12-19 00:43:11128div.imageblock, div.exampleblock, div.verseblock,
Junio C Hamano3dac5042007-12-15 08:40:54129div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
130div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22131 margin-top: 1.0em;
Junio C Hamano3dac5042007-12-15 08:40:54132 margin-bottom: 1.5em;
133}
134div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22135 margin-top: 2.0em;
136 margin-bottom: 2.0em;
137 margin-right: 10%;
138 color: #606060;
Junio C Hamano3dac5042007-12-15 08:40:54139}
140
141div.content { /* Block element content. */
142 padding: 0;
143}
144
145/* Block element titles. */
146div.title, caption.title {
Junio C Hamano97bcb482010-11-25 03:16:07147 color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:54148 font-weight: bold;
149 text-align: left;
150 margin-top: 1.0em;
151 margin-bottom: 0.5em;
152}
153div.title + * {
154 margin-top: 0;
155}
156
157td div.title:first-child {
158 margin-top: 0.0em;
159}
160div.content div.title:first-child {
161 margin-top: 0.0em;
162}
163div.content + div.title {
164 margin-top: 0.0em;
165}
166
167div.sidebarblock > div.content {
168 background: #ffffee;
Junio C Hamano9d971152012-12-19 00:43:11169 border: 1px solid #dddddd;
170 border-left: 4px solid #f0f0f0;
Junio C Hamano3dac5042007-12-15 08:40:54171 padding: 0.5em;
172}
173
174div.listingblock > div.content {
Junio C Hamano9d971152012-12-19 00:43:11175 border: 1px solid #dddddd;
176 border-left: 5px solid #f0f0f0;
177 background: #f8f8f8;
Junio C Hamano3dac5042007-12-15 08:40:54178 padding: 0.5em;
179}
180
Junio C Hamano7bd050f2011-09-22 06:32:22181div.quoteblock, div.verseblock {
182 padding-left: 1.0em;
183 margin-left: 1.0em;
Junio C Hamano97bcb482010-11-25 03:16:07184 margin-right: 10%;
Junio C Hamano9d971152012-12-19 00:43:11185 border-left: 5px solid #f0f0f0;
186 color: #888;
Junio C Hamano3dac5042007-12-15 08:40:54187}
Junio C Hamano7bd050f2011-09-22 06:32:22188
Junio C Hamano97bcb482010-11-25 03:16:07189div.quoteblock > div.attribution {
190 padding-top: 0.5em;
Junio C Hamano3dac5042007-12-15 08:40:54191 text-align: right;
192}
Junio C Hamano97bcb482010-11-25 03:16:07193
Junio C Hamano9d971152012-12-19 00:43:11194div.verseblock > pre.content {
195 font-family: inherit;
196 font-size: inherit;
Junio C Hamano97bcb482010-11-25 03:16:07197}
198div.verseblock > div.attribution {
199 padding-top: 0.75em;
200 text-align: left;
201}
202/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
Junio C Hamano4604fe52008-09-19 06:37:10203div.verseblock + div.attribution {
204 text-align: left;
205}
Junio C Hamano3dac5042007-12-15 08:40:54206
207div.admonitionblock .icon {
208 vertical-align: top;
209 font-size: 1.1em;
210 font-weight: bold;
211 text-decoration: underline;
212 color: #527bbd;
213 padding-right: 0.5em;
214}
215div.admonitionblock td.content {
216 padding-left: 0.5em;
Junio C Hamano7bd050f2011-09-22 06:32:22217 border-left: 3px solid #dddddd;
Junio C Hamano3dac5042007-12-15 08:40:54218}
219
220div.exampleblock > div.content {
Junio C Hamano7bd050f2011-09-22 06:32:22221 border-left: 3px solid #dddddd;
222 padding-left: 0.5em;
Junio C Hamano3dac5042007-12-15 08:40:54223}
224
Junio C Hamano3dac5042007-12-15 08:40:54225div.imageblock div.content { padding-left: 0; }
Junio C Hamano3dac5042007-12-15 08:40:54226span.image img { border-style: none; }
Junio C Hamano97bcb482010-11-25 03:16:07227a.image:visited { color: white; }
Junio C Hamano3dac5042007-12-15 08:40:54228
229dl {
230 margin-top: 0.8em;
231 margin-bottom: 0.8em;
232}
233dt {
234 margin-top: 0.5em;
235 margin-bottom: 0;
Junio C Hamano97bcb482010-11-25 03:16:07236 font-style: normal;
237 color: navy;
Junio C Hamano3dac5042007-12-15 08:40:54238}
239dd > *:first-child {
Junio C Hamano97bcb482010-11-25 03:16:07240 margin-top: 0.1em;
Junio C Hamano3dac5042007-12-15 08:40:54241}
242
243ul, ol {
244 list-style-position: outside;
245}
Junio C Hamano97bcb482010-11-25 03:16:07246ol.arabic {
247 list-style-type: decimal;
248}
249ol.loweralpha {
Junio C Hamano3dac5042007-12-15 08:40:54250 list-style-type: lower-alpha;
251}
Junio C Hamano97bcb482010-11-25 03:16:07252ol.upperalpha {
253 list-style-type: upper-alpha;
254}
255ol.lowerroman {
256 list-style-type: lower-roman;
257}
258ol.upperroman {
259 list-style-type: upper-roman;
260}
261
262div.compact ul, div.compact ol,
263div.compact p, div.compact p,
264div.compact div, div.compact div {
265 margin-top: 0.1em;
266 margin-bottom: 0.1em;
267}
Junio C Hamano3dac5042007-12-15 08:40:54268
Junio C Hamano3dac5042007-12-15 08:40:54269tfoot {
270 font-weight: bold;
271}
Junio C Hamano97bcb482010-11-25 03:16:07272td > div.verse {
273 white-space: pre;
274}
Junio C Hamano97bcb482010-11-25 03:16:07275
276div.hdlist {
Junio C Hamano3dac5042007-12-15 08:40:54277 margin-top: 0.8em;
278 margin-bottom: 0.8em;
279}
Junio C Hamano97bcb482010-11-25 03:16:07280div.hdlist tr {
281 padding-bottom: 15px;
Junio C Hamano4604fe52008-09-19 06:37:10282}
Junio C Hamano97bcb482010-11-25 03:16:07283dt.hdlist1.strong, td.hdlist1.strong {
284 font-weight: bold;
285}
286td.hdlist1 {
Junio C Hamano3dac5042007-12-15 08:40:54287 vertical-align: top;
Junio C Hamano97bcb482010-11-25 03:16:07288 font-style: normal;
Junio C Hamano3dac5042007-12-15 08:40:54289 padding-right: 0.8em;
Junio C Hamano97bcb482010-11-25 03:16:07290 color: navy;
Junio C Hamano3dac5042007-12-15 08:40:54291}
Junio C Hamano97bcb482010-11-25 03:16:07292td.hdlist2 {
Junio C Hamano3dac5042007-12-15 08:40:54293 vertical-align: top;
294}
Junio C Hamano97bcb482010-11-25 03:16:07295div.hdlist.compact tr {
296 margin: 0;
297 padding-bottom: 0;
298}
299
300.comment {
301 background: yellow;
302}
Junio C Hamano3dac5042007-12-15 08:40:54303
Junio C Hamano7bd050f2011-09-22 06:32:22304.footnote, .footnoteref {
305 font-size: 0.8em;
306}
307
308span.footnote, span.footnoteref {
309 vertical-align: super;
310}
311
312#footnotes {
313 margin: 20px 0 20px 0;
314 padding: 7px 0 0 0;
315}
316
317#footnotes div.footnote {
318 margin: 0 0 5px 0;
319}
320
321#footnotes hr {
322 border: none;
323 border-top: 1px solid silver;
324 height: 1px;
325 text-align: left;
326 margin-left: 0;
327 width: 20%;
328 min-width: 100px;
329}
330
Junio C Hamano9d971152012-12-19 00:43:11331div.colist td {
332 padding-right: 0.5em;
333 padding-bottom: 0.3em;
334 vertical-align: top;
335}
336div.colist td img {
337 margin-top: 0.3em;
Junio C Hamano3dac5042007-12-15 08:40:54338}
Junio C Hamano4604fe52008-09-19 06:37:10339
Junio C Hamano9d971152012-12-19 00:43:11340@media print {
341 #footer-badges { display: none; }
342}
343
344#toc {
Junio C Hamano7bd050f2011-09-22 06:32:22345 margin-bottom: 2.5em;
346}
347
Junio C Hamano9d971152012-12-19 00:43:11348#toctitle {
Junio C Hamano4604fe52008-09-19 06:37:10349 color: #527bbd;
Junio C Hamano4604fe52008-09-19 06:37:10350 font-size: 1.1em;
351 font-weight: bold;
352 margin-top: 1.0em;
353 margin-bottom: 0.1em;
354}
355
Junio C Hamano9d971152012-12-19 00:43:11356div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
Junio C Hamano4604fe52008-09-19 06:37:10357 margin-top: 0;
358 margin-bottom: 0;
359}
360div.toclevel2 {
361 margin-left: 2em;
362 font-size: 0.9em;
363}
364div.toclevel3 {
365 margin-left: 4em;
366 font-size: 0.9em;
367}
368div.toclevel4 {
369 margin-left: 6em;
370 font-size: 0.9em;
371}
Junio C Hamano3dac5042007-12-15 08:40:54372
Junio C Hamano9d971152012-12-19 00:43:11373span.aqua { color: aqua; }
374span.black { color: black; }
375span.blue { color: blue; }
376span.fuchsia { color: fuchsia; }
377span.gray { color: gray; }
378span.green { color: green; }
379span.lime { color: lime; }
380span.maroon { color: maroon; }
381span.navy { color: navy; }
382span.olive { color: olive; }
383span.purple { color: purple; }
384span.red { color: red; }
385span.silver { color: silver; }
386span.teal { color: teal; }
387span.white { color: white; }
388span.yellow { color: yellow; }
389
390span.aqua-background { background: aqua; }
391span.black-background { background: black; }
392span.blue-background { background: blue; }
393span.fuchsia-background { background: fuchsia; }
394span.gray-background { background: gray; }
395span.green-background { background: green; }
396span.lime-background { background: lime; }
397span.maroon-background { background: maroon; }
398span.navy-background { background: navy; }
399span.olive-background { background: olive; }
400span.purple-background { background: purple; }
401span.red-background { background: red; }
402span.silver-background { background: silver; }
403span.teal-background { background: teal; }
404span.white-background { background: white; }
405span.yellow-background { background: yellow; }
406
407span.big { font-size: 2em; }
408span.small { font-size: 0.6em; }
409
410span.underline { text-decoration: underline; }
411span.overline { text-decoration: overline; }
412span.line-through { text-decoration: line-through; }
413
414div.unbreakable { page-break-inside: avoid; }
415
416
417/*
418 * xhtml11 specific
419 *
420 * */
421
422div.tableblock {
423 margin-top: 1.0em;
424 margin-bottom: 1.5em;
Junio C Hamano3dac5042007-12-15 08:40:54425}
Junio C Hamano9d971152012-12-19 00:43:11426div.tableblock > table {
427 border: 3px solid #527bbd;
428}
429thead, p.table.header {
Junio C Hamano3dac5042007-12-15 08:40:54430 font-weight: bold;
Junio C Hamano9d971152012-12-19 00:43:11431 color: #527bbd;
432}
433p.table {
434 margin-top: 0;
435}
436/* Because the table frame attribute is overriden by CSS in most browsers. */
437div.tableblock > table[frame="void"] {
438 border-style: none;
439}
440div.tableblock > table[frame="hsides"] {
441 border-left-style: none;
442 border-right-style: none;
443}
444div.tableblock > table[frame="vsides"] {
445 border-top-style: none;
446 border-bottom-style: none;
Junio C Hamano3dac5042007-12-15 08:40:54447}
448
Junio C Hamano9d971152012-12-19 00:43:11449
450/*
451 * html5 specific
452 *
453 * */
454
455table.tableblock {
456 margin-top: 1.0em;
457 margin-bottom: 1.5em;
458}
459thead, p.tableblock.header {
460 font-weight: bold;
461 color: #527bbd;
462}
463p.tableblock {
464 margin-top: 0;
465}
466table.tableblock {
467 border-width: 3px;
468 border-spacing: 0px;
469 border-style: solid;
470 border-color: #527bbd;
471 border-collapse: collapse;
472}
473th.tableblock, td.tableblock {
474 border-width: 1px;
475 padding: 4px;
476 border-style: solid;
477 border-color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:54478}
479
Junio C Hamano9d971152012-12-19 00:43:11480table.tableblock.frame-topbot {
481 border-left-style: hidden;
482 border-right-style: hidden;
483}
484table.tableblock.frame-sides {
485 border-top-style: hidden;
486 border-bottom-style: hidden;
487}
488table.tableblock.frame-none {
489 border-style: hidden;
490}
491
492th.tableblock.halign-left, td.tableblock.halign-left {
493 text-align: left;
494}
495th.tableblock.halign-center, td.tableblock.halign-center {
496 text-align: center;
497}
498th.tableblock.halign-right, td.tableblock.halign-right {
Junio C Hamano97bcb482010-11-25 03:16:07499 text-align: right;
500}
501
Junio C Hamano9d971152012-12-19 00:43:11502th.tableblock.valign-top, td.tableblock.valign-top {
503 vertical-align: top;
Junio C Hamano97bcb482010-11-25 03:16:07504}
Junio C Hamano9d971152012-12-19 00:43:11505th.tableblock.valign-middle, td.tableblock.valign-middle {
506 vertical-align: middle;
507}
508th.tableblock.valign-bottom, td.tableblock.valign-bottom {
509 vertical-align: bottom;
Junio C Hamano3dac5042007-12-15 08:40:54510}
511
Junio C Hamano9d971152012-12-19 00:43:11512
513/*
514 * manpage specific
515 *
516 * */
517
518body.manpage h1 {
519 padding-top: 0.5em;
520 padding-bottom: 0.5em;
521 border-top: 2px solid silver;
522 border-bottom: 2px solid silver;
523}
524body.manpage h2 {
525 border-style: none;
526}
527body.manpage div.sectionbody {
528 margin-left: 3em;
Junio C Hamano3dac5042007-12-15 08:40:54529}
Junio C Hamano4604fe52008-09-19 06:37:10530
Junio C Hamano9d971152012-12-19 00:43:11531@media print {
532 body.manpage div#toc { display: none; }
533}
534
535
Junio C Hamano3dac5042007-12-15 08:40:54536</style>
Junio C Hamano7bd050f2011-09-22 06:32:22537<script type="text/javascript">
538/*<![CDATA[*/
Junio C Hamano7bd050f2011-09-22 06:32:22539var asciidoc = { // Namespace.
540
541/////////////////////////////////////////////////////////////////////
542// Table Of Contents generator
543/////////////////////////////////////////////////////////////////////
544
545/* Author: Mihai Bazon, September 2002
546 * http://students.infoiasi.ro/~mishoo
547 *
548 * Table Of Content generator
549 * Version: 0.4
550 *
551 * Feel free to use this script under the terms of the GNU General Public
552 * License, as long as you do not remove or alter this notice.
553 */
554
555 /* modified by Troy D. Hanson, September 2006. License: GPL */
556 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
557
558// toclevels = 1..4.
559toc: function (toclevels) {
560
561 function getText(el) {
562 var text = "";
563 for (var i = el.firstChild; i != null; i = i.nextSibling) {
564 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
565 text += i.data;
566 else if (i.firstChild != null)
567 text += getText(i);
568 }
569 return text;
570 }
571
572 function TocEntry(el, text, toclevel) {
573 this.element = el;
574 this.text = text;
575 this.toclevel = toclevel;
576 }
577
578 function tocEntries(el, toclevels) {
579 var result = new Array;
Junio C Hamano9d971152012-12-19 00:43:11580 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
Junio C Hamano7bd050f2011-09-22 06:32:22581 // Function that scans the DOM tree for header elements (the DOM2
582 // nodeIterator API would be a better technique but not supported by all
583 // browsers).
584 var iterate = function (el) {
585 for (var i = el.firstChild; i != null; i = i.nextSibling) {
586 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
587 var mo = re.exec(i.tagName);
588 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
589 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
590 }
591 iterate(i);
592 }
593 }
594 }
595 iterate(el);
596 return result;
597 }
598
599 var toc = document.getElementById("toc");
Junio C Hamano9d971152012-12-19 00:43:11600 if (!toc) {
601 return;
602 }
603
604 // Delete existing TOC entries in case we're reloading the TOC.
605 var tocEntriesToRemove = [];
606 var i;
607 for (i = 0; i < toc.childNodes.length; i++) {
608 var entry = toc.childNodes[i];
609 if (entry.nodeName.toLowerCase() == 'div'
610 && entry.getAttribute("class")
611 && entry.getAttribute("class").match(/^toclevel/))
612 tocEntriesToRemove.push(entry);
613 }
614 for (i = 0; i < tocEntriesToRemove.length; i++) {
615 toc.removeChild(tocEntriesToRemove[i]);
616 }
617
618 // Rebuild TOC entries.
Junio C Hamano7bd050f2011-09-22 06:32:22619 var entries = tocEntries(document.getElementById("content"), toclevels);
620 for (var i = 0; i < entries.length; ++i) {
621 var entry = entries[i];
622 if (entry.element.id == "")
623 entry.element.id = "_toc_" + i;
624 var a = document.createElement("a");
625 a.href = "#" + entry.element.id;
626 a.appendChild(document.createTextNode(entry.text));
627 var div = document.createElement("div");
628 div.appendChild(a);
629 div.className = "toclevel" + entry.toclevel;
630 toc.appendChild(div);
631 }
632 if (entries.length == 0)
633 toc.parentNode.removeChild(toc);
634},
635
636
637/////////////////////////////////////////////////////////////////////
638// Footnotes generator
639/////////////////////////////////////////////////////////////////////
640
641/* Based on footnote generation code from:
642 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
643 */
644
645footnotes: function () {
Junio C Hamano9d971152012-12-19 00:43:11646 // Delete existing footnote entries in case we're reloading the footnodes.
647 var i;
Junio C Hamano7bd050f2011-09-22 06:32:22648 var noteholder = document.getElementById("footnotes");
Junio C Hamano9d971152012-12-19 00:43:11649 if (!noteholder) {
650 return;
651 }
652 var entriesToRemove = [];
653 for (i = 0; i < noteholder.childNodes.length; i++) {
654 var entry = noteholder.childNodes[i];
655 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
656 entriesToRemove.push(entry);
657 }
658 for (i = 0; i < entriesToRemove.length; i++) {
659 noteholder.removeChild(entriesToRemove[i]);
660 }
661
662 // Rebuild footnote entries.
663 var cont = document.getElementById("content");
Junio C Hamano7bd050f2011-09-22 06:32:22664 var spans = cont.getElementsByTagName("span");
665 var refs = {};
666 var n = 0;
667 for (i=0; i<spans.length; i++) {
668 if (spans[i].className == "footnote") {
669 n++;
Junio C Hamano9d971152012-12-19 00:43:11670 var note = spans[i].getAttribute("data-note");
671 if (!note) {
672 // Use [\s\S] in place of . so multi-line matches work.
673 // Because JavaScript has no s (dotall) regex flag.
674 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
675 spans[i].innerHTML =
676 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
677 "' title='View footnote' class='footnote'>" + n + "</a>]";
678 spans[i].setAttribute("data-note", note);
679 }
Junio C Hamano7bd050f2011-09-22 06:32:22680 noteholder.innerHTML +=
681 "<div class='footnote' id='_footnote_" + n + "'>" +
682 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
683 n + "</a>. " + note + "</div>";
Junio C Hamano7bd050f2011-09-22 06:32:22684 var id =spans[i].getAttribute("id");
685 if (id != null) refs["#"+id] = n;
686 }
687 }
688 if (n == 0)
689 noteholder.parentNode.removeChild(noteholder);
690 else {
691 // Process footnoterefs.
692 for (i=0; i<spans.length; i++) {
693 if (spans[i].className == "footnoteref") {
694 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
695 href = href.match(/#.*/)[0]; // Because IE return full URL.
696 n = refs[href];
697 spans[i].innerHTML =
698 "[<a href='#_footnote_" + n +
699 "' title='View footnote' class='footnote'>" + n + "</a>]";
700 }
701 }
702 }
Junio C Hamano9d971152012-12-19 00:43:11703},
704
705install: function(toclevels) {
706 var timerId;
707
708 function reinstall() {
709 asciidoc.footnotes();
710 if (toclevels) {
711 asciidoc.toc(toclevels);
712 }
713 }
714
715 function reinstallAndRemoveTimer() {
716 clearInterval(timerId);
717 reinstall();
718 }
719
720 timerId = setInterval(reinstall, 500);
721 if (document.addEventListener)
722 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
723 else
724 window.onload = reinstallAndRemoveTimer;
Junio C Hamano7bd050f2011-09-22 06:32:22725}
726
727}
Junio C Hamano9d971152012-12-19 00:43:11728asciidoc.install();
Junio C Hamano7bd050f2011-09-22 06:32:22729/*]]>*/
730</script>
Junio C Hamano3dac5042007-12-15 08:40:54731</head>
Junio C Hamano9d971152012-12-19 00:43:11732<body class="article">
Junio C Hamano3dac5042007-12-15 08:40:54733<div id="header">
734<h1>parse-options API</h1>
735</div>
Junio C Hamano7bd050f2011-09-22 06:32:22736<div id="content">
Junio C Hamano3dac5042007-12-15 08:40:54737<div id="preamble">
738<div class="sectionbody">
Junio C Hamano076ffcc2013-02-06 05:13:21739<div class="paragraph"><p>The parse-options API is used to parse and massage options in Git
Junio C Hamano4604fe52008-09-19 06:37:10740and to provide a usage help with consistent look.</p></div>
Junio C Hamano3dac5042007-12-15 08:40:54741</div>
742</div>
Junio C Hamano9d971152012-12-19 00:43:11743<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:10744<h2 id="_basics">Basics</h2>
Junio C Hamano4224f992008-06-23 07:14:08745<div class="sectionbody">
Junio C Hamano9d971152012-12-19 00:43:11746<div class="paragraph"><p>The argument vector <code>argv[]</code> may usually contain mandatory or optional
Junio C Hamano4224f992008-06-23 07:14:08747<em>non-option arguments</em>, e.g. a filename or a branch, and <em>options</em>.
748Options are optional arguments that start with a dash and
Junio C Hamano4604fe52008-09-19 06:37:10749that allow to change the behavior of a command.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07750<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08751<li>
752<p>
753There are basically three types of options:
754 <em>boolean</em> options,
755 options with (mandatory) <em>arguments</em> and
756 options with <em>optional arguments</em>
757 (i.e. a boolean option that can be adjusted).
758</p>
759</li>
760<li>
761<p>
762There are basically two forms of options:
Junio C Hamano9d971152012-12-19 00:43:11763 <em>Short options</em> consist of one dash (<code>-</code>) and one alphanumeric
Junio C Hamano4224f992008-06-23 07:14:08764 character.
Junio C Hamano9d971152012-12-19 00:43:11765 <em>Long options</em> begin with two dashes (<code>--</code>) and some
Junio C Hamano4224f992008-06-23 07:14:08766 alphanumeric characters.
767</p>
768</li>
769<li>
770<p>
771Options are case-sensitive.
772 Please define <em>lower-case long options</em> only.
773</p>
774</li>
Junio C Hamano4604fe52008-09-19 06:37:10775</ul></div>
Junio C Hamano97bcb482010-11-25 03:16:07776<div class="paragraph"><p>The parse-options API allows:</p></div>
777<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08778<li>
779<p>
780<em>sticked</em> and <em>separate form</em> of options with arguments.
Junio C Hamano9d971152012-12-19 00:43:11781 <code>-oArg</code> is sticked, <code>-o Arg</code> is separate form.
782 <code>--option=Arg</code> is sticked, <code>--option Arg</code> is separate form.
Junio C Hamano4224f992008-06-23 07:14:08783</p>
784</li>
785<li>
786<p>
787Long options may be <em>abbreviated</em>, as long as the abbreviation
788 is unambiguous.
789</p>
790</li>
791<li>
792<p>
Junio C Hamano9d971152012-12-19 00:43:11793Short options may be bundled, e.g. <code>-a -b</code> can be specified as <code>-ab</code>.
Junio C Hamano4224f992008-06-23 07:14:08794</p>
795</li>
796<li>
797<p>
798Boolean long options can be <em>negated</em> (or <em>unset</em>) by prepending
Junio C Hamano9d971152012-12-19 00:43:11799 <code>no-</code>, e.g. <code>--no-abbrev</code> instead of <code>--abbrev</code>. Conversely,
800 options that begin with <code>no-</code> can be <em>negated</em> by removing it.
Junio C Hamanoc7102962013-05-29 23:57:17801 Other long options can be unset (e.g., set string to NULL, set
802 integer to 0) by prepending <code>no-</code>.
Junio C Hamano4224f992008-06-23 07:14:08803</p>
804</li>
805<li>
806<p>
Junio C Hamano9d971152012-12-19 00:43:11807Options and non-option arguments can clearly be separated using the <code>--</code>
808 option, e.g. <code>-a -b --option -- --this-is-a-file</code> indicates that
809 <code>--this-is-a-file</code> must not be processed as an option.
Junio C Hamano4224f992008-06-23 07:14:08810</p>
811</li>
Junio C Hamano4604fe52008-09-19 06:37:10812</ul></div>
Junio C Hamano4224f992008-06-23 07:14:08813</div>
Junio C Hamano9d971152012-12-19 00:43:11814</div>
815<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:10816<h2 id="_steps_to_parse_options">Steps to parse options</h2>
Junio C Hamano4224f992008-06-23 07:14:08817<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:07818<div class="olist arabic"><ol class="arabic">
Junio C Hamano4224f992008-06-23 07:14:08819<li>
820<p>
Junio C Hamano9d971152012-12-19 00:43:11821<code>#include "parse-options.h"</code>
Junio C Hamano4224f992008-06-23 07:14:08822</p>
823</li>
824<li>
825<p>
826define a NULL-terminated
Junio C Hamano9d971152012-12-19 00:43:11827 <code>static const char * const builtin_foo_usage[]</code> array
Junio C Hamano4224f992008-06-23 07:14:08828 containing alternative usage strings
829</p>
830</li>
831<li>
832<p>
Junio C Hamano9d971152012-12-19 00:43:11833define <code>builtin_foo_options</code> array as described below
Junio C Hamano4224f992008-06-23 07:14:08834 in section <em>Data Structure</em>.
835</p>
836</li>
837<li>
838<p>
Junio C Hamano9d971152012-12-19 00:43:11839in <code>cmd_foo(int argc, const char **argv, const char *prefix)</code>
Junio C Hamano4224f992008-06-23 07:14:08840 call
841</p>
842<div class="literalblock">
843<div class="content">
Junio C Hamano9d971152012-12-19 00:43:11844<pre><code>argc = parse_options(argc, argv, prefix, builtin_foo_options, builtin_foo_usage, flags);</code></pre>
Junio C Hamano4224f992008-06-23 07:14:08845</div></div>
Junio C Hamano9d971152012-12-19 00:43:11846<div class="paragraph"><p><code>parse_options()</code> will filter out the processed options of <code>argv[]</code> and leave the
847non-option arguments in <code>argv[]</code>.
848<code>argc</code> is updated appropriately because of the assignment.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07849<div class="paragraph"><p>You can also pass NULL instead of a usage array as the fifth parameter of
Junio C Hamano18f51402009-03-10 16:39:13850parse_options(), to avoid displaying a help screen with usage info and
851option list. This should only be done if necessary, e.g. to implement
852a limited parser for only a subset of the options that needs to be run
853before the full parser, which in turn shows the full help message.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07854<div class="paragraph"><p>Flags are the bitwise-or of:</p></div>
855<div class="dlist"><dl>
856<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11857<code>PARSE_OPT_KEEP_DASHDASH</code>
Junio C Hamano4224f992008-06-23 07:14:08858</dt>
859<dd>
860<p>
Junio C Hamano9d971152012-12-19 00:43:11861 Keep the <code>--</code> that usually separates options from
Junio C Hamano4224f992008-06-23 07:14:08862 non-option arguments.
863</p>
864</dd>
Junio C Hamano97bcb482010-11-25 03:16:07865<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11866<code>PARSE_OPT_STOP_AT_NON_OPTION</code>
Junio C Hamano4224f992008-06-23 07:14:08867</dt>
868<dd>
869<p>
870 Usually the whole argument vector is massaged and reordered.
871 Using this flag, processing is stopped at the first non-option
872 argument.
873</p>
874</dd>
Junio C Hamano97bcb482010-11-25 03:16:07875<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11876<code>PARSE_OPT_KEEP_ARGV0</code>
Junio C Hamano18f51402009-03-10 16:39:13877</dt>
878<dd>
879<p>
Junio C Hamano97bcb482010-11-25 03:16:07880 Keep the first argument, which contains the program name. It&#8217;s
Junio C Hamano18f51402009-03-10 16:39:13881 removed from argv[] by default.
882</p>
883</dd>
Junio C Hamano97bcb482010-11-25 03:16:07884<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11885<code>PARSE_OPT_KEEP_UNKNOWN</code>
Junio C Hamano18f51402009-03-10 16:39:13886</dt>
887<dd>
888<p>
Junio C Hamano97bcb482010-11-25 03:16:07889 Keep unknown arguments instead of erroring out. This doesn&#8217;t
Junio C Hamano18f51402009-03-10 16:39:13890 work for all combinations of arguments as users might expect
Junio C Hamano9d971152012-12-19 00:43:11891 it to do. E.g. if the first argument in <code>--unknown --known</code>
Junio C Hamano97bcb482010-11-25 03:16:07892 takes a value (which we can&#8217;t know), the second one is
Junio C Hamano18f51402009-03-10 16:39:13893 mistakenly interpreted as a known option. Similarly, if
Junio C Hamano9d971152012-12-19 00:43:11894 <code>PARSE_OPT_STOP_AT_NON_OPTION</code> is set, the second argument in
895 <code>--unknown value</code> will be mistakenly interpreted as a
Junio C Hamano18f51402009-03-10 16:39:13896 non-option, not as a value belonging to the unknown option,
Junio C Hamano97bcb482010-11-25 03:16:07897 the parser early. That&#8217;s why parse_options() errors out if
Junio C Hamano18f51402009-03-10 16:39:13898 both options are set.
899</p>
900</dd>
Junio C Hamano97bcb482010-11-25 03:16:07901<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11902<code>PARSE_OPT_NO_INTERNAL_HELP</code>
Junio C Hamano18f51402009-03-10 16:39:13903</dt>
904<dd>
905<p>
Junio C Hamano9d971152012-12-19 00:43:11906 By default, parse_options() handles <code>-h</code>, <code>--help</code> and
907 <code>--help-all</code> internally, by showing a help screen. This option
Junio C Hamano18f51402009-03-10 16:39:13908 turns it off and allows one to add custom handlers for these
909 options, or to just leave them unknown.
910</p>
911</dd>
Junio C Hamano4604fe52008-09-19 06:37:10912</dl></div>
Junio C Hamano4224f992008-06-23 07:14:08913</li>
Junio C Hamano4604fe52008-09-19 06:37:10914</ol></div>
Junio C Hamano4224f992008-06-23 07:14:08915</div>
Junio C Hamano9d971152012-12-19 00:43:11916</div>
917<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:10918<h2 id="_data_structure">Data Structure</h2>
Junio C Hamano4224f992008-06-23 07:14:08919<div class="sectionbody">
Junio C Hamano9d971152012-12-19 00:43:11920<div class="paragraph"><p>The main data structure is an array of the <code>option</code> struct,
921say <code>static struct option builtin_add_options[]</code>.
Junio C Hamano4604fe52008-09-19 06:37:10922There are some macros to easily define options:</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07923<div class="dlist"><dl>
924<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11925<code>OPT__ABBREV(&amp;int_var)</code>
Junio C Hamano4224f992008-06-23 07:14:08926</dt>
927<dd>
928<p>
Junio C Hamano9d971152012-12-19 00:43:11929 Add <code>--abbrev[=&lt;n&gt;]</code>.
Junio C Hamano4224f992008-06-23 07:14:08930</p>
931</dd>
Junio C Hamano97bcb482010-11-25 03:16:07932<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11933<code>OPT__COLOR(&amp;int_var, description)</code>
Junio C Hamano4aa0bcc2010-03-03 05:13:12934</dt>
935<dd>
936<p>
Junio C Hamano9d971152012-12-19 00:43:11937 Add <code>--color[=&lt;when&gt;]</code> and <code>--no-color</code>.
Junio C Hamano4aa0bcc2010-03-03 05:13:12938</p>
939</dd>
Junio C Hamano97bcb482010-11-25 03:16:07940<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11941<code>OPT__DRY_RUN(&amp;int_var, description)</code>
Junio C Hamano4224f992008-06-23 07:14:08942</dt>
943<dd>
944<p>
Junio C Hamano9d971152012-12-19 00:43:11945 Add <code>-n, --dry-run</code>.
Junio C Hamano4224f992008-06-23 07:14:08946</p>
947</dd>
Junio C Hamano97bcb482010-11-25 03:16:07948<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11949<code>OPT__FORCE(&amp;int_var, description)</code>
Junio C Hamano97bcb482010-11-25 03:16:07950</dt>
951<dd>
952<p>
Junio C Hamano9d971152012-12-19 00:43:11953 Add <code>-f, --force</code>.
Junio C Hamano97bcb482010-11-25 03:16:07954</p>
955</dd>
956<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11957<code>OPT__QUIET(&amp;int_var, description)</code>
Junio C Hamano4224f992008-06-23 07:14:08958</dt>
959<dd>
960<p>
Junio C Hamano9d971152012-12-19 00:43:11961 Add <code>-q, --quiet</code>.
Junio C Hamano4224f992008-06-23 07:14:08962</p>
963</dd>
Junio C Hamano97bcb482010-11-25 03:16:07964<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11965<code>OPT__VERBOSE(&amp;int_var, description)</code>
Junio C Hamano4224f992008-06-23 07:14:08966</dt>
967<dd>
968<p>
Junio C Hamano9d971152012-12-19 00:43:11969 Add <code>-v, --verbose</code>.
Junio C Hamano4224f992008-06-23 07:14:08970</p>
971</dd>
Junio C Hamano97bcb482010-11-25 03:16:07972<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11973<code>OPT_GROUP(description)</code>
Junio C Hamano4224f992008-06-23 07:14:08974</dt>
975<dd>
976<p>
Junio C Hamano9d971152012-12-19 00:43:11977 Start an option group. <code>description</code> is a short string that
Junio C Hamano4224f992008-06-23 07:14:08978 describes the group or an empty string.
979 Start the description with an upper-case letter.
980</p>
981</dd>
Junio C Hamano97bcb482010-11-25 03:16:07982<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11983<code>OPT_BOOL(short, long, &amp;int_var, description)</code>
Junio C Hamano4224f992008-06-23 07:14:08984</dt>
985<dd>
986<p>
Junio C Hamano9d971152012-12-19 00:43:11987 Introduce a boolean option. <code>int_var</code> is set to one with
988 <code>--option</code> and set to zero with <code>--no-option</code>.
Junio C Hamano4c6612f2011-10-12 23:54:21989</p>
990</dd>
991<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:11992<code>OPT_COUNTUP(short, long, &amp;int_var, description)</code>
Junio C Hamano4c6612f2011-10-12 23:54:21993</dt>
994<dd>
995<p>
996 Introduce a count-up option.
Junio C Hamano9d971152012-12-19 00:43:11997 <code>int_var</code> is incremented on each use of <code>--option</code>, and
998 reset to zero with <code>--no-option</code>.
Junio C Hamano4224f992008-06-23 07:14:08999</p>
1000</dd>
Junio C Hamano97bcb482010-11-25 03:16:071001<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111002<code>OPT_BIT(short, long, &amp;int_var, description, mask)</code>
Junio C Hamano4224f992008-06-23 07:14:081003</dt>
1004<dd>
1005<p>
1006 Introduce a boolean option.
Junio C Hamano9d971152012-12-19 00:43:111007 If used, <code>int_var</code> is bitwise-ored with <code>mask</code>.
Junio C Hamano4224f992008-06-23 07:14:081008</p>
1009</dd>
Junio C Hamano97bcb482010-11-25 03:16:071010<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111011<code>OPT_NEGBIT(short, long, &amp;int_var, description, mask)</code>
Junio C Hamano7ae18252009-05-23 09:53:321012</dt>
1013<dd>
1014<p>
1015 Introduce a boolean option.
Junio C Hamano9d971152012-12-19 00:43:111016 If used, <code>int_var</code> is bitwise-anded with the inverted <code>mask</code>.
Junio C Hamano7ae18252009-05-23 09:53:321017</p>
1018</dd>
Junio C Hamano97bcb482010-11-25 03:16:071019<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111020<code>OPT_SET_INT(short, long, &amp;int_var, description, integer)</code>
Junio C Hamano4224f992008-06-23 07:14:081021</dt>
1022<dd>
1023<p>
Junio C Hamano4c6612f2011-10-12 23:54:211024 Introduce an integer option.
Junio C Hamano9d971152012-12-19 00:43:111025 <code>int_var</code> is set to <code>integer</code> with <code>--option</code>, and
1026 reset to zero with <code>--no-option</code>.
Junio C Hamano4224f992008-06-23 07:14:081027</p>
1028</dd>
Junio C Hamano97bcb482010-11-25 03:16:071029<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111030<code>OPT_SET_PTR(short, long, &amp;ptr_var, description, ptr)</code>
Junio C Hamano4224f992008-06-23 07:14:081031</dt>
1032<dd>
1033<p>
1034 Introduce a boolean option.
Junio C Hamano9d971152012-12-19 00:43:111035 If used, set <code>ptr_var</code> to <code>ptr</code>.
Junio C Hamano4224f992008-06-23 07:14:081036</p>
1037</dd>
Junio C Hamano97bcb482010-11-25 03:16:071038<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111039<code>OPT_STRING(short, long, &amp;str_var, arg_str, description)</code>
Junio C Hamano4224f992008-06-23 07:14:081040</dt>
1041<dd>
1042<p>
1043 Introduce an option with string argument.
Junio C Hamano9d971152012-12-19 00:43:111044 The string argument is put into <code>str_var</code>.
Junio C Hamano4224f992008-06-23 07:14:081045</p>
1046</dd>
Junio C Hamano97bcb482010-11-25 03:16:071047<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111048<code>OPT_INTEGER(short, long, &amp;int_var, description)</code>
Junio C Hamano4224f992008-06-23 07:14:081049</dt>
1050<dd>
1051<p>
1052 Introduce an option with integer argument.
Junio C Hamano9d971152012-12-19 00:43:111053 The integer is put into <code>int_var</code>.
Junio C Hamano4224f992008-06-23 07:14:081054</p>
1055</dd>
Junio C Hamano97bcb482010-11-25 03:16:071056<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111057<code>OPT_DATE(short, long, &amp;int_var, description)</code>
Junio C Hamano4224f992008-06-23 07:14:081058</dt>
1059<dd>
1060<p>
Junio C Hamano9d971152012-12-19 00:43:111061 Introduce an option with date argument, see <code>approxidate()</code>.
1062 The timestamp is put into <code>int_var</code>.
Junio C Hamano4224f992008-06-23 07:14:081063</p>
1064</dd>
Junio C Hamano97bcb482010-11-25 03:16:071065<dt class="hdlist1">
Junio C Hamanoc7102962013-05-29 23:57:171066<code>OPT_EXPIRY_DATE(short, long, &amp;int_var, description)</code>
1067</dt>
1068<dd>
1069<p>
1070 Introduce an option with expiry date argument, see <code>parse_expiry_date()</code>.
1071 The timestamp is put into <code>int_var</code>.
1072</p>
1073</dd>
1074<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111075<code>OPT_CALLBACK(short, long, &amp;var, arg_str, description, func_ptr)</code>
Junio C Hamano4224f992008-06-23 07:14:081076</dt>
1077<dd>
1078<p>
1079 Introduce an option with argument.
Junio C Hamano9d971152012-12-19 00:43:111080 The argument will be fed into the function given by <code>func_ptr</code>
1081 and the result will be put into <code>var</code>.
Junio C Hamano4224f992008-06-23 07:14:081082 See <em>Option Callbacks</em> below for a more elaborate description.
1083</p>
1084</dd>
Junio C Hamano97bcb482010-11-25 03:16:071085<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111086<code>OPT_FILENAME(short, long, &amp;var, description)</code>
Junio C Hamano3d141512009-06-01 01:22:401087</dt>
1088<dd>
1089<p>
1090 Introduce an option with a filename argument.
1091 The filename will be prefixed by passing the filename along with
Junio C Hamano9d971152012-12-19 00:43:111092 the prefix argument of <code>parse_options()</code> to <code>prefix_filename()</code>.
Junio C Hamano3d141512009-06-01 01:22:401093</p>
1094</dd>
Junio C Hamano97bcb482010-11-25 03:16:071095<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111096<code>OPT_ARGUMENT(long, description)</code>
Junio C Hamano4224f992008-06-23 07:14:081097</dt>
1098<dd>
1099<p>
Junio C Hamano9d971152012-12-19 00:43:111100 Introduce a long-option argument that will be kept in <code>argv[]</code>.
Junio C Hamano4224f992008-06-23 07:14:081101</p>
1102</dd>
Junio C Hamano97bcb482010-11-25 03:16:071103<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111104<code>OPT_NUMBER_CALLBACK(&amp;var, description, func_ptr)</code>
Junio C Hamano7ae18252009-05-23 09:53:321105</dt>
1106<dd>
1107<p>
1108 Recognize numerical options like -123 and feed the integer as
Junio C Hamano9d971152012-12-19 00:43:111109 if it was an argument to the function given by <code>func_ptr</code>.
1110 The result will be put into <code>var</code>. There can be only one such
Junio C Hamano7ae18252009-05-23 09:53:321111 option definition. It cannot be negated and it takes no
1112 arguments. Short options that happen to be digits take
1113 precedence over it.
1114</p>
1115</dd>
Junio C Hamano97bcb482010-11-25 03:16:071116<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111117<code>OPT_COLOR_FLAG(short, long, &amp;int_var, description)</code>
Junio C Hamano4aa0bcc2010-03-03 05:13:121118</dt>
1119<dd>
1120<p>
1121 Introduce an option that takes an optional argument that can
1122 have one of three values: "always", "never", or "auto". If the
Junio C Hamano9d971152012-12-19 00:43:111123 argument is not given, it defaults to "always". The <code>--no-</code> form
1124 works like <code>--long=never</code>; it cannot take an argument. If
1125 "always", set <code>int_var</code> to 1; if "never", set <code>int_var</code> to 0; if
1126 "auto", set <code>int_var</code> to 1 if stdout is a tty or a pager,
Junio C Hamano4aa0bcc2010-03-03 05:13:121127 0 otherwise.
1128</p>
1129</dd>
Junio C Hamano4c6612f2011-10-12 23:54:211130<dt class="hdlist1">
Junio C Hamano9d971152012-12-19 00:43:111131<code>OPT_NOOP_NOARG(short, long)</code>
Junio C Hamano4c6612f2011-10-12 23:54:211132</dt>
1133<dd>
1134<p>
1135 Introduce an option that has no effect and takes no arguments.
1136 Use it to hide deprecated options that are still to be recognized
1137 and ignored silently.
1138</p>
1139</dd>
Junio C Hamano4604fe52008-09-19 06:37:101140</dl></div>
Junio C Hamano9d971152012-12-19 00:43:111141<div class="paragraph"><p>The last element of the array must be <code>OPT_END()</code>.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:071142<div class="paragraph"><p>If not stated otherwise, interpret the arguments as follows:</p></div>
1143<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:081144<li>
1145<p>
Junio C Hamano9d971152012-12-19 00:43:111146<code>short</code> is a character for the short option
1147 (e.g. <code>'e'</code> for <code>-e</code>, use <code>0</code> to omit),
Junio C Hamano4224f992008-06-23 07:14:081148</p>
1149</li>
1150<li>
1151<p>
Junio C Hamano9d971152012-12-19 00:43:111152<code>long</code> is a string for the long option
1153 (e.g. <code>"example"</code> for <code>--example</code>, use <code>NULL</code> to omit),
Junio C Hamano4224f992008-06-23 07:14:081154</p>
1155</li>
1156<li>
1157<p>
Junio C Hamano9d971152012-12-19 00:43:111158<code>int_var</code> is an integer variable,
Junio C Hamano4224f992008-06-23 07:14:081159</p>
1160</li>
1161<li>
1162<p>
Junio C Hamano9d971152012-12-19 00:43:111163<code>str_var</code> is a string variable (<code>char *</code>),
Junio C Hamano4224f992008-06-23 07:14:081164</p>
1165</li>
1166<li>
1167<p>
Junio C Hamano9d971152012-12-19 00:43:111168<code>arg_str</code> is the string that is shown as argument
1169 (e.g. <code>"branch"</code> will result in <code>&lt;branch&gt;</code>).
1170 If set to <code>NULL</code>, three dots (<code>...</code>) will be displayed.
Junio C Hamano4224f992008-06-23 07:14:081171</p>
1172</li>
1173<li>
1174<p>
Junio C Hamano9d971152012-12-19 00:43:111175<code>description</code> is a short string to describe the effect of the option.
1176 It shall begin with a lower-case letter and a full stop (<code>.</code>) shall be
Junio C Hamano4224f992008-06-23 07:14:081177 omitted at the end.
1178</p>
1179</li>
Junio C Hamano4604fe52008-09-19 06:37:101180</ul></div>
Junio C Hamano4224f992008-06-23 07:14:081181</div>
Junio C Hamano9d971152012-12-19 00:43:111182</div>
1183<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:101184<h2 id="_option_callbacks">Option Callbacks</h2>
Junio C Hamano4224f992008-06-23 07:14:081185<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:071186<div class="paragraph"><p>The function must be defined in this form:</p></div>
Junio C Hamano4224f992008-06-23 07:14:081187<div class="literalblock">
1188<div class="content">
Junio C Hamano9d971152012-12-19 00:43:111189<pre><code>int func(const struct option *opt, const char *arg, int unset)</code></pre>
Junio C Hamano4224f992008-06-23 07:14:081190</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071191<div class="paragraph"><p>The callback mechanism is as follows:</p></div>
1192<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:081193<li>
1194<p>
Junio C Hamano9d971152012-12-19 00:43:111195Inside <code>func</code>, the only interesting member of the structure
1196 given by <code>opt</code> is the void pointer <code>opt-&gt;value</code>.
1197 <code>*opt-&gt;value</code> will be the value that is saved into <code>var</code>, if you
1198 use <code>OPT_CALLBACK()</code>.
1199 For example, do <code>*(unsigned long *)opt-&gt;value = 42;</code> to get 42
1200 into an <code>unsigned long</code> variable.
Junio C Hamano4224f992008-06-23 07:14:081201</p>
1202</li>
1203<li>
1204<p>
Junio C Hamano9d971152012-12-19 00:43:111205Return value <code>0</code> indicates success and non-zero return
1206 value will invoke <code>usage_with_options()</code> and, thus, die.
Junio C Hamano4224f992008-06-23 07:14:081207</p>
1208</li>
1209<li>
1210<p>
Junio C Hamano9d971152012-12-19 00:43:111211If the user negates the option, <code>arg</code> is <code>NULL</code> and <code>unset</code> is 1.
Junio C Hamano4224f992008-06-23 07:14:081212</p>
1213</li>
Junio C Hamano4604fe52008-09-19 06:37:101214</ul></div>
Junio C Hamano4224f992008-06-23 07:14:081215</div>
Junio C Hamano9d971152012-12-19 00:43:111216</div>
1217<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:101218<h2 id="_sophisticated_option_parsing">Sophisticated option parsing</h2>
Junio C Hamano4224f992008-06-23 07:14:081219<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:071220<div class="paragraph"><p>If you need, for example, option callbacks with optional arguments
Junio C Hamano4224f992008-06-23 07:14:081221or without arguments at all, or if you need other special cases,
1222that are not handled by the macros above, you need to specify the
Junio C Hamano9d971152012-12-19 00:43:111223members of the <code>option</code> structure manually.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:071224<div class="paragraph"><p>This is not covered in this document, but well documented
Junio C Hamano9d971152012-12-19 00:43:111225in <code>parse-options.h</code> itself.</p></div>
Junio C Hamano4224f992008-06-23 07:14:081226</div>
Junio C Hamano9d971152012-12-19 00:43:111227</div>
1228<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:101229<h2 id="_examples">Examples</h2>
Junio C Hamano4224f992008-06-23 07:14:081230<div class="sectionbody">
Junio C Hamano9d971152012-12-19 00:43:111231<div class="paragraph"><p>See <code>test-parse-options.c</code> and
1232<code>builtin-add.c</code>,
1233<code>builtin-clone.c</code>,
1234<code>builtin-commit.c</code>,
1235<code>builtin-fetch.c</code>,
1236<code>builtin-fsck.c</code>,
1237<code>builtin-rm.c</code>
Junio C Hamano4604fe52008-09-19 06:37:101238for real-world examples.</p></div>
Junio C Hamano4224f992008-06-23 07:14:081239</div>
Junio C Hamano7bd050f2011-09-22 06:32:221240</div>
Junio C Hamano9d971152012-12-19 00:43:111241</div>
Junio C Hamano7bd050f2011-09-22 06:32:221242<div id="footnotes"><hr /></div>
Junio C Hamano3dac5042007-12-15 08:40:541243<div id="footer">
1244<div id="footer-text">
Junio C Hamanoc7102962013-05-29 23:57:171245Last updated 2013-05-29 16:56:14 PDT
Junio C Hamano3dac5042007-12-15 08:40:541246</div>
1247</div>
1248</body>
1249</html>