fixes #6 ; support of multiple triggers

This commit is contained in:
Aliaksei Chapyzhenka 2019-11-10 18:00:18 -08:00
parent 18e9624c1c
commit 2bca74aae1
5 changed files with 33 additions and 15 deletions

View File

@ -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);
s.change = {
on: (id, fn) => {
triggers.push(id);
const triggerString = triggers.join(' ') + ' ';
lib.setTrigger(cxt, triggerString);
triee.on(id, fn);
}
};
s.version = pkg.version;

View File

@ -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": {

View File

@ -1,7 +1,7 @@
'use strict';
const expect = require('chai').expect;
const vcd = require('../index.js');
const vcd = require('../lib/index.js');
describe('basic', () => {

4
vcd.c
View File

@ -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";

View File

@ -9,20 +9,32 @@
}
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
}
}
int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
napi_env env = state->napi_env;