Browse Source

Hack in zero byte again to not pass in old buffer

Ugh.  Quite hideous but it works.  Hm.
Luna Stadler 4 years ago
parent
commit
dd94c3ba98
1 changed files with 9 additions and 9 deletions
  1. 9 9
      zig/sdl/hello_sdl.zig

+ 9 - 9
zig/sdl/hello_sdl.zig

200
                    return err;
200
                    return err;
201
                },
201
                },
202
            };
202
            };
203
            std.debug.print("{d} ({d})\n", .{ process.stdout_buf.items.len, process.stderr_buf.items.len });
203
            //std.debug.print("{d} ({d})\n", .{ process.stdout_buf.items.len, process.stderr_buf.items.len });
204
            if (process.stdout_buf.items.len > 0) {
204
            if (process.stdout_buf.items.len > 0) {
205
                return process.stdout();
205
                return process.stdout();
206
            } else if (process.stderr_buf.items.len > 0) {
206
            } else if (process.stderr_buf.items.len > 0) {
231
231
232
    fn toArgv(cmd: []const u8) []const []const u8 {
232
    fn toArgv(cmd: []const u8) []const []const u8 {
233
        // NO idea why bufPrint is required, but without `cmd` will just be some random bit of memory, which is rude.
233
        // NO idea why bufPrint is required, but without `cmd` will just be some random bit of memory, which is rude.
234
        _ = std.fmt.bufPrint(&cmd_buf, "{s}", .{cmd["go ".len..]}) catch "???";
234
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["go ".len..]}) catch "???";
235
        return &[_][]const u8{ "go", "doc", &cmd_buf };
235
        return &[_][]const u8{ "go", "doc", &cmd_buf };
236
    }
236
    }
237
};
237
};
246
    }
246
    }
247
247
248
    fn toArgv(cmd: []const u8) []const []const u8 {
248
    fn toArgv(cmd: []const u8) []const []const u8 {
249
        _ = std.fmt.bufPrint(&cmd_buf, "import {s}; help({s});", .{ std.mem.sliceTo(cmd["py ".len..], '.'), cmd["py ".len..] }) catch "???";
249
        _ = std.fmt.bufPrint(&cmd_buf, "import {s}; help({s});\x00", .{ std.mem.sliceTo(cmd["py ".len..], '.'), cmd["py ".len..] }) catch "???";
250
        return &[_][]const u8{ "python", "-c", &cmd_buf };
250
        return &[_][]const u8{ "python", "-c", &cmd_buf };
251
    }
251
    }
252
};
252
};
261
    }
261
    }
262
262
263
    fn toArgv(cmd: []const u8) []const []const u8 {
263
    fn toArgv(cmd: []const u8) []const []const u8 {
264
        _ = std.fmt.bufPrint(&cmd_buf, "print({s})", .{cmd["py! ".len..]}) catch "???";
264
        _ = std.fmt.bufPrint(&cmd_buf, "print({s})\x00", .{cmd["py! ".len..]}) catch "???";
265
        return &[_][]const u8{ "python", "-c", &cmd_buf };
265
        return &[_][]const u8{ "python", "-c", &cmd_buf };
266
    }
266
    }
267
};
267
};
276
    }
276
    }
277
277
278
    fn toArgv(cmd: []const u8) []const []const u8 {
278
    fn toArgv(cmd: []const u8) []const []const u8 {
279
        _ = std.fmt.bufPrint(&cmd_buf, "{s}", .{cmd[0 .. cmd.len - " --help".len]}) catch "???";
279
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd[0 .. cmd.len - " --help".len]}) catch "???";
280
        return &[_][]const u8{ &cmd_buf, "--help" };
280
        return &[_][]const u8{ &cmd_buf, "--help" };
281
    }
281
    }
282
};
282
};
291
    }
291
    }
292
292
293
    fn toArgv(cmd: []const u8) []const []const u8 {
293
    fn toArgv(cmd: []const u8) []const []const u8 {
294
        _ = std.fmt.bufPrint(&cmd_buf, "{s}", .{cmd["man ".len..]}) catch "???";
294
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["man ".len..]}) catch "???";
295
        return &[_][]const u8{ "man", &cmd_buf };
295
        return &[_][]const u8{ "man", &cmd_buf };
296
    }
296
    }
297
};
297
};
306
    }
306
    }
307
307
308
    fn toArgv(cmd: []const u8) []const []const u8 {
308
    fn toArgv(cmd: []const u8) []const []const u8 {
309
        _ = std.fmt.bufPrint(&cmd_buf, "{s}", .{cmd["s ".len..]}) catch "???";
309
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd["s ".len..]}) catch "???";
310
        return &[_][]const u8{ "ag", &cmd_buf, "/home/luna/k/the-thing" };
310
        return &[_][]const u8{ "ag", &cmd_buf, "/home/luna/k/the-thing" };
311
    }
311
    }
312
};
312
};
326
        }
326
        }
327
327
328
        const service = cmd["logs ".len..];
328
        const service = cmd["logs ".len..];
329
        _ = std.fmt.bufPrint(&cmd_buf, "(systemctl status {s} &> /dev/null && journalctl -u {s} -f) || (systemctl status --user {s} &> /dev/null && journalctl --user -u {s} -f) || echo \"no logs for '{s}'\"", .{ service, service, service, service, service }) catch "???";
329
        _ = std.fmt.bufPrint(&cmd_buf, "(systemctl status {s} &> /dev/null && journalctl -u {s} -f) || (systemctl status --user {s} &> /dev/null && journalctl --user -u {s} -f) || echo \"no logs for '{s}'\"\x00", .{ service, service, service, service, service }) catch "???";
330
        return &[_][]const u8{ "bash", "-c", &cmd_buf };
330
        return &[_][]const u8{ "bash", "-c", &cmd_buf };
331
    }
331
    }
332
};
332
};
341
    }
341
    }
342
342
343
    fn toArgv(cmd: []const u8) []const []const u8 {
343
    fn toArgv(cmd: []const u8) []const []const u8 {
344
        _ = std.fmt.bufPrint(&cmd_buf, "{s}", .{cmd}) catch "???";
344
        _ = std.fmt.bufPrint(&cmd_buf, "{s}\x00", .{cmd}) catch "???";
345
        return &[_][]const u8{ "qalc", "-terse", &cmd_buf };
345
        return &[_][]const u8{ "qalc", "-terse", &cmd_buf };
346
    }
346
    }
347
};
347
};