Compare commits
2 Commits
7fad476b61
...
17f4306fc3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17f4306fc3 | ||
|
|
80df86df3d |
@@ -726,8 +726,8 @@ API double GetTimeSeconds() {
|
||||
return GetTimeMicros() / 1000000.0;
|
||||
}
|
||||
|
||||
API String WriteTempFile(String data) {
|
||||
Scratch scratch;
|
||||
API String WriteTempFile(Allocator allocator, String data) {
|
||||
Scratch scratch(allocator);
|
||||
|
||||
#if OS_WINDOWS
|
||||
int buffer_len = MAX_PATH+1;
|
||||
@@ -737,12 +737,12 @@ API String WriteTempFile(String data) {
|
||||
Assert(result != 0);
|
||||
String16 temp16 = {buffer, result};
|
||||
NormalizePathInPlace(temp16);
|
||||
String temp_directory = ToString(scratch, temp16);
|
||||
String temp_directory = ToString(allocator, temp16);
|
||||
#else
|
||||
String temp_directory = "/tmp";
|
||||
#endif
|
||||
|
||||
String temp_filename = Format(scratch, "%S/temp%llu", temp_directory, GetTimeNanos());
|
||||
String temp_filename = Format(allocator, "%S/temp%llu", temp_directory, GetTimeNanos());
|
||||
bool done = WriteFile(temp_filename, data);
|
||||
Assert(done);
|
||||
return temp_filename;
|
||||
|
||||
@@ -32,6 +32,7 @@ bool IsFile(String path);
|
||||
String GetWorkingDir(Allocator arena);
|
||||
bool IsAbsolute(String path);
|
||||
int64_t GetFileModTime(String file);
|
||||
String WriteTempFile(Allocator allocator, String data);
|
||||
|
||||
|
||||
|
||||
@@ -45,4 +46,4 @@ enum MakeDirResult {
|
||||
MakeDirResult_ErrorOther,
|
||||
};
|
||||
|
||||
MakeDirResult MakeDir(String path);
|
||||
MakeDirResult MakeDir(String path);
|
||||
|
||||
@@ -118,6 +118,7 @@ void LexDigit(Lexer *lex, Token *t) {
|
||||
}
|
||||
|
||||
bool IsOkForIdent(Lexer *lex, char c) {
|
||||
Unused(lex);
|
||||
bool result = IsAlphanumeric(c) || c == '_' || c == '/';
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ void Coro_SearchOpenBuffers(mco_coro *co) {
|
||||
if (out_buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
Buffer *it = GetBuffer(id, NULL);
|
||||
it = GetBuffer(id, NULL);
|
||||
if (it == NULL) {
|
||||
goto skip_buffer;
|
||||
}
|
||||
|
||||
@@ -233,22 +233,23 @@ Array<char *> SplitCommand(Allocator allocator, String command_line) {
|
||||
return cmd;
|
||||
}
|
||||
|
||||
Process SpawnProcess(String command_line, String working_dir, String write_stdin, Array<String> enviroment) {
|
||||
Process SpawnProcess(ExecArgs args) {
|
||||
Scratch scratch;
|
||||
const int PIPE_READ = 0;
|
||||
const int PIPE_WRITE = 1;
|
||||
bool error = false;
|
||||
|
||||
working_dir = Copy(scratch, working_dir);
|
||||
String working_dir = Copy(scratch, args.cwd);
|
||||
chdir(working_dir.data);
|
||||
|
||||
Process process = {};
|
||||
process.args = args;
|
||||
UnixProcess *plat = (UnixProcess *)&process.platform;
|
||||
Array<char *> args = SplitCommand(scratch, command_line);
|
||||
Array<char *> args_cmd = SplitCommand(scratch, args.cmd);
|
||||
Array<char *> env = {scratch};
|
||||
char *exe = Copy(scratch, args.exe).data;
|
||||
|
||||
For (enviroment) {
|
||||
For (args.env) {
|
||||
Add(&env, Copy(scratch, it).data);
|
||||
}
|
||||
|
||||
@@ -308,20 +309,22 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
|
||||
return process;
|
||||
}
|
||||
|
||||
error = posix_spawn_file_actions_addclose(&actions, stdin_desc[PIPE_WRITE]) != 0;
|
||||
if (error) {
|
||||
Error("Libc function failed: posix_spawn_file_actions_addclose, with error: %s", strerror(errno));
|
||||
return process;
|
||||
}
|
||||
if (args.open_stdin) {
|
||||
error = posix_spawn_file_actions_addclose(&actions, stdin_desc[PIPE_WRITE]) != 0;
|
||||
if (error) {
|
||||
Error("Libc function failed: posix_spawn_file_actions_addclose, with error: %s", strerror(errno));
|
||||
return process;
|
||||
}
|
||||
|
||||
error = posix_spawn_file_actions_adddup2(&actions, stdin_desc[PIPE_READ], STDIN_FILENO) != 0;
|
||||
if (error) {
|
||||
Error("Libc function failed: posix_spawn_file_actions_adddup2 STDIN_FILENO, with error: %s", strerror(errno));
|
||||
return process;
|
||||
error = posix_spawn_file_actions_adddup2(&actions, stdin_desc[PIPE_READ], STDIN_FILENO) != 0;
|
||||
if (error) {
|
||||
Error("Libc function failed: posix_spawn_file_actions_adddup2 STDIN_FILENO, with error: %s", strerror(errno));
|
||||
return process;
|
||||
}
|
||||
}
|
||||
|
||||
pid_t process_pid = 0;
|
||||
error = posix_spawnp(&process_pid, args[0], &actions, NULL, args.data, env.data) != 0;
|
||||
error = posix_spawnp(&process_pid, exe, &actions, NULL, args_cmd.data, env.data) != 0;
|
||||
if (error) {
|
||||
Error("Libc function failed: failed to create process\n, with error: %s", strerror(errno));
|
||||
return process;
|
||||
@@ -329,12 +332,9 @@ Process SpawnProcess(String command_line, String working_dir, String write_stdin
|
||||
|
||||
|
||||
plat->child_stdout_read = stdout_desc[PIPE_READ];
|
||||
plat->stdin_write = stdin_desc[PIPE_WRITE];
|
||||
plat->pid = process_pid;
|
||||
|
||||
if (write_stdin.len) {
|
||||
WriteStdin(&process, write_stdin);
|
||||
CloseStdin(&process);
|
||||
if (args.open_stdin) {
|
||||
plat->stdin_write = stdin_desc[PIPE_WRITE];
|
||||
}
|
||||
|
||||
process.id = process_pid;
|
||||
@@ -431,8 +431,13 @@ String FindPython(Allocator allocator) {
|
||||
for (int i = 0; i < Lengthof(tries); i += 1) {
|
||||
For (paths) {
|
||||
String path_it = Format(scratch, "%S/%S" IF_OS_WINDOWS_ELSE(".exe", ""), it, tries[i]);
|
||||
#if OS_WINDOWS
|
||||
bool is_bad_bad_ms = EndsWith(it, "AppData\\Local\\Microsoft\\WindowsApps") || EndsWith(it, "AppData/Local/Microsoft/WindowsApps");
|
||||
if (FileExists(path_it) IF_OS_WINDOWS(&& !is_bad_bad_ms)) {
|
||||
if (is_bad_bad_ms) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (FileExists(path_it)) {
|
||||
return Copy(allocator, path_it);
|
||||
}
|
||||
}
|
||||
@@ -446,7 +451,7 @@ void SetShell(Allocator allocator, String *exe, String *cmd, String in_cmd) {
|
||||
*cmd = Format(allocator, "%S /C %S", *exe, in_cmd);
|
||||
#else
|
||||
*exe = "/usr/bin/bash";
|
||||
String temp_file = WriteTempFile(in_cmd); // @todo: maybe try to pass by stdio here
|
||||
String temp_file = WriteTempFile(allocator, in_cmd); // @todo: maybe try to pass by stdio here
|
||||
*cmd = Format(allocator, "%S %S", *exe, temp_file);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
- [ ] GetWindowZOrder to IterateWindowsInZOrder
|
||||
- [ ] Rework history API, tagging modification blocks with carets?
|
||||
- [ ] The lexing / parsing code for config / bindings appears sloppy would be nice to clean it up but I don't have any ideas
|
||||
- [ ] Directory tree doesn't make much sense! Maybe just consolidate into one folder? create nice names - the raddbg idea didn't pan out well here
|
||||
- [ ] Test BlockArena correctnsess - random allocations, writes and undos, try to crash
|
||||
|
||||
- [ ] New error mechanism
|
||||
- New error mechanism - we were losing errors when ReportError was called multiple times, I still want that but I don't want to lose errors, so turn it into a summary list of errors
|
||||
- [ ] BeginLog EndLog, and then show all logs as a list in the UI thing
|
||||
- [ ] Undo kinds (to enable history in fuzzy buffers)
|
||||
- [ ] Add undo kind. Snapshot kind, so that history is possible in weird buffers without paying a huge memory cost. The idea is that we would store the exact buffer state to replace with, editor would just save history of first line etc.
|
||||
|
||||
@@ -294,7 +294,6 @@ void TestInsertVariable() {
|
||||
String a = "Thing/@(ProjectFolder)/Another";
|
||||
String b = "Thing/@ProjectFolder/Another";
|
||||
Assert(InsertVariables(scratch, a) == InsertVariables(scratch, b));
|
||||
int c = 10;
|
||||
|
||||
} RegisterFunction(&TestFunctions, TestInsertVariable);
|
||||
|
||||
@@ -545,7 +544,7 @@ BSet Open(Window *window, String path, ResolveOpenMeta meta, bool set_active = t
|
||||
|
||||
if (o.use_python_shell == 1) {
|
||||
args.exe = FindPython(scratch);
|
||||
String temp_file = WriteTempFile(o.path);
|
||||
String temp_file = WriteTempFile(scratch, o.path);
|
||||
args.cmd = Format(scratch, "%S %S", args.exe, temp_file);
|
||||
} else {
|
||||
SetShell(scratch, &args.exe, &args.cmd, o.path);
|
||||
|
||||
Reference in New Issue
Block a user