diff --git a/lib/parser.js b/lib/parser.js index bf52b77..ef82e6c 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -16,19 +16,25 @@ module.exports = () => { const triee = new EventEmitter(); const triemit = triee.emit.bind(triee); + let triemit2 = triemit; const cxt = lib.init(lifemit, triemit, info); s._write = function (chunk, encoding, callback) { - lib.execute(cxt, lifemit, triemit, info, chunk); + lib.execute(cxt, lifemit, triemit2, info, chunk); callback(); }; s.change = { on: (id, fn) => { + triemit2 = triemit; triee.on(id, fn); const triggerString = triee.eventNames().join(' ') + ' '; lib.setTrigger(cxt, triggerString); + }, + any: fn => { + triemit2 = fn; + lib.setTrigger(cxt, '\0'); } }; diff --git a/test/any.js b/test/any.js new file mode 100644 index 0000000..c04a42b --- /dev/null +++ b/test/any.js @@ -0,0 +1,43 @@ +'use strict'; + +const expect = require('chai').expect; +const lib = require('../lib/index.js'); + +describe('any', () => { + + it('simple', done => { + const inst = lib.parser(); + const dump = []; + inst.change.any((id, time, cmd, value, mask) => { + dump.push({ + id, time, cmd, value, mask + }); + }); + + inst.on('finish', () => { + expect(dump).to.deep.eq([ + { id: 'ABC', time: 100, cmd: 14, value: 0n, mask: 0n }, + { id: '123', time: 200, cmd: 15, value: 1n, mask: 0n }, + { id: 'XyZ', time: 300, cmd: 14, value: 0n, mask: 0n }, + { id: 'foo', time: 400, cmd: 15, value: 1n, mask: 0n }, + ]) + // console.log(dump); + done(); + }); + + inst.write(`\ +$enddefinitions $end +#100 +0ABC +#200 +1123 +#300 +0XyZ +#400 +1foo +`); + inst.end(); + }); +}); + +/* eslint-env mocha */ diff --git a/vcd_spans.c b/vcd_spans.c index dab5861..1a26cb7 100644 --- a/vcd_spans.c +++ b/vcd_spans.c @@ -25,6 +25,9 @@ int stringEq ( const unsigned char* p, const unsigned char* endp ) { + if (gold[0] == 0) { + return 1; + } unsigned char* i; unsigned char* j; i = gold;