From da2a5042e9ad7a37126c65c809ab89867ade44fd Mon Sep 17 00:00:00 2001 From: surdeus Date: Wed, 8 Mar 2023 22:26:23 +0300 Subject: [PATCH] HOW DO THE FUCK THE PATHS WORK ON WINDOWS? --- app/mk/inc/std/install | 5 +++-- src/pathx/main.go | 13 ++++++++----- src/tool/mk/parse.go | 1 - src/tool/mkdir/mkdir.go | 16 ++++++++++------ src/tool/paths/main.go | 35 ++++++++++++++++++----------------- 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/app/mk/inc/std/install b/app/mk/inc/std/install index 40c1946..3c26cea 100644 --- a/app/mk/inc/std/install +++ b/app/mk/inc/std/install @@ -8,12 +8,13 @@ install-sh:VQ: build if test -d app ; then echo Installing application files... echo "'$APPDIR'" - mkdir -p $APPDIR/$PKG_NAME && cp -rf app/* $APPDIR/$PKG_NAME/ + echo `goblin paths app/* $APPDIR/$PKG_NAME/` + #goblin mkdir -p `goblin path $APPDIR/$PKG_NAME` && cp -rf `goblin paths app/* $APPDIR/$PKG_NAME/` echo Done installing application files fi if test -d exe ; then echo Installing executables... - mkdir -p $EXEDIR + goblin mkdir -p $EXEDIR cp -rf exe/* $EXEDIR/ files=`goblin basename $(ls exe)` for i in $files ; do diff --git a/src/pathx/main.go b/src/pathx/main.go index ddb0261..c692e4a 100644 --- a/src/pathx/main.go +++ b/src/pathx/main.go @@ -4,6 +4,7 @@ package pathx // paths. import ( + //"fmt" "path" fp "path/filepath" "strings" @@ -28,10 +29,10 @@ func From(p string) Path { return ret } - /* p = path.Clean(p) - if p[0] == '/' { - ret.IsAbs = true - } */ + p = path.Clean(p) + if p[0] == '/' { + ret.IsAbs = true + } p, _ = strings.CutSuffix(p, "/") svalues := strings.Split(p, "/") @@ -45,7 +46,9 @@ func From(p string) Path { } func FromReal(p string) Path { - return From(fp.ToSlash(p)) + ret := From(fp.ToSlash(p)) + //fmt.Println("from real:", ret) + return ret } func (v Value) IsValid() bool { diff --git a/src/tool/mk/parse.go b/src/tool/mk/parse.go index 552da6a..c75fb54 100644 --- a/src/tool/mk/parse.go +++ b/src/tool/mk/parse.go @@ -174,7 +174,6 @@ func parseRedirInclude(p *parser, t token) parserStateFun { 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) diff --git a/src/tool/mkdir/mkdir.go b/src/tool/mkdir/mkdir.go index 67c5458..217048f 100644 --- a/src/tool/mkdir/mkdir.go +++ b/src/tool/mkdir/mkdir.go @@ -1,9 +1,11 @@ package mkdir -import( +import ( + "flag" "fmt" "os" - "flag" + + "github.com/surdeus/goblin/src/pathx" ) func Run(args []string) { @@ -11,7 +13,7 @@ func Run(args []string) { args = args[1:] var ( parentFlag bool - modeArg int + modeArg int ) flagSet := flag.NewFlagSet(arg0, flag.ExitOnError) flagSet.BoolVar(&parentFlag, "p", false, "No error if existing, make parent as needed.") @@ -24,14 +26,16 @@ func Run(args []string) { args = flagSet.Args() if len(args) == 0 { flagSet.Usage() + os.Exit(1) } mode := os.FileMode(modeArg) - for _, path := range args { + for _, path := range args { var e error + pth := pathx.From(path).Real() if parentFlag { - e = os.MkdirAll(path, mode) + e = os.MkdirAll(pth, mode) } else { - e = os.Mkdir(path, mode) + e = os.Mkdir(pth, mode) } if e != nil { fmt.Fprintf(os.Stderr, "%s: %s.\n", arg0, e) diff --git a/src/tool/paths/main.go b/src/tool/paths/main.go index 6c494e0..752ceb5 100644 --- a/src/tool/paths/main.go +++ b/src/tool/paths/main.go @@ -1,31 +1,33 @@ package paths import ( - "fmt" - "flag" "bufio" - "os" - "github.com/surdeus/goblin/src/pathx" - "path" - "log" "errors" + "flag" + "fmt" + "log" + "os" + "path" + + "github.com/surdeus/goblin/src/pathx" ) var ( - part string - handlers = map[string] func(string) string { - "base" : path.Base, - "ext" : path.Ext, - "dir" : path.Dir, - "all" : func(v string) string {return v}, + part string + handlers = map[string]func(string) string{ + "base": path.Base, + "ext": path.Ext, + "dir": path.Dir, + "all": func(v string) string { return v }, + "fr": func(v string) string { + return pathx.FromReal(v).String() + }, } - handler func(string) string - r bool + handler func(string) string + r bool noPartErr = errors.New("no such part") ) - - func handlePath(p string) { if handler != nil { p = handler(p) @@ -63,4 +65,3 @@ func Run(args []string) { handlePath(rd.Text()) } } -