fixes #6 ; support of multiple triggers
This commit is contained in:
parent
18e9624c1c
commit
2bca74aae1
@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const pkg = require('./package.json');
|
const pkg = require('../package.json');
|
||||||
let lib = require('bindings')('vcd.node');
|
let lib = require('bindings')('vcd.node');
|
||||||
|
|
||||||
module.exports = () => {
|
module.exports = () => {
|
||||||
|
|
||||||
|
const triggers = [];
|
||||||
|
|
||||||
const info = {path: []};
|
const info = {path: []};
|
||||||
|
|
||||||
const s = new stream.Writable();
|
const s = new stream.Writable();
|
||||||
@ -24,9 +26,13 @@ module.exports = () => {
|
|||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
|
|
||||||
s.onTrigger = (id, fn) => {
|
s.change = {
|
||||||
lib.setTrigger(cxt, id);
|
on: (id, fn) => {
|
||||||
|
triggers.push(id);
|
||||||
|
const triggerString = triggers.join(' ') + ' ';
|
||||||
|
lib.setTrigger(cxt, triggerString);
|
||||||
triee.on(id, fn);
|
triee.on(id, fn);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
s.version = pkg.version;
|
s.version = pkg.version;
|
@ -4,7 +4,7 @@
|
|||||||
"description": "Value Change Dump (VCD) parser",
|
"description": "Value Change Dump (VCD) parser",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"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"
|
"build": "node bin/build.js && node-gyp rebuild"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const expect = require('chai').expect;
|
const expect = require('chai').expect;
|
||||||
const vcd = require('../index.js');
|
const vcd = require('../lib/index.js');
|
||||||
|
|
||||||
describe('basic', () => {
|
describe('basic', () => {
|
||||||
|
|
||||||
|
4
vcd.c
4
vcd.c
@ -55,7 +55,7 @@
|
|||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
size_t result; \
|
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); \
|
napi_throw(env, name); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
@ -122,7 +122,7 @@ METHOD(init) {
|
|||||||
ASSERT_FUNCTION(args[1], state->triee)
|
ASSERT_FUNCTION(args[1], state->triee)
|
||||||
ASSERT_OBJECT(args[2], state->hier)
|
ASSERT_OBJECT(args[2], state->hier)
|
||||||
|
|
||||||
static char triggerString [256];
|
static char triggerString [4096] = " ";
|
||||||
|
|
||||||
state->trigger = triggerString;
|
state->trigger = triggerString;
|
||||||
state->reason = "NO REASON";
|
state->reason = "NO REASON";
|
||||||
|
24
vcd_spans.c
24
vcd_spans.c
@ -9,19 +9,31 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
int stringEq (
|
int stringEq (
|
||||||
const unsigned char* gold,
|
const unsigned char* gold, // search pattern
|
||||||
const unsigned char* p,
|
const unsigned char* p,
|
||||||
const unsigned char* endp
|
const unsigned char* endp
|
||||||
) {
|
) {
|
||||||
if (gold[0] == 0) {
|
unsigned char* i;
|
||||||
return 0;
|
unsigned char* j;
|
||||||
}
|
i = gold;
|
||||||
for (size_t i = 0; gold[i] != 0; i++) {
|
j = p;
|
||||||
if (gold[i] != p[i]) {
|
while (1) {
|
||||||
|
if (*i == ' ') { // end of search pattern
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
while (*i == *j) { // follow matching trail
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
|
if ((*i == ' ') && (j == (endp - 1))) { // exact match
|
||||||
return 1;
|
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) {
|
int commandSpan(vcd_parser_t* state, const unsigned char* p, const unsigned char* endp) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user