summaryrefslogtreecommitdiff
path: root/autoopts/tpl/cmd-doc.tlib
blob: b59cef99af7c1ca49b33e5f7b6c81b70da3674ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
[+: -*- Mode: nroff -*-

  AutoGen5 template man

# cmd-doc.tlib -- Template for command line man/mdoc pages
#
# Time-stamp:      "2012-05-12 20:52:33 bkorb"
#
#  This file is part of AutoOpts, a companion to AutoGen.
#  AutoOpts is free software.
#  Copyright (c) 1992-2012 Bruce Korb - all rights reserved
#
#  AutoOpts is available under any one of two licenses.  The license
#  in use must be one of these two and the choice is under the control
#  of the user of the license.
#
#   The GNU Lesser General Public License, version 3 or later
#      See the files "COPYING.lgplv3" and "COPYING.gplv3"
#
#   The Modified Berkeley Software Distribution License
#      See the file "COPYING.mbsd"
#
#  These files have the following md5sums:
#
#  43b91e8ca915626ed3818ffb1b71248b COPYING.gplv3
#  06a1a2e4760c90ea5e1dad8dfaac4d39 COPYING.lgplv3
#  66a5cedaf62c4b2637025f049f9b826f COPYING.mbsd

# Produce a man page for section 1, 5, 6 or 8 commands.  Which is
# selected via: -DMAN_SECTION=n.  "n" may have a suffix, if desired.
# These sections have default section names that may be overridden
# with -DSECTIN_NAME=XX, also passed to the autogen invocation.
#
:+][+:

   ;;# START-BUILDTREE-ISMS
   ;;
   (shell "CLexe=${AGexe%/agen5/*}/columns/columns
  test -x \"${CLexe}\" || {
    CLexe=${AGexe%/autogen}/columns
    test -x \"${CLexe}\" || die 'columns program is not findable'
  }")

:+][+: # END-BUILDTREE-ISMS

   (shell "CLexe=${AGexe%/autogen}/columns")

# END-INSTALL-ONLY-CODE :+][+:

(define down-prog-name (string-downcase! (get "prog-name")))
(define UP-PROG-NAME   (get-up-name "prog-name"))

(define tmp-val        (getenv "MAN_SECTION"))
(define man-sect       (if (exist? "cmd-section") (get "cmd-section") "1"))
(define file-name      "")
(define sect-name      "")
(define macro-name     "")
(define tmp-str        "")
(define fname-line     "")
(define use-flags      (exist? "flag.value"))
(define named-mode     (not (or use-flags (exist? "long-opts") )))

(if (defined? 'tmp-val)
    (if (string? tmp-val)
        (set! man-sect tmp-val)))

(define section-name
   (if (=* man-sect "1") "User Commands"
   (if (=* man-sect "5") "File Formats"
   (if (=* man-sect "6") "Games"
   (if (=* man-sect "8") "System Management"
   (error
    "the agman-cmd template only produces section 1, 5, 6 and 8 man pages")
)))))
(set! tmp-val (getenv "SECTION_NAME"))
(if (defined? 'tmp-val) (if (string? tmp-val)
    (set! section-name tmp-val) ))

(define package-text "")
(define package+version (and (exist? "package") (exist? "version")))

(if (or (exist? "package") (exist? "version")) (begin
  (set! package-text (string-append
        (get "package")
        (if package+version " (" "")
        (get "version")
        (if package+version ")" "") ))
) )

(define name-to-fname (lambda (nm)
    (string-tr (string-downcase nm) " " "-") ))

(define sect-line-fname (lambda () (begin
    (out-push-new file-name)
    (emit (string-append ".Sh \"" sect-name "\"\n"))
    (string-append "mk-" macro-name) )))

(make-tmp-dir)

(define home-rc-files (exist? "homerc"))
(define home-rc-text
  "\nSee \\fBOPTION PRESETS\\fP for configuration files.")

(define environ-init  (exist? "environrc"))
(define environ-text
  "\nSee \\fBOPTION PRESETS\\fP for configuration environment variables.")

(set! tmp-str (find-file (if man-page "texi2man" "texi2mdoc")))
(if (not (defined? 'tmp-str))
    (error (string-append "cannot locate "
           (if man-page "texi2man" "texi2mdoc"))))
(shell (string-append "cvt_prog='" tmp-str
       "'\ntest -x \"$cvt_prog\" || die 'no conversion program'" ))

(define get-cvt (lambda (nm alt-txt)
    (shell (string-append
      "{\n${cvt_prog} || die ${cvt_prog} failed in $PWD\n"
      "} <<\\_EndOfTexiSection_\n"
      (get nm alt-txt)
      "\n_EndOfTexiSection_"
    ))
))

(emit (head-line))
(dne ".\\\"  ")                       :+][+:

INCLUDE "tpl-config.tlib"             :+][+:#

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  B U I L D   D O C
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE build-doc                      :+][+:

INVOKE doc-sections                   :+][+:
INVOKE ao-sections                    :+][+:

(out-push-new (string-append tmp-dir "/.assemble")) \:+]

cat_n_rm() {
  test -f ${tmp_dir}/$1 || return 0
  [+:(. egrep-prog):+] -v '^[ 	]*$' ${tmp_dir}/$1
  rm -f ${tmp_dir}/$1
}

#.\" Insert these sections first, in the prescribed order
#
for f in synopsis description options option-presets
do cat_n_rm $f ; done
test -f ${tmp_dir}/name && rm -f ${tmp_dir}/name

#.\" These sections go last, in the prescribed order
#
for f in implementation-notes environment files examples exit-status errors \
      compatibility see-also conforming-to history authors copyright bugs notes
do cat_n_rm $f ; done > ${tmp_dir}/.fini

#.\" Insert the contents of all remaining files in alphabetic order,
#.\" except remove any blank lines.
#
set XX ${tmp_dir}/* ; shift
test -f "$1" && cat $* | [+:(. egrep-prog):+] -v '^[ 	]*$'

#.\" Now insert the sections we squirreled away for the end.
#
cat  ${tmp_dir}/.fini
[+: (out-pop)
    (shell ". ${tmp_dir}/.assemble")  :+][+:

ENDDEF build-doc

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  D O C   S E C T I O N S
.\"
.\" Emit the files for each section that was provided.
.\"
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE doc-sections                   :+][+:

FOR doc-section                       :+][+:

  CASE
    (define sec-type (string-upcase (get "ds-type")))
    (define sec-name (name-to-fname sec-type))
    (out-push-new (string-append tmp-dir "/" sec-name))
    (define cvt-fn (find-file (string-append
         (get "ds-format" "man") "2mdoc")))
    (if (not (defined? 'cvt-fn))
        (error (sprintf "Cannot locate converter for %s"
               (get "ds-format" "man"))))
    sec-type :+][+:
    == ""    :+][+: (error "unnamed doc-section") :+][+:
    *==* " " :+].Sh "[+: (. sec-type)            :+]"[+:
    *        :+].Sh [+: (. sec-type)              :+][+:
    ESAC     :+]
[+:
    (shell (string-append
      "fn='" cvt-fn "'\n"
      "test -f ${fn} || die ${fn} not found from $PWD\n"
      "${fn} <<\\_EndOfDocSection_ || die ${fn} failed in $PWD\n"
      (get "ds-text")
      "\n_EndOfDocSection_"
    ))                                :+][+:

    CASE (. sec-type)                 :+][+:
    == FILES                          :+][+:
        (if home-rc-files (emit home-rc-text))
        (set! home-rc-files #f)       :+][+:

    == ENVIRONMENT                    :+][+:
        (if environ-init (emit environ-text))
        (set! environ-init #f)        :+][+:
    ESAC                              :+][+:

    (out-pop)
    :+][+:

ENDFOR doc-section                    :+][+:

ENDDEF doc-sections

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  A O   S E C T I O N S
.\"
.\" Emit the files for the sections that these templates augment,
.\" replace or conditionally replace
.\"
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE ao-sections              :+][+:

INVOKE cond-section  sec = "OPTIONS"           mode = "replace"       :+][+:
INVOKE cond-section  sec = "SYNOPSIS"          mode = "alt"           :+][+:
INVOKE cond-section  sec = "DESCRIPTION"       mode = "append"        :+][+:
INVOKE cond-section  sec = "EXIT STATUS"       mode = "insert"        :+][+:
INVOKE cond-section  sec = "AUTHORS"           mode = "alt"           :+][+:
INVOKE cond-section  sec = "BUGS"              mode = "append"        :+][+:
INVOKE cond-section  sec = "NOTES"             mode = "append"        :+][+:

IF (exist? "copyright")                                               :+][+:
  INVOKE cond-section   sec = "COPYRIGHT"      mode = "alt"           :+][+:
ENDIF                                                                 :+][+:

IF (or home-rc-files environ-init)                                    :+][+:
  INVOKE cond-section   sec = "OPTION PRESETS" mode = "replace"       :+][+:

  IF (. home-rc-files)                                                :+][+:
    INVOKE cond-section sec = "FILES"          mode = "append"        :+][+:
  ENDIF                                                               :+][+:

  IF (. environ-init)                                                 :+][+:
    INVOKE cond-section sec = "ENVIRONMENT"    mode = "append"        :+][+:
  ENDIF                                                               :+][+:

ENDIF                                                                 :+][+:

ENDDEF ao-sections

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  C O N D I T I O N A L   S E C T I O N
.\"
.\" Figure out what to do for AutoOpts required sections, depending on "mode"
.\" In all cases, if the file does not exist, invoke the "mk" macro to create
.\" a new file.  If it does exist, then:
.\"
.\" alt       Alternate -- emit no text
.\" replace   throw away any pre-existing file.
.\" append    invoke the "append" macro to emit additional text
.\" insert    save the current contents, replacing the .Sh line with .Pp.
.\"           invoke the "mk" macro then emit the saved text
.\"
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE cond-section                     :+][+:

  IF 
     (set! sect-name   (string-upcase! (string-substitute
                       (get "sec") "-" " " )))
     (set! macro-name  (string-downcase! (string-substitute
                       sect-name " " "-" )))
     (set! file-name   (string-append tmp-dir "/" macro-name))

     (not (access? file-name R_OK))     :+][+:

     INVOKE (sect-line-fname)           :+][+:
     (out-pop)                          :+][+:

  ELSE file exists                      :+][+:

     CASE (get "mode")                  :+][+:

     ==  replace                        :+][+:
         INVOKE (sect-line-fname)       :+][+:
         (out-pop)                      :+][+:

     ==  append                         :+][+:
         (out-push-add file-name)       :+][+:
         INVOKE (string-append "append-" macro-name) :+][+:
         (out-pop)                      :+][+:

     ==  insert                         :+][+:
         (set! fname-line (shellf "sed '1s/.Sh .*/.Pp/' %s" file-name)) :+][+:
         INVOKE (sect-line-fname)       :+][+:
         (emit fname-line)
         (out-pop)                      :+][+:

     # * -- otherwise, do nothing       :+][+:

     ESAC                               :+][+:

  ENDIF file existence/non-existence    :+][+:
ENDDEF cond-section

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - D E S C R I P T I O N
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-description                   :+][+:

  (if (exist? "prog-man-descrip")
      (stack-join "\n.Pp\n" "prog-man-descrip")
      (if (exist? "detail")
          (stack-join "\n.Pp\n" "detail")
          "There is no description for this command."
  )   )                                 :+]
[+:
  INVOKE append-description             :+][+:

ENDDEF mk-description

.\" = = = = = APPEND TO IT:             :+][+:

DEFINE append-description               :+][+:

IF (= (get "main.main-type") "for-each"):+][+:

  CASE main.handler-type                :+][+:
  ~* ^(name|file)|.*text               \:+]
.Pp
This program will perform its function for every file named on the command
line or every file named in a list read from stdin.  The arguments or input
names must be pre\-existing files.  The input list may contain comments,
which[+:

  !E                                   \:+]
.Pp
This program will perform its function for every command line argument
or every non\-comment line in a list read from stdin.
The input list comments[+:

  *                                     :+][+:
  (error "the 'for-each' main has in invalid handler-type.") :+][+:
  ESAC                                 \:+]
 are blank lines or lines beginning with a '[+:
  ?% comment-char "%s" "#" :+]' character.
[+:

ENDIF - "main" exists                   :+][+:
ENDDEF append-description

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - O P T I O N S
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-options

:+][+:

(define opt-arg       "")
(define dis-name      "")
(define opt-name      "")
(define optname-from  "A-Z_^")
(define optname-to    "a-z--")
(define cvt-cmd       "")
(define formatted-doc (exist? "option-doc-format"))

(if formatted-doc (begin
    (out-push-new)
    (set! cvt-cmd (string-append (get "option-doc-format") "2mdoc"))
)   )

(if (exist? "preserve-case")
   (begin
      (set! optname-from "_^")
      (set! optname-to   "--")
)  )

(define fix-optname (lambda (o_nm) (begin
   (set! o_nm (string-tr o_nm optname-from optname-to))
   (set! o_nm (string-substitute o_nm "-" "\\-" ))
   o_nm )))

(if (exist? "option-info")
    (string-append ".Pp\n" (get "option-info") "\n") )
\:+]
.Bl -tag[+:

FOR flag                              :+][+:
  IF (not (exist? "documentation"))   :+][+:
    IF (exist? "aliases")             :+][+:
      INVOKE emit-alias-opt           :+][+:
    ELSE                              :+][+:
      INVOKE emit-flag-text           :+][+:
    ENDIF                             :+][+:

  ELSE                                :+]
.Ss "[+: (get-cvt "descrip" "") :+]"[+:

    IF (set! tmp-str (get-cvt "documentation" ""))
       (> (string-length tmp-str) 3)  :+]
[+: (. tmp-str) :+]
[+: ENDIF                             :+][+:

  ENDIF                               :+][+:
ENDFOR flag

.\" = = = = = = = = = = = = = = = = =
.\"  help option
.\" = = = = = = = = = = = = = = = = =

:+]
.It [+:

  IF (. use-flags)  :+]\-[+: (get "help-value" "?") :+][+:
     (if (exist? "long-opts") " , \" \\-\\-help\"") :+][+:
  ELSE   :+][+:
     (if (exist? "long-opts") "\\-\\-") :+]help[+:
  ENDIF  :+]
Display usage information and exit.[+:#

.\" = = = = = = = = = = = = = = = = =
.\"  more-help option
.\" = = = = = = = = = = = = = = = = = :+][+:

  IF (not (exist? "no-libopts")) :+]
.It [+:

  IF (. use-flags)  :+]\-[+: ?% more-help-value "%s" "!" :+][+:
     IF (exist? "long-opts") :+] , " \-\-more-help"[+: ENDIF :+][+:
  ELSE   :+][+:
     IF (exist? "long-opts") :+]\-\-[+: ENDIF :+]more-help[+:
  ENDIF  :+]
Pass the extended usage information through a pager.[+:

ENDIF no no-libopts

.\" = = = = = = = = = = = = = = = = =
.\"  save and load configuration
.\" = = = = = = = = = = = = = = = = = :+][+:

IF (exist? "homerc") :+]
.It [+:

  IF (. use-flags)  :+]\-[+: ?% save-opts-value "%s" ">"
     :+] " [\fIrcfile\fP][+:
     IF (exist? "long-opts") :+]," " \-\-save-opts" "[=\fIrcfile\fP][+:
     ENDIF :+]"[+:
  ELSE     :+][+:
     IF (exist? "long-opts") :+]\-\-[+:
     ENDIF :+]save-opts "[=\fIrcfile\fP]"[+:
  ENDIF    :+]
Save the option state to \fIrcfile\fP.  The default is the \fIlast\fP
configuration file listed in the \fBOPTION PRESETS\fP section, below.
.It [+:

  IF (. use-flags)  :+]\-[+: ?% load-opts-value "%s" "<"
     :+] " \fIrcfile\fP[+:
     IF (exist? "long-opts")
           :+]," " \-\-load-opts" "=\fIrcfile\fP," " \-\-no-load-opts[+:
     ENDIF :+]"[+:
  ELSE     :+][+:
     IF (exist? "long-opts") :+]\-\-[+:
     ENDIF :+]load-opts "=\fIrcfile\fP," " \-\-no-load-opts"[+:
  ENDIF    :+]
Load options from \fIrcfile\fP.
The \fIno-load-opts\fP form will disable the loading
of earlier RC/INI files.  \fI\-\-no-load-opts\fP is handled early,
out of order.[+:
ENDIF (exist? "homerc")

.\" = = = = = = = = = = = = = = = = =
.\"  version
.\" = = = = = = = = = = = = = = = = = :+][+:

IF (exist? "version") :+]
.It [+:

  IF (. use-flags)  :+]\-[+: ?% version-value "%s" "v"
     :+] " [{\fIv|c|n\fP}][+:
     IF (exist? "long-opts") :+]," " \-\-version" "[=\fI{v|c|n}\fP][+:
     ENDIF :+]"[+:
  ELSE     :+][+:
     IF (exist? "long-opts") :+]\-\-[+:
     ENDIF :+]version "[=\fI{v|c|n}\fP]"[+:
  ENDIF    :+]
