diff options
Diffstat (limited to 'gils')
| -rw-r--r-- | gils/cat.rv | 2 | ||||
| -rw-r--r-- | gils/cp.rv | 4 | ||||
| -rw-r--r-- | gils/ed.rv | 4 | ||||
| -rw-r--r-- | gils/gils.rv | 20 | ||||
| -rw-r--r-- | gils/head.rv | 2 | ||||
| -rw-r--r-- | gils/ls.rv | 2 | ||||
| -rw-r--r-- | gils/mkdir.rv | 2 | ||||
| -rw-r--r-- | gils/mv.rv | 4 | ||||
| -rw-r--r-- | gils/rm.rv | 2 | ||||
| -rw-r--r-- | gils/tail.rv | 2 | ||||
| -rw-r--r-- | gils/touch.rv | 2 | ||||
| -rw-r--r-- | gils/tree.rv | 2 | ||||
| -rw-r--r-- | gils/wc.rv | 2 |
13 files changed, 25 insertions, 25 deletions
diff --git a/gils/cat.rv b/gils/cat.rv index 1cca54b..220ce93 100644 --- a/gils/cat.rv +++ b/gils/cat.rv @@ -4,7 +4,7 @@ const context = env.ctx const parsed = arg_name(context.rest, 0) if parsed.name:len() == 0 do puts("usage: cat <path>\n") end else do - const path = abspath(parsed.name) + const path = expand_path(parsed.name) if vfs_owns(path) do vfs_cat(path) end else do fs:cat(path) end end @@ -4,8 +4,8 @@ const context = env.ctx if context.argv:len() < 3 do puts("usage: cp <source> <destination>\n") end else do - const source = abspath(context.argv[1]) - const destination = abspath(context.argv[2]) + const source = expand_path(context.argv[1]) + const destination = expand_path(context.argv[2]) const size = fs:size(source) if size < 0 do puts("cp: #{source}: no such file\n") end else do @@ -112,7 +112,7 @@ fn ed_write(state, command) do let path = state.path if command:len() > 1 do const filename = command[1..]:trim() - if filename:len() > 0 do path = abspath(filename) end + if filename:len() > 0 do path = expand_path(filename) end end if path:len() == 0 do puts("?\n") return :nil end const contents = ed_join(state.lines) @@ -134,7 +134,7 @@ fn gils_ed(context) do ed_state.input = :false ed_state.dirty = :false ed_state.lines = {} - ed_state.path = if context.argv:len() > 1 abspath(context.argv[1]) else "" + ed_state.path = if context.argv:len() > 1 expand_path(context.argv[1]) else "" if ed_state.path:len() > 0 do const size = fs:size(ed_state.path) if size > 0 do diff --git a/gils/gils.rv b/gils/gils.rv index afd0bbd..08c97cd 100644 --- a/gils/gils.rv +++ b/gils/gils.rv @@ -24,23 +24,23 @@ end # scripts read their args off env.ctx, stashed here before eval global env = { ctx = :nil } -global abspath = fn(arg) do - if arg:len() == 0 return wd.path - let path = arg - if arg[0] != "/" do - if wd.path == "/" do path = "/#{arg}" end - else do path = "#{wd.path}/#{arg}" end +# first use of unless in history +global expand_path = fn(path) do + if path:len() == 0 return wd.path + unless (path[0] == "/") do + const slash = unless (wd.path == "/") "/" else "" + path = "#{wd.path}#{slash}#{path}" end - while (path:len() > 1 and path[path:len() - 1] == "/") do path = path[0..(path:len() - 1)] end return path end -fn run_script(name, ctx) do - const path = "/bin/#{name}.rv" +fn run_script_path(path, label, ctx) do const size = fs:size(path) if size < 0 return :false env.ctx = ctx const error_msg = eval_script(fs:read_bytes(path, 0, size)) - if error_msg != :nil do puts("#{name}: #{error_msg}\n") end + if error_msg != :nil do puts("#{label}: #{error_msg}\n") end return :true end + +fn run_script(name, ctx) run_script_path("/bin/#{name}.rv", name, ctx) diff --git a/gils/head.rv b/gils/head.rv index edfd096..addd11a 100644 --- a/gils/head.rv +++ b/gils/head.rv @@ -18,7 +18,7 @@ else do let limit = 10 let path_arg = context.argv[1] if (context.argv:len() >= 3 and parse_pid(context.argv[1]) >= 0) do limit = parse_pid(context.argv[1]) path_arg = context.argv[2] end - const lines = file_lines(abspath(path_arg)) + const lines = file_lines(expand_path(path_arg)) if lines == :nil do puts("head: no such file\n") end else do let index = 0 @@ -1,7 +1,7 @@ # list a directory const context = env.ctx -const target = if context.argv:len() > 1 abspath(context.argv[1]) else wd.path +const target = if context.argv:len() > 1 expand_path(context.argv[1]) else wd.path if vfs_owns(target) do vfs_ls(target) end else do const count = fs:ls(target) diff --git a/gils/mkdir.rv b/gils/mkdir.rv index cb630d1..759544e 100644 --- a/gils/mkdir.rv +++ b/gils/mkdir.rv @@ -2,4 +2,4 @@ const context = env.ctx if context.argv:len() < 2 do puts("usage: mkdir <path>\n") end -else do fs:mkdir(abspath(context.argv[1])) end +else do fs:mkdir(expand_path(context.argv[1])) end @@ -3,8 +3,8 @@ const context = env.ctx if context.argv:len() < 3 do puts("usage: mv <source> <destination>\n") end else do - const source = abspath(context.argv[1]) - const destination = abspath(context.argv[2]) + const source = expand_path(context.argv[1]) + const destination = expand_path(context.argv[2]) const size = fs:size(source) if size < 0 do puts("mv: #{source}: no such file\n") end else do @@ -3,4 +3,4 @@ const context = env.ctx const parsed = arg_name(context.rest, 0) if parsed.name:len() == 0 do puts("usage: rm <path>\n") end -else do fs:rm(abspath(parsed.name)) end +else do fs:rm(expand_path(parsed.name)) end diff --git a/gils/tail.rv b/gils/tail.rv index 9cd5647..4a661b4 100644 --- a/gils/tail.rv +++ b/gils/tail.rv @@ -19,7 +19,7 @@ else do let limit = 10 let path_arg = context.argv[1] if (context.argv:len() >= 3 and parse_pid(context.argv[1]) >= 0) do limit = parse_pid(context.argv[1]) path_arg = context.argv[2] end - const lines = file_lines(abspath(path_arg)) + const lines = file_lines(expand_path(path_arg)) if lines == :nil do puts("tail: no such file\n") end else do let start = lines:len() - limit diff --git a/gils/touch.rv b/gils/touch.rv index 2dd0d8c..84ecca8 100644 --- a/gils/touch.rv +++ b/gils/touch.rv @@ -3,7 +3,7 @@ const context = env.ctx if context.argv:len() < 2 do puts("usage: touch <path>\n") end else do - const path = abspath(context.argv[1]) + const path = expand_path(context.argv[1]) if fs:is_dir(path) do puts("touch: #{path}: is a directory\n") end else if fs:size(path) < 0 do fs:store(path, "") end end diff --git a/gils/tree.rv b/gils/tree.rv index b052adb..cc41601 100644 --- a/gils/tree.rv +++ b/gils/tree.rv @@ -20,7 +20,7 @@ fn tree_walk(path, prefix) do end const context = env.ctx -const target = if context.argv:len() > 1 abspath(context.argv[1]) else wd.path +const target = if context.argv:len() > 1 expand_path(context.argv[1]) else wd.path if (vfs_owns(target) and target != "/") do puts("tree: #{target}: virtual dir\n") end else if (target != "/" and fs:is_dir(target) == :false) do puts("tree: #{target}: not a directory\n") end else do @@ -3,7 +3,7 @@ const context = env.ctx if context.argv:len() < 2 do puts("usage: wc <path>\n") end else do - const path = abspath(context.argv[1]) + const path = expand_path(context.argv[1]) const size = fs:size(path) if size < 0 do puts("wc: #{path}: no such file\n") end else do |
