[patches] Warnings & debug again

Nirgal <[email protected]> Tue, 30 Aug 2011 20:04:59 +0000
Newsgroups gmane.comp.db.mdb-tools.devel
Message-ID <[email protected]>
--Boundary-00=_vJUXOGUkCypC/6s
Content-Type: Text/Plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit

On Monday 29 August 2011 00:05:52 Brian Bruns wrote:
> I applied all the patches, except (...)

Here's another try with warnings and debug patches.

--Boundary-00=_vJUXOGUkCypC/6s
Content-Type: text/x-patch;
  charset="UTF-8";
  name="01_warnings2.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment;
	filename="01_warnings2.diff"

Author: Jean-Michel Vourgère <[email protected]>
Date: 2010-08-30
Description: Removes many compilation warnings.
Index: mdbtools-0.6~pre1/include/mdbsql.h
===================================================================
--- mdbtools-0.6~pre1.orig/include/mdbsql.h
+++ mdbtools-0.6~pre1/include/mdbsql.h
@@ -51,6 +51,10 @@
 #undef YY_INPUT
 #define YY_INPUT(b, r, ms) (r = mdb_sql_yyinput(b, ms));
 
+#define mdb_sql_has_error(sql) ((sql)->error_msg[0] ? 1 : 0)
+#define mdb_sql_last_error(sql) ((sql)->error_msg)
+
+void mdb_sql_error(MdbSQL* sql, char *fmt, ...);
 extern MdbSQL *_mdb_sql(MdbSQL *sql);
 extern MdbSQL *mdb_sql_init();
 extern MdbSQLSarg *mdb_sql_alloc_sarg();
Index: mdbtools-0.6~pre1/src/gmdb2/debug.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/gmdb2/debug.c
+++ mdbtools-0.6~pre1/src/gmdb2/debug.c
@@ -324,12 +324,12 @@
 static void
 gmdb_debug_display(GladeXML *xml, guint32 page)
 {
-	unsigned char *fbuf;
-	unsigned char *tbuf;
+	char *fbuf;
+	char *tbuf;
 	int length;
 	int i, j;
-	gchar line[80];
-	gchar field[10];
+	char line[80];
+	char field[10];
 	GtkTextBuffer *buffer;
 	GtkTextIter iter;
 	GtkTextView *textview;
@@ -349,8 +349,8 @@
 
 	lseek(mdb->f->fd, page * mdb->fmt->pg_size, SEEK_SET);
 	
-	fbuf = (unsigned char *) g_malloc(mdb->fmt->pg_size);
-	tbuf = (unsigned char *) g_malloc0( (mdb->fmt->pg_size / 16) * 80);
+	fbuf = g_malloc(mdb->fmt->pg_size);
+	tbuf = g_malloc0( (mdb->fmt->pg_size / 16) * 80);
 	length = read(mdb->f->fd, fbuf, mdb->fmt->pg_size);
 	if (length<mdb->fmt->pg_size) {
 	}
@@ -359,7 +359,7 @@
 		sprintf(line,"%06x  ", i);
 
 		for(j=0; j<16; j++) {
-			sprintf(field, "%02x ", fbuf[i+j]);
+			sprintf(field, "%02x ", ((unsigned char*)fbuf)[i+j]);
 			strcat(line,field);
 		}
 
@@ -430,7 +430,7 @@
 gmdb_debug_dissect_column(GtkTreeStore *store, GtkTreeIter *parent, char *fbuf, int offset)
 {
 	gchar *str;
-	char *foff = fbuf + offset;
+	unsigned char *foff = (unsigned char*)fbuf + offset;
 
 	str = g_strdup_printf("Column Type: 0x%02x (%s)", foff[0],
 		gmdb_val_to_str(column_types, foff[0]));
@@ -481,7 +481,7 @@
 		(flags & MDB_IDX_REQUIRED) ? " Required" : "",
 		NULL);
 	if (strcmp(str, "Index Flags:") == 0) {
-		gchar *str2 = g_strconcat(str, " None");
+		gchar *str2 = g_strconcat(str, " None", NULL);
 		g_free(str);
 		str = str2;
 	}
@@ -530,11 +530,11 @@
 			offset + loc1, loc2 - loc1);
 	}
 	str = g_strdup_printf("End of data (EOD): 0x%02x (%u)",
-		fbuf[eod_ptr], fbuf[eod_ptr]);
+		((unsigned char*)fbuf)[eod_ptr], ((unsigned char*)fbuf)[eod_ptr]);
 	gmdb_debug_add_item(store, parent, str, eod_ptr, 1);
 	for (i=0;i<var_cols;i++) {
 		g_strdup_printf("Var col %d offset: 0x%02x (%u)", var_cols-i,
-			fbuf[eod_ptr+i+1], fbuf[eod_ptr+i+1]);
+			((unsigned char*)fbuf)[eod_ptr+i+1], ((unsigned char*)fbuf)[eod_ptr+i+1]);
 		gmdb_debug_add_item(store, parent, str, eod_ptr + i + 1, 1);
 	}
 	str = g_strdup_printf("Num var cols: %u", var_cols);
