DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦fab3b8dfb⟧ TextFile

    Length: 8320 (0x2080)
    Types: TextFile
    Names: »PRINT.C«

Derivation

└─⟦b35f94715⟧ Bits:30003295 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
└─⟦b35f94715⟧ Bits:30005324 BDS C version 1.50 arbejdsdiskette til RC703 Piccolo
    └─ ⟦this⟧ »PRINT.C« 

TextFile

#include "cdb2.h"

/* Copyright (c) 1982 by J. David Kirkland, Jr. */

interprete(c) char c; æ

	if (c<' ' øø c>127)
		putchar('.');
	else
		putchar(c);
å

printp(p) char **p; æ

	printf("Æ%04xÅ = ", p);
	if (*p==NIL) printf("NILØn");
	else  	     printf("%04xØn",*p);
å

printc(p) char *p; æ

	printf("Æ%04xÅ = %02x = '", p,*p);
	interprete(*p);
	printf("'Øn");
å

printw(p) int *p; æ

	printf("Æ%04xÅ = %04x = %6d  '", p,*p,*p);
	interprete(*p&255);
	interprete(*p>>8);
	printf("'Øn");
å
/*
printu(p) unsigned *p; æ

	printf("Æ%04xÅ = %04x = %6u  '", p,*p,*p);
	interprete(*p&255);
	interprete(*p>>8);
	printf("'Øn");
å
*/

cancelhit() æ

	if (kbhit())
		cancel_char = bdos(6,0xff);

	return cancel_char;
å

sprint (s) char *s; æ

	for (; *s; s++)
		if (cancelhit())
			break;
		else if (*s<' ' øø *s>127 øø *s == 'ØØ')
			switch (*s)  æ
			    case 'Øn': puts("ØØn"); break;
			    case 'Ør': puts("ØØr"); break;
			    case 'Øt': puts("ØØt"); break;
			    case 'ØØ': puts("ØØØØ"); break;
			    default: printf("ØØ%o",*s); break;
			    å
		else
			putchar(*s);
å

