[patch]



Hi,

This patch for anjuta2 is a clean up of the anjuta-utils.c file.  Some of the functions there were not namespaced (I prefixed them with anjuta_), and others were not used anywhere (those were removed).

It also fixes a bug which segfaulted when trying to save a new file.  This was because bonobo_stream_vfs_open failed to create a non-existant file, so bonobo_stream_vfs_new is called instead.  This one is in document-manager/anjuta-document.c.

May I commit?

Cheers,
Gustavo

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/anjuta2/ChangeLog,v
retrieving revision 1.154
diff -u -r1.154 ChangeLog
--- ChangeLog	2001/11/22 09:21:53	1.154
+++ ChangeLog	2001/12/02 08:30:39
@@ -1,3 +1,43 @@
+2001-12-02  Gustavo Giráldez  <gustavo giraldez gmx net>
+
+	* libanjuta/anjuta-utils.h
+	* libanjuta/anjuta-utils.c:
+	Namespaced functions: isempty -> anjuta_is_empty_string,
+	file_exist -> anjuta_file_exists,
+	get_file_size -> anjuta_get_file_size,
+	file_check_if_exist -> anjuta_file_check_if_exists.
+	Removed unused functions and related #defines/structs: get_path,
+	SK_GetBetween, SK_GetFields, entry_dialog, get_last_mod,
+	get_write_stat, modal_dialog, strcase_hash, strcase_equal,
+	entry_dialog_data.
+	(anjuta_file_exists, anjuta_get_file_size,
+	anjuta_file_check_if_exists): Added GnomeVFS support.
+
+	* plugins/document-manager/file-ops.c: Changed function calls to
+	reflect namespace.  Removed duplicate file_check_if_exist.
+	(get_last_mod): moved over from anjuta-utils.c, since it's only
+	used here (though currently disabled with #if 0).
+
+	* plugins/files/files-tool.c: 
+	* plugins/functions/protogen.c:
+	* plugins/functions/tree.c:
+	* plugins/help/help.c:
+	* plugins/prjfiles/files.c:
+	* plugins/protogen/protogen.c:
+	* plugins/text/text-replace.c:
+	Changed function calls to reflect namespace.
+
+	* plugins/selection/plugin-selection.c: Moved SK_GetBetween and
+	SK_GetFields as they are only used here. (The plugin is not
+	compiled anyway).
+
+	* plugins/swapch/swapch-tool.c: Changed function calls to reflect
+	namespace.  Fixed leak.
+	
+	* plugins/document-manager/anjuta-document.c
+	(save_uri_from_control): Call bonobo_stream_vfs_new if file
+	doesn't exist.
+
 2001-11-21  Timothee Besset <ttimo ttimo net>
 
 	* added docs/compile.txt guide to compile and run Anjuta DevStudio
Index: libanjuta/anjuta-utils.c
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-utils.c,v
retrieving revision 1.16
diff -u -r1.16 anjuta-utils.c
--- libanjuta/anjuta-utils.c	2001/11/16 02:34:07	1.16
+++ libanjuta/anjuta-utils.c	2001/12/02 08:30:39
@@ -33,40 +33,26 @@
 #include <sys/types.h>
 #include <pwd.h>
 
-#include "anjuta-utils.h"
-
-/* local prototypes */
-static void modal_dialog_callback(GtkWidget *w,gpointer );
-
-gchar *get_path( gchar *filename )
-{
-	gchar *str;
+#include <libgnomevfs/gnome-vfs.h>
 
-	str = g_dirname(filename);
-	if (!strcmp(str, ".")) {
-		free(str);
-		str = g_strdup("");
-	}
-
-	return str;
-}
+#include "anjuta-utils.h"
 
 
-glong isempty( gchar *s )
+gboolean
+anjuta_is_empty_string (const gchar *s)
 {
-	if( !s )
-		return( 1 );
-	if( strlen( s ) == 0 )
-		return( 1 );
-
-	while(*s)
-	{
-		if( !isspace(*s) )
-			return( 0 );
+	if (!s)
+		return TRUE;
+	if (strlen (s) == 0)
+		return TRUE;
+
+	while (*s) {
+		if (!isspace (*s))
+			return FALSE;
 		s++;
 	}
 
-	return( 1 );
+	return TRUE;
 }
 
 
@@ -142,521 +128,93 @@
 
 /*
  ---------------------------------------------------------------------
-     Function: file_exist()
-     Desc: checks if a given file exists (1 = yep, it does, 0 = nope,
-                                          it doesnt, -1 = error)
+     Function: anjuta_file_exists ()
+     Desc: checks if a given file exists
  ---------------------------------------------------------------------
 */
-
-gint file_exist( gchar *filename )
-{
-	struct stat s;
-	glong ret;
-
-	if( !filename )
-	{
-		g_warning( "Filename is NULL-Pointer!\n" );
-		return( -1 );
-	}
-
-	if( strlen( filename ) == 0 )
-	{
-		g_warning( "Filename is 0 gchars glong!\n" );
-		return( -1 );
-	}
-
-	ret = stat( filename, &s );
-	if( (ret < 0) /*&& (errno == ENOENT)*/ )
-	{
-		return( 0 );
-	}
-	else
-	{
-		return( 1 );
-	}
-}
-
-
-glong get_file_size( gchar *filename )
-{
-	struct stat f_stat;
-
-	if( stat( filename, &f_stat ) != 0 )
-	{
-		g_print( "%s: %s\n", filename, g_strerror( errno ) );
-		return( -1 );
-	}
-
-	return( (glong) f_stat.st_size );
-}
-
-
-gchar *SK_GetBetween( gchar *str, gchar start, gchar stop )
-{
-	gchar *ptr = NULL;
-
-	while( *str )
-	{
-		if( *str == start && !ptr )
-		{
-			str++;
-			ptr = str;
-		}
-		if( *str == stop && ptr )
-		{
-			*str = '\0';
-			break;
-		}
-		str++;
-	}
-
-	if( !ptr )
-		return( str );
-	else
-		return( ptr );
-}
-
-
-/*
-(--------------------------------------------------------------------------)
-(                                                                          )
-(    Function Name: SK_GetFields                                           )
-(    Prototype: int SK_GetFields( gchar *string, gchar *retarray[],          )
-(                                 gchar separator )                         )
-(    Purpose: Liefert die einzelnen, durch das Trennzeichen seperator      )
-(             getrennten Felder, im Array retarray zurueck.                )
-(    Return: Bei Fehler 0, andernfalls die Anzahl der zurueckgelieferten   )
-(            Felder.                                                       )
-(    Author: Steffen Kern                                                  )
-(    Date: 05.04.1998 (Last Update: 07.04.1998)                            )
-(                                                                          )
-(--------------------------------------------------------------------------)
-*/
 
-gint SK_GetFields( gchar string[], gchar *retarray[], gchar separator )
+gboolean
+anjuta_file_exists (const gchar *filename)
 {
-	gint  HelpCount;
-	gint  strpos;
-	gint  ArrayCount;
-	gchar *HelpString = (gchar *) malloc( (strlen( string ) + 1) * sizeof( gchar ) );
-	gchar HelpChar;
-
-	/* set start values */
-	HelpCount = 0;
-	strpos = 0;
-	ArrayCount = 1;
-
-	if( strlen( string ) == 0 )
-	{
-		free(HelpString);
-		return(0);
-	}
-
-	while( strpos <= strlen( string ) )
-	{
-		HelpChar = string[strpos];
-		if( HelpChar == '\n' ||
-		        HelpChar == separator ||
-		        strpos == strlen( string ) )
-		{
-			HelpString[ HelpCount ] = '\0';
-			retarray[ArrayCount] = (gchar *)malloc( (HelpCount+1) * sizeof( gchar ) );
-			strcpy( retarray[ArrayCount], HelpString );
-			ArrayCount++;
-			strpos++;
-			HelpCount=0;
-		}
-		else
-		{
-			HelpString[ HelpCount ] = HelpChar;
-			HelpCount++;
-			strpos++;
-		}
-	}
-
-	/* free allocated memory */
-	free( HelpString );
-
-	/* allocate memory for retarray[0] */
-	retarray[0] = (gchar *)malloc( 10 );
-	sprintf( retarray[0], "%d", ArrayCount );
-
-	return( ArrayCount );
-}  /* SK_GetFields */
+	GnomeVFSURI *uri;
+	gboolean ret;
 
+	g_return_val_if_fail (filename != NULL, FALSE);
+	g_return_val_if_fail (strlen (filename) != 0, FALSE);
 
-GtkWidget *entry_dialog( gchar *label, gchar *title, void *ok_func )
-{
-	GtkWidget *button, *wlabel;
-	static GtkWidget *dialog_window;
-	static GtkWidget *entry;
-	GtkWidget *hbox;
-
-	dialog_window = gtk_dialog_new();
-	gtk_signal_connect( GTK_OBJECT( dialog_window ), "destroy",
-	                    GTK_SIGNAL_FUNC( gtk_widget_destroyed ),
-	                    &dialog_window );
-	gtk_container_set_border_width( GTK_CONTAINER( dialog_window ), 10 );
-	gtk_window_set_title( GTK_WINDOW( dialog_window ), title );
-	gtk_window_set_position( GTK_WINDOW( dialog_window ), GTK_WIN_POS_MOUSE );
-
-	hbox = gtk_hbox_new( FALSE, 0 );
-	gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog_window )->vbox ),
-	                    hbox, FALSE, TRUE, 5 );
-	gtk_widget_show( hbox );
-
-	wlabel = gtk_label_new( label );
-	gtk_box_pack_start( GTK_BOX( hbox ), wlabel, FALSE, TRUE, 5 );
-	gtk_widget_show( wlabel );
-
-	entry = gtk_entry_new();
-	gtk_box_pack_start( GTK_BOX( hbox ), entry, TRUE, TRUE, 0 );
-	gtk_signal_connect( GTK_OBJECT( entry ), "activate",
-	                    GTK_SIGNAL_FUNC( ok_func ), (gpointer) entry );
-	gtk_signal_connect_object( GTK_OBJECT( entry ), "activate",
-	                           GTK_SIGNAL_FUNC( gtk_widget_destroy ),
-	                           GTK_OBJECT( dialog_window ) );
-	gtk_widget_grab_focus( entry );
-	gtk_widget_show( entry );
-
-	button = gnome_stock_button (GNOME_STOCK_BUTTON_OK);
-	gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog_window )->action_area),
-	                    button, TRUE, TRUE, 5 );
-	gtk_signal_connect( GTK_OBJECT( button ), "clicked",
-	                    GTK_SIGNAL_FUNC( ok_func ), (gpointer) entry );
-	gtk_signal_connect_object( GTK_OBJECT( button ), "clicked",
-	                           GTK_SIGNAL_FUNC( gtk_widget_destroy ),
-	                           GTK_OBJECT( dialog_window ) );
-	GTK_WIDGET_SET_FLAGS( button, GTK_CAN_DEFAULT );
-	gtk_widget_grab_default( button );
-	gtk_widget_show( button );
-
-	button = gnome_stock_button (GNOME_STOCK_BUTTON_CANCEL);
-	gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog_window )->action_area),
-	                    button, TRUE, TRUE, 5 );
-	gtk_signal_connect_object( GTK_OBJECT( button ), "clicked",
-	                           GTK_SIGNAL_FUNC( gtk_widget_destroy ),
-	                           GTK_OBJECT( dialog_window ) );
-	gtk_widget_show( button );
-
-	gtk_widget_show( dialog_window );
+	uri = gnome_vfs_uri_new (filename);
+	ret = gnome_vfs_uri_exists (uri);
+	gnome_vfs_uri_unref (uri);
 