Output version of program and exit.  The default mode is `v', a simple
version.  The `c' mode will print copyright information and `n' will
print the full copyright notice.[+:
ENDIF                                 :+]
.El
[+:

(if formatted-doc
    (shell (string-append
    "fn='" (find-file cvt-cmd)
    "'\ntest -f ${fn} || die '" cvt-cmd " not found'\n"
    "${fn} <<\\_EndOfMdoc_ || die ${fn} failed in $PWD\n"
    (out-pop #t)
    "\n_EndOfMdoc_" )) )           :+][+:

ENDDEF mk-options

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - O P T I O N - P R E S E T S
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-option-presets              \:+]
Any option that is not marked as \fInot presettable\fP may be preset
by loading values from [+:
  IF (. home-rc-files)
    :+]configuration ("RC" or ".INI") file(s)[+:
    IF (. environ-init) :+] and values from
[+:
    ENDIF                             :+][+:
  ENDIF                               :+][+:
  IF (. environ-init) :+]environment variables named:
.nf
  \fB[+: (. UP-PROG-NAME) :+]_<option-name>\fP or \fB[+: (. UP-PROG-NAME) :+]\fP
.fi
.ad[+:
    IF (. home-rc-files)              :+]
The environmental presets take precedence (are processed later than)
the configuration files.[+:
    ENDIF                             :+][+:
  ELSE                                :+].[+:
  ENDIF                               :+][+:

  CASE
    (define rc-file
       (get "rcfile" (string-append "." (get "prog-name") "rc")) )
    (count "homerc")                  :+][+:

  == "0"                              :+][+:
  == "1"                              :+][+:

    CASE homerc                       :+][+:
    ~~ '\.|\$HOME'                    :+]
The file "\fI[+: (string-append (get "homerc") "/" rc-file)
:+]\fP" will be used, if present.[+:
    *                                 :+]
