1
0
mirror of https://github.com/golang/go synced 2024-11-26 15:16:54 -07:00
go/usr/gri/pretty/untab.go
Russ Cox 1f6463f823 Convert go tree to hierarchical pkg directory:
import (
		"vector" -> "container/vector"
		"ast" -> "go/ast"
		"sha1" -> "hash/sha1"
		etc.
	)

and update Makefiles.  Because I did the conversion
semi-automatically, I sorted all the import blocks
as a post-processing.  Some files have therefore
changed that didn't strictly need to.

Rename local packages to lower case.
The upper/lower distinction doesn't work on OS X
and complicates the "single-package directories
with the same package name as directory name"
heuristic used by gobuild and godoc to create
the correlation between source and binary locations.
Now that we have a plan to avoid globally unique
names, the upper/lower is unnecessary.

The renamings will cause trouble for a few users,
but so will the change in import paths.
This way, the two maintenance fixes are rolled into
one inconvenience.

R=r
OCL=27573
CL=27575
2009-04-16 20:52:37 -07:00

59 lines
1.1 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";
"fmt";
"io";
"os";
"tabwriter";
)
var (
tabwidth = flag.Int("tabwidth", 4, "tab width");
usetabs = flag.Bool("usetabs", false, "align with tabs instead of blanks");
)
func error(format string, params ...) {
fmt.Printf(format, params);
sys.Exit(1);
}
func untab(name string, src *os.File, dst *tabwriter.Writer) {
n, err := io.Copy(src, dst);
if err != nil {
error("error while processing %s (%v)", name, err);
}
//dst.Flush();
}
func main() {
flag.Parse();
padchar := byte(' ');
if *usetabs {
padchar = '\t';
}
dst := tabwriter.NewWriter(os.Stdout, *tabwidth, 1, padchar, 0);
if flag.NArg() > 0 {
for i := 0; i < flag.NArg(); i++ {
name := flag.Arg(i);
src, err := os.Open(name, os.O_RDONLY, 0);
if err != nil {
error("could not open %s (%v)\n", name, err);
}
untab(name, src, dst);
src.Close(); // ignore errors
}
} else {
// no files => use stdin
untab("/dev/stdin", os.Stdin, dst);
}
}