mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-24 08:54:17 +00:00
Upload
Digital Research
This commit is contained in:
55
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/vms/getc.c
Normal file
55
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/vms/getc.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#define BLEN 512
|
||||
|
||||
struct iob {
|
||||
int fd; /*file descriptor*/
|
||||
int cc; /*char count*/
|
||||
char *cp; /*ptr to next char*/
|
||||
char cbuf[BLEN]; /*char buffer*/
|
||||
};
|
||||
|
||||
fopen(fname,ibuf,x)
|
||||
char *fname;
|
||||
register struct iob *ibuf;
|
||||
int x;
|
||||
{
|
||||
|
||||
ibuf->cc = 0; /*no chars*/
|
||||
x = (x == 0) ? 0 : 1;
|
||||
return(ibuf->fd=open(fname,0,x));
|
||||
}
|
||||
|
||||
char getc(ibuf)
|
||||
register struct iob *ibuf;
|
||||
{
|
||||
char c;
|
||||
if(ibuf->cc<=0) {
|
||||
ibuf->cp = &(ibuf->cbuf[0]);
|
||||
ibuf->cc = read(ibuf->fd,ibuf->cp,BLEN);
|
||||
}
|
||||
if(ibuf->cc <= 0) {
|
||||
if(read(ibuf->fd,&c,1) != 1)
|
||||
return(-1);
|
||||
else
|
||||
return(c);
|
||||
}
|
||||
ibuf->cc--;
|
||||
return((int)(*(ibuf->cp)++)&0xff);
|
||||
}
|
||||
|
||||
getw(ibuf)
|
||||
register struct iob *ibuf;
|
||||
{
|
||||
|
||||
register int j;
|
||||
register int i;
|
||||
|
||||
if((j=getc(ibuf)) == -1)
|
||||
return(-1);
|
||||
i = j&0377;
|
||||
if((j=getc(ibuf)) == -1)
|
||||
return(-1);
|
||||
i =| (j&0377)<<8;
|
||||
if(i&0100000)
|
||||
i =| 0xffff0000; /* make it negative */
|
||||
return(i);
|
||||
}
|
||||
Reference in New Issue
Block a user