@@ -585,7 +585,7 @@
 	gchar *str;
 	int num_rows, i, row_start, row_len;
 	guint32 tdef;
-	GtkTreeIter *container;
+	//GtkTreeIter *container;
 
 	str = g_strdup_printf("Page free space: %u", get_uint16(fbuf+offset+2));
 	gmdb_debug_add_item(store, NULL, str, offset+2, 2);
@@ -612,7 +612,7 @@
 			row_len = (get_uint16(fbuf+offset+14+(i-1)*2) 
 				& 0x0FFF) - row_start;
 		str = g_strdup_printf("Row %d", i+1);
-		container = gmdb_debug_add_item(store, NULL, str,
+		/*container = */gmdb_debug_add_item(store, NULL, str,
 			row_start, row_len); 
 		
 		/* usage pages have parent id of 0 (database) and do not 
@@ -722,9 +722,9 @@
 		container = gmdb_debug_add_item(store, NULL, str, -1, 0);
 	}
 	for (i=0;i<num_idx;i++) {
-		GtkTreeIter *node;
+		/*GtkTreeIter *node;*/
 		str = g_strdup_printf("Index %d", i+1);
-		node = gmdb_debug_add_item(store, container, str, newbase, 12);
+		/*node = */gmdb_debug_add_item(store, container, str, newbase, 12);
 		//gmdb_debug_dissect_index1(store, node, fbuf, offset+63);
 		newbase += 12;
 	}
@@ -734,7 +734,7 @@
 	str = g_strdup("Column Info");
 	container = gmdb_debug_add_item(store, NULL, str, -1, 0);
 	for (i=0;i<num_cols;i++) {
-		GtkTreeIter *node, *subnode;
+		GtkTreeIter *node/*, *subnode*/;
 //		char *tmpstr;
 		int namelen;
 
@@ -742,7 +742,7 @@
 		node = gmdb_debug_add_item(store, container, str, -1, 0);
 
 		str = g_strdup("Data");
-		subnode = gmdb_debug_add_item(store, node, str, infobase, 25);
+		/*subnode = */gmdb_debug_add_item(store, node, str, infobase, 25);
 		//gmdb_debug_dissect_column(store, subnode, fbuf, infobase);
 		infobase += 25;
 
@@ -881,7 +881,7 @@
 {
 	gchar *str;
 
-	str = g_strdup_printf("Page Type: 0x%02x (%s)", fbuf[offset],
+	str = g_strdup_printf("Page Type: 0x%02x (%s)", ((unsigned char*)fbuf)[offset],
 		gmdb_val_to_str(object_types, fbuf[offset]));
 	gmdb_debug_add_item(store, NULL, str, 0, 1);
 	switch (fbuf[offset]) {
Index: mdbtools-0.6~pre1/src/gmdb2/info.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/gmdb2/info.c
+++ mdbtools-0.6~pre1/src/gmdb2/info.c
@@ -72,5 +72,5 @@
 
 	g_free(filepath);
 
-	return propswin_xml;
+	return propswin;
 }
Index: mdbtools-0.6~pre1/src/gmdb2/main2.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/gmdb2/main2.c
+++ mdbtools-0.6~pre1/src/gmdb2/main2.c
@@ -62,7 +62,7 @@
 	if (!pixbuf)
 		pixbuf = gdk_pixbuf_new_from_file (GMDB_ICONDIR "logo.xpm", NULL);
 
-  	gtk_show_about_dialog (parent,
+  	gtk_show_about_dialog ((GtkWindow*)parent,
    		"authors", authors,
 		"comments", _("GNOME MDB Viewer is a grapical interface to "
 			"MDB Tools. It lets you view and export data and schema "
@@ -129,50 +129,9 @@
 	}
 }
 
-static void
-gmdb_load_icons(GladeXML *xml)
-{
-	GtkWidget *icon;
-	char file[256];
-	GValue value = { 0, };
-	int i = 0;
-
-	char *icons[] = {
-		"table_icon",
-		"query_icon",
-		"form_icon",
-		"report_icon",
-		"macro_icon",
-		"module_icon",
-		"debug_icon",
-		NULL
-	};
-	char *files[] = {
-		"table.xpm",
-		"query.xpm",
-		"forms.xpm",
-		"reports.xpm",
-		"macros.xpm",
-		"code.xpm",
-		"debug.xpm",
-		NULL
-	};
-
-	while (icons[i]) {
-		icon =  glade_xml_get_widget (xml, icons[i]); 
-
-		g_value_init (&value, G_TYPE_STRING);
-		g_snprintf(file,256,"%s%s", GMDB_ICONDIR, files[i]); 
-		g_value_set_static_string (&value, file);
-		g_object_set_property (G_OBJECT (icon), "file" , &value);
-		g_value_unset (&value);
-		i++;
-	}
-}
 int main(int argc, char *argv[]) 
 {
 GtkWidget *gmdb;
-GnomeProgram *program;
 
 #ifdef SQL
 	/* initialize the SQL engine */
@@ -181,9 +140,9 @@
 	/* initialize MDB Tools library */
 	mdb_init();
 
-        /* Initialize GNOME */
-	       /* Initialize gnome program */
-	program = gnome_program_init ("gmdb", "0.2",
+	/* Initialize GNOME */
+	/* Initialize gnome program */
+	gnome_program_init ("gmdb", MDB_VERSION_NO,
 		LIBGNOMEUI_MODULE, argc, argv,
 		GNOME_PARAM_POPT_TABLE, NULL,
 		GNOME_PARAM_HUMAN_READABLE_NAME,
@@ -203,8 +162,6 @@
 	gtk_signal_connect (GTK_OBJECT (gmdb), "delete_event",
 		GTK_SIGNAL_FUNC (delete_event), NULL);
 
-	//gmdb_load_icons(mainwin_xml);
-
 	if (argc>1) {
 		gmdb_file_open(argv[1]);
 	}
Index: mdbtools-0.6~pre1/src/gmdb2/sql.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/gmdb2/sql.c
+++ mdbtools-0.6~pre1/src/gmdb2/sql.c
@@ -80,7 +80,7 @@
 	
 	filesel = glade_xml_get_widget (xml, "export_dialog");
 	sql_xml = g_object_get_data(G_OBJECT(filesel), "sql_xml");
-	printf("sql_xml %lu\n",sql_xml);
+	//printf("sql_xml %p\n",sql_xml);
 
 	gmdb_export_get_delimiter(xml, delimiter, 10);
 	gmdb_export_get_lineterm(xml, lineterm, 5);
@@ -102,7 +102,7 @@
 	glist = gtk_tree_view_get_columns(GTK_TREE_VIEW(treeview));
 	i = 0;
 	if (need_headers)  {
-		while (col = g_list_nth_data(glist, i)) {
+		while ((col = g_list_nth_data(glist, i))) {
 			gchar *title;
 			if (i>0) fputs(delimiter, outfile);
 			title = g_strdup(gtk_tree_view_column_get_title(col));
@@ -304,7 +304,7 @@
 		selection_data,
 		GDK_SELECTION_TYPE_STRING,
 		8,  /* 8 bits per character. */
-		tablename, strlen(tablename));
+		(guchar*)tablename, strlen(tablename));
 }
 static void gmdb_sql_dnd_datareceived_cb(
         GtkWidget *w,
@@ -351,11 +351,10 @@
 	gchar *bound_data[256];
 	int i;
 	MdbSQLColumn *sqlcol;
-	gchar *titles[256];
 	GtkTextBuffer *txtbuffer;
 	GtkTextIter start, end;
 	GtkWidget *textview, *combo, *treeview, *store;
-	GtkWidget *window;
+	/*GtkWidget *window;*/
 	GList *history;
 	GType *gtypes;
 	GtkTreeIter iter;
@@ -405,8 +404,7 @@
 
 	store = (GtkWidget *) gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
 	if (store) {
-		i=0;
-		while (column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), i)) {
+		while ((column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), 0))) {
 			gtk_tree_view_remove_column(GTK_TREE_VIEW(treeview), column);
 		}
 		gtk_widget_destroy(store);
Index: mdbtools-0.6~pre1/src/sql/mdbsql.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/sql/mdbsql.c
+++ mdbtools-0.6~pre1/src/sql/mdbsql.c
@@ -23,8 +23,6 @@
 #include "dmalloc.h"
 #endif
 
-void mdb_dump_results(MdbSQL *sql);
-
 #ifdef HAVE_WORDEXP_H
 #define HAVE_WORDEXP
 #include <wordexp.h>
@@ -32,6 +30,21 @@
 
 char *g_input_ptr;
 
+/* Prevent warnings from -Wmissing-prototypes.  */
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+
 void
 mdb_sql_error(MdbSQL* sql, char *fmt, ...)
 {
@@ -43,21 +56,7 @@
 	va_end(ap);
 	fprintf(stderr,"\n");
 }
-void
-mdb_sql_clear_error(MdbSQL* sql)
-{
-	sql->error_msg[0]='\0';
-}
-char *
-mdb_sql_last_error(MdbSQL* sql)
-{
-	return sql->error_msg;
-}
-unsigned char
-mdb_sql_has_error(MdbSQL* sql)
-{
-	return (sql->error_msg[0] ? 1 : 0);
-}
+
 int mdb_sql_yyinput(char *buf, int need)
 {
 int cplen, have;
@@ -90,8 +89,6 @@
 #define _(x) x
 #endif
 
-void mdb_sql_bind_all (MdbSQL*);
-
 /**
  * mdb_sql_run_query:
  * @sql: MDB SQL object to execute the query on.
@@ -112,7 +109,7 @@
 
 	/* begin unsafe */
 	_mdb_sql (sql);
-	mdb_sql_clear_error(sql);
+	sql->error_msg[0]='\0';
 	if (yyparse()) {
 		/* end unsafe */
 		mdb_sql_error (sql, _("Could not parse '%s' command"), querystr);
Index: mdbtools-0.6~pre1/src/odbc/unittest.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/odbc/unittest.c
+++ mdbtools-0.6~pre1/src/odbc/unittest.c
@@ -157,10 +157,6 @@
 			  
 	if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) 
 	{
-		long   p1;
-		long   p1Len = sizeof(p1);
-		long   sAge  = 1023;
-		long   cbAge = sizeof(long);
 		UCHAR  szCol1[60];
 		SQLINTEGER length;
 
@@ -189,7 +185,7 @@
 		while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
 		{
 			i++;
-			printf("%d: szCol1 = %s (%d)\n",i,szCol1, length);
+			printf("%d: szCol1 = %s (%d)\n", i, szCol1, (int)length);
 		}
 		if (retcode != SQL_NO_DATA_FOUND)
 		{
Index: mdbtools-0.6~pre1/src/gmdb2/prefs.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/gmdb2/prefs.c
+++ mdbtools-0.6~pre1/src/gmdb2/prefs.c
@@ -18,6 +18,7 @@
 #include "gmdb.h"
 
 #include <libgnome/gnome-config.h>
+#include <libgnome/gnome-help.h>
 
 extern GtkWidget *app;
 extern MdbHandle *mdb;
Index: mdbtools-0.6~pre1/src/sql/lexer.l
===================================================================
--- mdbtools-0.6~pre1.orig/src/sql/lexer.l
+++ mdbtools-0.6~pre1/src/sql/lexer.l
@@ -20,6 +20,7 @@
 #include <string.h>
 #include "mdbsql.h"
 #include "parser.h"
+extern int mdb_sql_yyinput(char *buf, int need);
 %}
 
 %%

--Boundary-00=_vJUXOGUkCypC/6s
Content-Type: text/x-patch;
  charset="UTF-8";
  name="02_debug.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment;
	filename="02_debug.diff"

Author: Jean-Michel Vourgère <[email protected]>
Date: 2011-08-30
Description:
  * Fix end of loop detection in gmdb_val_to_str
  * Support debug of encrypted files
  * Add missing NULL last parameter to g_strconcat
Index: mdbtools-0.6~pre1/src/gmdb2/debug.c
===================================================================
--- mdbtools-0.6~pre1.orig/src/gmdb2/debug.c
+++ mdbtools-0.6~pre1/src/gmdb2/debug.c
@@ -326,7 +326,6 @@
 {
 	char *fbuf;
 	char *tbuf;
-	int length;
 	int i, j;
 	char line[80];
 	char field[10];
@@ -347,15 +346,13 @@
 	gtk_entry_set_text(GTK_ENTRY(entry),pagestr);
 	g_free(pagestr);
 
-	lseek(mdb->f->fd, page * mdb->fmt->pg_size, SEEK_SET);
-	
+	mdb_read_pg(mdb, page);
 	fbuf = g_malloc(mdb->fmt->pg_size);
-	tbuf = g_malloc0( (mdb->fmt->pg_size / 16) * 80);
-	length = read(mdb->f->fd, fbuf, mdb->fmt->pg_size);
-	if (length<mdb->fmt->pg_size) {
-	}
+	memcpy(fbuf, mdb->pg_buf, mdb->fmt->pg_size);
+
+	tbuf = g_malloc0( (mdb->fmt->pg_size / 16) * sizeof(line));
 	i = 0;
-	while (i<length) {
+	while (i<mdb->fmt->pg_size) {
 		sprintf(line,"%06x  ", i);
 
 		for(j=0; j<16; j++) {
@@ -383,7 +380,7 @@
 	window = glade_xml_get_widget(xml, "debug_window");
 	dissect = g_object_get_data(G_OBJECT(window),"dissect");
 	if (!dissect || *dissect)
-		gmdb_debug_dissect(GTK_TREE_STORE(store), fbuf, 0, length);
+		gmdb_debug_dissect(GTK_TREE_STORE(store), fbuf, 0, mdb->fmt->pg_size);
 
 	g_free(fbuf);
 	g_free(tbuf);
@@ -409,7 +406,7 @@
 			return strptr;
 		}
 		i++;	
-	} while (*strptr);
+	} while (strptr);
 	return "unknown";
 }
 static guint16 

--Boundary-00=_vJUXOGUkCypC/6s
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
--Boundary-00=_vJUXOGUkCypC/6s
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev

--Boundary-00=_vJUXOGUkCypC/6s--