Skip to content

Instantly share code, notes, and snippets.

@themadsens
Created February 29, 2016 14:56
Show Gist options
  • Save themadsens/a892770c18c93dd82487 to your computer and use it in GitHub Desktop.
Save themadsens/a892770c18c93dd82487 to your computer and use it in GitHub Desktop.
PATCH: gkermit progress meter
Up for grabs:
gkermit progress meter
diff -u -ur org/gkermit.c ./gkermit.c
--- org/gkermit.c 1999-12-27 03:11:19.000000000 +0100
+++ ./gkermit.c 2016-02-29 15:45:29.000000000 +0100
@@ -89,6 +89,10 @@
int recvtype = 0; /* Type of last packet received */
int datalen = 0; /* Length of received data field */
+long totlen = 0L;
+long curlen = 0L;
+time_t stime;
+
/* Protocol parameters */
int spsiz = 90, /* Default send-packet size */
@@ -261,8 +265,28 @@
VOID
nxtpkt() { /* Next packet */
+ static char *twirl = "|/-\\";
+ static time_t ltime = 0;
+ time_t ctime;
+ char stat[50];
retries = 0; /* Reset per-packet retry count */
seq = (seq + 1) & 63; /* Next packet number, mod 64 */
+ if (!quiet) {
+ time(&ctime);
+ int el = ctime - stime;
+ if (ctime == ltime) {
+ sprintf(stat,"%c\r", twirl[seq & 3]);
+ }
+ else {
+ sprintf(stat,"%c %6d", twirl[seq & 3], curlen);
+ if (totlen) {
+ sprintf(stat + 8,"/%d - %d%%", totlen, curlen * 100 / totlen);
+ }
+ sprintf(stat + strlen(stat), " (%d/s %ds)\r", el > 0 ? curlen / el : 0, el);
+ }
+ fprintf(stderr, "%s", stat);
+ ltime = ctime;
+ }
}
int
@@ -335,7 +359,6 @@
return(spacket(c,seq,strlen(s),s)); /* Send S or I packet */
}
-int
sfile() { /* Send file header packet */
int x;
char pktnam[MAXPATHLEN];
@@ -346,6 +369,9 @@
fprintf(db,"sfile error %d",errno);
errpkt("Failure to open file");
}
+ totlen = zchki(filnam);
+ curlen = 0;
+ time(&stime);
if (cmarg2) /* User-supplied name - use as-is */
strncpy(pktnam,cmarg2,MAXPATHLEN);
else /* Actual filename - convert */
@@ -701,6 +727,7 @@
if (!c) c = -1;
} else { /* or file... */
c = zgetc(text);
+ curlen++;
}
if (c < 0) { /* Watch out for empty file. */
first = -1;
@@ -721,6 +748,7 @@
if (!next) next = -1;
} else {
next = zgetc(text);
+ curlen++;
}
if (next < 0) first = -1; /* If none, we're at EOF. */
osize = size; /* Remember current size. */
@@ -859,6 +887,7 @@
if (osp) { /* As many copies as indicated by */
*osp++ = a; /* the repeat count. */
} else {
+ curlen++;
putc((char)a,ofp); /* Use putc macro here to avoid */
if (ferror(ofp)) { /* function-call overhead. */
if (debug)
@@ -1070,6 +1099,9 @@
filnam[MAXPATHLEN] = NUL;
if (debug) fprintf(db,"rcvfil filename [%s]\n",filnam);
}
+ curlen = 0;
+ totlen = 0;
+ time(&stime);
if (zchko(myname) < 0) /* Check writability */
errpkt("Write access denied");
if (zopeno(myname) < 0) /* Open the output file */
diff -u -ur org/gkermit.h ./gkermit.h
--- org/gkermit.h 2003-05-27 17:30:13.000000000 +0200
+++ ./gkermit.h 2016-02-29 15:27:25.000000000 +0100
@@ -31,6 +31,8 @@
#define _GKERMIT_H
#include <stdio.h>
+#include <time.h>
+#include <string.h>
/* Kermit protocol definitions */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment