2008-09-18 17:58:37 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import Flag "flag"
|
|
|
|
import Platform "platform"
|
|
|
|
import Printer "printer"
|
2008-10-24 15:04:54 -06:00
|
|
|
import Compilation "compilation"
|
2008-09-18 17:58:37 -06:00
|
|
|
|
|
|
|
|
|
|
|
var (
|
2008-10-24 15:04:54 -06:00
|
|
|
flags Compilation.Flags;
|
2008-10-18 17:42:25 -06:00
|
|
|
silent = Flag.Bool("s", false, nil, "silent mode: no pretty print output");
|
2008-10-24 15:04:54 -06:00
|
|
|
verbose = Flag.Bool("v", false, &flags.verbose, "verbose mode: trace parsing");
|
|
|
|
sixg = Flag.Bool("6g", true, &flags.sixg, "6g compatibility mode");
|
|
|
|
deps = Flag.Bool("d", false, &flags.deps, "print dependency information only");
|
|
|
|
columns = Flag.Bool("columns", Platform.USER == "gri", &flags.columns, "print column info in error messages");
|
|
|
|
testmode = Flag.Bool("t", false, &flags.testmode, "test mode: interprets /* ERROR */ and /* SYNC */ comments");
|
|
|
|
tokenchan = Flag.Bool("token_chan", false, &flags.tokenchan, "use token channel for scanner-parser connection");
|
2008-09-18 17:58:37 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2008-09-19 13:12:28 -06:00
|
|
|
func Usage() {
|
|
|
|
print("usage: pretty { flags } { files }\n");
|
|
|
|
Flag.PrintDefaults();
|
|
|
|
sys.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-18 17:58:37 -06:00
|
|
|
func main() {
|
|
|
|
Flag.Parse();
|
|
|
|
|
2008-09-19 13:12:28 -06:00
|
|
|
if Flag.NFlag() == 0 && Flag.NArg() == 0 {
|
|
|
|
Usage();
|
|
|
|
}
|
|
|
|
|
2008-09-18 17:58:37 -06:00
|
|
|
// process files
|
|
|
|
for i := 0; i < Flag.NArg(); i++ {
|
2008-10-17 00:30:42 -06:00
|
|
|
src_file := Flag.Arg(i);
|
2008-09-18 17:58:37 -06:00
|
|
|
|
2008-10-24 15:04:54 -06:00
|
|
|
if flags.deps {
|
2008-10-26 22:32:30 -06:00
|
|
|
Compilation.ComputeDeps(src_file, &flags);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
prog, nerrors := Compilation.Compile(src_file, &flags);
|
|
|
|
if nerrors > 0 {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if !silent.BVal() && !flags.testmode {
|
2008-11-26 14:23:26 -07:00
|
|
|
Printer.Print(prog);
|
2008-10-26 22:32:30 -06:00
|
|
|
}
|
2008-09-23 17:40:12 -06:00
|
|
|
}
|
2008-09-18 17:58:37 -06:00
|
|
|
}
|
|
|
|
}
|