-	return( entry );
+	return ret;
 }
 
 
-glong get_last_mod( gchar const *filename )
+gulong 
+anjuta_get_file_size (const gchar *filename)
 {
-	struct stat f_stat;
-
-	if( stat( filename, &f_stat ) != 0 )
-	{
-		/*g_print( "%s: %s\n", filename, g_strerror( errno ) );*/
-		return( -1 );
-	}
-
-	return( (glong) f_stat.st_mtime );
-}
+	glong ret = -1;
+	GnomeVFSFileInfo *info;
+	GnomeVFSResult r;
 
-
-glong get_write_stat( gchar *filename )
-{
-	struct stat f_stat;
-	struct group *f_group;
-	struct passwd *f_passwd;
-	glong mnr;
-
-	if( access( filename, W_OK ) == 0 )
-	{
-		return( 1 );
-	}
+	info = gnome_vfs_file_info_new ();
+	r = gnome_vfs_get_file_info (filename, info, 
+				     GNOME_VFS_FILE_INFO_DEFAULT);
+	if (r == GNOME_VFS_OK) 
+		ret = (glong) info->size;
 	else
-	{
-		return( 0 );
-	}
+		g_warning ("%s: %s", filename, gnome_vfs_result_to_string (r));
 
-	/** old **/
+	gnome_vfs_file_info_unref (info);
 
-	if( stat( filename, &f_stat ) != 0 )
-	{
-		g_print( "%s: %s\n", filename, g_strerror( errno ) );
-		return( -1 );
-	}
-
-	/* others */
-	if( (f_stat.st_mode & S_IRWXU) || (f_stat.st_mode & S_IWUSR) )
-		return( 1 );
-
-	/* user */
-	if( (getuid() == f_stat.st_uid) || (geteuid() == f_stat.st_uid) )
-	{
-		if( (f_stat.st_mode & S_IWUSR) || (f_stat.st_mode & S_IRWXU) )
-			return( 1 );
-	}
-
-	/* group */
-	if( (getgid() == f_stat.st_gid) || (getegid() == f_stat.st_gid) )
-	{
-		if( (f_stat.st_mode & S_IWGRP) || (f_stat.st_mode & S_IRWXG) )
-			return( 1 );
-	}
-
-	f_group = getgrgid( f_stat.st_gid );
-	if( !f_group )
-		return( 0 );
-
-	mnr = 0;
-	while( f_group->gr_mem[mnr] != NULL )
-	{
-		f_passwd = getpwnam( f_group->gr_mem[mnr] );
-		if( !f_passwd )
-			return( 0 );
-
-		if( (f_passwd->pw_uid == getuid()) || (f_passwd->pw_uid == geteuid()) )
-		{
-			if( (f_stat.st_mode | S_IWGRP) || (f_stat.st_mode | S_IRWXG) )
-				return( 1 );
-		}
-		mnr++;
-	}
-
-	return( 0 );
+	return ret;
 }
