]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - correct.c
Remove constant string literal for correction check, use parse_tokval of the current...
[xonotic/gmqcc.git] / correct.c
index 9cadde260c653ef66ac466b0c82508686a398ae5..e32678e754e3770ebb5d142d06a9fc7c0a283ec4 100644 (file)
--- a/correct.c
+++ b/correct.c
@@ -111,10 +111,12 @@ static char *correct_strndup(const char *src, size_t n) {
 static char *correct_concat(char *str1, char *str2, bool next) {
     char *ret = NULL;
 
+#if 0
     if (!str1) {
          str1 = mem_a(1);
         *str1 = '\0';
     }
+#endif
 
     str1 = mem_r (str1, strlen(str1) + strlen(str2) + 1);
     ret  = strcat(str1, str2);
@@ -187,8 +189,8 @@ static size_t correct_alteration(const char *ident, char **array, size_t index)
                     false
                 ),
                 correct_strndup (
-                    ident+itr+1,
-                    len - (itr + 1)
+                    ident + (itr+1),
+                    len   - (itr+1)
                 ),
                 true
             );
@@ -283,8 +285,12 @@ static char **correct_known(ht table, char **array, size_t rows, size_t *next) {
             if (correct_find(table, end[jtr]) && !correct_exist(res, len, end[jtr])) {
                 res        = mem_r(res, sizeof(char*) * (len + 1));
                 res[len++] = end[jtr];
+            } else {
+                mem_d(end[jtr]);
             }
         }
+
+        mem_d(end);
     }
 
     *next = len;
@@ -311,6 +317,8 @@ static void correct_cleanup(char **array, size_t rows) {
     size_t itr;
     for (itr = 0; itr < rows; itr++)
         mem_d(array[itr]);
+
+    mem_d(array);
 }
 
 /*
@@ -334,7 +342,7 @@ void correct_add(ht table, size_t ***size, const char *ident) {
     }
 }
 
-char *correct_correct(ht table, const char *ident) {
+char *correct_str(ht table, const char *ident) {
     char **e1;
     char **e2;
     char  *e1ident;
@@ -348,27 +356,25 @@ char *correct_correct(ht table, const char *ident) {
     if (correct_find(table, ident))
         return found;
 
-    mem_d(found);
     if ((e1rows = correct_size(ident))) {
         e1      = correct_edit(ident);
 
         if ((e1ident = correct_maximum(table, e1, e1rows))) {
+            mem_d(found);
             found = util_strdup(e1ident);
             correct_cleanup(e1, e1rows);
-            mem_d(e1);
             return found;
         }
     }
 
     e2 = correct_known(table, e1, e1rows, &e2rows);
-    if (e2rows && ((e2ident = correct_maximum(table, e2, e2rows))))
+    if (e2rows && ((e2ident = correct_maximum(table, e2, e2rows)))) {
+        mem_d(found);
         found = util_strdup(e2ident);
+    }
     
     correct_cleanup(e1, e1rows);
     correct_cleanup(e2, e2rows);
-
-    mem_d(e1);
-    mem_d(e2);
     
     return found;
 }
@@ -381,37 +387,3 @@ void correct_del(ht dictonary, size_t **data) {
     vec_free(data);
     util_htdel(dictonary);
 }
-
-int main() {
-    opts.debug = true;
-    opts.memchk = true;
-    con_init();
-
-    ht       t = util_htnew(1024);
-    size_t **d = NULL;
-
-    correct_add(t, &d, "hellobain");
-    correct_add(t, &d, "ellor");
-    correct_add(t, &d, "world");
-
-    printf("found identifiers: (2)\n");
-    printf(" 1: hellobain\n");
-    printf(" 2: ellor\n");
-    printf(" 3: world\n");
-
-    char *b = correct_correct(t, "rld");
-    char *a = correct_correct(t, "ello");
-    char *c = correct_correct(t, "helbain");
-
-    printf("invalid identifier: `%s` (did you mean: `%s`?)\n", "ello", a);
-    printf("invalid identifier: `%s` (did you mean: `%s`?)\n", "rld", b);
-    printf("invalid identifier: `%s` (did you mean: `%s`?)\n", "helbain", c);
-
-    correct_del(t, d);
-    mem_d(b);
-    mem_d(a);
-    mem_d(c);
-
-    /*util_meminfo();*/
-
-}