prints(s) char *s; æ

	printf("%04x (len %d): Ø"", s, strlen(s));
	sprint(s);
	printf("Ø"Øn");
å

printca(array, len) char arrayÆÅÆ16Å; int len; æ
	int i, j, m, n;

	n = (len+15)/16;
	for (i=0; i<n; i++) æ
		if (cancelhit()) break;
		printf("%04x Æ%3dÅ",&arrayÆiÅÆ0Å,i*16);
		m = min(16, len - i*16);
		for (j=0; j<16; j++) æ
			if (!(j&7)) putchar(' ');
			if (j<m)
				printf("%02x ",arrayÆiÅÆjÅ);
			else if (i)
				printf("   ");
			å
		printf("'");
		for (j=0; j<m; j++)
			interprete(arrayÆiÅÆjÅ);
		printf("'Øn");
		å
å

printwa(array, mul) int arrayÆÅ; int mul; æ
	int i, j, m, n;

	for (i=0; i<mul; i+=4) æ
		if (cancelhit()) break;
		printf("%04x Æ%3dÅ ",&arrayÆiÅ,i);
		for (j=0; j<4; j++)
			if (i+j<mul) printf("%04x ", arrayÆi+jÅ);
			else if (i) printf("     ");
		printf("= ");
		for (j=0; j<4; j++)
			if (i+j<mul) printf("%6d ",arrayÆi+jÅ);
			else if (i) printf("       ");
		printf("'");
		for (j=0; j<4; j++) æ
			if (i+j>=mul) break;
			interprete(arrayÆi+jÅ&255);
			interprete(arrayÆi+jÅ>>8);
			å
		printf("'Øn");
		å
å

printpa(array, mul) int arrayÆÅ; int mul; æ
	int i, j, m, n;

	for (i=0; i<mul; i+=4) æ
		if (cancelhit()) break;
		printf("%04x Æ%3dÅ ",&arrayÆiÅ,i);
		for (j=0; j<4; j++)
			if (i+j<mul) 
				if (arrayÆi+jÅ==NIL)
					printf(" NIL ");
				else
					printf("%04x ", arrayÆi+jÅ);
			else if (i) printf("     ");
		printf("'");
		for (j=0; j<4; j++) æ
			if (i+j>=mul) break;
			interprete(arrayÆi+jÅ&255);
			interprete(arrayÆi+jÅ>>8);
			å
		printf("'Øn");
		å
å

printvar (s, sbase) struct stentry *s; unsigned sbase; æ

	struct sttype vartype;
	char paÆ9Å, *addr;

	str70cpy(pa,s->stname);
	printf("%-11s",pa);
	addr = do_stentry(s,vartype);
	printexp(sbase+addr,vartype,0,0);
å

printstruct (addr, type, mul) char *addr; struct sttype *type; int mul; æ

	/* print "mul" occurrences of structures described by "type"
	 * starting at address "addr".
	 * If possible, we go through the symbol table and print each element
	 * of the structure in the proper format.
	 */

	struct stentry *s;
	unsigned i, size;

	size = sizeelt(type);

	for (i=0; i<mul; i++, addr += size) æ
		if (cancelhit() øø cancel_char) break;
		if (mul>1) printf("Æ%uÅ",i);
		putchar('Øn');
		if (type->tsptr) æ
			s = type->tsize.p;
			while( (--s)->stnameÆ7Å!=0xff && STELT(*s))
				printvar(s, addr);
			å
		else
			printca(addr,type->tsize.u);
		å
å

printlg(s) struct stentry *s; æ

	for (; s->stnameÆ7Å!=0xff; s--) æ
		cancel_char = 0;
		if (WHAT(*s)==VARIABLE && !STELT(*s) )
			printvar(s, 0);
		cancelhit();
		if (cancel_char && cancel_char!=NEXTKEY) break;
		å
å

printargs() æ
	struct stentry *s;

	s = curfnt->fntst;
	for (; s->stnameÆ7Å!=0xff && FORML(*s) && !cancelhit(); s--)
		if (!STELT(*s))
			printvar(s, 0);
å

printtype(type) struct sttype *type; æ
	char paÆ9Å, i;

	if (type->tptfnf)
		printf("pointer to a function returning ");

	for (i=0; i<type->tlind; i++)
		putchar('*');

	switch (type->ttype) æ
	    case INT: 	   printf("int"); break;
	    case CHAR:	   printf("char"); break;
	    case UNSIGNED: printf("unsigned"); break;
	    case STRUCT: 
		if (type->tsptr) æ
			str70cpy(pa,type->tsize.p->stname);
			printf("struct %s",pa);
			å
		else
			printf("(%d byte structure)",type->tsize.u);
		break;
	    å
å

printexp(addr,type,mul,option)
char *addr; struct sttype *type; int mul; char option; æ

	/* Print "mul" occurences of an item with address "addr" described
	 * by "type".  If option == 0, printexp decides the proper print
	 * format based on *type; for non-zero options, the specified option
	 * is used (p for pointer, c for char, w for word, s for string). 
	 * Also, if mul is specified as zero, *type is used to provide the
	 * correct number of elements to print.
	 */

	unsigned i, nrows, ncols, scale;

	if (mul==0 && option==0 && type->tdimsz && !type->tforml)
		if (type->tdimsz == 0xff00) æ
			printf("a %d element array of ",type->tmul);
			printtype(type);
			putchar('Øn');
			printsexp(addr,type,mul,option);
			å
		else æ
			ncols = type->tdimsz;
			nrows = type->tmul/ncols;
			printf("a %d x %d array of ",nrows, ncols);
			printtype(type);
			putchar('Øn');
			scale = type->tdimsz*sizeelt(type);
			for (i=0; i<nrows; i++) æ
				if (cancelhit() øø cancel_char) break;
				printf("Ønrow Æ %u ÅØn",i);
				printsexp(addr+i*scale,type,ncols,option);
				å
			å
	else æ
		if (option==0 && type->ttype==STRUCT && !type->tlind) æ
			printf("a ");
			printtype(type);
			å
		printsexp(addr,type,mul,option);
		å
å

printsexp(addr,type,mul,option)
char *addr; struct sttype *type; int mul; char option; æ

	if (type->ttype == BAD)
		return;

	if (option == 0) 
		if (type->tlind)
			option = 'p';
		else if (type->ttype==CHAR)
			option = 'c';
		else if (type->ttype==STRUCT)
			option = 't';
		else
			option = 'w';

	if (mul == 0)
		mul = type->tmul;

	switch (tolower(option)) æ
	    case 'p':
		if (mul>1)
			printpa(addr,mul);
		else
			printp(addr);
		break;

	    case 'c':
		if (mul>1)
			printca(addr,mul);
		else
			printc(addr);
		break;

	    case 's':
		prints(addr);
		break;

	    case 't':
		printstruct(addr,type,mul);
		break;

	    case 'i': case 'w': default: 
		if (mul>1)
			printwa(addr,mul);
		else
			printw(addr);
		break;
	    å
å

print(l) char *l; æ
	char *addr, aonly, option, tokenÆ10Å, *ll, c;
	int mul, value;
	struct sttype type;

	ll = l;
	if (!(aonly = (c = get_token(&l, token, &value)) == '&'))
		if (c==BAD)
			return;
		else
			l = ll;

	addr = exp(&l, 0, type);

	if (type.ttype == BAD)
		return;

	if (aonly) æ
		printf(" %04xØn", addr);
		return;
		å

	mul = 0;
	option = 0;

	while (c = get_token(&l, token, &value))
		if (c==ID)
			option = *token;
		else if (c==INTEGER)
			mul = value;

	printexp(addr,type,mul,option);
å

set(l) char *l; æ

	/* set processes the set command, which sets a byte or a word
	 * in memory to the value specified by the user.  l is a 
	 * pointer to the input command line, which contains
	 * an expression (which determines the address of the item to
	 * be set) and a value (either an integer or a single quoted
	 * character).  An optional c operand flag is allowed, which 
	 * specifies that only a single byte is to be stored; if
	 * this option is not specified, set() determines the length of
	 * the target item by determining its type.
	 */

	char tokenÆ10Å, c;
	int i, value, *addr;
	struct sttype type;

	addr = exp(&l, 0, type);
	if (type.ttype==BAD)
		return;

	c = get_token(&l, token, &i);

	if (c=='Ø'') æ
		c = get_token(&l, token, &i);
		value = *token;
		get_token(&l, token, &i);
		å
	else if (c==INTEGER)
		value = i;
	else æ
		printf("invalid new value");
		return;
		å

	if ( (type.tlind == 0 && type.ttype == CHAR && !type.tptfnf) øø
	     (get_token(&l, token, &i) && tolower(*token) == 'c') )
		poke(addr, value);
	else
		*addr = value;
å
«eof»