SCCS-vsn: usr.bin/compress/compress.c 5.9
-static char sccsid[] = "@(#)compress.c 5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)compress.c @(#)compress.c 5.9 (Berkeley) %G%";
/*
* compress.c - File compression ala IEEE Computer, June 1984.
*
/*
* compress.c - File compression ala IEEE Computer, June 1984.
*
- * Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas)
+ * Authors: Spencer W. Thomas (decvax!utah-cs!thomas)
* Jim McKie (decvax!mcvax!jim)
* Steve Davies (decvax!vax135!petsd!peora!srd)
* Ken Turkowski (decvax!decwrl!turtlevax!ken)
* Jim McKie (decvax!mcvax!jim)
* Steve Davies (decvax!vax135!petsd!peora!srd)
* Ken Turkowski (decvax!decwrl!turtlevax!ken)
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef notdef
+#include <sys/ioctl.h>
+#endif
#define ARGVAL() (*++(*argv) || (--argc && *++argv))
#define ARGVAL() (*++(*argv) || (--argc && *++argv))
#define codetabof(i) (codetab[(i) >> 14][(i) & 0x3fff])
#else /* Normal machine */
#define codetabof(i) (codetab[(i) >> 14][(i) & 0x3fff])
#else /* Normal machine */
+
+#ifdef sel /* gould base register braindamage */
+/*NOBASE*/
+count_int htab [HSIZE];
+unsigned short codetab [HSIZE];
+/*NOBASE*/
+#else
count_int htab [HSIZE];
unsigned short codetab [HSIZE];
count_int htab [HSIZE];
unsigned short codetab [HSIZE];
#define htabof(i) htab[i]
#define codetabof(i) codetab[i]
#endif /* XENIX_16 */
#define htabof(i) htab[i]
#define codetabof(i) codetab[i]
#endif /* XENIX_16 */
#endif /* XENIX_16 */
code_int free_ent = 0; /* first unused entry */
#endif /* XENIX_16 */
code_int free_ent = 0; /* first unused entry */
+int exit_stat = 0; /* per-file status */
+int perm_stat = 0; /* permanent status */
#ifdef DEBUG
int verbose = 0;
#endif /* DEBUG */
#ifdef DEBUG
int verbose = 0;
#endif /* DEBUG */
+int (*oldint)();
+int bgnd_flag;
struct stat statbuf;
extern onintr(), oops();
struct stat statbuf;
extern onintr(), oops();
-
- if ( (bgnd_flag = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
+ /* This bg check only works for sh. */
+ if ( (oldint = signal ( SIGINT, SIG_IGN )) != SIG_IGN ) {
signal ( SIGINT, onintr );
signal ( SIGSEGV, oops );
}
signal ( SIGINT, onintr );
signal ( SIGSEGV, oops );
}
+ bgnd_flag = oldint != SIG_DFL;
+#ifdef notdef /* This works for csh but we don't want it. */
+ { int tgrp;
+ if (bgnd_flag == 0 && ioctl(2, TIOCGPGRP, (char *)&tgrp) == 0 &&
+ getpgrp(0) != tgrp)
+ bgnd_flag = 1;
+ }
+#endif
+
#ifdef COMPATIBLE
nomagic = 1; /* Original didn't have a magic number */
#endif /* COMPATIBLE */
#ifdef COMPATIBLE
nomagic = 1; /* Original didn't have a magic number */
#endif /* COMPATIBLE */
if (*filelist != NULL) {
for (fileptr = filelist; *fileptr; fileptr++) {
exit_stat = 0;
if (*filelist != NULL) {
for (fileptr = filelist; *fileptr; fileptr++) {
exit_stat = 0;
- if (do_decomp != 0) { /* DECOMPRESSION */
+ if (do_decomp) { /* DECOMPRESSION */
/* Check for .Z suffix */
if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") != 0) {
/* No .Z: tack one on */
/* Check for .Z suffix */
if (strcmp(*fileptr + strlen(*fileptr) - 2, ".Z") != 0) {
/* No .Z: tack one on */
}
/* Open input file */
if ((freopen(*fileptr, "r", stdin)) == NULL) {
}
/* Open input file */
if ((freopen(*fileptr, "r", stdin)) == NULL) {
- perror(*fileptr); continue;
+ perror(*fileptr);
+ perm_stat = 1;
+ continue;
}
/* Check the magic number */
if (nomagic == 0) {
}
/* Check the magic number */
if (nomagic == 0) {
}
/* Open input file */
if ((freopen(*fileptr, "r", stdin)) == NULL) {
}
/* Open input file */
if ((freopen(*fileptr, "r", stdin)) == NULL) {
- perror(*fileptr); continue;
+ perror(*fileptr);
+ perm_stat = 1;
+ continue;
}
stat ( *fileptr, &statbuf );
fsize = (long) statbuf.st_size;
}
stat ( *fileptr, &statbuf );
fsize = (long) statbuf.st_size;
char response[2];
response[0] = 'n';
fprintf(stderr, "%s already exists;", ofname);
char response[2];
response[0] = 'n';
fprintf(stderr, "%s already exists;", ofname);
+ if (bgnd_flag == 0 && isatty(2)) {
fprintf(stderr, " do you wish to overwrite %s (y or n)? ",
ofname);
fflush(stderr);
fprintf(stderr, " do you wish to overwrite %s (y or n)? ",
ofname);
fflush(stderr);
if(zcat_flg == 0) { /* Open output file */
if (freopen(ofname, "w", stdout) == NULL) {
perror(ofname);
if(zcat_flg == 0) { /* Open output file */
if (freopen(ofname, "w", stdout) == NULL) {
perror(ofname);
continue;
}
precious = 0;
continue;
}
precious = 0;
+ exit(perm_stat ? perm_stat : exit_stat);
fprintf(stderr, "%s: ", ifname);
fprintf(stderr, " -- not a regular file: unchanged");
exit_stat = 1;
fprintf(stderr, "%s: ", ifname);
fprintf(stderr, " -- not a regular file: unchanged");
exit_stat = 1;
} else if (statbuf.st_nlink > 1) {
if(quiet)
fprintf(stderr, "%s: ", ifname);
fprintf(stderr, " -- has %d other links: unchanged",
statbuf.st_nlink - 1);
exit_stat = 1;
} else if (statbuf.st_nlink > 1) {
if(quiet)
fprintf(stderr, "%s: ", ifname);
fprintf(stderr, " -- has %d other links: unchanged",
statbuf.st_nlink - 1);
exit_stat = 1;
} else if (exit_stat == 2 && (!force)) { /* No compression: remove file.Z */
if(!quiet)
fprintf(stderr, " -- file unchanged");
} else if (exit_stat == 2 && (!force)) { /* No compression: remove file.Z */
if(!quiet)
fprintf(stderr, " -- file unchanged");
if (unlink(ofname))
perror(ofname);
}
if (unlink(ofname))
perror(ofname);
}
-/*
- * This routine returns 1 if we are running in the foreground and stderr
- * is a tty.
- */
-foreground()
-{
- if(bgnd_flag) { /* background? */
- return(0);
- } else { /* foreground */
- if(isatty(2)) { /* and stderr is a tty */
- return(1);
- } else {
- return(0);
- }
- }
-}
oops ( ) /* wild pointer -- assume bad input */
{
oops ( ) /* wild pointer -- assume bad input */
{
fprintf ( stderr, "uncompress: corrupt input\n" );
unlink ( ofname );
exit ( 1 );
fprintf ( stderr, "uncompress: corrupt input\n" );
unlink ( ofname );
exit ( 1 );
- fprintf(stderr, "%s, Berkeley 5.8 %G%\n", rcs_ident);
+ fprintf(stderr, "%s, Berkeley 5.9 %G%\n", rcs_ident);
fprintf(stderr, "Options: ");
#ifdef vax
fprintf(stderr, "vax, ");
fprintf(stderr, "Options: ");
#ifdef vax
fprintf(stderr, "vax, ");