The \fIhomerc\fP file is "\fI[+:homerc:+]\fP", unless that is a directory.
In that case, the file "\fI[+: (. rc-file) :+]\fP"
is searched for within that directory.[+:
    ESAC                              :+][+:

  *                                   :+]
The \fIhomerc\fP files are [+:
    FOR homerc ", "                   :+][+:
      IF (last-for?)                  :+]and [+:
      ENDIF :+]"\fI[+: homerc :+]\fP"[+: ENDFOR :+].
If any of these are directories, then the file \fI[+: (. rc-file) :+]\fP
is searched for within those directories.[+:
  ESAC                                :+][+:

ENDDEF mk-option-presets

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - E X I T - S T A T U S
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-exit-status                \:+]
One of the following exit values will be returned:
.Bl -tag
[+:
(ag-fprintf 0 ".It 0 \" (EXIT_%s)\"\n%s\n"
    (string->c-name! (string-upcase (get "exit-name[0]" "SUCCESS")))
    (get-cvt "exit-desc[0]" "Successful program execution.") )

(define need-ex-noinput  (exist? "homerc"))
(define need-ex-software #t)

(ag-fprintf 0 ".It 1 \" (EXIT_%s)\"\n%s\n"
    (string->c-name! (string-upcase (get "exit-name[1]" "FAILURE")))
    (get-cvt "exit-desc[1]"
    "The operation failed or the command syntax was not valid.")) :+][+:

FOR exit-desc (for-from 2)            :+][+:
  (if (= (for-index) 66)
      (set! need-ex-noinput  #f)
      (if (= (for-index) 70)
          (set! need-ex-software #f) ))

  (set! tmp-str (get (sprintf "exit-name[%d]" (for-index)) "* unnamed *"))
  (sprintf ".It %d \" (EXIT_%s)\"\n%s\n"
    (for-index)
    (string-upcase (string->c-name! tmp-str))
    (get-cvt "exit-desc" ""))    :+][+:
ENDFOR exit-desc                      :+][+:
(if need-ex-noinput
    (emit ".It 66 \" (EX_NOINPUT)\"
A specified configuration file could not be loaded.\n"))

(if need-ex-noinput
    (emit ".It 70 \" (EX_SOFTWARE)\"
libopts had an internal operational error.  Please report
it to autogen-users@lists.sourceforge.net.  Thank you.\n"))

(if (> (string-length fname-line) 1)
    (emit fname-line)) :+]
.El
[+:

ENDDEF exit-status

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - A U T H O R S
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-authors                     :+][+:

  (define remove-authors #t)

  (set! tmp-val
      (if (exist? "copyright.author")
          (stack-join ",\n" "copyright.author")
          (stack-join ",\n" "copyright.owner") ))

  (if (> (string-length tmp-val) 1)
      (string-append tmp-val "\n")
      (delete-file file-name))

  :+][+:

ENDDEF mk-authors

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - B U G S
.\"
.\"  This section is guaranteed to be the last section in the man page
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-bugs                        :+][+:

    (set! tmp-val (get "copyright.eaddr" (get "eaddr")))
    (if (> (string-length tmp-val) 1)
        (string-append "Please send bug reports to: " tmp-val "\n")
        (delete-file file-name) )
    :+][+:

ENDDEF mk-bugs                        :+][+:

DEFINE append-bugs                    :+][+:

    (set! tmp-val (get "copyright.eaddr" (get "eaddr")))
    (if (> (string-length tmp-val) 1)
        (string-append "Please send bug reports to: " tmp-val "\n") )
    :+][+:

ENDDEF append-bugs

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - C O P Y R I G H T  (+ licensing)
.\"
.\"  This section is guaranteed to be the last section in the man page
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-copyright                    \:+]
Copyright (C) [+: copyright.date        :+] [+:
  (get "copyright.owner" (get "copyright.author" (get "copyright.eaddr")))
  :+] all rights reserved.
[+: CASE (get "copyright.type")         :+][+:
    = note  :+][+: (get "copyright.text") :+][+:
    == ''   :+]This program has an unspecified license.[+:

    *       :+][+:
    (string-append "This program is released under the terms of "
            (license-name (get "copyright.type")) ".")    :+][+:

  ESAC      :+]
[+:
ENDDEF mk-copyright

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - N O T E S
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-notes                       \:+]
This manual page was \fIAutoGen\fP-erated from the \fB[+: prog-name :+]\fP
option definitions.
[+:

ENDDEF mk-notes

.\" = = = = = APPEND TO IT:           :+][+:

DEFINE append-notes                  \:+]
.Pp
This manual page was \fIAutoGen\fP-erated from the \fB[+: prog-name :+]\fP
option definitions.[+:

ENDDEF append-notes

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - E N V I R O N M E N T
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-environment                 :+][+:
  INVOKE  append-environment          :+][+:
ENDDEF mk-environment

.\" = = = = = APPEND TO IT:           :+][+:

DEFINE append-environment             :+][+:
   (. environ-text)                   :+][+:
ENDDEF append-environment

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  M K - F I L E S
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE mk-files                       :+][+:
  INVOKE  append-files                :+][+:
ENDDEF mk-files

.\" = = = = = APPEND TO IT:           :+][+:

DEFINE append-files                   :+][+:
   (. home-rc-text)                   :+][+:
ENDDEF append-files

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  E M I T   A L I A S   O P T
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE emit-alias-opt                   :+]
.It [+:
  IF (exist? "value")                   :+][+:
    IF (exist? "long-opts")            \:+]
 \-[+:value:+] ", " -\-[+: name         :+][+:
    ELSE                               \:+]
 \-[+:value:+][+:
    ENDIF  (exist? "long-opts")         :+][+:

  ELSE  value does not exist -- named option only  :+][+:

    IF (not (exist? "long-opts"))      \:+]
 [+: name :+][+:
    ELSE                               \:+]
 \-\-[+: (. opt-name)                   :+][+:
    ENDIF                               :+][+:
  ENDIF                                 :+]
This is an alias for the [+: aliases :+] option.[+:
ENDDEF emit-alias-opt

.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.\"  E M I T   F L A G   T E X T
.\" = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = :+][+:

DEFINE emit-flag-text                 :+][+:

  (if (exist? "enable")
      (set! opt-name (string-append (get "enable") "-" (get "name")))
      (set! opt-name (get "name")) )
  (if (exist? "disable")
      (set! dis-name (string-append (get "disable") "-" (get "name")))
      (set! dis-name "") )

  (set! opt-name (fix-optname opt-name))
  (if (> (string-length dis-name) 0)
      (set! dis-name (fix-optname dis-name)) )

  (if (not (exist? "arg-type"))
      (set! opt-arg "")
      (set! opt-arg (string-append "\\fI"
            (fix-optname (if (exist? "arg-name")
                (get "arg-name")
                (string-downcase! (get "arg-type"))  ))
            "\\fP" ))
  )

:+]
.It [+:
  IF (exist? "value")                   :+][+:
    IF (exist? "long-opts")             :+][+:

          # * * * * * * * * * * * * * * * * * * * *
          *
          *  The option has a flag value (character) AND
          *  the program uses long options
          *
          \:+]
 \-[+:value:+][+:
      IF (not (exist? "arg-type"))      :+] ", " -\-[+:
      ELSE  :+] " [+:(. opt-arg):+], " \-\-[+:
      ENDIF :+][+: (. opt-name)         :+][+:
      IF (exist? "arg-type")            :+][+:
              ? arg-optional " [ =" ' "=" '
              :+][+:  (. opt-arg)       :+][+:
              arg-optional " ]"         :+][+:
      ENDIF                             :+][+:
      IF (exist? "disable") :+], " \fB\-\-[+:(. dis-name):+]\fP"[+:
      ENDIF                             :+][+:

    ELSE                                :+][+:

          # * * * * * * * * * * * * * * * * * * * *
          *
          *  The option has a flag value (character) BUT
          *  the program does _NOT_ use long options
          *
          \:+]
 \-[+:value:+][+:
      IF (exist? "arg-type")            :+][+:
            arg-optional "["     :+] "[+:(. opt-arg):+][+:
            arg-optional '"]"'          :+][+:
      ENDIF "                           :+][+:
    ENDIF  (exist? "long-opts")         :+][+:


  ELSE  value does not exist -- named option only  :+][+:

    IF (not (exist? "long-opts"))       :+][+:

          # * * * * * * * * * * * * * * * * * * * *
          *
          *  The option does not have a flag value (character).
          *  The program does _NOT_ use long options either.
          *  Special magic:  All arguments are named options.
          *
          \:+]
 [+: (. opt-name) :+][+:
      IF (exist? "arg-type")            :+] [+:
         ? arg-optional " [ =" ' "=" '
         :+][+:(. opt-arg)              :+][+:
         arg-optional "]"               :+][+:
      ENDIF:+][+:
      IF (exist? "disable") :+], " \fB[+:(. dis-name):+]\fP"[+:
      ENDIF                             :+][+:


    ELSE                                :+][+:
          # * * * * * * * * * * * * * * * * * * * *
          *
          *  The option does not have a flag value (character).
          *  The program, instead, only accepts long options.
          *
          \:+]
 \-\-[+: (. opt-name) :+][+:

      IF (exist? "arg-type") :+] "[+: #" :+][+:
            arg-optional "[" :+]=[+:(. opt-arg):+][+:
            arg-optional "]" :+]"[+: #" :+][+:
      ENDIF                             :+][+:

      IF (exist? "disable")
        :+], " \fB\-\-[+:(. dis-name):+]\fP"[+:
      ENDIF                             :+][+:
    ENDIF                               :+][+:
  ENDIF                                 :+]
[+: (get-cvt "descrip" "") :+].[+:

  IF (exist? "min")                     :+]
This option is required to appear.[+:
  ENDIF                                 :+][+:

  IF (exist? "max") :+]
This option may appear [+:
    IF % max (= "%s" "NOLIMIT")
      :+]an unlimited number of times[+:ELSE
      :+]up to [+: max :+] times[+:
    ENDIF:+].[+:
  ENDIF:+][+:

  IF (exist? "disable")               :+]
The \fI[+:(. dis-name):+]\fP form will [+:
    IF (exist? "stack-arg")
          :+]clear the list of option arguments[+:
    ELSE  :+]disable the option[+:
    ENDIF :+].[+:
  ENDIF:+][+:

  IF (exist? "enabled")               :+]
This option is enabled by default.[+:
  ENDIF                               :+][+:

  IF (exist? "no-preset")             :+]
This option may not be preset with environment variables
or in initialization (rc) files.[+:
  ENDIF                               :+][+:

  IF (and (exist? "default") named-mode) :+]
This option is the default option.[+:
  ENDIF                               :+][+:

  IF (exist? "equivalence")           :+]
This option is a member of the [+:equivalence:+] class of options.[+:
  ENDIF                               :+][+:

  IF (exist? "flags-must")            :+]
This option must appear in combination with the following options:
[+: FOR flags-must ", " :+][+:flags-must:+][+:ENDFOR:+].[+:
  ENDIF                               :+][+:

  IF (exist? "flags-cant")            :+]
This option must not appear in combination with any of the following options:
[+: FOR flags-cant ", " :+][+:flags-cant:+][+:ENDFOR:+].[+:
  ENDIF                               :+][+:


  IF (~* (get "arg-type") "key|set") :+]
This option takes a keyword as its argument[+:

    IF (=* (get "arg-type") "set")

:+] list.  Each entry turns on or off
membership bits.  The bits are set by name or numeric value and cleared
by preceding the name or number with an exclamation character ('!').
They can all be cleared with the magic name \fInone\fR and they can all be set
with
.IR all .
A single option will process a list of these values.[+:

    ELSE

:+].  The argument sets an enumeration value that can
be tested by comparing them against the option value macro.[+:

    ENDIF

:+]
The available keywords are:
.in +4
.nf
.na
[+: (shellf "${CLexe} --indent='' --spread=1 -W50 <<_EOF_\n%s\n_EOF_"
            (join "\n" (stack "keyword"))  )   :+]
.fi
or their numeric equivalent.
.in -4[+: (if (exist? "arg-default") "\n.sp" ) :+][+:

  ELIF (=* (get "arg-type") "num")    :+]
This option takes an integer number as its argument.[+:

    IF  (exist? "arg-range")          :+]
The value of [+:(. opt-arg):+] is constrained to being:
.in +4
.nf
.na[+:FOR arg_range ", or"            :+]
[+: (shellf "
range='%s'

case \"X${range}\" in
X'->'?*  )
  echo \"less than or equal to\" `
    echo $range | sed 's/->//' ` ;;

X?*'->'  )
  echo \"greater than or equal to\" `
    echo $range | sed 's/->.*//' ` ;;

X?*'->'?* )
  echo \"in the range \" `
    echo $range | sed 's/->/ through /' ` ;;

X?* )
  echo exactly $range ;;

X* ) echo $range is indeterminate
esac"

(get "arg-range") )
:+][+:
      ENDFOR arg-range :+]
.fi
.in -4[+:

    ENDIF  arg-range exists           :+][+:

  ENDIF  arg-type key/set/num         :+][+:

  IF (exist? "arg-default")           :+]
The default [+: (. opt-arg) :+] for this option is:
.ti +4
 [+: (join " + " (stack "arg-default" )) :+][+:
  ENDIF                               :+]
.sp
[+:
 (if (exist? "doc")
        (get-cvt "doc" "")
        "This option has not been fully documented." ) :+][+:
  IF (exist? "deprecated")            :+]
.sp
.B
NOTE: THIS OPTION IS DEPRECATED
.R[+:
  ENDIF                               :+][+:

ENDDEF emit-flag-text

.\" cmd-doc.tlib ends here \:+]