Upgraded to zig 16

This commit is contained in:
2026-05-28 22:50:33 -05:00
parent 7ed9502303
commit 8c12920e63
4 changed files with 79 additions and 47 deletions
+1
View File
@@ -1,3 +1,4 @@
.zig-cache
zig-pkg
zig-out
*.txt
+15 -1
View File
@@ -1,7 +1,7 @@
# The No Vibe Coders Open Source License
```
Copyright (C) 2025 William Welna (wwelna@occultusterra.com)
Copyright (C) 2026 William Welna (wwelna@occultusterra.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -20,6 +20,20 @@ In addition, the following restrictions apply:
that used an Artificial Intelligence (AI) model and/or Large Language Model
(LLM) to generate any portion of that other software's source code, binaries,
or artwork.
* The usage of this software is not authorized in the state of California nor are
residents of California authorized to be in possession of this software, either
in source or compiled binary form.
* The usage of this software is not authorized in the state of Colorado nor are
residents of Colorado authorized to be in possession of this software, either
in source or compiled binary form.
* The usage and/or possession of this software, in either source or compiled
binary form, is not authorized in any legal jurisdiction where there is a
requirement of any age verification mechanism and/or identity verification
mechanism as a requirement to use this software under threat of criminal
and/or civil penalties.
* If the unauthorized usage of this software results in financial penalties
towards the developer, William Welna, the responsible individual, corporation,
or other legal entity agrees to fully cover said financial penalties.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+3 -3
View File
@@ -2,11 +2,11 @@
.name = .zigkov,
.version = "0.0.0",
.fingerprint = 0x3629d222e9a79f2c, // Changing this has security and trust implications.
.minimum_zig_version = "0.15.2",
.minimum_zig_version = "0.16.0",
.dependencies = .{
.clap = .{
.url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.11.0.tar.gz",
.hash = "clap-0.11.0-oBajB-HnAQDPCKYzwF7rO3qDFwRcD39Q0DALlTSz5H7e",
.url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.12.0.tar.gz",
.hash = "clap-0.12.0-oBajB7foAQDqlSwaSG5g0yq7xGbQARUsBk5T64gAOqP5",
},
},
.paths = .{""},
+60 -43
View File
@@ -1,4 +1,4 @@
// Copyright (C) 2025 William Welna (wwelna@occultusterra.com)
// Copyright (C) 2026 William Welna (wwelna@occultusterra.com)
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -17,6 +17,20 @@
// that used an Artificial Intelligence (AI) model and/or Large Language Model
// (LLM) to generate any portion of that other software's source code, binaries,
// or artwork.
// * The usage of this software is not authorized in the state of California nor are
// residents of California authorized to be in possession of this software, either
// in source or compiled binary form.
// * The usage of this software is not authorized in the state of Colorado nor are
// residents of Colorado authorized to be in possession of this software, either
// in source or compiled binary form.
// * The usage and/or possession of this software, in either source or compiled
// binary form, is not authorized in any legal jurisdiction where there is a
// requirement of any age verification mechanism and/or identity verification
// mechanism as a requirement to use this software under threat of criminal
// and/or civil penalties.
// * If the unauthorized usage of this software results in financial penalties
// towards the developer, William Welna, the responsible individual, corporation,
// or other legal entity agrees to fully cover said financial penalties.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@@ -29,14 +43,6 @@
const std = @import("std");
const clap = @import("clap");
// Global Arena Allocator because we don't care
var gpa = std.heap.DebugAllocator(.{}){};
const gpa_allocator = gpa.allocator();
var arena = std.heap.ArenaAllocator.init(gpa_allocator);
var allocator = arena.allocator();
var stdout_buffer: [1024]u8 = undefined;
const Word = struct {
word: std.ArrayList(u8),
next: std.ArrayList(WordStat),
@@ -65,7 +71,7 @@ pub fn fnv(word: []const u8) u64 {
return hash;
}
pub inline fn clean(word: []const u8, output: *std.ArrayList(u8)) !void {
pub inline fn clean(allocator: std.mem.Allocator, word: []const u8, output: *std.ArrayList(u8)) !void {
//const filter:[]u8 = "$@\\€-_";
for (word) |x| { // pretty
if (std.ascii.isAlphabetic(x)) {
@@ -74,12 +80,12 @@ pub inline fn clean(word: []const u8, output: *std.ArrayList(u8)) !void {
}
}
pub inline fn add(chains: *std.ArrayList(Word), word: []const u8, next: []const u8, is_start: bool) !void {
pub inline fn add(allocator: std.mem.Allocator, chains: *std.ArrayList(Word), word: []const u8, next: []const u8, is_start: bool) !void {
var updated: bool = false;
var w: std.ArrayList(u8) = .empty;
var n: std.ArrayList(u8) = .empty;
try clean(word, &w);
try clean(next, &n);
try clean(allocator, word, &w);
try clean(allocator, next, &n);
if (w.items.len < 1 or n.items.len < 1) return;
for (chains.items) |*x| {
const looking: u64 = fnv(w.items);
@@ -110,10 +116,10 @@ pub inline fn add(chains: *std.ArrayList(Word), word: []const u8, next: []const
}
}
pub inline fn add_end(chains: *std.ArrayList(Word), word: []const u8) !void {
pub inline fn add_end(allocator: std.mem.Allocator, chains: *std.ArrayList(Word), word: []const u8) !void {
var updated: bool = false;
var w: std.ArrayList(u8) = .empty;
try clean(word, &w);
try clean(allocator, word, &w);
if (w.items.len < 1) return;
for (chains.items) |*x| {
const looking: u64 = fnv(w.items);
@@ -129,12 +135,13 @@ pub inline fn add_end(chains: *std.ArrayList(Word), word: []const u8) !void {
}
}
pub inline fn do_stats(chains: *std.ArrayList(Word), data: []const u8) !void {
pub inline fn do_stats(io: std.Io, allocator: std.mem.Allocator, rand: std.Random, chains: *std.ArrayList(Word), data: []const u8) !void {
var buffer: [4096]u8 = undefined;
var file = try std.fs.cwd().openFile(data, .{ .mode = .read_only });
defer file.close();
var file = try std.Io.Dir.cwd().openFile(io, data, .{ .mode = .read_only });
defer file.close(io);
_ = rand;
var frb = file.reader(&buffer);
var frb = file.reader(io, &buffer);
var reader = &frb.interface;
const buf2 = try allocator.alloc(u8, 4096);
@@ -148,8 +155,8 @@ pub inline fn do_stats(chains: *std.ArrayList(Word), data: []const u8) !void {
var is_start: bool = true;
while (splits.next()) |x| {
if (splits.peek()) |y| {
try add(chains, x, y, is_start);
} else try add_end(chains, x);
try add(allocator, chains, x, y, is_start);
} else try add_end(allocator, chains, x);
is_start = false;
}
} else |err| switch (err) {
@@ -169,15 +176,15 @@ pub inline fn do_stats(chains: *std.ArrayList(Word), data: []const u8) !void {
}
}
pub inline fn random(probability: f64, weight: f64) bool {
const rand = std.crypto.random.float(f64);
return rand <= (probability + weight);
pub inline fn random(rand: std.Random, probability: f64, weight: f64) bool {
const ret = rand.float(f64);
return ret <= (probability + weight);
}
pub inline fn do_spongebob(line: []u8) []u8 {
pub inline fn do_spongebob(rand: std.Random, line: []u8) []u8 {
for (line) |*x| {
if (std.ascii.isAlphabetic(x.*) and std.ascii.isLower(x.*)) {
if (random(0.5, 0)) {
if (random(rand, 0.5, 0)) {
x.* = std.ascii.toUpper(x.*);
}
}
@@ -197,12 +204,14 @@ pub inline fn find(chains: *std.ArrayList(Word), word: []u8) ?*Word {
return null;
}
pub fn do_next(chains: *std.ArrayList(Word)) !?[]u8 {
pub fn do_next(io: std.Io, allocator: std.mem.Allocator, rand: std.Random, chains: *std.ArrayList(Word)) !?[]u8 {
var post: std.ArrayList(u8) = .empty;
var starter: *Word = undefined;
_ = io;
while (true) {
const i: usize = std.crypto.random.uintAtMost(usize, chains.items.len - 1);
if (chains.items[i].next.items.len > 5 and random(chains.items[i].start_normalized, 0)) {
const i: usize = std.Random.uintAtMost(rand, usize, chains.items.len - 1);
if (chains.items[i].next.items.len > 5 and random(rand, chains.items[i].start_normalized, 0)) {
starter = &chains.items[i];
try post.appendSlice(allocator, starter.word.items);
try post.append(allocator, ' ');
@@ -214,10 +223,10 @@ pub fn do_next(chains: *std.ArrayList(Word)) !?[]u8 {
while (still_building) {
var selected: bool = false;
var next: []u8 = undefined;
if (random(starter.end_normalized, 0.0)) break;
if (random(rand, starter.end_normalized, 0.0)) break;
while (!selected) {
for (starter.next.items) |*x| {
if (random(x.normalized, 0.01)) {
if (random(rand, x.normalized, 0.01)) {
try post.appendSlice(allocator, x.word.items);
try post.append(allocator, ' ');
selected = true;
@@ -237,9 +246,12 @@ pub fn do_next(chains: *std.ArrayList(Word)) !?[]u8 {
return post.items;
}
pub fn main() !void {
var stdout_writer_wrapper = std.fs.File.stdout().writer(&stdout_buffer);
const stdout: *std.io.Writer = &stdout_writer_wrapper.interface;
pub fn main(init: std.process.Init) !void {
const allocator = init.arena.allocator();
var stdout_buffer: [1024]u8 = undefined;
var stdout_file_writer: std.Io.File.Writer = .init(.stdout(), init.io, &stdout_buffer);
var stdout = &stdout_file_writer.interface;
const params = comptime clap.parseParamsComptime(
\\-h, --help Display this help and exit.
@@ -250,27 +262,32 @@ pub fn main() !void {
); // Need to add the JSON Loading/Saving Code (am thinking of using zon)
var diag = clap.Diagnostic{};
var res = clap.parse(clap.Help, &params, clap.parsers.default, .{
var res = clap.parse(clap.Help, &params, clap.parsers.default, init.minimal.args, .{
.diagnostic = &diag,
.allocator = gpa_allocator,
.allocator = allocator,
}) catch |err| {
try diag.reportToFile(.stderr(), err);
try diag.reportToFile(init.io, .stderr(), err);
return err;
};
defer res.deinit();
if (res.args.help != 0)
return clap.helpToFile(.stderr(), clap.Help, &params, .{});
return clap.helpToFile(init.io, .stderr(), clap.Help, &params, .{});
if (res.args.process) |f| {
var randbuff: [8]u8 = undefined;
std.Io.random(init.io, &randbuff);
var prng = std.Random.Isaac64.init(std.mem.readInt(u64, randbuff[0..8], .little));
const rand = prng.random();
MarkovChain = .empty;
try do_stats(&MarkovChain, f);
try do_stats(init.io, allocator, rand, &MarkovChain, f);
if (res.args.spongebob > 0) {
try stdout.print("{s}\n", .{if (try do_next(&MarkovChain)) |s| do_spongebob(s) else ""});
try stdout.print("{s}\n", .{if (try do_next(init.io, allocator, rand, &MarkovChain)) |s| do_spongebob(rand, s) else ""});
} else {
try stdout.print("{s}\n", .{if (try do_next(&MarkovChain)) |s| s else ""});
try stdout.print("{s}\n", .{if (try do_next(init.io, allocator, rand, &MarkovChain)) |s| s else ""});
}
defer arena.deinit();
}
try stdout.flush();
defer _ = gpa.deinit();
}