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 fi
if test -d app ; then if test -d app ; then
echo Installing application files... echo Installing application files...
echo "'$APPDIR'"
mkdir -p $APPDIR/$PKG_NAME && cp -rf app/* $APPDIR/$PKG_NAME/ mkdir -p $APPDIR/$PKG_NAME && cp -rf app/* $APPDIR/$PKG_NAME/
echo Done installing application files echo Done installing application files
fi fi

View file

@ -1,35 +1,36 @@
package main package main
import ( import (
mtool "github.com/surdeus/gomtool/src/multitool" "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/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/echo"
"github.com/surdeus/goblin/src/tool/mkdir" "github.com/surdeus/goblin/src/tool/ftest"
"github.com/surdeus/goblin/src/tool/gtrue"
"github.com/surdeus/goblin/src/tool/gfalse" "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/sort"
"github.com/surdeus/goblin/src/tool/tac" "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/uniq"
"github.com/surdeus/goblin/src/tool/quote"
"github.com/surdeus/goblin/src/tool/urlprs" "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/useprog"
"github.com/surdeus/goblin/src/tool/path" "github.com/surdeus/goblin/src/tool/wc"
"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/whoami" "github.com/surdeus/goblin/src/tool/whoami"
"github.com/surdeus/goblin/src/tool/yes"
mtool "github.com/surdeus/gomtool/src/multitool"
) )
func main() { func main() {
@ -68,6 +69,10 @@ func main() {
whoami.Run, whoami.Run,
"print current user name", "print current user name",
}, },
"ln": mtool.Tool{
ln.Run,
"link files",
},
} }
mtool.Main("goblin", tools) mtool.Main("goblin", tools)

View file

@ -4,8 +4,8 @@ package pathx
// paths. // paths.
import ( import (
fp "path/filepath"
"path" "path"
fp "path/filepath"
"strings" "strings"
) )
@ -28,10 +28,10 @@ func From(p string) Path {
return ret return ret
} }
p = path.Clean(p) /* p = path.Clean(p)
if p[0] == '/' { if p[0] == '/' {
ret.IsAbs = true ret.IsAbs = true
} } */
p, _ = strings.CutSuffix(p, "/") p, _ = strings.CutSuffix(p, "/")
svalues := strings.Split(p, "/") svalues := strings.Split(p, "/")
@ -44,6 +44,10 @@ func From(p string) Path {
return ret return ret
} }
func FromReal(p string) Path {
return From(fp.ToSlash(p))
}
func (v Value) IsValid() bool { func (v Value) IsValid() bool {
return v.Err() == nil return v.Err() == nil
} }
@ -66,11 +70,17 @@ func (p Path) StringValues() []string {
} }
func (p Path) Real() string { func (p Path) Real() string {
return fp.Join(p.StringValues()...) return strings.Join(p.StringValues(), string(fp.Separator))
} }
func (p Path) String() string { 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 { func (p Path) IsValid() bool {
@ -92,4 +102,3 @@ func (p Path) Err() error {
return nil 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" "path/filepath"
"strings" "strings"
"sync" "sync"
"github.com/surdeus/goblin/src/pathx" "github.com/surdeus/goblin/src/pathx"
) )
@ -93,7 +94,6 @@ const (
) )
// Build a node's prereqs. Block until completed. // Build a node's prereqs. Block until completed.
//
func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool, func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool,
required bool) nodeStatus { required bool) nodeStatus {
prereqstat := make(chan nodeStatus) prereqstat := make(chan nodeStatus)
@ -131,11 +131,11 @@ func mkNodePrereqs(g *graph, u *node, e *edge, prereqs []*node, dryrun bool,
// concurrently. // concurrently.
// //
// Args: // Args:
//
// g: Graph in which the node lives. // g: Graph in which the node lives.
// u: Node to (possibly) build. // u: Node to (possibly) build.
// dryrun: Don't actually build anything, just pretend. // dryrun: Don't actually build anything, just pretend.
// required: Avoid building this node, unless its prereqs are out of date. // required: Avoid building this node, unless its prereqs are out of date.
//
func mkNode(g *graph, u *node, dryrun bool, required bool) { func mkNode(g *graph, u *node, dryrun bool, required bool) {
// try to claim on this node // try to claim on this node
u.mutex.Lock() u.mutex.Lock()
@ -327,9 +327,9 @@ func Run(args []string) {
arg0 := args[0] arg0 := args[0]
args = args[1:] args = args[1:]
if mkincdir := os.Getenv("MKINCDIR") ; if mkincdir := os.Getenv("MKINCDIR"); mkincdir == "" {
mkincdir == "" {
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
homeDir = pathx.FromReal(homeDir).String()
os.Setenv("MKINCDIR", homeDir+"/app/goblin/mk/inc") os.Setenv("MKINCDIR", homeDir+"/app/goblin/mk/inc")
} }

View file

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