#define MULE_IMPLEMENTATION
#include "mule.h"
#include <stdio.h>
#include <stdlib.h>
static void print_count(bool color, const char *label, size_t n) {
if (color)
else
printf("%-8s %zu\n", label, n);
}
int main(int argc, char **argv) {
if (argc > 2) {
fprintf(stderr, "usage: %s [file]\n", argv[0]);
return EXIT_FAILURE;
}
const char *name = argc == 2 ? argv[1] : "stdin";
FILE *f = argc == 2 ? fopen(name, "rb") : stdin;
if (f == NULL) {
perror(name);
return EXIT_FAILURE;
}
bool read_error = ferror(f);
if (f != stdin) fclose(f);
if (!ok) {
fprintf(stderr, "%s: %s\n", name,
read_error ? "read error" : "out of memory");
return EXIT_FAILURE;
}
size_t lines = 0, words = 0, longest = 0;
lines++;
if (line.len > longest) longest = line.len;
}
print_count(color, "lines", lines);
print_count(color, "words", words);
print_count(color,
"bytes", text.
len);
print_count(color, "longest", longest);
return EXIT_SUCCESS;
}
#define LOG_GREEN
Green text.
#define LOG_RESET
Back to the terminal's default style.
bool log_color_enabled(FILE *f)
True when colour escapes written to f will render as colour.
const Allocator * arena_allocator(Arena *a)
An Allocator that draws from a.
void arena_free(Arena *a)
Release every block.
Bump allocator over a chain of blocks.
size_t len
Bytes of content, excluding the terminator.
#define SV(lit)
View of a string literal, with its length computed at compile time.
StrView str_view(const Str *s)
Borrow the whole of s.
bool sv_token_next(StrView *rest, StrView delims, StrView *token)
strtok without the mutation: skip delims, then cut the next run of other bytes.
bool str_append_file(Str *s, FILE *f)
Append everything left to read from f.
bool sv_ends_with(StrView v, StrView suffix)
True when v ends with suffix.
bool sv_split_next(StrView *rest, StrView sep, StrView *piece)
Cut the piece before sep off rest.
StrView sv_slice(StrView v, size_t from, size_t to)
Bytes from up to but not including to.
Owned, growable byte string.
Non-owning view of bytes; handy for passing slices and literals around.