Path: utzoo!attcan!uunet!blkcat!p0.f40.n109.z1.fidonet.org!Kai-Uwe.Rommel From: Kai-Uwe.Rommel@p0.f40.n109.z1.fidonet.org (Kai-Uwe Rommel) Newsgroups: comp.os.os2 Subject: (Part 6) compress (fast!) for OS/2 Message-ID: <724.25FAE701@blkcat.fidonet.org> Date: 12 Mar 90 04:39:48 GMT Sender: ufgate@blkcat.fidonet.org (newsout1.26) Organization: FidoNet node 1:109/40.0 - Crewe 400 Nat'l Hub, Joe Keenan Lines: 190 *** Split Message, part #6, MsgSplit Version 2 (11-Mar-90) *** X chown(ofname, statbuf.st_uid, statbuf.st_gid); /* Copy ownership */ X#endif X#ifndef __TURBOC__ X timep[0] = statbuf.st_atime; X timep[1] = statbuf.st_mtime; X utime(ofname, timep); X#else X if ((fd = open(ofname, O_RDONLY)) >= 0) { X if (getftime(fileno(stdin), &filetime) == 0) X setftime(fd, &filetime); X close(fd); X } X#endif X fclose(stdin); X ss = signal(SIGINT, SIG_IGN); X okunlink = 0; X /* ^C here would leave both input, and output files around */ X if ( !keep ) X { X if (unlink(ifname)) /* Remove input file */ X perror(ifname); X signal(SIGINT, ss); X if (verbose) X fprintf(stderr, " -- replaced with %s", ofname); X } X return; /* Successful return */ X } X X /* Unsuccessful return -- one of the tests failed */ X X if (unlink(ofname)) X perror(ofname); X} X Xvoid onintr(void) X{ X fclose(stdout); X if (okunlink) X unlink(ofname); X exit(1); X} X Xvoid oops(void) /* wild pointer -- assume bad input */ X{ X if (do_decomp) X fprintf (stderr, "uncompress: %s is corrupt.\n", ifname); X fclose(stdout); X if (okunlink) X unlink(ofname); X exit(1); X} X Xvoid prratio(num, den) Xlong int num, den; X{ X register int q; /* Doesn't need to be long */ X X if (num > 214748L) /* 2147483647/10000 */ X q = (int)(num / (den / 10000L)); X else X q = (int)(10000L * num / den); /* Long calculations, though */ X if (q < 0) { X putc('-', stderr); X q = -q; X } X fprintf(stderr, "%d.%02d%%", q / 100, q % 100); X} X Xvoid version() X{ X static shown = 0; X X if ( shown == 0 ) X { X fprintf(stderr, "\n%s\n", rcs_ident + 5); X fprintf(stderr, "BITS = %d\n", BITS); X shown = 1; X } X} X X/* X * Open the file "ofname" for binary output with possible check X * for overwrite. If all goes well, return non-zero, else zero. X */ Xint ofopen(filename) Xchar *filename; X{ X static char IOoutbuf[8192]; X struct stat statbuf; X X if (filename && !*filename) X filename = 0; X X /* X * Check for overwrite of existing file X */ X if (filename && !force && stat(filename, &statbuf) == 0) { X char response[2]; X response[0] = 'n'; X fprintf(stderr, "%s already exists;", filename); X if (foreground) { X fprintf(stderr, " do you wish to overwrite %s (y or n)? ", filename); X fflush(stderr); X read(2, response, 2); X while (response[1] != '\n') { X if (read(2, response+1, 1) < 0) { /* Ack! */ X perror("stderr"); X break; X } X } X } X if (response[0] != 'y') { X fprintf(stderr, "\tnot overwritten\n"); X return (0); X } X } X X okunlink = 1; X /* X * Open the output file. X */ X if (filename && !freopen(filename, "wb", stdout)) { X perror(filename); X return (0); X } X#ifdef O_BINARY X setmode(fileno(stdout), O_BINARY); X#else X#ifdef __ZTC__ X /* X * I'm sure there must be a better way in Zortech C to change the X * mode of an already opened file, but I can't find it. It doesn't X * have a "setmode" call it seems. X */ X stdout->_flag &= ~_IOTRAN; X#endif X#endif X setvbuf(stdout, IOoutbuf, _IOFBF, sizeof(IOoutbuf)); X return (1); X} X Xifopen(filename) Xchar *filename; X{ X static char IOinbuf[8192]; X X if (filename && !freopen(filename, "rb", stdin)) { X perror(filename); X return (0); X } X#ifdef O_BINARY X setmode(fileno(stdin), O_BINARY); X#else X#ifdef __ZTC__ X stdin->_flag &= ~_IOTRAN; X#endif X#endif X setvbuf(stdin, IOinbuf, _IOFBF, sizeof(IOinbuf)); X return (1); X} SHAR_EOF chmod 0666 compress.c || echo "restore of compress.c fails" echo "x - extracting compress.def (Text)" sed 's/^X//' << 'SHAR_EOF' > compress.def && XNAME COMPRESS WINDOWCOMPAT XDESCRIPTION 'compress 4.2 (very fast!) - for MS-DOS and OS/2' SHAR_EOF chmod 0666 compress.def || echo "restore of compress.def fails" echo "x - extracting compress.cs (Text)" sed 's/^X//' << 'SHAR_EOF' > compress.cs && X(-DOS2 -DMSC -DPROTO -Di8088 compress.c) Xcompress.exe Xcompress.def Xsetargv.obj X-AS -LB -S0x2000 SHAR_EOF chmod 0666 compress.cs || echo "restore of compress.cs fails" exit 0 ; -- Kai-Uwe Rommel at The Black Cat's Shack (Fidonet 1:109/401) Internet: Kai-Uwe.Rommel@p0.f40.n109.z1.fidonet.org UUCP: ...!uunet!blkcat!40.0!Kai-Uwe.Rommel