[genius] Thu Aug 21 16:55:25 2014 Jiri (George) Lebl <jirka 5z com>



commit 39d33aedc068e7dc04f6c640c841055a2bc3a9d2
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date:   Thu Aug 21 16:57:10 2014 -0500

    Thu Aug 21 16:55:25 2014  Jiri (George) Lebl <jirka 5z com>
    
        * src/calc.c, src/compil.c: change the encoding/decoding of strings
          to be not stupid, waste a byte and add more legal characters to the
          list.  Also remove extra unneeded letters from the function record,
          streamlining things a bit more.  Altogether save another 2.7k from
          the compiled standard library.

 ChangeLog    |    8 ++++++++
 src/calc.c   |   24 ++++++++++++++++--------
 src/compil.c |   25 +++++++++++--------------
 3 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 979e901..a9b208b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Aug 21 16:55:25 2014  Jiri (George) Lebl <jirka 5z com>
+
+       * src/calc.c, src/compil.c: change the encoding/decoding of strings
+         to be not stupid, waste a byte and add more legal characters to the
+         list.  Also remove extra unneeded letters from the function record,
+         streamlining things a bit more.  Altogether save another 2.7k from
+         the compiled standard library.
+
 Thu Aug 21 14:11:31 2014  Jiri (George) Lebl <jirka 5z com>
 
        * src/calc.c: Reduce redundancy in the compiled file, killing about
diff --git a/src/calc.c b/src/calc.c
index 5d53d56..d2f6d7b 100644
--- a/src/calc.c
+++ b/src/calc.c
@@ -1894,7 +1894,8 @@ compile_funcs_in_dict (FILE *outfile, GSList *dict, gboolean is_extra_dict)
 
                if (func->type == GEL_USER_FUNC) {
                        fprintf (outfile,
-                                "%c;%d;%s;%s;n%d;v%d;p%d;o%d;l%d;e%d;b%d",
+                                /*old "%c;%d;%s;%s;n%d;v%d;p%d;o%d;l%d;e%d;b%d",*/
+                                "%c;%d;%s;%s;%d;%d;%d;%d;%d;%d;%d",
                                 fs,
                                 (int)strlen (body),
                                 func->id->token,
@@ -2213,7 +2214,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        nargs = -1;
-                       sscanf(p,"n%d",&nargs);
+                       /*old sscanf(p,"n%d",&nargs); */
+                       sscanf(p,"%d",&nargs);
                        if G_UNLIKELY (nargs == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
@@ -2226,7 +2228,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        vararg = -1;
-                       sscanf(p,"v%d",&vararg);
+                       /*old sscanf(p,"v%d",&vararg); */
+                       sscanf(p,"%d",&vararg);
                        if G_UNLIKELY (vararg == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
@@ -2239,7 +2242,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        propagate_mod = -1;
-                       sscanf(p,"p%d",&propagate_mod);
+                       /*old sscanf(p,"p%d",&propagate_mod); */
+                       sscanf(p,"%d",&propagate_mod);
                        if G_UNLIKELY (propagate_mod == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
@@ -2252,7 +2256,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        no_mod_all_args = -1;
-                       sscanf(p,"o%d",&no_mod_all_args);
+                       /*old sscanf(p,"o%d",&no_mod_all_args); */
+                       sscanf(p,"%d",&no_mod_all_args);
                        if G_UNLIKELY (no_mod_all_args == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
@@ -2265,7 +2270,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        local_all = -1;
-                       sscanf(p,"l%d",&local_all);
+                       /*old sscanf(p,"l%d",&local_all); */
+                       sscanf(p,"%d",&local_all);
                        if G_UNLIKELY (local_all == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
@@ -2278,7 +2284,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        never_on_subst_list = -1;
-                       sscanf(p,"e%d",&never_on_subst_list);
+                       /*old sscanf(p,"e%d",&never_on_subst_list); */
+                       sscanf(p,"%d",&never_on_subst_list);
                        if G_UNLIKELY (never_on_subst_list == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
@@ -2291,7 +2298,8 @@ load_compiled_fp (const char *file, FILE *fp)
                                continue;
                        }
                        built_subst_dict = -1;
-                       sscanf(p,"b%d",&built_subst_dict);
+                       /*old sscanf(p,"b%d",&built_subst_dict); */
+                       sscanf(p,"%d",&built_subst_dict);
                        if G_UNLIKELY (built_subst_dict == -1) {
                                gel_errorout (_("Badly formed record"));
                                continue;
diff --git a/src/compil.c b/src/compil.c
index 319a799..1bd008d 100644
--- a/src/compil.c
+++ b/src/compil.c
@@ -42,11 +42,9 @@
 char *
 gel_decode_string (const char *s)
 {
-       if (s == NULL)
+       if (s == NULL) {
                return NULL;
-       if (s[0] == 'A') {
-               return g_strdup (&(s[1]));
-       } else if (s[0] == 'B') {
+       } else if (s[0] == '=') {
                gsize len;
                char *p = (char *)g_base64_decode (&(s[1]), &len);
                if (p == NULL || len < 0) /* error was probably logged by now */
@@ -54,11 +52,8 @@ gel_decode_string (const char *s)
                p = g_realloc (p, len+1);
                p[len] = '\0';
                return p;
-       } else if (s[0] == 'E') {
-               return g_strdup ("");
        } else {
-               g_warning ("gel_decode_string: bad string!");
-               return NULL;
+               return g_strdup (s);
        }
 }
 
@@ -66,11 +61,13 @@ static int
 is_ok_ascii (const char *s)
 {
        const char *p;
+       if (s[0] == '=')
+               return FALSE;
        for (p = s; *p != '\0'; p++) {
                if ( ! ( (*p >= 'a' && *p <= 'z') ||
                         (*p >= 'A' && *p <= 'Z') ||
                         (*p >= '0' && *p <= '9') ||
-                        strchr ("():,.[] !?~+-_{}/=><*^'\"", *p) != NULL) ) {
+                        strchr ("():,.[] !?~+-_{}/=><*^'\"@#$|\\&\t", *p) != NULL) ) {
                        return FALSE;
                }
        }
@@ -80,13 +77,13 @@ is_ok_ascii (const char *s)
 char *
 gel_encode_string (const char *s)
 {
-       if (ve_string_empty (s))
-               return g_strdup ("E");
-       if (is_ok_ascii (s)) {
-               return g_strconcat ("A", s, NULL);
+       if (ve_string_empty (s)) {
+               return g_strdup ("");
+       } else if (is_ok_ascii (s)) {
+               return g_strdup (s);
        } else {
                char *p = g_base64_encode ((const unsigned char *)s, strlen (s));
-               char *ret = g_strconcat ("B", p, NULL);
+               char *ret = g_strconcat ("=", p, NULL);
                g_free (p);
                return ret;
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]