| ... | @@ -97,7 +97,40 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -97,7 +97,40 @@ pub fn execute(args: [][]u8) !void { |
| 97 | const file = try cwd.createFile("LICENSE", .{}); | 97 | const file = try cwd.createFile("LICENSE", .{}); |
| 98 | defer file.close(); | 98 | defer file.close(); |
| 99 | const w = file.writer(); | 99 | const w = file.writer(); |
| 100 | try w.writeAll(realtext); | 100 | |
| | 101 | // properly format license text to fit within 80 columns |
| | 102 | var start: usize = 0; |
| | 103 | var end: usize = 0; |
| | 104 | var run: u32 = 0; |
| | 105 | var i: usize = 0; |
| | 106 | while (i < realtext.len) { |
| | 107 | const c = realtext[i]; |
| | 108 | end += 1; |
| | 109 | i += 1; |
| | 110 | |
| | 111 | if (c == '\n') { |
| | 112 | try w.writeAll(realtext[start..end]); |
| | 113 | std.log.info("{s}", .{realtext[start .. end - 1]}); |
| | 114 | start = end; |
| | 115 | run = 0; |
| | 116 | i = start; |
| | 117 | continue; |
| | 118 | } |
| | 119 | run += 1; |
| | 120 | |
| | 121 | if (run >= 79) { |
| | 122 | const s_ind = (std.mem.lastIndexOfScalar(u8, realtext[start..end], ' ') orelse end) + start; |
| | 123 | const n_ind = (std.mem.lastIndexOfScalar(u8, realtext[start .. end - 1], '\n') orelse end) + start; |
| | 124 | const ind = std.math.min(s_ind, n_ind); |
| | 125 | try w.print("{s}\n", .{realtext[start..ind]}); |
| | 126 | std.log.debug("{s}", .{realtext[start..ind]}); |
| | 127 | end = ind + 1; |
| | 128 | start = end; |
| | 129 | run = 0; |
| | 130 | i = start; |
| | 131 | } |
| | 132 | } |
| | 133 | try w.writeAll(realtext[start..realtext.len]); |
| 101 | } | 134 | } |
| 102 | } | 135 | } |
| 103 | } | 136 | } |