-
-
-/*
---------------------------------------------------
-gint modal_dialog(gchar *msg,gchar *title,gint type);
-
-	type can be ~ (bitwise) with MB_OK MB_YESNO MB_CANCEL MB_RETRY
-	return values are IDOK IDYES IDNO IDRETRY IDCANCEL
-----------------------------------------------------
-*/
-gint modal_dialog(gchar *msg,gchar *title,gint type)
-{
-	gint *returnvalue;
-	gint retvalue;
-	GtkWidget *window;
-	GtkWidget *buttonok;
-	GtkWidget *buttoncancel;
-	GtkWidget *buttonyes;
-	GtkWidget *buttonno;
-	GtkWidget *buttonretry;
-	GtkWidget *vbox,*hbox;
-	GtkWidget *label;
-	GtkWidget *separator;
-
-	returnvalue=g_malloc(sizeof(gint));
-	*returnvalue=0;
-
-	window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
-	gtk_window_set_policy(GTK_WINDOW(window),FALSE,FALSE,FALSE);
-	gtk_window_set_title(GTK_WINDOW(window),title);
-
-	gtk_signal_connect_object(GTK_OBJECT(window),"destroy",
-	                          GTK_SIGNAL_FUNC(gtk_widget_destroy),GTK_OBJECT(window));
-
-	/*gtk_widget_set_usize(GTK_WIDGET(window),280,150);*/
-	vbox=gtk_vbox_new(FALSE,0);
-	gtk_container_add(GTK_CONTAINER(window),vbox);
-	gtk_container_set_border_width(GTK_CONTAINER(vbox),10);
-
-	separator=gtk_hseparator_new();
-	label=gtk_label_new(msg);
-	gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);
-	hbox=gtk_hbox_new(FALSE,0);
-	gtk_container_set_border_width(GTK_CONTAINER(window),10);
-	gtk_box_pack_start(GTK_BOX(vbox),separator,FALSE,FALSE,10);
-	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,10);
-
-	gtk_signal_connect(GTK_OBJECT(window),"delete_event",
-	                   GTK_SIGNAL_FUNC(modal_dialog_callback),returnvalue);
-
-	if(type & MB_OK) {
-		buttonok = gnome_stock_button (GNOME_STOCK_BUTTON_OK);
-		gtk_box_pack_start(GTK_BOX(hbox),buttonok,TRUE,FALSE,0);
-
-		if(!(type & MB_CANCEL))
-			gtk_object_set_data(GTK_OBJECT(window),"ButtonID",(gpointer)IDOK);
-
-		gtk_object_set_data(GTK_OBJECT(buttonok),"ButtonID",(gpointer)IDOK);
-		gtk_signal_connect(GTK_OBJECT(buttonok),"clicked",
-		                   GTK_SIGNAL_FUNC(modal_dialog_callback),returnvalue);
-	}
-	else if(type & MB_YESNO)	{
-		buttonyes = gnome_stock_button (GNOME_STOCK_BUTTON_YES);
-		buttonno = gnome_stock_button (GNOME_STOCK_BUTTON_NO);
-
-		gtk_box_pack_start(GTK_BOX(hbox),buttonyes,TRUE,FALSE,0);
-		gtk_box_pack_start(GTK_BOX(hbox),buttonno,TRUE,FALSE,0);
-		gtk_signal_connect(GTK_OBJECT(buttonyes),"clicked",
-		                   GTK_SIGNAL_FUNC(modal_dialog_callback),returnvalue);
-		gtk_signal_connect(GTK_OBJECT(buttonno),"clicked",
-		                   GTK_SIGNAL_FUNC(modal_dialog_callback),returnvalue);
-
-		if(!(type & MB_CANCEL))     /* if no CANCEL button then default is no if  */
-			gtk_object_set_data(GTK_OBJECT(window),"ButtonID",(gpointer)IDNO);
-
-		gtk_object_set_data(GTK_OBJECT(buttonyes),"ButtonID",(gpointer)IDYES);
-		gtk_object_set_data(GTK_OBJECT(buttonno),"ButtonID",(gpointer)IDNO);
-	}
-	if(type & MB_RETRY)
-	{
-		buttonretry=gtk_button_new_with_label( _("Retry") );
-		gtk_widget_set_usize(GTK_WIDGET(buttonretry),70,24);
-
-		gtk_box_pack_start(GTK_BOX(hbox),buttonretry,TRUE,FALSE,0);
-
-		gtk_object_set_data(GTK_OBJECT(buttonretry),"ButtonID",(gpointer)IDRETRY);
-		gtk_signal_connect(GTK_OBJECT(buttonretry),"clicked",
-		                   GTK_SIGNAL_FUNC(modal_dialog_callback),returnvalue);
-
-	}
-	if(type & MB_CANCEL)
-	{
-		buttoncancel = gnome_stock_button (GNOME_STOCK_BUTTON_CANCEL);
-		gtk_box_pack_start(GTK_BOX(hbox),buttoncancel,TRUE,FALSE,0);
-		gtk_object_set_data(GTK_OBJECT(buttoncancel),"ButtonID",(gpointer)IDCANCEL);
-
-		gtk_signal_connect(GTK_OBJECT(buttoncancel),"clicked",
-		                   GTK_SIGNAL_FUNC(modal_dialog_callback),returnvalue);
 
-		gtk_object_set_data(GTK_OBJECT(window),"ButtonID",(gpointer)IDCANCEL);
-	}
-
-	gtk_widget_show_all(window);
-
-	gtk_grab_add(window);
-	while (!*returnvalue)
-	{	/* loop until callback return something */
-		gtk_main_iteration_do(TRUE);
+gboolean
+anjuta_file_check_if_exists (const gchar *fname, gint askcreate)
+{
+	GnomeVFSURI *uri;
+	gboolean ret = FALSE;
+
+	g_return_val_if_fail (fname != NULL, FALSE);
+	g_return_val_if_fail (strlen (fname) != 0, FALSE);
+
+	uri = gnome_vfs_uri_new (fname);
+	if (gnome_vfs_uri_exists (uri))
+		ret = TRUE;
+
+	else if (askcreate) {
+		gchar *txt;
+		txt = g_strdup_printf (_("The file\n'%s'\ndoes not "
+					 "exist!\nDo you want to "
+					 "create the file?"), fname );
+		
+		if (anjuta_ask_dialog (txt) == 0) {
+			GnomeVFSResult r;
+			GnomeVFSHandle *handle = NULL;
+
+			/* FIXME: is the default permission ok? */
+			r = gnome_vfs_create_uri (&handle, uri, 
+						  GNOME_VFS_OPEN_WRITE,
+						  TRUE, 0660);
+			
+			if (r == GNOME_VFS_OK) {
+				gnome_vfs_close (handle);
+				ret = TRUE;
+			} else {
+				g_free (txt);
+				txt = g_strdup_printf (
+					_("Error creating file '%s': %s'"), 
+					fname, 
+					gnome_vfs_result_to_string (r));
+				anjuta_error_dialog (txt);
+			}
+		};
+		g_free (txt);
 	};
-	gtk_grab_remove(window);
-	gtk_widget_destroy(window);
 
-	retvalue = *returnvalue;
-	g_free(returnvalue);
+	gnome_vfs_uri_unref (uri);
 
-	return retvalue;
+	return ret;
 }
 
-static void modal_dialog_callback(GtkWidget *w,gpointer ret)
-{
-	gint *r=(gint *)ret;
-	*r=(gint)gtk_object_get_data(GTK_OBJECT(w),"ButtonID");
-}
-
-
-GtkWidget *entry_dialog_data( gchar *label, gchar *title, void *ok_func, gpointer data )
-{
-	GtkWidget *button, *wlabel;
-	static GtkWidget *dialog_window;
-	static GtkWidget *entry;
-	GtkWidget *hbox;
-	entry_data *ed;
-
-	dialog_window = gtk_dialog_new();
-	gtk_signal_connect( GTK_OBJECT( dialog_window ), "destroy",
-	                    GTK_SIGNAL_FUNC( gtk_widget_destroyed ),
-	                    &dialog_window );
-	gtk_container_set_border_width( GTK_CONTAINER( dialog_window ), 10 );
-	gtk_window_set_title( GTK_WINDOW( dialog_window ), title );
-	gtk_window_set_position( GTK_WINDOW( dialog_window ), GTK_WIN_POS_MOUSE );
-	gtk_widget_show( dialog_window );
-
-	hbox = gtk_hbox_new( FALSE, 0 );
-	gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog_window )->vbox ),
-	                    hbox, FALSE, TRUE, 5 );
-	gtk_widget_show( hbox );
-
-	wlabel = gtk_label_new( label );
-	gtk_box_pack_start( GTK_BOX( hbox ), wlabel, FALSE, TRUE, 5 );
-	gtk_widget_show( wlabel );
-
-	ed = (entry_data *) g_malloc0( sizeof( entry_data ) );
-	ed->data = data;
-	ed->dialog = dialog_window;
-
-	entry = gtk_entry_new();
-	ed->entry = entry;
-	gtk_box_pack_start( GTK_BOX( hbox ), entry, TRUE, TRUE, 0 );
-	gtk_signal_connect( GTK_OBJECT( entry ), "activate",
-	                    GTK_SIGNAL_FUNC( ok_func ), ed );
-	gtk_widget_grab_focus( entry );
-	gtk_widget_show( entry );
-
-	button = gnome_stock_button (GNOME_STOCK_BUTTON_OK);
-	gtk_box_pack_start( GTK_BOX( GTK_DIALOG( dialog_window )->action_area),
-	                    button, TRUE, TRUE, 0 );
-	gtk_signal_connect( GTK_OBJECT( button ), "clicked",
-	                    GTK_SIGNAL_FUNC( ok_func ), ed );
-	GTK_WIDGET_SET_FLAGS( button, GTK_CAN_DEFAULT );
-	gtk_widget_grab_default( button );
-	gtk_widget_show( button );
-
-	return( entry );
-}
-
-gint
-strcase_equal (gconstpointer v, gconstpointer v2)
-{
-        return strcasecmp ((const gchar*) v, (const gchar*)v2) == 0;
-}
-
-guint
-strcase_hash (gconstpointer v)
-{ 
-        const unsigned char *s = (const unsigned char *)v;
-        const unsigned char *p;
-        guint h = 0, g; 
-   
-        for(p = s; *p != '\0'; p += 1) {
-                h = ( h << 4 ) + tolower (*p);
-                if ( ( g = h & 0xf0000000 ) ) {  
-                        h = h ^ (g >> 24);
-                        h = h ^ g;
-                }
-        }
- 
-        return h /* % M */;
-}
-
-gint file_check_if_exist( gchar *fname, gint askcreate )
-{
-	gchar txt[512];
-	FILE *file;
-	struct stat sta;
-	gint e;
-        
-	e=stat(fname,&sta);
-	if( !e && S_ISREG(sta.st_mode) )
-	{   	/* file exist and is a regular file */
-		return( 1 );	
-	}
-
-	if( askcreate && e==-1 )
-	{
-	    sprintf( txt, _("The file\n'%s'\ndoes not exist!\nDo you want to create the file?"), fname );
-	    if( anjuta_ask_dialog( txt ) == 0 ) /*GNOME_YES )*/
-	    {
-	        file = fopen( fname, "w" );	/* this is not a good way!! */
-		if( file ) 
-		{
-			fclose( file );
-		}
-
-		return( 1 );
-	    }
-	}
-	else
-	{
-		if( !e )
-		{ 
-		    sprintf( txt, _("The file '%s' is not a regular file!"), fname );
-                    anjuta_error_dialog( txt );
-                }
-	}
-
-	return( 0 );
-}
Index: libanjuta/anjuta-utils.h
===================================================================
RCS file: /cvs/gnome/anjuta2/libanjuta/anjuta-utils.h,v
retrieving revision 1.9
diff -u -r1.9 anjuta-utils.h
--- libanjuta/anjuta-utils.h	2001/11/16 02:34:07	1.9
+++ libanjuta/anjuta-utils.h	2001/12/02 08:30:39
@@ -16,59 +16,26 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#ifndef GI_TOOLS_H
-#define GI_TOOLS_H
+#ifndef __ANJUTA_UTILS_H__
+#define __ANJUTA_UTILS_H__
 
 #include <gnome.h>
 
 /*
  * Prototypes for 'gI_common.c'
  */
