[Coco] Microware C Compiler port

John W. Linville linville at tuxdriver.com
Wed Jan 21 18:53:08 EST 2009


On Wed, Jan 21, 2009 at 07:05:23AM -0500, Steven Hirsch wrote:
> On Tue, 20 Jan 2009, John W. Linville wrote:

>> Some of the changes are simple, such as changing "%6D" to "%6d",
>> implementing a utility function ("sig_err"), and fixing an actual
>> syntax error.  That was enough to get the program basically running,
>> but it was producing 0 counts for lines, words, and characters.
>>
>> The original sources had those count vars defined as long.  Changing
>> them to int yielded correct results, except that it doesn't take much
>> to overflow the character count... :-(
>>
>> Did this compiler have problems with long in the original OS-9/6809
>> version?  It is bad enough to not handle long, but to compile it
>> without complaint and simply not work seems rather  wrong.  FWIW,
>> changing to 'long int' didn't change anything.

So it turns-out that leaving the vars declared as long and simply
casting them to int in the printf arguments yields the same results
as simply declaring them as int in the first place.  To me this
suggests that the basic code generation for the long type is working.
Perhaps there is some different conversion format needed for the
Microware printf to handle long?

>> Still, it _is_ cool to compile for OS-9 on my Linux box... :-)
>
> Thanks, John.  The feedback is appreciated.  I'm going to gather input 
> and hopefully work on a more refined release for the near future.

Sounds great.  I'd love to hear about your future plans.

John

P.S.  New diff from the original Minix sources inlined below...

--- minix/commands/wc.c	1987-01-02 04:16:15.000000000 -0500
+++ wc.c	2009-01-21 18:47:27.000000000 -0500
@@ -1,9 +1,15 @@
 /* wc - count lines, words and characters	Author: David Messer */
 
-#include "stdio.h"
-#define isdigit(c) (c >= '0' && c <= '9)
+#include <stdio.h>
+#define isdigit(c) (c >= '0' && c <= '9')
 #define isspace(c) (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
 
+std_err(str)
+char *str;
+{
+	fprintf(stderr, "%s", str);
+}
+
 /*
  *
  *	Usage:  wc [-lwc] [names]
@@ -79,9 +85,9 @@ char *argv[];
   /* Check to see if input comes from std input. */
   if (k >= argc) {
 	count();
-	if(lflag) printf(" %6D", lcount);
-	if(wflag) printf(" %6D", wcount);
-	if(cflag) printf(" %6D", ccount);
+	if(lflag) printf(" %6d", (int)lcount);
+	if(wflag) printf(" %6d", (int)wcount);
+	if(cflag) printf(" %6d", (int)ccount);
 	printf(" \n");
 	fflush(stdout);
 	exit(0);
@@ -99,18 +105,18 @@ char *argv[];
 	} else {
 		/* Next file has been opened as std input. */
 		count();
-		if(lflag) printf(" %6D", lcount);
-		if(wflag) printf(" %6D", wcount);
-		if(cflag) printf(" %6D", ccount);
+		if(lflag) printf(" %6d", (int)lcount);
+		if(wflag) printf(" %6d", (int)wcount);
+		if(cflag) printf(" %6d", (int)ccount);
 		printf(" %s\n", argv[k]);
 	}
 	k++;
   }
 
   if(tflag) {
-	if(lflag) printf(" %6D", ltotal);
-	if(wflag) printf(" %6D", wtotal);
-	if(cflag) printf(" %6D", ctotal);
+	if(lflag) printf(" %6d", (int)ltotal);
+	if(wflag) printf(" %6d", (int)wtotal);
+	if(cflag) printf(" %6d", (int)ctotal);
 	printf(" total\n");
   }
 
-- 
John W. Linville		Linux should be at the core
linville at tuxdriver.com			of your literate lifestyle.



More information about the Coco mailing list