summaryrefslogtreecommitdiff
path: root/stdin_wrapper.d
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-12-13 09:50:42 +0000
committerw0rp <devw0rp@gmail.com>2016-12-13 10:00:40 +0000
commit76a03b07099ec32135be4c7d9a7283343972b0af (patch)
tree25e5615b04347baccaa624601c94d1b581c872e9 /stdin_wrapper.d
parent70e379cc46868916126156558486a8d8971cc5fa (diff)
downloadale-76a03b07099ec32135be4c7d9a7283343972b0af.zip
Add a Batch stdin wrapper script
Diffstat (limited to 'stdin_wrapper.d')
-rw-r--r--stdin_wrapper.d84
1 files changed, 0 insertions, 84 deletions
diff --git a/stdin_wrapper.d b/stdin_wrapper.d
deleted file mode 100644
index 8714bc2a..00000000
--- a/stdin_wrapper.d
+++ /dev/null
@@ -1,84 +0,0 @@
-// Author: w0rp <devw0rp@gmail.com>
-// Description: This file provides a D program for implementing
-// the stdin-wrapper on Windows.
-
-import std.algorithm;
-import std.array;
-import std.file;
-import std.process;
-import std.stdio;
-import std.path;
-
-@safe
-auto createTemporaryFilename(string fileExtension) {
- import std.uuid;
-
- string filename;
-
- do {
- const randomPart = randomUUID().toString.replace("-", "_");
-
- filename = buildPath(tempDir(), "ale_" ~ randomPart ~ fileExtension);
- } while (exists(filename));
-
- return filename;
-}
-
-@trusted
-void readStdinToFile(ref File tempFile) {
- stdin.byChunk(4096).copy(tempFile.lockingTextWriter());
-}
-
-// Expand program names like "csslint" to "csslint.cmd"
-// D is not able to perform this kind of expanstion in spawnProcess
-@safe
-string expandedProgramName(string name) {
- auto extArray = environment["PATHEXT"].split(";");
-
- foreach(pathDir; environment["PATH"].split(";")) {
- foreach(extension; extArray) {
- const candidate = buildPath(pathDir, name ~ extension);
-
- if (exists(candidate)) {
- return candidate;
- }
- }
- }
-
- // We were given a full path for a program name, so use that.
- if (exists(name)) {
- return name;
- }
-
- return "";
-}
-
-@trusted
-int runLinterProgram(string[] args) {
- const expandedName = expandedProgramName(args[0]);
-
- writeln(expandedName);
-
- if (expandedName) {
- return wait(spawnProcess([expandedName] ~ args[1..$]));
- }
-
- return 1;
-}
-
-@safe
-int main(string[] args) {
- const filename = createTemporaryFilename(args[1]);
-
- auto tempFile = File(filename, "w");
-
- scope(exit) {
- tempFile.close();
- remove(filename);
- }
-
- readStdinToFile(tempFile);
- tempFile.close();
-
- return runLinterProgram(args[2..$] ~ [filename]);
-}