cpm commands

This commit is contained in:
Oliver Lehmann 1988-07-27 16:47:34 +00:00
parent 674f28f04b
commit f20c9dae40
1 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,87 @@
/* cflsbuf.c 1.10 83/05/13 */
#include <stdio.h>
#include "cpmio.h"
#include "cpmfio.h"
/*
* Flush a full block to floppy disk file
* (these routines are never called unless a full block is
* to be written)
* Create a new extent if required
*/
extern int flp_fmt;
c_flush(fptr)
register C_FILE *fptr;
{
int it;
int alloc();
if (!(fptr->c_flag & WRITE)) {
fprintf(stderr, "no write access");
return (EOF);
}
fptr->c_seccnt += blksiz/128;
fptr -> c_blk -= flp_fmt;
it = getblno( fptr );
if (putblock( it, fptr->c_base, -1) == EOF)
return (EOF);
if (fptr->c_blk == 16) {
fptr->c_dirp->blkcnt = (char) 0x80;
savedir();
/* create lew extent */
if ((it = creext(fptr->c_ext)) == NULL) {
fprintf(stderr,"can't create new extent, current: %d\n",
fptr->c_ext);
return (EOF);
}
fptr->c_dirp = dirbuf+it;
fptr->c_ext = it;
fptr->c_blk = 0;
fptr->c_seccnt = 0;
fptr->c_extno++;
fptr->c_dirp->extno= fptr->c_extno;
}
fptr->c_buf = fptr->c_base;
fptr->c_cnt = blksiz;
it = alloc();
if( it == 0 ) {
fprintf(stderr, "disk full\n");
return (EOF);
}
putblno( fptr, it );
return (0);
}
c_flsbuf(c, fptr)
register C_FILE *fptr;
{
if (c_flush(fptr) == EOF)
return (EOF);
*(fptr->c_buf++) = c;
fptr->c_cnt--;
return (c);
}
/*
* move the contents of 'buf' into the cpm block buffer,
* flush the buffer if full (for binary file transfers)
*/
c_write(fptr, buf, cnt)
register C_FILE *fptr;
char *buf;
{
int i = cnt;
while (i-- > 0) {
*(fptr->c_buf++) = *(buf++);
if (--fptr->c_cnt == 0)
if (c_flush(fptr) == EOF)
return (EOF);
}
return (cnt);
}