diff -Naur gkermit/gcmdline.c gkermit-serial/gcmdline.c --- gkermit/gcmdline.c 1999-12-27 01:35:38.000000000 +0530 +++ gkermit-serial/gcmdline.c 2004-04-28 10:20:32.000000000 +0530 @@ -173,6 +173,14 @@ action = 's'; break; + case 'o': /* Output serial line */ + if (*(xp+1)) fatal("invalid argument bundling after -o"); + *xargv++, xargc--; + if ((xargc == 0) || (**xargv == '-')) + fatal("missing filename for -o"); + cmarg = *xargv; + break; + case 'g': /* get */ if (action) fatal("conflicting actions"); if (*(xp+1)) fatal("invalid argument bundling after -g"); diff -Naur gkermit/gkermit.c gkermit-serial/gkermit.c --- gkermit/gkermit.c 1999-12-27 07:41:19.000000000 +0530 +++ gkermit-serial/gkermit.c 2004-04-28 10:40:29.000000000 +0530 @@ -72,6 +72,10 @@ /* Externs */ +#include +#include +#include + extern int zincnt; /* For buffered file i/o */ extern char * zinptr; extern FILE * ofp; /* Output file pointer */ @@ -161,7 +165,9 @@ char **xargv; /* Global copies of argv */ int xargc; /* and argc */ -char *dftty = CTTNAM; /* Default controlling terminal name */ +char *dftty = "/dev/ttyS1"; /* Default controlling terminal name */ +int sd; char * #ifdef __STDC__ @@ -200,6 +207,14 @@ fprintf(stderr,"No start state\n"); doexit(1); } + + sd = open (cmarg, O_RDWR | O_NOCTTY | O_SYNC); + + if (!sd) { + fprintf (stderr, "Error opening serial device"); + doexit(1); + } + if (ttopen(ttname) < 0) { /* "Open" the communication device */ fprintf(stderr,"Can't open terminal\n"); doexit(1); @@ -213,6 +228,9 @@ ttflui(); /* flush comm line input buffer */ gwart(); /* Do the protocol */ } + + close(sd); + doexit(failure); /* Done, exit. */ return(failure); /* To shut up picky compilers. */ } @@ -327,7 +345,6 @@ s = rpar(); /* Get our protocol parameters */ if (c == 'S') { /* Sending a file... */ tmsgl(versio); - tmsgl("Escape back to your local Kermit and give a RECEIVE command."); tmsgl(""); tmsgl("KERMIT READY TO SEND..."); sleep(delay); diff -Naur gkermit/gunixio.c gkermit-serial/gunixio.c --- gkermit/gunixio.c 1999-12-27 05:02:26.000000000 +0530 +++ gkermit-serial/gunixio.c 2004-04-28 10:23:15.000000000 +0530 @@ -164,6 +164,8 @@ #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #endif /* S_ISREG */ +void UpdateProgress(char *, unsigned int, unsigned int); + /* External variables */ extern int literal; /* Literal filenames */ @@ -211,6 +213,8 @@ #endif /* POSIX */ static jmp_buf jbuf; /* Longjump buffer for timeouts */ +static long filesize = 0, senddone = 0; +extern int sd; /* Functions... */ @@ -221,7 +225,8 @@ ttres(); /* Reset the communication device */ #ifdef F_SETFL if (ttflags > -1) /* Restore its flags */ - fcntl(0,F_SETFL,ttflags); + fcntl(sd,F_SETFL,ttflags); #endif /* F_SETFL */ if (debug) { fprintf(db,"exit %d\n",x); @@ -233,7 +238,8 @@ VOID sysinit() { /* To be run first thing */ #ifdef F_SETFL - ttflags = fcntl(0,F_GETFL,0); /* Get and save stdin flags */ + ttflags = fcntl(sd,F_GETFL,0); /* Get and save stdin flags */ #endif /* F_SETFL */ #ifdef SIGINT signal(SIGINT,SIG_IGN); /* Ignore interrupts */ @@ -362,7 +368,8 @@ #ifdef F_SETFL if (ttflags != -1) { /* Set nonbocking i/o on stdin */ errno = 0; - if (fcntl(0, F_SETFL,ttflags|O_NDELAY) == -1) + if (fcntl(sd, F_SETFL,ttflags|O_NDELAY) == -1) logerr("ttopen fcntl(0,F_SETFL,O_NDELAY)"); else nonblock = 1; @@ -377,8 +384,10 @@ if (debug) fprintf(db,"ttopen nonblock = %d\n", nonblock); #ifdef POSIX - tcgetattr(0,&ttold); /* Get stdin device attributes */ - tcgetattr(0,&ttraw); + tcgetattr(sd,&ttold); /* Get stdin device attributes */ + tcgetattr(sd,&ttraw); #else #ifdef SYSV ioctl(0,TCGETA,&ttold); @@ -453,7 +462,8 @@ #endif /* VINTR */ #ifdef POSIX - if (tcsetattr(0,TCSADRAIN,&ttraw) < 0) + if (tcsetattr(sd,TCSADRAIN,&ttraw) < 0) return(-1); #else if (ioctl(0,TCSETAW,&ttraw) < 0) @@ -478,7 +488,8 @@ } #endif /* SETXONXOFF */ ttraw.sg_flags &= ~(ECHO|CRMOD); /* No echo, etc */ - if (stty(0,&ttraw) < 0) return(-1); /* Set modes */ + if (stty(sd,&ttraw) < 0) return(-1); /* Set modes */ #else system("stty raw -echo"); #endif /* BSD */ @@ -492,7 +503,8 @@ int x = 0; if (havemodes) { /* Restore old modes */ #ifdef POSIX - x = tcsetattr(0,TCSADRAIN,&ttold); + x = tcsetattr(sd,TCSADRAIN,&ttold); #else #ifdef SYSV sleep(1); /* Let output finish */ @@ -507,7 +519,8 @@ #endif /* SYSV */ #endif /* POSIX */ } - write(1,"\015\012",2); + write(sd,"\015\012",2); raw = 0; return(x); } @@ -517,7 +530,8 @@ int x = 0; if (nonblock) { /* Try to read */ errno = 0; - x = read(0,&tinbuf[tlast],TINBUFSIZ-tlast); + x = read(sd,&tinbuf[tlast],TINBUFSIZ-tlast); #ifdef EXTRADEBUG fprintf(db,"ttchk read %d errno = %d\n",x,errno); #endif /* EXTRADEBUG */ @@ -544,7 +558,8 @@ tinptr = tinbuf; errno = 0; #ifdef POSIX - x = tcflush(0,TCIFLUSH); /* kernel/driver buffers */ + x = tcflush(sd,TCIFLUSH); /* kernel/driver buffers */ #else #ifdef SYSV x = ioctl(0,TCFLSH,0); @@ -607,7 +622,8 @@ } else { /* Otherwise... */ while (1) { /* Read until we have a packet */ #ifdef DUMBIO - x = read(0,&c,1); /* Dumb blocking read byte loop */ + x = read(sd,&c,1); /* Dumb blocking read byte loop */ if (x < 0) { logerr("ttinl XX read 1"); rc = -2; @@ -629,7 +645,8 @@ int x; if (tincnt < 1) { /* Need to fill our buffer */ errno = 0; - tincnt = read(0,tinbuf,TINBUFSIZ); + tincnt = read(sd,tinbuf,TINBUFSIZ); if (tincnt > -1) tlast = tincnt; if (debug) fprintf(db,"ttinl nonblock tincnt=%d errno=%d\n", @@ -639,15 +656,18 @@ /* Go back to blocking and wait for 1 char */ if (ttflags != -1) { errno = 0; - x = fcntl(0, F_SETFL, ttflags & ~O_NDELAY); + x = fcntl(sd, F_SETFL, ttflags & ~O_NDELAY); if (x == -1 || errno) logerr("ttinl fcntl O_NDELAY off"); errno = 0; - tincnt = read(0,tinbuf,1); + tincnt = read(sd,tinbuf,1); if (tincnt < 1 || errno) logerr("ttinl BL read"); errno = 0; - fcntl(0, F_SETFL, ttflags | O_NDELAY); + fcntl(sd, F_SETFL, ttflags | O_NDELAY); if (x == -1 || errno) logerr("ttinl fcntl O_NDELAY on"); } @@ -675,7 +695,8 @@ tincnt--; } else { #endif /* O_NDELAY */ - x = read(0,&c,1); /* Dumb read byte loop */ + x = read(sd,&c,1); /* Dumb read byte loop */ if (x < 0) { logerr("ttinl XX read 1"); rc = -2; @@ -816,11 +837,13 @@ } } } - fflush(stdout); /* Push it out */ + fflush(sd); /* Push it out */ return(n); #else while (n > 0) { /* Send the packet with write() */ - i = write(1,&s[m],n); /* Allowing for partial results */ + i = write(sd,&s[m],n); /* Allowing for partial results */ if (i < 0) { if (errno == EWOULDBLOCK) /* and even no results at all.. */ continue; @@ -907,6 +930,11 @@ int zopeni(name) char *name; { /* Open existing file for input */ ifp = fopen(name,"r"); + + fseek(ifp, 0, SEEK_END); + filesize = ftell(ifp); + fseek(ifp, 0, SEEK_SET); + if (debug) fprintf(db,"zopeni %s: %d\n",name, ifp ? 0 : errno); filelength = zchki(name); if (filelength < 0) @@ -1155,6 +1183,9 @@ } } else { /* Binary - just read raw buffers */ zincnt = fread(zinbuf, sizeof(char), MAXRECORD, ifp); + senddone += zincnt; + UpdateProgress("Download progress", senddone, filesize); } zinbuf[zincnt] = NUL; /* Terminate. */ if (zincnt == 0) /* Check for EOF */ @@ -1170,3 +1201,37 @@ zincnt--; /* Return first byte. */ return(*zinptr++ & 0xff); } + +void UpdateProgress(char *title, unsigned int cur, unsigned int max) +{ + int dpywidth = 40; + static int progress_pos = 0; + char bar[] = + "===============================================================" + "==============================================================="; + char spaces[] = + " " + " "; + char spinner[] = "\\|/-"; + unsigned int i, percent; + + progress_pos = (progress_pos+1) & 3; + percent = (cur * 100) / max; + i = ((percent * dpywidth) + 50) / 100; + fprintf(stderr, "%s: |%s%s", title, + bar + (sizeof(bar) - (i+1)), + spaces + (sizeof(spaces) - (dpywidth - i + 1))); + if(percent == 100) + { + fprintf(stderr, "|"); + } + else + { + fprintf(stderr, "%c", spinner[progress_pos & 3] ); + } + fprintf(stderr, " %4d%% \r", percent); + if(percent == 100) /* clear prog bar */ + { + fprintf(stderr, "%s\r", spaces + (sizeof(spaces) - 80)); + } +}