gay_d%elma.epfl.ch@cunyvm.cuny.edu (David Gay) (08/08/89)
The nice unshar program posted recently has a rather inconvenient bug in that it eats the 80th (or 81th) character of a line. The following are diffs which cure the program (as well as making the executable slightly smaller). Compile the new version with lc -O -v unshar, and link with blink FROM LIB:c.o+unshar.o TO unshar LIB LIB:lc.lib LIB:amiga.lib BATCH + sc sd VERBOSE nodebug define __main = __tinymain ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ David Gay "(p.suiv :=: q.prec.suiv).prec :=: q.prec" You don't want to know about this language ! GAY_D@ELMA.EPFL.CH, or GAY_D%ELMA.EPFL.CH@CLSEPF51.bitnet (Till the mid-august) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --------------------------- Cut here for diffs ------------------------------ 34c34 < * --- > * 46a47 > #include <proto/exec.h> 53a55,57 > /* Should be all >= MAXLINE */ > #define MAXPATH 255 > #define MAXSTR 255 67c71 < /* --- > /* 76a81,85 > void chkabort() > { > if (SetSignal(0, 0) & (SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D)) CtrlC = YE S; > } > 95c104 < * --- > * 118a128 > #define MAXLINE 255 123c133 < int diskerror = NO; --- > int diskerror = NO, ungotchar = EOF, noneread = YES; 132a143,149 > unsigned char ch; > > if (ungotchar != EOF) { > ch = ungotchar; > ungotchar = EOF; > return (ch); > } 142,145c159,182 < return (inbuffer[inbuf++]); < } < < /* --- > noneread = NO; > ch = inbuffer[inbuf++]; > MemCleanup(); /* dummy call, replace by any nop routine */ > return (ch); > } > > /* > * ungetc(c) > * Pushes back one character onto the input stream. It is an error tu push > * back more than one, or to do so before any chars have been read, or after > * end of file. > * > */ > > int ungetc(int ch) > { > if (!maxin || noneread || ungotchar != EOF) return (EOF); > > ungotchar = ch; > > return (ch); > } > > /* 215c252 < static char line[90]; --- > static char line[MAXLINE + 2]; 221c258 < while (i < 80 && ch != EOF && ch != EOL) { --- > while (i < MAXLINE && ch != EOF && ch != EOL) { 224a262,263 > if (i == MAXLINE && ch != EOF && ch != EOL) > ungetc(ch); 256,258c295,297 < static char s[80]; < < s[Read(Input(),s,75)] = '\0'; --- > static char s[MAXLINE + 2]; > > s[Read(Input(),s,MAXLINE)] = '\0'; 378c417 < char dir[80], *p; --- > char dir[MAXPATH], *p; 422c461 < char endmarker[100], filename[100],sedstring[100]; --- > char endmarker[MAXSTR], filename[MAXPATH],sedstring[MAXSTR]; 448,451c487,490 < } < } < < if (startfile) { --- > } > } > > if (startfile) { 533c572 < * New handler for Ctrl-C. Simply sets global variable to true and exits. --- > * Start of mainline 537,571c576,596 < int brk() < { < CtrlC = YES; < return (0); < } < < /* < * Start of mainline < * < */ < < int main(argc,argv) < int argc; < char *argv[]; < { < < int i, ok, overwrite = NO; < < if ((argc == 1) || (*argv[1] == '?')) { < print(HelpMsg); < return (10); < } < if (onbreak(brk)) < exit(10); < < for (i = 1, ok = YES; ok && i < argc && !CtrlC; i++) { < if (*argv[i] == '-' && (argv[i][1] == 'o' || argv[i][1] == 'O') ) < overwrite = YES; < else < ok = !unshar(argv[i], argc > 2, overwrite); < } < < if (CtrlC) < print("^C\n"); < } --- > int main(argc,argv) > int argc; > char *argv[]; > { > > int i, ok, overwrite = NO; > > if ((argc == 1) || (*argv[1] == '?')) { > print(HelpMsg); > XCEXIT (10); > } > for (i = 1, ok = YES; ok && i < argc && !CtrlC; i++) { > if (*argv[i] == '-' && (argv[i][1] == 'o' || argv[i][1] == 'O') ) > overwrite = YES; > else > ok = !unshar(argv[i], argc > 2, overwrite); > } > > if (CtrlC) > print("^C\n"); > }