[PATCH] remove global vars in fish.c



Hi,

this patch removes the two remaining static globals in vfs/fish.c:

1) force_expiration is unused anyway;
2) reply_str is replaced by an additional parameter in command().

Regards,
--
Jindrich Makovicka
Index: fish.c
===================================================================
RCS file: /cvsroot/mc/mc/vfs/fish.c,v
retrieving revision 1.61
diff -u -b -B -r1.61 fish.c
--- fish.c	8 May 2003 06:04:05 -0000	1.61
+++ fish.c	9 Sep 2003 13:45:16 -0000
@@ -55,20 +55,14 @@
 #define TRANSIENT	4	/* transient negative completion */
 #define ERROR		5	/* permanent negative completion */
 
-/* If true, the directory cache is forced to reload */
-static int force_expiration = 0;
-
-/* FIXME: prev two variables should be killed */
-
 /* command wait_flag: */
 #define NONE        0x00
 #define WAIT_REPLY  0x01
 #define WANT_STRING 0x02
-static char reply_str [80];
 
 static int
-command (vfs *me, vfs_s_super *super, int wait_reply, const char *fmt, ...)
-    __attribute__ ((format (printf, 4, 5)));
+command (vfs *me, vfs_s_super *super, int wait_reply, char **reply_ret, const char *fmt, ...)
+    __attribute__ ((format (printf, 5, 6)));
 
 static int decode_reply (char *s, int was_garbage)
 {
@@ -106,7 +100,7 @@
 #define SUP super->u.fish
 
 static int
-command (vfs *me, vfs_s_super *super, int wait_reply, const char *fmt, ...)
+command (vfs *me, vfs_s_super *super, int wait_reply, char **reply_ret, const char *fmt, ...)
 {
     va_list ap;
     char *str;
@@ -132,8 +126,11 @@
     if (status < 0)
 	return TRANSIENT;
     
-    if (wait_reply)
-	return get_reply (me, SUP.sockr, (wait_reply & WANT_STRING) ? reply_str : NULL, sizeof (reply_str)-1);
+    if (wait_reply) {
+	if (reply_ret && (wait_reply & WANT_STRING)) *reply_ret = (char*)malloc(sizeof(char)*80);
+	return get_reply (me, SUP.sockr, (wait_reply & WANT_STRING) ? *reply_ret : NULL, 80-1);
+    }
+    
     return COMPLETE;
 }
 
@@ -142,7 +139,7 @@
 {
     if ((SUP.sockw != -1) || (SUP.sockr != -1)){
 	print_vfs_message (_("fish: Disconnecting from %s"), super->name?super->name:"???");
-	command(me, super, NONE, "#BYE\nexit\n");
+	command(me, super, NONE, NULL, "#BYE\nexit\n");
 	close(SUP.sockw);
 	close(SUP.sockr);
 	SUP.sockw = SUP.sockr = -1;
@@ -186,8 +183,13 @@
 /* The returned directory should always contain a trailing slash */
 static char *fish_getcwd(vfs *me, vfs_s_super *super)
 {
-    if (command(me, super, WANT_STRING, "#PWD\npwd; echo '### 200'\n") == COMPLETE)
-        return  g_strconcat (reply_str, "/", NULL);
+    char *reply_str;
+    if (command(me, super, WANT_STRING, &reply_str, "#PWD\npwd; echo '### 200'\n") == COMPLETE) {
+	char *res = g_strconcat (reply_str, "/", NULL);
+	g_free (reply_str);
+        return res;
+    }
+    
     ERRNOR (EIO, NULL);
 }
 static int
@@ -254,17 +256,17 @@
      * Run `start_fish_server'. If it doesn't exist - no problem,
      * we'll talk directly to the shell.
      */
-    if (command (me, super, WAIT_REPLY,
+    if (command (me, super, WAIT_REPLY, NULL,
                  "#FISH\necho; start_fish_server 2>&1;"
                  " echo '### 200'\n") != COMPLETE)
         ERRNOR (E_PROTO, -1);
 
     print_vfs_message( _("fish: Handshaking version...") );
-    if (command (me, super, WAIT_REPLY, "#VER 0.0.0\necho '### 000'\n") != COMPLETE)
+    if (command (me, super, WAIT_REPLY, NULL, "#VER 0.0.0\necho '### 000'\n") != COMPLETE)
         ERRNOR (E_PROTO, -1);
 
     /* Set up remote locale to C, otherwise dates cannot be recognized */
-    if (command (me, super, WAIT_REPLY, "LANG=C; LC_ALL=C; LC_TIME=C\n"
+    if (command (me, super, WAIT_REPLY, NULL, "LANG=C; LC_ALL=C; LC_TIME=C\n"
 					"export LANG; export LC_ALL; export LC_TIME\n"
 					"echo '### 200'\n") != COMPLETE)
         ERRNOR (E_PROTO, -1);
@@ -329,10 +331,6 @@
     struct timeval tim;
 
     gettimeofday(&tim, NULL);
-    if (force_expiration) {
-	force_expiration = 0;
-	return 0;
-    }
     if (tim.tv_sec < ino->u.fish.timestamp.tv_sec)
 	return 1;
     return 0;
@@ -355,7 +353,7 @@
     dir->u.fish.timestamp.tv_sec += 10; /* was 360: 10 is good for
 					   stressing direntry layer a bit */
     quoted_path = name_quote (remote_path, 0);
-    command(me, super, NONE,
+    command(me, super, NONE, NULL,
 	    "#LIST /%s\n"
 	    "ls -lLa /%s 2>/dev/null | grep '^[^cbt]' | (\n"
 	      "while read p x u g s m d y n; do\n"
@@ -487,7 +485,7 @@
 
     /* FIXME: File size is limited to ULONG_MAX */
     if (!fh->u.fish.append)
-	n = command (me, super, WAIT_REPLY,
+	n = command (me, super, WAIT_REPLY, NULL,
 		 "#STOR %lu /%s\n"
 		 "> /%s\n"
 		 "echo '### 001'\n"
@@ -500,7 +498,7 @@
 		 (unsigned long) s.st_size, name, quoted_name,
 		 (unsigned long) s.st_size, quoted_name);
     else
-	n = command (me, super, WAIT_REPLY,
+	n = command (me, super, WAIT_REPLY, NULL,
 		 "#STOR %lu /%s\n"
 		 "echo '### 001'\n"
 		 "(\n"
@@ -553,6 +551,8 @@
 {
     char *name;
     char *quoted_name;
+    char *reply_str;
+
     if (offset)
         ERRNOR (E_NOTSUPP, 0);
 /*    fe->local_stat.st_mtime = 0; FIXME: what is this good for? */
@@ -563,7 +563,7 @@
     g_free (name);
     name = quoted_name;
     fh->u.fish.append = 0;
-    offset = command(me, FH_SUPER, WANT_STRING,
+    offset = command(me, FH_SUPER, WANT_STRING, &reply_str,
 		"#RETR /%s\n"
 		"ls -l /%s 2>/dev/null | (\n"
 		  "read var1 var2 var3 var4 var5 var6\n"
@@ -574,11 +574,17 @@
 		"echo '### 200'\n", 
 		name, name, name );
     g_free (name);
-    if (offset != PRELIM) ERRNOR (E_REMOTE, 0);
+    if (offset != PRELIM) {
+	g_free (reply_str);
+	ERRNOR (E_REMOTE, 0);
+    }
     fh->linear = LS_LINEAR_OPEN;
     fh->u.fish.got = 0;
-    if (sscanf( reply_str, "%d", &fh->u.fish.total )!=1)
+    if (sscanf( reply_str, "%d", &fh->u.fish.total )!=1) {
+	g_free (reply_str);
 	ERRNOR (E_REMOTE, 0);
+    }
+    g_free (reply_str);
     return 1;
 }
 
@@ -662,7 +668,7 @@
 {
     int r;
 
-    r = command (me, super, WAIT_REPLY, cmd);
+    r = command (me, super, WAIT_REPLY, NULL, cmd);
     vfs_add_noncurrent_stamps (&vfs_fish_ops, (vfsid) super, NULL);
     if (r != COMPLETE) ERRNOR (E_REMOTE, -1);
     if (flags & OPT_FLUSH)


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