[monkey-bubble: 16/753] Hmm, some moron (me) added all the test suite binaries to CVS, must fix that.



commit 1846620b54d5075295dc1c5c3d89fa2bad95ea82
Author: Elliot Lee <sopwith src gnome org>
Date:   Tue Dec 23 03:46:26 1997 +0000

    Hmm, some moron (me) added all the test suite binaries to CVS, must
    fix that.
    
    What I actually did:
    	. Added gnome_chomp_string
    	. Filled in the TODO list a bit more.
    	. Coded the gnome_recently_used stuff from the TODO list
    	  (it's theoretically beautiful, but needs testing beyond
    	   compilation :-)

 libgnome/Makefile.am     |    4 ++
 libgnome/gnome-history.c |  101 ++++++++++++++++++++++++++++++++++++++++++++++
 libgnome/gnome-history.h |   23 ++++++++++
 libgnome/gnome-string.c  |   20 +++++++++-
 libgnome/gnome-string.h  |    3 +
 5 files changed, 150 insertions(+), 1 deletions(-)
---
diff --git a/libgnome/Makefile.am b/libgnome/Makefile.am
index e16f804..b312eae 100644
--- a/libgnome/Makefile.am
+++ b/libgnome/Makefile.am
@@ -20,6 +20,8 @@ libgnome_la_SOURCES = \
 	gnomelib-init.c         \
 	gnome-dentry.c          \
 	gnome-dns.c		\
+	gnome-fileconvert.c	\
+	gnome-history.c		\
 	gnome-mime.c		\
 	gnome-string.c		\
 	gnome-triggers.c
@@ -27,10 +29,12 @@ libgnome_la_SOURCES = \
 libgnomeinclude_HEADERS = \
         gnome-config.h 		\
 	gnome-defs.h   		\
+	gnome-fileconvert.h	\
 	gnome-hook.h   		\
 	gnome-util.h   		\
 	gnome-dns.h    		\
 	gnome-dentry.h 		\
+	gnome-history.h		\
 	gnome-i18n.h 		\
 	gnome-mime.h		\
 	gnome-triggers.h 	\
