diff --git a/main.go b/main.go index 57b2913..b1d8f4b 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,10 @@ package main import ( + "flag" "fmt" "os" - "strings" + //"strings" "code.miflux.com/hyung-hwan/hcl/go" ) @@ -26,9 +27,17 @@ var SYSCONFDIR = "." type Param struct { log_file string input_file string + heapsize uint + modlibdirs string + fs_usage func() +} + +func empty_usage() { + } func handle_arguments(param *Param) error { + /* var nargs int = len(os.Args) var i int @@ -51,6 +60,36 @@ func handle_arguments(param *Param) error { param.input_file = os.Args[i] return nil + */ + var fs *flag.FlagSet + var heapsize *uint + var modlibdirs *string + var log *string + var err error + + fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) + + heapsize = fs.Uint("heapsize", 0, "specify heap size") + modlibdirs = fs.String("modlibdirs", "", "specify module library directories") + log = fs.String("log", "", "specify log file") + + param.fs_usage = fs.Usage + fs.Usage = empty_usage // i don't want fs.Parse() print the usage + err = fs.Parse(os.Args[1:]) + fs.Usage = param.fs_usage // restore it + if err != nil { + return fmt.Errorf("command line error - %s", err.Error()) + } + + if fs.NArg() != 1 { + return fmt.Errorf("no input file or too many input files specified") + } + + param.input_file = fs.Arg(0); + param.log_file = *log // TODO: parse the option part (e.g. --log /dev/stderr,debug+) + param.heapsize = *heapsize // TODO: set this to hcl + param.modlibdirs = *modlibdirs // TODO: set this to hcl + return nil; } func main() { @@ -66,6 +105,7 @@ func main() { err = handle_arguments(¶m) if err != nil { fmt.Printf("Error: %s\n", err.Error()) + param.fs_usage() os.Exit(1) } diff --git a/t/Makefile.am b/t/Makefile.am index 39a5cc1..e3f6296 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -32,8 +32,10 @@ TESTS = $(check_PROGRAMS) $(check_SCRIPTS) $(check_ERRORS) TEST_EXTENSIONS = .hcl .err -HCL_LOG_COMPILER = $(SHELL) $(abs_srcdir)/run.sh ../bin/hcl --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 +HCLBIN = ../bin/hcl + +HCL_LOG_COMPILER = $(SHELL) $(abs_srcdir)/run.sh $(HCLBIN) --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 AM_HCL_LOG_FLAGS = -ERR_LOG_COMPILER = $(SHELL) $(abs_srcdir)/err.sh ../bin/hcl --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 +ERR_LOG_COMPILER = $(SHELL) $(abs_srcdir)/err.sh $(HCLBIN) --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 AM_ERR_LOG_FLAGS = diff --git a/t/Makefile.in b/t/Makefile.in index c194be3..765eae4 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -497,9 +497,10 @@ check_ERRORS = \ EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS) TEST_EXTENSIONS = .hcl .err -HCL_LOG_COMPILER = $(SHELL) $(abs_srcdir)/run.sh ../bin/hcl --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 +HCLBIN = ../bin/hcl +HCL_LOG_COMPILER = $(SHELL) $(abs_srcdir)/run.sh $(HCLBIN) --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 AM_HCL_LOG_FLAGS = -ERR_LOG_COMPILER = $(SHELL) $(abs_srcdir)/err.sh ../bin/hcl --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 +ERR_LOG_COMPILER = $(SHELL) $(abs_srcdir)/err.sh $(HCLBIN) --modlibdirs="@abs_top_builddir@/mod:@abs_top_builddir@/mod/.libs" --heapsize=0 AM_ERR_LOG_FLAGS = all: all-am