@@ -624,25 +624,6 @@ define method show-copyright (stream :: <stream>) => ()
624
624
format(stream, "Copyright 2005-2015 Dylan Hackers\n " );
625
625
end method show-copyright;
626
626
627
- define method show-usage (stream :: <stream>) => ()
628
- format(stream,
629
- "Usage: melange [-v] [--headers]\n "
630
- " [--Ttarget]\n "
631
- " [-Ddef[=val]...] [-Uundef...]\n "
632
- " [-Iincdir...] [--framework name...]\n "
633
- " [-m modulefile] infile [outfile]\n "
634
- " melange --defines\n "
635
- " melange --undefines\n "
636
- " melange --includes\n "
637
- " melange --help\n "
638
- " melange --version\n " );
639
- end method show-usage;
640
-
641
- define method show-usage-and-exit () => ()
642
- show-usage(*standard-error*);
643
- exit-application(1 );
644
- end method show-usage-and-exit;
645
-
646
627
define method show-default-defines (stream :: <stream>) => ()
647
628
for (i from 0 below $default-defines.size by 2 )
648
629
let name = $default-defines[i];
@@ -678,41 +659,6 @@ define method show-default-includes (stream :: <stream>) => ()
678
659
end for ;
679
660
end method show-default-includes;
680
661
681
- define method show-help (stream :: <stream>) => ()
682
- show-copyright(stream);
683
- format(stream, "\n " );
684
- show-usage(stream);
685
- format(stream, "\n "
686
- "Options:\n "
687
- " -v, --verbose Print progress messages while parsing.\n "
688
- " (Includes --headers.)\n "
689
- " --headers Print each header file included while parsing.\n "
690
- " -T, --target Generate output for use only with the named target.\n "
691
- " Target can be one of: c-ffi, mindy. Defaults to c-ffi.\n "
692
- " -D, --define Define a C preprocessor macro for use by C headers.\n "
693
- " If no value is given, defaults to 1.\n "
694
- " -U, --undefine Prevent definition of a default preprocessor macro.\n "
695
- " (Use --defines to see the defaults. Use --undefines to"
696
- " see the default undefines.)\n "
697
- " -I, --includedir Extra directories to search for C headers.\n "
698
- " --framework The name of a framework bundle to search for C headers\n "
699
- " and child frameworks. Required when a child framework\n "
700
- " is directly referred to in an interface definition\n "
701
- " with no previous references to its parent; once a\n "
702
- " parent is seen,either via this option or in a clause\n "
703
- " of the interface definition, its children will be\n "
704
- " found automatically. (Note: Parent --framework\n "
705
- " options must be given before child framework options.)\n "
706
- " -m, --module-file Create a Dylan interchange file with a module\n "
707
- " definition that exports the interface names.\n "
708
- " --defines Show the default C preprocessor definitions.\n "
709
- " --undefines Show the default platform undefinitions.\n "
710
- " --includes Show the default C preprocessor include directories.\n "
711
- " --help Show this help text.\n "
712
- " --version Show version number.\n "
713
- );
714
- end method show-help;
715
-
716
662
717
663
// ----------------------------------------------------------------------
718
664
// The main program
@@ -725,55 +671,85 @@ end method show-help;
725
671
726
672
define method main (program, args)
727
673
// Describe our arguments and create appropriate parser objects.
728
- let *argp* = make (<command-line-parser>);
729
- add-option(*argp*,
730
- make (<flag-option>,
731
- names: #("help" , "h" )));
674
+ let *argp* = make (<command-line-parser>,
675
+ help: "Melange" );
732
676
add-option(*argp*,
733
677
make (<flag-option>,
678
+ help: "Show copyright info." ,
734
679
names: #("version" )));
735
680
add-option(*argp*,
736
681
make (<flag-option>,
682
+ help: "Show the default C preprocessor definitions." ,
737
683
names: #("defines" )));
738
684
add-option(*argp*,
739
685
make (<flag-option>,
686
+ help: "Show the default platform undefinitions." ,
740
687
names: #("undefines" )));
741
688
add-option(*argp*,
742
689
make (<flag-option>,
690
+ help: "Show the default C preprocessor include directories." ,
743
691
names: #("includes" )));
744
692
add-option(*argp*,
745
693
make (<flag-option>,
694
+ help: "Print progress messages while parsing (includes --headers)." ,
746
695
names: #("verbose" , "v" )));
747
696
add-option(*argp*,
748
697
make (<flag-option>,
698
+ help: "Print each header file included while parsing." ,
749
699
names: #("headers" )));
750
700
add-option(*argp*,
751
701
make (<choice-option>,
702
+ help: "Generate output for use only with the named target. "
703
+ "Target can be one of: c-ffi, mindy. [%default%]" ,
752
704
names: #("target" , "T" ),
753
705
choices: #("c-ffi" , "mindy" ),
754
706
test: string-equal-ic?,
755
707
default: "c-ffi" ));
756
708
add-option(*argp*,
757
709
make (<parameter-option>,
710
+ help: "Create a Dylan interchange file with a module definition "
711
+ "that exports the interface names." ,
758
712
names: #("module-file" , "m" )));
759
713
add-option(*argp*,
760
714
make (<repeated-parameter-option>,
715
+ help: "Extra directories to search for C headers." ,
761
716
names: #("includedir" , "I" )));
762
717
add-option(*argp*,
763
718
make (<keyed-option>,
719
+ help: "Define a C preprocessor macro for use by C headers. "
720
+ "If no value is given, defaults to 1." ,
764
721
names: #("define" , "D" )));
765
722
add-option(*argp*,
766
723
make (<repeated-parameter-option>,
724
+ help: "Prevent definition of a default preprocessor macro. "
725
+ "(Use --defines to see the defaults. Use --undefines to "
726
+ "see the default undefines.)" ,
767
727
names: #("undefine" , "U" )));
768
728
add-option(*argp*,
769
729
make (<repeated-parameter-option>,
730
+ help: "The name of a framework bundle to search for C headers "
731
+ "and child frameworks. Required when a child framework is directly "
732
+ "referred to in an interface definition with no previous references "
733
+ "to its parent; once a parent is seen, either via this option or in "
734
+ "a clause of the interface definition, its children will be found "
735
+ "automatically. (Note: Parent --framework options must be given "
736
+ "before child framework options.)" ,
770
737
names: #("framework" )));
738
+ add-option(*argp*,
739
+ make (<positional-option>,
740
+ help: "Input file with interface specification." ,
741
+ names: #("infile" )));
742
+ add-option(*argp*,
743
+ make (<positional-option>,
744
+ help: "Output file for generated Dylan code." ,
745
+ names: #("outfile" ),
746
+ required?: #f ));
771
747
772
748
// Parse our command-line arguments.
773
749
block ()
774
750
parse-command-line(*argp*, args);
775
- exception (ex :: <usage -error>)
776
- show-usage-and- exit( );
751
+ exception (ex :: <abort-command -error>)
752
+ exit-application( 1 );
777
753
end ;
778
754
779
755
// Handle our informational options.
@@ -789,10 +765,6 @@ define method main (program, args)
789
765
show-default-includes(*standard-output*);
790
766
exit-application(0 );
791
767
end if ;
792
- if (get-option-value(*argp*, "help" ))
793
- show-help(*standard-output*);
794
- exit-application(0 );
795
- end if ;
796
768
if (get-option-value(*argp*, "version" ))
797
769
show-copyright(*standard-output*);
798
770
exit-application(0 );
@@ -806,7 +778,6 @@ define method main (program, args)
806
778
let include-dirs = get-option-value(*argp*, "includedir" );
807
779
let defines = get-option-value(*argp*, "define" );
808
780
let undefines = get-option-value(*argp*, "undefine" );
809
- let regular-args = positional-options(*argp*);
810
781
let framework-dirs = get-option-value(*argp*, "framework" );
811
782
812
783
// Handle --headers.
@@ -834,21 +805,13 @@ define method main (program, args)
834
805
end for ;
835
806
find-frameworks(*framework-paths*);
836
807
837
- // Handle regular arguments.
838
- let in-file = #f ;
839
- let out-file = #f ;
840
- select (regular-args.size )
841
- 1 =>
842
- in-file := regular-args[0 ];
843
- 2 =>
844
- in-file := regular-args[0 ];
845
- out-file := make (<file-stream>,
846
- locator: regular-args[1 ],
847
- direction: # "output" );
848
- otherwise =>
849
- show-usage-and-exit();
850
- end select ;
851
-
808
+ let in-file = get-option-value(*argp*, "infile" );
809
+ let out-file = get-option-value(*argp*, "outfile" );
810
+ if (out-file)
811
+ out-file := make (<file-stream>,
812
+ locator: out-file,
813
+ direction: # "output" );
814
+ end ;
852
815
let module-stream = module-file & make (<file-stream>,
853
816
locator: module-file,
854
817
direction: # "output" );
0 commit comments