diff --git a/go.sum b/go.sum deleted file mode 100644 index cc09fc4..0000000 --- a/go.sum +++ /dev/null @@ -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= diff --git a/goblin.go b/main.go similarity index 95% rename from goblin.go rename to main.go index 5f1139d..62247c4 100644 --- a/goblin.go +++ b/main.go @@ -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" { diff --git a/mergelbl/main.go b/mergelbl/main.go new file mode 100644 index 0000000..aeed434 --- /dev/null +++ b/mergelbl/main.go @@ -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 .. [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 +} +