mirror of
https://github.com/golang/go
synced 2024-11-26 16:57:14 -07:00
7a706fb3d7
Make Fstat, Readdirnames, and Readdir methods on os.File. R=r DELTA=281 (79 added, 3 deleted, 199 changed) OCL=25891 CL=26130
59 lines
1.1 KiB
Go
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 (
|
|
"os";
|
|
"io";
|
|
"flag";
|
|
"fmt";
|
|
"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);
|
|
}
|
|
}
|