blob: 4dd0cb8c68a7be4377d4f28a3d15f9d72f50069f [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" />
Junio C Hamano61525f92014-01-17 22:46:496<meta name="generator" content="AsciiDoc 8.6.6" />
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 Hamano61525f92014-01-17 22:46:4990pre {
Junio C Hamano3dac5042007-12-15 08:40:5491 padding: 0;
92 margin: 0;
93}
94
Junio C Hamano9d971152012-12-19 00:43:1195#author {
Junio C Hamano3dac5042007-12-15 08:40:5496 color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:5497 font-weight: bold;
Junio C Hamano4604fe52008-09-19 06:37:1098 font-size: 1.1em;
Junio C Hamano3dac5042007-12-15 08:40:5499}
Junio C Hamano9d971152012-12-19 00:43:11100#email {
Junio C Hamano3dac5042007-12-15 08:40:54101}
Junio C Hamano9d971152012-12-19 00:43:11102#revnumber, #revdate, #revremark {
Junio C Hamano3dac5042007-12-15 08:40:54103}
104
Junio C Hamano9d971152012-12-19 00:43:11105#footer {
Junio C Hamano3dac5042007-12-15 08:40:54106 font-size: small;
107 border-top: 2px solid silver;
108 padding-top: 0.5em;
109 margin-top: 4.0em;
110}
Junio C Hamano9d971152012-12-19 00:43:11111#footer-text {
Junio C Hamano3dac5042007-12-15 08:40:54112 float: left;
113 padding-bottom: 0.5em;
114}
Junio C Hamano9d971152012-12-19 00:43:11115#footer-badges {
Junio C Hamano3dac5042007-12-15 08:40:54116 float: right;
117 padding-bottom: 0.5em;
118}
119
Junio C Hamano9d971152012-12-19 00:43:11120#preamble {
Junio C Hamano97bcb482010-11-25 03:16:07121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
123}
Junio C Hamano9d971152012-12-19 00:43:11124div.imageblock, div.exampleblock, div.verseblock,
Junio C Hamano3dac5042007-12-15 08:40:54125div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
126div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22127 margin-top: 1.0em;
Junio C Hamano3dac5042007-12-15 08:40:54128 margin-bottom: 1.5em;
129}
130div.admonitionblock {
Junio C Hamano7bd050f2011-09-22 06:32:22131 margin-top: 2.0em;
132 margin-bottom: 2.0em;
133 margin-right: 10%;
134 color: #606060;
Junio C Hamano3dac5042007-12-15 08:40:54135}
136
137div.content { /* Block element content. */
138 padding: 0;
139}
140
141/* Block element titles. */
142div.title, caption.title {
Junio C Hamano97bcb482010-11-25 03:16:07143 color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:54144 font-weight: bold;
145 text-align: left;
146 margin-top: 1.0em;
147 margin-bottom: 0.5em;
148}
149div.title + * {
150 margin-top: 0;
151}
152
153td div.title:first-child {
154 margin-top: 0.0em;
155}
156div.content div.title:first-child {
157 margin-top: 0.0em;
158}
159div.content + div.title {
160 margin-top: 0.0em;
161}
162
163div.sidebarblock > div.content {
164 background: #ffffee;
Junio C Hamano9d971152012-12-19 00:43:11165 border: 1px solid #dddddd;
166 border-left: 4px solid #f0f0f0;
Junio C Hamano3dac5042007-12-15 08:40:54167 padding: 0.5em;
168}
169
170div.listingblock > div.content {
Junio C Hamano9d971152012-12-19 00:43:11171 border: 1px solid #dddddd;
172 border-left: 5px solid #f0f0f0;
173 background: #f8f8f8;
Junio C Hamano3dac5042007-12-15 08:40:54174 padding: 0.5em;
175}
176
Junio C Hamano7bd050f2011-09-22 06:32:22177div.quoteblock, div.verseblock {
178 padding-left: 1.0em;
179 margin-left: 1.0em;
Junio C Hamano97bcb482010-11-25 03:16:07180 margin-right: 10%;
Junio C Hamano9d971152012-12-19 00:43:11181 border-left: 5px solid #f0f0f0;
182 color: #888;
Junio C Hamano3dac5042007-12-15 08:40:54183}
Junio C Hamano7bd050f2011-09-22 06:32:22184
Junio C Hamano97bcb482010-11-25 03:16:07185div.quoteblock > div.attribution {
186 padding-top: 0.5em;
Junio C Hamano3dac5042007-12-15 08:40:54187 text-align: right;
188}
Junio C Hamano97bcb482010-11-25 03:16:07189
Junio C Hamano9d971152012-12-19 00:43:11190div.verseblock > pre.content {
191 font-family: inherit;
192 font-size: inherit;
Junio C Hamano97bcb482010-11-25 03:16:07193}
194div.verseblock > div.attribution {
195 padding-top: 0.75em;
196 text-align: left;
197}
198/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
Junio C Hamano4604fe52008-09-19 06:37:10199div.verseblock + div.attribution {
200 text-align: left;
201}
Junio C Hamano3dac5042007-12-15 08:40:54202
203div.admonitionblock .icon {
204 vertical-align: top;
205 font-size: 1.1em;
206 font-weight: bold;
207 text-decoration: underline;
208 color: #527bbd;
209 padding-right: 0.5em;
210}
211div.admonitionblock td.content {
212 padding-left: 0.5em;
Junio C Hamano7bd050f2011-09-22 06:32:22213 border-left: 3px solid #dddddd;
Junio C Hamano3dac5042007-12-15 08:40:54214}
215
216div.exampleblock > div.content {
Junio C Hamano7bd050f2011-09-22 06:32:22217 border-left: 3px solid #dddddd;
218 padding-left: 0.5em;
Junio C Hamano3dac5042007-12-15 08:40:54219}
220
Junio C Hamano3dac5042007-12-15 08:40:54221div.imageblock div.content { padding-left: 0; }
Junio C Hamano3dac5042007-12-15 08:40:54222span.image img { border-style: none; }
Junio C Hamano97bcb482010-11-25 03:16:07223a.image:visited { color: white; }
Junio C Hamano3dac5042007-12-15 08:40:54224
225dl {
226 margin-top: 0.8em;
227 margin-bottom: 0.8em;
228}
229dt {
230 margin-top: 0.5em;
231 margin-bottom: 0;
Junio C Hamano97bcb482010-11-25 03:16:07232 font-style: normal;
233 color: navy;
Junio C Hamano3dac5042007-12-15 08:40:54234}
235dd > *:first-child {
Junio C Hamano97bcb482010-11-25 03:16:07236 margin-top: 0.1em;
Junio C Hamano3dac5042007-12-15 08:40:54237}
238
239ul, ol {
240 list-style-position: outside;
241}
Junio C Hamano97bcb482010-11-25 03:16:07242ol.arabic {
243 list-style-type: decimal;
244}
245ol.loweralpha {
Junio C Hamano3dac5042007-12-15 08:40:54246 list-style-type: lower-alpha;
247}
Junio C Hamano97bcb482010-11-25 03:16:07248ol.upperalpha {
249 list-style-type: upper-alpha;
250}
251ol.lowerroman {
252 list-style-type: lower-roman;
253}
254ol.upperroman {
255 list-style-type: upper-roman;
256}
257
258div.compact ul, div.compact ol,
259div.compact p, div.compact p,
260div.compact div, div.compact div {
261 margin-top: 0.1em;
262 margin-bottom: 0.1em;
263}
Junio C Hamano3dac5042007-12-15 08:40:54264
Junio C Hamano3dac5042007-12-15 08:40:54265tfoot {
266 font-weight: bold;
267}
Junio C Hamano97bcb482010-11-25 03:16:07268td > div.verse {
269 white-space: pre;
270}
Junio C Hamano97bcb482010-11-25 03:16:07271
272div.hdlist {
Junio C Hamano3dac5042007-12-15 08:40:54273 margin-top: 0.8em;
274 margin-bottom: 0.8em;
275}
Junio C Hamano97bcb482010-11-25 03:16:07276div.hdlist tr {
277 padding-bottom: 15px;
Junio C Hamano4604fe52008-09-19 06:37:10278}
Junio C Hamano97bcb482010-11-25 03:16:07279dt.hdlist1.strong, td.hdlist1.strong {
280 font-weight: bold;
281}
282td.hdlist1 {
Junio C Hamano3dac5042007-12-15 08:40:54283 vertical-align: top;
Junio C Hamano97bcb482010-11-25 03:16:07284 font-style: normal;
Junio C Hamano3dac5042007-12-15 08:40:54285 padding-right: 0.8em;
Junio C Hamano97bcb482010-11-25 03:16:07286 color: navy;
Junio C Hamano3dac5042007-12-15 08:40:54287}
Junio C Hamano97bcb482010-11-25 03:16:07288td.hdlist2 {
Junio C Hamano3dac5042007-12-15 08:40:54289 vertical-align: top;
290}
Junio C Hamano97bcb482010-11-25 03:16:07291div.hdlist.compact tr {
292 margin: 0;
293 padding-bottom: 0;
294}
295
296.comment {
297 background: yellow;
298}
Junio C Hamano3dac5042007-12-15 08:40:54299
Junio C Hamano7bd050f2011-09-22 06:32:22300.footnote, .footnoteref {
301 font-size: 0.8em;
302}
303
304span.footnote, span.footnoteref {
305 vertical-align: super;
306}
307
308#footnotes {
309 margin: 20px 0 20px 0;
310 padding: 7px 0 0 0;
311}
312
313#footnotes div.footnote {
314 margin: 0 0 5px 0;
315}
316
317#footnotes hr {
318 border: none;
319 border-top: 1px solid silver;
320 height: 1px;
321 text-align: left;
322 margin-left: 0;
323 width: 20%;
324 min-width: 100px;
325}
326
Junio C Hamano9d971152012-12-19 00:43:11327div.colist td {
328 padding-right: 0.5em;
329 padding-bottom: 0.3em;
330 vertical-align: top;
331}
332div.colist td img {
333 margin-top: 0.3em;
Junio C Hamano3dac5042007-12-15 08:40:54334}
Junio C Hamano4604fe52008-09-19 06:37:10335
Junio C Hamano9d971152012-12-19 00:43:11336@media print {
337 #footer-badges { display: none; }
338}
339
340#toc {
Junio C Hamano7bd050f2011-09-22 06:32:22341 margin-bottom: 2.5em;
342}
343
Junio C Hamano9d971152012-12-19 00:43:11344#toctitle {
Junio C Hamano4604fe52008-09-19 06:37:10345 color: #527bbd;
Junio C Hamano4604fe52008-09-19 06:37:10346 font-size: 1.1em;
347 font-weight: bold;
348 margin-top: 1.0em;
349 margin-bottom: 0.1em;
350}
351
Junio C Hamano61525f92014-01-17 22:46:49352div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
Junio C Hamano4604fe52008-09-19 06:37:10353 margin-top: 0;
354 margin-bottom: 0;
355}
356div.toclevel2 {
357 margin-left: 2em;
358 font-size: 0.9em;
359}
360div.toclevel3 {
361 margin-left: 4em;
362 font-size: 0.9em;
363}
364div.toclevel4 {
365 margin-left: 6em;
366 font-size: 0.9em;
367}
Junio C Hamano3dac5042007-12-15 08:40:54368
Junio C Hamano9d971152012-12-19 00:43:11369span.aqua { color: aqua; }
370span.black { color: black; }
371span.blue { color: blue; }
372span.fuchsia { color: fuchsia; }
373span.gray { color: gray; }
374span.green { color: green; }
375span.lime { color: lime; }
376span.maroon { color: maroon; }
377span.navy { color: navy; }
378span.olive { color: olive; }
379span.purple { color: purple; }
380span.red { color: red; }
381span.silver { color: silver; }
382span.teal { color: teal; }
383span.white { color: white; }
384span.yellow { color: yellow; }
385
386span.aqua-background { background: aqua; }
387span.black-background { background: black; }
388span.blue-background { background: blue; }
389span.fuchsia-background { background: fuchsia; }
390span.gray-background { background: gray; }
391span.green-background { background: green; }
392span.lime-background { background: lime; }
393span.maroon-background { background: maroon; }
394span.navy-background { background: navy; }
395span.olive-background { background: olive; }
396span.purple-background { background: purple; }
397span.red-background { background: red; }
398span.silver-background { background: silver; }
399span.teal-background { background: teal; }
400span.white-background { background: white; }
401span.yellow-background { background: yellow; }
402
403span.big { font-size: 2em; }
404span.small { font-size: 0.6em; }
405
406span.underline { text-decoration: underline; }
407span.overline { text-decoration: overline; }
408span.line-through { text-decoration: line-through; }
409
Junio C Hamano9d971152012-12-19 00:43:11410
411/*
412 * xhtml11 specific
413 *
414 * */
415
Junio C Hamano61525f92014-01-17 22:46:49416tt {
417 font-family: monospace;
418 font-size: inherit;
419 color: navy;
420}
421
Junio C Hamano9d971152012-12-19 00:43:11422div.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
Junio C Hamano61525f92014-01-17 22:46:49455.monospaced {
456 font-family: monospace;
457 font-size: inherit;
458 color: navy;
459}
460
Junio C Hamano9d971152012-12-19 00:43:11461table.tableblock {
462 margin-top: 1.0em;
463 margin-bottom: 1.5em;
464}
465thead, p.tableblock.header {
466 font-weight: bold;
467 color: #527bbd;
468}
469p.tableblock {
470 margin-top: 0;
471}
472table.tableblock {
473 border-width: 3px;
474 border-spacing: 0px;
475 border-style: solid;
476 border-color: #527bbd;
477 border-collapse: collapse;
478}
479th.tableblock, td.tableblock {
480 border-width: 1px;
481 padding: 4px;
482 border-style: solid;
483 border-color: #527bbd;
Junio C Hamano3dac5042007-12-15 08:40:54484}
485
Junio C Hamano9d971152012-12-19 00:43:11486table.tableblock.frame-topbot {
487 border-left-style: hidden;
488 border-right-style: hidden;
489}
490table.tableblock.frame-sides {
491 border-top-style: hidden;
492 border-bottom-style: hidden;
493}
494table.tableblock.frame-none {
495 border-style: hidden;
496}
497
498th.tableblock.halign-left, td.tableblock.halign-left {
499 text-align: left;
500}
501th.tableblock.halign-center, td.tableblock.halign-center {
502 text-align: center;
503}
504th.tableblock.halign-right, td.tableblock.halign-right {
Junio C Hamano97bcb482010-11-25 03:16:07505 text-align: right;
506}
507
Junio C Hamano9d971152012-12-19 00:43:11508th.tableblock.valign-top, td.tableblock.valign-top {
509 vertical-align: top;
Junio C Hamano97bcb482010-11-25 03:16:07510}
Junio C Hamano9d971152012-12-19 00:43:11511th.tableblock.valign-middle, td.tableblock.valign-middle {
512 vertical-align: middle;
513}
514th.tableblock.valign-bottom, td.tableblock.valign-bottom {
515 vertical-align: bottom;
Junio C Hamano3dac5042007-12-15 08:40:54516}
517
Junio C Hamano9d971152012-12-19 00:43:11518
519/*
520 * manpage specific
521 *
522 * */
523
524body.manpage h1 {
525 padding-top: 0.5em;
526 padding-bottom: 0.5em;
527 border-top: 2px solid silver;
528 border-bottom: 2px solid silver;
529}
530body.manpage h2 {
531 border-style: none;
532}
533body.manpage div.sectionbody {
534 margin-left: 3em;
Junio C Hamano3dac5042007-12-15 08:40:54535}
Junio C Hamano4604fe52008-09-19 06:37:10536
Junio C Hamano9d971152012-12-19 00:43:11537@media print {
538 body.manpage div#toc { display: none; }
539}
Junio C Hamano3dac5042007-12-15 08:40:54540</style>
Junio C Hamano7bd050f2011-09-22 06:32:22541<script type="text/javascript">
542/*<![CDATA[*/
Junio C Hamano7bd050f2011-09-22 06:32:22543var asciidoc = { // Namespace.
544
545/////////////////////////////////////////////////////////////////////
546// Table Of Contents generator
547/////////////////////////////////////////////////////////////////////
548
549/* Author: Mihai Bazon, September 2002
550 * http://students.infoiasi.ro/~mishoo
551 *
552 * Table Of Content generator
553 * Version: 0.4
554 *
555 * Feel free to use this script under the terms of the GNU General Public
556 * License, as long as you do not remove or alter this notice.
557 */
558
559 /* modified by Troy D. Hanson, September 2006. License: GPL */
560 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
561
562// toclevels = 1..4.
563toc: function (toclevels) {
564
565 function getText(el) {
566 var text = "";
567 for (var i = el.firstChild; i != null; i = i.nextSibling) {
568 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
569 text += i.data;
570 else if (i.firstChild != null)
571 text += getText(i);
572 }
573 return text;
574 }
575
576 function TocEntry(el, text, toclevel) {
577 this.element = el;
578 this.text = text;
579 this.toclevel = toclevel;
580 }
581
582 function tocEntries(el, toclevels) {
583 var result = new Array;
Junio C Hamano61525f92014-01-17 22:46:49584 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
Junio C Hamano7bd050f2011-09-22 06:32:22585 // Function that scans the DOM tree for header elements (the DOM2
586 // nodeIterator API would be a better technique but not supported by all
587 // browsers).
588 var iterate = function (el) {
589 for (var i = el.firstChild; i != null; i = i.nextSibling) {
590 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
591 var mo = re.exec(i.tagName);
592 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
593 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
594 }
595 iterate(i);
596 }
597 }
598 }
599 iterate(el);
600 return result;
601 }
602
603 var toc = document.getElementById("toc");
Junio C Hamano9d971152012-12-19 00:43:11604 if (!toc) {
605 return;
606 }
607
608 // Delete existing TOC entries in case we're reloading the TOC.
609 var tocEntriesToRemove = [];
610 var i;
611 for (i = 0; i < toc.childNodes.length; i++) {
612 var entry = toc.childNodes[i];
Junio C Hamano61525f92014-01-17 22:46:49613 if (entry.nodeName == 'div'
Junio C Hamano9d971152012-12-19 00:43:11614 && entry.getAttribute("class")
615 && entry.getAttribute("class").match(/^toclevel/))
616 tocEntriesToRemove.push(entry);
617 }
618 for (i = 0; i < tocEntriesToRemove.length; i++) {
619 toc.removeChild(tocEntriesToRemove[i]);
620 }
621
622 // Rebuild TOC entries.
Junio C Hamano7bd050f2011-09-22 06:32:22623 var entries = tocEntries(document.getElementById("content"), toclevels);
624 for (var i = 0; i < entries.length; ++i) {
625 var entry = entries[i];
626 if (entry.element.id == "")
627 entry.element.id = "_toc_" + i;
628 var a = document.createElement("a");
629 a.href = "#" + entry.element.id;
630 a.appendChild(document.createTextNode(entry.text));
631 var div = document.createElement("div");
632 div.appendChild(a);
633 div.className = "toclevel" + entry.toclevel;
634 toc.appendChild(div);
635 }
636 if (entries.length == 0)
637 toc.parentNode.removeChild(toc);
638},
639
640
641/////////////////////////////////////////////////////////////////////
642// Footnotes generator
643/////////////////////////////////////////////////////////////////////
644
645/* Based on footnote generation code from:
646 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
647 */
648
649footnotes: function () {
Junio C Hamano9d971152012-12-19 00:43:11650 // Delete existing footnote entries in case we're reloading the footnodes.
651 var i;
Junio C Hamano7bd050f2011-09-22 06:32:22652 var noteholder = document.getElementById("footnotes");
Junio C Hamano9d971152012-12-19 00:43:11653 if (!noteholder) {
654 return;
655 }
656 var entriesToRemove = [];
657 for (i = 0; i < noteholder.childNodes.length; i++) {
658 var entry = noteholder.childNodes[i];
Junio C Hamano61525f92014-01-17 22:46:49659 if (entry.nodeName == 'div' && entry.getAttribute("class") == "footnote")
Junio C Hamano9d971152012-12-19 00:43:11660 entriesToRemove.push(entry);
661 }
662 for (i = 0; i < entriesToRemove.length; i++) {
663 noteholder.removeChild(entriesToRemove[i]);
664 }
665
666 // Rebuild footnote entries.
667 var cont = document.getElementById("content");
Junio C Hamano7bd050f2011-09-22 06:32:22668 var spans = cont.getElementsByTagName("span");
669 var refs = {};
670 var n = 0;
671 for (i=0; i<spans.length; i++) {
672 if (spans[i].className == "footnote") {
673 n++;
Junio C Hamano9d971152012-12-19 00:43:11674 var note = spans[i].getAttribute("data-note");
675 if (!note) {
676 // Use [\s\S] in place of . so multi-line matches work.
677 // Because JavaScript has no s (dotall) regex flag.
678 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
679 spans[i].innerHTML =
680 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
681 "' title='View footnote' class='footnote'>" + n + "</a>]";
682 spans[i].setAttribute("data-note", note);
683 }
Junio C Hamano7bd050f2011-09-22 06:32:22684 noteholder.innerHTML +=
685 "<div class='footnote' id='_footnote_" + n + "'>" +
686 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
687 n + "</a>. " + note + "</div>";
Junio C Hamano7bd050f2011-09-22 06:32:22688 var id =spans[i].getAttribute("id");
689 if (id != null) refs["#"+id] = n;
690 }
691 }
692 if (n == 0)
693 noteholder.parentNode.removeChild(noteholder);
694 else {
695 // Process footnoterefs.
696 for (i=0; i<spans.length; i++) {
697 if (spans[i].className == "footnoteref") {
698 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
699 href = href.match(/#.*/)[0]; // Because IE return full URL.
700 n = refs[href];
701 spans[i].innerHTML =
702 "[<a href='#_footnote_" + n +
703 "' title='View footnote' class='footnote'>" + n + "</a>]";
704 }
705 }
706 }
Junio C Hamano9d971152012-12-19 00:43:11707},
708
709install: function(toclevels) {
710 var timerId;
711
712 function reinstall() {
713 asciidoc.footnotes();
714 if (toclevels) {
715 asciidoc.toc(toclevels);
716 }
717 }
718
719 function reinstallAndRemoveTimer() {
720 clearInterval(timerId);
721 reinstall();
722 }
723
724 timerId = setInterval(reinstall, 500);
725 if (document.addEventListener)
726 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
727 else
728 window.onload = reinstallAndRemoveTimer;
Junio C Hamano7bd050f2011-09-22 06:32:22729}
730
731}
Junio C Hamano9d971152012-12-19 00:43:11732asciidoc.install();
Junio C Hamano7bd050f2011-09-22 06:32:22733/*]]>*/
734</script>
Junio C Hamano3dac5042007-12-15 08:40:54735</head>
Junio C Hamano9d971152012-12-19 00:43:11736<body class="article">
Junio C Hamano3dac5042007-12-15 08:40:54737<div id="header">
738<h1>parse-options API</h1>
739</div>
Junio C Hamano7bd050f2011-09-22 06:32:22740<div id="content">
Junio C Hamano3dac5042007-12-15 08:40:54741<div id="preamble">
742<div class="sectionbody">
Junio C Hamano076ffcc2013-02-06 05:13:21743<div class="paragraph"><p>The parse-options API is used to parse and massage options in Git
Junio C Hamano4604fe52008-09-19 06:37:10744and to provide a usage help with consistent look.</p></div>
Junio C Hamano3dac5042007-12-15 08:40:54745</div>
746</div>
Junio C Hamano9d971152012-12-19 00:43:11747<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:10748<h2 id="_basics">Basics</h2>
Junio C Hamano4224f992008-06-23 07:14:08749<div class="sectionbody">
Junio C Hamano61525f92014-01-17 22:46:49750<div class="paragraph"><p>The argument vector <tt>argv[]</tt> may usually contain mandatory or optional
Junio C Hamano4224f992008-06-23 07:14:08751<em>non-option arguments</em>, e.g. a filename or a branch, and <em>options</em>.
752Options are optional arguments that start with a dash and
Junio C Hamano4604fe52008-09-19 06:37:10753that allow to change the behavior of a command.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07754<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08755<li>
756<p>
757There are basically three types of options:
758 <em>boolean</em> options,
759 options with (mandatory) <em>arguments</em> and
760 options with <em>optional arguments</em>
761 (i.e. a boolean option that can be adjusted).
762</p>
763</li>
764<li>
765<p>
766There are basically two forms of options:
Junio C Hamano61525f92014-01-17 22:46:49767 <em>Short options</em> consist of one dash (<tt>-</tt>) and one alphanumeric
Junio C Hamano4224f992008-06-23 07:14:08768 character.
Junio C Hamano61525f92014-01-17 22:46:49769 <em>Long options</em> begin with two dashes (<tt>--</tt>) and some
Junio C Hamano4224f992008-06-23 07:14:08770 alphanumeric characters.
771</p>
772</li>
773<li>
774<p>
775Options are case-sensitive.
776 Please define <em>lower-case long options</em> only.
777</p>
778</li>
Junio C Hamano4604fe52008-09-19 06:37:10779</ul></div>
Junio C Hamano97bcb482010-11-25 03:16:07780<div class="paragraph"><p>The parse-options API allows:</p></div>
781<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:08782<li>
783<p>
Junio C Hamanof079f702013-12-06 23:43:18784<em>stuck</em> and <em>separate form</em> of options with arguments.
Junio C Hamano61525f92014-01-17 22:46:49785 <tt>-oArg</tt> is stuck, <tt>-o Arg</tt> is separate form.
786 <tt>--option=Arg</tt> is stuck, <tt>--option Arg</tt> is separate form.
Junio C Hamano4224f992008-06-23 07:14:08787</p>
788</li>
789<li>
790<p>
791Long options may be <em>abbreviated</em>, as long as the abbreviation
792 is unambiguous.
793</p>
794</li>
795<li>
796<p>
Junio C Hamano61525f92014-01-17 22:46:49797Short options may be bundled, e.g. <tt>-a -b</tt> can be specified as <tt>-ab</tt>.
Junio C Hamano4224f992008-06-23 07:14:08798</p>
799</li>
800<li>
801<p>
802Boolean long options can be <em>negated</em> (or <em>unset</em>) by prepending
Junio C Hamano61525f92014-01-17 22:46:49803 <tt>no-</tt>, e.g. <tt>--no-abbrev</tt> instead of <tt>--abbrev</tt>. Conversely,
804 options that begin with <tt>no-</tt> can be <em>negated</em> by removing it.
Junio C Hamanoc7102962013-05-29 23:57:17805 Other long options can be unset (e.g., set string to NULL, set
Junio C Hamano61525f92014-01-17 22:46:49806 integer to 0) by prepending <tt>no-</tt>.
Junio C Hamano4224f992008-06-23 07:14:08807</p>
808</li>
809<li>
810<p>
Junio C Hamano61525f92014-01-17 22:46:49811Options and non-option arguments can clearly be separated using the <tt>--</tt>
812 option, e.g. <tt>-a -b --option -- --this-is-a-file</tt> indicates that
813 <tt>--this-is-a-file</tt> must not be processed as an option.
Junio C Hamano4224f992008-06-23 07:14:08814</p>
815</li>
Junio C Hamano4604fe52008-09-19 06:37:10816</ul></div>
Junio C Hamano4224f992008-06-23 07:14:08817</div>
Junio C Hamano9d971152012-12-19 00:43:11818</div>
819<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:10820<h2 id="_steps_to_parse_options">Steps to parse options</h2>
Junio C Hamano4224f992008-06-23 07:14:08821<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:07822<div class="olist arabic"><ol class="arabic">
Junio C Hamano4224f992008-06-23 07:14:08823<li>
824<p>
Junio C Hamano61525f92014-01-17 22:46:49825<tt>#include "parse-options.h"</tt>
Junio C Hamano4224f992008-06-23 07:14:08826</p>
827</li>
828<li>
829<p>
830define a NULL-terminated
Junio C Hamano61525f92014-01-17 22:46:49831 <tt>static const char * const builtin_foo_usage[]</tt> array
Junio C Hamano4224f992008-06-23 07:14:08832 containing alternative usage strings
833</p>
834</li>
835<li>
836<p>
Junio C Hamano61525f92014-01-17 22:46:49837define <tt>builtin_foo_options</tt> array as described below
Junio C Hamano4224f992008-06-23 07:14:08838 in section <em>Data Structure</em>.
839</p>
840</li>
841<li>
842<p>
Junio C Hamano61525f92014-01-17 22:46:49843in <tt>cmd_foo(int argc, const char **argv, const char *prefix)</tt>
Junio C Hamano4224f992008-06-23 07:14:08844 call
845</p>
846<div class="literalblock">
847<div class="content">
Junio C Hamano61525f92014-01-17 22:46:49848<pre><tt>argc = parse_options(argc, argv, prefix, builtin_foo_options, builtin_foo_usage, flags);</tt></pre>
Junio C Hamano4224f992008-06-23 07:14:08849</div></div>
Junio C Hamano61525f92014-01-17 22:46:49850<div class="paragraph"><p><tt>parse_options()</tt> will filter out the processed options of <tt>argv[]</tt> and leave the
851non-option arguments in <tt>argv[]</tt>.
852<tt>argc</tt> is updated appropriately because of the assignment.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07853<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:13854parse_options(), to avoid displaying a help screen with usage info and
855option list. This should only be done if necessary, e.g. to implement
856a limited parser for only a subset of the options that needs to be run
857before the full parser, which in turn shows the full help message.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07858<div class="paragraph"><p>Flags are the bitwise-or of:</p></div>
859<div class="dlist"><dl>
860<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49861<tt>PARSE_OPT_KEEP_DASHDASH</tt>
Junio C Hamano4224f992008-06-23 07:14:08862</dt>
863<dd>
864<p>
Junio C Hamano61525f92014-01-17 22:46:49865 Keep the <tt>--</tt> that usually separates options from
Junio C Hamano4224f992008-06-23 07:14:08866 non-option arguments.
867</p>
868</dd>
Junio C Hamano97bcb482010-11-25 03:16:07869<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49870<tt>PARSE_OPT_STOP_AT_NON_OPTION</tt>
Junio C Hamano4224f992008-06-23 07:14:08871</dt>
872<dd>
873<p>
874 Usually the whole argument vector is massaged and reordered.
875 Using this flag, processing is stopped at the first non-option
876 argument.
877</p>
878</dd>
Junio C Hamano97bcb482010-11-25 03:16:07879<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49880<tt>PARSE_OPT_KEEP_ARGV0</tt>
Junio C Hamano18f51402009-03-10 16:39:13881</dt>
882<dd>
883<p>
Junio C Hamano97bcb482010-11-25 03:16:07884 Keep the first argument, which contains the program name. It&#8217;s
Junio C Hamano18f51402009-03-10 16:39:13885 removed from argv[] by default.
886</p>
887</dd>
Junio C Hamano97bcb482010-11-25 03:16:07888<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49889<tt>PARSE_OPT_KEEP_UNKNOWN</tt>
Junio C Hamano18f51402009-03-10 16:39:13890</dt>
891<dd>
892<p>
Junio C Hamano97bcb482010-11-25 03:16:07893 Keep unknown arguments instead of erroring out. This doesn&#8217;t
Junio C Hamano18f51402009-03-10 16:39:13894 work for all combinations of arguments as users might expect
Junio C Hamano61525f92014-01-17 22:46:49895 it to do. E.g. if the first argument in <tt>--unknown --known</tt>
Junio C Hamano97bcb482010-11-25 03:16:07896 takes a value (which we can&#8217;t know), the second one is
Junio C Hamano18f51402009-03-10 16:39:13897 mistakenly interpreted as a known option. Similarly, if
Junio C Hamano61525f92014-01-17 22:46:49898 <tt>PARSE_OPT_STOP_AT_NON_OPTION</tt> is set, the second argument in
899 <tt>--unknown value</tt> will be mistakenly interpreted as a
Junio C Hamano18f51402009-03-10 16:39:13900 non-option, not as a value belonging to the unknown option,
Junio C Hamano97bcb482010-11-25 03:16:07901 the parser early. That&#8217;s why parse_options() errors out if
Junio C Hamano18f51402009-03-10 16:39:13902 both options are set.
903</p>
904</dd>
Junio C Hamano97bcb482010-11-25 03:16:07905<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49906<tt>PARSE_OPT_NO_INTERNAL_HELP</tt>
Junio C Hamano18f51402009-03-10 16:39:13907</dt>
908<dd>
909<p>
Junio C Hamano61525f92014-01-17 22:46:49910 By default, parse_options() handles <tt>-h</tt>, <tt>--help</tt> and
911 <tt>--help-all</tt> internally, by showing a help screen. This option
Junio C Hamano18f51402009-03-10 16:39:13912 turns it off and allows one to add custom handlers for these
913 options, or to just leave them unknown.
914</p>
915</dd>
Junio C Hamano4604fe52008-09-19 06:37:10916</dl></div>
Junio C Hamano4224f992008-06-23 07:14:08917</li>
Junio C Hamano4604fe52008-09-19 06:37:10918</ol></div>
Junio C Hamano4224f992008-06-23 07:14:08919</div>
Junio C Hamano9d971152012-12-19 00:43:11920</div>
921<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:10922<h2 id="_data_structure">Data Structure</h2>
Junio C Hamano4224f992008-06-23 07:14:08923<div class="sectionbody">
Junio C Hamano61525f92014-01-17 22:46:49924<div class="paragraph"><p>The main data structure is an array of the <tt>option</tt> struct,
925say <tt>static struct option builtin_add_options[]</tt>.
Junio C Hamano4604fe52008-09-19 06:37:10926There are some macros to easily define options:</p></div>
Junio C Hamano97bcb482010-11-25 03:16:07927<div class="dlist"><dl>
928<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49929<tt>OPT__ABBREV(&amp;int_var)</tt>
Junio C Hamano4224f992008-06-23 07:14:08930</dt>
931<dd>
932<p>
Junio C Hamano61525f92014-01-17 22:46:49933 Add <tt>--abbrev[=&lt;n&gt;]</tt>.
Junio C Hamano4224f992008-06-23 07:14:08934</p>
935</dd>
Junio C Hamano97bcb482010-11-25 03:16:07936<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49937<tt>OPT__COLOR(&amp;int_var, description)</tt>
Junio C Hamano4aa0bcc2010-03-03 05:13:12938</dt>
939<dd>
940<p>
Junio C Hamano61525f92014-01-17 22:46:49941 Add <tt>--color[=&lt;when&gt;]</tt> and <tt>--no-color</tt>.
Junio C Hamano4aa0bcc2010-03-03 05:13:12942</p>
943</dd>
Junio C Hamano97bcb482010-11-25 03:16:07944<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49945<tt>OPT__DRY_RUN(&amp;int_var, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:08946</dt>
947<dd>
948<p>
Junio C Hamano61525f92014-01-17 22:46:49949 Add <tt>-n, --dry-run</tt>.
Junio C Hamano4224f992008-06-23 07:14:08950</p>
951</dd>
Junio C Hamano97bcb482010-11-25 03:16:07952<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49953<tt>OPT__FORCE(&amp;int_var, description)</tt>
Junio C Hamano97bcb482010-11-25 03:16:07954</dt>
955<dd>
956<p>
Junio C Hamano61525f92014-01-17 22:46:49957 Add <tt>-f, --force</tt>.
Junio C Hamano97bcb482010-11-25 03:16:07958</p>
959</dd>
960<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49961<tt>OPT__QUIET(&amp;int_var, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:08962</dt>
963<dd>
964<p>
Junio C Hamano61525f92014-01-17 22:46:49965 Add <tt>-q, --quiet</tt>.
Junio C Hamano4224f992008-06-23 07:14:08966</p>
967</dd>
Junio C Hamano97bcb482010-11-25 03:16:07968<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49969<tt>OPT__VERBOSE(&amp;int_var, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:08970</dt>
971<dd>
972<p>
Junio C Hamano61525f92014-01-17 22:46:49973 Add <tt>-v, --verbose</tt>.
Junio C Hamano4224f992008-06-23 07:14:08974</p>
975</dd>
Junio C Hamano97bcb482010-11-25 03:16:07976<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49977<tt>OPT_GROUP(description)</tt>
Junio C Hamano4224f992008-06-23 07:14:08978</dt>
979<dd>
980<p>
Junio C Hamano61525f92014-01-17 22:46:49981 Start an option group. <tt>description</tt> is a short string that
Junio C Hamano4224f992008-06-23 07:14:08982 describes the group or an empty string.
983 Start the description with an upper-case letter.
984</p>
985</dd>
Junio C Hamano97bcb482010-11-25 03:16:07986<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49987<tt>OPT_BOOL(short, long, &amp;int_var, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:08988</dt>
989<dd>
990<p>
Junio C Hamano61525f92014-01-17 22:46:49991 Introduce a boolean option. <tt>int_var</tt> is set to one with
992 <tt>--option</tt> and set to zero with <tt>--no-option</tt>.
Junio C Hamano4c6612f2011-10-12 23:54:21993</p>
994</dd>
995<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:49996<tt>OPT_COUNTUP(short, long, &amp;int_var, description)</tt>
Junio C Hamano4c6612f2011-10-12 23:54:21997</dt>
998<dd>
999<p>
1000 Introduce a count-up option.
Junio C Hamano61525f92014-01-17 22:46:491001 <tt>int_var</tt> is incremented on each use of <tt>--option</tt>, and
1002 reset to zero with <tt>--no-option</tt>.
Junio C Hamano4224f992008-06-23 07:14:081003</p>
1004</dd>
Junio C Hamano97bcb482010-11-25 03:16:071005<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491006<tt>OPT_BIT(short, long, &amp;int_var, description, mask)</tt>
Junio C Hamano4224f992008-06-23 07:14:081007</dt>
1008<dd>
1009<p>
1010 Introduce a boolean option.
Junio C Hamano61525f92014-01-17 22:46:491011 If used, <tt>int_var</tt> is bitwise-ored with <tt>mask</tt>.
Junio C Hamano4224f992008-06-23 07:14:081012</p>
1013</dd>
Junio C Hamano97bcb482010-11-25 03:16:071014<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491015<tt>OPT_NEGBIT(short, long, &amp;int_var, description, mask)</tt>
Junio C Hamano7ae18252009-05-23 09:53:321016</dt>
1017<dd>
1018<p>
1019 Introduce a boolean option.
Junio C Hamano61525f92014-01-17 22:46:491020 If used, <tt>int_var</tt> is bitwise-anded with the inverted <tt>mask</tt>.
Junio C Hamano7ae18252009-05-23 09:53:321021</p>
1022</dd>
Junio C Hamano97bcb482010-11-25 03:16:071023<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491024<tt>OPT_SET_INT(short, long, &amp;int_var, description, integer)</tt>
Junio C Hamano4224f992008-06-23 07:14:081025</dt>
1026<dd>
1027<p>
Junio C Hamano4c6612f2011-10-12 23:54:211028 Introduce an integer option.
Junio C Hamano61525f92014-01-17 22:46:491029 <tt>int_var</tt> is set to <tt>integer</tt> with <tt>--option</tt>, and
1030 reset to zero with <tt>--no-option</tt>.
Junio C Hamano4224f992008-06-23 07:14:081031</p>
1032</dd>
Junio C Hamano97bcb482010-11-25 03:16:071033<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491034<tt>OPT_STRING(short, long, &amp;str_var, arg_str, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:081035</dt>
1036<dd>
1037<p>
1038 Introduce an option with string argument.
Junio C Hamano61525f92014-01-17 22:46:491039 The string argument is put into <tt>str_var</tt>.
Junio C Hamano4224f992008-06-23 07:14:081040</p>
1041</dd>
Junio C Hamano97bcb482010-11-25 03:16:071042<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491043<tt>OPT_INTEGER(short, long, &amp;int_var, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:081044</dt>
1045<dd>
1046<p>
1047 Introduce an option with integer argument.
Junio C Hamano61525f92014-01-17 22:46:491048 The integer is put into <tt>int_var</tt>.
Junio C Hamano4224f992008-06-23 07:14:081049</p>
1050</dd>
Junio C Hamano97bcb482010-11-25 03:16:071051<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491052<tt>OPT_DATE(short, long, &amp;int_var, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:081053</dt>
1054<dd>
1055<p>
Junio C Hamano61525f92014-01-17 22:46:491056 Introduce an option with date argument, see <tt>approxidate()</tt>.
1057 The timestamp is put into <tt>int_var</tt>.
Junio C Hamano4224f992008-06-23 07:14:081058</p>
1059</dd>
Junio C Hamano97bcb482010-11-25 03:16:071060<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491061<tt>OPT_EXPIRY_DATE(short, long, &amp;int_var, description)</tt>
Junio C Hamanoc7102962013-05-29 23:57:171062</dt>
1063<dd>
1064<p>
Junio C Hamano61525f92014-01-17 22:46:491065 Introduce an option with expiry date argument, see <tt>parse_expiry_date()</tt>.
1066 The timestamp is put into <tt>int_var</tt>.
Junio C Hamanoc7102962013-05-29 23:57:171067</p>
1068</dd>
1069<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491070<tt>OPT_CALLBACK(short, long, &amp;var, arg_str, description, func_ptr)</tt>
Junio C Hamano4224f992008-06-23 07:14:081071</dt>
1072<dd>
1073<p>
1074 Introduce an option with argument.
Junio C Hamano61525f92014-01-17 22:46:491075 The argument will be fed into the function given by <tt>func_ptr</tt>
1076 and the result will be put into <tt>var</tt>.
Junio C Hamano4224f992008-06-23 07:14:081077 See <em>Option Callbacks</em> below for a more elaborate description.
1078</p>
1079</dd>
Junio C Hamano97bcb482010-11-25 03:16:071080<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491081<tt>OPT_FILENAME(short, long, &amp;var, description)</tt>
Junio C Hamano3d141512009-06-01 01:22:401082</dt>
1083<dd>
1084<p>
1085 Introduce an option with a filename argument.
1086 The filename will be prefixed by passing the filename along with
Junio C Hamano61525f92014-01-17 22:46:491087 the prefix argument of <tt>parse_options()</tt> to <tt>prefix_filename()</tt>.
Junio C Hamano3d141512009-06-01 01:22:401088</p>
1089</dd>
Junio C Hamano97bcb482010-11-25 03:16:071090<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491091<tt>OPT_ARGUMENT(long, description)</tt>
Junio C Hamano4224f992008-06-23 07:14:081092</dt>
1093<dd>
1094<p>
Junio C Hamano61525f92014-01-17 22:46:491095 Introduce a long-option argument that will be kept in <tt>argv[]</tt>.
Junio C Hamano4224f992008-06-23 07:14:081096</p>
1097</dd>
Junio C Hamano97bcb482010-11-25 03:16:071098<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491099<tt>OPT_NUMBER_CALLBACK(&amp;var, description, func_ptr)</tt>
Junio C Hamano7ae18252009-05-23 09:53:321100</dt>
1101<dd>
1102<p>
1103 Recognize numerical options like -123 and feed the integer as
Junio C Hamano61525f92014-01-17 22:46:491104 if it was an argument to the function given by <tt>func_ptr</tt>.
1105 The result will be put into <tt>var</tt>. There can be only one such
Junio C Hamano7ae18252009-05-23 09:53:321106 option definition. It cannot be negated and it takes no
1107 arguments. Short options that happen to be digits take
1108 precedence over it.
1109</p>
1110</dd>
Junio C Hamano97bcb482010-11-25 03:16:071111<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491112<tt>OPT_COLOR_FLAG(short, long, &amp;int_var, description)</tt>
Junio C Hamano4aa0bcc2010-03-03 05:13:121113</dt>
1114<dd>
1115<p>
1116 Introduce an option that takes an optional argument that can
1117 have one of three values: "always", "never", or "auto". If the
Junio C Hamano61525f92014-01-17 22:46:491118 argument is not given, it defaults to "always". The <tt>--no-</tt> form
1119 works like <tt>--long=never</tt>; it cannot take an argument. If
1120 "always", set <tt>int_var</tt> to 1; if "never", set <tt>int_var</tt> to 0; if
1121 "auto", set <tt>int_var</tt> to 1 if stdout is a tty or a pager,
Junio C Hamano4aa0bcc2010-03-03 05:13:121122 0 otherwise.
1123</p>
1124</dd>
Junio C Hamano4c6612f2011-10-12 23:54:211125<dt class="hdlist1">
Junio C Hamano61525f92014-01-17 22:46:491126<tt>OPT_NOOP_NOARG(short, long)</tt>
Junio C Hamano4c6612f2011-10-12 23:54:211127</dt>
1128<dd>
1129<p>
1130 Introduce an option that has no effect and takes no arguments.
1131 Use it to hide deprecated options that are still to be recognized
1132 and ignored silently.
1133</p>
1134</dd>
Junio C Hamano4604fe52008-09-19 06:37:101135</dl></div>
Junio C Hamano61525f92014-01-17 22:46:491136<div class="paragraph"><p>The last element of the array must be <tt>OPT_END()</tt>.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:071137<div class="paragraph"><p>If not stated otherwise, interpret the arguments as follows:</p></div>
1138<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:081139<li>
1140<p>
Junio C Hamano61525f92014-01-17 22:46:491141<tt>short</tt> is a character for the short option
1142 (e.g. <tt>'e'</tt> for <tt>-e</tt>, use <tt>0</tt> to omit),
Junio C Hamano4224f992008-06-23 07:14:081143</p>
1144</li>
1145<li>
1146<p>
Junio C Hamano61525f92014-01-17 22:46:491147<tt>long</tt> is a string for the long option
1148 (e.g. <tt>"example"</tt> for <tt>--example</tt>, use <tt>NULL</tt> to omit),
Junio C Hamano4224f992008-06-23 07:14:081149</p>
1150</li>
1151<li>
1152<p>
Junio C Hamano61525f92014-01-17 22:46:491153<tt>int_var</tt> is an integer variable,
Junio C Hamano4224f992008-06-23 07:14:081154</p>
1155</li>
1156<li>
1157<p>
Junio C Hamano61525f92014-01-17 22:46:491158<tt>str_var</tt> is a string variable (<tt>char *</tt>),
Junio C Hamano4224f992008-06-23 07:14:081159</p>
1160</li>
1161<li>
1162<p>
Junio C Hamano61525f92014-01-17 22:46:491163<tt>arg_str</tt> is the string that is shown as argument
1164 (e.g. <tt>"branch"</tt> will result in <tt>&lt;branch&gt;</tt>).
1165 If set to <tt>NULL</tt>, three dots (<tt>...</tt>) will be displayed.
Junio C Hamano4224f992008-06-23 07:14:081166</p>
1167</li>
1168<li>
1169<p>
Junio C Hamano61525f92014-01-17 22:46:491170<tt>description</tt> is a short string to describe the effect of the option.
1171 It shall begin with a lower-case letter and a full stop (<tt>.</tt>) shall be
Junio C Hamano4224f992008-06-23 07:14:081172 omitted at the end.
1173</p>
1174</li>
Junio C Hamano4604fe52008-09-19 06:37:101175</ul></div>
Junio C Hamano4224f992008-06-23 07:14:081176</div>
Junio C Hamano9d971152012-12-19 00:43:111177</div>
1178<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:101179<h2 id="_option_callbacks">Option Callbacks</h2>
Junio C Hamano4224f992008-06-23 07:14:081180<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:071181<div class="paragraph"><p>The function must be defined in this form:</p></div>
Junio C Hamano4224f992008-06-23 07:14:081182<div class="literalblock">
1183<div class="content">
Junio C Hamano61525f92014-01-17 22:46:491184<pre><tt>int func(const struct option *opt, const char *arg, int unset)</tt></pre>
Junio C Hamano4224f992008-06-23 07:14:081185</div></div>
Junio C Hamano97bcb482010-11-25 03:16:071186<div class="paragraph"><p>The callback mechanism is as follows:</p></div>
1187<div class="ulist"><ul>
Junio C Hamano4224f992008-06-23 07:14:081188<li>
1189<p>
Junio C Hamano61525f92014-01-17 22:46:491190Inside <tt>func</tt>, the only interesting member of the structure
1191 given by <tt>opt</tt> is the void pointer <tt>opt-&gt;value</tt>.
1192 <tt>*opt-&gt;value</tt> will be the value that is saved into <tt>var</tt>, if you
1193 use <tt>OPT_CALLBACK()</tt>.
1194 For example, do <tt>*(unsigned long *)opt-&gt;value = 42;</tt> to get 42
1195 into an <tt>unsigned long</tt> variable.
Junio C Hamano4224f992008-06-23 07:14:081196</p>
1197</li>
1198<li>
1199<p>
Junio C Hamano61525f92014-01-17 22:46:491200Return value <tt>0</tt> indicates success and non-zero return
1201 value will invoke <tt>usage_with_options()</tt> and, thus, die.
Junio C Hamano4224f992008-06-23 07:14:081202</p>
1203</li>
1204<li>
1205<p>
Junio C Hamano61525f92014-01-17 22:46:491206If the user negates the option, <tt>arg</tt> is <tt>NULL</tt> and <tt>unset</tt> is 1.
Junio C Hamano4224f992008-06-23 07:14:081207</p>
1208</li>
Junio C Hamano4604fe52008-09-19 06:37:101209</ul></div>
Junio C Hamano4224f992008-06-23 07:14:081210</div>
Junio C Hamano9d971152012-12-19 00:43:111211</div>
1212<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:101213<h2 id="_sophisticated_option_parsing">Sophisticated option parsing</h2>
Junio C Hamano4224f992008-06-23 07:14:081214<div class="sectionbody">
Junio C Hamano97bcb482010-11-25 03:16:071215<div class="paragraph"><p>If you need, for example, option callbacks with optional arguments
Junio C Hamano4224f992008-06-23 07:14:081216or without arguments at all, or if you need other special cases,
1217that are not handled by the macros above, you need to specify the
Junio C Hamano61525f92014-01-17 22:46:491218members of the <tt>option</tt> structure manually.</p></div>
Junio C Hamano97bcb482010-11-25 03:16:071219<div class="paragraph"><p>This is not covered in this document, but well documented
Junio C Hamano61525f92014-01-17 22:46:491220in <tt>parse-options.h</tt> itself.</p></div>
Junio C Hamano4224f992008-06-23 07:14:081221</div>
Junio C Hamano9d971152012-12-19 00:43:111222</div>
1223<div class="sect1">
Junio C Hamano4604fe52008-09-19 06:37:101224<h2 id="_examples">Examples</h2>
Junio C Hamano4224f992008-06-23 07:14:081225<div class="sectionbody">
Junio C Hamano61525f92014-01-17 22:46:491226<div class="paragraph"><p>See <tt>test-parse-options.c</tt> and
1227<tt>builtin/add.c</tt>,
1228<tt>builtin/clone.c</tt>,
1229<tt>builtin/commit.c</tt>,
1230<tt>builtin/fetch.c</tt>,
1231<tt>builtin/fsck.c</tt>,
1232<tt>builtin/rm.c</tt>
Junio C Hamano4604fe52008-09-19 06:37:101233for real-world examples.</p></div>
Junio C Hamano4224f992008-06-23 07:14:081234</div>
Junio C Hamano7bd050f2011-09-22 06:32:221235</div>
Junio C Hamano9d971152012-12-19 00:43:111236</div>
Junio C Hamano7bd050f2011-09-22 06:32:221237<div id="footnotes"><hr /></div>
Junio C Hamano3dac5042007-12-15 08:40:541238<div id="footer">
1239<div id="footer-text">
Junio C Hamanod75148a2014-04-08 19:48:381240Last updated 2014-04-08 12:47:26 PDT
Junio C Hamano3dac5042007-12-15 08:40:541241</div>
1242</div>
1243</body>
1244</html>