summaryrefslogtreecommitdiff
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
parent16fc477e1d18fee40f807770f02c77c01d2fe852 (diff)
Working pattern recognition algorithmdeveloppement
-rw-r--r--groffdown.c32
-rw-r--r--tree.h95
2 files changed, 57 insertions, 70 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); */
diff --git a/tree.h b/tree.h
index c4f86b9..1e9971a 100644
--- a/tree.h
+++ b/tree.h
@@ -1,6 +1,7 @@
typedef struct singleNode {
char pattern; // Character to match
- int pos; // Position of char to match relative to it's parent node.
+ int move; // Position of char to match relative to it's parent node.
+ int start; // Position where the matched pattern starts relative to this char.
int event; // What happens when this treeNode is the last to be matched
// 0: Invalid match: Match pattern is most likely incomplete (or escaped)
// 1: italics delimiter
@@ -28,242 +29,242 @@ typedef struct singleNode {
// 8 depth {{{
node n_dfaaaaaa = {
- ':', 1, 11, 0,
+ ':', 1, 0, 11, 0,
{}
};
// }}}
// 7 depth {{{
node n_dfaaaaa = {
- 'r', 1, 0, 1,
+ 'r', 1, 0, 0, 1,
{&n_dfaaaaaa}
};
node n_dfcaaaa = {
- ':', 1, 10, 0,
+ ':', 1, 0, 10, 0,
{}
};
// }}}
// 6 depth {{{
node n_dfaaaa = {
- 'o', 1, 0, 1,
+ 'o', 1, 0, 0, 1,
{&n_dfaaaaa}
};
node n_dfbaaa = {
- ':', 1, 13, 0,
+ ':', 1, 0, 13, 0,
{}
};
node n_dfbaab = {
- '\n', 1, 12, 0,
+ '\n', 1, 0, 12, 0,
{}
};
node n_dfcaaa = {
- 'e', 1, 0, 1,
+ 'e', 1, 0, 0, 1,
{&n_dfcaaaa}
};
// }}}
// 5 depth {{{
node n_dfaaa = {
- 'h', 2, 0, 1,
+ 'h', 2, 0, 0, 1,
{&n_dfaaaa}
};
node n_dfbaa = {
- 'e', 2, 0, 2,
+ 'e', 2, 0, 0, 2,
{&n_dfbaaa, &n_dfbaab}
};
node n_dfcaa = {
- 'l', 2, 0, 1,
+ 'l', 2, 0, 0, 1,
{&n_dfcaaa}
};
// }}}
// 4 depth {{{
node n_dfca = {
- 'i', 1, 0, 1,
+ 'i', 1, 0, 0, 1,
{&n_dfcaa}
};
node n_cbaa = {
- '\n', -3, 5, 0,
+ '\n', -3, 0, 5, 0,
{}
};
node n_deaa = {
- '-', -1, 9, 0,
+ '-', -1, 0, 9, 0,
{}
};
node n_dfaa = {
- 'u', 1, 0, 1,
+ 'u', 1, 0, 0, 1,
{&n_dfaaa}
};
node n_dfba = {
- 'a', 1, 0, 1,
+ 'a', 1, 0, 0, 1,
{&n_dfbaa}
};
// }}}
// 3 depth {{{
node n_dfc = {
- 't', -2, 0, 1,
+ 't', -2, 0, 0, 1,
{&n_dfca}
};
node n_aba = {
- '_', -2, 15, 0,
+ '_', -2, 0, 15, 0,
{}
};
node n_abb = {
- '*', 1, 3, 0,
+ '*', 1, 0, 3, 0,
{}
};
node n_abc = {
- '_', 1, 3, 0,
+ '_', 1, 0, 3, 0,
{}
};
node n_aca = {
- '_', -1, 16, 0,
+ '_', -1, 0, 16, 0,
{}
};
node n_ada = {
- '_', 1, 3, 0,
+ '_', 1, 0, 3, 0,
{}
};
node n_bba = {
- '_', 1, 3, 0,
+ '_', 1, 0, 3, 0,
{}
};
node n_cba = {
- '`', 1, 0, 1,
+ '`', 1, 0, 0, 1,
{&n_cbaa}
};
node n_dea = {
- '-', -1, 0, 1,
+ '-', -1, 0, 0, 1,
{&n_deaa}
};
node n_dfa = {
- 'a', -2, 0, 1,
+ 'a', -2, 0, 0, 1,
{&n_dfaa}
};
node n_dfb = {
- 'd', -2, 0, 1,
+ 'd', -2, 0, 0, 1,
{&n_dfba}
};
// }}}
// 2 depth {{{
node n_df = {
- 't', 3, 0, 3,
+ 't', 3, 0, 0, 3,
{&n_dfa, &n_dfb, &n_dfc}
};
node n_aa = {
- '\\', -1, 17, 0,
+ '\\', -1, 0, 17, 0,
{}
};
node n_ab = {
- '*', 1, 2, 3,
+ '*', 1, 0, 2, 3,
{&n_aba, &n_abb, &n_abc}
};
node n_ac = {
- '_', -1, 0, 1,
+ '_', -1, 0, 0, 1,
{&n_aca}
};
node n_ad = {
- '_', 1, 0, 1,
+ '_', 1, 0, 0, 1,
{&n_ada}
};
node n_ba = {
- '\\', -1, 18, 0,
+ '\\', -1, 0, 18, 0,
{}
};
node n_bb = {
- '_', 1, 0, 1,
+ '_', 1, 0, 0, 1,
{&n_bba}
};
node n_ca = {
- '\\', -1, 19, 0,
+ '\\', -1, 0, 19, 0,
{}
};
node n_cb = {
- '`', 1, 0, 1,
+ '`', 1, 0, 0, 1,
{&n_cba}
};
node n_da = {
- '#', 1, 8, 0,
+ '#', 1, 0, 8, 0,
{}
};
node n_db = {
- '=', 1, 6, 0,
+ '=', 1, 0, 6, 0,
{}
};
node n_dc = {
- '-', 1, 7, 0,
+ '-', 1, 0, 7, 0,
{}
};
node n_dd = {
- '>', 1, 14, 0,
+ '>', 1, 0, 14, 0,
{}
};
node n_de = {
- '-', -1, 0, 1,
+ '-', -1, 0, 0, 1,
{&n_dea}
};
// }}}
// 1 depth {{{
node n_a = {
- '*', 0, 1, 4,
+ '*', 0, 0, 1, 4,
{&n_aa, &n_ab, &n_ac, &n_ad}
};
node n_b = {
- '_', 0, 1, 2,
+ '_', 0, 0, 1, 2,
{&n_ba, &n_bb}
};
node n_c = {
- '`', 0, 4, 2,
+ '`', 0, 0, 4, 2,
{&n_ca, &n_cb}
};
node n_d = {
- '\n', 0, 0, 6,
- {&n_da, &n_db, &n_dc, &n_dd, &n_de, &n_df, }
+ '\n', 0, 0, 0, 6,
+ {&n_da, &n_db, &n_dc, &n_dd, &n_de, &n_df}
};
// }}}
node main_root = {
- '@', 0, 0, 4,
+ '@', 0, 0, 0, 4,
{&n_a, &n_b, &n_c, &n_d}
};