[Goodies-commits] r6997 - xfbib/branches/gobject/src
Jesper Karlsson
zarper at xfce.org
Thu Mar 26 00:25:32 CET 2009
Author: zarper
Date: 2009-03-25 23:25:32 +0000 (Wed, 25 Mar 2009)
New Revision: 6997
Modified:
xfbib/branches/gobject/src/xfbib-file-io.c
xfbib/branches/gobject/src/xfbib-file-io.h
xfbib/branches/gobject/src/xfbib-string.c
xfbib/branches/gobject/src/xfbib-string.h
Log:
Initial functionality to parse latex commands from file and write them to a file.
Modified: xfbib/branches/gobject/src/xfbib-file-io.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.c 2009-03-25 18:26:14 UTC (rev 6996)
+++ xfbib/branches/gobject/src/xfbib-file-io.c 2009-03-25 23:25:32 UTC (rev 6997)
@@ -25,6 +25,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include <libxfcegui4/libxfcegui4.h>
+#include <stdlib.h>
#include "xfbib-file-io.h"
#include "xfbib-state.h"
@@ -252,7 +253,7 @@
if (XFBIB_IS_STRING(obj->data)) {
separator = xfbib_string_get_separator(XFBIB_STRING(obj->data));
g_string_append_c(str, separator);
- g_string_append(str, xfbib_string_get(XFBIB_STRING(obj->data)));
+ g_string_append(str, xfbib_file_io_escape_commands(xfbib_string_get(XFBIB_STRING(obj->data))));
g_string_append_c(str, (separator == '{') ? '}' : '"');
} else if (XFBIB_IS_INTEGER(obj->data)) {
g_string_append(str, xfbib_integer_get(XFBIB_INTEGER(obj->data)));
@@ -266,3 +267,33 @@
}
}
+gchar *
+xfbib_file_io_escape_commands(gchar *str)
+{
+ int len, new_len, n, i;
+ gchar *new_str;
+
+ len = new_len = strlen(str) + 1;
+ new_str = malloc(len);
+
+ n = i = 0;
+ while(n < len) {
+ switch(str[n]) {
+ case '&':
+ case '%':
+ new_len++;
+ new_str = realloc(new_str, new_len);
+ new_str[i] = '\\';
+ i++;
+ new_str[i] = str[n];
+ i++;
+ n++;
+ break;
+ default:
+ new_str[i] = str[n];
+ i++;
+ n++;
+ }
+ }
+ return new_str;
+}
Modified: xfbib/branches/gobject/src/xfbib-file-io.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.h 2009-03-25 18:26:14 UTC (rev 6996)
+++ xfbib/branches/gobject/src/xfbib-file-io.h 2009-03-25 23:25:32 UTC (rev 6997)
@@ -27,6 +27,7 @@
gchar *xfbib_file_io_open(gchar *);
gboolean xfbib_file_io_save(gchar *);
gboolean xfbib_file_io_save_as(void);
+gchar *xfbib_file_io_escape_commands(gchar *);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.c 2009-03-25 18:26:14 UTC (rev 6996)
+++ xfbib/branches/gobject/src/xfbib-string.c 2009-03-25 23:25:32 UTC (rev 6997)
@@ -22,6 +22,7 @@
#endif
#include <string.h>
#include <gtk/gtk.h>
+#include <stdlib.h>
#include "xfbib-string.h"
@@ -76,7 +77,7 @@
xfbib_string_parse(XfbibString *string, const gchar *str)
{
string->separator = str[0];
- string->str = g_strndup(str+1, strlen(str)-2);
+ string->str = xfbib_string_parse_commands(g_strndup(str+1, strlen(str)-2));
return TRUE;
}
@@ -104,3 +105,52 @@
return string->separator;
}
}
+
+gchar *
+xfbib_string_parse_commands(gchar *str)
+{
+ int len, old_len, n, i;
+ gchar *old_str;
+
+ len = old_len = strlen(str) + 1;
+ old_str = g_strdup(str);
+
+ n = i = 0;
+ while(n < len) {
+ switch(old_str[i]) {
+ case '\\':
+ switch(old_str[i+1]) {
+ case '&':
+ case '%':
+ len--;
+ str = realloc(str, len);
+ i++;
+ str[n] = old_str[i];
+ i++;
+ n++;
+ break;
+ default:
+ str[n] = old_str[i];
+ i++;
+ n++;
+ }
+ break;
+ case '\n':
+ len--;
+ str = realloc(str, len);
+ i++;
+ break;
+ case '\t':
+ str[n] = ' ';
+ i++;
+ n++;
+ break;
+ default:
+ str[n] = old_str[i];
+ i++;
+ n++;
+ }
+ }
+ free(old_str);
+ return str;
+}
Modified: xfbib/branches/gobject/src/xfbib-string.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.h 2009-03-25 18:26:14 UTC (rev 6996)
+++ xfbib/branches/gobject/src/xfbib-string.h 2009-03-25 23:25:32 UTC (rev 6997)
@@ -40,8 +40,8 @@
gchar *xfbib_string_get(XfbibString *);
void xfbib_string_set(XfbibString *, const gchar *);
gchar xfbib_string_get_separator(XfbibString *);
+gchar *xfbib_string_parse_commands(gchar *);
-
G_END_DECLS
#endif //__XFBIB_STRING_H
More information about the Goodies-commits
mailing list