changeset 1238:78c4f497db2b

[gaim-migrate @ 1248] nsanch did this. thank you. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 12 Dec 2000 13:32:23 +0000
parents 72692c70317e
children b55da88df938
files src/dialogs.c src/gaim.h src/perl.c src/util.c
diffstat 4 files changed, 75 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/dialogs.c	Tue Dec 12 12:56:53 2000 +0000
+++ b/src/dialogs.c	Tue Dec 12 13:32:23 2000 +0000
@@ -2768,9 +2768,9 @@
 		g_screenname[i] = toupper(gc->username[i]);
 	g_screenname[i] = '\0';
 
-	file = getenv( "HOME" );
+	file = gaim_user_dir();
 	if ( file != (char *) NULL ) {
-	       	sprintf( path, "%s/.gaim/%s.blist", file, g_screenname);
+		sprintf(path, "%s/%s.blist", file, g_screenname); 
 		if ( !stat(path, &sbuf) ) {
 			sprintf(debug_buff, "%s exists.\n", path);
 			debug_print(debug_buff);
@@ -2779,6 +2779,7 @@
 			sprintf(debug_buff, "%s does not exist.\n", path);
 			debug_print(debug_buff);
 		}
+		g_free(file);
 	}
 	return ret;
 }
@@ -2818,10 +2819,10 @@
 		char g_screenname[64];
 		int i;
 
-		file = getenv( "HOME" );
+		file = gaim_user_dir();
 		if ( file != (char *) NULL ) {
 			FILE *dir;
-			sprintf(buf, "%s/.gaim/", file);
+			strcpy(buf, file);
 			dir = fopen(buf, "r");
 			if (!dir)
 				mkdir(buf, S_IRUSR | S_IWUSR | S_IXUSR);
@@ -2834,7 +2835,7 @@
 				for (i = 0; i < strlen(g->username); i++)
 					g_screenname[i] = toupper(g->username[i]);
 				g_screenname[i] = '\0';
-				sprintf( path, "%s/.gaim/%s.blist", file, g_screenname);
+				sprintf(path, "%s/%s.blist", file, g_screenname);
 				if ((f = fopen(path,"w"))) {
 					sprintf(debug_buff, "writing %s\n", path);
 					debug_print(debug_buff);
@@ -2849,10 +2850,11 @@
 
 				c = c->next;
 			}
+			g_free(file);
 		} else return;
 	}
 
-        g_free(buf);
+	g_free(buf);
         
 }
 
@@ -2901,9 +2903,9 @@
         FILE *f;
 	gboolean from_dialog = FALSE;
 
-        if ( !gc ) {
-        	file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog));
-                strncpy( path, file, PATHSIZE - 1 );
+	if ( !gc ) {
+		file = gtk_file_selection_get_filename(GTK_FILE_SELECTION(importdialog));
+				strncpy( path, file, PATHSIZE - 1 );
 		if (file_is_dir(path, importdialog)) {
 			g_free (buf);
 			g_free (first);
@@ -2912,22 +2914,24 @@
 		/* FIXME : import buddy list file. moderately important */
 		gc = connections->data;
 		from_dialog = TRUE;
-        }
-        else {
+	}
+	else {
 		for (i = 0; i < strlen(gc->username); i++)
 			g_screenname[i] = toupper(gc->username[i]);
 		g_screenname[i] = '\0';
 
-                file = getenv( "HOME" );
-                if ( file != (char *) NULL )
-                        sprintf( path, "%s/.gaim/%s.blist", file, g_screenname);
-                else
+		file = gaim_user_dir();
+		if ( file != (char *) NULL ) {
+			sprintf( path, "%s/%s.blist", file, g_screenname);
+			g_free(file);
+		} else {
 			return;
-        }
-
-        if (!(f = fopen(path,"r"))) {
+		}
+	}
+
+	if (!(f = fopen(path,"r"))) {
 		if ( !gc ) {
-                	g_snprintf(buf, BUF_LONG / 2, _("Error reading file %s"), file);
+                	g_snprintf(buf, BUF_LONG / 2, _("Error reading file %s"), path);
                 	do_error_dialog(buf, _("Error"));
                 	destroy_dialog(NULL, importdialog);
                 	importdialog = NULL;
@@ -2937,12 +2941,12 @@
                 g_free(buf);
 		g_free(first);
                 return;
-        }
+	}
                 
         fgets(first, 64, f);
 
 	/* AIM 4 buddy list */
-        if (!strcasecmp(first, "Config {\n")) {
+	if (!strcasecmp(first, "Config {\n")) {
 		debug_print("aim 4\n");
 		rewind(f);
 		translate_blt (f, buf);
@@ -2997,8 +3001,8 @@
                	importdialog = NULL;
 	} 
 
-        g_free(buf);
-        g_free(first);
+	g_free(buf);
+	g_free(first);
 }
 
 void show_import_dialog()
--- a/src/gaim.h	Tue Dec 12 12:56:53 2000 +0000
+++ b/src/gaim.h	Tue Dec 12 13:32:23 2000 +0000
@@ -559,6 +559,7 @@
 extern void set_first_user (char *);
 extern int do_auto_login (char *);
 extern int file_is_dir (char *, GtkWidget *);
+extern char *gaim_user_dir();
 extern void strncpy_withhtml(gchar *, const gchar *, size_t);
 
 /* Functions in server.c */
--- a/src/perl.c	Tue Dec 12 12:56:53 2000 +0000
+++ b/src/perl.c	Tue Dec 12 13:32:23 2000 +0000
@@ -44,6 +44,7 @@
 #undef PACKAGE
 #include <stdio.h>
 #include <dirent.h>
+#include <string.h>
 #include <gtk/gtk.h>
 
 
@@ -157,9 +158,9 @@
 	DIR *dir;
 	struct dirent *ent;
 	char *buf;
-	char path[BUF_LONG];
+	char *path;
 
-	g_snprintf(path, sizeof(path), "%s/.gaim", getenv("HOME"));
+	path = gaim_user_dir();
 	dir = opendir(path);
 	if (dir) {
 		while ((ent = readdir(dir))) {
@@ -174,6 +175,7 @@
 		}
 		closedir(dir);
 	}
+	g_free(path);
 }
 
 void perl_init()
