+/* ----------------- reading/writing of primitives with caching -------------- */
+
+static char* read_string(reader_t*r, state_t*state, U8 id, U8 flags)
+{
+ assert(id>=0 && id<16);
+ if(flags&FLAG_SAME_AS_LAST) {
+ assert(state->last_string[id]);
+ return strdup(state->last_string[id]);
+ }
+ char*s = reader_readString(r);
+ state->last_string[id] = strdup(s);
+ return s;
+}
+static gfxcolor_t read_color(reader_t*r, state_t*state, U8 id, U8 flags)
+{
+ assert(id>=0 && id<16);
+ if(flags&FLAG_SAME_AS_LAST)
+ return state->last_color[id];
+ gfxcolor_t c = readColor(r, state);
+ state->last_color[id] = c;
+ return c;
+}
+static gfxmatrix_t read_matrix(reader_t*r, state_t*state, U8 id, U8 flags)
+{
+ assert(id>=0 && id<16);
+ if(flags&FLAG_SAME_AS_LAST) {
+ gfxmatrix_t m = state->last_matrix[id];
+ readXY(r, state, &m);
+ return m;
+ }
+ gfxmatrix_t m = readMatrix(r, state);
+ state->last_matrix[id] = m;
+ return m;
+}
+
+/* --------------------------- record device operations ---------------------- */
+
+static int record_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
+{
+ internal_t*i = (internal_t*)dev->internal;
+ msg("<trace> record: %08x SETPARAM %s %s\n", dev, key, value);
+ writer_writeU8(&i->w, OP_SETPARAM);
+ writer_writeString(&i->w, key);
+ writer_writeString(&i->w, value);
+ return 1;
+}
+