summaryrefslogtreecommitdiff
path: root/groffdown.c
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2021-01-18 12:06:59 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2021-01-18 12:06:59 -0500
commitfb6a887f2393a81ce8d60dd9ee3f7fdfab2d1d7c (patch)
treeb14fa1565ec7f9ebe91a66e3cfe2ec4b8fd42832 /groffdown.c
parent16fc477e1d18fee40f807770f02c77c01d2fe852 (diff)
Working pattern recognition algorithm
Diffstat (limited to 'groffdown.c')
-rw-r--r--groffdown.c32
1 files changed, 9 insertions, 23 deletions
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 <string.h>
#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); */