diff --git a/libgnome/gnome-history.c b/libgnome/gnome-history.c
new file mode 100644
index 0000000..1ba49ea
--- /dev/null
+++ b/libgnome/gnome-history.c
@@ -0,0 +1,101 @@
+#include <stdio.h>
+#include <glib.h>
+
+#include "gnome-defs.h"
+#include "gnome-util.h"
+#include "gnome-string.h"
+#include "gnome-history.h"
+
+#define NUM_ENTS 10
+
+static void write_history(GList *ents);
+static void free_history_list_entry(gpointer data,
+				    gpointer user_data);
+
+void
+gnome_history_recently_used(GnomeHistoryEntry ent)
+{
+  GList *ents;
+  ents = gnome_history_get_recently_used();
+  ents = g_list_append(ents, ent);
+  write_history(ents);
+  gnome_history_free_recently_used_list(ents);
+}
+
+GList *gnome_history_get_recently_used(void)
+{
+  GnomeHistoryEntry anent;
+  GList *retval = NULL;
+  FILE *infile;
+  gchar *filename = gnome_util_home_file("document_history");
+  gchar aline[512], **parts;
+
+  infile = fopen(filename, "r");
+  if(infile)
+    {
+      while(fgets(aline, sizeof(aline), infile))
+	{
+	  gnome_chomp_string(aline, TRUE);
+	  if(aline[0] == '\0') continue;
+
+	  parts = gnome_split_string(aline, " ", 4);
+
+	  anent = g_malloc(sizeof(struct _GnomeHistoryEntry));
+	  anent->filename = parts[0];
+	  anent->filetype = parts[1];
+	  anent->creator = parts[2];
+	  anent->desc = parts[3];
+
+	  g_free(parts);
+
+	  retval = g_list_append(retval, anent);
+	}
+      fclose(infile);
+    }
+  g_free(filename);
+  return retval;
+}
+
+static void
+write_history_entry(GnomeHistoryEntry ent, FILE *outfile)
+{
+  fprintf(outfile, "%s %s %s %s\n",
+	  ent->filename, ent->filetype, ent->creator, ent->desc);
+}
+
+static void write_history(GList *ents)
+{
+  FILE *outfile;
+  gchar *filename = gnome_util_home_file("document_history");
+  GList *t;
+  gint n;
+
+  outfile = fopen(filename, "w");
+  if(outfile) {
+    n = g_list_length(ents) - NUM_ENTS;
+    if(n < 0) n = 0;
+    g_list_foreach(g_list_nth(ents, n),
+		   (GFunc)write_history_entry, outfile);
+  }
+  fclose(outfile);
+  g_free(filename);
+}
+
+void
+gnome_history_free_recently_used_list(GList *alist)
+{
+  g_list_foreach(alist, (GFunc) free_history_list_entry, NULL);
+  g_list_free(alist);
+}
+
+static void free_history_list_entry(gpointer data,
+				    gpointer user_data)
+{
+  GnomeHistoryEntry anent;
+  anent = data;
+  g_free(anent->filename);
+  g_free(anent->filetype);
+  g_free(anent->creator);
+  g_free(anent->desc);
+  g_free(anent);
+}
diff --git a/libgnome/gnome-history.h b/libgnome/gnome-history.h
new file mode 100644
index 0000000..c10a3b1
--- /dev/null
+++ b/libgnome/gnome-history.h
@@ -0,0 +1,23 @@
+#ifndef __GNOME_HISTORY_H__
+#define __GNOME_HISTORY_H__ 1
+
+BEGIN_GNOME_DECLS
+
+struct _GnomeHistoryEntry {
+  char *filename, *filetype, *creator, *desc;
+};
+typedef struct _GnomeHistoryEntry * GnomeHistoryEntry;
+
+void
+gnome_history_recently_used(GnomeHistoryEntry ent);
+
+GList * /* GList of GnomeHistoryEntrys */
+gnome_history_get_recently_used(void);
+
+/* Convenience function */
+void
+gnome_history_free_recently_used_list(GList *alist /* From the above */);
+
+END_GNOME_DECLS
+
+#endif /* __GNOME_HISTORY_H__ */
diff --git a/libgnome/gnome-string.c b/libgnome/gnome-string.c
index 4452f30..9467c81 100644
--- a/libgnome/gnome-string.c
+++ b/libgnome/gnome-string.c
@@ -1,9 +1,9 @@
 #include "gnome-string.h"
 #include <string.h>
-
 #include <glib.h>
 #include <string.h>
 #include <limits.h>
+#include <ctype.h>
 
 gchar **gnome_split_string(gchar *string, gchar *delim, gint max_tokens)
 {
@@ -90,3 +90,21 @@ gnome_join_vstrings(gchar *separator, gchar **strings)
 
 	return retval;
 }
+
+inline
+gchar *
+gnome_chomp_string(gchar *astring, gboolean in_place)
+{
+	int i;
+	gchar *retval;
+
+	g_return_val_if_fail(astring != NULL, NULL);
+
+	if(in_place == FALSE)
+		retval = g_strdup(astring);
+	else
+		retval = astring;
+
+	i = strlen(retval) - 1;
+	while(isspace(retval[i])) retval[i--] = '\0';
+}
diff --git a/libgnome/gnome-string.h b/libgnome/gnome-string.h
index 62ee2c7..9ebad21 100644
--- a/libgnome/gnome-string.h
+++ b/libgnome/gnome-string.h
@@ -8,3 +8,6 @@ gchar **gnome_split_string  (gchar *string,
 gchar * gnome_join_strings  (gchar *separator, ...);
 gchar * gnome_join_vstrings (gchar *separator,
 			     gchar **strings);
+inline
+gchar * gnome_chomp_string  (gchar *astring,
+			     gboolean in_place);



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