1
0
mirror of https://github.com/golang/go synced 2024-11-23 10:20:03 -07:00
go/usr/gri/pretty/pretty.go
Robert Griesemer eba73552d2 - added simple facility to print Makefile dependency rules given a Go source file
(e.g.: pretty -d pretty.go will print the Makefile dep. rules of the involved
  Go files that are not part of the installed library)
- minor fix in pretty printer (tested against ken's test files)

R=r
OCL=17872
CL=17872
2008-10-26 21:32:30 -07:00

58 lines
1.5 KiB
Go

// 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"
import Compilation "compilation"
var (
flags Compilation.Flags;
silent = Flag.Bool("s", false, nil, "silent mode: no pretty print output");
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");
)
func Usage() {
print("usage: pretty { flags } { files }\n");
Flag.PrintDefaults();
sys.exit(0);
}
func main() {
Flag.Parse();
if Flag.NFlag() == 0 && Flag.NArg() == 0 {
Usage();
}
// process files
for i := 0; i < Flag.NArg(); i++ {
src_file := Flag.Arg(i);
if flags.deps {
Compilation.ComputeDeps(src_file, &flags);
} else {
prog, nerrors := Compilation.Compile(src_file, &flags);
if nerrors > 0 {
return;
}
if !silent.BVal() && !flags.testmode {
var P Printer.Printer;
(&P).Program(prog);
}
}
}
}