-gchar *get_path( gchar *filename );
-glong isempty( gchar *s );
+gboolean anjuta_is_empty_string (const gchar *s);
 gint anjuta_ask_dialog( gchar *msg );
 void anjuta_error_dialog( gchar *msg);
 void anjuta_ok_dialog( gchar *msg);
-gint file_exist( gchar *filename );
-glong get_file_size( gchar *filename );
-gchar *SK_GetBetween( gchar *str, gchar start, gchar stop );
-gint SK_GetFields( gchar string[], gchar *retarray[], gchar separator );
-GtkWidget *entry_dialog( gchar *label, gchar *title, void *ok_func );
-glong get_last_mod( gchar const *filename );
-glong get_write_stat( gchar *filename );
-gint modal_dialog(gchar *msg,gchar *title,gint type);
-guint strcase_hash  (gconstpointer v);
-gint  strcase_equal (gconstpointer v, gconstpointer v2);
-gint file_check_if_exist( gchar *fname, gint askcreate );
+gboolean anjuta_file_exists (const gchar *filename);
+gulong anjuta_get_file_size (const gchar *filename);
+gboolean anjuta_file_check_if_exists (const gchar *fname, gint askcreate);
 
 #ifndef STRLEN
 #  define STRLEN 1024
 #endif
 
