Restored cls to help; dropped recls instead.
Added simple timer class. This uses timevals; gettimeofday is wrapped
in xgettimeofday for systems without it. (I did some searching; there
are a lot of places that say some systems don't have gettimeofday, but
none about timeval. If systems do turn out not to have it, we can just
define it ourselves.)
Added cmd:status-interval; default 1000 (ms). Implemented it for
StatusLine and completion status. This is also slightly more accurate,
even for 1000 ms delays; it Timeout()s the amount of time actually left
until the next update.
You might want to change cmd:status-interval's default to something
slightly lower (but still reasonable for slow terminals), like 500-750.
Suggestion: drop rels, reget, renlist, all other immediate variants;
replace them with "[re]ls", "[re]nlist", "[re]cls", etc. in short help
descriptions. It'll clean up the list and give room for queue, repeat,
glob ...
--
Glenn Maynard
? .FileCopy.cc.swp
? .FileCopy.h.swp
? .StatusLine.cc.swp
? .commands.cc.swp
? .misc.cc.swp
? .misc.h.swp
? gmon.out
? ls-lR
Index: StatusLine.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/StatusLine.cc,v
retrieving revision 1.11
diff -u -r1.11 StatusLine.cc
--- StatusLine.cc 2001/10/03 08:13:38 1.11
+++ StatusLine.cc 2001/10/08 09:11:01
@@ -40,6 +40,8 @@
#include "misc.h"
#include "StatusLine.h"
+ResDecl status_interval ("cmd:status-interval", "1000",
+ResMgr::UNumberValidate,0);
+
int StatusLine::GetWidth()
{
#ifdef TIOCGWINSZ
@@ -60,7 +62,6 @@
{
fd=new_fd;
update_delayed=false;
- update_time=0;
strcpy(shown,"");
strcpy(def_title,"");
not_term=!isatty(fd);
@@ -78,7 +79,7 @@
newstr[0]=0;
update(newstr);
update_delayed=false;
- update_time=0;
+ timer.force();
WriteTitle(def_title, fd);
}
@@ -104,17 +105,19 @@
vsnprintf(newstr,sizeof(newstr),f,v);
va_end(v);
- if(now>update_time)
+ if(!strcmp(to_be_shown,newstr)) return;
+
+ int res = timer.go(status_interval.Query(0));
+ if(!res)
{
update(newstr);
update_delayed=false;
- update_time=now;
}
- else if(strcmp(to_be_shown,newstr))
+ else
{
strcpy(to_be_shown,newstr);
update_delayed=true;
- TimeoutS(1);
+ Timeout(res);
}
}
@@ -182,7 +185,6 @@
write(fd,newstr,strlen(newstr));
}
-
void StatusLine::WriteLine(const char *f,...)
{
char *newstr=(char*)alloca(sizeof(shown)+strlen(f)+64);
@@ -230,13 +232,13 @@
{
if(!update_delayed)
return STALL;
- if(now>update_time)
+ int res = timer.go(status_interval.Query(0));
+ if(!res)
{
update(to_be_shown);
update_delayed=false;
- update_time=now;
return STALL;
}
- TimeoutS(1);
+ Timeout(res);
return STALL;
}
Index: StatusLine.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/StatusLine.h,v
retrieving revision 1.6
diff -u -r1.6 StatusLine.h
--- StatusLine.h 2001/03/13 08:41:42 1.6
+++ StatusLine.h 2001/10/08 09:11:01
@@ -29,14 +29,16 @@
# define PRINTF_LIKE(n,m)
#endif
+#include <time.h>
#include "SMTask.h"
+#include "misc.h"
class StatusLine : public SMTask
{
int fd;
char shown[0x800];
bool not_term;
- time_t update_time;
+ Timer timer;
char to_be_shown[0x800];
char def_title[0x800];
bool update_delayed;
Index: commands.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/commands.cc,v
retrieving revision 1.141
diff -u -r1.141 commands.cc
--- commands.cc 2001/10/08 07:14:50 1.141
+++ commands.cc 2001/10/08 09:11:02
@@ -147,7 +147,7 @@
{"close", cmd_close, "close [-a]",
N_("Close idle connections. By default only with current server.\n"
" -a close idle connections with all servers\n")},
- {"cls", cmd_cls, 0,
+ {"cls", cmd_cls, N_("cls [opts] [path/][wildcards]..."),
N_("cls [opts] [path/][wildcards]..."
"List remote files. You can redirect output of this command to file\n"
"or via pipe to external command.\n"
@@ -366,8 +366,9 @@
"unknown remote state and thus will cause reconnect. You cannot\n"
"be sure that any change of remote state because of quoted command\n"
"is solid - it can be reset by reconnect at any time.\n")},
- {"recls", cmd_cls, N_("recls [<args>]"),
- N_("Same as `cls', but don't look in cache\n")},
+ {"recls", cmd_cls, 0,
+ N_("recls [<args>]"
+ "Same as `cls', but don't look in cache\n")},
{"reget", cmd_get, N_("reget [OPTS] <rfile> [-o <lfile>]"),
N_("Same as `get -c'\n")},
{"rels", cmd_ls, N_("rels [<args>]"),
Index: complete.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/complete.cc,v
retrieving revision 1.43
diff -u -r1.43 complete.cc
--- complete.cc 2001/10/08 05:50:55 1.43
+++ complete.cc 2001/10/08 09:11:02
@@ -638,8 +638,6 @@
rl_save_prompt();
- int now_s = SMTask::now, now_ms = SMTask::now_ms;
-
ArgV arg("", ResMgr::Query("cmd:cls-completion-default", 0));
fso.parse_argv(&arg);
@@ -654,6 +652,9 @@
rl_variable_bind("completion-ignore-case", "0");
if(type==REMOTE_DIR)
rg->glob->DirectoriesOnly();
+ Timer timer;
+ int interval = ResMgr::Query("cmd:status-interval", 0);
+
for(;;)
{
SMTask::Schedule();
@@ -666,19 +667,13 @@
delete rg;
return 0;
}
-
- /* this time should match StatusLine's */
- if((SMTask::now - now_s)*1000 + (SMTask::now_ms - now_ms) > 1000) {
- now_s = SMTask::now;
- now_ms = SMTask::now_ms;
- if(!fso.quiet) {
- /* don't set blank status; if we're operating from cache,
- * that's all we'll get and it'll look ugly: */
- const char *ret = rg->Status();
- if(*ret)
- rl_message ("%s ", ret);
- }
+ if(!fso.quiet && !timer.go(interval)) {
+ /* don't set blank status; if we're operating from cache,
+ * that's all we'll get and it'll look ugly: */
+ const char *ret = rg->Status();
+ if(*ret)
+ rl_message ("%s ", ret);
}
SMTask::Block();
Index: misc.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.cc,v
retrieving revision 1.28
diff -u -r1.28 misc.cc
--- misc.cc 2001/10/05 06:26:53 1.28
+++ misc.cc 2001/10/08 09:11:02
@@ -37,9 +37,11 @@
#include <termios.h>
#endif
-#ifdef TM_IN_SYS_TIME
-# include <sys/time.h>
+#include <sys/time.h>
+#ifdef TIME_WITH_SYS_TIME
+# include <time.h>
#endif
+
#include <regex.h>
#include "misc.h"
#include "ProcWait.h"
@@ -598,5 +600,53 @@
if(!argv) return;
xfree(argv[0]);
xfree(argv);
+}
+
+void xgettimeofday(struct timeval *tv)
+{
+#ifdef HAVE_GETTIMEOFDAY
+ gettimeofday(tv,0);
+#else
+ time(&tv->tv_sec);
+ tv->tv_usec = 0;
+#endif
+}
+
+/* don't want to add a dependancy to SMTask */
+void Timer::reset()
+{
+ xgettimeofday(&last);
+}
+
+void Timer::force()
+{
+ last.tv_sec = last.tv_usec = 0;
+}
+
+Timer::Timer()
+{
+ force();
+}
+
+int Timer::go(int ms)
+{
+ struct timeval now;
+ xgettimeofday(&now);
+
+ struct timeval next = last;
+ next.tv_usec += ms * 1000;
+ next.tv_sec += (next.tv_usec / 1000000);
+ next.tv_usec %= 1000000;
+
+ if(now.tv_sec < next.tv_sec ||
+ (now.tv_sec == next.tv_sec && now.tv_usec < next.tv_usec)) {
+ int left = (now.tv_sec - next.tv_sec) * 1000;
+ left += (now.tv_usec - next.tv_usec) / 1000;
+ return left;
+ }
+
+ reset();
+
+ return 0;
}
Index: misc.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/misc.h,v
retrieving revision 1.20
diff -u -r1.20 misc.h
--- misc.h 2001/10/05 06:43:31 1.20
+++ misc.h 2001/10/08 09:11:03
@@ -25,7 +25,10 @@
#include <stdio.h>
#include <sys/types.h>
-#include <time.h>
+#include <sys/time.h>
+#ifdef TIME_WITH_SYS_TIME
+# include <time.h>
+#endif
// expands tilde; returns pointer to static data
const char *expand_home_relative(const char *);
@@ -93,5 +96,25 @@
char **tokenize(const char *str, int *argc = NULL);
void tokenize_free(char **argv);
+
+/* uses gettimeofday if available */
+void xgettimeofday(struct timeval *tv);
+
+class Timer {
+ struct timeval last;
+
+public:
+ Timer();
+
+ /* return 0 if ms have elapsed since last 0 return or instantiation;
+ * otherwise return the number of ms left */
+ int go(int ms);
+
+ /* reset timer */
+ void reset();
+
+ /* force timer to go on next call */
+ void force();
+};
#endif // MISC_H