about summary refs log tree commit diff stats
path: root/src/extern
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-14 20:57:45 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-14 21:05:16 +0100
commitd26766c4c4015990703e84e8136f96d222edbc97 (patch)
tree7f412f8ca98d2b04323da5cf2fd607efbd6c408d /src/extern
parenta8f05f18fdd64485c26b453e62e8073b50e271ef (diff)
downloadchawan-d26766c4c4015990703e84e8136f96d222edbc97.tar.gz
Move around some modules
* extern -> gone, runproc absorbed by pager, others moved into io/
* display -> local/ (where else would we display?)
* xhr -> html/
* move out WindowAttributes from term, so we don't depend on local
  from server
Diffstat (limited to 'src/extern')
-rw-r--r--src/extern/runproc.nim58
-rw-r--r--src/extern/stdio.nim25
-rw-r--r--src/extern/tempfile.nim18
3 files changed, 0 insertions, 101 deletions
diff --git a/src/extern/runproc.nim b/src/extern/runproc.nim
deleted file mode 100644
index 9d189dff..00000000
--- a/src/extern/runproc.nim
+++ /dev/null
@@ -1,58 +0,0 @@
-import std/posix
-import std/streams
-
-import display/term
-
-proc c_system(cmd: cstring): cint {.
-  importc: "system", header: "<stdlib.h>".}
-
-# Run process (without suspending the terminal controller).
-proc runProcess*(cmd: string): bool =
-  let wstatus = c_system(cstring(cmd))
-  if wstatus == -1:
-    result = false
-  else:
-    result = WIFEXITED(wstatus) and WEXITSTATUS(wstatus) == 0
-    if not result:
-      # Hack.
-      #TODO this is a very bad idea, e.g. say the editor is writing into the
-      # file, then receives SIGINT, now the file is corrupted but Chawan will
-      # happily read it as if nothing happened.
-      # We should find a proper solution for this.
-      result = WIFSIGNALED(wstatus) and WTERMSIG(wstatus) == SIGINT
-
-# Run process (and suspend the terminal controller).
-proc runProcess*(term: Terminal, cmd: string, wait = false): bool =
-  term.quit()
-  result = runProcess(cmd)
-  if wait:
-    term.anyKey()
-  term.restart()
-
-# Run process, and capture its output.
-proc runProcessCapture*(cmd: string, outs: var string): bool =
-  let file = popen(cmd, "r")
-  if file == nil:
-    return false
-  let fs = newFileStream(file)
-  outs = fs.readAll()
-  let rv = pclose(file)
-  if rv == -1:
-    return false
-  return rv == 0
-
-# Run process, and write an arbitrary string into its standard input.
-proc runProcessInto*(cmd, ins: string): bool =
-  let file = popen(cmd, "w")
-  if file == nil:
-    return false
-  let fs = newFileStream(file)
-  fs.write(ins)
-  let rv = pclose(file)
-  if rv == -1:
-    return false
-  return rv == 0
-
-proc myExec*(cmd: string) =
-  discard execl("/bin/sh", "sh", "-c", cmd, nil)
-  exitnow(127)
diff --git a/src/extern/stdio.nim b/src/extern/stdio.nim
deleted file mode 100644
index 729b50f6..00000000
--- a/src/extern/stdio.nim
+++ /dev/null
@@ -1,25 +0,0 @@
-import std/posix
-
-proc closeHandle(fd, flags: cint) =
-  let devnull = open("/dev/null", flags)
-  doAssert devnull != -1
-  if devnull != fd:
-    discard dup2(devnull, fd)
-    discard close(devnull)
-
-proc closeStdin*() =
-  closeHandle(0, O_RDONLY)
-
-proc closeStdout*() =
-  closeHandle(1, O_WRONLY)
-
-proc closeStderr*() =
-  closeHandle(2, O_WRONLY)
-
-proc safeClose*(fd: cint) =
-  if fd == 0:
-    closeStdin()
-  elif fd == 1 or fd == 2:
-    closeHandle(fd, O_WRONLY)
-  else:
-    discard close(fd)
diff --git a/src/extern/tempfile.nim b/src/extern/tempfile.nim
deleted file mode 100644
index 5968270b..00000000
--- a/src/extern/tempfile.nim
+++ /dev/null
@@ -1,18 +0,0 @@
-import std/os
-
-var tmpf_seq: int
-proc getTempFile*(tmpdir: string, ext = ""): string =
-  if not dirExists(tmpdir):
-    createDir(tmpdir)
-  var tmpf = tmpdir / "chatmp" & $getCurrentProcessId() & "-" & $tmpf_seq
-  if ext != "":
-    tmpf &= "."
-    tmpf &= ext
-  while fileExists(tmpf):
-    inc tmpf_seq
-    tmpf = tmpdir / "chatmp" & $tmpf_seq
-    if ext != "":
-      tmpf &= "."
-      tmpf &= ext
-  inc tmpf_seq
-  return tmpf