Digital Research
This commit is contained in:
2020-11-06 18:50:37 +01:00
parent 621ed8ccaf
commit 31738079c4
8481 changed files with 1888323 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
/*
* C library -- alloc/free
*/
#define logical char *
struct fb {
logical size;
char *next;
};
int _freelist[] {
0,
-1,
};
logical _slop 4;
char *
malloc(asize)
logical asize;
{
register logical rsize;
register logical np;
register logical cp;
if ((rsize = asize) == 0)
return(-1);
rsize += 3;
rsize = _andptr(rsize,~01);
for (;;)
{
for (cp=_freelist; (np= cp->next) != -1; cp=np)
{
if (np->size >= rsize)
{
if (_addptr(rsize,_slop) >= np->size)
{
cp->next = np->next;
return(&np->next);
}
cp = cp->next = _addptr(np , rsize);
cp->size = np->size - rsize;
cp->next = np->next;
np->size = rsize;
return(&np->next);
}
}
asize = (rsize < 1024) ? 1024: rsize;
if ((cp = sbrk(asize)) == -1)
{
return (-1);
}
cp->size = asize;
free(&cp->next);
}
}
free(aptr)
char *aptr;
{
register logical ptr;
register logical cp;
register logical np;
ptr = aptr-4;
cp = _freelist;
while ((np = cp->next) < ptr)
cp = np;
if (_addptr(ptr,ptr->size) == np)
{
ptr->size = _addptr(ptr->size,np->size);
ptr->next = np->next;
np = ptr;
}
else
ptr->next = np;
if (_addptr(cp,cp->size) == ptr)
{
cp->size = _addptr(cp->size,ptr->size);
cp->next = ptr->next;
}
else
cp->next = ptr;
}
/* Fudge routines */
_addptr (a,b)
{
return(a+b);
}
_andptr (a,b)
{
return(a&b);
}

View File

@@ -0,0 +1,11 @@
$ set noon
$ cp68 :== $bin:c68.exe
$ c068 :== $bin:c068.exe
$ c168 :== $bin:c168.exe
$ as68 :== $bin:as68.exe
$ lo68 :== $bin:lo68.exe
$ cp68 -i lib: 'p1'.c 'p1'.i
$ c068 'p1'.i 'p1'.ic 'p1'.st
$ c168 'p1'.ic 'p1'.s -L
$ as68 -l -u 'p1'.s
$ delete 'p1'.s;*,'p1'.ic;*,'p1'.i;*,'p1'.st;*

View File

@@ -0,0 +1,12 @@
#define OUTSTR 9
#define EXIT 0
char mesg[] = {"Hello, Steve\r\n$"};
_main()
{
__BDOS(OUTSTR,&mesg[0]);
}
exit()
{
__BDOS(EXIT,0L);
}

View File

