1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
diff --git a/build/so/Makefile b/build/so/Makefile
index 8447fa2..f96ffc1 100644
--- a/build/so/Makefile
+++ b/build/so/Makefile
@@ -7,8 +7,8 @@ CFLAGS = -O0 -ggdb -W -Wall -Werror -fpic
LDFLAGS = -fPIC -shared
LIBS =
-HEADERS = ord.h string7.h strings7.h
-OBJECTS = ord.o string7.o strings7.o
+HEADERS = bus7.h ord.h string7.h strings7.h
+OBJECTS = bus7.o ord.o string7.o strings7.o
SRC = ${HEADERS} ${OBJECTS:%.o=%.c}
diff --git a/bus7.c b/bus7.c
new file mode 100644
index 0000000..1c194a4
--- /dev/null
+++ b/bus7.c
@@ -0,0 +1,4 @@
+
+#include "bus7.h"
+
+CODE_BUS7(8000)
diff --git a/bus7.h b/bus7.h
new file mode 100644
index 0000000..6a7d3c4
--- /dev/null
+++ b/bus7.h
@@ -0,0 +1,138 @@
+
+#ifndef BUS7_H
+#define BUS7_H
+
+#include "string7.h"
+#include "strings7.h"
+
+#define STRUCT_BUS7(count) struct bus7_ ## count
+#define S_BUS7(count) s_bus7_ ## count
+#define TYPEDEF_BUS7(count) \
+ typedef \
+ STRUCT_BUS7(count) \
+ S_BUS7(count); \
+
+#define STRUCT__BUS7(count) \
+ STRUCT_BUS7(count) \
+ { \
+ unsigned in; \
+ unsigned out; \
+ unsigned len; \
+ strings7 r[count]; \
+ strings7 e; \
+ }; \
+
+#define INIT_BUS7(var) \
+ var.in = var.out = var.len = 0;
+
+#define BUS7_FIRST(count) bus7_ ## count ## _first
+#define PROTO_BUS7_FIRST(count) \
+ strings7 * BUS7_FIRST(count) (S_BUS7(count) *b)
+#define DEF_BUS7_FIRST(count) \
+ PROTO_BUS7_FIRST(count) \
+ { \
+ if (!b || !b->len) \
+ return 0; \
+ return b->r + b->out; \
+ } \
+
+#define BUS7_LAST(count) bus7_ ## count ## _last
+#define PROTO_BUS7_LAST(count) \
+ strings7 * BUS7_LAST(count) (S_BUS7(count) *b)
+#define DEF_BUS7_LAST(count) \
+ PROTO_BUS7_LAST(count) \
+ { \
+ if (!b || !b->len) \
+ return 0; \
+ return b->r + b->in; \
+ } \
+
+#define BUS7_LEN(count) bus7_ ## count ## _len
+#define PROTO_BUS7_LEN(count) \
+ unsigned BUS7_LEN(count) (S_BUS7(count) *b)
+#define DEF_BUS7_LEN(count) \
+ PROTO_BUS7_LEN(count) \
+ { \
+ if (!b) \
+ return 0; \
+ return b->len; \
+ } \
+
+#define BUS7_NTH(count) bus7_ ## count ## _nth
+#define PROTO_BUS7_NTH(count) \
+ strings7 * BUS7_NTH(count) (S_BUS7(count) *b, unsigned n)
+#define DEF_BUS7_NTH(count) \
+ PROTO_BUS7_NTH(count) \
+ { \
+ strings7 *r = BUS7_FIRST(count)(b); \
+ if (!r) \
+ return 0; \
+ unsigned l = count - (r - b->r); \
+ while (1) { \
+ if (l == 0 || *r >= 0 || l < (unsigned) -*r) { \
+ if (b->out < b->in) \
+ return 0; \
+ r = b->r; \
+ l = b->in; \
+ if (l == 0 || *r >= 0 || l < (unsigned) -*r) \
+ return 0; \
+ } \
+ if (n == 0) \
+ return r; \
+ l += *r; \
+ n--; \
+ r -= *r; \
+ } \
+ } \
+
+#define BUS7_STRING7(count) bus7_ ## count ## _string7
+#define PROTO_BUS7_STRING7(count) \
+ string7 * BUS7_STRING7(count) (string7 *s, S_BUS7(count) *b)
+#define DEF_BUS7_STRING7(count) \
+ PROTO_BUS7_STRING7(count) \
+ { \
+ if (!b || !s || !b->len) \
+ return 0; \
+ if ((b->out < b->in && b->out + b->r < s && s < b->in + b->r) || \
+ (b->out >= b->in && ((b->out + b->r < s && s < count + b->r) || \
+ (b->r < s && s < b->in + b->r)))) \
+ return s; \
+ strings7 *r = BUS7_FIRST(count)(b); \
+ if (!r) \
+ return 0; \
+ unsigned l = count - (r - b->r); \
+ while (1) { \
+ if (l == 0 || *r >= 0 || l < (unsigned) -*r) { \
+ if (b->out < b->in) \
+ return 0; \
+ r = b->r; \
+ l = b->in; \
+ if (l == 0 || *r >= 0 || l < (unsigned) -*r) \
+ return 0; \
+ } \
+ if (string7_eq(r, s)) \
+ return r; \
+ l += *r; \
+ r -= *r; \
+ } \
+ } \
+
+#define HEADER_BUS7(count) \
+ TYPEDEF_BUS7(count) \
+ STRUCT__BUS7(count) \
+ PROTO_BUS7_FIRST(count); \
+ PROTO_BUS7_LAST(count); \
+ PROTO_BUS7_LEN(count); \
+ PROTO_BUS7_NTH(count); \
+ PROTO_BUS7_STRING7(count);
+
+#define CODE_BUS7(count) \
+ DEF_BUS7_FIRST(count) \
+ DEF_BUS7_LAST(count) \
+ DEF_BUS7_LEN(count) \
+ DEF_BUS7_NTH(count) \
+ DEF_BUS7_STRING7(count)
+
+HEADER_BUS7(8000)
+
+#endif /* BUS7_H */