mergelbl: init.
This commit is contained in:
parent
90eb998001
commit
0ea7d29134
3 changed files with 59 additions and 2 deletions
2
go.sum
2
go.sum
|
@ -1,2 +0,0 @@
|
|||
github.com/jienfak/goblin v0.0.0-20200524232316-580d70cbe1ba h1:wCB3lb+yf83W65Ol1l17vSmWSrGuCW38JY4Z3XH+Pv8=
|
||||
github.com/jienfak/goblin v0.0.0-20200524232316-580d70cbe1ba/go.mod h1:u1tkXwykxJiJntXSR8Cd96cVL6jJeaPjva3tnG8e5aw=
|
|
@ -18,6 +18,7 @@ import(
|
|||
"goblin/quote"
|
||||
"goblin/urlprs"
|
||||
"goblin/noext"
|
||||
"goblin/mergelbl"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -42,6 +43,7 @@ func main() {
|
|||
"quote" : quote.Run,
|
||||
"urlprs" : urlprs.Run,
|
||||
"noext" : noext.Run,
|
||||
"mergelbl" : mergelbl.Run,
|
||||
}
|
||||
|
||||
if binBase := path.Base(os.Args[0]) ; binBase != "goblin" {
|
57
mergelbl/main.go
Normal file
57
mergelbl/main.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package mergelbl
|
||||
|
||||
import(
|
||||
"os"
|
||||
"fmt"
|
||||
"bufio"
|
||||
"flag"
|
||||
"log"
|
||||
)
|
||||
|
||||
func
|
||||
Run(args []string) int {
|
||||
var(
|
||||
e error
|
||||
buf string
|
||||
)
|
||||
rsep := '\n'
|
||||
wsep := "\n"
|
||||
//del := ""
|
||||
status := 0
|
||||
arg0 := args[0]
|
||||
args = args[1:]
|
||||
flagSet := flag.NewFlagSet(arg0, flag.ExitOnError)
|
||||
flagSet.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "usage: %s <file1> <file2> .. [fileN]\n", arg0)
|
||||
flagSet.PrintDefaults()
|
||||
}
|
||||
flagSet.Parse(args)
|
||||
args = flagSet.Args()
|
||||
|
||||
files := make([]*os.File, len(args))
|
||||
for i, v := range args {
|
||||
files[i], e = os.Open(v)
|
||||
if e!=nil {
|
||||
log.Fatal(e)
|
||||
}
|
||||
}
|
||||
|
||||
rds := make([]*bufio.Reader, len(files))
|
||||
for i, v := range files {
|
||||
rds[i] = bufio.NewReader(v)
|
||||
}
|
||||
|
||||
for{
|
||||
s := ""
|
||||
for _, r := range rds{
|
||||
buf, e = r.ReadString(byte(rsep))
|
||||
if e!=nil {
|
||||
return 0
|
||||
}
|
||||
s += buf[:len(buf)-1]
|
||||
}
|
||||
fmt.Printf("%s%s", s, wsep)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
Loading…
Reference in a new issue