@@ -0,0 +1,79 @@
/*
* COMDEX El-kludgo display program.
*
* disp file d
*
* Where "file" is a text file containing 24 x 80 pages, delineated by
* "`" characters. "d" is the number of seconds to delay.
*
*/
#include <stdio.h>
main(argc,argv)
WORD argc;
BYTE **argv;
{ /****************************/
BYTE buffer[2048]; /* Buffer for screen text */
REG FILE *ifp; /* Input file pointer */
REG WORD delay; /* Delay for pages */
REG BYTE c; /* Character temporary */
REG WORD i,k,l; /* Count temporary */
/****************************/
if(argc != 3) /* Check the arg count */
{ /* */
printf("Bad Argument count\n"); /* Give error */
exit(); /* Quit */
} /****************************/
/* */
if((ifp=fopen(argv[1],"r")) <= 0) /* Open Input */
{ /* */
printf("Cannot open %s\n",argv[1]); /* Give error */
exit(); /* Quit in disgust */
} /* */
/****************************/
delay=atoi(argv[2]); /* Convert delay quantity */
if(delay < 0 || delay > 10000) /* Range check */
{ /* */
printf("Illegal delay = %d\n",delay); /* Print delay nfg */
exit(); /* Quit */
} /****************************/
/* */
while(1) /* Always */
{ /* */
i = 0; /* Subscript init */
c = 1; /* Initialize char */
while(c != '`' && c > 0) /* While c in page & not EOF*/
{ /****************************/
c = getc(ifp); /* Read next character */
buffer[i++] = c; /* Put next character in buf*/
} /****************************/
i--; /* Decrement count back to 0*/
l = 0; /* Initially no lfs in buff */
for(k=0; k <= i; k++) /* Count line feeds */
if(buffer[k] == '\n') l++; /* L = # line feeds */
k = 23 - l; /* K = # line feeds desired */
write(1,buffer,i); /* Write buffer to stdout */
while(k-- > 0) /* Until loop exhausted */
write(1,"\n",1); /* Print new line */
loop(delay); /* Do the delay */
/****************************/
if(feof(ifp)) /* Check for EOF */
fseek(ifp,0L,0); /* Seek back to beginning */
} /****************************/
}
clear()
{ /****************************/
REG WORD i; /* Loop counter */
for(i=0;i<24;i++) /* loop on lines */
printf("\n"); /* Write a newline */
} /****************************/
loop(delay) /* Delay loop */
WORD delay; /* # counts */
{ /****************************/
REG WORD i; /* Inner loop count */
while(delay > 0) /****************************/
{ /* */
for (i = 0; i < 10000; i++); /* Do nothing */
delay--; /* Down count */
} /****************************/
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include <setjmp.h>
jmp_buf env;
main()
{
WORD i; /* Temp */
if((i=setjmp(env))) /* only for the longjump return */
{
printf("Longjmp returns %d\n",i);
exit();
}
b();
}
b()
{
longjmp(env,12);
}

View File

@@ -0,0 +1 @@
int junk;

View File

@@ -0,0 +1 @@
int junk1;

View File

@@ -0,0 +1,8 @@
all:
cc -O -d2 ed.c -o ed
install:
mv ed ${DESTDIR}/bin/ed
rm -f ${DESTDIR}/bin/e
ln ${DESTDIR}/bin/ed ${DESTDIR}/bin/e
clean:
rm -f ed

View File

@@ -0,0 +1,57 @@
#include <stdio.h>
#define MIN 1
#define MAX 50
#define MAXPART 175
main()
{
int *p;
int i;
int j;
int k;
int *q;
int *a[MAXPART];
int pass;
pass = 0;
k = 0;
while(1)
{
for(i = MIN; i < MAX; i++)
{
p = malloc(i*sizeof(int)); /* Gettum buffer */
if(p == NULL)
{
printf("Allocation fails %d blocks\n",k);
exit();
}
for (j = 0; j < i; j++) /* Fill buffer */
{
p[j] = j; /* Set up pattern */
}
q = realloc(p,i*sizeof(int) + 200);
if(q==NULL)
{
printf("Realloc out of room size = %d k = %lx\n",i,k);
exit();
}
for (j = 0; j < i; j++)
{
if(q[j] != j) /* OOPS!! */
{
printf("Realloc fails addr=%lx size = %d\n",q,i);
exit();
}
}
if(k >= MAXPART)
{
for(k=0; k < MAXPART; k++)
free(a[k]);
k = 0;
}
a[k++] = q;
}
printf("Pass %d\n",++pass);
}
}

View File

@@ -0,0 +1,21 @@
#include <stdio.h>
#include <signal.h>
main()
{
int illegal();
int buserr();
signal(SIGIOT,&illegal);
signal(SIGBUS,&buserr);
xbarf();
printf("Return OK\n");
}
illegal()
{
printf("Trap instruction\n");
}
buserr()
{
printf("Bus error exception\n");
}

View File

@@ -0,0 +1,68 @@
/*****************************************************************************
*
* C P / M C H E A D E R F I L E
* -----------------------------------
* Copyright 1982 by Digital Research Inc. All rights reserved.
*
* This is the standard include file for the CP/M C Run Time Library.
*
*****************************************************************************/
/* */
#include <portab.h> /* Portability Definitions */
/* */
/****************************************************************************
* Stream I/O File Definitions
*****************************************************************************/
#define BUFSIZ 512 /* Standard (ascii) buf size */
#define MAXFILES 16 /* Max # open files ( < 32 ) */
struct _iobuf { /* */
WORD _fd; /* file descriptor for low level io */
WORD _flag; /* stream info flags */
BYTE *_base; /* base of buffer */
BYTE *_ptr; /* current r/w pointer */
WORD _cnt; /* # chars to be read/have been wrt */
}; /* */
#ifndef FILE /* conditionally include: */
extern struct _iobuf _iob[MAXFILES]; /* an array of this info */
#define FILE struct _iobuf /* stream definition */
#endif /************************************/
/* flag byte definition */
#define _IOREAD 0x01 /* readable file */
#define _IOWRT 0x02 /* writeable file */
#define _IOABUF 0x04 /* alloc'd buffer */
#define _IONBUF 0x08 /* no buffer */
#define _IOERR 0x10 /* error has occurred */
#define _IOEOF 0x20 /* EOF has occurred */
#define _IOLBUF 0x40 /* handle as line buffer */
#define _IOSTRI 0x80 /* this stream is really a string */
#define _IOASCI 0x100 /* this was opened as an ascii file */
/************************************/
#define stdin (&_iob[0]) /* standard input stream */
#define stdout (&_iob[1]) /* " output " */
#define stderr (&_iob[2]) /* " error " */
/************************************/
#define clearerr(p) ((p)->_flag & ~_IOERR) /* clear error flag */
#define feof(p) ((p)->_flag & _IOEOF) /* EOF encountered on stream */
#define ferror(p) ((p)->_flag & _IOERR) /* error encountered on stream */
#define fileno(p) ((p)->_fd) /* get stream's file descriptor */
#define getchar() getc(stdin) /* get char from stdin */
#define putchar(c) putc(c,stdout) /* put char to stdout */
#define putc fputc
#define getc fgetc
/****************************************************************************/
/* */
/* M A C R O S */
/* ----------- */
/* */
/* Define some stuff as macros .... */
/* */
/****************************************************************************/
#define abs(x) ((x) < 0 ? -(x) : (x)) /* Absolute value function */
#define max(x,y) (((x) > (y)) ? (x) : (y)) /* Max function */
#define min(x,y) (((x) < (y)) ? (x) : (y)) /* Min function */
/*************************** end of stdio.h *********************************/

View File

@@ -0,0 +1,15 @@
#define INCR 100
main()
{
char *blivot[100];
extern char *_break;
extern char *sbrk();
int i;
printf("Original: %lx\n",_break);
for(i=0; i<100; i++)
{
blivot[i] = sbrk(INCR);
printf("i = %3d sbrk=%lx\n",i,blivot[i]);
}
}

View File

@@ -0,0 +1,248 @@
/*************************************************************************/
/* */
/* This program tests : fopen,printf,fclose,gets,puts, */
/* fgets,fputs,freopen . */
/* Written 8/4/82 for C run-time library. FMB */
/* */
/*************************************************************************/
#include <stdio.h> /* Has stdin,BYTE,etc.*/
#define CREATF "w" /* To create a file */
#define RO "r" /* To reopen a RO file */
#define APPMODE "a" /* To append to a file */
#define ASCYES 0 /* For ascii files */
#define BINARY 1 /* For binary files */
#define BUFFMAX 100 /* Maximum buffer length */
#define LINSIZ 256 /* Input file name */
#define MAXFILES 16 /* Max number of files open */
main()
{
FILE *filarray[MAXFILES + 4];
FILE *fp,*fp2,*temp; /* Pointers to open files */
BYTE *testbuff,*echobuff; /* Mem buffers for io */
WORD returnw; /* Function value */
BYTE returnb; /* Function value */
WORD maxchars = 80; /* Default mem buffer size */
LONG cursor = 0; /* # bytes in stream of file.*/
BYTE i; /* loop counter */
BYTE fname[LINSIZ] ; /* For user file name */
printf("\n\n *************************************************\n\n");
printf(" Begin C run-time test #1. \n\n");
printf(" *************************************************\n");
/***********************************************************************/
/* This section tests memory allocation. */
/***********************************************************************/
/* Allocate buffer space */
printf("\nTesting memory allocation...........................\n");
testbuff = malloc(BUFFMAX); echobuff = malloc(BUFFMAX);
/* Test for malloc o.k. */
if ((testbuff || echobuff) == NULL)
printf("Malloc didn't make it. Stop here.\n");
/***********************************************************************/
/* This section tests Fopen. */
/***********************************************************************/
printf("Testing maximum open and reopen....................\n");
opnall(filarray); /* Open every file */
printf("Opened all.\n");
reopnall(filarray); /* Reopen as binary*/
printf("Reopened all.\n");
dotwo(filarray); /* Release two of them */
printf("Closed two.\n");
/* Open file to start */
printf("Opening first file...................................\n");
/* Test fopen with a string filename. */
fp = fopen("George",CREATF,ASCYES) ;
if (fp == NULL) printf("Couldn't get fopen to work on #1.\n ");
/* Test for standard input filename with fopen.*/
printf("Opening second file. Please enter a new filename.\n");
gets(fname); /* Get name from stdin */
fp2 = fopen(fname,CREATF,ASCYES);
if (fp2 == NULL) printf("#2 fopen didn't work.\n");
/***********************************************************************/
/* This section tests Gets and Puts. */
/***********************************************************************/
/* Test for gets and puts . Simple echo first */
printf("\nNow please enter a string ending with a CR.\n");
if (gets(testbuff) == NULL) printf("Gets didn't make it.\n");
else {printf("Echoing ......\n");
returnw = puts(testbuff);
}
/***********************************************************************/
/* This section tests Fputs, Fgets, and Freopen. */
/***********************************************************************/
/* Test for fputs and fgets. */
/* Put something in George's stream.*/
printf("Testing Fputs........................\n");
if (fputs(testbuff,fp) == NULL) /* Check for error in Fputs */
printf("\nFputs didn't work.\n");
/* Else,o.k. to test the other stuff.*/
else
{
fp = freopen("George",RO,fp,ASCYES); /* So we can read */
fgets(testbuff,maxchars,fp); /* Move stream to buffer*/
fputs(testbuff,stdout); /* Move buffer to screen*/
printf("\nPlease enter 3 complete lines of text .Do not use ctr Z .\n");
/* After this loop,all 3 lines should be in the stream,*/
/* only last line typed should be in the memory buffer.*/
for (i = 0; i < 3 ; i++)
{
fgets(echobuff,maxchars,stdin);/* From terminal to memory buffer.*/
fputs(echobuff,fp2); /* From buffer to stream.*/
}
printf("\nTesting to see if all 3 lines are in file stream.\n");
fp2 = freopen(fname,RO,fp2,ASCYES);
for (i = 0; i < 3; i++)
{
fgets(testbuff,maxchars,fp2);/* Move stream to buffer*/
fputs(testbuff,stdout); /* Move buffer to screen*/
}
returnw = rewind(fp); /* So we can read from the top */
fgets(echobuff,maxchars,fp);/* Should give first line in George */
printf("\nTesting Fseek ,Freopen and Fputs............\n");
fp2 = freopen(fname,APPMODE,fp2,ASCYES);/* So we can add it */
returnw = fseek(fp2,cursor,2); /* Go to EOF for append*/
if (fputs(echobuff,fp2) == FAILURE )
printf("\nLast line append didn't work.\n");
printf("\nTesting puts and fputs...................\n");
fp2 = freopen(fname,RO,fp2,ASCYES);/* So we can read from it */
fgets(echobuff,BUFFMAX,fp2); /* Move some of file into buffer.*/
printf("\n");
puts(echobuff); /* First echo.*/
printf("\n");
fputs(echobuff,stdout); /* Second echo.*/
printf("\nThat should've been the first line of three.\n");
}
/*********************************************************************/
/* This section tests Fclose. */
/*********************************************************************/
printf("Testing Fclose.................................\n"); /* Test for fclose . */
if (fclose(fp) < 0) printf("Couldn't close first file.\n");
if (fclose(fp2) < 0) printf("Couldn't close the second file.\n");
printf("Testing some illegal file closes......................\n");
/* Now try some illegal fcloses. */
printf("We\'ll call fclose on a file that\'s already been closed.\n");
returnw = fclose(fp); /* This one's already been closed. */
printf("Return val should be -1. It is %d .\n",returnw);
/* The following test results in a compiler error, as */
/* fclose does not check for declared-but-not-defined arg's. */
/* It has been commented out for obvious reasons. */
/* returnw = fclose(temp); No such file. */
/* printf("Retval should be -1. It is %d .\n",returnw); */
printf("\n And that's all for this test. Bye ....................\n");
}
/****************************/
/* Function Openall opens */
/* maximum # of files */
/****************************/
opnall(filist)
FILE *filist[ ];
{
BYTE i, alpha[2];
alpha[1] = '\0';
for (i=3 ; i != MAXFILES ; i++)
{
alpha[0] = 'a' + i;
filist[i] = fopena(alpha,CREATF);
if (filist[i] == NULL)
printf("\nFile # %s was not opened.\n",alpha);
}
}
/***************************/
/* Reopenall reopens max # */
/***************************/
reopnall(filist)
FILE *filist[ ];
{
BYTE i,alpha[2];
alpha[1] = '\0';
for (i = 3 ; i != MAXFILES ; i++)
{
if (filist[i] != NULL)
{
alpha[0] = 'a' + i;
filist[i] = freopen(alpha,RO,filist[i]);
}
else
printf("\nFile # %s not reopened correctly.\n",alpha);
}
}
/**************************/
/* Dotwo closes 2 files */
/* so they can be used */
/* for further testing. */
/**************************/
dotwo(filist)
FILE *filist[ ];
{
if (filist[4] != NULL)
{
if (fclose(filist[4]) == FAILURE)
printf("\nCouldn\'t close file # d .\n");
}
else
printf("\n File #3 was NULL.\n");
if (filist[5] != NULL)
{
if (fclose(filist[5]) == FAILURE)
printf("\nCouldn\'t close file # e .\n");
}
else
printf("\nFile #4 was NULL.\n");
}

View File

@@ -0,0 +1,248 @@
/*************************************************************************/
/* */
/* This program tests : fopen,printf,fclose,gets,puts, */
/* fgets,fputs,freopen . */
/* Written 8/4/82 for C run-time library. FMB */
/* */
/*************************************************************************/
#include <stdio.h> /* Has stdin,BYTE,etc.*/
#define CREATF "w" /* To create a file */
#define RO "r" /* To reopen a RO file */
#define APPMODE "a" /* To append to a file */
#define ASCYES 0 /* For ascii files */
#define BINARY 1 /* For binary files */
#define BUFFMAX 100 /* Maximum buffer length */
#define LINSIZ 256 /* Input file name */
#define MAXFILES 16 /* Max number of files open */
main()
{
FILE *filarray[MAXFILES + 4];
FILE *fp,*fp2,*temp; /* Pointers to open files */
BYTE *testbuff,*echobuff; /* Mem buffers for io */
WORD returnw; /* Function value */
BYTE returnb; /* Function value */
WORD maxchars = 80; /* Default mem buffer size */
LONG cursor = 0; /* # bytes in stream of file.*/
BYTE i; /* loop counter */
BYTE fname[LINSIZ] ; /* For user file name */
printf("\n\n *************************************************\n\n");
printf(" Begin C run-time test #1. \n\n");
printf(" *************************************************\n");
/***********************************************************************/
/* This section tests memory allocation. */
/***********************************************************************/
/* Allocate buffer space */
printf("\nTesting memory allocation...........................\n");
testbuff = malloc(BUFFMAX); echobuff = malloc(BUFFMAX);
/* Test for malloc o.k. */
if ((testbuff || echobuff) == NULL)
printf("Malloc didn't make it. Stop here.\n");
/***********************************************************************/
/* This section tests Fopen. */
/***********************************************************************/
printf("Testing maximum open and reopen....................\n");
opnall(filarray); /* Open every file */
printf("Opened all.\n");
reopnall(filarray); /* Reopen as binary*/
printf("Reopened all.\n");
dotwo(filarray); /* Release two of them */
printf("Closed two.\n");
/* Open file to start */
printf("Opening first file...................................\n");
/* Test fopen with a string filename. */
fp = fopen("George",CREATF,BINARY);
if (fp == NULL) printf("Couldn't get fopen to work on #1.\n ");
/* Test for standard input filename with fopen.*/
printf("Opening second file. Please enter a new filename.\n");
gets(fname); /* Get name from stdin */
fp2 = fopen(fname,CREATF,BINARY);
if (fp2 == NULL) printf("#2 fopen didn't work.\n");
/***********************************************************************/
/* This section tests Gets and Puts. */
/***********************************************************************/
/* Test for gets and puts . Simple echo first */
printf("\nNow please enter a string ending with a CR.\n");
if (gets(testbuff) == NULL) printf("Gets didn't make it.\n");
else {printf("Echoing ......\n");
returnw = puts(testbuff);
}
/***********************************************************************/
/* This section tests Fputs, Fgets, and Freopen. */
/***********************************************************************/
/* Test for fputs and fgets. */
/* Put something in George's stream.*/
printf("Testing Fputs........................\n");
if (fputs(testbuff,fp) == NULL) /* Check for error in Fputs */
printf("\nFputs didn't work.\n");
/* Else,o.k. to test the other stuff.*/
else
{
fp = freopen("George",RO,fp,BINARY); /* So we can read */
fgets(testbuff,maxchars,fp); /* Move stream to buffer*/
fputs(testbuff,stdout); /* Move buffer to screen*/
printf("\nPlease enter 3 complete lines of text .Do not use ctr Z .\n");
/* After this loop,all 3 lines should be in the stream,*/
/* only last line typed should be in the memory buffer.*/
for (i = 0; i < 3 ; i++)
{
fgets(echobuff,maxchars,stdin);/* From terminal to memory buffer.*/
fputs(echobuff,fp2); /* From buffer to stream.*/
}
printf("\nTesting to see if all 3 lines are in file stream.\n");
fp2 = freopen(fname,RO,fp2,BINARY);
for (i = 0; i < 3; i++)
{
fgets(testbuff,maxchars,fp2);/* Move stream to buffer*/
fputs(testbuff,stdout); /* Move buffer to screen*/
}
returnw = rewind(fp); /* So we can read from the top */
fgets(echobuff,maxchars,fp);/* Should give first line in George */
printf("\nTesting Fseek ,Freopen and Fputs............\n");
fp2 = freopen(fname,APPMODE,fp2,BINARY);/* So we can add it */
returnw = fseek(fp2,cursor,2); /* Go to EOF for append*/
if (fputs(echobuff,fp2) == FAILURE )
printf("\nLast line append didn't work.\n");
printf("\nTesting fputs and puts....................\n");
fp2 = freopen(fname,RO,fp2,BINARY);/* So we can read from it */
fgets(echobuff,BUFFMAX,fp2); /* Move some of file into buffer.*/
printf("\n");
puts(echobuff); /* First echo.*/
printf("\n");
fputs(echobuff,stdout); /* Second echo.*/
printf("\nThat should've been the first line of three.\n");
}
/*********************************************************************/
/* This section tests Fclose. */
/*********************************************************************/
printf("Testing Fclose.................................\n"); /* Test for fclose . */
if (fclose(fp) < 0) printf("Couldn't close first file.\n");
if (fclose(fp2) < 0) printf("Couldn't close the second file.\n");
printf("Testing some illegal file closes.\n");
/* Now try some illegal fcloses. */
printf("We\'ll call fclose on a file that\'s already been closed.\n");
returnw = fclose(fp); /* This one's already been closed. */
printf("Return val should be -1. It is %d .\n",returnw);
/* The following test results in a compiler error, as */
/* fclose does not check for declared-but-not-defined arg's. */
/* It has been commented out for obvious reasons. */
/* returnw = fclose(temp); No such file. */
/* printf("Retval should be -1. It is %d .\n",returnw); */
printf("\n And that's all for this test. Bye ....................\n");
}
/****************************/
/* Function Openall opens */
/* maximum # of files */
/****************************/
opnall(filist)
FILE *filist[ ];
{
BYTE i, alpha[2];
alpha[1] = '\0';
for (i=3 ; i != MAXFILES ; i++)
{
alpha[0] = 'a' + i;
filist[i] = fopena(alpha,CREATF);
if (filist[i] == NULL)
printf("\nFile # %s was not opened.\n",alpha);
}
}
/***************************/
/* Reopenall reopens max # */
/***************************/
reopnall(filist)
FILE *filist[ ];
{
BYTE i,alpha[2];
alpha[1] = '\0';
for (i = 3 ; i != MAXFILES ; i++)
{
if (filist[i] != NULL)
{
alpha[0] = 'a' + i;
filist[i] = freopen(alpha,RO,filist[i]);
}
else
printf("\nFile # %s not reopened correctly.\n",alpha);
}
}
/**************************/
/* Dotwo closes 2 files */
/* so they can be used */
/* for further testing. */
/**************************/
dotwo(filist)
FILE *filist[ ];
{
if (filist[4] != NULL)
{
if (fclose(filist[4]) == FAILURE)
printf("\nCouldn\'t close file # d .\n");
}
else
printf("\n File #3 was NULL.\n");
if (filist[5] != NULL)
{
if (fclose(filist[5]) == FAILURE)
printf("\nCouldn\'t close file # e .\n");
}
else
printf("\nFile #4 was NULL.\n");
}

View File

@@ -0,0 +1,258 @@
/*****************************************************************************/
/* */
/* Test program 2 for C run-time library. Tests : */
/* fopen,fclose,rewind,fwrite,fread,fseek. */
/* Program stream1.c should be run before stream2.c. */
/* 8/5/82 . FMB */
/* */
/*****************************************************************************/
#include <stdio.h>
#define CREATF "w" /* Mode for create file. */
#define READMODE "r" /* Mode for open-read . */
#define APPMODE "a" /* Mode for append to file. */
#define G "George" /* Existing file. Make */
/* sure you run Stream1 first.*/
#define S "Shirley" /* Gets created below. */
#define ASCYES 0 /* Specifies ascii file. */
#define STDSIZ 100 /* Standard block size. */
#define BUFFMAX 100 /* Maximum buffer length */
#define SIZE 1 /* Number bytes in item */
/* And for formatting... */
#define STARS "***************************************************************"
main ()
{
FILE *fp,*fp1,*fp2,*temp; /* File pointers. */
BYTE *strptr,*echobuff,*notherbuff; /* Buffer pointers. */
BOOLEAN greenlite ; /* To stop test before you */
/* get into trouble . */
WORD size = 1; /* # bytes in an item */
LONG cursor = 0; /* # bytes in file stream. */
WORD returnw; /* Function ret value */
BYTE i;
/****************************/
/* Begin program. */
/****************************/
printf("%-15s\n\n",STARS);
printf("%-15s\n\n","Begin C library test # 2 : ");
printf("%-15s\n",STARS);
greenlite = TRUE;
/****************************/
/* This section tests memory*/
/* allocation for buffers. */
/****************************/
printf("\nTesting for memory allocation.......................\n");
strptr = malloc(BUFFMAX); echobuff = malloc(BUFFMAX);
notherbuff = malloc(BUFFMAX);
/*****************************/
/* Test for malloc o.k. */
/*****************************/
if ((strptr && echobuff && notherbuff) == NULL)
{
printf("Malloc didn't work. Stop here.\n");
greenlite = FALSE;
}
else
printf("Malloc succeeded on three successive calls,100 bytes each.\n");
/*****************************************************************************/
/* This section tests fopen,fread,and ftell, all on one ascii file. An */
/* attempt is made to write one section (100 bytes) of the file (the */
/* results of fread) to the screen. File is opened as RO. */
/*****************************************************************************/
/*****************************/
/* Open first file - George. */
/*****************************/
if (greenlite)
{
printf("Testing fopen..................................\n");
fp = fopena(G,READMODE);
if (fp == NULL )
{
printf("Couldn\'t open first file.\n");
greenlite = FALSE;
}
else /*****************************/
/* Ok to do more with George.*/
/* Read from file to memory */
/* and to stream. */
/*****************************/
{
printf("Testing fread...................................\n");
if (fread(strptr,SIZE,STDSIZ,fp) == NULL )
{
if (feof(fp) != 0)
{
printf("Fread unable to read from file........\n");
greenlite = FALSE;
}
else
printf("Fread read up to the EOF.");
}
if (greenlite)
{
printf("Testing ftell on ascii file..........\n");
cursor = ftell(fp); /* Go to end of buffer.*/
printf("\nCursor is %ld after ftell.\n",cursor);
/* Check for place to put NULL for fputs */
if (cursor <= BUFFMAX)
*(strptr + cursor) =NULL; /* Insert the NULL */
else
*(strptr + BUFFMAX - 1) = NULL;
/* Now print it out. */
printf("Testing fputs on fread ...............\n");
if (fputs(strptr,stdout) < 0 )
printf("\nFputs should have printed contents of George.\n");
}
}
}
/* Now try to write to George. */
if (greenlite )
{
printf("\nTesting realloc and illegal write..........................\n");
printf("Enter a string for first file. At this point,file is RO.\n");
printf("Make your entry at least 500 bytes\' worth.\n");
notherbuff = realloc(notherbuff,BUFFMAX * 5);
fgets(notherbuff,BUFFMAX * 5,stdin); /* Get something into buffer 1st*/
if (fputs(notherbuff,fp) >= 0 )
printf("\nFputs should not have worked here.\n");
}
/*****************************/
/* Now do a rewind on George.*/
/*****************************/
if (greenlite )
{
printf("Testing rewind on ascii file..........................\n");
if (rewind(fp) < 0 )
{
printf("Rewind failed on ascii file.\n");
greenlite = FALSE;
}
}
/*****************************/
/* Reopen George so we can */
/* write to him. */
/*****************************/
fp = freopa(G,APPMODE,fp);
if (fp == NULL )
{
printf("Reopening of first file didn\'t work.\n");
greenlite = FALSE;
}
else
{
printf("File is reopened in append mode. Writing to it...\n");
greenlite = TRUE; /*****************************/
/* Since we're starting over */
/* again anyway. */
/*****************************/
}
if ( greenlite )
{
printf("Please enter a string of 80 chars followed by a CR.\n");
fgets(notherbuff,STDSIZ,stdin);
/*****************************/
/* Data's in buffer. Move */
/* cursor to end of current */
/* stream. */
/*****************************/
printf("Testing fseek on ascii file...........................\n");
fseek(fp,0,2);
/****************************/
/* Now append buffer to the */
/* end of George's stream. */
/****************************/
printf("Testing fwrite...................................\n");
if (fwrite(notherbuff,SIZE,STDSIZ,fp) < 0 )
{
printf("Attempt to append to first file failed.\n");
greenlite = FALSE;
}
}
if (greenlite )
{
printf("Testing fputc and ftell on ascii file.................\n");
/*****************************/
fputc(NULL,fp); /* Tack on the null */
cursor = ftell(fp); /* Find out how much to read.*/
if (cursor < 1) /*****************************/
cursor = BUFFMAX;
/*****************************/
/* Reopen file for Reading */
fp = freopa(G,READMODE,fp); /*****************************/
if (fread(echobuff,SIZE,cursor,fp) == NULL)
printf("\nAttempt at Fread on file one failed or saw EOF.\n");
/* This should have read file and null char into memory buffer.*/
/* Now printf the whole thing out to the terminal.*/
printf("We\'ll try to print the entire file to the screen.\n");
if (fputs(echobuff,stdout) < 0 )
printf("\nAs you can see, that wasn\'t right.\n");
}
/* Do another file */
if (greenlite )
{
printf("Opening second file.....................................\n");
fp2 = fopena(S,CREATF);
if (fp2 == 0 )
printf("Couldn\'t open second file.\n");
/* Open was successful, do a write.*/
strptr = echobuff; /* Save this */
printf("Filling file with test pattern..............\n");
for (i = 1; i < BUFFMAX; i++)
*echobuff++ = 'a'; /**************************/
echobuff = strptr; /* Restore buffer pointer */
/* Now write to file */
/**************************/
if (fwrite(echobuff,1,BUFFMAX - 1,fp2) != (BUFFMAX -1))
printf("\nFwrite of 100 chars returned bad count.\n");
putc(NULL,fp2); /***************************/
/* Tack on the null */
/* Try to retrieve what's */
/* in there anyway. */
/***************************/
printf("\nReading from second file.........................\n");
/****************************/
fp2 = freopa(S,READMODE,fp2); /* So we can read from it */
fgets(strptr,BUFFMAX,fp2); /* Put from stream to memory*/
fputs(strptr,stdout); /* Send it to the screen */
/****************************/
}
/*************************/
/* As a last test, close */
/* all files. */
/*************************/
printf("\n\n\t\t\tEnd of Test # 2\n");
_cleanup();
} /* End main. */

View File

@@ -0,0 +1,253 @@
/*****************************************************************************/
/* */
/* Test program 2 for C run-time library. Tests : */
/* fopen,fclose,rewind,fwrite,fread,fseek,ftell,freopb. */
/* Program stream1.c should be run before stream2.c. */
/* 8/5/82 . FMB */
/* */
/*****************************************************************************/
#include <stdio.h>
#define CREATF "w" /* Mode for create file. */
#define READMODE "r" /* Mode for open-read . */
#define APPMODE "a" /* Mode for append to file. */
#define G "George" /* Existing file. Make */
/* sure you run Stream1 first.*/
#define S "Shirley" /* Gets created below. */
#define ASCYES 1 /* Specifies binary file. */
#define STDSIZ 100 /* Standard block size. */
#define BUFFMAX 100 /* Maximum buffer length */
#define SIZE 1 /* Number bytes in item */
/* And for formatting... */
#define STARS "***************************************************************"
main ()
{
FILE *fp,*fp1,*fp2,*temp; /* File pointers. */
BYTE *strptr,*echobuff,*notherbuff; /* Buffer pointers. */
BOOLEAN greenlite ; /* To stop test before you */
/* get into trouble . */
WORD size = 1; /* # bytes in an item */
LONG cursor = 0; /* # bytes in file stream. */
WORD returnw; /* Function ret value */
BYTE i;
/****************************/
/* Begin program. */
/****************************/
printf("%-15s\n\n",STARS);
printf("%-15s\n\n","Begin C library test # 2 : ");
printf("%-15s\n",STARS);
greenlite = TRUE;
/****************************/
/* This section tests memory*/
/* allocation for buffers. */
/****************************/
printf("\nTesting for memory allocation.......................\n");
strptr = malloc(BUFFMAX); echobuff = malloc(BUFFMAX);
notherbuff = malloc(BUFFMAX);
/*****************************/
/* Test for malloc o.k. */
/*****************************/
if ((strptr && echobuff && notherbuff) == NULL)
{
printf("Malloc didn't work. Stop here.\n");
greenlite = FALSE;
}
else
printf("Malloc succeeded on three successive calls,100 bytes each.\n");
/*****************************************************************************/
/* This section tests fopen,fread,and ftell, all on one binary file. An */
/* attempt is made to write one section (100 bytes) of the file (the */
/* results of fread) to the screen. File is opened as RO. */
/*****************************************************************************/
/*****************************/
/* Open first file - George. */
/*****************************/
if (greenlite)
{
printf("Testing fopen..................................\n");
fp = fopenb(G,READMODE,ASCYES) ;
if (fp == NULL )
{
printf("Couldn\'t open first file.\n");
greenlite = FALSE;
}
else /*****************************/
/* Ok to do more with George.*/
/* Read from file to memory */
/* and to stream. */
/*****************************/
{
printf("Testing fread...................................\n");
if ((returnw = fread(strptr,SIZE,STDSIZ,fp)) == NULL )
{
if (feof(fp) != 0)
{
printf("Fread unable to read from file........\n");
printf("Fread returned %D .\n",returnw);
greenlite = FALSE;
}
else
printf("Fread read up to the EOF.");
}
if (greenlite)
{
printf("Testing ftell on binary file..........\n");
cursor = ftell(fp);
printf("\nCursor is %ld after ftell.\n",cursor);
/*********************/
/* Now print it out. */
/*********************/
printf("Testing fputs on fread ...............\n");
if (fputs(strptr,stdout) < 0 )
printf("\nFputs should have printed contents of George.\n");
}
}
} /*********************/
/* Try to write to it*/
if (greenlite ) /*********************/
{
printf("\nTesting realloc and illegal write..........................\n");
printf("Enter a string for first file. At this point,file is RO.\n");
printf("Make your entry at least 500 bytes\' worth.\n");
notherbuff = realloc(notherbuff,BUFFMAX * 5);
fgets(notherbuff,BUFFMAX * 5,stdin); /* Get something into buffer 1st*/
if (fputs(notherbuff,fp) >= 0 )
printf("\nFputs should not have worked here.\n");
}
/*****************************/
/* Now do a rewind on George.*/
/*****************************/
if (greenlite )
{
printf("Testing rewind on binary file..........................\n");
if (rewind(fp) < 0 )
{
printf("Rewind failed on binary file.\n");
greenlite = FALSE;
}
}
/*****************************/
/* Reopen George so we can */
/* write to him. */
/*****************************/
fp = freopb(G,APPMODE,fp,ASCYES);
if (fp == NULL )
{
printf("Reopening of first file didn\'t work.\n");
greenlite = FALSE;
}
else
{
printf("File is reopened in append mode.................\n");
greenlite = TRUE; /*****************************/
/* Since we're starting over */
/* again anyway. */
/*****************************/
}
if ( greenlite )
{
printf("Please enter a string of 80 chars followed by a CR.\n");
fgets(notherbuff,STDSIZ,stdin);
/*****************************/
/* Data's in buffer. Move */
/* cursor to end of current */
/* stream. */
/*****************************/
printf("Testing fseek on binary file...........................\n");
fseek(fp,0,2);
/****************************/
/* Now append buffer to the */
/* end of George's stream. */
/****************************/
printf("Testing fwrite with your 80 chars......................\n");
if (fwrite(notherbuff,SIZE,STDSIZ,fp) < 0 )
{
printf("Attempt to append to first file failed.\n");
greenlite = FALSE;
}
}
if (greenlite )
{
printf("Testing fputc and ftell on binary file.................\n");
/*****************************/
fputc(NULL,fp); /* Tack on the null */
cursor = ftell(fp); /* Find out how much to read.*/
/*****************************/
printf("After ftell,cursor is %ld.\n",cursor);
/*****************************/
/* Reopen file for Reading */
fp = freopb(G,READMODE,fp); /*****************************/
if ((returnw = fread(echobuff,SIZE,cursor,fp)) == NULL)
printf("\nAttempt at Fread on file one failed or saw EOF.\n");
printf("Number bytes read fro file: %ld.\n",returnw);
/* This should have read file and null char into memory buffer.*/
/* Now printf the whole thing out to the terminal.*/
printf("Echoing appended file to the screen.\n");
if (fputs(echobuff,stdout) < 0 )
printf("\nAs you can see, that wasn\'t right.\n");
}
/* Do another file */
if (greenlite )
{
printf("Opening second file.....................................\n");
fp2 = fopenb(S,CREATF,ASCYES);
if (fp2 == 0 )
printf("Couldn\'t open second file.\n");
/* Open was successful, do a write.*/
strptr = echobuff; /* Save this */
printf("Filling file with test pattern..............\n");
for (i = 1; i < BUFFMAX; i++)
*echobuff++ = 'a';
echobuff = strptr; /* Restore buffer pointer */
/* Now write to file */
if (fwrite(echobuff,1,BUFFMAX - 1,fp2) != (BUFFMAX -1))
printf("\nFwrite of 100 chars returned bad count.\n");
putc(NULL,fp2); /* Tack on the null */
/* Try to retrieve what's */
/* in there anyway. */
printf("\nReading from second file.........................\n");
fp2 = freopb(S,READMODE,fp2,ASCYES);/* So we can read from it */
fgets(strptr,BUFFMAX,fp2); /* Put from stream to memory */
fputs(strptr,stdout); /* Send it to the screen */
}
/*************************/
/* As a last test, close */
/* all files. */
/*************************/
printf("\n\n\t\t\tEnd of Test # 2\n");
_cleanup();
} /* End main.*/

View File

@@ -0,0 +1,240 @@
/*****************************************************************************/
/* */
/* */
/* This program tests the printf-scanf family of routines */
/* contained in the C run-time library. */
/* Tests: fprintf,sprintf,printf,puts,scanf,sscanf, */
/* fscanf. */
/* */
/* 8-12-82 . FMB. */
/* */
/*****************************************************************************/
#include <stdio.h>
#define C "Clarence" /* An empty file. */
#define READMODE "r" /* RO files */
#define CREATF "w" /* New files */
#define APPMODE "a" /* Append files */
#define ASCYES 0 /* Ascii file */
#define BINARY 1 /* Binary file */
#define BUFFMAX 100 /* Maximum buffer length */
main()
{
FILE *filstream,filstream2; /* Point to file buff*/
BYTE *buff1,*buff2,*buff3,*buff4; /* Memory buffers */
WORD returnw; /* Return values */
BOOLEAN goahead ; /* Prevents traffic jams.*/
WORD nitems,savitems; /* # items read */
BYTE dum_d, a; /* Vars for scanf family */
LONG *dum_b[2],*dum_c[6],*c[10]; /* " */
BYTE *name,*dum_a,*sav_a; /* " */
/*****************************************************************************/
/* Begin Program */
/*****************************************************************************/
/* Print program header */
printf("\n\n\n ********************************************\n");
printf(" Begin C Test # 3.\n\n");
printf("%10s \n\n","First test malloc on the buffers...................");
/* Init breaker */
goahead = TRUE;
/*********************/
/* This section tests*/
/* memory allocation.*/
/*********************/
printf("Testing memory allocation..........................\n");
/*********************/
/* Allocate buffer */
buff1 = malloc(BUFFMAX); buff2 = malloc(BUFFMAX); /* space. */
buff3 = malloc(BUFFMAX); buff4 = malloc(BUFFMAX); /*********************/
dum_a = malloc(10); name = malloc(50);
if ((buff1 && buff2 && buff3 && buff4 && dum_a && name) == NULL)
{
printf("Malloc failed on buffer allocation.\n\n");
goahead = FALSE;
} /*********************/
/* This section tests*/
/* fscanf and sscanf */
/* with an arbitrary */
/* delimiter. */
/*********************/
/*********************/
/* Now open a file */
/* for testing */
filstream = fopen(C,CREATF,ASCYES); /*********************/
if (filstream == NULL )
{
printf("File open failed.Stop here.\n\n");
goahead = FALSE;
}
else /*********************/
/* Coast is clear.Go */
/* and test fscanf. */
{ /*********************/
printf("After fopen, fp is %X.\n",filstream);
printf("Testing Fscanf.................................\n");
printf("Please input file material ending with a \'!\'.\n");
savitems = nitems = fscanf(stdin,"%[^!]%*c",buff3);
/*********************/
/* Where ! is the */
/* file delimiter & */
/* c gobbles up the !*/
if (nitems == NULL ) /*********************/
{
printf("\nfscanf failed on terminal input.\n\n");
goahead = FALSE;
}
else
{
printf("Testing fprintf...................\n");
/*********************************/
/* Now let's try fprintf to move */
/* this stuff into a file stream */
/*********************************/
nitems = fprintf(filstream,"%[^.]%*c",buff3);
fputc('\0',filstream);
printf("After fprintf,fp is %X .\n",filstream);
if (nitems == NULL )
printf("Fprintf didn\'t make it.\n\n");
}
}
if (goahead) /*********************/
{ /* Close file, open */
printf("Testing reopen.................\n"); /* it,and read from */
filstream = freopa(C,READMODE,filstream); /* it with fscanf. */
printf("Testing fscanf........................\n");
savitems = fscanf(filstream,"[^.].",buff4); /* Then use sscanf to*/
printf("Testing sscanf........................\n");
nitems = sscanf(buff4,"%s",stdout); /* echo to screen. */
} /*********************/
/*************************************************************************/
/* This section tests scanf and sprintf with 3 kinds of variables. */
/*************************************************************************/
if (goahead )
{
/* Test scanf with dum_ var's. */
printf("Please enter data for scanf test. For the first item \n");
printf("type in a word. \n");
printf("Next,type in one 5-digit decimal and one 2-digit \n");
printf("hex number,with optional spaces in between items.\n");
nitems = scanf("%s%5D%2x",dum_a,dum_c,dum_b);
/* At this point, dum_a should have a 1-word string ending with a null.*/
/* Dum_b should have 2 hex digits,and dum_c should have a 5-place decimal #*/
if (nitems != 3)
{
printf("Scanf returned bad item count.\n");
printf("Nitems was %d .\n",nitems);
} /*********************/
else /*Go ahead and test */
{ /* sprintf. */
/*********************/
printf("Testing sprintf...................\n");
buff2 = sprintf(buff2,"%s %5D %2x ",dum_a,*dum_c,*dum_b);
if (buff2 == NULL)
printf("\nSprintf didn\'t work.");
else
printf("\nEcho = %s\n",buff2);
}
} /*********************/
if (goahead) /* Now test scanf */
{ /* with printf. */
/*********************/
printf("\n%c%c %s%c %c \n",'*',' ',"Please enter : ",'*',' ');
printf("%5c%s%5c\n", ' ',"One 2-digit decimal number ,",' ');
printf("%5c%s%c\n",' ',"one 6-digit decmal number,",' ');
printf("%5c%s%c\n",' ',"and one filename.",' ');
printf("%5c%s%5c",' ',"Intervening spaces are ok.CR's not allowed.\0",' ');
printf("\n\n"); /*********************/
/*Get data from screen*/
nitems = scanf("%2D%6D%s",dum_c,c,name); /*********************/
/*********************/
if (nitems != 3) /* See if it flopped */
printf("Scanf didn\'t make it.\n"); /*********************/
/*********************/
/* Should we bother */
if (goahead) /* trying to read it */
{ /* back? */
printf("Echoing values ................\n"); /*********************/
printf("The 6-digit decimal number is : %D .\n",*c);
printf("The 2-digit decimal number is : %D .\n",*dum_c);
printf("The name is : %s .\n",name);
printf("Testing field widths ...............\n");
printf("This one should be 2 out of 6 digits : %40.2D\n",*c);
printf("This one should move back some : %20.2D\n",*c);
printf("This one should move back completely: %-20.2D\n",*c);
}
}
/*************************************************************************/
/* This section tests puts by displaying contents of memory buffer. */
/*************************************************************************/
if (goahead )
{
printf("Testing puts on first file input..........................\n");
if (puts(buff3) == FAILURE )
printf("\nPuts didn\'t echo buff to screen.\n");
}
/************************************************************************/
/* This section tests fprintf (with an append) and printf. */
/************************************************************************/
if (goahead )
{
printf("Testing fprintf.................................\n");
filstream = fopen("Ace",CREATF); /*********************/
if (fprintf(filstream,"%s\0",buff2) == FAILURE)/* Put buff2 into new*/
printf("Couldn\'t write with fprintf.\n\n");/*file with fprintf */
else /*********************/
{
printf("Testing Fscanf..............................\n");
filstream = freopen("Ace",READMODE,filstream);
nitems = fscanf(filstream,"%s",buff1); /*********************/
printf("Echoing..... %s \n",buff1); /* Reopen and copy to*/
} /* Buff1. Echo to */
/* screen. */
} /*********************/
printf("\n\t\t\tEnd Test # 3\n");
} /* End program */

View File

@@ -0,0 +1,217 @@
/*****************************************************************************/
/* */
/* */
/* This program tests the printf-scanf family of routines */
/* contained in the C run-time library. */
/* Tests: fprintf,sprintf,printf,puts,scanf,sscanf, */
/* fscanf. */
/* */
/* 8-12-82 . FMB. */
/* */
/*****************************************************************************/
#include <stdio.h>
#define C "Clarence" /* An empty file. */
#define READMODE "r" /* RO files */
#define CREATF "w" /* New files */
#define APPMODE "a" /* Append files */
#define ASCYES 0 /* Ascii file */
#define BINARY 1 /* Binary file */
#define BUFFMAX 100 /* Maximum buffer length */
main()
{
FILE *filstream; /* Point to file buff*/
BYTE *buff1,*buff2,*buff3,*buff4; /* Memory buffers */
WORD returnw; /* Return values */
BOOLEAN goahead ; /* Prevents traffic jams.*/
WORD nitems,savitems; /* # items read */
BYTE dum_d, a; /* Vars for scanf family */
LONG *dum_b[2],*dum_c[6],*c[10]; /* " */
BYTE *name,*dum_a,*sav_a; /* " */
/*****************************************************************************/
/* Begin Program */
/*****************************************************************************/
/* Print program header */
printf("\n\n\n ********************************************\n");
printf(" Begin C Test # 3.\n\n");
printf("%10s \n\n","First we will test malloc on the buffers.");
/* Init breaker */
goahead = TRUE;
/*************************************************************************/
/* This section tests malloc while initializing memory buffers. */
/*************************************************************************/
printf("Testing memory allocation..........................\n");
/* Allocate buffer space */
buff1 = malloc(BUFFMAX); buff2 = malloc(BUFFMAX);
buff3 = malloc(BUFFMAX); buff4 = malloc(BUFFMAX);
dum_a = malloc(10); name = malloc(50);
if ((buff1 && buff2 && buff3 && buff4 && dum_a && name) == NULL)
{
printf("Malloc failed on buffer allocation.\n\n");
goahead = FALSE;
}
/*************************************************************************/
/* This section tests fscanf and sscanf with an arbitrary delimiter. */
/*************************************************************************/
/* Now open a file for testing. */
filstream = fopen(C,CREATF,BINARY);
if (filstream == NULL )
{
printf("File open failed.Stop here.\n\n");
goahead = FALSE;
}
else /* Else, coast is clear */
/* Go ahead and test fscanf.*/
{
printf("Testing Fscanf.................................\n");
printf("Please input file material ending with a \'!\'.\n");
savitems = nitems = fscanf(stdin,"%[^!]%*c",buff3);
/* Where ! is the file delimiter */
/* And c gobbles up the ! */
if (nitems == NULL )
{
printf("\nfscanf failed on terminal input.\n\n");
goahead = FALSE;
}
else
{
printf("Testing Sscanf...................\n");
/* Now let's try sscanf to move */
/* this stuff into a mem buffer. */
filstream = fopena("Ace",CREATF);
nitems = sscanf(buff3,"%[^.]%*c",filstream);
if (nitems == NULL )
printf("Sscanf didn\'t make it.\n\n");
}
}
/*************************************************************************/
/* This section tests scanf and sprintf with 3 kinds of variables. */
/*************************************************************************/
if (goahead )
{
/* Test scanf with dum_ var's. */
printf("Please enter data for scanf test. For the first item \n");
printf("type in a word. \n");
printf("Next,type in one 5-digit decimal and one 2-digit \n");
printf("hex number,with optional spaces in between items.\n");
nitems = scanf("%s%5D%2x",dum_a,dum_c,dum_b);
/* At this point, dum_a should have a 1-word string ending with a null.*/
/* Dum_b should have 2 hex digits,and dum_c should have a 5-place decimal #*/
if (nitems != 3)
{
printf("Scanf returned bad item count.\n");
printf("Nitems was %d .\n",nitems);
}
else /*Else, go ahead and test sprintf.*/
{
printf("Testing sprintf...................\n");
buff2 = sprintf(buff2,"%s %5D %2x ",dum_a,*dum_c,*dum_b);
if (buff2 == NULL)
printf("\nSprintf didn\'t work.");
else
printf("\nEcho = %s\n",buff2);
}
}
if (goahead) /* Now test scanf with printf */
{
/* The spacing between control char's below is an intentional test. */
/* Printf should ignore the spaces and just count arg's with types.*/
printf("\n%c%c %s%c %c \n",'*',' ',"Please enter : ",'*',' ');
printf("%5c%s%5c\n", ' ',"One 2-digit decimal number ,",' ');
printf("%5c%s%c\n",' ',"one 6-digit decmal number,",' ');
printf("%5c%s%c\n",' ',"and one filename.",' ');
printf("%5c%s%5c",' ',"Intervening spaces are ok.CR's not allowed.\0",' ');
printf("\n\n");
/* Get data from terminal */
nitems = scanf("%2D%6D%s",dum_c,c,name);
if (nitems != 3) /* See if it flopped */
printf("Scanf didn't make it.\n");
if (goahead) /* Should we bother trying to read it back?*/
{
printf("Echoing values ................\n");
printf("The 6-digit decimal number is : %D .\n",*c);
printf("The 2-digit decimal number is : %D .\n",*dum_c);
printf("The name is : %s .\n",name);
printf("Testing field widths ...............\n");
printf("This one should be 2 out of 6 digits : %40.2D\n",*c);
printf("This one should move over some : %20.2D\n",*c);
printf("This one should move back some : %-20.2D\n",*c);
}
}
/*************************************************************************/
/* This section tests puts by displaying contents of memory buffer. */
/*************************************************************************/
if (goahead )
{ /* Use puts to echo the buffer results to screen.*/
if (puts(buff3) == FAILURE )
printf("\nPuts didn't echo buff to screen.\n");
}
/************************************************************************/
/* This section tests fprintf (with an append) and printf. */
/************************************************************************/
if (goahead )
{
filstream = fopen("Ace",CREATF);
if (fprintf(filstream,"%s",buff2) == FAILURE )
printf("Couldn\'t append with fprintf.\n\n");
else
{
filstream = freopen("Ace",READMODE,filstream);
nitems = fscanf(filstream,"%s",buff1);
printf("Echoing..... %s \n",buff1);
}
}
} /* End program */

View File

@@ -0,0 +1,212 @@
/*****************************************************************************/
/* */
/* */
/* */
/* Test 4 for C run-time library. */
/* Tests the get and put families for char and word */
/* manipulations : */
/* fgetc(getc),fputc(putc),ungetc, */
/* putw,getw,getchar,putchar. */
/* May be run independently of other tests. */
/* Uses one ascii and one binary file. */
/* 8-10-82. FMB */
/* */
/* */
/*****************************************************************************/
#include <stdio.h>
#define CREATF "w" /* Create and write mode */
#define RO "r" /* Read only mode */
#define APPMODE "a" /* Append mode */
#define BUFFMAX 100 /* Size of memory buffer */
#define BSIZE 1 /* For byte-size items */
#define WSIZE 2 /* For word-size items */
#define ASCYES 1 /* For ascii files */
#define BINARY 0 /* For nonascii files */
#define T1 "test1" /* File one */
#define T2 "test2" /* File two */
/*****************************************************************************/
/* Begin Program */
/*****************************************************************************/
main()
{
FILE *fp, *fp2; /* Stream pointers */
WORD *buff2,*tempbuff2; /* Buffer pointers */
BYTE *buff1, *tempbuff1; /* Buffer pointers */
WORD *chr1, *chr2, *chr3; /* Char var's for fgetc,fputc */
WORD valword,retword; /* Word var's for getw,putw */
BOOLEAN goahead = TRUE; /* Breakpoint variable */
BYTE i; /* Loop counter */
BYTE retbyte; /* Byte var for fgetc */
BYTE chrc1,chrc2; /* Char's for putchar */
WORD ch1,ch2;
printf("\n >>>>>>>> <<<<<<<< \n");
printf("\n BEGIN STREAM4 TEST \n");
/*****************************************************************************/
/* Initialization */
/*****************************************************************************/
fp = fopen(T1,CREATF,ASCYES); /* Open the files */
fp2 = fopen(T2,CREATF,BINARY);
/*****************************************************************************/
/* This section tests malloc and realloc while initializing buffers. */
/*****************************************************************************/
printf("\nTesting memory allocation.................................\n");
buff1 = malloc(BUFFMAX/2); buff2 = malloc(BUFFMAX/4);
if ((buff1 || buff2 ) == FAILURE)
{
printf("\nMalloc didn't like something. Maybe the size argument.\n");
goahead = FALSE;
}
buff1 = realloc(buff1,BUFFMAX); buff2 = realloc(buff2,BUFFMAX);
if ((buff1 || buff2 )== FAILURE)
{
printf("Realloc didn't succeed here.\n\n");
goahead = FALSE;
}
tempbuff1 = buff1; /* Save buffer start addresses */
tempbuff2 = buff2;
/*****************************************************************************/
/* This section tests getchar and getw. */
/*****************************************************************************/
printf("\nBegin testing getchar....................................\n");
printf("Please enter 100 characters to test getchar.Blanks are valid char's.\n");
for (i = 0; i < BUFFMAX; i++)
*buff1++ = getchar(); /* Fill buffer with chars */
*buff1 = NULL; /* Tack on the NULL */
buff1 = tempbuff1; /* Reset buffer pointer */
/* Now echo it back */
printf("Here is an echo of your entry.\n%s\n",buff1);
printf("Please enter 20 16-bit items to test getw.\n");
for (i = 0; i < BUFFMAX/5; i++)
*buff2++ = getw(stdin); /* Fill buffer with words */
*buff2 = NULL; /* Tack on a NULL */
buff2 = tempbuff2; /* Reset buffer pointer */
/* Now echo it back */
printf("Here is an echo of your entry.\n%s\n",buff2);
/*****************************************************************************/
/* This section tests Fputc and Putw. */
/*****************************************************************************/
printf("Testing fputc ........................................\n");
/* Copy buffers to streams */
while (*buff1 != NULL)
fputc(*buff1++,fp);
*buff1 = NULL; /* Tack on the null 8/
buff1 = tempbuff1; /* Reset buffer pointer */
printf("Testing putw .........................................\n");
while (*buff2 != NULL)
putw(*buff2++,fp2);
*buff2 = NULL; /* Tack on the null */
buff2 = tempbuff2; /* Reset buffer pointer */
/*****************************************************************************/
/* This section tests Putchar, Fgetc and Ungetc. */
/*****************************************************************************/
printf("Testing fgetc and putchar ..............................\n");
fp = freopen(T1,RO,fp,ASCYES); /* So we can read from file */
while ((retword = fgetc(fp)) != FAILURE) /* Put char's on screen */
putchar(retword);
valword = ungetc(retword,fp); /* Push EOF back on stream */
/*****************************************************************************/
/* This section tests Getw and Putw. */
/*****************************************************************************/
fp2 = freopen(T2,RO,fp2,BINARY); /* So we can read from the file*/
while ((retword = getw(fp2)) != FAILURE)/* Get word from stream to screen */
putw(retword,stdout);
valword = ungetc(retword,fp2); /* Push EOF back on stream */
/*****************************************************************************/
/* This section tests char-word exchanges. */
/*****************************************************************************/
printf("\nTesting char-word output.........................\n");
putchar('5'); /* Put it on the screen */
printf("\nThat was the character. Now let's show it as a word.\n");
putw('5',stdout);
printf("\nThat was putw with the same argument.\n");
chrc1 = 53; /* Output another 5 */
putchar(chrc1);
printf("\n");
chrc1 = 33; /* Output an ! */
putchar(chrc1);
printf("\n");
ch1 = 0x6948; /* Output Hi */
putw(ch1,stdout);
printf("\n");
ch2 = 0x3231; /* Output 1234 */
putw(ch2,stdout);
ch1 = 0x3433;
putw(ch1,stdout);
printf("\n");
}

View File

@@ -0,0 +1,206 @@
/*****************************************************************************/
/* */
/* */
/* This program tests the String Manipulation */
/* functions in the C run-time library. Tests: */
/* strlen,strcat,strncat,strcpy,strncpy,strcmp */
/* and strncmp. */
/* May be tested independently of the other */
/* stream tests. */
/* 8-16-82. FMB. */
/* */
/*****************************************************************************/
#include <stdio.h>
#define u " you"
#define r " are"
#define h " Here"
#define BUFFMAX 100
#define a "\nHello there, this is your captain speaking.\n"
#define b "\nWing Commanders - please report to the flight deck.\n"
#define c "\nJello there, this is your captain speaking.\n"
main()
{ /* String pointers */
BYTE *string1, *string2, *string3, *temp1, *temp2, *holding;
WORD retval;
/*****************************************************************************/
/* */
/* Begin Program */
/* */
/*****************************************************************************/
/* This section initializes variables and tests memory allocation. */
printf("\n\n BEGIN STREAM5 TEST \n");
printf("\nTesting memory allocation..............................\n");
temp1 = malloc(BUFFMAX);
string1 = malloc(BUFFMAX);
temp2 = malloc(BUFFMAX);
string2 = malloc(BUFFMAX);
string3 = malloc(BUFFMAX);
holding = malloc(BUFFMAX);
if ((temp1 || string1 || temp2 || string2 || string3 || holding) == NULL)
printf("\nMemory allocation unsuccessful. Stop here.\n");
else
printf("Memory allocation successful. Continue tests.\n");
/**************************/
/* Set up primary strings.*/
/**************************/
printf("Testing strcopy........................................\n");
string1 = strcpy(string1,a);
temp1 = strcpy(temp1,string1);
string2 = strcpy(string2,b);
temp2 = strcpy(temp2,string2);
string3 = strcpy(string3,c);
/****************************************************************************/
/* This section tests strcat and strncat. */
/****************************************************************************/
printf("Following are string1 and string 2.\n %s %s \n",string1,string2);
printf("Testing string concatenation...........................\n");
/***********************/
/* Cat the 2 strings */
/* Check lengths */
/***********************/
if ((strlen(string1) + strlen(string2)) == strlen(strcat(string1,string2)))
{
printf("Let\'s see the results of strcat on the 2 strings.\n");
puts(string1); printf("\n");
}
else /* Lengths don't match.*/
printf("\nError in strcat. Length comparison was off.\n");
/* Now try an illegal call */
printf("Testing illegal strcat.........................\n");
holding = strcat(string1,"go"); /* No null terminator here */
if (holding == FAILURE)
printf("Strcat failed on cue.\n");
else
printf("Strcat should not have worked here.\n");
/* Now test strncat */
printf("Testing strncat..........................\n");
string1 = strcpy(string1,temp1); /* Restore original string */
holding = strncat(string1,h,strlen(string1) + strlen(h));
printf("You should now see string1 with >here< added to it.\n");
puts(holding); printf("\n");
holding = strncat(string1,u,strlen(string1) + strlen(u)); /* Add "you" */
holding = strncat(string1,r,strlen(string1) + strlen(r)); /* Add "are" */
holding = strncat(string1,"!\0",strlen(string1) + strlen("!\0"));/* Add "!" */
printf("You should now see a 3 word sentence added on.\n");
puts(holding);printf("\n");
/****************************************************************************/
/* This section tests strcmp and strncmp. */
/****************************************************************************/
printf("Testing strcmp..........................................\n");
string1 = strcpy(string1,temp1); /* Restore original string */
if (strcmp(string1,string1) == NULL) /* Try two identical strings.*/
printf("Strcmp matched %s and %s\n successfully.\n",string1,string1);
else
printf("Strcmp could\'nt match two identical strings.\n");
if (strcmp("goo \0","go o\0") == NULL) /* Try 2 strings off by one letter*/
printf("Strcmp could\'nt distinguish between goo and go o.\n");
else
printf("Strcmp knew the difference between goo and go o.\n");
if (strcmp(string1,string2) != 0) /* Different char's and lengths */
printf("Strcmp distinguished between %s and %s\n",string1,string2);
else
printf("Strcmp could\'t tell the difference between %s and %s\n",
string1,string2);
if (strcmp(string1,string3) == NULL) /* One-char difference,equal lengths*/
printf("Strcmp didn\'t distinguish between %s and %s\n",string1,string3);
else
printf("Strcmp distinguished between %s and %s\n",string1,string3);
/* Now test strncmp */
printf("Testing strncmp....................................\n");
if (strncmp(string1,string3,5) == 0) /* Compare first 5 letters */
printf("Strcmp couldn\'t tell %s from %s.\n","Hello","Jello");
else
printf("Strcmp knew %s from %s.\n","Hello","Jello");
if (strncmp("aaaaaaa","aaaaaab",6) != 0) /* Just compare the a's*/
printf("Strncmp didn\'t work on two strings of a\'s.\n");
else
printf("Strncmp picked off 6 a\'s from each of 2 strings and matched them.\n");
/****************************************************************************/
/* This section tests strcpy and strncpy. */
/****************************************************************************/
printf("Now testing strcpy......................................\n");
string1 = strcpy(string1,temp1); string2 = strcpy(string2,temp2);/* Restore original strings.*/
string2 = strcat(string2,temp2);
holding = strcpy(string1,string2);
printf("You should now see 2 copies of string2.%s\n",string1);
/* Now double the copy,add "and" */
holding = strcat(string2,"\nand\n");
holding = strcat(string2,temp2);
holding = strcpy(string1,string2); /* Put whole thing back into string1 */
printf("You should next see 3 copies of string1.%s\n",string1);
printf("Now testing strncpy.......................................\n");
string1 = strcpy(string1,temp1); /* Restore original string */
holding = strncpy(string1,string2,strlen(string2));
printf("You should next see a copy of string2 in string1.%s\n",
string1);
holding = strncpy(string2,strcat(temp1,temp2),BUFFMAX);
printf("You should then see a copy of both strings in string2.%s\n",
string2);
/****************************************************************************/
/* Now free up memory and test FREE */
printf("Testing memory free function.............................\n");
free(temp1);
free(string1);
free(temp2);
free(string2);
free(string3);
free(holding);
printf("\n\n Ending Stream5 Test \n");
}

View File

@@ -0,0 +1,230 @@
/****************************************************************************/
/* */
/* */
/* Test Program #6 for C run-time library. */
/* Tests : putl,getl,setbuf,read,write,feof, */
/* calloc,fileno and rewind. */
/* Uses one ascii and one binary file. */
/* May be run independently of other tests. */
/* */
/* 8-23-82. FMB */
/****************************************************************************/
#include <stdio.h>
#define NUMLS 5 /* number of longs */
#define BUFFMAX BUFSIZ /* Buffer size */
#define LSIZE 4 /* Longs are 4 bytes */
#define CREATF "w" /* To create and write to */
/* a file. */
#define RO "r" /* To read from a file */
#define APPMODE "a" /* To append to a file */
#define poslong1 0x21214948 /* Sample positive long */
#define neglong1 -0x8655555 /* Sample negative long */
/***************************************************************************/
/* BEGIN MAIN PROGRAM */
/***************************************************************************/
main()
{
WORD retw; /* Function return value */
FILE *strm1,*strm2; /* Stream pointers */
LONG *shadowbuf,
*shadowbuf2; /* Buffers for setbuf */
BYTE *mybuf,*mybuf2; /* " " " */
LONG lval1,lval2,lval3,lval4; /* For getl,putl */
BYTE i;
/***************************/
/* Memory allocation and */
/* initialization. */
/***************************/
printf("\n *************** ");
printf("\n Stream Test # 6 ");
printf("\n *************** \n\n");
printf("\nTesting memory allocation with malloc.....................\n");
mybuf = malloc(BUFFMAX);
mybuf2 = malloc(BUFFMAX);
printf("Testing fopen.............................................\n");
if ((strm1 = fopena("ONE",CREATF)) == NULL)
printf("\nAscii file open failed.\n");
if ((strm2 = fopenb("TWO",CREATF)) == NULL)
printf("\nBinary file open failed.\n");
/*****************************/
/* This section tests Setbuf */
/*****************************/
printf("Testing setbuf..........................................\n");
if ((retw = setbuf(strm1,mybuf))== FAILURE)
printf("\nSetbuf of ascii file failed.\n");
if ((retw = setbuf(strm2,mybuf2)) == FAILURE)
printf("\nSetbuf of binary file failed.\n");
/*****************************/
/* This section tests Putl */
/*****************************/
printf("Testing Putl .........................................\n");
/***************************/
/* Fill one buffer with */
/* long values. */
/***************************/
for ( i=0; i < NUMLS; i++)
if((retw = putl((LONG)poslong1,strm1)) == FAILURE)
printf("\nPutl failed on ascii file at the %dth slot.",i);
for ( i=0; i < NUMLS; i++)
if ((retw = putl((LONG)neglong1,strm1)) == FAILURE)
printf("\nPutl failed on ascii file at the %dth slot.",i);
fputc('\0',strm1);
/**************************/
/* Echo buffer to screen */
/**************************/
printf("Buffered results of putl are : \n");
for( i=0 ; i < 2*NUMLS; i++ )
printf(" %x%x%x%x",*mybuf++,*mybuf++,*mybuf++,*mybuf++);
printf("\n");
if ((retw = rewind(strm1)) != SUCCESS){
perror("rewind failed");
printf("\nRewind returned a %d .\n",retw);
}
strm1 = freopa("ONE",RO,strm1);
setbuf(mybuf,strm1);
printf("Filed results of putl (getl) are : \n");
for( i=0 ; i < 2*NUMLS; i++ )
printf(" %X",getl(strm1));
strm1 = freopa("ONE",APPMODE,strm1);
setbuf(mybuf,strm1);
/**************************/
/* Use stdin to fill the */
/* other buffer. */
/**************************/
printf("\nPlease enter 2 positive long values \n");
printf(" and 2 negative long values.\n");
lval1 = getl(stdin);
lval2 = getl(stdin);
lval3 = getl(stdin);
lval4 = getl(stdin);
for (i = 0; i < (NUMLS * 4) ; i++)
{
if ((retw = putl(lval1,strm2)) == FAILURE)
printf("\nPutl failed on binary stream at %dth slot.\n",i);
if ((retw = putl(lval2,strm2)) == FAILURE)
printf("\nPutl failed on binary stream at %dth slot.\n",i);
if ((retw = putl(lval3,strm2)) == FAILURE)
printf("\nPutl failed on binary stream at %dth slot.\n",i);
if ((retw = putl(lval4,strm2)) == FAILURE)
printf("\nPutl failed on binary stream at %dth slot.\n",i);
}
fputc('\0',strm2); /* Tack on the null */
/*************************/
/* Now echo them back to*/
/* the screen. */
/*************************/
if ((retw = rewind(strm2)) == FAILURE)
printf("\nRewind failed on binary file.\n");
else
{
printf("\nBuffered results of putl : \n");
for (i=0 ; i < NUMLS*4; i++)
printf(" %d%d%d%d",*mybuf2++,*mybuf2++,*mybuf2++,*mybuf2++);
strm2 = freopb("TWO",RO,strm2);
setbuf(mybuf2,strm2);
printf("\nFile results of putl : \n");
for (i=0; i < NUMLS*4; i++)
printf(" %X",getl(strm2));
}
strm2 = freopb("TWO",APPMODE,strm2);
setbuf(mybuf2,strm2);
/**************************/
/* Try direct write to */
/* mybuffs. */
/**************************/
for ( i = 0; i < NUMLS; i++)
{
/*(LONG)*mybuf = 123456;*/
/*printf("\nResults of direct write to buffer : %X",(LONG)*mybuf++);*/
}
/***************************/
/* This section closes and */
/* opens the files */
/***************************/
if (fclose(strm1) == FAILURE)
printf("\nCouldn\'t close file 1.\n");
if (fclose(strm2) == FAILURE)
printf("\nCould\'t close file 2.\n");
if ((strm1 = fopena("ONE",RO)) == NULL)
printf("\nFile open on ascii file failed.\n");
if ((strm2 = fopenb("TWO",RO)) == NULL)
printf("\nFile open on binary file failed.\n");
/*****************************/
/* This section tests setbuf */
/* and reads from the files. */
/*****************************/
if ((retw = setbuf(strm1,mybuf2)) == FAILURE)
printf("\nSetbuf on reopened ascii file failed.\n");
if ((retw = setbuf(strm2,mybuf)) == FAILURE)
printf("\nSetbuf on reopened binary file failed.\n");
printf("\nTesting Putl on file 1. Should be HI! .\n");
putl(getl(strm1),stdout);
printf("\nTesting same data from buffer: %x%x%x%x\n",*mybuf2++,*mybuf2++,
*mybuf2++,*mybuf2++);
printf("Testing Putl on file 2. Should be your 4 inputs.\n");
putl(getl(strm2),stdout);
printf("\nTesting same data from buffer: %d%d%d%d\n",*mybuf++,*mybuf++,
*mybuf++,*mybuf++);
/***************************/
/* Finish up by freeing */
/* memory,closing files. */
/***************************/
free(mybuf);
free(mybuf2);
_cleanup();
}

View File

@@ -0,0 +1,135 @@
/*****************************************************************************/
/* */
/* Test Program for Sscanf and scanf. */
/* 8-17-82. FMB. */
/* Modified by B.Fitler */
/* */
/*****************************************************************************/
#include <stdio.h>
#define G "This is a string...with dots & spaces. \0!"
#define F "5691a24This is a buffer string. z37"
#define H "$$$...........$$$$\0"
#define BUFFMAX 100
#define E "-1234567890"
#define E1 "%3hd%*2d%2hd%*2d%2hd"
main()
{
WORD wd1,wd2,wd3; /* For hex,octal,etc. */
BYTE ch1,ch2,ch3,; /* For char's */
LONG dec1,dec2,dec3,dec4; /* For decimals */
WORD ni1,ni2; /* Item counts */
BYTE buff1[BUFFMAX],buff2[BUFFMAX]; /* String buffers */
printf("\n\t\tBegin Test # 7 for Sscanf and scanf.\n\n");
/************************/
/* Begin Program */
/* Test one string */
/************************/
ni1 = sscanf(G,"%[^!]",buff1);
if (ni1 != 1)
printf("\nSscanf returned bad item count.\n");
if (strcmp(G,buff1) != NULL)
printf("\nSscanf failed on whole string transfer.\n");
ni1 = sscanf(H,"%s",buff2);
if (ni1 != 1)
{
printf("\nSscanf returned bad item count.\n");
printf("Nitems was %d .\n",ni1);
}
/************************/
/* Print out both. */
/* They should match. */
/************************/
printf("Testing echo to screen.........................\n");
puts(buff1);
puts(buff2);
/************************/
/* Try multiple arg's */
/************************/
ni2 = sscanf(F,"%4D%3x%[^.]. %c%ho",&dec1,&wd1,buff1,&ch1,&wd2);
if (ni2 != 5)
{
printf("\nSscanf returned bad item count.\n");
printf("Nitems was %d.\n",ni2);
}
if (dec1 != 5691)
printf("\n6-digit decimal not transferred correctly.\n");
if (wd1 != 0xa24)
printf("\n3-digit hex not done correctly.\n");
if (ch1 != 'z')
printf("\nSingle char not assigned correctly.\n");
if (wd2 != 037)
printf("\n2-digit octal not assigned correctly.\n");
/***********************/
/* Print string */
/***********************/
puts(buff1);
printf("\n");
/***********************/
/* Unix examples. */
/***********************/
printf("Waiting for one decimal # (2 digits) and one string.\n");
ni2 = scanf("%d %s",&wd3,buff2);
if (ni2 != 2)
printf("\nScanf returned bad item count.\n");
printf("%d %s",wd3,buff2);
printf("\nWaiting for a decimal # (3 digits) and a name.\n");
ni2 = scanf("%2d%*d%s",&wd2,buff2);
if (ni2 != 2)
{
printf("\nScanf returned bad item count.\n");
printf("Item count was %d.\n",ni2);
}
printf("Decimal should be 2 of 3 digits :%2d and the name %s.\n",
wd2,buff2);
/**************************/
/* More sscanf stuff. */
/**************************/
#define E2 "%3ld%*2d%2ld%*2d%2ld"
ni1 = sscanf(E,E2,&dec1,&dec2,&dec3);
printf("Sscanf:\tscanned\t///%s///\tusing\t%s\n\t\tfound (%d)\t%ld %ld %ld\n",
E,E2,ni1,dec1,dec2,dec3);
#define E3 "%3D%*2D%2D%*2D%2D"
ni1 = sscanf(E,E3,&dec1,&dec2,&dec3);
printf("Sscanf:\tscanned\t///%s///\tusing\t%s\n\t\tfound (%d)\t%ld %ld %ld",
E,E3,ni1,dec1,dec2,dec3);
#define E4 "%3d%*2d%2d%*2d%2d"
ni1 = sscanf(E,E4,&dec1,&dec2,&dec3);
printf("\nSscanf:\tscanned\t///%s///\tusing\t%s\n\t\tfound (%d)\t%d %d %d\n",
E,E4,ni1,dec1,dec2,dec3);
printf("\n\n\t\t\tEnd Test # 7\n");
/***********************/
/* End for now. */
/***********************/
}

View File

@@ -0,0 +1,60 @@
main(argc,argv)
int argc;
char **argv;
{
char buff[512];
int fd;
int ofd;
int i,j,k,l;
int bufcnt;
int xbytes;
if(argc != 3)
{
printf("Illegal arg count = %d\n",argc);
exit();
}
i = 1;
while(argc > 1)
{
printf("Copying file %s to file %s\n",argv[i],argv[i+1]);
fd=open(argv[i++],0,0); /* Open read on ascii file */
if(fd < 0)
{
printf("Cannot open file %s\n",argv[--i]);
exit();
}
ofd=creat(argv[i],0,0);
if(ofd < 0)
{
printf("Cannot create file %s\n",argv[i]);
exit();
}
j = 512;
xbytes=0;
bufcnt=0;
while(j > 0)
{
j = read(fd,&buff,512);
if(j > 0)
{
for(k=0; k<j; k++)
{
l=write(ofd,&buff[k],1);
if(l != 1)
{
printf("Write error %d\n",l);
exit();
}
}
}
xbytes += j;
bufcnt++;
}
close(fd);
printf("File %s -- %d sectors; %d bytes\n",argv[i],
(xbytes+127) >> 7,xbytes);
argc -= 2;
}
}

View File

@@ -0,0 +1,10 @@
$ set noon
$ cc68 test
$ @rear
$ lo68 -r startup.o test.o lib6.a
$ nm68 c.out >test.map
$ print test.map
$ conv
c.out
test.asc
$ ! end

View File

@@ -0,0 +1,7 @@
#include <junk.h>
#include "junk1.h"
main()
{
printf("hello, world\n");
}

View File

@@ -0,0 +1,12 @@
*
* as68 / lo68 test program -- part 1
*
.globl print
.globl exit
start: move.l #20,d2
loop: jsr print * String print routine
subq.l #1,d2 * subtract 1
bne loop * and call again
jsr exit * call quit routine

View File

@@ -0,0 +1,20 @@
*
* Part 2 of the test
*
.globl print
.globl exit
jsr print * If entered as only module
exit:
move.l #0,d0 * Exit
trap #2 * to BDOS
print:
move.l #9,d0 * Print string func code
lea hello,a0 * a0 -> string
move.l a0,d1 * load param reg
trap #2 * do BDOS entry
rts * and return
.data
hello: .dc.b 'Hello, Steve',$0d,$0a,'$'

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,63 @@
#define SIGHUP 1
#define SIGINTR 2
#define SIGQUIT 3
#define BRKPIPE 13
#define FNSIZE 64
#define LBSIZE 512
#define ESIZE 128
#define GBSIZE 256
#define NBRA 5
#define EOF -1
#define CBRA 1
#define CCHR 2
#define CDOT 4
#define CCL 6
#define NCCL 8
#define CDOL 10
#define CEOF 11
#define CKET 12
#define STAR 01
#define READ 0
#define WRITE 1
#define NP 014
int peekc=0;
int brktst=0;
int lastc=0;
char savedfile[FNSIZE]=0;
char file[FNSIZE]=0;
char linebuf[LBSIZE]=0;
char rhsbuf[LBSIZE/2]=0;
char expbuf[ESIZE+4]=0;
int circfl=0;
int *zero=0;
int *dot=0;
int *dol=0;
int *endcore=0;
int *fendcore=0;
int *addr1=0;
int *addr2=0;
char genbuf[LBSIZE]=0;
int count[2]=0;
char *nextip=0;
char *linebp=0;
int ninbuf=0;
int io=0;
int pflag=0;
int onquit=0;
int col=0;
char *globp=0;
int tline=0;
char *tfname=0;
char *loc1=0;
char *loc2=0;
char *locs=0
char ibuff[512]=0;
char obuff[512]=0;
int ichanged=0;
int nleft=0;
int names[26]=0;
char *braslist[NBRA]=0;
char *braelist[NBRA]=0;
char line[70]=0;

View File

@@ -0,0 +1,35 @@
.globl setjmp
setjmp:
.word 0
movl fp,static
movl sp,static+4
movl ap,static+8
movl 0(sp),static+12
movl 4(sp),static+16
movl 8(sp),static+20
movl 12(sp),static+24
movl 16(sp),static+28
movl 20(sp),static+32
movl 24(sp),static+36
ret
.globl longjmp
longjmp:
.word 0
movl static,fp
movl static+4,sp
movl static+8,ap
movl static+12,0(sp)
movl static+16,4(sp)
movl static+20,8(sp)
movl static+24,12(sp)
movl static+28,16(sp)
movl static+32,20(sp)
movl static+36,24(sp)
ret
static: .long 0
.long 0
.long 0
.long 0,0,0,0,0,0,0,0
.end

View File

@@ -0,0 +1,57 @@
#define MAXNUM 1266
main()
{
int fd; /* Out descriptor */
int i;
int length;
short buffer[MAXNUM];
short chk[MAXNUM];
if((fd=creat("test.dat",0,1)) < 0)
{
printf("Cannot create test.dat\n");
exit();
}
for(i=0; i<MAXNUM; i++)
buffer[i] = i; /* Unique tag */
if(write(fd,&buffer[0],2*MAXNUM/3) != 2*MAXNUM/3)
{
printf("Write error 1\n");
exit();
}
if(write(fd,&buffer[MAXNUM/3],2*MAXNUM/3) != 2*MAXNUM/3)
{
printf("Write error 2\n");
exit();
}
if(write(fd,&buffer[(2*MAXNUM)/3],2*MAXNUM/3) != 2*MAXNUM/3)
{
printf("Write error 3\n");
exit();
}
if(lseek(fd,0L,0) != 0)
{
printf("Seek error\n");
}
close(fd);
if((fd=open("test.dat",0,1)) < 0)
{
printf("Cannot re-open test file\n");
exit();
}
for(i=0; i<MAXNUM; i++)
{
if(read(fd,&chk[i],2) != 2)
{
printf("Read failure at offset=%d\n",i*2);
}
}
for(i=0; i<MAXNUM; i++)
{
if(chk[i] != i)
printf("Compare error file=%4d i=%4d\n",buffer[i],i);
}
exit();
}

View File

@@ -0,0 +1,8 @@
.globl _xbarf
_xbarf:
link a6,#0 * C linkage convention
trap #15 * Do regular trap
lea 1,a0 * now
tst.w (a0) * address trap
unlk a6 * try to make
rts * it back