[Coco] Microware C Compiler port

John W. Linville linville at tuxdriver.com
Tue Jan 20 21:15:08 EST 2009


Doh...forgot the attachments...

On Tue, Jan 20, 2009 at 09:04:08PM -0500, John W. Linville wrote:
> On Fri, Jan 16, 2009 at 08:03:23AM -0500, Steven Hirsch wrote:
> 
> > I sent the compiler sources and binaries to about six people that  
> > contacted me directly, but have heard nothing, nada, zilch, zip..
> >
> > Has anyone tried using it for anything?  Any comments or observations?
> 
> So I went looking for some old K&R sources that I could play with and
> reasonably expect to test on a (emulated) coco.  I decided to try some
> utilities from an old version of Minix (1.1).  The 'wc' utility seemed
> like a reasonable candidate.  I'll attach the slightly modified sources
> I got to work along with the diff from the original Minix sources.
> 
> 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.
> 
> Still, it _is_ cool to compile for OS-9 on my Linux box... :-)
> 
> John
> -- 
> John W. Linville		Linux should be at the core
> linville at tuxdriver.com			of your literate lifestyle.
> 
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
> 

-- 
John W. Linville		Linux should be at the core
linville at tuxdriver.com			of your literate lifestyle.
-------------- next part --------------
/* wc - count lines, words and characters	Author: David Messer */

#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]
 *
 *		Flags:
 *			l - count lines.
 *			w - count words.
 *			c - count characters.
 *
 *		Flags l, w, and c are default.  
 *		Words are delimited by any non-alphabetic character.
 *
 *  Released into the PUBLIC-DOMAIN 02/10/86
 *
 *	If you find this program to be of use to you, a donation of
 *	whatever you think it is worth will be cheerfully accepted.
 *
 *	Written by: David L. Messer
 *				P.O. Box 19130, Mpls, MN,  55119
 *      Program (heavily) modified by Andy Tanenbaum 
 */


int lflag;			/* Count lines */
int wflag;			/* Count words */
int cflag;			/* Count characters */

int lcount;			/* Count of lines */
int wcount;			/* Count of words */
int ccount;			/* Count of characters */

int ltotal;			/* Total count of lines */
int wtotal;			/* Total count of words */
int ctotal;			/* Total count of characters */

main(argc, argv)
int argc;
char *argv[];
{
  int k;
  char *cp;
  int tflag, files;
  int i;

  /* Get flags. */
  files = argc - 1;
  k = 1;
  cp = argv[1];
  if (*cp++ == '-') {
	files--;
	k++;			/* points to first file */
	while (*cp != 0) {
		switch (*cp) {
			case 'l':	lflag++;	break;
			case 'w':	wflag++;	break;
			case 'c':	cflag++;	break;
			default:	usage();
		}
		cp++;
	}
  }

  /* If no flags are set, treat as wc -lwc. */
  if(!lflag && !wflag && !cflag) {
	lflag = 1;
	wflag = 1;
	cflag = 1;
  }

  /* Process files. */
  tflag = files >= 2;		/* set if # files > 1 */

  /* 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);
	printf(" \n");
	fflush(stdout);
	exit(0);
  }

  /* There is an explicit list of files.  Loop on files. */
  while (k < argc) {
	fclose(stdin);
	if (fopen(argv[k], "r") == NULL) {
		std_err("wc: cannot open ");
		std_err(argv[k]);
		std_err("\n");
		k++;
		continue;
	} 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);
		printf(" %s\n", argv[k]);
	}
	k++;
  }

  if(tflag) {
	if(lflag) printf(" %6d", ltotal);
	if(wflag) printf(" %6d", wtotal);
	if(cflag) printf(" %6d", ctotal);
	printf(" total\n");
  }

  fflush(stdout);
  exit(0);
}

count()
{
  register int c;
  register int word = 0;

	lcount = 0;
	wcount = 0;
	ccount = 0;

  while((c = getc(stdin)) > 0) {
	ccount++;

	if(isspace(c)) {
		if(word) wcount++;
		word = 0;
	} else {
		word = 1;
	}

	if (c == '\n' || c == '\f') lcount++;
  }
  ltotal += lcount;
  wtotal += wcount;
  ctotal += ccount;
}

usage()
{
  std_err("Usage: wc [-lwc] [name ...]\n");
  exit(1);
}


-------------- next part --------------
--- minix/commands/wc.c	1987-01-02 04:16:15.000000000 -0500
+++ wc.c	2009-01-20 20:50:19.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]
@@ -31,13 +37,13 @@ int lflag;			/* Count lines */
 int wflag;			/* Count words */
 int cflag;			/* Count characters */
 
-long lcount;			/* Count of lines */
-long wcount;			/* Count of words */
-long ccount;			/* Count of characters */
-
-long ltotal;			/* Total count of lines */
-long wtotal;			/* Total count of words */
-long ctotal;			/* Total count of characters */
+int lcount;			/* Count of lines */
+int wcount;			/* Count of words */
+int ccount;			/* Count of characters */
+
+int ltotal;			/* Total count of lines */
+int wtotal;			/* Total count of words */
+int ctotal;			/* Total count of characters */
 
 main(argc, argv)
 int argc;
@@ -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", lcount);
+	if(wflag) printf(" %6d", wcount);
+	if(cflag) printf(" %6d", 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", lcount);
+		if(wflag) printf(" %6d", wcount);
+		if(cflag) printf(" %6d", 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", ltotal);
+	if(wflag) printf(" %6d", wtotal);
+	if(cflag) printf(" %6d", ctotal);
 	printf(" total\n");
   }
 
@@ -125,7 +131,7 @@ count()
 
 	lcount = 0;
 	wcount = 0;
-	ccount = 0L;
+	ccount = 0;
 
   while((c = getc(stdin)) > 0) {
 	ccount++;


More information about the Coco mailing list