]> git.xolatile.top Git - public-libhl.git/commitdiff
it sort of works now
authoranon <anon@anon.anon>
Fri, 25 Aug 2023 23:16:05 +0000 (01:16 +0200)
committeranon <anon@anon.anon>
Fri, 25 Aug 2023 23:16:05 +0000 (01:16 +0200)
source/main.c
source/regex.c

index 77d4868f7b618f0b21362bc0477e5eb8288773cb..2a09724214f58884d25c765ea65235e35307c64f 100644 (file)
@@ -42,6 +42,7 @@ int main(int      argc,
        //
        #include "c.h"
        //
+
        render_string(buffer, "cterm");
        putchar('\n');
        fflush(stdout);
index ece14def859f89a9393e96399a41e8687b1ae080..6dea9eb93795f3330ca8eed763cfe3e4cfdd492c 100644 (file)
@@ -311,19 +311,6 @@ static int compile_range(const char * const     range,
        return ((s - range) + 1);
 }
 
-static bool catch_(const regex_t * const regex,
-                         int     * const state) {
-
-       for (size_t i = 0; i < regex->catch_table.element_count; i++){
-               const offshoot_t * const offshoot = *(offshoot_t**)vector_get(&regex->catch_table, i);
-               if (offshoot->in == *state) {
-                       *state = offshoot->to;
-                       return true;
-               }
-       }
-       return false;
-}
-
 #define HALT_AND_CATCH_FIRE -1
 
 void HOOK_ALL(int              from,
@@ -343,7 +330,7 @@ void HOOK_ALL(int              from,
                vector_push(&cs->regex->delta_table,
                            &delta);
        }
-       if (cs->do_catch || cs->is_negative) {
+       if (*cs->do_catch || *cs->is_negative) {
                offshoot_t * offshoot = malloc(sizeof(offshoot_t));
                offshoot->in = *cs->state + from; 
                offshoot->to   = hook_to;
@@ -383,6 +370,7 @@ regex_t * regex_compile(const char * const pattern) {
                assert(!is_quantifier(*pattern) && "Pattern starts with quantifier.");
                whitelist[0] = '\00';
                do_catch     = false;
+               is_negative  = false;
                width        = 1;
 
                switch (*s) {
@@ -454,9 +442,23 @@ int regex_free(regex_t * const regex) {
 // -----------------
 // ### Searching ###
 // -----------------
-static bool regex_assert(const regex_t * const  regex,
+static bool catch_(const regex_t * const regex,
+                         int     * const state) {
+
+       for (size_t i = 0; i < regex->catch_table.element_count; i++){
+               const offshoot_t * const offshoot = *(offshoot_t**)vector_get(&regex->catch_table, i);
+               if (offshoot->in == *state) {
+                       *state = offshoot->to;
+                       return true;
+               }
+       }
+       return false;
+}
+
+static int regex_assert(const regex_t * const  regex,
                          const char    * const string,
-                               int              state) {
+                               int              state,
+                                                          int     *        width) {
 
        for (const char * s = string; *s != '\00'; s++) {
                // delta
@@ -474,14 +476,14 @@ static bool regex_assert(const regex_t * const  regex,
                        continue;
                }
 
-               return false;
+               return (state == regex->accepting_state);
        }
 
-       return (state == regex->accepting_state);
+       return false;
 }
 
-bool regex_search(      regex_t *        regex,
-                  const char    * const string) {
+int regex_match(      regex_t *        regex,
+                const char    * const string) {
 
        if (regex == NULL) {
                return false;
@@ -490,5 +492,13 @@ bool regex_search(      regex_t *        regex,
                return true;
        }
 
-       return regex_assert(regex, string, 0);
+       int r = 0;
+       return regex_assert(regex, string, 0, &r);
 }
+
+bool regex_search(      regex_t *        regex,
+                  const char    * const string) {
+
+       return (bool)regex_match(regex, string, 0);
+}
+