From 80d0f8c3773a644aba808b949c40e8d5dae2597b Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Mon, 3 Apr 2023 16:05:20 -0700 Subject: [PATCH] add expected output --- src/main.zig | 24 ++++++++++++++++++++++++ src/testExpectedBytes.bin | Bin 0 -> 8192 bytes 2 files changed, 24 insertions(+) create mode 100644 src/testExpectedBytes.bin diff --git a/src/main.zig b/src/main.zig index 676e340..b7e902d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -48,6 +48,30 @@ pub fn main() !void { const stdout = bw.writer(); defer bw.flush() catch unreachable; // don't forget to flush! + // If we have stdin redirected, we want to process that before + // we take command line options. So cli will overwrite any lines specified + // from the file + const stdin_file = std.io.getStdIn(); + var stdin_data: [WIDTH * HEIGHT + 1]u8 = undefined; + var line_inx: usize = 0; + defer { + for (0..line_inx) |i| { + alloc.free(@constCast(lines[i].*)); + } + } + if (!stdin_file.isTty()) { + const read = try stdin_file.readAll(&stdin_data); + if (read == stdin_data.len) { + try std.io.getStdErr().writer().print("ERROR: data provided exceeds what can be sent to device!\n", .{}); + try usage(args); + } + var it = std.mem.split(u8, &stdin_data, "\n"); + while (it.next()) |line| { + const bwahahaha = try alloc.dupeZ(u8, line); + lines[line_inx] = &bwahahaha; + line_inx += 1; + } + } const opts = try processArgs(alloc, args, &lines); defer alloc.destroy(opts); if (opts.background_filename.len > 0) try stdout.print("Converting {s}\n", .{opts.background_filename}); diff --git a/src/testExpectedBytes.bin b/src/testExpectedBytes.bin new file mode 100644 index 0000000000000000000000000000000000000000..90546a5a9d082e5f9484e549d48144b674b78eb2 GIT binary patch literal 8192 zcmeH|i<0Xg2!{LqFWtk>RfuVmshHWB<8~t;@&VfP_4+@qci^2|vzC^cl>Nk}LVgST zXdB+Iw|#!A;?C}&;x`RSf&S@l^B^kFI=B&AlK|fa=Yn+1kY-9T=?fID`VeQvnR_0# z-ZY$?_pwgYeze}CRrgfWr|9fB>q?DyPe)N0bF^EP?)p8*2k&bY8Gbe2s?P}?DC~wD zvfuC8JYcm7c`+Z5xX+Gs!HWY|huanjR~l+;%!{xV=2ArJkqz6oZvI{o6>a$M&g&Ah zNNADq&9-p{8m}f!VI$X2R{AsiL|=aUwZ;+`%xU#uw&j*tYv$OTiyAiJ?XpX4&Ss&d z-Wrrh$YJF3Yuasf!*ZQ#l>|h@Gjdwas{w;=U;MCC-ws`9{w2_tj~z(|F~?Lsil?sA z+TQXNM^LQe4)_>Ew>1e*^M?b73ddfAwMU8uMEsq6P&Efn zAYBHxb_$$90HB8UT_R`m=Z&#j%(i$QDHA!J@0&avxwL!Nb4(i2~AL~{6~$YyK_(xl?h-M$o z;dI}yP=G}p9A{$Sm@5xy$JGQ1u&6WWU{ikFeMl4nE_kpo_|L>bggSF;voSxA5Ajn1 zZMDt6lX0RL2_cd~0Y1XDbTY+zHz=R*Sp|9+SJWC)}`=zJ(`m2}I=r7v| e8El#_w+lwhb31kbWU^?(@*XiKv4{D$DgOX12T