@@ -639,8 +641,9 @@
 	gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(config));
 
 	if (!last_dir) {
-		buf = g_strjoin(NULL, g_get_home_dir(), G_DIR_SEPARATOR_S, ".gaim", 
-					G_DIR_SEPARATOR_S, NULL);
+		temp = gaim_user_dir();
+		buf = g_strconcat(temp, G_DIR_SEPARATOR_S);
+		g_free(temp);
 	} else {
 		buf = g_strconcat(last_dir, G_DIR_SEPARATOR_S, NULL);
 	}
--- a/src/util.c	Tue Dec 12 12:56:53 2000 +0000
+++ b/src/util.c	Tue Dec 12 13:32:23 2000 +0000
@@ -330,6 +330,7 @@
         int flag = 0;
         FILE *fd;
         int res;
+	gchar* gaim_dir;
 
         if (!(general_options & OPT_GEN_LOG_ALL)) {
 
@@ -353,9 +354,10 @@
 
 	buf = g_malloc(BUF_LONG);
 	buf2 = g_malloc(BUF_LONG);
-
+	gaim_dir = gaim_user_dir();
+	
         /*  Dont log yourself */
-        g_snprintf(log_all_file, 256, "%s/.gaim", getenv("HOME"));
+	strncpy(log_all_file, gaim_dir, 256);
 
         stat(log_all_file, &st);
         if (!S_ISDIR(st.st_mode))
@@ -375,7 +377,7 @@
         } else
                 fclose(fd);
 
-        g_snprintf(log_all_file, 256, "%s/.gaim/logs", getenv("HOME"));
+		g_snprintf(log_all_file, 256, "%s/logs", gaim_dir);
 
         if (stat(log_all_file, &st) < 0)
                 flag = 1;
@@ -396,8 +398,8 @@
                 fclose(fd);
 
         
-        g_snprintf(log_all_file, 256, "%s/.gaim/logs/%s.log", getenv("HOME"), normalize(name));
 
+        g_snprintf(log_all_file, 256, "%s/logs/%s.log", gaim_dir, normalize(name));
         if (stat(log_all_file, &st) < 0)
                 flag = 1;
 
@@ -414,6 +416,7 @@
 
 	g_free(buf);
 	g_free(buf2);
+	g_free(gaim_dir);
         return fd;
 }
 
@@ -429,7 +432,7 @@
 		debug_print(debug_buff);
 		msg[2047]='\0';
 	}
-	
+
 	cpy = g_strdup(msg);
 	c = cpy;
 	while(*c) {
@@ -462,7 +465,7 @@
 		fprintf(stderr, "Warning:  truncating message to 2048 bytes\n");
 		msg[2047]='\0';
 	}
