ref: e46528a5028c4d2080d075002037444769e93218
parent: 0cbe9b4217052015b2a1d979dbe4ede82410070d
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Jun 11 21:11:23 EDT 2024
add a simple test
--- /dev/null
+++ b/.gitignore
@@ -1,0 +1,3 @@
+out.h
+[a0125678vqki].*
+*.[o0125678vqki]
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,10 @@
+</$objtype/mkfile
+
+BIN=/$objtype/bin
+TARG=test
+HFILES=\
+ out.h\
+
+default:V: all
+
+</sys/src/cmd/mkmany
--- /dev/null
+++ b/test.c
@@ -1,0 +1,67 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+typedef struct Ctx Ctx;
+
+struct Ctx {
+ u8int buf[8192];
+ Biobuf *f;
+};
+
+u8int *
+ctxreadn(Ctx *ctx, int n)
+{
+ int r;
+ if((r = Bread(ctx->f, ctx->buf, n)) != n){
+ werrstr("short read: need %d, got %d", n, r);
+ return nil;
+ }
+ return ctx->buf;
+}
+
+int
+ctxarray(Ctx *ctx, void **arr_, void *fun_, int elsz, int num)
+{
+ int i;
+ int (*fun)(Ctx*, void*);
+ u8int *arr;
+
+ if((arr = calloc(num, elsz)) == nil)
+ return -1;
+ fun = fun_;
+ for(i = 0; i < num; i++){
+ if(fun(ctx, arr + i*elsz) < 0){
+ free(arr);
+ return -1;
+ }
+ }
+ *arr_ = arr;
+ return 0;
+}
+
+#include "out.h"
+
+void
+main(int argc, char **argv)
+{
+ TableDirectory td;
+ Ctx ctx;
+ int i;
+
+ otfinit();
+ for(i = 1; i < argc; i++){
+ print("%s\n", argv[i]);
+ if((ctx.f = Bopen(argv[i], OREAD)) == nil){
+ fprint(2, "%r\n");
+ }else if(read_TableDirectory(&ctx, &td) != 0){
+ fprint(2, "%s: %r\n", argv[i]);
+ } else {
+ fprint_TableDirectory(1, 0, &td);
+ }
+ if(ctx.f != nil)
+ Bterm(ctx.f);
+ }
+
+ exits(nil);
+}