-/* defines for modal_dialog */
-#define MB_YESNO 0x0002
-#define MB_CANCEL 0x0004 
-#define MB_OK 0x0008
-#define MB_RETRY 0x0010
-#define IDYES 1
-#define IDNO 2
-#define IDCANCEL 3
-#define IDRETRY 4
-#define IDOK 5
-
-GtkWidget *entry_dialog_data( gchar *label, gchar *title, void *ok_func, gpointer data );
-
-typedef struct _entry_data entry_data;
-struct _entry_data
-{
-	GtkWidget *dialog;
-        GtkWidget *entry;
-        gpointer data;
-};
-
-/* useful macros */
-/* number of items in an array */
-#define anjuta_number(arr) ((gint)(sizeof(arr) / sizeof(arr[0])))
 
 #endif
 
Index: plugins/document-manager/anjuta-document.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/anjuta-document.c,v
retrieving revision 1.39
diff -u -r1.39 anjuta-document.c
--- plugins/document-manager/anjuta-document.c	2001/11/16 02:34:08	1.39
+++ plugins/document-manager/anjuta-document.c	2001/12/02 08:30:40
@@ -772,8 +772,12 @@
 		  }
 	 } else {
 		 BonoboStream *stream;
-		 stream = bonobo_stream_vfs_open (document->filename,
-						  Bonobo_Storage_WRITE);
+		 if (anjuta_file_exists (document->filename))
+			 stream = bonobo_stream_vfs_open (
+				 document->filename, Bonobo_Storage_WRITE);
+		 else
+			 stream = bonobo_stream_vfs_new (document->filename);
+
 		 Bonobo_PersistStream_save (document->persist_stream,
 					    bonobo_object_corba_objref (BONOBO_OBJECT (stream)),
 					    document->mime_type,
Index: plugins/document-manager/file-ops.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/file-ops.c,v
retrieving revision 1.29
diff -u -r1.29 file-ops.c
--- plugins/document-manager/file-ops.c	2001/11/16 02:34:08	1.29
+++ plugins/document-manager/file-ops.c	2001/12/02 08:30:40
@@ -243,7 +243,7 @@
 	gchar warnmsg[STRLEN];
 	gint btn;
 
-	if( file_exist( filename ) != 0 ) {
+	if( anjuta_file_exists ( filename ) != 0 ) {
 		/* overwrite dialog */
 		sprintf( warnmsg,
 			 _("The File %s already exists. Overwrite it?"),
@@ -347,6 +347,21 @@
 	fprintf( history, "%s\n", anjuta_document_get_filename(document) );
 }
 
+#if 0
+static glong get_last_mod( gchar const *filename )
+{
+	struct stat f_stat;
+
+	if( stat( filename, &f_stat ) != 0 )
+	{
+		/*g_print( "%s: %s\n", filename, g_strerror( errno ) );*/
+		return( -1 );
+	}
+
+	return( (glong) f_stat.st_mtime );
+}
+#endif
+
 static void
 _file_autosave( AnjutaDocument *document, gpointer data )
 {
@@ -412,45 +427,6 @@
 #endif
 }
 
-
-gint file_check_if_exist( gchar *fname, gint askcreate )
-{
-	gchar txt[512];
-	FILE *file;
-	struct stat sta;
-	gint e;
-        
-	e=stat(fname,&sta);
-	if( !e && S_ISREG(sta.st_mode) )
-	{   	/* file exist and is a regular file */
-		return( 1 );	
-	}
-
-	if( askcreate && e==-1 )
-	{
-	    sprintf( txt, _("The file\n'%s'\ndoes not exist!\nDo you want to create the file?"), fname );
-	    if( anjuta_ask_dialog( txt ) == 0 ) /*GNOME_YES )*/
-	    {
-	        file = fopen( fname, "w" );	/* this is not a good way!! */
-		if( file ) 
-		{
-			fclose( file );
-		}
-
-		return( 1 );
-	    }
-	}
-	else
-	{
-		if( !e )
-		{ 
-		    sprintf( txt, _("The file '%s' is not a regular file!"), fname );
-                    anjuta_error_dialog( txt );
-                }
-	}
-
-	return( 0 );
-}
 
 /*
  * Close all open files
Index: plugins/document-manager/file-ops.h
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/document-manager/file-ops.h,v
retrieving revision 1.13
diff -u -r1.13 file-ops.h
--- plugins/document-manager/file-ops.h	2001/11/04 01:55:21	1.13
+++ plugins/document-manager/file-ops.h	2001/12/02 08:30:40
@@ -40,7 +40,6 @@
 void file_close( GtkWidget *widget, gpointer data );
 void file_exit( GtkWidget *widget, gpointer data );
 void file_autosave( GtkWidget *widget, gpointer data );
-gint file_check_if_exist(gchar *,gint );
 glong check_doc_changed( AnjutaDocument *doc );
 void file_close_all(GtkWidget* widget, gpointer data);
 void file_save_all(GtkWidget* widget, gpointer data);
Index: plugins/files/files-tool.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/files/files-tool.c,v
retrieving revision 1.8
diff -u -r1.8 files-tool.c
--- plugins/files/files-tool.c	2001/11/04 01:55:25	1.8
+++ plugins/files/files-tool.c	2001/12/02 08:30:40
@@ -410,7 +410,7 @@
 	gchar*				filename;
 
 	filename = g_strdup_printf("%s/%s", dname, fname);
-	sprintf(filesize, "%ld", get_file_size(filename));
+	sprintf(filesize, "%ld", anjuta_get_file_size (filename));
 	g_free(filename);
 
 	return filesize;
Index: plugins/functions/protogen.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/functions/protogen.c,v
retrieving revision 1.3
diff -u -r1.3 protogen.c
--- plugins/functions/protogen.c	2001/11/04 01:55:27	1.3
+++ plugins/functions/protogen.c	2001/12/02 08:30:40
@@ -53,7 +53,7 @@
 	ptr = gtk_entry_get_text(GTK_ENTRY(e_source));
 	if(ptr)
 	{
-		if(isempty(ptr))
+		if(anjuta_is_empty_string (ptr))
 		{
 			return 0;
 		}
@@ -66,7 +66,7 @@
 	ptr = gtk_entry_get_text(GTK_ENTRY(e_target));
 	if(ptr)
 	{
-		if(isempty(ptr))
+		if(anjuta_is_empty_string (ptr))
 		{
 			return 0;
 		}
Index: plugins/functions/tree.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/functions/tree.c,v
retrieving revision 1.5
diff -u -r1.5 tree.c
--- plugins/functions/tree.c	2001/11/04 01:55:27	1.5
+++ plugins/functions/tree.c	2001/12/02 08:30:42
@@ -342,7 +342,7 @@
 	}
 
 	/* show functions, defines & prototypes */
-	if(!hit && !isempty(key))
+	if(!hit && !anjuta_is_empty_string (key))
 	{
 		if(modus == 1)
 		{
@@ -764,7 +764,7 @@
 
 #if 0
 	/* parse function file */
-	if(isempty(cfg->ign_file))
+	if(anjuta_is_empty_string (cfg->ign_file))
 	{
 		g_snprintf(funcfilewp, MAXLEN, "%s/%s", gide_path,
 			FUNC_IGN_FILE);
Index: plugins/help/help.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/help/help.c,v
retrieving revision 1.5
diff -u -r1.5 help.c
--- plugins/help/help.c	2001/11/04 01:55:28	1.5
+++ plugins/help/help.c	2001/12/02 08:30:42
@@ -318,7 +318,7 @@
 
 	/* skip first line */
 	fgets(line, sizeof(line), fp);
-	if(!isempty(line))
+	if(!anjuta_is_empty_string (line))
 	{
 		/* no help available */
 		/* Show some error message */
@@ -500,7 +500,7 @@
 
 		*ptr = '\0';
 
-		if(!isempty(mp))
+		if(!anjuta_is_empty_string (mp))
 		{
 			help_show(mp);
 		}
Index: plugins/prjfiles/files.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/prjfiles/files.c,v
retrieving revision 1.5
diff -u -r1.5 files.c
--- plugins/prjfiles/files.c	2001/11/04 00:12:40	1.5
+++ plugins/prjfiles/files.c	2001/12/02 08:30:42
@@ -85,7 +85,7 @@
 	files++;
 
 	filename = gI_document_get_filename(document);
-	if(filename != NULL && !isempty(filename))
+	if(filename != NULL && !anjuta_is_empty_string (filename))
 	{
 		sprintf(no_str, "%ld", files);
 		insrow[0] = no_str;
Index: plugins/protogen/protogen.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/protogen/protogen.c,v
retrieving revision 1.2
diff -u -r1.2 protogen.c
--- plugins/protogen/protogen.c	2001/11/04 00:12:46	1.2
+++ plugins/protogen/protogen.c	2001/12/02 08:30:42
@@ -51,7 +51,7 @@
 	ptr = gtk_entry_get_text(GTK_ENTRY(e_source));
 	if(ptr)
 	{
-		if(isempty(ptr))
+		if(anjuta_is_empty_string (ptr))
 		{
 			return 0;
 		}
@@ -64,7 +64,7 @@
 	ptr = gtk_entry_get_text(GTK_ENTRY(e_target));
 	if(ptr)
 	{
-		if(isempty(ptr))
+		if(anjuta_is_empty_string (ptr))
 		{
 			return 0;
 		}
Index: plugins/selection/plugin-selection.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/selection/plugin-selection.c,v
retrieving revision 1.4
diff -u -r1.4 plugin-selection.c
--- plugins/selection/plugin-selection.c	2001/11/04 01:55:34	1.4
+++ plugins/selection/plugin-selection.c	2001/12/02 08:30:43
@@ -18,6 +18,100 @@
 #define SELECTION_TITLE _("selection Plugin")
 #define SELECTION_DESCR _("Tries to open a file which is selected in the editor")
 
+static gchar *
+SK_GetBetween( gchar *str, gchar start, gchar stop )
+{
+	gchar *ptr = NULL;
+
+	while( *str )
+	{
+		if( *str == start && !ptr )
+		{
+			str++;
+			ptr = str;
+		}
+		if( *str == stop && ptr )
+		{
+			*str = '\0';
+			break;
+		}
+		str++;
+	}
+
+	if( !ptr )
+		return( str );
+	else
+		return( ptr );
+}
+
+/*
+(--------------------------------------------------------------------------)
+(                                                                          )
+(    Function Name: SK_GetFields                                           )
+(    Prototype: int SK_GetFields( gchar *string, gchar *retarray[],          )
+(                                 gchar separator )                         )
+(    Purpose: Liefert die einzelnen, durch das Trennzeichen seperator      )
+(             getrennten Felder, im Array retarray zurueck.                )
+(    Return: Bei Fehler 0, andernfalls die Anzahl der zurueckgelieferten   )
+(            Felder.                                                       )
+(    Author: Steffen Kern                                                  )
+(    Date: 05.04.1998 (Last Update: 07.04.1998)                            )
+(                                                                          )
+(--------------------------------------------------------------------------)
+*/
+
+gint SK_GetFields( gchar string[], gchar *retarray[], gchar separator )
+{
+	gint  HelpCount;
+	gint  strpos;
+	gint  ArrayCount;
+	gchar *HelpString = (gchar *) malloc( (strlen( string ) + 1) * sizeof( gchar ) );
+	gchar HelpChar;
+
+	/* set start values */
+	HelpCount = 0;
+	strpos = 0;
+	ArrayCount = 1;
+
+	if( strlen( string ) == 0 )
+	{
+		free(HelpString);
+		return(0);
+	}
+
+	while( strpos <= strlen( string ) )
+	{
+		HelpChar = string[strpos];
+		if( HelpChar == '\n' ||
+		        HelpChar == separator ||
+		        strpos == strlen( string ) )
+		{
+			HelpString[ HelpCount ] = '\0';
+			retarray[ArrayCount] = (gchar *)malloc( (HelpCount+1) * sizeof( gchar ) );
+			strcpy( retarray[ArrayCount], HelpString );
+			ArrayCount++;
+			strpos++;
+			HelpCount=0;
+		}
+		else
+		{
+			HelpString[ HelpCount ] = HelpChar;
+			HelpCount++;
+			strpos++;
+		}
+	}
+
+	/* free allocated memory */
+	free( HelpString );
+
+	/* allocate memory for retarray[0] */
+	retarray[0] = (gchar *)malloc( 10 );
+	sprintf( retarray[0], "%d", ArrayCount );
+
+	return( ArrayCount );
+}  /* SK_GetFields */
+
+
 static void
 open_selected(
 	Tool*				tool,
Index: plugins/swapch/swapch-tool.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/swapch/swapch-tool.c,v
retrieving revision 1.9
diff -u -r1.9 swapch-tool.c
--- plugins/swapch/swapch-tool.c	2001/11/04 01:55:53	1.9
+++ plugins/swapch/swapch-tool.c	2001/12/02 08:30:43
@@ -44,6 +44,7 @@
 	}
 	if(!len)
 	{
+		g_free (filename);
 		return;
 	}
 
@@ -53,15 +54,16 @@
 		newfname = g_malloc(len + 4);
 		strcpy(newfname, filename);
 		strcpy(&newfname[len], "cc");
-		if(!file_check_if_exist(newfname, FALSE))
+		if(!anjuta_file_check_if_exists(newfname, FALSE))
 		{
 			strcpy(&newfname[len], "cpp");
-			if(!file_check_if_exist(newfname, FALSE))
+			if(!anjuta_file_check_if_exists(newfname, FALSE))
 			{
 				newfname[len + 1] = 0;
-				if(!file_check_if_exist(newfname, TRUE))
+				if(!anjuta_file_check_if_exists(newfname, TRUE))
 				{
-					g_free(newfname);
+					g_free (newfname);
+					g_free (filename);
 					return;
 				}
 			}
@@ -73,9 +75,10 @@
 		newfname = g_strdup(filename);
 		newfname[len] = 'h';
 		newfname[len + 1] = 0;
-		if(!file_check_if_exist(newfname, TRUE))
+		if(!anjuta_file_check_if_exists(newfname, TRUE))
 		{
-			g_free(newfname);
+			g_free (filename);
+			g_free (newfname);
 			return;
 		}
 	}
@@ -85,6 +88,7 @@
 	}
 
 	anjuta_show_file(tool, newfname);
+	g_free (filename);
 	g_free(newfname);
 }
 
Index: plugins/text/text-replace.c
===================================================================
RCS file: /cvs/gnome/anjuta2/plugins/text/text-replace.c,v
retrieving revision 1.5
diff -u -r1.5 text-replace.c
--- plugins/text/text-replace.c	2001/11/04 01:55:54	1.5
+++ plugins/text/text-replace.c	2001/12/02 08:30:43
@@ -23,7 +23,7 @@
 	gchar*				filler;
 	gint				numspaces;
 
-	if(!str || isempty(str))
+	if(!str || anjuta_is_empty_string (str))
 	{
 		return;
 	}


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