🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #2636

putchar() getchar() problem?

#2636
From: Mike Whitbeck
Date: Wed, 26 Jul 1989 21:43
74 lines
2431 bytes
HELP ! 
I seem to get extra \r's from putchar()!!!! (or getchar()?)
I am using MWC 3.0 to port BR's splay compression program to the
ST. The program works fine under UNIX(SUN) and IDRIS (PE7300)
but on the ST I get extra 0x0D's (\r) in the output!
I put a counter in bit_output() immediately after the putchar()
(see below) and the loop is executed the correct no. of
times (e.g. N times but the file written contains more than
N bytes the extra bytes are 0x0D's).

[ To get the unsplay program to work I had to replace getchar()
with Cnecin(). Typically
	splay < rawbinary > splaycompressed
	unsplay < splaycompressed > rawbinary 
This makes for smaller files than unix compress when working
with raw binary (poorer performance with ASCII files). ]
{I am using Mark William's C 3.0 and their msh.prg (a shell)}.

WHAT'S WRONG?
-------------------partial listing------------------------
/*
    Splay Tree Compression

    from: "Application Of Splay Trees To Data Compression"
          by Douglas W. Jones, Communications of the ACM, August 1988

    implemented in C by Bodo Rueskamp, <br@unido.uucp>
*/

/*  splay tree compress  */

#include <stdio.h>

int left[257], right[257], up[514];

static int bitnum = 0;

void bit_output(bit)
int bit;
{
	static int byte = 0;

	byte = (byte << 1) | bit;
	++bitnum;
	if (bitnum == 8) {
		putchar(byte); <--------- main output from here

/* a counter placed here indicates the correct no. of passes
through this loop, the bytes written are also correct except for
a few extra 0x0D's interspersed */

		byte = 0;
		bitnum = 0;
	}
}

...

	stuff deleted for brevity
...

main()
{
	int c;

	putchar(0x1f); <------ magic number  ok
	putchar('S'); <------ magic number  ok
	initialize();
	while ((c = getchar()) != EOF)
		compress(c); <----- calls bit_output() to write
				compressed data to stdout
	..... stuff deleted....
	return(0);
}
Technical Details
Message-ID: <2829@tahoe.unr.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!tahoe!wheeler!mikew

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!tahoe!wheeler!mikew
From: mikew@wheeler.wrcr.unr.edu (Mike Whitbeck)
Newsgroups: comp.sys.atari.st
Subject: putchar() getchar() problem?
Summary: problem with extra 0x0D chars written under MWC
Keywords: extra CR's, MWC
Message-ID: <2829@tahoe.unr.edu>
Date: 26 Jul 89 21:43:58 GMT
Sender: news@tahoe.unr.edu
Reply-To: mikew@wheeler.UUCP (Mike Whitbeck)
Distribution: usa
Organization: DRI-WRC Reno
Lines: 74