-	
+
 	cpy = g_strdup(msg);
 	c = cpy;
 	while(*c) {
@@ -491,7 +494,7 @@
 
 char * escape_text2(char *msg)
 {
-        char *c, *cpy;
+	char *c, *cpy;
 	char *woo;
         int cnt=0;
         /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */
@@ -539,9 +542,9 @@
 	char *c;
 	unsigned int tmp = 0;
 	int len = 0, n = 0;
-	
+    
 	c = text;
-	
+    
 	while(c) {
 		tmp = tmp << 8;
 		tmp += *c;
@@ -560,22 +563,22 @@
 		c++;
 	}
 	switch(n) {
-	
+
 	case 2:
-	        out = g_realloc(out, len+5);
-	        out[len] = alphabet[(tmp >> 12) & 0x3f];
-	        out[len+1] = alphabet[(tmp >> 6) & 0x3f];
-	        out[len+2] = alphabet[tmp & 0x3f];
-	        out[len+3] = '=';
-	        out[len+4] = 0;
-	        break;
+		out = g_realloc(out, len+5);
+		out[len] = alphabet[(tmp >> 12) & 0x3f];
+		out[len+1] = alphabet[(tmp >> 6) & 0x3f];
+		out[len+2] = alphabet[tmp & 0x3f];
+		out[len+3] = '=';
+		out[len+4] = 0;
+		break;
 	case 1:
-	        out = g_realloc(out, len+4);
-	        out[len] = alphabet[(tmp >> 6) & 0x3f];
-	        out[len+1] = alphabet[tmp & 0x3f];
-	        out[len+2] = '=';
-	        out[len+3] = 0;
-	        break;
+		out = g_realloc(out, len+4);
+		out[len] = alphabet[(tmp >> 6) & 0x3f];
+		out[len+1] = alphabet[tmp & 0x3f];
+		out[len+2] = '=';
+		out[len+3] = 0;
+		break;
 	case 0:
 		out = g_realloc(out, len+2);
 		out[len] = '=';
@@ -606,7 +609,7 @@
                 } else if (*c == '+') {
                         tmp = 62;
                 } else if (*c == '/') {
-                	tmp = 63;
+                        tmp = 63;
                 } else if (*c == '=') {
                         if (n == 3) {
                                 out = g_realloc(out, len + 2);
@@ -697,7 +700,7 @@
 #ifndef _WIN32
 	if (icon_pm == NULL) {
 		icon_pm = gdk_pixmap_create_from_xpm_d(w, &icon_bm,
-						       NULL, (gchar **)aimicon_xpm);
+							   NULL, (gchar **)aimicon_xpm);
 	}
 	gdk_window_set_icon(w, NULL, icon_pm, icon_bm);
 	if (mainwindow) gdk_window_set_group(w, mainwindow->window);
@@ -820,7 +823,7 @@
 	gtk_widget_show(button_box);
 
 /* this causes clipping on lots of buttons with long text */
-/*	gtk_widget_set_usize(button, 75, 30);*/
+/*  gtk_widget_set_usize(button, 75, 30);*/
 	gtk_widget_show(button);
 	gdk_pixmap_unref(pm);
 	gdk_bitmap_unref(mask);
@@ -837,7 +840,7 @@
 	GdkPixmap *pm;
 	GtkWidget *pixmap;
 	GtkWidget *label;
-	
+
 	if (!button_tips) button_tips = gtk_tooltips_new();
 	button = gtk_button_new();
 	if (display_options & OPT_DISP_COOL_LOOK)
@@ -933,14 +936,14 @@
 
 	sprintf (dest, "m 1\n");
   
-	while (strstr (fgets (line, BUF_LEN, src_fp), "Buddy") == NULL)	;
-	while (strstr (fgets (line, BUF_LEN, src_fp), "list") == NULL)	;
+	while (strstr (fgets (line, BUF_LEN, src_fp), "Buddy") == NULL) ;
+	while (strstr (fgets (line, BUF_LEN, src_fp), "list") == NULL)  ;
 
 	while (1) {
 		fgets (line, BUF_LEN, src_fp);
 		if (strchr (line, '}') != NULL)
 			break;
-    
+	
 		/* Syntax starting with "<group> {" */
 		if (strchr (line, '{') != NULL) {
 			strcat (dest, "g ");
@@ -1233,6 +1236,13 @@
 	}
 }
 
+/* returns a string of the form ~/.gaim, where ~ is replaced by the user's home
+ * dir. this string should be freed after it's used. Note that there is no
+ * trailing slash after .gaim. */
+gchar* gaim_user_dir() {
+	return g_strjoin(G_DIR_SEPARATOR_S, g_get_home_dir(), ".gaim", NULL);
+}
+
 void strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize)
 {
 	gchar *end = dest + destsize;