From fb6a887f2393a81ce8d60dd9ee3f7fdfab2d1d7c Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Mon, 18 Jan 2021 12:06:59 -0500 Subject: Working pattern recognition algorithm --- groffdown.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'groffdown.c') diff --git a/groffdown.c b/groffdown.c index 1a96109..ea939cb 100644 --- a/groffdown.c +++ b/groffdown.c @@ -2,7 +2,7 @@ title: groffdown author: Benjamin Chausse - last update: 2020-01-02 + last update: 2020-01-18 Groffdown is meant as a translation layer between markdown and groff (or GNU/Troff if you are so inclined). Most solutions for generating formatted @@ -23,44 +23,28 @@ #include #include "tree.h" -#include "preprocessing.h" +#include "matchlist.h" FILE *fileptr; char *buffer; long filelen; - -void printnode(node *n) { - printf(" ---------Node:-------- -pattern: %c -pos: %d -event: %d -childsize: %d ----------------------\n\n", - n->pattern, - n->pos, - n->event, - n->childsize - ); -} - /* * Checks for pattern matches within all the nodes children * returns the the deepest child for which there is a match * returns 0 if no match was found - * if node a->pos, b->pos = -1, 2 (And b is a's child) + * if node a->move, b->move = -1, 2 (And b is a's child) * b should be changed to 3: * 0(the root) -1(node a) + 3(node b) = 2 - * 2 being b's actual position relative to root + * 2 being b's actual moveition relative to root */ node * checkChildren(node *n, char *b){ node *curr; for ( int i = 0; i < n->childsize-1; i++ ) { curr = n->child[i]; - if ( curr->pattern == b[curr->pos] ){ - return checkChildren(curr, b+curr->pos); + if ( curr->pattern == b[curr->move] ){ + return checkChildren(curr, b+curr->move); }; }; return n; @@ -69,7 +53,9 @@ node * checkChildren(node *n, char *b){ int main() { char *c = "\\*ello"; - c ++; + const char *bufstart = c; + c +=4; + printf("Index: %d\n", c-bufstart); node *current = &main_root; /* printf("CS: %d\n", n->childsize); */ -- cgit v1.2.3