diff --git a/index.js b/lib/index.js similarity index 71% rename from index.js rename to lib/index.js index d17b84d..246c6f8 100644 --- a/index.js +++ b/lib/index.js @@ -2,11 +2,13 @@ const stream = require('stream'); const EventEmitter = require('events').EventEmitter; -const pkg = require('./package.json'); +const pkg = require('../package.json'); let lib = require('bindings')('vcd.node'); module.exports = () => { + const triggers = []; + const info = {path: []}; const s = new stream.Writable(); @@ -24,9 +26,13 @@ module.exports = () => { callback(); }; - s.onTrigger = (id, fn) => { - lib.setTrigger(cxt, id); - triee.on(id, fn); + s.change = { + on: (id, fn) => { + triggers.push(id); + const triggerString = triggers.join(' ') + ' '; + lib.setTrigger(cxt, triggerString); + triee.on(id, fn); + } }; s.version = pkg.version; diff --git a/package.json b/package.json index 45a1960..b248109 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Value Change Dump (VCD) parser", "main": "lib/index.js", "scripts": { - "test": "eslint bin && nyc -r=text -r=lcov mocha", + "test": "eslint bin lib && nyc -r=text -r=lcov mocha", "build": "node bin/build.js && node-gyp rebuild" }, "repository": { diff --git a/test/basic.js b/test/basic.js index 7bda9b4..469979a 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,7 +1,7 @@ 'use strict'; const expect = require('chai').expect; -const vcd = require('../index.js'); +const vcd = require('../lib/index.js'); describe('basic', () => { diff --git a/vcd.c b/vcd.c index c636b4a..aa67179 100644 --- a/vcd.c +++ b/vcd.c @@ -55,7 +55,7 @@ return 0; \ } \ size_t result; \ - if (napi_get_value_string_latin1(env, tmp, var, 256, &result) != napi_ok) { \ + if (napi_get_value_string_latin1(env, tmp, var, 4096, &result) != napi_ok) { \ napi_throw(env, name); \ return 0; \ } \ @@ -122,7 +122,7 @@ METHOD(init) { ASSERT_FUNCTION(args[1], state->triee) ASSERT_OBJECT(args[2], state->hier) - static char triggerString [256]; + static char triggerString [4096] = " "; state->trigger = triggerString; state->reason = "NO REASON"; diff --git a/vcd_spans.c b/vcd_spans.c index 8aa7e47..0c63542 100644 --- a/vcd_spans.c +++ b/vcd_spans.c @@ -9,19 +9,31 @@ } int stringEq ( - const unsigned char* gold, + const unsigned char* gold, // search pattern const unsigned char* p, const unsigned char* endp ) { - if (gold[0] == 0) { - return 0; - } - for (size_t i = 0; gold[i] != 0; i++) { - if (gold[i] != p[i]) { + unsigned char* i; + unsigned char* j; + i = gold; + j = p; + while (1) { + if (*i == ' ') { // end of search pattern return 0; } + while (*i == *j) { // follow matching trail + i++; + j++; + } + if ((*i == ' ') && (j == (endp - 1))) { // exact match + return 1; + } + while (*i != ' ') { // skip to the end of pattern word + i++; + } + i++; + j = p; // try another word } - return 1; } int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {