[genius] Tue Jun 28 15:53:40 2011 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Tue Jun 28 15:53:40 2011 Jiri (George) Lebl <jirka 5z com>
- Date: Wed, 29 Jun 2011 00:47:00 +0000 (UTC)
commit 37e94065158584dce8d089689df9c7ef0d9cec8e
Author: Jiri (George) Lebl <jirka 5z com>
Date: Tue Jun 28 15:53:54 2011 -0700
Tue Jun 28 15:53:40 2011 Jiri (George) Lebl <jirka 5z com>
* src/compil.c: use basic ascii for encoding simple strings
use base64 for encoding strings that have nonallowed characters.
* src/compil.c: fix some very minor memory leaks
* configure.in: raise version
ChangeLog | 9 ++++++
configure.in | 2 +-
src/compil.c | 92 ++++++++++++++++++++++++++++++++-------------------------
3 files changed, 62 insertions(+), 41 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index abbe6f5..9a0e2b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Jun 28 15:53:40 2011 Jiri (George) Lebl <jirka 5z com>
+
+ * src/compil.c: use basic ascii for encoding simple strings
+ use base64 for encoding strings that have nonallowed characters.
+
+ * src/compil.c: fix some very minor memory leaks
+
+ * configure.in: raise version
+
Tue Jun 28 14:09:30 2011 Jiri (George) Lebl <jirka 5z com>
* src/gnome-genius.c, ve/ve-miscui.c: update some deprecated things
diff --git a/configure.in b/configure.in
index 7d5a0dc..7fb2ef8 100644
--- a/configure.in
+++ b/configure.in
@@ -1,7 +1,7 @@
AC_INIT(src/calc.c)
AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(genius,1.0.12)
+AM_INIT_AUTOMAKE(genius,1.0.13)
dnl make sure we keep ACLOCAL_FLAGS around for maintainer builds to work
AC_SUBST(ACLOCAL_AMFLAGS, "$ACLOCAL_FLAGS")
diff --git a/src/compil.c b/src/compil.c
index 0a6f630..3d2445f 100644
--- a/src/compil.c
+++ b/src/compil.c
@@ -1,5 +1,5 @@
/* GENIUS Calculator
- * Copyright (C) 1997-2009 George Lebl
+ * Copyright (C) 1997-2011 George Lebl
*
* Author: George Lebl
*
@@ -32,51 +32,64 @@
#include "matrix.h"
#include "matrixw.h"
-#include "compil.h"
+#include <vicious.h>
-/* sort of weird encoding, for each byte use 'a'+upper 4 bits and 'a'+lower 4 bits */
-static void
-append_string (GString *gs,const char *s)
-{
- const char *p;
- char out[3] = "aa";
- for (p = s; *p != '\0'; p++) {
- out[0] = 'a' + ((*p)&0xF);
- out[1] = 'a' + ((*p)>>4);
- g_string_append (gs, out);
- }
-}
+#include "compil.h"
-/*sort of weird encoding, use 'a'+upper 4 bits and 'a'+lower 4 bits*/
+/* first char 'A' then rest just ascii */
+/* first char 'B' then rest Base64 */
+/* first char 'E' then empty */
char *
gel_decode_string (const char *s)
{
- int len = strlen(s);
- const char *ps;
- char *p, *pp;
- if (len%2 == 1)
+ if (s == NULL)
return NULL;
-
- /*the 0 takes care of the termination*/
- p = g_new0(char,(len/2)+1);
-
- for(ps=s,pp=p;*ps;ps+=2,pp++) {
- if(*ps<'a' || *ps >'a'+0xF ||
- *(ps+1)<'a' || *(ps+1) >'a'+0xF) {
- g_free(p);
+ if (s[0] == 'A') {
+ return g_strdup (&(s[1]));
+ } else if (s[0] == 'B') {
+ int len;
+ char *p = g_base64_decode (&(s[1]), &len);
+ if (p == NULL || len < 0) /* error was probably logged by now */
return NULL;
+ 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;
+ }
+}
+
+static int
+is_ok_ascii (const char *s)
+{
+ const char *p;
+ for (p = s; *p != '\0'; p++) {
+ if ( ! ( (*p >= 'a' && *p <= 'z') ||
+ (*p >= 'A' && *p <= 'Z') ||
+ (*p >= '0' && *p <= '9') ||
+ strchr ("():,.[] !?~+-_{}/=><*^'\"", *p) != NULL) ) {
+ return FALSE;
}
- *pp = (*ps-'a') + ((*(ps+1)-'a')<<4);
}
- return p;
+ return TRUE;
}
char *
gel_encode_string (const char *s)
{
- GString *gs = g_string_new (NULL);
- append_string (gs, s);
- return g_string_free (gs, FALSE);
+ if (ve_string_empty (s))
+ return g_strdup ("E");
+ if (is_ok_ascii (s)) {
+ return g_strconcat ("A", s, NULL);
+ } else {
+ char *p = g_base64_encode (s, strlen (s));
+ char *ret = g_strconcat ("B", p, NULL);
+ g_free (p);
+ return ret;
+ }
}
static void
@@ -126,12 +139,10 @@ gel_compile_node(GelETree *t,GString *gs)
g_string_append_printf (gs, ";%s", t->id.id->token);
break;
case GEL_STRING_NODE:
- if(*t->str.str) {
- g_string_append_c(gs,';');
- append_string(gs,t->str.str);
- } else {
- g_string_append(gs,";E");
- }
+ g_string_append_c (gs, ';');
+ s = gel_encode_string (t->str.str);
+ g_string_append (gs, s);
+ g_free (s);
break;
case GEL_FUNCTION_NODE:
g_assert(t->func.func->type==GEL_USER_FUNC);
@@ -535,16 +546,17 @@ gel_decompile_tree (char *s)
if G_UNLIKELY (strcmp (p, "T") != 0) {
gel_errorout (_("Bad tree record when decompiling"));
+ g_free (s);
return NULL;
}
t = gel_decompile_node (&ptrptr);
+ g_free (s);
+
if G_UNLIKELY (t == NULL) {
gel_errorout (_("Bad tree record when decompiling"));
return NULL;
}
- g_free (s);
-
return t;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]