/*
- * Copyright (c) 1989 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Edward Wang at The University of California, Berkeley.
*
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement: ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
*/
#ifndef lint
-static char sccsid[] = "@(#)compress.c 3.5 (Berkeley) 6/6/90";
+static char sccsid[] = "@(#)compress.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include "ww.h"
/* special */
#include <stdio.h>
+#include <fcntl.h>
int cc_trace = 0;
FILE *cc_trace_fp;
ccstart()
{
- register struct cc *p;
int ccflush();
- (*tt.tt_flush)();
+ ttflush();
tt_obp = tt_ob = cc_buffer;
tt_obe = tt_ob + cc_bufsize;
tt.tt_flush = ccflush;
+ if (cc_trace) {
+ cc_trace_fp = fopen("window-trace", "a");
+ (void) fcntl(fileno(cc_trace_fp), F_SETFD, 1);
+ }
+ ccreset();
+}
+
+ccreset()
+{
+ register struct cc *p;
+
bzero((char *) cc_htab, HSIZE * sizeof *cc_htab);
for (p = cc_q0a.qforw; p != &cc_q0a; p = p->qforw)
p->hback = 0;
for (p = cc_q1a.qforw; p != &cc_q1a; p = p->qforw)
p->hback = 0;
- if (cc_trace)
- cc_trace_fp = fopen("window-trace", "a");
}
ccend()
{
- int ttflush();
- (*tt.tt_flush)();
+ ttflush();
tt_obp = tt_ob = cc_tt_ob;
tt_obe = cc_tt_obe;
- tt.tt_flush = ttflush;
+ tt.tt_flush = 0;
if (cc_trace_fp != NULL) {
(void) fclose(cc_trace_fp);
cc_trace_fp = NULL;
{
int bufsize = tt_obp - tt_ob;
int n;
- int ttflush();
if (tt_ob != cc_buffer)
abort();
if (cc_trace_fp != NULL) {
(void) fwrite(tt_ob, 1, bufsize, cc_trace_fp);
- putc(-1, cc_trace_fp);
+ (void) putc(-1, cc_trace_fp);
}
+ tt.tt_flush = 0;
+ (*tt.tt_compress)(1);
if (bufsize < tt.tt_token_min) {
ttflush();
- return;
+ goto out;
}
tt_obp = tt_ob = cc_tt_ob;
tt_obe = cc_tt_obe;
- tt.tt_flush = ttflush;
cc_time0 = cc_time;
cc_time += bufsize;
n = cc_sweep_phase(cc_buffer, bufsize, cc_tokens);
ttflush();
tt_obp = tt_ob = cc_buffer;
tt_obe = cc_buffer + cc_bufsize;
+out:
+ (*tt.tt_compress)(0);
tt.tt_flush = ccflush;
}
register struct cc **output;
struct cc **tokens;
{
- register int i = 0;
register struct cc **pp;
#ifdef STATS
+ register int i = 0;
int nt = 0, cc = 0, nc = 0;
#endif