ln implemented.

This commit is contained in:
Andrey Parhomenko 2023-03-08 16:39:50 +03:00
parent 5140f3591b
commit afa0e736bd
6 changed files with 120 additions and 67 deletions

View file

@ -7,6 +7,7 @@ install-sh:VQ: build
fi
if test -d app ; then
echo Installing application files...
echo "'$APPDIR'"
mkdir -p $APPDIR/$PKG_NAME && cp -rf app/* $APPDIR/$PKG_NAME/
echo Done installing application files
fi

View file

@ -1,66 +1,67 @@
package main
import(
mtool "github.com/surdeus/gomtool/src/multitool"
import (
"github.com/surdeus/goblin/src/tool/awk"
"github.com/surdeus/goblin/src/tool/basename"
"github.com/surdeus/goblin/src/tool/cat"
"github.com/surdeus/goblin/src/tool/date"
"github.com/surdeus/goblin/src/tool/ec"
"github.com/surdeus/goblin/src/tool/echo"
"github.com/surdeus/goblin/src/tool/mkdir"
"github.com/surdeus/goblin/src/tool/gtrue"
"github.com/surdeus/goblin/src/tool/ftest"
"github.com/surdeus/goblin/src/tool/gfalse"
"github.com/surdeus/goblin/src/tool/grange"
"github.com/surdeus/goblin/src/tool/gtrue"
"github.com/surdeus/goblin/src/tool/in"
"github.com/surdeus/goblin/src/tool/ln"
"github.com/surdeus/goblin/src/tool/ls"
"github.com/surdeus/goblin/src/tool/mergelbl"
"github.com/surdeus/goblin/src/tool/mk"
"github.com/surdeus/goblin/src/tool/mkdir"
"github.com/surdeus/goblin/src/tool/noext"
"github.com/surdeus/goblin/src/tool/path"
"github.com/surdeus/goblin/src/tool/paths"
"github.com/surdeus/goblin/src/tool/quote"
"github.com/surdeus/goblin/src/tool/read"
"github.com/surdeus/goblin/src/tool/sort"
"github.com/surdeus/goblin/src/tool/tac"
"github.com/surdeus/goblin/src/tool/ls"
"github.com/surdeus/goblin/src/tool/yes"
"github.com/surdeus/goblin/src/tool/date"
"github.com/surdeus/goblin/src/tool/uniq"
"github.com/surdeus/goblin/src/tool/quote"
"github.com/surdeus/goblin/src/tool/urlprs"
"github.com/surdeus/goblin/src/tool/noext"
"github.com/surdeus/goblin/src/tool/mergelbl"
"github.com/surdeus/goblin/src/tool/basename"
"github.com/surdeus/goblin/src/tool/ec"
"github.com/surdeus/goblin/src/tool/read"
"github.com/surdeus/goblin/src/tool/wc"
"github.com/surdeus/goblin/src/tool/ftest"
"github.com/surdeus/goblin/src/tool/grange"
"github.com/surdeus/goblin/src/tool/in"
"github.com/surdeus/goblin/src/tool/useprog"
"github.com/surdeus/goblin/src/tool/path"
"github.com/surdeus/goblin/src/tool/mk"
"github.com/surdeus/goblin/src/tool/awk"
"github.com/surdeus/goblin/src/tool/paths"
"github.com/surdeus/goblin/src/tool/wc"
"github.com/surdeus/goblin/src/tool/whoami"
"github.com/surdeus/goblin/src/tool/yes"
mtool "github.com/surdeus/gomtool/src/multitool"
)
func main() {
tools := mtool.Tools {
"basename" : mtool.Tool{basename.Run, "get base name of file path"},
tools := mtool.Tools{
"basename": mtool.Tool{basename.Run, "get base name of file path"},
"cat": mtool.Tool{cat.Run, "print file data to the standard output"},
"mkdir" : mtool.Tool{mkdir.Run, "make new directory"},
"echo" : mtool.Tool{echo.Run, "print strings to the standard output"},
"true" : mtool.Tool{gtrue.Run, "exit with true status"},
"false" : mtool.Tool{gfalse.Run, "exit with false status"},
"sort" : mtool.Tool{sort.Run, "sort strings inputed from standard input"},
"tac" : mtool.Tool{tac.Run, "print strings from standard input in reversed order"},
"ls" :mtool.Tool{ ls.Run, "list directory content"},
"yes" : mtool.Tool{ yes.Run, "print string infinite/exact amount times"},
"date" : mtool.Tool{date.Run, "print current date"},
"uniq" : mtool.Tool{uniq.Run, "filter repeated strings"},
"quote" : mtool.Tool{quote.Run, "quote words containing space characters"},
"urlprs" : mtool.Tool{urlprs.Run, "parse URLs"},
"noext" : mtool.Tool{noext.Run, "print file path without extension"},
"mergelbl" : mtool.Tool{mergelbl.Run, "merge line by line"},
"ec" : mtool.Tool{ec.Run, "render escape sequences"},
"read" : mtool.Tool{read.Run, "read lines and exit"},
"wc" : mtool.Tool{wc.Run, "count words, bytes, runes etc"},
"ftest" : mtool.Tool{ftest.Run, "filter files by specified features"},
"range" : mtool.Tool{grange.Run, "too lazy"},
"in" : mtool.Tool{in.Run, "filter strings from stdin that aren not in arguments"},
"useprog" : mtool.Tool{useprog.Run, "print the name of the first existing program in arg list"},
"path" : mtool.Tool{path.Run, "print cross platform path based on cmd arguments"},
"mk" : mtool.Tool{mk.Run, "file dependency system, simpler make"},
"awk" : mtool.Tool{awk.Run, "simple scripting language for working with string templates"},
"paths" : mtool.Tool{
"mkdir": mtool.Tool{mkdir.Run, "make new directory"},
"echo": mtool.Tool{echo.Run, "print strings to the standard output"},
"true": mtool.Tool{gtrue.Run, "exit with true status"},
"false": mtool.Tool{gfalse.Run, "exit with false status"},
"sort": mtool.Tool{sort.Run, "sort strings inputed from standard input"},
"tac": mtool.Tool{tac.Run, "print strings from standard input in reversed order"},
"ls": mtool.Tool{ls.Run, "list directory content"},
"yes": mtool.Tool{yes.Run, "print string infinite/exact amount times"},
"date": mtool.Tool{date.Run, "print current date"},
"uniq": mtool.Tool{uniq.Run, "filter repeated strings"},
"quote": mtool.Tool{quote.Run, "quote words containing space characters"},
"urlprs": mtool.Tool{urlprs.Run, "parse URLs"},
"noext": mtool.Tool{noext.Run, "print file path without extension"},
"mergelbl": mtool.Tool{mergelbl.Run, "merge line by line"},
"ec": mtool.Tool{ec.Run, "render escape sequences"},
"read": mtool.Tool{read.Run, "read lines and exit"},
"wc": mtool.Tool{wc.Run, "count words, bytes, runes etc"},
"ftest": mtool.Tool{ftest.Run, "filter files by specified features"},
"range": mtool.Tool{grange.Run, "too lazy"},
"in": mtool.Tool{in.Run, "filter strings from stdin that aren not in arguments"},
"useprog": mtool.Tool{useprog.Run, "print the name of the first existing program in arg list"},
"path": mtool.Tool{path.Run, "print cross platform path based on cmd arguments"},
"mk": mtool.Tool{mk.Run, "file dependency system, simpler make"},
"awk": mtool.Tool{awk.Run, "simple scripting language for working with string templates"},
"paths": mtool.Tool{
paths.Run,
"convert UNIX slash separated paths into the OS compatible ones",
},
@ -68,6 +69,10 @@ func main() {
whoami.Run,
"print current user name",
},
"ln": mtool.Tool{
ln.Run,
"link files",
},
}
mtool.Main("goblin", tools)

View file

@ -4,8 +4,8 @@ package pathx
// paths.
import (
fp "path/filepath"
"path"
fp "path/filepath"
"strings"
)
@ -28,10 +28,10 @@ func From(p string) Path {
return ret
}
p = path.Clean(p)
/* p = path.Clean(p)
if p[0] == '/' {
ret.IsAbs = true
}
} */
p, _ = strings.CutSuffix(p, "/")
svalues := strings.Split(p, "/")
@ -44,6 +44,10 @@ func From(p string) Path {
return ret
}
func FromReal(p string) Path {
return From(fp.ToSlash(p))
}
func (v Value) IsValid() bool {
return v.Err() == nil
}
@ -66,11 +70,17 @@ func (p Path) StringValues() []string {
}
func (p Path) Real() string {
return fp.Join(p.StringValues()...)
return strings.Join(p.StringValues(), string(fp.Separator))
}
func (p Path) String() string {
return path.Join(p.StringValues()...)
ret := ""
if p.IsAbs {
ret = "/"
}
ret += path.Join(p.StringValues()...)
return ret
}
func (p Path) IsValid() bool {
@ -92,4 +102,3 @@ func (p Path) Err() error {
return nil
}

35
src/tool/ln/main.go Normal file
View file

@ -0,0 +1,35 @@
package ln
import (
"flag"
"fmt"
"os"
)
func Run(args []string) {
var lflag bool
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
flagSet.BoolVar(&lflag, "s", false, "make a symbolic link, not a hard one")
flagSet.Parse(args[1:])
args = flagSet.Args()
if len(args) != 2 {
flagSet.Usage()
os.Exit(1)
}
src := args[0]
dst := args[1]
var err error
if lflag {
err = os.Symlink(src, dst)
} else {
err = os.Link(src, dst)
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
}

View file

@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"sync"
"github.com/surdeus/goblin/src/pathx"
)
@ -93,7 +94,6 @@ const (
)
// Build a node's prereqs. Block until completed.
//
func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool,
required bool) nodeStatus {
prereqstat := make(chan nodeStatus)
@ -131,11 +131,11 @@ func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool,
// concurrently.
//
// Args:
//
// g: Graph in which the node lives.
// u: Node to (possibly) build.
// dryrun: Don't actually build anything, just pretend.
// required: Avoid building this node, unless its prereqs are out of date.
//
func mkNode(g *graph, u *node, dryrun bool, required bool) {
// try to claim on this node
u.mutex.Lock()
@ -327,10 +327,10 @@ func Run(args []string) {
arg0 := args[0]
args = args[1:]
if mkincdir := os.Getenv("MKINCDIR") ;
mkincdir == "" {
if mkincdir := os.Getenv("MKINCDIR"); mkincdir == "" {
homeDir, _ := os.UserHomeDir()
os.Setenv("MKINCDIR", homeDir + "/app/goblin/mk/inc" )
homeDir = pathx.FromReal(homeDir).String()
os.Setenv("MKINCDIR", homeDir+"/app/goblin/mk/inc")
}
flags := flag.NewFlagSet(arg0, flag.ExitOnError)

View file

@ -10,6 +10,7 @@ import (
"path/filepath"
"regexp"
"strings"
"github.com/surdeus/goblin/src/pathx"
)
@ -169,9 +170,11 @@ func parseRedirInclude(p *parser, t token) parserStateFun {
true,
)[0]
}
file, err := os.Open(pathx.From(filename).Real())
pths := pathx.From(filename)
file, err := os.Open(pths.Real())
if err != nil {
p.basicWarnAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
//fmt.Printf("%q %q %q\n", pths.Values, pths.Real(), pths.String())
//p.basicErrorAtToken(fmt.Sprintf("cannot open %s", filename), p.tokenbuf[0])
}
input, _ := io.ReadAll(file)