mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-25 01:14:21 +00:00
Upload
Digital Research
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
********************************************************************
|
||||
*
|
||||
* CP/M abort function for C Run Time Library
|
||||
*
|
||||
* "abort" generates an Illegal Instruction Trap to recall DDT
|
||||
* (if it is loaded).
|
||||
*
|
||||
*********************************************************************
|
||||
illegal = $4AFC
|
||||
.globl _abort
|
||||
.text
|
||||
_abort:
|
||||
move.w 4(sp),d0
|
||||
a: .dc.w illegal
|
||||
bra.b a * For Wise Guys
|
||||
@@ -0,0 +1,63 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* a c c e s s F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "access" returns 0 if access to a file is allowed, -1 o.w.
|
||||
* Under CP/M, this just tests for existence.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = access(fname,mode)
|
||||
* Where:
|
||||
* ret = 0 if accessable, -1 o.w.
|
||||
* fname -> file's name, NULL terminated string
|
||||
* mode = test for read, write, exec, dir path access
|
||||
* (ignored by CP/M)
|
||||
*
|
||||
* Made O/S independent 20-Aug-83 sw
|
||||
* Added chmod & chown to this source module 16-Sep-83 whf
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
#include "osiferr.h"
|
||||
#include "errno.h"
|
||||
|
||||
WORD access(fname,mode) /* CLEAR FUNCTION ***********/
|
||||
BYTE *fname;
|
||||
WORD mode;
|
||||
{
|
||||
REG WORD rval;
|
||||
|
||||
if ((rval=open(fname,READ)) >= 0 ) /* File must be there ... */
|
||||
{
|
||||
close(rval); /* Free up fd */
|
||||
return(SUCCESS);
|
||||
}
|
||||
RETERR(FAILURE,ENOENT);
|
||||
}
|
||||
|
||||
|
||||
/***************************************/
|
||||
/* chmod - change mode: NOP under CP/M */
|
||||
/***************************************/
|
||||
WORD chmod(name,mode) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name;
|
||||
WORD mode;
|
||||
{
|
||||
return(access(name,mode));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/* chown - change owner: like access() under CP/M */
|
||||
/**************************************************/
|
||||
WORD chown(name,owner,group) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name;
|
||||
WORD owner;
|
||||
WORD group;
|
||||
{
|
||||
return(access(name,0));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
.globl _ldiv
|
||||
.globl _aldiv
|
||||
.globl aldiv
|
||||
.text
|
||||
_aldiv:
|
||||
aldiv:
|
||||
~~aldiv:
|
||||
~l2=12
|
||||
~al1=8
|
||||
link R14,#-2
|
||||
move.l 12(R14),-(sp)
|
||||
move.l 8(R14),R8
|
||||
move.l (R8),-(sp)
|
||||
jsr _ldiv
|
||||
cmpm.l (sp)+,(sp)+
|
||||
move.l 8(R14),R9
|
||||
move.l R0,(R9)
|
||||
L1:
|
||||
unlk R14
|
||||
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* A L L O C C / F R E E C R O U T I N E S
|
||||
* ---------------------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Routines "allocc" and "freec" are used to allocate / deallocate a
|
||||
* channel number so that the user may do I/O directly without the OTS
|
||||
* getting in the way.
|
||||
* Note that this scheme preserves compatibility with OS's that really
|
||||
* truly use channels, and allows users to inform the C Run Time Library
|
||||
* routines that they are using the channel.
|
||||
* It's not important to use these routines under CP/M, since CP/M
|
||||
* allows you to have as many FCBs as you wish.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* i = allocc();
|
||||
* freec(i);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <portab.h> /* Include std definitions */
|
||||
#include <cpm.h> /* Also CP/M ones */
|
||||
#include <errno.h> /* for error returns */
|
||||
LONG _chvec ={0}; /* Allocate storage */
|
||||
WORD allocc() /****************************/
|
||||
{ /* */
|
||||
REG WORD i; /* Define 2 temporaries */
|
||||
REG LONG j; /* */
|
||||
/* */
|
||||
j = 1; /* Start with channel 0 */
|
||||
for(i=0;i<MAXCCBS;i++) /* Look at the bits */
|
||||
{ /* */
|
||||
if((j & _chvec) == 0) /* If 0, then channel free */
|
||||
{ /* */
|
||||
_chvec |= j; /* set allocated bit */
|
||||
return(i); /* and return the channel # */
|
||||
} /* */
|
||||
j = j << 1; /* Up to next bit */
|
||||
} /* End FOR loop */
|
||||
RETERR(FAILURE,EMFILE); /* All channels in use! */
|
||||
} /****************************/
|
||||
|
||||
WORD freec(ch) /****************************/
|
||||
REG WORD ch; /* Channel number to free */
|
||||
{ /* */
|
||||
_chvec &= ~(1 << ch); /* Clear appropriate bit */
|
||||
return(SUCCESS); /* Return OK */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,19 @@
|
||||
.text
|
||||
.globl almul
|
||||
.globl lmul
|
||||
*
|
||||
* / this routine multiplies together two 32 bit signed long integers.
|
||||
* / the first arg is a pointer to the long, which is multiplied by the
|
||||
* / second arg, with the result being stored at the firstarg.
|
||||
* / lmul.s does the meat of the work
|
||||
*
|
||||
almul:
|
||||
move.l A5,-(sp)
|
||||
move.l 8(sp),A5
|
||||
move.l 12(sp),-(sp)
|
||||
move.l (A5),-(sp)
|
||||
jsr lmul
|
||||
add #8,sp
|
||||
move.l R0,(A5)
|
||||
move.l (sp)+,A5
|
||||
rts
|
||||
@@ -0,0 +1,22 @@
|
||||
.globl _ldiv
|
||||
.globl _ldivr
|
||||
.comm _ldivr,4
|
||||
.globl _alrem
|
||||
.globl alrem
|
||||
.text
|
||||
_alrem:
|
||||
alrem:
|
||||
~~alrem:
|
||||
~l2=12
|
||||
~al1=8
|
||||
link R14,#-2
|
||||
move.l 12(R14),-(sp)
|
||||
move.l 8(R14),R8
|
||||
move.l (R8),-(sp)
|
||||
jsr _ldiv
|
||||
cmpm.l (sp)+,(sp)+
|
||||
move.l _ldivr,R0
|
||||
move.l 8(R14),R9
|
||||
move.l R0,(R9)
|
||||
unlk R14
|
||||
rts
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifdef IN_SCCS_ID
|
||||
static char S_assert.h [] = "@(#)assert.h 3.1 11:30:01 - 82/01/26 ";
|
||||
#endif IN_SCCS_ID
|
||||
# ifndef NDEBUG
|
||||
# define _assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);exit(1);}}
|
||||
# def
|
||||
ine assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);exit(1);}}
|
||||
# else
|
||||
# define _assert(ex) ;
|
||||
# define assert(ex) ;
|
||||
28
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/atoi.c
Normal file
28
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/atoi.c
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
/* atoi - convert decimal number in ascii to integer */
|
||||
|
||||
#include "portab.h"
|
||||
#include "ctype.h"
|
||||
|
||||
WORD atoi(str) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *str;
|
||||
{
|
||||
REG WORD val;
|
||||
REG WORD isneg;
|
||||
|
||||
val = 0;
|
||||
isneg = FALSE;
|
||||
while( isspace(*str) )
|
||||
str++;
|
||||
if( *str == '+' )
|
||||
str++;
|
||||
else if( *str == '-' ) {
|
||||
str++;
|
||||
isneg++;
|
||||
}
|
||||
while( *str >= '0' && *str <= '9' )
|
||||
val = 10 * val + ( *str++ - '0' );
|
||||
if( isneg )
|
||||
val = -val;
|
||||
return( val );
|
||||
}
|
||||
29
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/atol.c
Normal file
29
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/atol.c
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
/* atol - convert decimal number in ascii to long integer */
|
||||
|
||||
#include "portab.h"
|
||||
#include "ctype.h"
|
||||
|
||||
LONG atol(str) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *str;
|
||||
{
|
||||
REG LONG val;
|
||||
REG WORD isneg;
|
||||
|
||||
val = 0L;
|
||||
isneg = FALSE;
|
||||
while( isspace(*str) )
|
||||
str++;
|
||||
if( *str == '+' )
|
||||
str++;
|
||||
else if( *str == '-' ) {
|
||||
str++;
|
||||
isneg++;
|
||||
}
|
||||
while( *str >= '0' && *str <= '9' )
|
||||
val = 10 * val + ( *str++ - '0' );
|
||||
if( isneg )
|
||||
val = -val;
|
||||
return( val );
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* B A S E P A G E . H */
|
||||
/* ------------------- */
|
||||
/* */
|
||||
/* This file contains a definition of the CP/M basepage structure, */
|
||||
/* b_page. */
|
||||
/* */
|
||||
/* NOTE: In the portable CP/M environment, it is NOT guaranteed */
|
||||
/* that the location of the base page is known at link-edit time */
|
||||
/* (as it is, for example, in CP/M-80 and CP/M-86.) Instead, a */
|
||||
/* pointer to the current basepage is delivered by the BDOS */
|
||||
/* to each new program which is run. This pointer, _base, is */
|
||||
/* initialized by the C startup function (startup.s) and is */
|
||||
/* available to C programs as an external. */
|
||||
/* */
|
||||
/* "cpm.h" MUST be '#include'd before this file */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
struct b_page
|
||||
{
|
||||
BYTE *ltpa; /* Low TPA address */
|
||||
BYTE *htpa; /* High TPA address */
|
||||
BYTE *lcode; /* Start address of code seg*/
|
||||
LONG codelen; /* Code segment length */
|
||||
BYTE *ldata; /* Start address of data seg*/
|
||||
LONG datalen; /* Data segment length */
|
||||
BYTE *lbss; /* Start address of bss seg */
|
||||
LONG bsslen; /* Bss segment length */
|
||||
LONG freelen; /* Free segment length */
|
||||
BYTE resvd1[20]; /* Reserved area */
|
||||
struct fcb fcb2; /* Second basepage FCB */
|
||||
struct fcb fcb1; /* First basepage FCB */
|
||||
BYTE buff[128]; /* Default DMA buffer, */
|
||||
/* command line tail */
|
||||
};
|
||||
|
||||
extern struct b_page *_base;
|
||||
367
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/bdos.h
Normal file
367
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/bdos.h
Normal file
@@ -0,0 +1,367 @@
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* B D O S . H */
|
||||
/* ----------- */
|
||||
/* */
|
||||
/* Copyright (c) 1982, Zilog Incorporated */
|
||||
/* */
|
||||
/* Macros defining the direct BDOS calls used by the standard CP/M */
|
||||
/* utilities (ED, PIP, STAT, SET, SHOW.) Some necessary data */
|
||||
/* data structures are also defined. */
|
||||
/* */
|
||||
/* All macros return a long value, even when the BDOS function they */
|
||||
/* call does produce a return parameter. */
|
||||
/* */
|
||||
/* This header file can be used applications which do not require */
|
||||
/* to use the C standard I/O library functions. For applications */
|
||||
/* which require the library, but which wish to make use of the */
|
||||
/* additional information in this file, cpm.h should be included in */
|
||||
/* the source ahead of this file. The compiler flags multiple */
|
||||
/* definition errors if this ordering is not observed. */
|
||||
/* */
|
||||
/* portab.h must always be included ahead of this file. */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
extern long __BDOS(); /* BDOS entry point */
|
||||
|
||||
#define XADDR long /* 32-bit address data type */
|
||||
|
||||
/****************************************************************************/
|
||||
/* The following BDOS calls are defined in cpm.h. Define them only if they */
|
||||
/* are not defined already. */
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef EXIT /* Find out where we stand */
|
||||
/* Define if necessary */
|
||||
#define EXIT 0 /* Exit to BDOS */
|
||||
#define CONOUT 2 /* Direct console output */
|
||||
#define LSTOUT 5 /* Direct list device output*/
|
||||
#define CONIO 6 /* Direct console I/O */
|
||||
#define CONBUF 10 /* Read console buffer */
|
||||
#define OPEN 15 /* OPEN a disk file */
|
||||
#define CLOSE 16 /* Close a disk file */
|
||||
#define DELETE 19 /* Delete a disk file */
|
||||
#define CREATE 22 /* Create a disk file */
|
||||
#define SETDMA 26 /* Set DMA address */
|
||||
#define B_READ 33 /* Read Random record */
|
||||
#define B_WRITE 34 /* Write Random record */
|
||||
#define FILSIZ 35 /* Compute File Size */
|
||||
#define SETMSC 44 /* Set Multi-Sector Count */
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************/
|
||||
/* The following BDOS calls are not defined in cpm.h */
|
||||
/****************************************************************************/
|
||||
|
||||
#define CONIN 1 /* Single char I/P with echo*/
|
||||
#define READER 3 /* Paper tape input */
|
||||
#define PUNCH 4 /* Paper tape output */
|
||||
#define GET_IOB 7 /* Get I/O byte */
|
||||
#define SET_IOB 8 /* Set I/O byte */
|
||||
#define PRINT 9 /* Print $-terminated line */
|
||||
#define CONSTAT 11 /* Check if I/P char waiting*/
|
||||
#define VERSION 12 /* Return version number */
|
||||
#define RS_DISK 13 /* Reset disk system */
|
||||
#define SEL_DISK 14 /* Select disk */
|
||||
#define SRCH_1ST 17 /* Search 1st filename match*/
|
||||
#define SRCH_NEXT 18 /* Search next match */
|
||||
#define S_READ 20 /* Sequential read from file*/
|
||||
#define S_WRITE 21 /* Sequential write to file */
|
||||
#define RENAME 23 /* Rename a file */
|
||||
#define RET_LOGIN 24 /* Return login vector */
|
||||
#define RET_CDISK 25 /* Return current disk */
|
||||
#define GET_ALLOC 27 /* Get allocation vector */
|
||||
#define WR_PROTD 28 /* Write protect disk */
|
||||
#define GET_RO 29 /* Get read-only vector */
|
||||
#define SET_ATT 30 /* Set file attributes */
|
||||
#define GET_DPB 31 /* Get disk parameters */
|
||||
#define GSET_UCODE 32 /* Get/set user code */
|
||||
#define SET_RAND 36 /* Set random record */
|
||||
#define RS_DRIVE 37 /* Reset disk specified drv */
|
||||
/* 38, 39 not used */
|
||||
#define B_WRZF 40 /* Write random, zero fill */
|
||||
/* 41 - 43 not used */
|
||||
#define RET_ERRORS 45 /* Set error return mode */
|
||||
#define GET_DFS 46 /* Get free disk space */
|
||||
#define CHAIN 47 /* Chain to program via CCP */
|
||||
#define FLUSH 48 /* Flush buffers to disk */
|
||||
#define GSET_SCB 49 /* Get/set system control bk*/
|
||||
#define BIOS_CALL 50 /* Direct call to BIOS */
|
||||
/* 51 - 58 not used */
|
||||
#define PROG_LOAD 59 /* Program load */
|
||||
/* 60 unused */
|
||||
#define SET_EXV 61 /* Set exception vector */
|
||||
#define SET_SUP 62 /* Set supervisor state */
|
||||
#define SET_LABEL 100 /* Set directory label */
|
||||
#define GET_LABEL 101 /* Get directory label */
|
||||
#define GET_XFCB 102 /* Get extended FCB */
|
||||
#define SET_XFCB 103 /* Set extended FCB */
|
||||
#define COND_LST 161 /* Conditionally attach LST:*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* The macros themselves... */
|
||||
/****************************************************************************/
|
||||
|
||||
#define _conin() (__BDOS(CONIN, (long) 0))
|
||||
|
||||
#define _conout(a) (__BDOS(CONOUT, (long) (a)))
|
||||
|
||||
#define _reader() (__BDOS(READER, (long) 0))
|
||||
|
||||
#define _punch(a) (__BDOS(PUNCH, (long) (a)))
|
||||
|
||||
#define _lstout(a) (__BDOS(LSTOUT, (long) (a)))
|
||||
|
||||
#define _conio(a) (__BDOS(CONIO, (long) (a)))
|
||||
|
||||
#define _get_iob() (__BDOS(GET_IOB, (long) 0))
|
||||
|
||||
#define _set_iob(a) (__BDOS(SET_IOB, (long) (a)))
|
||||
|
||||
#define _print(a) (__BDOS(PRINT, (long) (a)))
|
||||
|
||||
#define _conbuf(a) (__BDOS(CONBUF, (long) (a)))
|
||||
|
||||
#define _constat() (__BDOS(CONSTAT, (long) 0))
|
||||
|
||||
#define _version() (__BDOS(VERSION, (long) 0))
|
||||
|
||||
#define _rs_disk(a) (__BDOS(RS_DISK, (long) (a)))
|
||||
|
||||
#define _sel_disk(a) (__BDOS(SEL_DISK, (long) (a)))
|
||||
|
||||
#define _open(a) (__BDOS(OPEN, (long) (a)))
|
||||
|
||||
#define _close(a) (__BDOS(CLOSE, (long) (a)))
|
||||
|
||||
#define _srch_1st(a) (__BDOS(SRCH_1ST, (long) (a)))
|
||||
|
||||
#define _srch_next() (__BDOS(SRCH_NEXT, (long) 0))
|
||||
|
||||
#define _delete(a) (__BDOS(DELETE, (long) (a)))
|
||||
|
||||
#define _s_read(a) (__BDOS(S_READ, (long) (a)))
|
||||
|
||||
#define _s_write(a) (__BDOS(S_WRITE, (long) (a)))
|
||||
|
||||
#define _create(a) (__BDOS(CREATE, (long) (a)))
|
||||
|
||||
#define _rename(a) (__BDOS(RENAME, (long) (a)))
|
||||
|
||||
#define _ret_login() (__BDOS(RET_LOGIN, (long) 0))
|
||||
|
||||
#define _ret_cdisk() (__BDOS(RET_CDISK, (long) 0))
|
||||
|
||||
#define _setdma(a) (__BDOS(SETDMA, (long) (a)))
|
||||
|
||||
#define _get_alloc() (__BDOS(GET_ALLOC, (long) 0))
|
||||
|
||||
#define _wr_protd() (__BDOS(WR_PROTD, (long) 0))
|
||||
|
||||
#define _get_ro() (__BDOS(GET_RO, (long) 0))
|
||||
|
||||
#define _set_att(a) (__BDOS(SET_ATT, (long) (a)))
|
||||
|
||||
/* _get_dpb has parameter in*/
|
||||
/* some implementations */
|
||||
/* of CP/M but not others */
|
||||
/* This macro suitable only */
|
||||
/* for former */
|
||||
#define _get_dpb(a) (__BDOS(GET_DPB, (long) (a)))
|
||||
/* This one handles latter */
|
||||
#define _get_dpa() (__BDOS(GET_DPB, (long) 0))
|
||||
|
||||
#define _gset_ucode(a) (__BDOS(GSET_UCODE, (long) (a)))
|
||||
|
||||
#define _b_read(a) (__BDOS(B_READ, (long) (a)))
|
||||
|
||||
#define _b_write(a) (__BDOS(B_WRITE, (long) (a)))
|
||||
|
||||
#define _filsiz(a) (__BDOS(FILSIZ, (long) (a)))
|
||||
|
||||
#define _set_rand(a) (__BDOS(SET_RAND, (long) (a)))
|
||||
|
||||
#define _rs_drive(a) (__BDOS(RS_DRIVE, (long) (a)))
|
||||
|
||||
#define _b_wrzf(a) (__BDOS(B_WRZF, (long) (a)))
|
||||
|
||||
#define _setmsc(a) (__BDOS(SETMSC, (long) (a)))
|
||||
|
||||
#define _ret_errors(a) (__BDOS(RET_ERRORS, (long) (a)))
|
||||
|
||||
#define _get_dfs(a) (__BDOS(GET_DFS, (long) (a)))
|
||||
|
||||
#define _chain() (__BDOS(CHAIN, (long) 0))
|
||||
|
||||
#define _flush() (__BDOS(FLUSH, (long) 0))
|
||||
|
||||
#define _gset_scb(a) (__BDOS(GSET_SCB, (long) (a)))
|
||||
|
||||
#define _bios_call(a) (__BDOS(BIOS_CALL, (long) (a)))
|
||||
|
||||
#define _prog_load(a) (__BDOS(PROG_LOAD, (long) (a)))
|
||||
|
||||
#define _set_exv(a) (__BDOS(SET_EXV, (long) (a)))
|
||||
|
||||
#define _set_sup(a) (__BDOS(SET_SUP, (long) 0))
|
||||
|
||||
#define _get_label(a) (__BDOS(GET_LABEL, (long) (a)))
|
||||
|
||||
#define _set_label(a) (__BDOS(SET_LABEL, (long) (a)))
|
||||
|
||||
#define _get_xfcb(a) (__BDOS(GET_XFCB, (long) (a)))
|
||||
|
||||
#define _set_xfcb(a) (__BDOS(SET_XFCB, (long) (a)))
|
||||
|
||||
#define _cond_lst() (__BDOS(COND_LST, (long) 0))
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* BIOS calls, for use in conjunction with BDOS call 50 & struct bios_parms */
|
||||
/****************************************************************************/
|
||||
|
||||
#define _INIT 0 /* Cold start */
|
||||
#define _WARM 1 /* Warm start */
|
||||
#define _CONST 2 /* Console status */
|
||||
#define _CONIN 3 /* Read console character */
|
||||
#define _CONOUT 4 /* Write console character */
|
||||
#define _LIST 5 /* Write listing character */
|
||||
#define _PUNCH 6 /* Write punch character */
|
||||
#define _READER 7 /* Read tape character */
|
||||
#define _HOME 8 /* Move to track 0 */
|
||||
#define _SELDSK 9 /* Select disk drive */
|
||||
#define _SETTRK 10 /* Set track number */
|
||||
#define _SETSEC 11 /* Set sector number */
|
||||
#define _SETDMA 12 /* Set DMA address */
|
||||
#define _READ 13 /* Read selected sector */
|
||||
#define _WRITE 14 /* Write selected sector */
|
||||
#define _LISTST 15 /* Return list status */
|
||||
#define _GETMRT 16 /* Get memory region table */
|
||||
/* address */
|
||||
#define _GETIOB 17 /* Get IOBYTE value */
|
||||
#define _SETIOB 18 /* Set IOBYTE value */
|
||||
#define _FLUSH 19 /* Flush buffers */
|
||||
#define _SETEXC 20 /* Set exception vector */
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* FCB structure is defined in cpm.h. Define it here only if it is not */
|
||||
/* defined already. Declare some useful values at the same time. */
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef SECSIZ /* Not already declared? */
|
||||
|
||||
struct fcbtab /* File control block */
|
||||
{ /* */
|
||||
BYTE drive; /* Disk drive field */
|
||||
BYTE fname[8]; /* File name */
|
||||
BYTE ftype[3]; /* File type */
|
||||
BYTE extent; /* Current extent number */
|
||||
BYTE s1,s2; /* "system reserved" */
|
||||
BYTE reccnt; /* Record counter */
|
||||
BYTE resvd[16]; /* More "system reserved" */
|
||||
LONG record; /* Note -- we overlap the */
|
||||
/* current record field to */
|
||||
/* make this useful. */
|
||||
};
|
||||
|
||||
#define fcb fcbtab /* A useful synonym */
|
||||
#define SECSIZ 128 /* size of CP/M sector */
|
||||
#define _MAXSXFR 1 /* max # sectors xferrable */
|
||||
#define _MAXSHFT 12 /* shift right BDOS rtn val */
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************/
|
||||
/* Data structures not defined in cpm.h */
|
||||
/****************************************************************************/
|
||||
|
||||
struct dpbs /* Disk parameter block */
|
||||
{
|
||||
UWORD spt; /* Sectors per track */
|
||||
BYTE bls; /* Block shift factor */
|
||||
BYTE bms; /* Block mask */
|
||||
BYTE exm; /* Extent mark */
|
||||
/* BYTE filler; *** Pad to align words ***/
|
||||
UWORD mxa; /* Maximum allocation (blks)*/
|
||||
UWORD dmx; /* Max directory entries */
|
||||
UWORD dbl; /* Directory alloc. map */
|
||||
UWORD cks; /* Directory checksum */
|
||||
UWORD ofs; /* Track offset from track 0*/
|
||||
};
|
||||
|
||||
struct bios_parm /* BIOS parameters for BDOS */
|
||||
{ /* call 50 */
|
||||
UWORD req; /* BIOS request code */
|
||||
LONG p1; /* First parameter */
|
||||
LONG p2; /* Second parameter */
|
||||
};
|
||||
|
||||
struct scbs /* System control block */
|
||||
{
|
||||
BYTE resvd_1[6]; /* Reserved for system use */
|
||||
BYTE u_flags[4]; /* Utility flags */
|
||||
BYTE d_flags[4]; /* Display flags */
|
||||
BYTE clp_flags[2]; /* Command Line Proc flags */
|
||||
UWORD p_error; /* Program error return code*/
|
||||
BYTE resvd_2[8]; /* Reserved for system use */
|
||||
BYTE con_w; /* Console width */
|
||||
BYTE con_c; /* Console column */
|
||||
BYTE con_l; /* Console page length */
|
||||
BYTE resvd_3[5]; /* Reserved for system use */
|
||||
UWORD conin_r; /* CONIN redirection flag */
|
||||
UWORD conout_r; /* CONOUT redirection flag */
|
||||
UWORD auxin_r; /* AUXIN redirection flag */
|
||||
UWORD auxout_r; /* AUXOUT redirection flag */
|
||||
UWORD lstout_r; /* LSTOUT redirection flag */
|
||||
BYTE resvd_4[2]; /* Reserved for system use */
|
||||
BOOLEAN ctl_h_a; /* Backspace active */
|
||||
BOOLEAN rubout_a; /* Rubout active */
|
||||
BYTE resvd_5[2]; /* Reserved for system use */
|
||||
UWORD c_xlate; /* Console translate func. */
|
||||
UWORD con_m; /* Console mode (raw/cooked)*/
|
||||
UWORD buff_a; /* 128 byte buffer available*/
|
||||
BYTE o_delim; /* Output delimiter */
|
||||
BOOLEAN lo_flag; /* List output flag */
|
||||
BYTE resvd_6[2]; /* Reserved for system use */
|
||||
UWORD d_m_a; /* Current DMA address */
|
||||
BYTE disk_no; /* Current disk */
|
||||
BYTE bdos_info[2]; /* BDOS variable info */
|
||||
BYTE resvd_7[3]; /* Reserved for system use */
|
||||
BYTE user_no; /* Current user number */
|
||||
BYTE resvd_8[6]; /* Reserved for system use */
|
||||
BYTE bdos_mode; /* BDOS error mode */
|
||||
BYTE c_chain[4]; /* Current search chain */
|
||||
BYTE tmp_drv; /* Drive for temporary files*/
|
||||
BYTE resvd_9[7]; /* Reserved for system use */
|
||||
BYTE date_s[5]; /* Date stamp */
|
||||
BYTE error_jmp[3]; /* Error jump */
|
||||
UWORD cmb_a; /* Common memory base addr */
|
||||
UWORD bdos_ent; /* BDOS entry point */
|
||||
};
|
||||
|
||||
struct scbpb /* SCB parameter block */
|
||||
{
|
||||
BYTE off; /* Index to data in SCB */
|
||||
BYTE op; /* Operation: 0xff Set byte */
|
||||
/* 0xfe Set word */
|
||||
/* else Get word */
|
||||
UWORD val; /* Byte/word value to be set*/
|
||||
};
|
||||
|
||||
#define SET_BYTE 0xff
|
||||
#define SET_WORD 0xfe
|
||||
#define GET 0
|
||||
|
||||
/****************************************************************************/
|
||||
/* HILO must be defined for the Z8000. Undefine it first, in case cpm.h */
|
||||
/* has already defined it. The tagless structures defining byte ordering */
|
||||
/* which are declared in cpm.h are not redeclared here (the use of members */
|
||||
/* of tagless structures to define offsets is an obsolete feature of the C */
|
||||
/* language.) */
|
||||
/****************************************************************************/
|
||||
|
||||
#undef HILO
|
||||
#define HILO
|
||||
@@ -0,0 +1,21 @@
|
||||
.globl _sw_
|
||||
_sw_:
|
||||
.text
|
||||
tst.l d5
|
||||
beq ok
|
||||
move.l #-1,(sp) * Destroy the evidence
|
||||
divs #$0,d5
|
||||
ok: rts
|
||||
|
||||
*********************************************************
|
||||
* *
|
||||
* Copyright Notice Module *
|
||||
* *
|
||||
*********************************************************
|
||||
|
||||
.data
|
||||
___cpyrt: .dc.b 'CP/M-68K(tm), Version 1.2, '
|
||||
.dc.b 'Copyright (c) 1983, Digital Research '
|
||||
serial: .dc.b 'XXXX-0000-654321'
|
||||
.dc.w 0
|
||||
.end
|
||||
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* b l k f i l l F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1983 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The blkfill function sets a region of memory to a given value.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* blkfill(addr,fc,num);
|
||||
*
|
||||
* Where:
|
||||
* addr Is a pointer to region of memory to blkfill
|
||||
* fc Is a character to blkfill with
|
||||
* num Is the number of chars to blkfill with
|
||||
*
|
||||
****************************************************************************/
|
||||
#include <portab.h>
|
||||
|
||||
VOID blkfill(addr,fc,num) /* CLEAR FUNCTION ***********/
|
||||
BYTE *addr;
|
||||
BYTE fc;
|
||||
WORD num;
|
||||
{
|
||||
while( num-- > 0 )
|
||||
*addr++ = fc;
|
||||
}
|
||||
115
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/blkio.c
Normal file
115
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/blkio.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* _ b l k i o F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982,1983 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The _blkio function is used to read / write a set of contiguous
|
||||
* sectors in an open file.
|
||||
* Note: if CPM, it will use CP/M function 44 (Set Multi-Sector Count)
|
||||
* if os_multisectorio is TRUE (BDOS versions 3.0 and above).
|
||||
* Note 2: if PC-DOS, it will use block read and write functions.
|
||||
*
|
||||
* Edits:
|
||||
* 8-Dec-83 whf handle PC-DOS changes.
|
||||
*
|
||||
* Calling Sequence:
|
||||
* ret = _blkio(ccbp,sector,buffer,count,bdosfunc);
|
||||
*
|
||||
* Where:
|
||||
* ret = sectors actually read/written
|
||||
* ccbp -> the open file channel control block
|
||||
* sector = The desired starting sector number
|
||||
* buffer = The memory address to begin transfer
|
||||
* count = the number of sectors to read/write
|
||||
* bdosfunc= The BDOS function number (B_READ / B_WRITE)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
#include "osiferr.h"
|
||||
#include "osattr.h"
|
||||
|
||||
#define MIN(x,y) ( ((x) < (y)) ? (x) : (y) )
|
||||
|
||||
LONG
|
||||
_blkio(ccbp,sector,buffer,count,bdosfunc)
|
||||
/****************************/
|
||||
FD *ccbp; /* open file pointer */
|
||||
LONG sector; /* Sector number */
|
||||
BYTE *buffer; /* User's buffer area */
|
||||
LONG count; /* # of sectors to do */
|
||||
int bdosfunc; /* BDOS function to use */
|
||||
{ /****************************/
|
||||
|
||||
#if PCDOS /*=============================================================*/
|
||||
REG WORD seccnt; /* number sectors xferred */
|
||||
WORD _pc_readblk(), _pc_writeblk(); /* functions to read/write */
|
||||
|
||||
if( bdosfunc == B_READ )
|
||||
return _pc_readblk(&(ccbp->fcb),sector,buffer,(WORD)count,SECSIZ);
|
||||
else return _pc_writeblk(&(ccbp->fcb),sector,buffer,(WORD)count,SECSIZ);
|
||||
}
|
||||
|
||||
#endif /*==============================================================*/
|
||||
|
||||
|
||||
#if CPM /*==============================================================*/
|
||||
WORD nsecs; /* # secs to xfer each time */
|
||||
LONG seccnt; /* # sectors processed */
|
||||
WORD xuser; /* old user number */
|
||||
WORD retcode; /* return code from BDOS */
|
||||
WORD Used_Multisec; /* flag for resetting msecio*/
|
||||
/****************************/
|
||||
seccnt = 0; /* Zero count initally */
|
||||
Used_Multisec = 0; /* Haven't used it yet */
|
||||
xuser = _chkuser(ccbp->user); /* Check for changed user # */
|
||||
nsecs = 1; /* default: xfer singly */
|
||||
/* */
|
||||
while (count > 0) /* Until all sectors xferred*/
|
||||
{ /* */
|
||||
__OSIF(SETDMA,buffer); /* Set new DMA address */
|
||||
|
||||
#if HILO /*==========================================================*/
|
||||
ccbp->fcb.record = sector; /* Set new record number */
|
||||
#else /*----------------------------------------------------------*/
|
||||
ccbp->fcb.record = sector << 8; /* Set new record number */
|
||||
#endif /*==========================================================*/
|
||||
|
||||
/* Multi Sector I/O xfer? */
|
||||
if( (count > 1 && os_multisectorio ) || nsecs > 1 )
|
||||
{ /* yes! */
|
||||
if( os_oldmultisec )
|
||||
nsecs = MIN(16,count); /* Older version of msecio */
|
||||
else nsecs = MIN(128,count);/* Later version of msecio */
|
||||
++Used_Multisec; /* Flag: need to reset */
|
||||
__OSIF(F_MULTISEC,nsecs); /* make the call */
|
||||
} /******* */
|
||||
/****************************/
|
||||
retcode = __OSIF(bdosfunc,&(ccbp->fcb));/* do the read/write*/
|
||||
/****************************/
|
||||
if(retcode != 0)
|
||||
{ /****************************/
|
||||
if(nsecs>1) /* were we trying multi-sec?*/
|
||||
{ /* yes! do error handling */
|
||||
if( os_oldmultisec ) /* Older msecio? */
|
||||
nsecs = __cpmrv >> 12; /* adjust nsecs read like so*/
|
||||
else nsecs = __cpmrv >> 8;/* later versions: use AH */
|
||||
} /*** */
|
||||
else nsecs = 0; /* ow. assume 0 secs read */
|
||||
seccnt += nsecs; /* Return nfg */
|
||||
break; /* Return from bottom */
|
||||
} /****************************/
|
||||
/* */
|
||||
sector += nsecs; /* Increment sector number */
|
||||
count -= nsecs; /* Down count */
|
||||
seccnt += nsecs; /* Bump sector count */
|
||||
buffer += nsecs*SECSIZ; /* Increment address */
|
||||
} /****************************/
|
||||
_uchkuser(ccbp->user,xuser); /* Reset user # if needed */
|
||||
if( Used_Multisec ) /* Need to reset msecio? */
|
||||
__OSIF(F_MULTISEC,1); /* then do so... */
|
||||
return(seccnt); /* All is OK */
|
||||
} /****************************/
|
||||
#endif /*==================================================================*/
|
||||
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* b l k m o v e F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1983, by Digital Research Inc.
|
||||
*
|
||||
* "blkmove()" moves a block of bytes from one address to another.
|
||||
*
|
||||
* Calling sequence:
|
||||
* blkmove(to,from,nn)
|
||||
* Where:
|
||||
* 'to' points to destination
|
||||
* 'from' points to source, and
|
||||
* 'nn' is the number of chars to move
|
||||
*
|
||||
***************************************************************************/
|
||||
#include <portab.h>
|
||||
|
||||
VOID blkmove(to,from,nn) /* CLEAR FUNCTION ***********/
|
||||
BYTE *to, *from;
|
||||
WORD nn;
|
||||
{
|
||||
if( to < from )
|
||||
while(nn--)
|
||||
*to++ = *from++;
|
||||
else
|
||||
for( to += nn, from += nn; nn--; )
|
||||
*--to = *--from;
|
||||
@@ -0,0 +1,9 @@
|
||||
cp68 -i 0: $1.c $1.i
|
||||
c068 $1.i $1.1 $1.2 $1.3 -f
|
||||
era $1.i
|
||||
c168 $1.1 $1.2 $1.s
|
||||
era $1.1
|
||||
era $1.2
|
||||
as68 -l -u $1.s
|
||||
era $1.s
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/********************************************************************
|
||||
*
|
||||
* calloc.c - memory allocator for sets of elements
|
||||
* zalloc - memory allocator like malloc only zeros storage.
|
||||
*
|
||||
* BYTE *calloc(nelem,sizelem)
|
||||
* WORD nelem, sizelem;
|
||||
*
|
||||
* Returns a pointer to a region of (zero filled) memory large
|
||||
* enough to hold 'nelem' items each of size 'sizelem'.
|
||||
* Returns NULL if not enough memory.
|
||||
*
|
||||
* BYTE *zalloc(nbytes)
|
||||
* UWORD nbytes;
|
||||
*
|
||||
* Returns a pointer to a region of zero filled memory nbytes long.
|
||||
* Returns NULL if not enough memory.
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
BYTE * zalloc(nbytes) /* CLEAR FUNCTION ***********/
|
||||
WORD nbytes; /* number of bytes */
|
||||
{
|
||||
REG BYTE *rp; /* pointer to region */
|
||||
BYTE *malloc();
|
||||
|
||||
if( (rp = malloc(nbytes)) == NULLPTR) return(NULLPTR);
|
||||
blkfill( rp, NULL, nbytes );
|
||||
return(rp);
|
||||
}
|
||||
|
||||
BYTE * calloc(nelem,sizelem) /* CLEAR FUNCTION ***********/
|
||||
WORD nelem, /* number of elements */
|
||||
sizelem; /* size of element */
|
||||
{
|
||||
return(zalloc(sizelem*nelem));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
cp68 -i 0: $1.c $1.i
|
||||
c068 $1.i $1.1 $1.2 $1.3 -e
|
||||
era $1.i
|
||||
c168 $1.1 $1.2 $1.s
|
||||
era $1.1
|
||||
era $1.2
|
||||
as68 -l -u -s 0: $1.s
|
||||
era $1.s
|
||||
|
||||
155
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/channels.c
Normal file
155
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/channels.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* C H A N N E L A L L O C A T I N G R O U T I N E S
|
||||
* -----------------------------------------------------
|
||||
* Copyright 1984 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Herein are all the routines which deal with Channel Control Block
|
||||
* (CCB) allocation and initialization. These routines (documented
|
||||
* individually below) are:
|
||||
*
|
||||
* i = _allocc();
|
||||
* _freec(i);
|
||||
* _chinit();
|
||||
* __chinit(fd)
|
||||
* ccbptr = _chkc(ch);
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include "portab.h" /* Include std definitions */
|
||||
#include "osif.h" /* Also CP/M ones */
|
||||
#include "osiferr.h" /* To set error vars */
|
||||
#include "errno.h" /* Error return vals */
|
||||
|
||||
#ifdef MAXF5 /*--------------------------*/
|
||||
# define MAXCCBS 5 /* Maximum Num CCBs */
|
||||
maxfiles5() { ; } /* stubroutine for option.h */
|
||||
#else /*--------------------------*/
|
||||
|
||||
#ifdef MAXF10 /*--------------------------*/
|
||||
# define MAXCCBS 10 /* Maximum Num CCBs */
|
||||
#else /*--------------------------*/
|
||||
# define MAXCCBS 16 /* Maximum Num CCBs */
|
||||
#endif /*--------------------------*/
|
||||
|
||||
#endif /*--------------------------*/
|
||||
|
||||
LONG _chvec ={0}; /* Allocate storage */
|
||||
FD _fds[MAXCCBS]; /* Allocate CCB storage */
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* _ A L L O C C / _ F R E E C R O U T I N E S
|
||||
* -------------------------------------------------
|
||||
* Routines "_allocc" and "_freec" are used to allocate / deallocate a
|
||||
* channel number so that the user may do I/O directly without the OTS
|
||||
* getting in the way.
|
||||
* Note that this scheme preserves compatibility with OS's that really
|
||||
* truly use channels, and allows users to inform the C Run Time Library
|
||||
* routines that they are using the channel.
|
||||
* It's not important to use these routines under CP/M, since CP/M
|
||||
* allows you to have as many FCBs as you wish.
|
||||
*
|
||||
* Calling Sequence:
|
||||
* i = _allocc();
|
||||
* _freec(i);
|
||||
*****************************************************************************/
|
||||
|
||||
WORD _allocc() /****************************/
|
||||
{ /* */
|
||||
REG WORD i; /* Define 2 temporaries */
|
||||
REG LONG j; /* */
|
||||
/* */
|
||||
j = 1; /* Start with channel 0 */
|
||||
for(i=0;i<MAXCCBS;i++) /* Look at the bits */
|
||||
{ /* */
|
||||
if((j & _chvec) == 0) /* If 0, then channel free */
|
||||
{ /* */
|
||||
_chvec |= j; /* set allocated bit */
|
||||
return(i); /* and return the channel # */
|
||||
} /* */
|
||||
j <<= 1; /* Up to next bit */
|
||||
} /* End FOR loop */
|
||||
RETERR(FAILURE,EMFILE); /* All channels in use! */
|
||||
} /****************************/
|
||||
|
||||
WORD _freec(ch) /****************************/
|
||||
WORD ch; /* Channel number to free */
|
||||
{ /* */
|
||||
_chvec &= ~(1 << ch); /* Clear appropriate bit */
|
||||
return(SUCCESS); /* Return OK */
|
||||
} /****************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C C B I N I T I A L I Z A T I O N
|
||||
* -----------------------------------
|
||||
* Routine "_chinit" is called from the run-time initialization to clear
|
||||
* out all the CCB storage.
|
||||
* Calling sequence:
|
||||
* _chinit();
|
||||
*
|
||||
* Routine "__chinit(fd)" is called from other low-level routines
|
||||
* for single channel initialization.
|
||||
* Calling sequence:
|
||||
* __chinit(fd)
|
||||
* where: fd = file descriptor #
|
||||
*****************************************************************************/
|
||||
|
||||
_chinit() /****************************/
|
||||
{ /* */
|
||||
REG WORD i; /* Index */
|
||||
for(i=0;i<MAXCCBS;i++) /* For all channels */
|
||||
__chinit(i); /* Init fds(i); */
|
||||
} /****************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* The __chinit routine initializes only 1 channel.
|
||||
*****************************************************************************/
|
||||
|
||||
__chinit(i)
|
||||
{ /****************************/
|
||||
REG FD *ch; /* -> CCB */
|
||||
REG BYTE *p; /* Byte pointer temporary */
|
||||
|
||||
ch = _getccb(i); /* convert fd to CCB */
|
||||
ch -> chan = i; /* Load channel byte */
|
||||
ch -> flags = 0; /* clear flag word */
|
||||
ch -> user = 0; /* assume user 0 */
|
||||
ch -> sector = -1; /* Set no sector in buff */
|
||||
ch -> offset = 0; /* Clear file offset word */
|
||||
ch -> hiwater = 0; /* Init hiwater mark */
|
||||
ch -> fcb.drive = 0; /* Init drive field of fcb */
|
||||
p = &ch->fcb.fname[0]; /* Set to file var */
|
||||
while (p< &ch->fcb.ftype[3]) /* Init file name fields */
|
||||
*p++ = ' '; /* To spaces */
|
||||
while (p < &ch->fcb.record) /* Init rest of fcb */
|
||||
*p++ = 0; /* To zeros */
|
||||
} /****************************/
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* C H A N N E L N U M B E R V A L I D A T I O N
|
||||
* -------------------------------------------------
|
||||
* This routine is used to validate a channel number and return the
|
||||
* pointer to the ccb area. The channel must be in range and open.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* Where:
|
||||
* ch Is the channel number
|
||||
* ccbptr Is the returned ccb address, NULLFD if error
|
||||
*****************************************************************************/
|
||||
|
||||
FD *_chkc(ch) /****************************/
|
||||
REG UWORD ch; /* Facilitate error check */
|
||||
{ /* */
|
||||
REG FD *xcb; /* -> CCB */
|
||||
/****************************/
|
||||
if(ch >= MAXCCBS) /* Is channel in range? */
|
||||
RETERR(NULLFD,EBADF); /* No, quit now. */
|
||||
/* */
|
||||
xcb = _getccb(ch); /* xcb -> ccb for channel */
|
||||
if((xcb->flags & OPENED) == 0) /* Is channel OPEN? */
|
||||
RETERR(NULLFD,EBADF); /* Noooooooo!! */
|
||||
return(xcb); /* Else, return pointer */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* C C B I N I T I A L I Z A T I O N
|
||||
* -----------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Routine "_chinit" is called from the run-time initialization to clear
|
||||
* out all the CCB storage.
|
||||
* Calling sequence:
|
||||
* _chinit();
|
||||
*
|
||||
* Routine "__chinit(fd)" is called from other low-level routines
|
||||
* for single channel initialization.
|
||||
* Calling sequence:
|
||||
* __chinit(fd)
|
||||
* where: fd = file descriptor #
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <portab.h> /* Include std definitions */
|
||||
#include <cpm.h> /* Include CP/M definitions */
|
||||
|
||||
FD _fds[MAXCCBS]; /* Allocate CCB storage */
|
||||
|
||||
_chinit() /****************************/
|
||||
{ /* */
|
||||
REG WORD i; /* Index */
|
||||
for(i=0;i<MAXCCBS;i++) /* For all channels */
|
||||
__chinit(i); /* Init fds(i); */
|
||||
} /****************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* The __chinit routine initializes only 1 channel.
|
||||
*****************************************************************************/
|
||||
|
||||
__chinit(i)
|
||||
{ /****************************/
|
||||
REG FD *ch; /* -> CCB */
|
||||
REG BYTE *p; /* Byte pointer temporary */
|
||||
|
||||
ch = _getccb(i); /* convert fd to CCB */
|
||||
ch -> chan = i; /* Load channel byte */
|
||||
ch -> flags = 0; /* clear flag word */
|
||||
ch -> sector = -1; /* Set no sector in buff */
|
||||
ch -> offset = 0; /* Clear file offset word */
|
||||
ch -> hiwater = 0; /* Init hiwater mark */
|
||||
ch -> fcb.drive = 0; /* Init drive field of fcb */
|
||||
p = &ch->fcb.fname[0]; /* Set to file var */
|
||||
while (p< &ch->fcb.ftype[3]) /* Init file name fields */
|
||||
*p++ = ' '; /* To spaces */
|
||||
while (p < &ch->fcb.record) /* Init rest of fcb */
|
||||
*p++ = 0; /* To zeros */
|
||||
} /****************************/
|
||||
|
||||
35
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/chkc.c
Normal file
35
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/chkc.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* C H A N N E L N U M B E R V A L I D A T I O N
|
||||
* -------------------------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* This routine is used to validate a channel number and return the
|
||||
* pointer to the ccb area. The channel must be in range and open.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* ccbptr = _chkc(ch);
|
||||
*
|
||||
* Where:
|
||||
*
|
||||
* ch Is the channel number
|
||||
* ccbptr Is the returned ccb address
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <portab.h> /* Include std definitions */
|
||||
#include <cpm.h> /* and CP/M definitions */
|
||||
#include <errno.h>
|
||||
FD *_chkc(ch) /****************************/
|
||||
REG UWORD ch; /* Facilitate error check */
|
||||
{ /* */
|
||||
REG FD *xcb; /* -> CCB */
|
||||
/****************************/
|
||||
if(ch >= MAXCCBS) /* Is channel in range? */
|
||||
RETERR(NULL,EBADF); /* No, quit now. */
|
||||
/* */
|
||||
xcb = _getccb(ch); /* xcb -> ccb for channel */
|
||||
if((xcb->flags & OPENED) == 0) /* Is channel OPEN? */
|
||||
RETERR(NULL,EBADF); /* Noooooooo!! */
|
||||
return(xcb); /* Else, return pointer */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* _ c h k u s e r F u n c t i o n
|
||||
* ---------------------------------
|
||||
*
|
||||
* '_chkuser' and '_uchkuser' handle user numbers under CPM before
|
||||
* version 4. The user number is stored in the ccb structure;
|
||||
* if a zero, the default user # is assumed, else the _chkuser()
|
||||
* routine sets the user number to the desired user number (one less
|
||||
* than the stored user number, since user 0 is valid - similar to the
|
||||
* default drive spec for an FCB).
|
||||
* '_uchkuser()' sets the user number back to its previous value.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
/****************************/
|
||||
WORD _chkuser(newu) /* */
|
||||
WORD newu; /* Desired user number */
|
||||
{ /****************************/
|
||||
#if CPM /*===============================================================*/
|
||||
REG WORD prevu; /* Previous user number */
|
||||
/****************************/
|
||||
if( newu == 0 ) /* Default user # desired? */
|
||||
return 0; /* Yes, return */
|
||||
prevu = __OSIF(USER,0xFF)+1; /* Get prev and adjust */
|
||||
if( newu != prevu ) /* Are they different? */
|
||||
__OSIF(USER,newu-1); /* Yes, set to desired u# */
|
||||
return prevu; /* Return the previous */
|
||||
#else /*===============================================================*/
|
||||
return 0;
|
||||
#endif /*===============================================================*/
|
||||
} /****************************/
|
||||
|
||||
/****************************/
|
||||
_uchkuser(newu,prevu) /* */
|
||||
WORD newu; /* Desired user number */
|
||||
WORD prevu; /* Previous user number */
|
||||
{ /****************************/
|
||||
#if CPM /*===============================================================*/
|
||||
if( newu == 0 ) /* Default user #? */
|
||||
return; /* assume no change */
|
||||
if( newu != prevu ) /* Are they different? */
|
||||
__OSIF(USER,prevu-1); /* Yes, set to what it was*/
|
||||
#else /*===============================================================*/
|
||||
return 0;
|
||||
#endif /*===============================================================*/
|
||||
@@ -0,0 +1,8 @@
|
||||
/* chmod - change mode: NOP under CP/M */
|
||||
#include <portab.h>
|
||||
WORD chmod(name,mode)
|
||||
BYTE *name;
|
||||
WORD mode;
|
||||
{
|
||||
return(access(name,mode));
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/* chown - change owner: like access() under CP/M */
|
||||
#include <portab.h>
|
||||
WORD chown(name,owner,group)
|
||||
BYTE *name;
|
||||
WORD owner;
|
||||
WORD group;
|
||||
{
|
||||
return(access(name,0));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* _ c l e a n u p F u n c t i o n
|
||||
* ---------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "_cleanup" closes all buffered files
|
||||
*
|
||||
* Calling sequence:
|
||||
* _cleanup()
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
_cleanup()
|
||||
{
|
||||
REG WORD ii;
|
||||
|
||||
for( ii=0; ii<MAXFILES; ii++ )
|
||||
fclose(&_iob[ii]);
|
||||
/* _m_term(); /* CLEAR termination routine */
|
||||
@@ -0,0 +1 @@
|
||||
lo68 -r -u_nofloat -o $1.68k s.o $1.o $2.o $3.o $4.o $5.o $6.o $7.o $8.o $9.o clib
|
||||
@@ -0,0 +1 @@
|
||||
lo68 -r -o $1.68k s.o $1.o $2.o $3.o $4.o $5.o $6.o $7.o $8.o $9.o clib libe.a
|
||||
@@ -0,0 +1 @@
|
||||
lo68 -r -o $1.68k s.o $1.o $2.o $3.o $4.o $5.o $6.o $7.o $8.o $9.o clib libf.a
|
||||
@@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* C l o s e F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The close function is used to terminate access to a file / device.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* ret = close(fd);
|
||||
*
|
||||
* Where "fd" is an open file descriptor to be CLOSEd.
|
||||
*
|
||||
* Modifications:
|
||||
* 12/83: PC-DOS mods whf
|
||||
* 10/83: changed user # handling whf
|
||||
* 9/83: add steve's user # mods, change _chkc whf
|
||||
* 8/83: improve error handling whf
|
||||
****************************************************************************/
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
#include "osiferr.h"
|
||||
#include "errno.h"
|
||||
/****************************/
|
||||
EXTERN BYTE __xeof; /* End of file for ASCII */
|
||||
WORD close(fd) /* CLEAR FUNCTION ***********/
|
||||
REG WORD fd; /* File descriptor to close */
|
||||
{ /****************************/
|
||||
EXTERN FD *_chkc(); /* fd -> fp conversion MGL */
|
||||
REG FD *fp; /* file pointer Temporary */
|
||||
REG WORD rv; /* return value */
|
||||
REG WORD xuser; /* User number temporary */
|
||||
/* */
|
||||
if((fp=_chkc(fd)) == NULLFD) /* File Open? */
|
||||
RETERR(FAILURE,EBADF); /* no, quit */
|
||||
rv = SUCCESS; /* assume it will work */
|
||||
if ((fp->flags & (ISTTY|ISLPT)) == 0) /* Character device? */
|
||||
{ /* if not, handle file: *****/
|
||||
#if CPM /*================================================================*/
|
||||
if((fp->flags & ISASCII) != 0 && (fp->flags & ISREAD) == 0) /* */
|
||||
{ /* ASCII file? not ReadOnly?*/
|
||||
if( fp->offset < fp->hiwater ) /* Have we been seeking? */
|
||||
lseek(fd,0L,2); /* Seek to EOF ifso */
|
||||
write(fd,&__xeof,1); /* Write a ^Z character */
|
||||
} /****************************/
|
||||
if((fp->flags & DIRTY) != 0) /* Buffer dirty? */
|
||||
if(_blkio(fp,fp->sector,fp->buffer,1L,B_WRITE) != 1)/* write it */
|
||||
rv = FAILURE; /* can't */
|
||||
xuser = _chkuser(fp->user); /* Check user # for change */
|
||||
if((__OSIF(CLOSE,&(fp->fcb))&0xFF) == 0xFF)/* Close the fcb */
|
||||
rv = FAILURE; /* */
|
||||
_uchkuser(fp->user,xuser); /* Change user # if needed */
|
||||
#endif /*================================================================*/
|
||||
#if PCDOS /*================================================================*/
|
||||
if((__OSIF(CLOSE,&(fp->fcb))&0xFF) == 0xFF)/* Close the fcb */
|
||||
rv = FAILURE; /* */
|
||||
#endif /*================================================================*/
|
||||
} /* end of file handling *****/
|
||||
__chinit(fd); /* Release the space */
|
||||
_freec(fd); /* Release the channel */
|
||||
if( rv == SUCCESS ) /* Was everything ok? */
|
||||
return(rv); /* Yes, return Success */
|
||||
else RETERR(FAILURE,EIO); /* else let them know */
|
||||
} /****************************/
|
||||
254
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/cpm.h
Normal file
254
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/cpm.h
Normal file
@@ -0,0 +1,254 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* O S I F . H
|
||||
* -----------
|
||||
* Copyright 1982,1983 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Edits:
|
||||
* 17-Jan-84 whf Moved to 68K
|
||||
* 5-Jan-84 whf Moved MAXCCBS to channel.c
|
||||
* 29-Dec-83 whf Add F_TRUNC for tclose()
|
||||
* 12-Dec-83 whf Change from "CPM.H" to "OSIF.H"
|
||||
* 9-Dec-83 whf Handle PCDOS differences
|
||||
* 3-Nov-83 whf Add multi-sector i/o
|
||||
* 19-Oct-83 whf Add QUEUE handling info
|
||||
* 6-Oct-83 whf Redefine reserved area in fcb for parsefn() return
|
||||
* 25-June-83 sw Add user number to file "fd" structure.
|
||||
*
|
||||
* This file contains O.S. specific definitions for the
|
||||
* DRI CLEAR/C Run Time Library.
|
||||
* This file is intended only for inclusion with those functions
|
||||
* dealing directly with the O.S. interface, as well as any function
|
||||
* which has hardware dependent code (byte storage order, for
|
||||
* instance).
|
||||
*
|
||||
****************************************************************************/
|
||||
/*
|
||||
* "machine.h": to determine what kind of machine you want to run on.
|
||||
*/
|
||||
|
||||
#define MC68000 1 /* Motorola 68000 */
|
||||
#define CPM68K 1 /* CP/M 68000 ver 2.2 */
|
||||
#define CPM 1 /* CP/M version 2.2 */
|
||||
#define ALCYON 1 /* Alcyon C Compiler */
|
||||
|
||||
|
||||
/*#ifdef UNdefined*/ /* Unused DEFINEs */
|
||||
|
||||
/*** Processor ***/
|
||||
#define I8086 0 /* Intel 8086/8088 */
|
||||
#define VAX 0 /* DEC VAX */
|
||||
#define PDP11 0 /* DEC PDP-11 */
|
||||
#define Z8000 0 /* Zilog Z8000 */
|
||||
|
||||
/*** Operating System ***/
|
||||
#define PCDOS 0 /* IBM PC DOS */
|
||||
#define CCPM 0 /* Concurrent (multi-tasking) */
|
||||
#define CPM3 0 /* CP/M version 3.x (Concurrent & Plus) */
|
||||
#define CPM4 0 /* CP/M version 4.x (Portable Concurrent) */
|
||||
#define UNIX 0 /* UNIX */
|
||||
#define VMS 0 /* DEC VMS */
|
||||
|
||||
/*** Compiler ***/
|
||||
#define DRC 0 /* Digital Research C Compiler */
|
||||
|
||||
/*#endif */ /**********************/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* CP/M FCB definition
|
||||
****************************************************************************/
|
||||
#if CPM /****************************/
|
||||
struct fcbtab /****************************/
|
||||
{ /* */
|
||||
BYTE drive; /* Disk drive field [0] */
|
||||
BYTE fname[8]; /* File name [1-8] */
|
||||
BYTE ftype[3]; /* File type [9-11] */
|
||||
BYTE extent; /* Current extent number[12]*/
|
||||
BYTE s1,s2; /* "system reserved" [13-14]*/
|
||||
BYTE reccnt; /* Record counter [15] */
|
||||
BYTE fpasswd[8]; /* Parsefn passwd area[16-23]*/
|
||||
BYTE fuser; /* Parsefn user# area [24] */
|
||||
BYTE resvd[7]; /* More "system reserved" */
|
||||
LONG record; /* Note -- we overlap [32-36]*/
|
||||
/* current record field to */
|
||||
/* make this useful. */
|
||||
}; /****************************/
|
||||
#endif /****************************/
|
||||
|
||||
/****************************************************************************
|
||||
* PC-DOS FCB definition
|
||||
****************************************************************************/
|
||||
#if PCDOS /****************************/
|
||||
struct fcbtab { /****************************/
|
||||
BYTE drive; /* Disk drive field [0] */
|
||||
BYTE fname[8]; /* File name [1-8] */
|
||||
BYTE ftype[3]; /* File type [9-11] */
|
||||
WORD fcb_curblk; /* Curr 128 byte blk [12-13]*/
|
||||
WORD fcb_lrecsiz; /* Logical record size[14-15]*/
|
||||
LONG fcb_filsiz; /* Num bytes in file [16-19]*/
|
||||
WORD fcb_date; /* Last updated [20-21] */
|
||||
BYTE fcb_resvd[10]; /* System reserved [22-31] */
|
||||
BYTE fcb_currec; /* Rel Rec# within curblk[32]*/
|
||||
LONG record; /* Rel Rec# from bgn file */
|
||||
/* [33-36] depends on lrecsiz*/
|
||||
}; /****************************/
|
||||
#endif /****************************/
|
||||
/* */
|
||||
#define SECSIZ 128 /* size of CP/M sector */
|
||||
/* to obtain nsecs on err */
|
||||
/****************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* Channel Control Block (CCB) */
|
||||
/* */
|
||||
/* One CCB is allocated (statically) for each of the 16 possible open */
|
||||
/* files under C (including STDIN, STDOUT, STDERR). Permanent data */
|
||||
/* regarding the channel is kept here. */
|
||||
/* */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
struct ccb /************************************/
|
||||
{ /* */
|
||||
WORD flags; /*sw Flags byte */
|
||||
BYTE user; /*sw User # */
|
||||
BYTE chan; /* Channel number being used */
|
||||
LONG offset; /* File offset word (bytes) */
|
||||
LONG sector; /* Sector currently in buffer */
|
||||
LONG hiwater; /* High water mark */
|
||||
struct fcbtab fcb; /* File FCB (may have TTY info)*/
|
||||
BYTE buffer[SECSIZ]; /* Read/write buffer */
|
||||
}; /************************************/
|
||||
|
||||
extern struct ccb _fds[]; /* */ /* Declare storage */
|
||||
#define FD struct ccb /* FD Type definition */
|
||||
#define NULLFD ((FD *)0) /* NULLPTRs for FD */
|
||||
/************************************/
|
||||
/* Flags word bit definitions */
|
||||
/************************************/
|
||||
#define OPENED 0x01 /* Channel is OPEN */
|
||||
#define ISTTY 0x02 /* Channel open to TTT */
|
||||
#define ISLPT 0x04 /* Channel open to LPT */
|
||||
#define ISREAD 0x08 /* Channel open readonly */
|
||||
#define ISASCII 0x10 /* ASCII file attached */
|
||||
#define ATEOF 0x20 /* End of file encountered */
|
||||
#define DIRTY 0x40 /* Buffer needs writing */
|
||||
#define ISSPTTY 0x80 /* Special tty info */
|
||||
#define ISAUX 0x100 /*sw Auxiliary device */
|
||||
#define ISQUE 0x0200 /*whf Queue device */
|
||||
/************************************/
|
||||
#define READ 0 /* Read mode parameter for open */
|
||||
#define WRITE 1 /* Write mode */
|
||||
|
||||
/* CCB manipulation macros *************************************/
|
||||
#define _getccb(i) (&_fds[i]) /* Get CCB addr */
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* O S I F F u n c t i o n D e f i n i t i o n s */
|
||||
/* ------------------------------------------------- */
|
||||
/* */
|
||||
/* Following are OSIF function definitions used by the C runtime */
|
||||
/* library. */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
/****************************/
|
||||
#if CPM68K /* */
|
||||
#define __OSIF(fn,arg) __BDOS((fn),(LONG)(arg)) /* CPM68K does it this way */
|
||||
#else /* */
|
||||
#define __OSIF(fn,arg) __BDOS((fn),(arg)) /* DRC does it this way */
|
||||
#endif /* */
|
||||
#if CPM /****************************/
|
||||
#define EXIT 0 /* Exit to BDOS */
|
||||
#define CONIN 1 /* direct echoing con input */
|
||||
#define CONOUT 2 /* Direct console output */
|
||||
#define LSTOUT 5 /* Direct list device output*/
|
||||
#define CONIO 6 /* Direct console I/O */
|
||||
#define C_WRITESTR 9 /* Console string output */
|
||||
#define CONBUF 10 /* Read console buffer */
|
||||
#define S_BDOSVER 12 /* Get System BDOS Ver Num */
|
||||
#define OPEN 15 /* OPEN a disk file */
|
||||
#define CLOSE 16 /* Close a disk file */
|
||||
#define SEARCHF 17 /* Search for first */
|
||||
#define SEARCHN 18 /* Search for next */
|
||||
#define DELETE 19 /* Delete a disk file */
|
||||
#define CREATE 22 /* Create a disk file */
|
||||
#define F_RENAME 23 /* Rename a disk file */
|
||||
#define SETDMA 26 /* Set DMA address */
|
||||
#define USER 32 /*sw Get / set user number */
|
||||
#define B_READ 33 /* Read Random record */
|
||||
#define B_WRITE 34 /* Write Random record */
|
||||
#define FILSIZ 35 /* Compute File Size */
|
||||
#define F_MULTISEC 44 /* Set Multi-Sector Count */
|
||||
#define P_CHAIN 47 /* Program Chain */
|
||||
#define SETVEC 61 /* Set exception vector */
|
||||
#define N_NETSTAT 68 /* Get Network Status */
|
||||
#define F_TRUNC 99 /* Truncate File function */
|
||||
#define S_OSVER 163 /* Get OS Version Number */
|
||||
#endif /****************************/
|
||||
#if PCDOS /****************************/
|
||||
#define EXIT 0 /* Exit to BDOS */
|
||||
#define CONIN 1 /* direct echoing con input */
|
||||
#define CONOUT 2 /* Direct console output */
|
||||
#define LSTOUT 5 /* Direct list device output*/
|
||||
#define CONIO 6 /* Direct console I/O */
|
||||
#define C_WRITESTR 9 /* Console string output */
|
||||
#define CONBUF 10 /* Read console buffer */
|
||||
#define OPEN 15 /* OPEN a disk file */
|
||||
#define CLOSE 16 /* Close a disk file */
|
||||
#define SEARCHF 17 /* Search for first */
|
||||
#define SEARCHN 18 /* Search for next */
|
||||
#define DELETE 19 /* Delete a disk file */
|
||||
#define CREATE 22 /* Create a disk file */
|
||||
#define F_RENAME 23 /* Rename a disk file */
|
||||
#define SETDMA 26 /* Set DMA address */
|
||||
#define B_READ 33 /* Read Random record */
|
||||
#define B_WRITE 34 /* Write Random record */
|
||||
#define FILSIZ 35 /* Compute File Size */
|
||||
#endif /****************************/
|
||||
/****************************************************************************/
|
||||
/* Other CP/M definitions */
|
||||
/****************************************************************************/
|
||||
#define TERM "CON:" /* Console file name */
|
||||
#define LIST "LST:" /* List device file name */
|
||||
#define EOFCHAR 0x1a /* End of file character-^Z */
|
||||
/****************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Hardware dependencies */
|
||||
/****************************************************************************/
|
||||
/****************************/
|
||||
#if MC68000 | Z8000 /* 68K or Z8000 */
|
||||
#define HILO 1 /* used when bytes stored */
|
||||
#else /* */
|
||||
#define HILO 0 /* */
|
||||
#endif /* */
|
||||
/* */
|
||||
#if HILO /* Hi/Lo storage used in */
|
||||
struct long_struct{ /* 68K */
|
||||
BYTE lbhihi; /* Use this for accessing */
|
||||
BYTE lbhilo; /* ordered bytes in 32 bit*/
|
||||
BYTE lblohi; /* LONG qtys. */
|
||||
BYTE lblolo; /* */
|
||||
}; /* */
|
||||
struct word_struct{ /* Use this for accessing */
|
||||
WORD lwhi; /* ordered words in 32 bit*/
|
||||
WORD lwlo; /* LONG qtys. */
|
||||
}; /* */
|
||||
#else /****************************/
|
||||
struct long_struct{ /* Lo/Hi storage use on */
|
||||
BYTE lblolo; /* PDP-11, VAX, 8086,... */
|
||||
BYTE lblohi; /* */
|
||||
BYTE lbhilo; /* */
|
||||
BYTE lbhihi; /* */
|
||||
}; /* */
|
||||
struct word_struct{ /* */
|
||||
WORD lwlo; /* */
|
||||
WORD lwhi; /* */
|
||||
}; /* */
|
||||
#endif /****************************/
|
||||
/*************************** end of osif.h **********************************/
|
||||
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* C F I L E C R E A T E R O U T I N E
|
||||
* -----------------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The "creat" routine opens a new "C" file and returns a file id.
|
||||
* Comes in 3 flavors: ascii (CP/M text files), binary, and default
|
||||
* (currently ascii).
|
||||
*
|
||||
* Calling Sequence:
|
||||
* fid = creat(fname,prot)
|
||||
* fid = creata(fname,prot)
|
||||
* fid = creatb(fname,prot)
|
||||
* fid = _creat(fname,prot,type);
|
||||
*
|
||||
* Where:
|
||||
*
|
||||
* fname is the address of a null terminated file name.
|
||||
* prot is the UNIX file protection
|
||||
* type is 0 for ASCII, 1 for BINARY
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include "portab.h" /* Include std definitions */
|
||||
#include "osif.h" /* Include CP/M definitions */
|
||||
#include "osiferr.h"
|
||||
#include "errno.h" /* Error codes */
|
||||
EXTERN BYTE __tname[]; /* Terminal name */
|
||||
EXTERN BYTE __lname[]; /* List device name */
|
||||
/****************************/
|
||||
WORD _creat (fname,prot,type) /****************************/
|
||||
BYTE *fname; /* -> File name */
|
||||
WORD prot; /* Open mode */
|
||||
WORD type; /* ASCII/BINARY flag */
|
||||
{ /****************************/
|
||||
REG WORD ich; /* Channel number for open */
|
||||
WORD _allocc(); /* gets a channel */
|
||||
REG FD *ch; /* -> CCB for channel */
|
||||
/* */
|
||||
if((ich = _allocc()) == FAILURE) /* Allocate a channel */
|
||||
return (FAILURE); /* Can't (EMFILE) */
|
||||
/* */
|
||||
__chinit(ich); /* Clear out channel's ccb */
|
||||
ch = _getccb(ich); /* Get address of ccb */
|
||||
/* */
|
||||
if(type==0) /* ASCII file? */
|
||||
ch -> flags |= ISASCII; /* Yes, mark it. */
|
||||
/****************************/
|
||||
if(_strcmp(fname,__tname) == 0) /* Terminal file? */
|
||||
{ /* */
|
||||
ch -> flags |= ISTTY|OPENED; /* Set flag */
|
||||
return(ich); /* Return file descriptor */
|
||||
} /****************************/
|
||||
else if(_strcmp(fname,__lname) == 0) /* List device? */
|
||||
{ /* */
|
||||
ch -> flags |= ISLPT|OPENED; /* set flag */
|
||||
return(ich); /* */
|
||||
} /* */
|
||||
/****************************/
|
||||
if(__open(ich,fname,CREATE) != 0) /* Use BDOS interface */
|
||||
RETERR(FAILURE,ENODSPC); /* Oops, No dir space. */
|
||||
/* Else: */
|
||||
ch -> flags |= OPENED; /* Set OPEN bit */
|
||||
return(ich); /* Return Channel # */
|
||||
} /****************************/
|
||||
|
||||
WORD creat(fname,prot) /* CLEAR FUNCTION ***********/
|
||||
BYTE *fname; WORD prot;
|
||||
{ return(_creat(fname,prot,0)); } /* default to ascii */
|
||||
|
||||
WORD creata(fname,prot) /* CLEAR FUNCTION ***********/
|
||||
BYTE *fname; WORD prot;
|
||||
{ return(_creat(fname,prot,0)); } /* ascii file open */
|
||||
|
||||
WORD creatb(fname,prot) /* CLEAR FUNCTION ***********/
|
||||
BYTE *fname; WORD prot;
|
||||
{ return(_creat(fname,prot,1)); } /* binary file open */
|
||||
@@ -0,0 +1,32 @@
|
||||
/* CREATE A NEW FILE FOR VMS
|
||||
* copyright (c) 1980 by Whitesmiths, Ltd.
|
||||
*/
|
||||
#include <std.h>
|
||||
#include "vms.h"
|
||||
|
||||
FILE creat(fname, mode)
|
||||
TEXT *fname;
|
||||
COUNT mode;
|
||||
{
|
||||
return (_creat(fname, mode, 0));
|
||||
}
|
||||
FILE creata(fname, mode)
|
||||
TEXT *fname;
|
||||
COUNT mode;
|
||||
{
|
||||
return (_creat(fname, mode, 0));
|
||||
}
|
||||
FILE creatb(fname, mode)
|
||||
TEXT *fname;
|
||||
COUNT mode;
|
||||
{
|
||||
return (_creat(fname, mode, 1));
|
||||
}
|
||||
|
||||
FILE _creat(fname, mode, rsize)
|
||||
TEXT *fname;
|
||||
COUNT mode;
|
||||
BYTES rsize;
|
||||
{
|
||||
return (_copen(fname, (mode + 1) & 03, rsize));
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**************************************************************************
|
||||
* CTYPE.C - provides static tables for 'ctype.h' extern defs.
|
||||
* Modified 10/31/82 by MGL to add ___atab() for forced loading
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
#define CTYPE /* tells ctype.h who's boss */
|
||||
#include "ctype.h"
|
||||
|
||||
GLOBAL UBYTE __atab[] = { /* table of ascii char types */
|
||||
|
||||
/********************************************************************/
|
||||
/* nn0 nn1 nn2 nn3 nn4 nn5 nn6 nn7 */
|
||||
|
||||
/* nul soh stx etx eot enq ack bel */
|
||||
/*00m*/ __c, __c, __c, __c, __c, __c, __c, __c,
|
||||
|
||||
/* bs ht nl vt np cr so si */
|
||||
/*01m*/ __c, __cs, __cs, __c, __cs, __cs, __c, __c,
|
||||
|
||||
/* dle dc1 dc2 dc3 dc4 nak syn etb */
|
||||
/*02m*/ __c, __c, __c, __c, __c, __c, __c, __c,
|
||||
|
||||
/* can em sub esc fs gs rs us */
|
||||
/*03m*/ __c, __c, __c, __c, __c, __c, __c, __c,
|
||||
|
||||
/* sp ! " # $ % & ' */
|
||||
/*04m*/ __ps, __p, __p, __p, __p, __p, __p, __p,
|
||||
|
||||
/* ( ) * + , - . / */
|
||||
/*05m*/ __p, __p, __p, __p, __p, __p, __p, __p,
|
||||
|
||||
/* 0 1 2 3 4 5 6 7 */
|
||||
/*06m*/ __d, __d, __d, __d, __d, __d, __d, __d,
|
||||
|
||||
/* 8 9 : ; < = > ? */
|
||||
/*07m*/ __d, __d, __p, __p, __p, __p, __p, __p,
|
||||
|
||||
/* @ A B C D E F G */
|
||||
/*10m*/ __p, __u, __u, __u, __u, __u, __u, __u,
|
||||
|
||||
/* H I J K L M N O */
|
||||
/*11m*/ __u, __u, __u, __u, __u, __u, __u, __u,
|
||||
|
||||
/* P Q R S T U V W */
|
||||
/*12m*/ __u, __u, __u, __u, __u, __u, __u, __u,
|
||||
|
||||
/* X Y Z [ \ ] ^ _ */
|
||||
/*13m*/ __u, __u, __u, __p, __p, __p, __p, __p,
|
||||
|
||||
/* ` a b c d e f g */
|
||||
/*14m*/ __p, __l, __l, __l, __l, __l, __l, __l,
|
||||
|
||||
/* h i j k l m n o */
|
||||
/*15m*/ __l, __l, __l, __l, __l, __l, __l, __l,
|
||||
|
||||
/* p q r s t u v w */
|
||||
/*16m*/ __l, __l, __l, __l, __l, __l, __l, __l,
|
||||
|
||||
/* x y z { | } ~ del */
|
||||
/*17m*/ __l, __l, __l, __p, __p, __p, __p, __c
|
||||
|
||||
};
|
||||
|
||||
___atab()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* CTYPE */
|
||||
/* ----- */
|
||||
/* */
|
||||
/* CTYPE.H - macros to classify ASCII-coded integers by table lookup. */
|
||||
/* */
|
||||
/* */
|
||||
/* Note: Integer args are undefined for all int values > 127, */
|
||||
/* except for macro 'isascii()'. */
|
||||
/* Assumes: */
|
||||
/* User will link with standard library functions. */
|
||||
/* Compiler can handle declarator initializers and */
|
||||
/* '#defines' with parameters. */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
/*
|
||||
* Bit patterns for character class DEFINEs
|
||||
*/
|
||||
#define __c 01
|
||||
#define __p 02
|
||||
#define __d 04
|
||||
#define __u 010
|
||||
#define __l 020
|
||||
#define __s 040
|
||||
#define __cs 041
|
||||
#define __ps 042
|
||||
|
||||
#ifndef CTYPE
|
||||
extern char ___atab();
|
||||
extern char __atab[];
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Character Class Testing and Conversion DEFINEs:
|
||||
*/
|
||||
#define isascii(ch) ((ch) < 0200)
|
||||
#define isalpha(ch) (__atab[ch] & (__u | __l))
|
||||
#define isupper(ch) (__atab[ch] & __u)
|
||||
#define islower(ch) (__atab[ch] & __l)
|
||||
#define isdigit(ch) (__atab[ch] & __d)
|
||||
#define isalnum(ch) (__atab[ch] & (__u | __l | __d))
|
||||
#define isspace(ch) (__atab[ch] & __s)
|
||||
#define ispunct(ch) (__atab[ch] & __p)
|
||||
#define isprint(ch) (__atab[ch] & (__u | __l | __d | __p))
|
||||
#define iscntrl(ch) (__atab[ch] & __c)
|
||||
|
||||
#define tolower(ch) (isupper(ch) ? (ch)+('a'-'A') : (ch))
|
||||
#define toupper(ch) (islower(ch) ? (ch)+('A'-'a') : (ch))
|
||||
#define toascii(ch) ((ch) & 0177)
|
||||
228
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/doprt.c
Normal file
228
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/doprt.c
Normal file
@@ -0,0 +1,228 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* _ d o p r t F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Reseacrh Inc. All rights reserved.
|
||||
*
|
||||
* "_doprt" handles the printing for functions "printf", "fprintf",
|
||||
* and "sprintf". Each of these sets up the parameters and calls _doprt.
|
||||
*
|
||||
* Calling sequence:
|
||||
*
|
||||
* nchrs = _doprt(stream,fmt,args)
|
||||
* Where:
|
||||
* nchrs = number of chars output by _doprt
|
||||
* stream -> destination buffer (FILE *)
|
||||
* fmt -> a string specifying how "args" are to be output.
|
||||
* args -> a list of arguments
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include "stdio.h"
|
||||
#include "osif.h"
|
||||
|
||||
#define ARGWIDTH (sizeof(int)) /* width of arg to function */
|
||||
#define NXTARG(ptr,isl) ((ptr)+=((isl) ? MAX(ARGWIDTH,sizeof(LONG)):ARGWIDTH))
|
||||
#define IARG(ptr) ((ptr)+=ARGWIDTH) /* int arg increment */
|
||||
#if CPM68K
|
||||
#define FARG(ptr) ((ptr)+=sizeof(float)) /* float/double arg increment */
|
||||
#else
|
||||
#define FARG(ptr) ((ptr)+=sizeof(double)) /* float/double arg increment */
|
||||
#endif
|
||||
#define CHOOSELS(isl) ((isl) ? __prtld : __prtshort ) /* prt long or short */
|
||||
#define XPUTC(a1,a2) {putc(a1,a2);nchrs++;} /* count chars output */
|
||||
/****************************/
|
||||
_doprt(sp,fmt,pb) /* print subroutine */
|
||||
FILE *sp; /* stream buffer ptr */
|
||||
BYTE *fmt; /* format string */
|
||||
REG BYTE *pb; /* pointer to args */
|
||||
{ /****************************/
|
||||
REG BYTE c; /* format char */
|
||||
BYTE **ppi; /* pointer to ptr */
|
||||
WORD *pw; /* pointer to word */
|
||||
BYTE padchar, /* for padding */
|
||||
*s, /* string ptr for output */
|
||||
buf[BUFSIZ]; /* s usually points here */
|
||||
WORD width; /* for format spec */
|
||||
REG WORD prec, /* precision */
|
||||
len; /* total length of field */
|
||||
WORD n, /* counter */
|
||||
nchrs; /* number chars output */
|
||||
BOOLEAN left, /* pad on left? */
|
||||
longf; /* a long arg? */
|
||||
MLOCAL BYTE (*fn)(); /* function holder */
|
||||
GLOBAL BYTE *__prtshort(), /* for 16 bit integers */
|
||||
*__prtld(); /* for 32 bit integers */
|
||||
double *dblptr; /* in case we need one */
|
||||
/****************************/
|
||||
nchrs = 0; /* init # chars output */
|
||||
if (fmt) /* make sure it's not NULL */
|
||||
while (TRUE) /* examine the format string*/
|
||||
{ /* */
|
||||
for( len=0, s=fmt; *s && *s != '%'; ++s, ++len )
|
||||
; /* grab up to EOS or '%' */
|
||||
if( len > 0 ) /* did we grab anything? */
|
||||
{ /* yes... */
|
||||
fputn(fmt,len,sp); /* put them out */
|
||||
fmt = s; /* update this pointer */
|
||||
nchrs += len; /* update the counter */
|
||||
} /* */
|
||||
if( *fmt++ != '%' ) /* Did we stop for '%'? */
|
||||
break; /* no, EOS: we're finished*/
|
||||
/****************************/
|
||||
left = 0; /* assume no left pad */
|
||||
if ((c = *fmt++) == '-') /* left pad specified */
|
||||
{ /* */
|
||||
c = *fmt++; /* */
|
||||
left++; /* */
|
||||
} /* */
|
||||
padchar = ' '; /* assume blank padding */
|
||||
if (c == '0') /* zero fill specified */
|
||||
{ /* */
|
||||
padchar = c; /* */
|
||||
c = *fmt++; /* */
|
||||
} /* */
|
||||
width = -1; /* assume no field spc width*/
|
||||
if( c== '*' ) /* get width from args */
|
||||
{ /* */
|
||||
pw = pb; /* use word ptr for access */
|
||||
width = *pw; /* */
|
||||
IARG(pb); /* */
|
||||
c = *fmt++; /* */
|
||||
} /* */
|
||||
else while (c >= '0' && c <= '9') /* get width from fmt */
|
||||
{ /* */
|
||||
if (width < 0) /* */
|
||||
|
||||
width = 0; /* */
|
||||
width = width * 10 + (c - '0'); /* */
|
||||
c = *fmt++; /* */
|
||||
} /* */
|
||||
prec = -1; /* assume no precision */
|
||||
if (c == '.') /* get precision */
|
||||
{ /* */
|
||||
prec = 0; /* */
|
||||
c = *fmt++; /* */
|
||||
} /* */
|
||||
if( c== '*' ) /* get prec from args */
|
||||
{ /* */
|
||||
pw = pb; /* get word pointer */
|
||||
prec = *pw; /* */
|
||||
IARG(pb); /* */
|
||||
c = *fmt++; /* */
|
||||
} /* */
|
||||
else while (c >= '0' && c <= '9') /* get prec from fmt */
|
||||
{ /* */
|
||||
prec = prec * 10 + (c - '0'); /* */
|
||||
c = *fmt++; /* */
|
||||
} /* */
|
||||
longf = 0; /* assume short int */
|
||||
if (c == 'l' || c == 'L') /* long int specified */
|
||||
{ /* */
|
||||
longf++; /* */
|
||||
c = *fmt++; /* */
|
||||
} /****************************/
|
||||
/* we now have all prelims */
|
||||
/* out of the way; let's see*/
|
||||
/* what we want to print */
|
||||
s = buf; /* assume we'll be using buf*/
|
||||
switch (c) /* */
|
||||
{ /* */
|
||||
/****************************/
|
||||
case 'D': /* decimal signed */
|
||||
longf++; /* capital letter means long*/
|
||||
case 'd': /* */
|
||||
fn = CHOOSELS(longf); /* */
|
||||
__prtint(pb, buf, 10, TRUE, fn); /* */
|
||||
NXTARG(pb,longf); /* point to next arg */
|
||||
break; /* finis switch */
|
||||
/****************************/
|
||||
case 'U': /* decimal unsigned */
|
||||
longf++; /* */
|
||||
case 'u': /* */
|
||||
fn = CHOOSELS(longf); /* */
|
||||
__prtint(pb, buf, 10, FALSE, fn); /* */
|
||||
NXTARG(pb,longf); /* */
|
||||
break; /* */
|
||||
/****************************/
|
||||
case 'O': /* octal signed */
|
||||
longf++; /* */
|
||||
case 'o': /* */
|
||||
fn = CHOOSELS(longf); /* */
|
||||
__prtint(pb, buf, 8, FALSE, fn); /* */
|
||||
NXTARG(pb,longf); /* */
|
||||
break; /* */
|
||||
/****************************/
|
||||
case 'X': /* hexadecimal unsigned */
|
||||
longf++; /* */
|
||||
case 'x': /* */
|
||||
fn = CHOOSELS(longf); /* */
|
||||
__prtint(pb, buf, 16, FALSE, fn); /* */
|
||||
NXTARG(pb,longf); /* */
|
||||
break; /* */
|
||||
/****************************/
|
||||
case 's': /* string */
|
||||
case 'S': /* */
|
||||
ppi = pb; /* need to deal with ptr */
|
||||
s = *ppi; /* cast to pointer */
|
||||
NXTARG(pb,(sizeof(char *)==sizeof(long)));
|
||||
/* TRUE if pointers are long*/
|
||||
/* FALSE if not */
|
||||
break; /* */
|
||||
/****************************/
|
||||
case 'c': /* character */
|
||||
case 'C': /* */
|
||||
pw = pb; /* word ptr for portability */
|
||||
buf[0] = (*pw & 0377); /* assume chars passed as */
|
||||
buf[1] = NULL; /* ints */
|
||||
IARG(pb); /* */
|
||||
break; /* */
|
||||
/****************************/
|
||||
/****************************/
|
||||
case 'E': /* E format */
|
||||
case 'e': /* */
|
||||
_petoa(pb, buf, prec, c);/* Do the conversion */
|
||||
FARG(pb); /* Bump to next arg */
|
||||
prec = -1; /* Avoid truncation */
|
||||
break; /* Next */
|
||||
/****************************/
|
||||
case 'F': /* F format floating */
|
||||
case 'f': /* */
|
||||
_pftoa(pb, buf, prec, c);/* do the conversion */
|
||||
FARG(pb); /* Bump to next arg */
|
||||
prec = -1; /* Avoid truncation */
|
||||
break; /* */
|
||||
/****************************/
|
||||
case 'G': /* G format floating */
|
||||
case 'g': /* */
|
||||
_pgtoa(pb, buf, prec, c);/* do the conversion */
|
||||
FARG(pb); /* Bump to next arg */
|
||||
prec = -1; /* Avoid truncation */
|
||||
break; /* */
|
||||
/****************************/
|
||||
/****************************/
|
||||
default: /* just print the character */
|
||||
XPUTC(c,sp); /* */
|
||||
continue; /* */
|
||||
} /****************************/
|
||||
len = strlen(s); /* how long is the output? */
|
||||
if (prec < len && prec >= 0) /* cut off if user says so */
|
||||
len = prec; /* */
|
||||
n = width - len; /* how much extra room? */
|
||||
if (!left) /* if left not specified */
|
||||
{ /* */
|
||||
if (padchar == '0' && *s == '-') /* check for neg */
|
||||
{ /* */
|
||||
len--; /* output minus if leading 0*/
|
||||
XPUTC(*s++,sp); /* */
|
||||
|
||||
} /* */
|
||||
while (n-- > 0) /* now pad on left */
|
||||
XPUTC(padchar,sp); /* */
|
||||
} /* */
|
||||
fputn(s,len,sp); /* put buffered n chars */
|
||||
nchrs += len; /* assume they got there */
|
||||
while (n-- > 0) /* anything remain, then pad*/
|
||||
XPUTC(padchar,sp); /* */
|
||||
} /* */
|
||||
return(nchrs); /* report on # chars output */
|
||||
} /****************************/
|
||||
181
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/doprtfp.c
Normal file
181
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/doprtfp.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* d o p r t f p R o u t i n e
|
||||
* -----------------------------
|
||||
*
|
||||
* This file contains subroutines called from "_doprt()" which are
|
||||
* specific to floating point. The purpose of having a separate file
|
||||
* is so that these routines may be declared global in a special
|
||||
* version of "s.o", to allow running without the floating point
|
||||
* library routines.
|
||||
*
|
||||
* Entry Points:
|
||||
*
|
||||
* _petoa(^float, ^buff, prec);
|
||||
* _pftoa(^float, ^buff, prec);
|
||||
* _pgtoa(^float, ^buff, prec);
|
||||
*
|
||||
* ^float is a pointer to the floating number to convert
|
||||
* ^buff is a pointer to the buffer
|
||||
* prec is the precision specifier
|
||||
*
|
||||
* Modifications:
|
||||
* 1/84 whf - change to include "osif.h"
|
||||
* 8/83 whf - add in DRC floating point call
|
||||
* 10/83 whf - get it to work on DRC
|
||||
*
|
||||
*****************************************************************************/
|
||||
/* */
|
||||
#include "portab.h" /* */
|
||||
#include "osif.h" /* */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
#if CPM68K /* I hope to resolve these differences someday. whf 8/83 */
|
||||
/****************************************************************************/
|
||||
BYTE *ftoa(); /* Converts float to ascii "F" fmt */
|
||||
BYTE *etoa(); /* Converts float to ascii "E" fmt */
|
||||
/************************************/
|
||||
BYTE *_pftoa(addr,buf,prec) /* Print "F" format */
|
||||
FLOAT *addr; /* -> Number to convert */
|
||||
BYTE *buf; /* -> Output buffer */
|
||||
WORD prec; /* Fraction precision specifier */
|
||||
{ /************************************/
|
||||
FLOAT fp; /* Float temp */
|
||||
/************************************/
|
||||
prec = (prec < 0) ? 6 : prec; /* If < 0, make it 6 */
|
||||
fp = *addr; /* Load float number */
|
||||
return(ftoa(fp,buf,prec)); /* Do conversion */
|
||||
} /************************************/
|
||||
/* */
|
||||
BYTE *_petoa(addr,buf,prec) /* Print "E" format */
|
||||
FLOAT *addr; /* -> Number to convert */
|
||||
BYTE *buf; /* -> Output buffer */
|
||||
WORD prec; /* Fraction precision specifier */
|
||||
{ /************************************/
|
||||
FLOAT fp; /* Floating temp */
|
||||
prec = (prec < 0) ? 6 : prec; /* If < 0, make it 6 */
|
||||
fp = *addr; /* Load temp */
|
||||
return(etoa(fp,buf,prec)); /* Do conversion */
|
||||
} /************************************/
|
||||
/* */
|
||||
BYTE *_pgtoa(addr,buf,prec) /* Print "G" format */
|
||||
FLOAT *addr; /* -> Number to convert */
|
||||
BYTE *buf; /* -> Output buffer */
|
||||
WORD prec; /* Fraction precision specifier */
|
||||
{ /************************************/
|
||||
BYTE *sp; /* String temp */
|
||||
/************************************/
|
||||
sp = _pftoa(addr, buf, prec); /* Try F first */
|
||||
if(strlen(buf) > (7+prec)) /* Smallest FP string */
|
||||
sp = _petoa(addr,buf,prec); /* Do E format instead */
|
||||
return sp; /* */
|
||||
} /************************************/
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
#else /* for DRC */
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
BYTE *ftoa(); /* General purpose floating point */
|
||||
/* */
|
||||
BYTE *_drcftoa(addr,buf,prec,kind) /* Use DRC ftoa routine */
|
||||
DOUBLE *addr; /* -> Number to convert */
|
||||
REG BYTE *buf; /* -> Output buffer */
|
||||
REG WORD prec; /* Fraction precision specifier */
|
||||
BYTE kind; /* Kind of convert (f, e, or g) */
|
||||
{ /************************************/
|
||||
REG BYTE *ss; /* Temp pointer for adjustment */
|
||||
REG WORD nn; /* Counter */
|
||||
WORD len; /* */
|
||||
/* */
|
||||
ss = buf; /* Save til later */
|
||||
if( prec < 0) prec = 6; /* If <0, make it 6 */
|
||||
if( prec > 17 ) prec = 17; /* If >17, make it 17 */
|
||||
if( kind == 'f' ) nn = 17; /* use max. precision */
|
||||
else if( kind == 'e' || kind == 'E' )
|
||||
nn = prec + 1;
|
||||
else if( (nn = prec) == 0 ) /* G format */
|
||||
++nn;
|
||||
if (nn > 17) nn = 17;
|
||||
*buf = ' ';
|
||||
ftoa(addr, &buf[1], 80, nn, kind); /* go convert */
|
||||
if( kind == 'f' )
|
||||
_ffmt(ss,prec);
|
||||
len = strlen(buf);
|
||||
if(buf[len-1] == '.') /* Zap trailing decimal point */
|
||||
buf[len-1] = NULL; /* */
|
||||
while( *buf == ' ' ) /* Zap leading blanks */
|
||||
++buf; /* */
|
||||
if( ss != buf ) /* Did we zap leading blanks? */
|
||||
strcpy(ss,buf); /* Ifso, shift everything into place*/
|
||||
return ss; /* */
|
||||
} /************************************/
|
||||
|
||||
BYTE *_pftoa(addr,buf,prec,ch) /* Print "F" format */
|
||||
FLOAT *addr; /* -> Number to convert */
|
||||
BYTE *buf; /* -> Output buffer */
|
||||
WORD prec; /* Fraction precision specifier */
|
||||
BYTE ch; /* Char format specifier */
|
||||
{ /************************************/
|
||||
return(_drcftoa(addr,buf,prec,ch));/* Do conversion */
|
||||
} /************************************/
|
||||
/* */
|
||||
BYTE *_petoa(addr,buf,prec,ch) /* Print "E" format */
|
||||
FLOAT *addr; /* -> Number to convert */
|
||||
BYTE *buf; /* -> Output buffer */
|
||||
WORD prec; /* Fraction precision specifier */
|
||||
BYTE ch; /* Char format specifier */
|
||||
{ /************************************/
|
||||
return(_drcftoa(addr,buf,prec,ch));/* Do conversion */
|
||||
} /************************************/
|
||||
/* */
|
||||
BYTE *_pgtoa(addr,buf,prec,ch) /* Print "G" format */
|
||||
FLOAT *addr; /* -> Number to convert */
|
||||
BYTE *buf; /* -> Output buffer */
|
||||
WORD prec; /* Fraction precision specifier */
|
||||
BYTE ch; /* Char format specifier */
|
||||
{ /************************************/
|
||||
return(_drcftoa(addr,buf,prec,ch));/* Do conversion */
|
||||
} /************************************/
|
||||
/****************************************************************************/
|
||||
|
||||
|
||||
MLOCAL _ffmt(s, prec)
|
||||
char *s;
|
||||
register prec;
|
||||
{
|
||||
register char *p;
|
||||
register int i;
|
||||
char *dot, lastdig;
|
||||
|
||||
p = s;
|
||||
while (*++p) {
|
||||
if (*p == '.') dot = p; /* found decimal pt. */
|
||||
else if (*p == 'e') {
|
||||
s = dot + prec + 1;
|
||||
if (s < p)
|
||||
while (*s++ = *p++); /* remove extra zeros */
|
||||
return;
|
||||
}
|
||||
}
|
||||
i = p - dot - 1;
|
||||
while (i++ < prec)
|
||||
*p++ = '0'; /* fill trailing zeros */
|
||||
p = dot + prec + 1;
|
||||
lastdig = *p;
|
||||
*p = '\0';
|
||||
if (lastdig >= '5') {
|
||||
while (1) { /* round preceeding digit */
|
||||
if (*--p == '.') p--;
|
||||
if ((*p += 1) <= '9') break;
|
||||
*p = '0';
|
||||
}
|
||||
if (*p < '1') {
|
||||
if (*p == '.') *(p-1) = '-';
|
||||
*p = '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/****************************************************************************/
|
||||
276
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/doscan.c
Normal file
276
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/doscan.c
Normal file
@@ -0,0 +1,276 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* _ d o s c a n F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "_doscan" is the common subroutine to "scanf", "fscanf", and
|
||||
* "sscanf".
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = _doscan(sp,fmt,aps)
|
||||
* Where:
|
||||
* WORD ret number items matched AND assigned
|
||||
* EOF when encountered on stream sp
|
||||
* FILE *sp pointer to input stream
|
||||
* BYTE *fmt input specification string
|
||||
* BYTE **aps pointer to (pointers to) arguments
|
||||
*
|
||||
* Edits:
|
||||
* 1/11/84 whf fix "%1s" bug
|
||||
* 12/02/83 HY ???
|
||||
*****************************************************************************/
|
||||
#include "stdio.h"
|
||||
#include "ctype.h"
|
||||
|
||||
#define INFINITY 32767
|
||||
#define NXTNI(d) if( ((d)=getc(sp)) == EOF ) return(EOF)
|
||||
|
||||
WORD _doscan(sp,fmt,aps) /****************************/
|
||||
REG FILE *sp; /* Stream ptr */
|
||||
BYTE *fmt; /* Input format spec ptr */
|
||||
BYTE **aps; /* Argument ptrs ptr */
|
||||
{ /****************************/
|
||||
REG BYTE c; /* Spec character */
|
||||
REG WORD ni; /* Input char */
|
||||
BOOLEAN noassign, /* Suppress assignment flag */
|
||||
invert, /* Invert flag (_ismember) */
|
||||
numfound, /* Number found flag */
|
||||
longf, /* Long ptr flag */
|
||||
shortf; /* Short ptr flag */
|
||||
REG WORD width; /* Max field width */
|
||||
WORD tval, /* Temp val holder */
|
||||
base, /* For numeric conversion */
|
||||
nitems; /* Number items mtchd & assd*/
|
||||
LONG val, /* For numeric conversion */
|
||||
locval; /* Local value area */
|
||||
BYTE locbuf[BUFSIZ], /* Local buffer area */
|
||||
*db, /* Destination ptr */
|
||||
setbuf[128], /* Area for '[...]' sets */
|
||||
*sb; /* Ptr into setbuf */
|
||||
DOUBLE _atof(); /* */
|
||||
/****************************/
|
||||
nitems = 0; /* */
|
||||
while( c = *fmt++ )
|
||||
{
|
||||
if( isspace(c) ) /* if space in spec str */
|
||||
{ /* */
|
||||
do{ /* deblank leading blanks */
|
||||
c = *fmt++; /* */
|
||||
} while( isspace(c) ); /* */
|
||||
do{ /* deblank input stream */
|
||||
NXTNI(ni); /* */
|
||||
} while( isspace(ni) ); /* read past space in input */
|
||||
ungetc(ni,sp); /* back up once */
|
||||
if( c == NULL ) /* check for this here */
|
||||
break; /* */
|
||||
} /* c points to non space */
|
||||
/****************************/
|
||||
if( c != '%' ) /* match spec char (non'%')?*/
|
||||
{ /* */
|
||||
NXTNI(ni); /* grab from input */
|
||||
if( ni != c ) /* & test */
|
||||
{ /* */
|
||||
ungetc(ni,sp); /* nope, put it back */
|
||||
return(nitems); /* return early */
|
||||
} /* */
|
||||
continue; /* yup, do the next char */
|
||||
} else /****************************/
|
||||
c = *fmt++; /* look for an assignment */
|
||||
noassign = FALSE; /* assume we will assign */
|
||||
if( c == '*' ) /* unless they say otherwise*/
|
||||
{
|
||||
noassign++;
|
||||
c = *fmt++;
|
||||
}
|
||||
width = INFINITY; /* assume no special width */
|
||||
while( c >= '0' && c <= '9' ) /* unless they say otherwise*/
|
||||
{
|
||||
if( width == INFINITY )
|
||||
width = 0;
|
||||
width = 10 * width + (c - '0');
|
||||
c = *fmt++;
|
||||
}
|
||||
|
||||
longf = FALSE; /* assume ptrs not to LONGs */
|
||||
shortf = FALSE; /* and not to SHORTs */
|
||||
if( c == 'l' ) /* unless they say otherwise*/
|
||||
{
|
||||
longf++;
|
||||
c = *fmt++;
|
||||
} else if( c=='h' )
|
||||
{
|
||||
shortf++;
|
||||
c = *fmt++;
|
||||
}
|
||||
|
||||
/****************************/
|
||||
switch( c ) /* which conversion char? */
|
||||
{ /****************************/
|
||||
case 'D': /* decimal input */
|
||||
case 'd':
|
||||
base = 10; goto procnum;
|
||||
case 'O': /* octal input */
|
||||
case 'o':
|
||||
base = 8; goto procnum;
|
||||
case 'X': /* hex input */
|
||||
case 'x':
|
||||
base = 16;
|
||||
procnum: /****************************/
|
||||
if( isupper(c) ) /* upper case means long */
|
||||
longf++;
|
||||
do{
|
||||
NXTNI(ni); /* grab a char from input */
|
||||
} while( isspace(ni) ); /* until non-blank */
|
||||
if( noassign )
|
||||
db = &locval; /* got to put it somewhere */
|
||||
else db = *aps++; /* like to put it here */
|
||||
invert = FALSE; /* assume pos number */
|
||||
if( ni=='+' || ni=='-' ) { /* leading plus or minus */
|
||||
if( ni == '-' )
|
||||
invert++;
|
||||
width--;
|
||||
NXTNI(ni);
|
||||
}
|
||||
val = 0L; /* initial value */
|
||||
numfound = FALSE; /* assume guilty til proven */
|
||||
while( width-- > 0 ) { /* for each char ************/
|
||||
tval = ni = toupper(ni); /* should work for numbers */
|
||||
if( tval<'0' || tval>'F')
|
||||
break;
|
||||
if( tval>'9' && tval<'A')
|
||||
break;
|
||||
tval -= '0';
|
||||
if( tval>9 )
|
||||
tval = tval+('0'-'A'+10);
|
||||
if( tval >= base )
|
||||
|
||||
break;
|
||||
numfound++; /* is a number */
|
||||
val = base * val + tval; /* */
|
||||
NXTNI(ni); /* next input, please */
|
||||
} /* *********************/
|
||||
ungetc(ni,sp); /* back off input */
|
||||
if( numfound == FALSE ) /* was it there? */
|
||||
return(nitems); /* no, too bad */
|
||||
if( invert ) /* leading minus? */
|
||||
val = -val; /* */
|
||||
if( longf ) /* store this value */
|
||||
*( long *)db = val; /* somewhere */
|
||||
else if( shortf ) /* */
|
||||
*( short *)db = val; /* somehow */
|
||||
else /* */
|
||||
*( int *)db = val; /* sometime */
|
||||
if( !noassign ) /* increment only if assign */
|
||||
nitems++; /* */
|
||||
break; /****************************/
|
||||
|
||||
case 's': /* string input */
|
||||
case 'c': /* char input */
|
||||
case '[': /* input 'one of' */
|
||||
NXTNI(ni); /* grab a character */
|
||||
if( c== 's' ) /* scan string **************/
|
||||
{
|
||||
sb = " \t\n"; /* point set to white chars */
|
||||
while(_ismem(ni,sb,FALSE)) /* keep reading whitespace */
|
||||
NXTNI(ni); /* if there is any */
|
||||
invert = TRUE; /* after, read until whites */
|
||||
} else if( c == 'c' ) /* scan char ****************/
|
||||
{
|
||||
sb = ""; /* Null set */
|
||||
if( width == INFINITY ) /* handle default width */
|
||||
width = 1;
|
||||
invert = TRUE; /* invert "_ismem" func */
|
||||
} else /* scan set *****************/
|
||||
{ /* must be a '[' */
|
||||
invert = FALSE;
|
||||
if( (c = *fmt++) == '^' ) /* invert "_ismem" ??? */
|
||||
{
|
||||
invert = TRUE;
|
||||
c = *fmt++;
|
||||
}
|
||||
for( sb=setbuf; c != NULL && c != ']'; sb++, c = *fmt++)
|
||||
*sb = c;
|
||||
*sb = NULL;
|
||||
sb = setbuf;
|
||||
}
|
||||
if( noassign )
|
||||
db = locbuf; /* give rtn somewhere to pt */
|
||||
else db = *aps++; /* o.w. grab the desired ptr*/
|
||||
while( width-- > 0 && _ismem(ni,sb,invert) )
|
||||
{
|
||||
*db++ = ni;
|
||||
NXTNI(ni);
|
||||
|
||||
}
|
||||
ungetc(ni,sp); /* we've always read 1 past */
|
||||
if( c != 'c' ) /* not char type? */
|
||||
*db = NULL; /* then null terminate */
|
||||
if( !noassign )
|
||||
nitems++; /* successful assignment */
|
||||
break; /****************************/
|
||||
/****************************/
|
||||
|
||||
case 'E': /*********** not fully implemented **********/
|
||||
case 'e':
|
||||
case 'F':
|
||||
case 'f':
|
||||
if( isupper(c) ) /* upper case means long */
|
||||
longf++;
|
||||
do {
|
||||
NXTNI(ni); /* grab a char from input */
|
||||
} while( isspace(ni) ); /* until non-blank */
|
||||
if( noassign )
|
||||
db = &locval; /* got to put it somewhere */
|
||||
else db = *aps++; /* like to put it here */
|
||||
|
||||
sb = setbuf; /* setup up addr to hold string */
|
||||
while (width-- > 0)
|
||||
{
|
||||
*sb++ = ni;
|
||||
if ((ni < '0' || ni > '9') && (ni != '.')
|
||||
&& (ni != 'e')
|
||||
&& (ni != 'E')
|
||||
&& (ni != '-')
|
||||
&& (ni != '+'))
|
||||
break;
|
||||
NXTNI(ni);
|
||||
}
|
||||
|
||||
ungetc(ni,sp);
|
||||
*--sb = '\0';
|
||||
if (longf)
|
||||
*(double *)db = _atof(setbuf);
|
||||
else
|
||||
*(float *)db = (float) _atof(setbuf);
|
||||
|
||||
if (!noassign)
|
||||
nitems++;
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case '%':
|
||||
default:
|
||||
NXTNI(ni);
|
||||
if( ni != c ) /* must match c */
|
||||
{
|
||||
ungetc(ni,sp);
|
||||
return(nitems);
|
||||
}
|
||||
break;
|
||||
} /***** end switch ***********/
|
||||
} /***** end while loop *******/
|
||||
return(nitems); /* */
|
||||
} /****************************/
|
||||
|
||||
/****************************/
|
||||
MLOCAL WORD _ismem(c,set,invert) /* is_member of a set */
|
||||
BYTE c; /* candidate for set element*/
|
||||
BYTE *set; /* null terminated string */
|
||||
BOOLEAN invert; /* invert sense of function */
|
||||
{ /****************************/
|
||||
REG WORD rv; /* temp return val */
|
||||
rv = strchr(set,c); /* look for c in set */
|
||||
return( invert ? !rv : rv ); /* return (maybe inverted) #*/
|
||||
} /****************************/
|
||||
150
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/down.sub
Normal file
150
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/down.sub
Normal file
@@ -0,0 +1,150 @@
|
||||
e:vax ABORT.S r
|
||||
e:vax ACCESS.C r
|
||||
e:vax ALDIV.S r
|
||||
e:vax ALLOCC.C r
|
||||
e:vax ALMUL.S r
|
||||
e:vax ALREM.S r
|
||||
e:vax ATOI.C r
|
||||
e:vax ATOL.C r
|
||||
e:vax BASEPAGE.H r
|
||||
e:vax BDOS.H r
|
||||
e:vax BLIVOT.S r
|
||||
e:vax BLKIO.C r
|
||||
e:vax C.SUB r
|
||||
e:vax CALLOC.C r
|
||||
e:vax CE.SUB r
|
||||
e:vax CHINIT.C r
|
||||
e:vax CHKC.C r
|
||||
e:vax CHMOD.C r
|
||||
e:vax CHOWN.C r
|
||||
e:vax CLEANUP.C r
|
||||
e:vax CLINK.SUB r
|
||||
e:vax CLINKE.SUB r
|
||||
e:vax CLINKF.SUB r
|
||||
e:vax CLOSE.C r
|
||||
e:vax CPM.H r
|
||||
e:vax CREAT.C r
|
||||
e:vax CREATVMS.C r
|
||||
e:vax CTYPE.C r
|
||||
e:vax CTYPE.H r
|
||||
e:vax DOWN.SUB r
|
||||
e:vax DOWN6.SUB r
|
||||
e:vax ERRNO.C r
|
||||
e:vax ERRNO.H r
|
||||
e:vax EXEC.C r
|
||||
e:vax EXIT.C r
|
||||
e:vax FCLOSE.C r
|
||||
e:vax FDOPEN.C r
|
||||
e:vax FFLUSH.C r
|
||||
e:vax FGETC.C r
|
||||
e:vax FGETS.C r
|
||||
e:vax FOPEN.C r
|
||||
e:vax FPRINTF.C r
|
||||
e:vax FPUTC.C r
|
||||
e:vax FPUTS.C r
|
||||
e:vax FREAD.C r
|
||||
e:vax FREOPEN.C r
|
||||
e:vax FSCANF.C r
|
||||
e:vax FSEEK.C r
|
||||
e:vax FTELL.C r
|
||||
e:vax FTOAVMS.C r
|
||||
e:vax FWRITE.C r
|
||||
e:vax GETL.C r
|
||||
e:vax GETPASS.C r
|
||||
e:vax GETPID.C r
|
||||
e:vax GETS.C r
|
||||
e:vax GETW.C r
|
||||
e:vax INDEX.C r
|
||||
e:vax ISATTY.C r
|
||||
e:vax ISATTYVMS.C r
|
||||
e:vax LDIV.C r
|
||||
e:vax LDIV.S r
|
||||
e:vax LIST.COM r
|
||||
e:vax LISTVMS.COM r
|
||||
e:vax LMUL.S r
|
||||
e:vax LREM.S r
|
||||
e:vax LSEEK.C r
|
||||
e:vax LSEEKVMS.C r
|
||||
e:vax MACHINE.11 r
|
||||
e:vax MACHINE.68K r
|
||||
e:vax MACHINE.H r
|
||||
e:vax MACHINE.VAX r
|
||||
e:vax MAKE.COM r
|
||||
e:vax MAKE.SUB r
|
||||
e:vax MALLOC.C r
|
||||
e:vax MKTEMP.C r
|
||||
e:vax MOPEN.MAR r
|
||||
e:vax NEXT.SUB r
|
||||
e:vax NOFLOAT.S r
|
||||
e:vax OPEN.C r
|
||||
e:vax OPENVMS.C r
|
||||
e:vax PERROR.C r
|
||||
e:vax PORTAB.H r
|
||||
e:vax PRINTF.C r
|
||||
e:vax PUTL.C r
|
||||
e:vax PUTS.C r
|
||||
e:vax PUTW.C r
|
||||
e:vax QSORT.C r
|
||||
e:vax RAND.C r
|
||||
e:vax READ.C r
|
||||
e:vax REAR.COM r
|
||||
e:vax REAR.SUB r
|
||||
e:vax REWIND.C r
|
||||
e:vax RINDEX.C r
|
||||
e:vax S.S r
|
||||
e:vax SBREAK.MAR r
|
||||
e:vax SBRK.C r
|
||||
e:vax SBRKVMS.C r
|
||||
e:vax SCANF.C r
|
||||
e:vax SEND.SUB r
|
||||
e:vax SEND6.SUB r
|
||||
e:vax SETBUF.C r
|
||||
e:vax SETJMP.H r
|
||||
e:vax SETJMP.S r
|
||||
e:vax SGTTY.H r
|
||||
e:vax SIGNAL.C r
|
||||
e:vax SIGNAL.H r
|
||||
e:vax SPRINTF.C r
|
||||
e:vax SSCANF.C r
|
||||
e:vax STDIO.H r
|
||||
e:vax STKCPY.S r
|
||||
e:vax STRCAT.C r
|
||||
e:vax STRCMP.C r
|
||||
e:vax STRCPY.C r
|
||||
e:vax STRINS.C r
|
||||
e:vax STRLEN.C r
|
||||
e:vax STRNCAT.C r
|
||||
e:vax STRNCMP.C r
|
||||
e:vax STRNCPY.C r
|
||||
e:vax SWAB.C r
|
||||
e:vax TTYNAME.C r
|
||||
e:vax ULDIV.S r
|
||||
e:vax ULDIVVMS.C r
|
||||
e:vax UNGETC.C r
|
||||
e:vax UNLINK.C r
|
||||
e:vax UNLINKVMS.C r
|
||||
e:vax UP6.SUB r
|
||||
e:vax VMAKE.COM r
|
||||
e:vax VMS.H r
|
||||
e:vax VSEND.COM r
|
||||
e:vax W.S r
|
||||
e:vax WRITE.C r
|
||||
e:vax XDOPRT.C r
|
||||
e:vax XDOPRTFP.C r
|
||||
e:vax XDOSCAN.C r
|
||||
e:vax XFDECLS.C r
|
||||
e:vax XFILBUF.C r
|
||||
e:vax XFILESZ.C r
|
||||
e:vax XFLSBFVMS.C r
|
||||
e:vax XFLSBUF.C r
|
||||
e:vax XFPRINTF.C r
|
||||
e:vax XHDR.MAR r
|
||||
e:vax XMAIN.C r
|
||||
e:vax XOPEN.C r
|
||||
e:vax XPRTINT.C r
|
||||
e:vax XPRTLD.C r
|
||||
e:vax XPRTSHRT.C r
|
||||
e:vax XSIGNAL.S r
|
||||
e:vax XSTRCMP.C r
|
||||
e:vax XTTYIN.C r
|
||||
e:vax XWMAIN.C r
|
||||
122
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/down6.sub
Normal file
122
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/down6.sub
Normal file
@@ -0,0 +1,122 @@
|
||||
vax ACCESS.C r
|
||||
vax ALLOCC.C r
|
||||
vax ATOI.C r
|
||||
vax ATOL.C r
|
||||
vax CPM.h r
|
||||
vax CALLOC.C r
|
||||
vax CHINIT.C r
|
||||
vax CHKC.C r
|
||||
vax CHMOD.C r
|
||||
vax CHOWN.C r
|
||||
vax CLEANUP.C r
|
||||
vax CLOSE.C r
|
||||
vax CREAT.C r
|
||||
vax CTYPE.C r
|
||||
vax ERRNO.C r
|
||||
vax EXEC.C r
|
||||
vax EXIT.C r
|
||||
vax FCLOSE.C r
|
||||
vax FDOPEN.C r
|
||||
vax FFLUSH.C r
|
||||
vax FGETC.C r
|
||||
vax FGETS.C r
|
||||
vax FOPEN.C r
|
||||
vax FPRINTF.C r
|
||||
vax FPUTC.C r
|
||||
vax FPUTS.C r
|
||||
vax FREAD.C r
|
||||
vax FREOPEN.C r
|
||||
vax FSCANF.C r
|
||||
vax READ.C r
|
||||
vax FTELL.C r
|
||||
vax FWRITE.C r
|
||||
vax GETL.C r
|
||||
vax GETPASS.C r
|
||||
vax GETPID.C r
|
||||
vax GETS.C r
|
||||
vax GETW.C r
|
||||
vax INDEX.C r
|
||||
vax ISATTY.C r
|
||||
vax LDIV.C r
|
||||
vax LSEEK.C r
|
||||
vax MALLOC.C r
|
||||
vax MKTEMP.C r
|
||||
vax OPEN.C r
|
||||
vax PERROR.C r
|
||||
vax PRINTF.C r
|
||||
vax PUTL.C r
|
||||
vax PUTS.C r
|
||||
vax PUTW.C r
|
||||
vax QSORT.C r
|
||||
vax RAND.C r
|
||||
vax REAR.SUB r
|
||||
vax REWIND.C r
|
||||
vax RINDEX.C r
|
||||
vax SBRK.C r
|
||||
vax SCANF.C r
|
||||
vax SETBUF.C r
|
||||
vax SIGNAL.C r
|
||||
vax SPRINTF.C r
|
||||
vax SSCANF.C r
|
||||
vax STRCAT.C r
|
||||
vax STRCMP.C r
|
||||
vax STRCPY.C r
|
||||
vax STRINS.C r
|
||||
vax STRLEN.C r
|
||||
vax STRNCAT.C r
|
||||
vax STRNCMP.C r
|
||||
vax STRNCPY.C r
|
||||
vax SWAB.C r
|
||||
vax TTYNAME.C r
|
||||
vax UNGETC.C r
|
||||
vax UNLINK.C r
|
||||
vax XFILESZ.C r
|
||||
vax XDOPRT.C r
|
||||
vax XDOPRTFP.C r
|
||||
vax XDOSCAN.C r
|
||||
vax XEXIT.C r
|
||||
vax XFDECLS.C r
|
||||
vax XFILBUF.C r
|
||||
vax XOPEN.C r
|
||||
vax XFLSBUF.C r
|
||||
vax XFPRINTF.C r
|
||||
vax XMAIN.C r
|
||||
vax XPRTINT.C r
|
||||
vax XPRTLD.C r
|
||||
vax XPRTSHRT.C r
|
||||
vax XSTRCMP.C r
|
||||
vax XTTYIN.C r
|
||||
vax XWMAIN.C r
|
||||
vax ABORT.S r
|
||||
vax ALDIV.S r
|
||||
vax ALMUL.S r
|
||||
vax ALREM.S r
|
||||
vax BLIVOT.S r
|
||||
vax LDIV.S r
|
||||
vax LMUL.S r
|
||||
vax LREM.S r
|
||||
vax NOFLOAT.S r
|
||||
vax W.S r
|
||||
vax SETJMP.S r
|
||||
vax STKCPY.S r
|
||||
vax ULDIV.S r
|
||||
vax XSIGNAL.S r
|
||||
vax BASEPAGE.h r
|
||||
vax BDOS.h r
|
||||
vax FSEEK.C r
|
||||
vax CTYPE.h r
|
||||
vax ERRNO.h r
|
||||
vax PORTAB.h r
|
||||
vax SETJMP.h r
|
||||
vax SGTTY.h r
|
||||
vax SIGNAL.h r
|
||||
vax STDIO.h r
|
||||
vax C.SUB r
|
||||
vax CLINK.SUB r
|
||||
vax NEXT.SUB r
|
||||
vax S.S r
|
||||
vax MAKE.SUB r
|
||||
vax BLKIO.C r
|
||||
vax WRITE.C r
|
||||
vax SEND6.SUB r
|
||||
vax up6.sub r
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* errno.c : declares storage for errno, a variable containing the last
|
||||
* system error.
|
||||
*/
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
|
||||
WORD errno = 0; /* set by low level i/o, unset by user (if at all) */
|
||||
WORD _errcpm = 0; /* assign BDOS return val when assigning errno */
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
/*
|
||||
* errno.h - error codes
|
||||
*/
|
||||
|
||||
#define EPERM 1
|
||||
#define ENOENT 2
|
||||
#define ESRCH 3
|
||||
#define EINTR 4
|
||||
#define EIO 5
|
||||
#define ENXIO 6
|
||||
#define E2BIG 7
|
||||
#define ENOEXEC 8
|
||||
#define EBADF 9
|
||||
#define ECHILD 10
|
||||
#define EAGAIN 11
|
||||
#define ENOMEM 12
|
||||
#define EACCES 13
|
||||
#define EFAULT 14
|
||||
#define ENOTBLK 15
|
||||
#define EBUSY 16
|
||||
#define EEXIST 17
|
||||
#define EXDEV 18
|
||||
#define ENODEV 19
|
||||
#define ENOTDIR 20
|
||||
#define EISDIR 21
|
||||
#define EINVAL 22
|
||||
#define ENFILE 23
|
||||
#define EMFILE 24
|
||||
#define ENOTTY 25
|
||||
#define ETXTBSY 26
|
||||
#define EFBIG 27
|
||||
#define ENOSPC 28
|
||||
#define ESPIPE 29
|
||||
#define EROFS 30
|
||||
#define EMLINK 31
|
||||
#define EPIPE 32
|
||||
|
||||
/* math software */
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
|
||||
/* hereafter is available to CP/M specials */
|
||||
#define ENODSPC 35
|
||||
#define ERENAME 36
|
||||
|
||||
/****** end of errno.h ******/
|
||||
|
||||
54
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/exec.c
Normal file
54
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/exec.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* E x e c F u n c t i o n
|
||||
* -------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The execl function is called from anywhere to pass control to
|
||||
* another program from the the executing C program.
|
||||
* Note that the stream files are closed via '_cleanup()'.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* execl(name,arg0,arg1,...,argn,NULLPTR);
|
||||
*
|
||||
* Where:
|
||||
* name, arg0, arg1...argn are pointers to character strings
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
#include "osiferr.h"
|
||||
#include "errno.h"
|
||||
#include "ctype.h"
|
||||
|
||||
UWORD execl(name,arg0) /* CLEAR FUNCTION ***********/
|
||||
UBYTE *name,*arg0; /* pointers arguments */
|
||||
{ /* */
|
||||
REG UBYTE **args; /* used to index into args */
|
||||
UBYTE cmdline[128]; /* CP/M command line area */
|
||||
REG WORD i; /***************************/
|
||||
/* */
|
||||
_cleanup(); /* Close all (stream) files*/
|
||||
/* now build cmdline */
|
||||
strcpy(cmdline,name); /* Copy name portion */
|
||||
#if PCDOS == 0 /* Don't do for PCDOS */
|
||||
for(i = strlen(cmdline); --i >= 0; ) /* uppercase command name */
|
||||
cmdline[i] = toupper(cmdline[i]); /* */
|
||||
#endif /***************************/
|
||||
args = &arg0; /* Copy args */
|
||||
args++; /* arg0 is a dup of the */
|
||||
/* command name */
|
||||
while(*args != NULLPTR) /***************************/
|
||||
{ /* */
|
||||
strcat(cmdline," "); /* Add a blank */
|
||||
strcat(cmdline,*args++); /* Add next arg */
|
||||
} /***************************/
|
||||
#if PCDOS /* handle differently ifso */
|
||||
_pc_chain(cmdline); /* special home grown func */
|
||||
#else /* O.S. handles it? */
|
||||
__OSIF(SETDMA,cmdline); /* DMA -> Command line */
|
||||
__OSIF(P_CHAIN,0); /* chain to program */
|
||||
#endif
|
||||
RETERR(FAILURE,ENOENT); /* error: file not found */
|
||||
} /***************************/
|
||||
27
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/exit.c
Normal file
27
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/exit.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* E x i t F u n c t i o n
|
||||
* -------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The exit function is called from anywhere to pass control back to
|
||||
* the CCP from the executing C program.
|
||||
* Note that the stream files are closed via '_cleanup()'.
|
||||
*
|
||||
* Calling Sequence:
|
||||
*
|
||||
* exit(code);
|
||||
*
|
||||
* Where:
|
||||
* code Is the exit status (ignored)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
VOID exit(code) /* CLEAR FUNCTION ***********/
|
||||
WORD code; /* Exit status */
|
||||
{ /* */
|
||||
_cleanup(); /* Close all (stream) files*/
|
||||
_exit(code); /* return to O.S. */
|
||||
} /***************************/
|
||||
@@ -0,0 +1,34 @@
|
||||
/*********************************************************************
|
||||
*
|
||||
* f c l o s e F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fclose" flushes a stream (buffered file) and releases the
|
||||
* channel and any allocated buffers.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = fclose(stream)
|
||||
* Where:
|
||||
* stream -> file to be closed (FILE *)
|
||||
* ret = SUCCESS or FAILURE (if IO error)
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fclose(sp) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp; /* stream to close */
|
||||
{ /* */
|
||||
/****************************/
|
||||
if( sp->_flag & (_IOREAD|_IOWRT) ) /* is it closeable? */
|
||||
{ /* yup... */
|
||||
fflush(sp); /* do the flush */
|
||||
if( sp->_flag & _IOABUF ) /* was buf alloc'd? */
|
||||
free(sp->_base); /* free it ifso */
|
||||
sp->_base = sp->_ptr = NULL; /* reset these */
|
||||
sp->_cnt = 0; /* */
|
||||
} /* reset all flags */
|
||||
sp->_flag &= ~(_IOREAD|_IOWRT|_IOABUF|_IONBUF|_IOERR|_IOEOF|_IOLBUF);
|
||||
return(close(sp->_fd)); /* and return */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* D a t a D e c l a r a t i o n s M o d u l e
|
||||
* -----------------------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Herein lie the data definitions for the stdio.h functions.
|
||||
* Note: function __fdecls() is here so _main can force this module to
|
||||
* be loaded.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#define FILE /* avoid duplicate decls */
|
||||
#include "stdio.h"
|
||||
|
||||
#if MAXFILES != 16
|
||||
compile snafu: fix following table
|
||||
#endif
|
||||
|
||||
struct _iobuf _iob[16] ={
|
||||
{ 0, _IOREAD, NULLPTR, NULLPTR, 0},
|
||||
{ 1, _IOWRT+_IONBUF, NULLPTR, NULLPTR, 0},
|
||||
{ 2, _IOWRT+_IONBUF, NULLPTR, NULLPTR, 0},
|
||||
{ 3, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 4, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 5, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 6, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 7, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 8, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 9, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 10, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 11, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 12, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 13, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 14, 0, NULLPTR, NULLPTR, 0 },
|
||||
{ 15, 0, NULLPTR, NULLPTR, 0 }
|
||||
};
|
||||
|
||||
__fdecls()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* f d o p e n F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fdopen" associates a file which was opened by a file descriptor
|
||||
* (using "open" or "creat") with a stream.
|
||||
*
|
||||
* Calling sequence:
|
||||
* stream = fdopen( fd, mode )
|
||||
* Where:
|
||||
* stream -> stream info (FILE *) (NULLPTR returned on fail)
|
||||
* fd = small int returned by open or creat
|
||||
* mode = "r" for read-only, "w" for write, "a" for append
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
FILE * fdopen( fd, mode ) /* CLEAR FUNCTION ***********/
|
||||
REG WORD fd;
|
||||
REG BYTE *mode;
|
||||
{
|
||||
REG FILE *sp;
|
||||
REG WORD ii;
|
||||
/****************************/
|
||||
if( fd<0 || lseek(fd,0L,1)==FAILURE ) /* is fd valid? */
|
||||
return(NULLFILE); /* no, oh well */
|
||||
for( ii=0; /* look at _iob table */
|
||||
(sp=(&_iob[ii]))->_flag&(_IOREAD|_IOWRT); /* not marked rd/wrt */
|
||||
ii++ ) /* */
|
||||
if( ii >= MAXFILES ) /* if off end of table */
|
||||
break; /* */
|
||||
if( ii >= MAXFILES ) /* */
|
||||
return(NULLFILE); /* fail */
|
||||
if( *mode != 'r' && *mode != 'R') /* not 'r'ead mode? */
|
||||
{ /* */
|
||||
sp->_flag |= _IOWRT; /* set this flag */
|
||||
if( *mode == 'a' || /* 'a'ppend mode? */
|
||||
*mode == 'A' ) /* */
|
||||
lseek(fd,0L,2); /* its out there, seef EOF */
|
||||
} /* ************************/
|
||||
else sp->_flag |= _IOREAD; /* 'r'ead mode */
|
||||
/****************************/
|
||||
sp->_cnt = 0; /* init count */
|
||||
sp->_fd = fd; /* and file des */
|
||||
sp->_base = sp->_ptr = NULLPTR; /* and buffer pointers */
|
||||
/****************************/
|
||||
return(sp); /* return the stream ptr */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* f f l u s h F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* 'fflush' causes any buffered data in a stream to be written out
|
||||
* to the file. The stream remains open.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = fflush(stream)
|
||||
* Where:
|
||||
* stream is a (FILE *)
|
||||
* ret = SUCCESS or FAILURE (I/O error)
|
||||
*
|
||||
* 9/83 fix fseek(stream,xx,1) bug whf
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fflush(sp) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp; /* stream to flush */
|
||||
{ /****************************/
|
||||
REG WORD n, /* num written */
|
||||
ns; /* num sposed to be written */
|
||||
/****************************/
|
||||
if((sp->_flag&(_IONBUF|_IOWRT))==_IOWRT /* does it have a wrt buf? */
|
||||
&& (ns=(WORD)sp->_ptr-sp->_base) > 0 )/* and does buf need wrt?*/
|
||||
{ /* yes! */
|
||||
n=write(sp->_fd,sp->_base,ns); /* do it */
|
||||
if(ns!=n) /* did they all git writ? */
|
||||
{ /* oooops */
|
||||
sp->_flag |= _IOERR; /* this stream no good */
|
||||
return(FAILURE); /* let em know */
|
||||
} /* */
|
||||
} /****************************/
|
||||
if( sp->_flag & _IOWRT ) /* is this a writable file? */
|
||||
{ /* */
|
||||
if( sp->_base != NULL ) /* written to already? */
|
||||
{ /* */
|
||||
if(sp->_flag&_IONBUF) /* is this a nobuf stream? */
|
||||
sp->_cnt = 1; /* yes */
|
||||
else sp->_cnt = BUFSIZ-1; /* standard size */
|
||||
} /* */
|
||||
} else { /* is a readable file */
|
||||
lseek(sp->_fd,(LONG) -(sp->_cnt),1);/* back up cur position ptr */
|
||||
sp->_cnt = 0; /* zap out count */
|
||||
} /* */
|
||||
sp->_ptr=sp->_base; /* reset buf */
|
||||
return(SUCCESS); /* */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,28 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f g e t c F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Function "fgetc" does the yanking of a char out of the stream.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ch = fgetc(s)
|
||||
* Where:
|
||||
* ch = a (WORD) character (-1 on EOF)
|
||||
* s -> a stream file (FILE *)
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
#define CMASK 0xFF
|
||||
|
||||
WORD fgetc(sp) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp; /* stream pointer */
|
||||
{ /****************************/
|
||||
EXTERN WORD _filbuf(); /* use this when we run shrt*/
|
||||
if( --sp->_cnt >= 0 ) /* any chars left in buf? */
|
||||
return(((WORD) *sp->_ptr++) & CMASK);/* return & advance ptr ifso*/
|
||||
else /* */
|
||||
return( _filbuf(sp) ); /* o.w. whatever happens */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,43 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* f g e t s F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fgets" reads a string from a stream file (up to n-1 chars), and
|
||||
* returns pointer s (NULLPTR on end of file). The newline at the
|
||||
* end of line is included, NOT replaced, and the string is terminated
|
||||
* by a NULL.
|
||||
*
|
||||
* Calling sequence:
|
||||
* addr = fgets(saddr,n,stream)
|
||||
* Where:
|
||||
* saddr -> where the string is to go (no bounds check)
|
||||
* n = max # chars (inc. NULL) for saddr (assumed > 0)
|
||||
* stream-> where to get from
|
||||
* addr = saddr if all ok, NULLPTR o.w.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
BYTE *fgets(str,maxc,sp) /*CLEAR Function */
|
||||
REG BYTE *str; /* string save area */
|
||||
REG WORD maxc; /* max size of string */
|
||||
REG FILE *sp; /* where to get from */
|
||||
{ /****************************/
|
||||
REG WORD c; /* char to test for eof */
|
||||
REG BYTE *sav; /* sav pointer for return */
|
||||
sav = str; /* remember this */
|
||||
while( --maxc > 0 && /* while there's still room */
|
||||
/* for getc and NULL */
|
||||
(c=getc(sp)) != FAILURE ) /* and read_char ok */
|
||||
{ /* */
|
||||
*str++ = c; /* store it */
|
||||
if( c == '\n' ) /* if end of line */
|
||||
break; /* stop the presses */
|
||||
} /* */
|
||||
*str = NULL; /* clean up string */
|
||||
if(c == FAILURE) /* if not cool */
|
||||
return(NULLPTR); /* then tell them so */
|
||||
return(sav); /* tell them is cool */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,60 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* _ f i l b u f F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "_filbuf" function is called by getc to fill the buffer.
|
||||
* It performs any initialization of the buffered on the first
|
||||
* call.
|
||||
*
|
||||
* Calling sequence:
|
||||
* char = _filbuf(stream)
|
||||
* Where:
|
||||
* stream -> file info
|
||||
* char = the first character returned, or FAILURE (-1)
|
||||
* on error or EOF
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
#define CMASK 0xFF
|
||||
|
||||
WORD _filbuf(sp) /* fill buffer */
|
||||
REG FILE *sp; /* from this stream */
|
||||
{ /****************************/
|
||||
static BYTE onebuf[MAXFILES]; /* a place if no mem avail. */
|
||||
/* small buf for ungetc */
|
||||
EXTERN BYTE *malloc(); /* someplace to get mem */
|
||||
/****************************/
|
||||
if((sp->_flag & _IOREAD) == 0) /* is readable file? */
|
||||
return(FAILURE); /* no */
|
||||
if( sp->_flag & _IOSTRI ) /* is this stream a string? */
|
||||
{ /* yes: handle EOS as EOF*/
|
||||
sp->_flag |= _IOEOF; /* */
|
||||
return(FAILURE); /* */
|
||||
} /****************************/
|
||||
if( sp->_base == NULL ) /* has this been done? */
|
||||
{ /* no...*********************/
|
||||
if( sp->_flag & _IONBUF || /* is the No Buf flag set? */
|
||||
(sp->_base=malloc(BUFSIZ))==NULL) /* can't we get buffer? */
|
||||
sp->_flag |= _IONBUF; /* set No Buf flag */
|
||||
else sp->_flag |= _IOABUF; /* we're all set */
|
||||
} /****************************/
|
||||
if( sp->_flag & _IONBUF ) /* insure this set right */
|
||||
sp->_base = &onebuf[sp->_fd]; /* set 'buf' to small buf */
|
||||
if( sp==stdin && (stdout->_flag&_IOLBUF))/* console i/o? */
|
||||
fflush(stdout); /* output whatever to con */
|
||||
sp->_cnt = read(sp->_fd, sp->_base, /* read to our buffer */
|
||||
sp->_flag & _IONBUF ? 1 : BUFSIZ); /* the right # of bytes */
|
||||
if( sp->_cnt <= 0 ) /* did read screw up? */
|
||||
{ /* yup...********************/
|
||||
if( sp->_cnt == FAILURE ) /* really bad? */
|
||||
sp->_flag |= _IOERR|_IOEOF; /* say so */
|
||||
else sp->_flag |= _IOEOF; /* or just say we can't read*/
|
||||
return(FAILURE); /* */
|
||||
} /****************************/
|
||||
sp->_cnt--; /* take the 1st item */
|
||||
sp->_ptr=sp->_base; /* set up stream */
|
||||
return(((WORD)(*sp->_ptr++) & CMASK)); /* and return the char */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,92 @@
|
||||
/**********************************************************************
|
||||
*
|
||||
* _ f i l e s z f u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* This routine computes the size of a CP/M file, and leaves the fd
|
||||
* pointing to the end of file.
|
||||
* Note that the file must have been previously opened.
|
||||
*
|
||||
* Calling sequence:
|
||||
* size = _filesz(fd)
|
||||
* where:
|
||||
* size = # bytes in file;
|
||||
* 0 if not disk file;
|
||||
* -1 if I/O error
|
||||
* fd = file descriptor returned by open.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
#include "osiferr.h"
|
||||
#include "errno.h"
|
||||
|
||||
LONG _filesz(fd) /****************************/
|
||||
WORD fd; /* file descriptor */
|
||||
{
|
||||
REG FD *fp; /* file's ccb pointer */
|
||||
REG BYTE *p1, *p2; /* temps for buffer work */
|
||||
REG LONG xsector; /* where we are in file */
|
||||
FD *_chkc(); /* cvt & check fd to fp */
|
||||
REG WORD xuser; /* Current user # */
|
||||
/****************************/
|
||||
if((fp = _chkc(fd)) == NULLFD) /* Convert to pointer */
|
||||
return(FAILURE); /* Can't: EBADF */
|
||||
if(fp->flags&(ISTTY|ISLPT)) /* Non disk file? */
|
||||
return(0); /* */
|
||||
#if PCDOS /*================================================================*/
|
||||
fp->offset = (fp->fcb).fcb_filsiz; /* simple, eh? */
|
||||
#endif /*================================================================*/
|
||||
|
||||
#if CPM /*================================================================*/
|
||||
|
||||
if( fp->flags & DIRTY ) { /* File been used? */
|
||||
fp->offset = fp->hiwater; /* yes: this must be right */
|
||||
} else { /****************************/
|
||||
xuser = _chkuser(fp->user); /* Check user # for change */
|
||||
__OSIF(FILSIZ,&(fp->fcb)); /* Do BDOS call */
|
||||
_uchkuser(fp->user,xuser); /* Change back if needed */
|
||||
#if HILO /*--------------------------*/
|
||||
fp->fcb.record &= 0xFFFFFFL; /* mask off cr byte */
|
||||
xsector = fp->fcb.record - 1; /* last sector in file */
|
||||
#else /*--------------------------*/
|
||||
xsector = (fp->fcb.record >>8) - 1; /* last sector in file */
|
||||
#endif /*--------------------------*/
|
||||
if( fp->flags & ISASCII ) /****************************/
|
||||
{ /* Ascii file: posit to EOF */
|
||||
if(xsector >= 0) /* if any size at all */
|
||||
{ /* *********************/
|
||||
if( xsector != fp->sector ) /* need to change sector? */
|
||||
{ /* get correct sector********/
|
||||
if((fp->flags & DIRTY) != 0) /* Something to write 1st? */
|
||||
{ /* */
|
||||
if(_blkio(fp,fp->sector,fp->buffer, /* Write out */
|
||||
1L,B_WRITE) != 1) /* the buffer */
|
||||
RETERR(FAILURE,EIO); /* */
|
||||
fp->flags &= ~DIRTY; /* turn off this bit */
|
||||
} /* */
|
||||
if(_blkio(fp,xsector,fp->buffer, /* scan this last sector */
|
||||
1L,B_READ) != 1) /* for EOFCHAR */
|
||||
RETERR(FAILURE,EIO); /* */
|
||||
} /* got correct sector********/
|
||||
fp->sector = xsector; /* */
|
||||
fp->offset = xsector << 7; /* */
|
||||
p1 = &(fp->buffer[0]); /* start of buf */
|
||||
p2 = &(fp->buffer[SECSIZ]); /* end of buf */
|
||||
while( p1<p2 && *p1 != EOFCHAR) /* look for EOFCHAR */
|
||||
p1++; /* */
|
||||
fp->offset += p1-&(fp->buffer[0]); /* update offset to EOF */
|
||||
} /* *********************/
|
||||
else fp->offset=0; /* o.w. beginning of file */
|
||||
/****************************/
|
||||
} else { /* Binary file:compute size */
|
||||
fp->offset = (xsector+1) << 7; /* set to end of last record*/
|
||||
} /****************************/
|
||||
} /****************************/
|
||||
#endif /*================================================================*/
|
||||
fp->hiwater = fp->offset; /* whatever happened, set it*/
|
||||
fp->flags |= ATEOF; /* make sure they know */
|
||||
return(fp->offset); /* this is it */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,84 @@
|
||||
/************************************************************************
|
||||
*
|
||||
* _ f l s b u f F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* '_flsbuf' handles writes to the stream when its buffer is full.
|
||||
* Included is the ability to handle 'non-buffered' (_IONBUF), as
|
||||
* well as line buffered (_IOLBUF) output. It is supposed to be
|
||||
* called by 'putc'. It will init the buffers, as needed.
|
||||
*
|
||||
* Calling sequence:
|
||||
* chr = _flsbuf( ch, stream )
|
||||
* Where:
|
||||
* ch = the 1st char to be buffered
|
||||
* stream -> where its going (FILE *)
|
||||
* chr = ch if write ok, FAILURE (-1 WORD) o.w.
|
||||
*
|
||||
* Modifications:
|
||||
* 19-Oct-83 whf Handle IONBUF differently
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD _flsbuf(c,sp) /****************************/
|
||||
REG BYTE c; /* char to be written */
|
||||
REG FILE *sp; /* stream to write to */
|
||||
{ /****************************/
|
||||
BYTE csave; /* a temp save area */
|
||||
BYTE *malloc(); /* alloc memory */
|
||||
REG WORD n, /* number chars written */
|
||||
ns; /* num chars sposed to be w.*/
|
||||
/* */
|
||||
ns = n = 0; /* init them */
|
||||
if( (sp->_flag & _IOWRT) == 0 ) /* is this file writeable? */
|
||||
return(FAILURE); /* no! */
|
||||
if( sp->_base == NULLPTR && /* if no init yet and */
|
||||
(sp->_flag & _IONBUF) == 0 ) /* and not a no buff file */
|
||||
{ /* ifso...*******************/
|
||||
if( (sp->_ptr=sp->_base=malloc(BUFSIZ)) == NULLPTR ) /* alloc ok?*/
|
||||
sp->_flag |= _IONBUF; /* set to a no buff file */
|
||||
else { /* o.w. we have a buffer! */
|
||||
sp->_flag |= _IOABUF; /* mark it as alloc'd */
|
||||
if( isatty(sp->_fd) ) /* do we handle newlines? */
|
||||
sp->_flag |= _IOLBUF; /* yessir, this is a linbuf */
|
||||
else { /* o.w. *********************/
|
||||
sp->_cnt = BUFSIZ-2; /* lv room for 1st & last ch*/
|
||||
return(*sp->_ptr++ = c); /* store 1st & quit */
|
||||
} /*tty chk********************/
|
||||
} /*malloc*********************/
|
||||
} /*NULL buff******************/
|
||||
if( sp->_flag & _IONBUF ) /* insure this pts ok */
|
||||
sp->_ptr = sp->_base = &csave; /* give buff a temp place */
|
||||
*sp->_ptr++ = c; /* put this somewhere */
|
||||
if( sp->_flag & _IONBUF ) /* if a no buff file */
|
||||
|
||||
{ /* */
|
||||
n=write(sp->_fd,sp->_base,(ns=1)); /* write single char */
|
||||
sp->_cnt = 0; /* enforce coming back again*/
|
||||
} /****************************/
|
||||
else if( sp->_flag & _IOLBUF ) /* if a line buff file */
|
||||
{ /* */
|
||||
if(c=='\n' || sp->_ptr >= sp->_base+BUFSIZ ) /* buf full or '\n'*/
|
||||
{ /* */
|
||||
n=write(sp->_fd,sp->_base, /* output the line */
|
||||
(ns=sp->_ptr-sp->_base)); /* */
|
||||
sp->_ptr = sp->_base; /* reset the buffer */
|
||||
} /* */
|
||||
sp->_cnt = 0; /* enforce coming right back*/
|
||||
} /****************************/
|
||||
else /* o.w. we really have a */
|
||||
{ /* full buffer */
|
||||
n=write(sp->_fd,sp->_base, /* output the whole buff */
|
||||
(ns=sp->_ptr-sp->_base)); /* */
|
||||
sp->_cnt = BUFSIZ-1; /* lv room for last char */
|
||||
sp->_ptr = sp->_base; /* init ptr */
|
||||
} /* end buf handlers**********/
|
||||
if( ns != n ) /* error on write? */
|
||||
{ /* */
|
||||
sp->_flag |= _IOERR; /* mark stream */
|
||||
return(FAILURE); /* and die */
|
||||
} /****************************/
|
||||
return(((WORD) c) & 0xff ); /* everything ok, quit */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,94 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f o p e n F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fopen" opens a buffered stream file, either on disk, console, or
|
||||
* line printer.
|
||||
* Note that "fopen" comes in three (3) flavors, one for ascii CP/M
|
||||
* files, another for binary files, and the default (presently to
|
||||
* ascii files).
|
||||
*
|
||||
* Calling sequence:
|
||||
* stream = fopena(name,mode) (ascii files)
|
||||
* stream = fopenb(name,mode) (binary files)
|
||||
* stream = fopen(name,mode) (default-ascii files)
|
||||
* stream = _fopen(name,mode,ascii)
|
||||
* Where:
|
||||
* stream -> file opened (FILE *), NULLPTR if failure
|
||||
* name -> NULL terminated string containing filename,
|
||||
* name="CON:" means the console,
|
||||
* name="LST:" goes to the line printer, and
|
||||
* otherwise a disk file is assumed.
|
||||
* mode -> "r" for read only,
|
||||
* "w" for write only,
|
||||
* "a" to append (write only) to end of file.
|
||||
* ascii = 0 if the file is handled as a CP/M text file
|
||||
* (newline -> CRLF xlation, ^Z EOF convention).
|
||||
* Otherwise, file is treated as a binary file.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h" /****************************/
|
||||
#define READ 0 /* read mode val */
|
||||
#define WRITE 1 /* write mode val */
|
||||
#define CREATMODE 1 /* mode to use for 'creat' */
|
||||
/****************************/
|
||||
FILE * _fopen(name,mode,ascii) /* */
|
||||
REG BYTE *name, /* file name */
|
||||
*mode; /* "r","w", or "a" */
|
||||
BOOLEAN ascii; /* CP/M text file */
|
||||
{ /****************************/
|
||||
REG FILE *sp; /* stream pointer */
|
||||
REG WORD ii, /* index into _iob */
|
||||
fd; /* file descriptor */
|
||||
/****************************/
|
||||
for( ii=0; /* look at _iob table */
|
||||
(sp=(&_iob[ii]))->_flag&(_IOREAD|_IOWRT); /* not marked rd/wrt */
|
||||
ii++ ) /* */
|
||||
if( ii >= MAXFILES ) /* if off end of table */
|
||||
break; /* */
|
||||
if( ii >= MAXFILES ) /* */
|
||||
return(NULLFILE); /* fail */
|
||||
if( *mode == 'w' || *mode == 'W' ) /* 'w'rite mode? */
|
||||
fd=_creat(name,CREATMODE,ascii);/* create file *********/
|
||||
else if( *mode == 'a' || *mode == 'A' ) /* 'a'ppend mode? */
|
||||
{ /* */
|
||||
if( (fd=_open(name,WRITE,ascii)) < 0 ) /* try open */
|
||||
fd=_creat(name,CREATMODE,ascii);/* ow. do create */
|
||||
else lseek(fd,0L,2); /* its out there, seef EOF */
|
||||
} /* ************************/
|
||||
else if( *mode == 'r' || *mode == 'R' ) /* 'r'ead mode? */
|
||||
fd=_open(name,READ,ascii); /* try open ************/
|
||||
else return(NULLFILE); /* bad mode barf... */
|
||||
/****************************/
|
||||
if(fd<0) /* did one of those work? */
|
||||
return(NULLFILE); /* no, oh well */
|
||||
sp->_cnt = 0; /* init count */
|
||||
sp->_fd = fd; /* and file des */
|
||||
sp->_base = sp->_ptr = NULLPTR; /* and buffer pointers */
|
||||
if( *mode == 'r' || *mode == 'R' ) /* 'r'ead mode? */
|
||||
sp->_flag = _IOREAD; /* say so */
|
||||
else sp->_flag = _IOWRT; /* else 'w'rite mode */
|
||||
if( ascii == 0 ) /* ascii mode? */
|
||||
sp->_flag |= _IOASCI; /* */
|
||||
/****************************/
|
||||
return(sp); /* return the stream ptr */
|
||||
} /****************************/
|
||||
|
||||
/****************************/
|
||||
FILE * fopen(name,mode) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name, *mode; /* */
|
||||
{ /* */
|
||||
return(_fopen(name,mode,0)); } /* ascii file open */
|
||||
/****************************/
|
||||
FILE * fopena(name,mode) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name,*mode; /* */
|
||||
{ /* */
|
||||
return(_fopen(name,mode,0)); } /* ascii file open */
|
||||
/****************************/
|
||||
FILE * fopenb(name,mode) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name, *mode; /* */
|
||||
{ /* */
|
||||
return(_fopen(name,mode,1)); } /* binary file open */
|
||||
@@ -0,0 +1,23 @@
|
||||
/************************************************************************
|
||||
*
|
||||
* f p r i n t f F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fprintf" prints args specified in format string to a stream file.
|
||||
*
|
||||
* Calling sequence:
|
||||
* nchrs = fprintf(fmt,arg1,arg2,...argn);
|
||||
* Where:
|
||||
* nchrs = number of chars output
|
||||
* fmt -> a string specifying how arg1-n are to be printed.
|
||||
*
|
||||
**************************************************************************/
|
||||
#include <stdio.h>
|
||||
WORD fprintf(stream,fmt,args)
|
||||
FILE *stream;
|
||||
BYTE *fmt,
|
||||
*args;
|
||||
{
|
||||
return(_doprt(stream,fmt,&args));
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* f p u t c F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fputc" does the inserting of a char into a stream buffer,
|
||||
* calling _flsbuf when the buffer fills up.
|
||||
* Returns the character put, or FAILURE (-1) if any errors.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret=fputc(ch,s)
|
||||
* Where:
|
||||
* ch = the char to put
|
||||
* s -> the stream (FILE *)
|
||||
* ret= ch or FAILURE
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fputc(ch,sp) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE ch; /* char to put */
|
||||
REG FILE *sp; /* stream to put it to */
|
||||
{ /****************************/
|
||||
if( --(sp->_cnt) >= 0 ) /* if there's room in buf */
|
||||
return(((WORD)(*sp->_ptr++ = ch)) & 0377);/* put it! */
|
||||
else return(_flsbuf(ch,sp)); /* o.w. flush & put */
|
||||
/****************************/
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/************************************************************************
|
||||
*
|
||||
* f p u t n F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1983 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* 'fputn()' writes 'n' chars to a buffered file. It optimizes
|
||||
* for 'non-buffered' (_IONBUF) output.
|
||||
*
|
||||
* Calling sequence:
|
||||
* rv = fputn(cp,n,stream)
|
||||
* Where:
|
||||
* cp -> chars to be put
|
||||
* n = num chars to be put
|
||||
* stream -> where its going (FILE *)
|
||||
* rv = SUCCESS if write ok, FAILURE (-1 WORD) o.w.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fputn(buf,num,sp) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *buf; /* chars to be written */
|
||||
REG WORD num; /* num chars to be written */
|
||||
REG FILE *sp; /* stream to write to */
|
||||
{ /****************************/
|
||||
if( sp->_flag & _IONBUF ) /* Non-buffered file? */
|
||||
{ /* */
|
||||
sp->_cnt = 0; /* Always force to zero */
|
||||
if(num!=write(sp->_fd,buf,num)) /* try to write */
|
||||
{ /* no good */
|
||||
sp->_flag |= _IOERR; /* mark this file */
|
||||
return FAILURE; /* and complain */
|
||||
} /* */
|
||||
return SUCCESS; /* */
|
||||
} /****************************/
|
||||
/* */
|
||||
while(num--) /* Buffered output */
|
||||
if( FAILURE==fputc(*buf++,sp)) /* try to put in buf */
|
||||
return FAILURE; /* no good */
|
||||
return SUCCESS; /* everything a-ok */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,31 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f p u t s F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fputs" copies a null terminated string to a stream file.
|
||||
* To be compatible with Unix, it does NOT append a newline.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = fputs(s,stream)
|
||||
* Where:
|
||||
* ret = last char out, on error FAILURE
|
||||
* s = string to put
|
||||
* stream -> stream (FILE *)
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fputs(str,sp) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *str; /* null term string */
|
||||
REG FILE *sp; /* stream file pointer */
|
||||
{ /****************************/
|
||||
REG WORD rv; /* return val */
|
||||
rv = NULL; /* init for *s==NULL */
|
||||
while(*str) /* for all chars in s */
|
||||
if((rv=putc(*str++,sp))==FAILURE) /* if putc fouls up */
|
||||
return(FAILURE); /* give up */
|
||||
return(rv); /* it worked */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,41 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f r e a d F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fread" reads NI items of size SZ from stream SP and deposits them
|
||||
* at BUFF.
|
||||
*
|
||||
* Calling sequence:
|
||||
* nitems = fread(buff,size,nitems,stream)
|
||||
* Where:
|
||||
* buff -> where to read to
|
||||
* size = number bytes in each item
|
||||
* nitems = number bytes read/to read
|
||||
* stream -> file
|
||||
*
|
||||
* nitems is set to 0 if an error occurs (including EOF).
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fread(buff,siz,num,sp) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *buff;
|
||||
WORD siz,
|
||||
num;
|
||||
REG FILE *sp;
|
||||
{
|
||||
REG WORD jj, kk, ch;
|
||||
|
||||
|
||||
for( jj=0; jj<num; jj++ )
|
||||
for( kk=0; kk<siz; kk++ )
|
||||
{
|
||||
if( (ch = getc(sp)) == FAILURE )
|
||||
return(NULL);
|
||||
else *buff++ = ch;
|
||||
}
|
||||
return(num);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* f r e o p e n F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "freopen" opens a buffered stream file, either on disk, console, or
|
||||
* line printer. It first closes the given stream, and reuses that slot.
|
||||
* Comes in 3 flavors, like "fopen".
|
||||
*
|
||||
* Calling sequence:
|
||||
* stream = freopen(name,mode,stream)
|
||||
* stream = freopa(name,mode,stream)
|
||||
* stream = freopb(name,mode,stream)
|
||||
* stream = _freopen(name,mode,stream,ascii)
|
||||
* Where:
|
||||
* stream -> file reopened (FILE *), NULLPTR if failure
|
||||
* name -> NULL terminated string containing filename,
|
||||
* name="CON:" means the console,
|
||||
* name="LST:" goes to the line printer, and
|
||||
* otherwise a disk file is assumed.
|
||||
* mode -> "r" for read only,
|
||||
* "w" for write only,
|
||||
* "a" to append (write only) to end of file.
|
||||
* ascii = 0 if the file is handled as a CP/M text file
|
||||
* (newline -> CRLF xlation, ^Z EOF convention).
|
||||
* Otherwise, file is treated as a binary file.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h" /****************************/
|
||||
#define READ 0 /* read mode val */
|
||||
#define WRITE 1 /* write mode val */
|
||||
|
||||
FILE *_freope(name,mode,sp,ascii) /****************************/
|
||||
REG BYTE *name, /* file name */
|
||||
*mode; /* "r","w", or "a" */
|
||||
REG FILE *sp; /* stream pointer */
|
||||
BOOLEAN ascii; /* CP/M text file */
|
||||
{ /****************************/
|
||||
REG WORD fd; /* file descriptor */
|
||||
/****************************/
|
||||
if( fclose(sp) == FAILURE ) /* try closing the file 1st */
|
||||
return(NULLFILE); /* oops, it failed */
|
||||
if( *mode == 'w' || *mode == 'W' ) /* 'w'rite mode? */
|
||||
fd=_creat(name,0,ascii); /* create file *********/
|
||||
|
||||
else if( *mode == 'a' || *mode == 'A' ) /* 'a'ppend mode? */
|
||||
{ /* */
|
||||
if( (fd=_open(name,WRITE,ascii)) < 0 ) /* try open */
|
||||
fd=_creat(name,0,ascii);/* do create if needed */
|
||||
else lseek(fd,0L,2); /* its out there, seef EOF */
|
||||
} /* ************************/
|
||||
else if( *mode == 'r' || *mode == 'R' ) /* 'r'ead mode? */
|
||||
fd=_open(name,READ,ascii); /* try open ************/
|
||||
else return(NULLFILE); /* bad mode barf... */
|
||||
/****************************/
|
||||
if(fd<0) /* did one of those work? */
|
||||
return(NULLFILE); /* no, oh well */
|
||||
sp->_cnt = 0; /* init count */
|
||||
sp->_fd = fd; /* and file des */
|
||||
sp->_base = sp->_ptr = NULLPTR; /* and buffer pointers */
|
||||
if( *mode == 'r' || *mode == 'R' ) /* 'r'ead mode? */
|
||||
sp->_flag = _IOREAD; /* say so */
|
||||
else sp->_flag = _IOWRT; /* else 'w'rite mode */
|
||||
if( ascii == 0 ) /* ascii file? */
|
||||
sp->_flag |= _IOASCI; /* */
|
||||
/****************************/
|
||||
return(sp); /* return the stream ptr */
|
||||
} /****************************/
|
||||
|
||||
FILE * freopen(name,mode,sp) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name, *mode; FILE *sp;
|
||||
{ return(_freope(name,mode,sp,0)); } /* reopen ascii file */
|
||||
|
||||
FILE * freopa(name,mode,sp) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name, *mode; FILE *sp;
|
||||
{ return(_freope(name,mode,sp,0)); } /* reopen ascii file */
|
||||
|
||||
FILE * freopb(name,mode,sp) /* CLEAR FUNCTION ***********/
|
||||
BYTE *name, *mode; FILE *sp;
|
||||
{ return(_freope(name,mode,sp,1)); } /* reopen binary file */
|
||||
@@ -0,0 +1,27 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f s c a n f F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fscanf" scans the given stream for items specified, and assigns
|
||||
* them to user supplied variables (via pointers to these vars).
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = fscanf(sp,fmt,p1,p2,...)
|
||||
* Where:
|
||||
* ret = the number of items successfully matched & assigned
|
||||
* EOF returned if encountered on input
|
||||
* sp -> (FILE *) stream pointer
|
||||
* fmt -> a string specifying how to parse the input
|
||||
* p1,p2,... -> where matched items get stored
|
||||
*
|
||||
*****************************************************************************/
|
||||
#include <stdio.h>
|
||||
WORD fscanf(sp,fmt,ptrs)
|
||||
FILE *sp;
|
||||
BYTE *fmt;
|
||||
BYTE *ptrs;
|
||||
{
|
||||
return(_doscan(sp,fmt,&ptrs));
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f s e e k F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fseek" sets the read/write pointer of a stream to an arbitrary
|
||||
* offset.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = fseek(sp,offset,sense)
|
||||
* Where:
|
||||
* sp -> (FILE *) stream to seek on
|
||||
* offset = signed number of bytes
|
||||
* sense = 0 => offset from beginning of file
|
||||
* 1 => offset from current position
|
||||
* 2 => from end of file
|
||||
* ret = 0 for success, -1 for failure
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fseek(sp,offs,sense) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp;
|
||||
LONG offs;
|
||||
WORD sense;
|
||||
{
|
||||
LONG p, lseek();
|
||||
|
||||
if ( fflush(sp) == FAILURE )
|
||||
return( FAILURE );
|
||||
p = lseek(fileno(sp),offs,sense);
|
||||
sp->_flag &= ~_IOEOF; /* any seek clears EOF flag */
|
||||
return( p==(LONG) FAILURE ? FAILURE : SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* r e w i n d F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "rewind" sets the read/write pointer of a stream file to the
|
||||
* beginning of the stream.
|
||||
*
|
||||
* Calling sequence:
|
||||
* ret = rewind(sp)
|
||||
* Where:
|
||||
* sp -> a stream file (FILE *)
|
||||
* ret = 0 for success, -1 for failure
|
||||
*
|
||||
*************************************************************************/
|
||||
WORD rewind(sp) /* CLEAR FUNCTION ***********/
|
||||
FILE *sp;
|
||||
{
|
||||
return(fseek(sp,0L,0));
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* f t e l l F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "ftell" returns the present value of the read/write pointer
|
||||
* within the stream. This is a meaningless number for console
|
||||
* and list devices.
|
||||
*
|
||||
* Calling sequence:
|
||||
* offset = ftell(sp)
|
||||
* Where:
|
||||
* sp -> (FILE *) stream
|
||||
* offset = (LONG) where stream is reading from/writing to
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
LONG ftell(sp) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp; /* stream pointer */
|
||||
{ /* */
|
||||
REG LONG filepos; /* file position */
|
||||
REG BYTE *bp; /* Buffer ptr */
|
||||
LONG nread; /* Temp var */
|
||||
LONG lseek(); /* byte offset into buf */
|
||||
/* */
|
||||
if( isatty(fileno(sp)) ) /* are we talking to a tty? */
|
||||
return(0L); /* quit now if so */
|
||||
filepos = FAILURE; /* default return value */
|
||||
if( sp->_flag & (_IOREAD|_IOWRT) ) /* if file is open */
|
||||
{ /* */
|
||||
if((filepos=lseek(fileno(sp),0L,1)) /* get where next byte read */
|
||||
== FAILURE ) /* from or written to */
|
||||
return((LONG)FAILURE); /* quit if bad lseek */
|
||||
if( sp->_base == NULLPTR ) /* if file hasn't had i/o */
|
||||
return(filepos); /* return this position */
|
||||
nread = sp->_ptr - sp->_base; /* calc for # read/written */
|
||||
filepos += nread; /* correct for # read/wrtn */
|
||||
if( sp->_flag & _IOREAD ) /* if reading from file */
|
||||
if( filepos > 0 ) /* and we've read from file*/
|
||||
filepos -= nread + sp->_cnt; /* adjust file position */
|
||||
/* to reflect read ahead */
|
||||
if( sp->_flag & _IOASCI ) /* ascii file? **************/
|
||||
{ /* count the newlines */
|
||||
if( sp->_flag & _IOWRT ) /* add in newline's cr's */
|
||||
{ /* */
|
||||
for( bp=sp->_base; bp < sp->_ptr; bp++ ) /* */
|
||||
if( *bp == '\n' ) /* count newlines in stuff */
|
||||
filepos++; /* written/read so far */
|
||||
} else { /* we're reading... */
|
||||
if( filepos > 0 ) /* check to see we've read */
|
||||
for(bp= &(sp->_ptr[sp->_cnt-1]);/* start at end of buffer */
|
||||
bp >= sp->_ptr; bp-- ) /* back up to next read char*/
|
||||
if( *bp == '\n' ) /* count off for newlines */
|
||||
filepos--; /* */
|
||||
} /* */
|
||||
} /* fini ascii ***************/
|
||||
} /****************************/
|
||||
return(filepos); /* */
|
||||
} /****************************/
|
||||
|
||||
103
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/ftoavms.c
Normal file
103
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/ftoavms.c
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <portab.h>
|
||||
|
||||
ftoa(fp,buf,prec)
|
||||
FLOAT *fp;
|
||||
BYTE *buf;
|
||||
WORD prec;
|
||||
{
|
||||
_ftoa(*fp,buf,prec,'f');
|
||||
return(strlen(buf));
|
||||
}
|
||||
|
||||
|
||||
etoa(fp,buf,prec)
|
||||
FLOAT *fp;
|
||||
BYTE *buf;
|
||||
WORD prec;
|
||||
{
|
||||
_ftoa(*fp,buf,prec,'e');
|
||||
return(strlen(buf));
|
||||
}
|
||||
|
||||
_ftoa (x, str, prec, format)
|
||||
float x;
|
||||
char *str;
|
||||
{
|
||||
/* converts a floating point number to an ascii string */
|
||||
/* x is stored into str, which should be at least 30 chars long */
|
||||
int ie, i, k, ndig, fstyle;
|
||||
double y;
|
||||
ndig = ( prec<=0) ? 7 : (prec > 22 ? 23 : prec+1);
|
||||
if (format == 'f' || format == 'F')
|
||||
fstyle = 1;
|
||||
else
|
||||
fstyle = 0;
|
||||
/* print in e format unless last arg is 'f' */
|
||||
ie = 0;
|
||||
/* if x negative, write minus and reverse */
|
||||
if ( x < 0)
|
||||
{
|
||||
*str++ = '-';
|
||||
x = -x;
|
||||
}
|
||||
|
||||
/* put x in range 1 <= x < 10 */
|
||||
if (x > 0.0) while (x < 1.0)
|
||||
{
|
||||
x =* 10.0;
|
||||
ie--;
|
||||
}
|
||||
while (x >= 10.0)
|
||||
{
|
||||
x = x/10.0;
|
||||
ie++;
|
||||
}
|
||||
|
||||
/* in f format, number of digits is related to size */
|
||||
if (fstyle) ndig =+ ie;
|
||||
|
||||
/* round. x is between 1 and 10 and ndig will be printed to
|
||||
right of decimal point so rounding is ... */
|
||||
for (y = i = 1; i < ndig; i++)
|
||||
y = y/10.;
|
||||
x =+ y/2.;
|
||||
if (x >= 10.0) {x = 1.0; ie++;} /* repair rounding disasters */
|
||||
/* now loop. put out a digit (obtain by multiplying by
|
||||
10, truncating, subtracting) until enough digits out */
|
||||
/* if fstyle, and leading zeros, they go out special */
|
||||
if (fstyle && ie<0)
|
||||
{
|
||||
*str++ = '0'; *str++ = '.';
|
||||
if (ndig < 0) ie = ie-ndig; /* limit zeros if underflow */
|
||||
for (i = -1; i > ie; i--)
|
||||
*str++ = '0';
|
||||
}
|
||||
for (i=0; i < ndig; i++)
|
||||
{
|
||||
k = x;
|
||||
*str++ = k + '0';
|
||||
if (i == (fstyle ? ie : 0)) /* where is decimal point */
|
||||
*str++ = '.';
|
||||
x =- (y=k);
|
||||
x =* 10.0;
|
||||
}
|
||||
|
||||
/* now, in estyle, put out exponent if not zero */
|
||||
if (!fstyle && ie != 0)
|
||||
{
|
||||
*str++ = 'E';
|
||||
if (ie < 0)
|
||||
{
|
||||
ie = -ie;
|
||||
*str++ = '-';
|
||||
}
|
||||
for (k=100; k > ie; k =/10);
|
||||
for (; k > 0; k =/10)
|
||||
{
|
||||
*str++ = ie/k + '0';
|
||||
ie = ie%k;
|
||||
}
|
||||
}
|
||||
*str = '\0';
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* f w r i t e F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "fwrite" writes NI items of size SZ from memory at BUFF into stream
|
||||
* SP.
|
||||
*
|
||||
* Calling sequence:
|
||||
* nitems = fwrite(buff,size,nitems,stream)
|
||||
* Where:
|
||||
* buff -> where to write from
|
||||
* size = number bytes in each item
|
||||
* nitems = number bytes written/to write
|
||||
* stream -> file
|
||||
*
|
||||
* nitems is set to 0 if an error occurs (including EOF).
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD fwrite(buff,siz,num,sp) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *buff;
|
||||
WORD siz,
|
||||
num;
|
||||
REG FILE *sp;
|
||||
{
|
||||
REG WORD jj, kk;
|
||||
|
||||
for( jj=0; jj<num; jj++ )
|
||||
for( kk=0; kk<siz; kk++ )
|
||||
if( fputc(*buff++,sp) == FAILURE ) /* used for side effects */
|
||||
return(NULL);
|
||||
return(num);
|
||||
}
|
||||
34
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/getl.c
Normal file
34
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/getl.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* g e t l F u n c t i o n
|
||||
* -------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "getl" gets an LONG (4 byte) value from the input stream.
|
||||
* Note that what's written (binary) by a PDP 11 (UNIX: lo byte, hi byte)
|
||||
* system will NOT be compatible with what's written by a
|
||||
* 68K (NUXI: hi byte, lo byte) system.
|
||||
*
|
||||
* Calling sequence:
|
||||
* l = getl(stream)
|
||||
* Where:
|
||||
* l = a 32-bit long value
|
||||
* stream-> a (FILE *) input stream
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
LONG getl(sp) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp; /* the stream to get from */
|
||||
{ /* */
|
||||
LONG l; /* place to get to */
|
||||
REG BYTE *p; /* make ptr to l */
|
||||
/****************************/
|
||||
p = (char *)&l; /* point to l */
|
||||
*p++ = getc(sp); /* no way to distinguish */
|
||||
*p++ = getc(sp); /* twixt EOF & -1 */
|
||||
*p++ = getc(sp); /* */
|
||||
*p++ = getc(sp); /* */
|
||||
return(l); /* there it is */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,91 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* g e t p a s s F u n c t i o n
|
||||
* -------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "getpass" writes a prompt to the console (NOT stdout) and accepts
|
||||
* a string of 1-8 chars from the console (NOT stdin) without
|
||||
* echoing the input to the terminal. Only limited CP/M line edit
|
||||
* commands are available (CTL H, DEL, CTL X) on input.
|
||||
*
|
||||
* Calling sequence:
|
||||
* pret = getpass(prompt)
|
||||
* Where:
|
||||
* pret -> ptr to 1-8 chars of null terminated password
|
||||
* prompt -> null teminated console out msg.
|
||||
*
|
||||
* Modified:
|
||||
* Oct 83 whf - handle OS Independent Raw Input
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
|
||||
BYTE * getpass(prompt) /* CLEAR FUNCTION ***********/
|
||||
BYTE *prompt;
|
||||
{
|
||||
MLOCAL BYTE ibuf[9];
|
||||
|
||||
_conout(prompt,strlen(prompt),CONOUT); /* same fn write uses */
|
||||
_noecho(ibuf,9);
|
||||
return(ibuf);
|
||||
}
|
||||
|
||||
#define CMASK 0x7F
|
||||
#define DEL 0x7F
|
||||
#define CTRLX 0x18
|
||||
#define CTRLC 0x03
|
||||
MLOCAL _noecho(bf,ln)
|
||||
REG BYTE *bf;
|
||||
WORD ln;
|
||||
{
|
||||
REG WORD cur;
|
||||
WORD ch;
|
||||
|
||||
cur = 0;
|
||||
FOREVER {
|
||||
switch( ch = CMASK & _ttyinraw()) {
|
||||
case '\b':
|
||||
case DEL:
|
||||
if( cur>0 ) {
|
||||
cur--;
|
||||
bf--;
|
||||
}
|
||||
break;
|
||||
case CTRLX:
|
||||
bf -= cur;
|
||||
cur = 0;
|
||||
break;
|
||||
case '\r':
|
||||
case '\n':
|
||||
*bf = NULL;
|
||||
return;
|
||||
case CTRLC:
|
||||
exit(1);
|
||||
default:
|
||||
*bf++ = ch;
|
||||
cur++;
|
||||
if( cur+1 >= ln ) {
|
||||
*bf = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
|
||||
MLOCAL _conout(buffer,count,os_func) /***************************/
|
||||
REG BYTE *buffer; /* -> 1st char output */
|
||||
REG WORD count; /* = # bytes to xfer */
|
||||
REG WORD os_func; /* OS function to use */
|
||||
{ /***************************/
|
||||
WORD xcount; /* save area for count */
|
||||
/* */
|
||||
while(count-- > 0) /* Until all written */
|
||||
__OSIF(os_func,*buffer++); /* Output next character */
|
||||
} /***************************/
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
/* getpid - return process ID */
|
||||
/* returns phony number under CP/M */
|
||||
#include "portab.h"
|
||||
#define PHONYPID 222
|
||||
WORD getpid() /* CLEAR FUNCTION ***********/
|
||||
{
|
||||
return(PHONYPID);
|
||||
}
|
||||
34
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/gets.c
Normal file
34
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/gets.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* g e t s F u n c t i o n
|
||||
* -------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "gets" reads a string from the standard input, and returns
|
||||
* its argument (NULL on end of file). The newline at the
|
||||
* end of the string is replaced by a NULL.
|
||||
*
|
||||
* Calling sequence:
|
||||
* addr = gets(saddr)
|
||||
* Where:
|
||||
* saddr -> where the string is to go (no bounds check)
|
||||
* addr = saddr if all ok, NULLPTR o.w.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
BYTE * gets(str) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *str; /* string save area */
|
||||
{ /****************************/
|
||||
REG WORD c; /* char to test for eof */
|
||||
BYTE *sav; /* sav pointer for return */
|
||||
sav = str; /* remember this */
|
||||
while( (c=getc(stdin)) != FAILURE && /* while everything ok */
|
||||
c != '\n' ) /* and not end of line */
|
||||
*str++ = c; /* store it */
|
||||
*str = NULL; /* clean up string */
|
||||
if( c == FAILURE ) /* if not cool */
|
||||
return(NULLPTR); /* then tell them so */
|
||||
return(sav); /* tell them is cool */
|
||||
} /****************************/
|
||||
32
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/getw.c
Normal file
32
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/getw.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* g e t w F u n c t i o n
|
||||
* -------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "getw" gets an WORD (2 byte) value from the input stream.
|
||||
* Note that what's written (binary) by a PDP 11 (UNIX: lo byte, hi byte)
|
||||
* system will NOT be compatible with what's written by a
|
||||
* 68K (NUXI: hi byte, lo byte) system.
|
||||
*
|
||||
* Calling sequence:
|
||||
* w = getw(stream)
|
||||
* Where:
|
||||
* w = a 16-bit word value
|
||||
* stream-> a (FILE *) input stream
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
WORD getw(sp) /* CLEAR FUNCTION ***********/
|
||||
REG FILE *sp; /* the stream to get from */
|
||||
{ /* */
|
||||
WORD w; /* place to get to */
|
||||
REG BYTE *p; /* make ptr to w */
|
||||
/****************************/
|
||||
p = (char *)&w; /* point to w */
|
||||
*p++ = getc(sp); /* no way to distinguish */
|
||||
*p++ = getc(sp); /* twixt EOF & -1 */
|
||||
return(w); /* there it is */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,21 @@
|
||||
/*********************************************************************
|
||||
* INDEX - returns a pointer to first occurrence of char in string.
|
||||
*
|
||||
* BYTE *index(s,c)
|
||||
* BYTE *s, c;
|
||||
*
|
||||
* Returns pointer to first c in s, or zero if c not in s.
|
||||
**********************************************************************/
|
||||
|
||||
#include <portab.h>
|
||||
|
||||
BYTE * index(str,ch) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *str, ch;
|
||||
{
|
||||
for( ; ch != *str ; str++ ) /* look for c in s. */
|
||||
if( *str == NULL ) /* if we get to eos, we've gone */
|
||||
return(0); /* too far. */
|
||||
return(str); /* found c. note that 'index' */
|
||||
/* works to find NULL, (ie. */
|
||||
/* eos), if c==NULL. */
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Channel Info Functions
|
||||
* ----------------------
|
||||
* Copyright 1982,83 by Digital Reserach Inc. All rights reserved.
|
||||
*
|
||||
* "isatty(fd)" == TRUE iff the file on channel fd is a 'CON:' device.
|
||||
* "isdev(fd)" == TRUE iff fd is 'CON:', 'LST:', 'AUX:'
|
||||
*
|
||||
* Where:
|
||||
* fd = file descriptor returned by 'open'
|
||||
*
|
||||
**************************************************************************/
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
|
||||
BOOLEAN isatty(fd) /* CLEAR FUNCTION ***********/
|
||||
WORD fd; /* file des returned by open*/
|
||||
{ /****************************/
|
||||
REG FD *fp; /* ptr to ccb */
|
||||
FD *_chkc(); /* validates fd, cvt to fp */
|
||||
/* */
|
||||
if((fp=_chkc(fd)) == NULLFD) /* make sure its open MGL */
|
||||
return(FALSE); /* isno TTY ifnot open */
|
||||
return( (fp->flags & ISTTY) != 0 ); /* test this flag */
|
||||
} /****************************/
|
||||
|
||||
BOOLEAN isdev(fd) /* CLEAR FUNCTION ***********/
|
||||
WORD fd; /* file des returned by open*/
|
||||
{ /****************************/
|
||||
REG FD *fp; /* ptr to ccb */
|
||||
FD *_chkc(); /* validates fd, cvt to fp */
|
||||
/* */
|
||||
if((fp=_chkc(fd)) == NULLFD) /* make sure its open MGL */
|
||||
return(FALSE); /* isno TTY ifnot open */
|
||||
return(fp->flags&(ISTTY|ISLPT|ISAUX)); /* test these flags */
|
||||
} /****************************/
|
||||
|
||||
|
||||
/* ttyname - find name of a terminal */
|
||||
/* returns "CON:" if isatty, NULLPTR o.w., under CP/M */
|
||||
|
||||
EXTERN BYTE __tname[]; /* CON: String */
|
||||
BYTE * ttyname(fd) /* CLEAR FUNCTION ***********/
|
||||
WORD fd;
|
||||
{
|
||||
if( isatty(fd) )
|
||||
return(__tname);
|
||||
return(NULLPTR);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Kludge VMS isatty routine.
|
||||
*/
|
||||
isatty()
|
||||
{
|
||||
return(0); /* Always returns FALSE */
|
||||
}
|
||||
56
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/ldiv.c
Normal file
56
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/ldiv.c
Normal file
@@ -0,0 +1,56 @@
|
||||
long ldivr = 0;
|
||||
|
||||
long ldiv(al1,al2)
|
||||
long al1,al2;
|
||||
{
|
||||
|
||||
register long l1,l2,q,b;
|
||||
register int sign;
|
||||
|
||||
sign = 0;
|
||||
l1 = al1;
|
||||
l2 = al2;
|
||||
if(l2==0) {
|
||||
ldivr = 0x80000000;
|
||||
return(0x80000000);
|
||||
}
|
||||
if(l2 > l1) {
|
||||
ldivr = l1;
|
||||
return(0);
|
||||
}
|
||||
if(l1<0) {
|
||||
l1 = -l1;
|
||||
sign++;
|
||||
}
|
||||
if(l2<0) {
|
||||
l2 = -l2;
|
||||
sign++;
|
||||
}
|
||||
if(l1==l2) {
|
||||
q = 1;
|
||||
l1 = 0;
|
||||
goto doret;
|
||||
}
|
||||
b = 1; /* bit value */
|
||||
while(l1>=l2) {
|
||||
l2 =<< 1;
|
||||
b =<< 1;
|
||||
}
|
||||
q = 0;
|
||||
while(b) { /* now do shifts and subtracts */
|
||||
if(l1>=l2) {
|
||||
q =| b;
|
||||
l1 =- l2;
|
||||
}
|
||||
b =>> 1;
|
||||
l2 =>> 1;
|
||||
}
|
||||
doret:
|
||||
if(sign==1) {
|
||||
ldivr = -l1;
|
||||
return(-q);
|
||||
}
|
||||
ldivr = l1;
|
||||
return(q);
|
||||
}
|
||||
|
||||
84
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/ldiv.s
Normal file
84
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/ldiv.s
Normal file
@@ -0,0 +1,84 @@
|
||||
.globl _ldivr
|
||||
.comm _ldivr,4
|
||||
.globl _ldiv
|
||||
.globl ldiv
|
||||
.text
|
||||
_ldiv:
|
||||
ldiv:
|
||||
~~ldiv:
|
||||
~b=R4
|
||||
~q=R5
|
||||
~l1=R7
|
||||
~l2=R6
|
||||
~al1=8
|
||||
~al2=12
|
||||
~sign=R3
|
||||
link R14,#-2
|
||||
movem.l R2-R7,-(sp)
|
||||
clr R3
|
||||
clr.l R5
|
||||
move.l 8(R14),R7
|
||||
move.l 12(R14),R6
|
||||
bne L2
|
||||
move.l #$80000000,_ldivr
|
||||
move.l #$80000000,R0
|
||||
bra L1
|
||||
L2:
|
||||
bge L3
|
||||
neg.l R6
|
||||
add #1,R3
|
||||
L3:
|
||||
tst.l R7
|
||||
bge L4
|
||||
neg.l R7
|
||||
add #1,R3
|
||||
L4:
|
||||
cmp.l R7,R6
|
||||
bgt L6
|
||||
bne L7
|
||||
move.l #1,R5
|
||||
clr.l R7
|
||||
bra L6
|
||||
L7:
|
||||
cmp.l #$10000,R7
|
||||
bge L9
|
||||
divu R6,R7
|
||||
move R7,R5
|
||||
swap R7
|
||||
ext.l R7
|
||||
bra L6
|
||||
L9:
|
||||
move.l #1,R4
|
||||
L12:
|
||||
cmp.l R6,R7
|
||||
blo L11
|
||||
asl.l #1,R6
|
||||
asl.l #1,R4
|
||||
bra L12
|
||||
L11:
|
||||
tst.l R4
|
||||
beq L6
|
||||
cmp.l R6,R7
|
||||
blo L15
|
||||
or.l R4,R5
|
||||
sub.l R6,R7
|
||||
L15:
|
||||
lsr.l #1,R4
|
||||
lsr.l #1,R6
|
||||
bra L11
|
||||
L6:
|
||||
cmp #1,R3
|
||||
bne L16
|
||||
neg.l R7
|
||||
move.l R7,_ldivr
|
||||
move.l R5,R0
|
||||
neg.l R0
|
||||
bra L1
|
||||
L16:
|
||||
move.l R7,_ldivr
|
||||
move.l R5,R0
|
||||
L1:
|
||||
tst.l (sp)+
|
||||
movem.l (sp)+,R3-R7
|
||||
unlk R14
|
||||
rts
|
||||
344
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/list.com
Normal file
344
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/list.com
Normal file
@@ -0,0 +1,344 @@
|
||||
$ clib
|
||||
$ set noon
|
||||
$ num
|
||||
ACCESS.C
|
||||
ACCESS.lis
|
||||
$ num
|
||||
ALLOCC.C
|
||||
ALLOCC.lis
|
||||
$ num
|
||||
ATOI.C
|
||||
ATOI.lis
|
||||
$ num
|
||||
ATOL.C
|
||||
ATOL.lis
|
||||
$ num
|
||||
BLKIO.C
|
||||
BLKIO.lis
|
||||
$ num
|
||||
CALLOC.C
|
||||
CALLOC.lis
|
||||
$ num
|
||||
CHINIT.C
|
||||
CHINIT.lis
|
||||
$ num
|
||||
CHKC.C
|
||||
CHKC.lis
|
||||
$ num
|
||||
CHMOD.C
|
||||
CHMOD.lis
|
||||
$ num
|
||||
CHOWN.C
|
||||
CHOWN.lis
|
||||
$ num
|
||||
CLEANUP.C
|
||||
CLEANUP.lis
|
||||
$ num
|
||||
CLOSE.C
|
||||
CLOSE.lis
|
||||
$ num
|
||||
CREAT.C
|
||||
CREAT.lis
|
||||
$ num
|
||||
CTYPE.C
|
||||
CTYPE.lis
|
||||
$ num
|
||||
ERRNO.C
|
||||
ERRNO.lis
|
||||
$ num
|
||||
EXEC.C
|
||||
EXEC.lis
|
||||
$ num
|
||||
EXIT.C
|
||||
EXIT.lis
|
||||
$ num
|
||||
FCLOSE.C
|
||||
FCLOSE.lis
|
||||
$ num
|
||||
FDOPEN.C
|
||||
FDOPEN.lis
|
||||
$ num
|
||||
FFLUSH.C
|
||||
FFLUSH.lis
|
||||
$ num
|
||||
FGETC.C
|
||||
FGETC.lis
|
||||
$ num
|
||||
FGETS.C
|
||||
FGETS.lis
|
||||
$ num
|
||||
FOPEN.C
|
||||
FOPEN.lis
|
||||
$ num
|
||||
FPRINTF.C
|
||||
FPRINTF.lis
|
||||
$ num
|
||||
FPUTC.C
|
||||
FPUTC.lis
|
||||
$ num
|
||||
FPUTS.C
|
||||
FPUTS.lis
|
||||
$ num
|
||||
FREAD.C
|
||||
FREAD.lis
|
||||
$ num
|
||||
FREOPEN.C
|
||||
FREOPEN.lis
|
||||
$ num
|
||||
FSCANF.C
|
||||
FSCANF.lis
|
||||
$ num
|
||||
FSEEK.C
|
||||
FSEEK.lis
|
||||
$ num
|
||||
FTELL.C
|
||||
FTELL.lis
|
||||
$ num
|
||||
FWRITE.C
|
||||
FWRITE.lis
|
||||
$ num
|
||||
GETL.C
|
||||
GETL.lis
|
||||
$ num
|
||||
GETPASS.C
|
||||
GETPASS.lis
|
||||
$ num
|
||||
GETPID.C
|
||||
GETPID.lis
|
||||
$ num
|
||||
GETS.C
|
||||
GETS.lis
|
||||
$ num
|
||||
GETW.C
|
||||
GETW.lis
|
||||
$ num
|
||||
INDEX.C
|
||||
INDEX.lis
|
||||
$ num
|
||||
ISATTY.C
|
||||
ISATTY.lis
|
||||
$ num
|
||||
LDIV.C
|
||||
LDIV.lis
|
||||
$ num
|
||||
LSEEK.C
|
||||
LSEEK.lis
|
||||
$ num
|
||||
MALLOC.C
|
||||
MALLOC.lis
|
||||
$ num
|
||||
MKTEMP.C
|
||||
MKTEMP.lis
|
||||
$ num
|
||||
OPEN.C
|
||||
OPEN.lis
|
||||
$ num
|
||||
PERROR.C
|
||||
PERROR.lis
|
||||
$ num
|
||||
PRINTF.C
|
||||
PRINTF.lis
|
||||
$ num
|
||||
PUTL.C
|
||||
PUTL.lis
|
||||
$ num
|
||||
PUTS.C
|
||||
PUTS.lis
|
||||
$ num
|
||||
PUTW.C
|
||||
PUTW.lis
|
||||
$ num
|
||||
QSORT.C
|
||||
QSORT.lis
|
||||
$ num
|
||||
RAND.C
|
||||
RAND.lis
|
||||
$ num
|
||||
READ.C
|
||||
READ.lis
|
||||
$ num
|
||||
REWIND.C
|
||||
REWIND.lis
|
||||
$ num
|
||||
RINDEX.C
|
||||
RINDEX.lis
|
||||
$ num
|
||||
SBRK.C
|
||||
SBRK.lis
|
||||
$ num
|
||||
SCANF.C
|
||||
SCANF.lis
|
||||
$ num
|
||||
SETBUF.C
|
||||
SETBUF.lis
|
||||
$ num
|
||||
SIGNAL.C
|
||||
SIGNAL.lis
|
||||
$ num
|
||||
SPRINTF.C
|
||||
SPRINTF.lis
|
||||
$ num
|
||||
SSCANF.C
|
||||
SSCANF.lis
|
||||
$ num
|
||||
STRCAT.C
|
||||
STRCAT.lis
|
||||
$ num
|
||||
STRCMP.C
|
||||
STRCMP.lis
|
||||
$ num
|
||||
STRCPY.C
|
||||
STRCPY.lis
|
||||
$ num
|
||||
STRINS.C
|
||||
STRINS.lis
|
||||
$ num
|
||||
STRLEN.C
|
||||
STRLEN.lis
|
||||
$ num
|
||||
STRNCAT.C
|
||||
STRNCAT.lis
|
||||
$ num
|
||||
STRNCMP.C
|
||||
STRNCMP.lis
|
||||
$ num
|
||||
STRNCPY.C
|
||||
STRNCPY.lis
|
||||
$ num
|
||||
SWAB.C
|
||||
SWAB.lis
|
||||
$ num
|
||||
TTYNAME.C
|
||||
TTYNAME.lis
|
||||
$ num
|
||||
UNGETC.C
|
||||
UNGETC.lis
|
||||
$ num
|
||||
UNLINK.C
|
||||
UNLINK.lis
|
||||
$ num
|
||||
WRITE.C
|
||||
WRITE.lis
|
||||
$ num
|
||||
XDOPRT.C
|
||||
XDOPRT.lis
|
||||
$ num
|
||||
XDOPRTFP.C
|
||||
XDOPRTFP.lis
|
||||
$ num
|
||||
XDOSCAN.C
|
||||
XDOSCAN.lis
|
||||
$ num
|
||||
XFDECLS.C
|
||||
XFDECLS.lis
|
||||
$ num
|
||||
XFILBUF.C
|
||||
XFILBUF.lis
|
||||
$ num
|
||||
XFILESZ.C
|
||||
XFILESZ.lis
|
||||
$ num
|
||||
XFLSBUF.C
|
||||
XFLSBUF.lis
|
||||
$ num
|
||||
XFPRINTF.C
|
||||
XFPRINTF.lis
|
||||
$ num
|
||||
XMAIN.C
|
||||
XMAIN.lis
|
||||
$ num
|
||||
XOPEN.C
|
||||
XOPEN.lis
|
||||
$ num
|
||||
XPRTINT.C
|
||||
XPRTINT.lis
|
||||
$ num
|
||||
XPRTLD.C
|
||||
XPRTLD.lis
|
||||
$ num
|
||||
XPRTSHRT.C
|
||||
XPRTSHRT.lis
|
||||
$ num
|
||||
XSTRCMP.C
|
||||
XSTRCMP.lis
|
||||
$ num
|
||||
XTTYIN.C
|
||||
XTTYIN.lis
|
||||
$ num
|
||||
XWMAIN.C
|
||||
XWMAIN.lis
|
||||
$ num
|
||||
BASEPAGE.H
|
||||
BASEPAGE.lst
|
||||
$ num
|
||||
BDOS.H
|
||||
BDOS.lst
|
||||
$ num
|
||||
CPM.H
|
||||
CPM.lst
|
||||
$ num
|
||||
CTYPE.H
|
||||
CTYPE.lst
|
||||
$ num
|
||||
ERRNO.H
|
||||
ERRNO.lst
|
||||
$ num
|
||||
PORTAB.H
|
||||
PORTAB.lst
|
||||
$ num
|
||||
SETJMP.H
|
||||
SETJMP.lst
|
||||
$ num
|
||||
SGTTY.H
|
||||
SGTTY.lst
|
||||
$ num
|
||||
SIGNAL.H
|
||||
SIGNAL.lst
|
||||
$ num
|
||||
STDIO.H
|
||||
STDIO.lst
|
||||
$ num
|
||||
CREATVMS.C
|
||||
CREATVMS.lsv
|
||||
$ num
|
||||
FTOAVMS.C
|
||||
FTOAVMS.lsv
|
||||
$ num
|
||||
LSEEKVMS.C
|
||||
LSEEKVMS.lsv
|
||||
$ num
|
||||
OPENVMS.C
|
||||
OPENVMS.lsv
|
||||
$ num
|
||||
SBRKVMS.C
|
||||
SBRKVMS.lsv
|
||||
$ num
|
||||
ULDIVVMS.C
|
||||
ULDIVVMS.lsv
|
||||
$ num
|
||||
UNLINKVMS.C
|
||||
UNLINKVMS.lsv
|
||||
$ num
|
||||
XFLSBFVMS.C
|
||||
XFLSBFVMS.lsv
|
||||
$ num
|
||||
VMS.H
|
||||
VMS.lsv
|
||||
$ as68 -l -u -p ABORT.S >ABORT.lsa
|
||||
$ as68 -l -u -p ALDIV.S >ALDIV.lsa
|
||||
$ as68 -l -u -p ALMUL.S >ALMUL.lsa
|
||||
$ as68 -l -u -p ALREM.S >ALREM.lsa
|
||||
$ as68 -l -u -p BLIVOT.S >BLIVOT.lsa
|
||||
$ as68 -l -u -p LDIV.S >LDIV.lsa
|
||||
$ as68 -l -u -p LMUL.S >LMUL.lsa
|
||||
$ as68 -l -u -p LREM.S >LREM.lsa
|
||||
$ as68 -l -u -p NOFLOAT.S >NOFLOAT.lsa
|
||||
$ as68 -l -u -p S.S >S.lsa
|
||||
$ as68 -l -u -p SETJMP.S >SETJMP.lsa
|
||||
$ as68 -l -u -p STKCPY.S >STKCPY.lsa
|
||||
$ as68 -l -u -p ULDIV.S >ULDIV.lsa
|
||||
$ as68 -l -u -p W.S >W.lsa
|
||||
$ as68 -l -u -p XSIGNAL.S >XSIGNAL.lsa
|
||||
$ del *.o;*
|
||||
$ purge
|
||||
$ pri/del/nofee *.lis,*.lsa,*.lst,*.lsv
|
||||
@@ -0,0 +1,54 @@
|
||||
$ num
|
||||
CREATVMS.C
|
||||
CREATVMS.lsv
|
||||
$ num
|
||||
FTOAVMS.C
|
||||
FTOAVMS.lsv
|
||||
$ num
|
||||
LSEEKVMS.C
|
||||
LSEEKVMS.lsv
|
||||
$ num
|
||||
OPENVMS.C
|
||||
OPENVMS.lsv
|
||||
$ num
|
||||
SBRKVMS.C
|
||||
SBRKVMS.lsv
|
||||
$ num
|
||||
ULDIVVMS.C
|
||||
ULDIVVMS.lsv
|
||||
$ num
|
||||
UNLINKVMS.C
|
||||
UNLINKVMS.lsv
|
||||
$ num
|
||||
XFLSBFVMS.C
|
||||
XFLSBFVMS.lsv
|
||||
$ num
|
||||
VMS.H
|
||||
VMS.lsv
|
||||
$ num
|
||||
CREATVMS.C
|
||||
CREATVMS.lsv
|
||||
$ num
|
||||
FTOAVMS.C
|
||||
FTOAVMS.lsv
|
||||
$ num
|
||||
LSEEKVMS.C
|
||||
LSEEKVMS.lsv
|
||||
$ num
|
||||
OPENVMS.C
|
||||
OPENVMS.lsv
|
||||
$ num
|
||||
SBRKVMS.C
|
||||
SBRKVMS.lsv
|
||||
$ num
|
||||
ULDIVVMS.C
|
||||
ULDIVVMS.lsv
|
||||
$ num
|
||||
UNLINKVMS.C
|
||||
UNLINKVMS.lsv
|
||||
$ num
|
||||
XFLSBFVMS.C
|
||||
XFLSBFVMS.lsv
|
||||
$ num
|
||||
VMS.H
|
||||
VMS.lsv
|
||||
73
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/lmul.s
Normal file
73
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/lmul.s
Normal file
@@ -0,0 +1,73 @@
|
||||
*// long multiply routine without floating point
|
||||
*// call with:
|
||||
*// two long values on stack
|
||||
*// returns:
|
||||
*// long value in R0 and R1
|
||||
*//
|
||||
*// warning: no overflow checking or indication!!!!
|
||||
*struct {
|
||||
* int hiword;
|
||||
* int loword;
|
||||
*};
|
||||
*long lmul(l1,l2)
|
||||
*long l1,l2;
|
||||
*{
|
||||
*
|
||||
* long t1;
|
||||
* register int sign;
|
||||
* register int t2;
|
||||
*
|
||||
* sign = 0;
|
||||
* if(l1 < 0) {
|
||||
* l1 = -l1; //make it positive
|
||||
* sign++;
|
||||
* }
|
||||
* if(l2 < 0) {
|
||||
* l2 = -l2; //make it positive
|
||||
* sign++;
|
||||
* }
|
||||
* t1 = l1.loword*l2.loword;
|
||||
* t2 = l1.hiword*l2.loword + l2.hiword*l1.loword;
|
||||
* t1.hiword = t1.hiword + t2;
|
||||
* if(sign&1)
|
||||
* t1 = -t1; //negate results
|
||||
* return(t1);
|
||||
*}
|
||||
*
|
||||
*
|
||||
.globl lmul
|
||||
.text
|
||||
lmul:
|
||||
~~lmul:
|
||||
~sign=R2
|
||||
~l1=8
|
||||
~l2=12
|
||||
~t1=-4
|
||||
~t2=R6
|
||||
link R14,#-4
|
||||
clr R2
|
||||
tst.l 8(R14) //is first arg negative?
|
||||
bge L2
|
||||
neg.l 8(R14) //yes, negate it
|
||||
inc R2 // increment sign flag
|
||||
L2:tst.l 12(R14) //is second arg negative?
|
||||
bge L3
|
||||
neg.l 12(R14) //yes, make it positive
|
||||
inc R2 //increment sign flag
|
||||
L3:move 10(R14),R0 //arg1.loword
|
||||
mulu 14(R14),R0 //arg2.loword
|
||||
move.l R0,-4(R14) //save in temp
|
||||
move 8(R14),R0 //arg1.hiword
|
||||
mulu 14(R14),R0 //arg2.loword
|
||||
move 12(R14),R1 //arg2.hiword
|
||||
mulu 10(R14),R1 //arg1.loword
|
||||
add R1,R0 //form the sum of 2 lo-hi products
|
||||
add -4(R14),R0 //add to temp hiword
|
||||
move R0,-4(R14) //store back in temp hiword
|
||||
move.l -4(R14),R0 //long results
|
||||
btst #0,R2 //test sign flag
|
||||
beq L4
|
||||
neg.l R0 //complement the results
|
||||
L4:
|
||||
unlk R14
|
||||
rts
|
||||
21
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/lrem.s
Normal file
21
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/lrem.s
Normal file
@@ -0,0 +1,21 @@
|
||||
.globl _ldiv
|
||||
.globl _ldivr
|
||||
.comm _ldivr,4
|
||||
.globl _lrem
|
||||
.globl lrem
|
||||
.text
|
||||
_lrem:
|
||||
lrem:
|
||||
~~lrem:
|
||||
~l2=12
|
||||
~al1=8
|
||||
link R14,#-2
|
||||
move.l 12(R14),-(sp)
|
||||
move.l 8(R14),-(sp)
|
||||
jsr _ldiv
|
||||
cmpm.l (sp)+,(sp)+
|
||||
move.l _ldivr,R0
|
||||
unlk R14
|
||||
rts
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* L s e e k F u n c t i o n
|
||||
* ---------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* The lseek function changes the present position of reading
|
||||
* to or writing from a file.
|
||||
* The tell function returns the present position in a file.
|
||||
*
|
||||
* Calling sequence:
|
||||
*
|
||||
* ret = lseek(fd,offset,sense);
|
||||
* or ret = tell(fd);
|
||||
*
|
||||
* Where:
|
||||
*
|
||||
* fd Is an open file descriptor
|
||||
* offset Is the (long) file offset
|
||||
* sense Is the meaning of offset
|
||||
* 0 => From the beginning of the file
|
||||
* 1 => From the present file position
|
||||
* 2 => From the end of the file
|
||||
*
|
||||
* ret Is the resulting absolute file offset
|
||||
* -1 indicates failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
#include "osiferr.h"
|
||||
#include "errno.h"
|
||||
|
||||
LONG lseek(fd,offs,sense) /* CLEAR FUNCTION ***********/
|
||||
/* */
|
||||
WORD fd; /* Open file descriptor */
|
||||
LONG offs; /* File offset */
|
||||
WORD sense; /* Sense of offset */
|
||||
/* */
|
||||
/****************************/
|
||||
{
|
||||
/****************************/
|
||||
REG FD *fp; /* File pointer */
|
||||
EXTERN FD *_chkc(); /* fd to fp translation MGL */
|
||||
EXTERN LONG _filesz(); /* computes CP/M file size */
|
||||
/* */
|
||||
if((fp = _chkc(fd)) == NULLFD) /* Convert to pointer */
|
||||
RETERR(FAILURE,EBADF); /* Can't */
|
||||
switch(sense) /****************************/
|
||||
{ /* */
|
||||
case 0: /* From beginning of file */
|
||||
fp->offset = offs; /* Just set to offset */
|
||||
break; /* Then quit */
|
||||
/****************************/
|
||||
case 1: /* From present position */
|
||||
fp->offset += offs; /* */
|
||||
break; /* */
|
||||
/****************************/
|
||||
case 2: /* From end of file */
|
||||
fp->hiwater = _filesz(fd); /* go find the end of file */
|
||||
fp->offset = fp->hiwater + offs;/* compute from end of file */
|
||||
break; /* */
|
||||
/****************************/
|
||||
default: /* All others NFG */
|
||||
RETERR(FAILURE,EINVAL); /* */
|
||||
} /****************************/
|
||||
fp->flags &= ~ATEOF; /* any seek clears EOF */
|
||||
if( fp->offset < 0 ) /* bad seek call? */
|
||||
fp->offset = -1; /* set to uniform value */
|
||||
return(fp->offset); /* Return resultant offset */
|
||||
} /****************************/
|
||||
|
||||
/****************************/
|
||||
LONG tell(fd) /* CLEAR FUNCTION ***********/
|
||||
WORD fd; /* this file here */
|
||||
{ /* */
|
||||
return(lseek(fd,0L,1)); /* is that all? */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,26 @@
|
||||
/* SEEK FOR VMS
|
||||
* copyright (c) 1980 by Whitesmiths, Ltd.
|
||||
*/
|
||||
#include <std.h>
|
||||
#include "vms.h"
|
||||
|
||||
FILE lseek(fd, loff, way)
|
||||
FILE fd;
|
||||
LONG loff;
|
||||
COUNT way;
|
||||
{
|
||||
FAST RCB *p;
|
||||
|
||||
if (!(p = _ckfd(fd)) || !(p->flags & WFIX))
|
||||
return (FAIL);
|
||||
else
|
||||
{
|
||||
if (way == 0)
|
||||
p->lseek = loff;
|
||||
else if (way == 1)
|
||||
p->lseek =+ loff;
|
||||
else
|
||||
p->lseek = p->lend + loff;
|
||||
return (p->lseek);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* _ l s t o u t F u n c t i o n
|
||||
* -------------------------------
|
||||
*
|
||||
* Function "_lstout" is called to perform "write" operations to the
|
||||
* list device.
|
||||
*
|
||||
* Calling Sequence:
|
||||
* ret = _lstout(buffer,count,func);
|
||||
*
|
||||
* Where:
|
||||
* buffer -> the output buffer (byte 0 is count)
|
||||
* ret = count on return
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
#include "osif.h"
|
||||
|
||||
WORD _lstout(buffer) /***************************/
|
||||
REG BYTE *buffer; /* -> 1st char output */
|
||||
{ /***************************/
|
||||
REG WORD count; /* = # bytes to xfer */
|
||||
WORD xcount; /* save area for count */
|
||||
/* */
|
||||
xcount = count = (0xFF & *buffer++); /* Copy for later */
|
||||
/* */
|
||||
while(count-- > 0) /* Until all written */
|
||||
__OSIF(LSTOUT,*buffer++); /* Output next character */
|
||||
return(xcount); /* return original count */
|
||||
} /***************************/
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Use this file to determine what kind of machine you want the
|
||||
* Alcyon stuff to run on ....
|
||||
*/
|
||||
/*#define MC68000 1*/ /* 68000 version */
|
||||
/*#define VAX 1*/ /* VAX Version */
|
||||
#define PDP11 1 /* PDP-11 Version*/
|
||||
/*#define CPM 1*/ /* CP/M Operating System*/
|
||||
#define UNIX 1 /* UNIX Operating System*/
|
||||
/*#define VMS 1*/ /* VMS Operating System*/
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Use this file to determine what kind of machine you want the
|
||||
* Alcyon stuff to run on ....
|
||||
*/
|
||||
#define MC68000 1 /* 68000 version */
|
||||
/*#define VAX 1*/ /* VAX Version */
|
||||
/*#define PDP11 1*/ /* PDP-11 Version*/
|
||||
#define CPM 1 /* CP/M Operating System*/
|
||||
/*#define UNIX 1*/ /* UNIX Operating System*/
|
||||
/*#define VMS 1*/ /* VMS Operating System*/
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Use this file to determine what kind of machine you want the
|
||||
* Alcyon stuff to run on ....
|
||||
*/
|
||||
#define MC68000 1 /* 68000 version */
|
||||
/*#define VAX 1*/ /* VAX Version */
|
||||
/*#define PDP11 1*/ /* PDP-11 Version*/
|
||||
#define CPM 1 /* CP/M Operating System*/
|
||||
/*#define UNIX 1*/ /* UNIX Operating System*/
|
||||
/*#define VMS 1*/ /* VMS Operating System*/
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Use this file to determine what kind of machine you want the
|
||||
* Alcyon stuff to run on ....
|
||||
*/
|
||||
/*#define MC68000 1*/ /* 68000 version */
|
||||
#define VAX 1 /* VAX Version */
|
||||
/*#define PDP11 1*/ /* PDP-11 Version*/
|
||||
/*#define CPM 1*/ /* CP/M Operating System*/
|
||||
/*#define UNIX 1*/ /* UNIX Operating System*/
|
||||
#define VMS 1 /* VMS Operating System*/
|
||||
54
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/main.c
Normal file
54
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/main.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* R U N T I M E S T A R T O F F R O U T I N E
|
||||
* -----------------------------------------------
|
||||
* Copyright 1982,83 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* Routine "_main" is entered from the C header routine to start a C
|
||||
* program. It opens STDIN, STDOUT and STDERR to the console, and
|
||||
* translates the command line to lower case. Then it calls "__main()".
|
||||
* There are two versions of "__main()" (one compiled for wildcards
|
||||
* and the other compiled without) compiled from the source module
|
||||
* "XMAIN.C".
|
||||
*
|
||||
* Calling Sequence:
|
||||
* return = _main(command,length);
|
||||
*
|
||||
* Where:
|
||||
* command Is the address of the command line from CP/M
|
||||
* length Is the number of characters in the line,
|
||||
* excluding the termination character (CR/LF).
|
||||
*
|
||||
* Modfications:
|
||||
* 11-Oct-83 whf converted to DRC from CPM68K
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "portab.h" /* Include std definitions */
|
||||
#include "osif.h" /* */
|
||||
#include "ctype.h" /* */
|
||||
|
||||
EXTERN BYTE __tname[]; /* Name of terminal device */
|
||||
EXTERN BYTE __fdecls(); /* force loading of _iob */
|
||||
EXTERN BYTE ___atab(); /* force loading of ___atab */
|
||||
|
||||
#define STDIN 0 /* file descriptors */
|
||||
#define STDOUT 1 /* */
|
||||
#define STDERR 2 /* */
|
||||
/* */
|
||||
_main(com, len) /****************************/
|
||||
BYTE *com; /* Command address */
|
||||
WORD len; /* Command length */
|
||||
{ /****************************/
|
||||
REG BYTE *s; /* Temp byte pointer */
|
||||
/****************************/
|
||||
_chinit(); /* Initialize channels */
|
||||
open(__tname,READ); /* Open STDIN */
|
||||
open(__tname,WRITE); /* Open STDOUT */
|
||||
open(__tname,WRITE); /* Open STDERR */
|
||||
com[len] = NULL; /* Insure null at line end */
|
||||
for (s = com; *s; s++) /* Convert string to */
|
||||
*s = tolower(*s); /* lower case */
|
||||
__main(com,len); /* Do rest (replaceable) */
|
||||
} /****************************/
|
||||
|
||||
104
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/make.com
Normal file
104
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/make.com
Normal file
@@ -0,0 +1,104 @@
|
||||
$ set noon
|
||||
$ clib
|
||||
$ copy machine.68k machine.h
|
||||
$ pur machine.h
|
||||
$ cc68 XMAIN
|
||||
$ cc68 XWMAIN
|
||||
$ cc68 PERROR
|
||||
$ cc68 MKTEMP
|
||||
$ cc68 CHMOD
|
||||
$ cc68 CHOWN
|
||||
$ cc68 FPRINTF
|
||||
$ cc68 PRINTF
|
||||
$ cc68 SPRINTF
|
||||
$ cc68 XDOPRT
|
||||
$ cc68 XPRTINT
|
||||
$ cc68 XPRTLD
|
||||
$ cc68 XPRTSHRT
|
||||
$ cc68 FSCANF
|
||||
$ cc68 SCANF
|
||||
$ cc68 SSCANF
|
||||
$ cc68 XDOSCAN
|
||||
$ cc68 FDOPEN
|
||||
$ cc68 FOPEN
|
||||
$ cc68 FREOPEN
|
||||
$ cc68 FTELL
|
||||
$ cc68 REWIND
|
||||
$ cc68 FSEEK
|
||||
$ cc68 EXIT
|
||||
$ cc68 CLEANUP
|
||||
$ cc68 FCLOSE
|
||||
$ cc68 FFLUSH
|
||||
$ cc68 FREAD
|
||||
$ cc68 FWRITE
|
||||
$ cc68 FGETS
|
||||
$ cc68 GETS
|
||||
$ cc68 FPUTS
|
||||
$ cc68 PUTS
|
||||
$ cc68 GETL
|
||||
$ cc68 GETW
|
||||
$ cc68 PUTL
|
||||
$ cc68 PUTW
|
||||
$ cc68 UNGETC
|
||||
$ cc68 SETBUF
|
||||
$ cc68 FGETC
|
||||
$ cc68 FPUTC
|
||||
$ cc68 XFILBUF
|
||||
$ cc68 XFLSBUF
|
||||
$ cc68 XFDECLS
|
||||
$ cc68 CLOSE
|
||||
$ cc68 CREAT
|
||||
$ cc68 LSEEK
|
||||
$ cc68 XFILESZ
|
||||
$ cc68 OPEN
|
||||
$ cc68 READ
|
||||
$ cc68 XTTYIN
|
||||
$ cc68 UNLINK
|
||||
$ cc68 WRITE
|
||||
$ cc68 XOPEN
|
||||
$ cc68 ACCESS
|
||||
$ cc68 GETPASS
|
||||
$ cc68 TTYNAME
|
||||
$ cc68 ISATTY
|
||||
$ cc68 CHINIT
|
||||
$ cc68 CHKC
|
||||
$ cc68 BLKIO
|
||||
$ cc68 ALLOCC
|
||||
$ cc68 ATOI
|
||||
$ cc68 ATOL
|
||||
$ cc68 SWAB
|
||||
$ cc68 GETPID
|
||||
$ cc68 RAND
|
||||
$ cc68 QSORT
|
||||
$ cc68 CALLOC
|
||||
$ cc68 MALLOC
|
||||
$ cc68 SBRK
|
||||
$ cc68 ERRNO
|
||||
$ cc68 exec
|
||||
$ cc68 CTYPE
|
||||
$ cc68 INDEX
|
||||
$ cc68 RINDEX
|
||||
$ cc68 STRCAT
|
||||
$ cc68 STRCMP
|
||||
$ cc68 STRCPY
|
||||
$ cc68 STRLEN
|
||||
$ cc68 STRNCAT
|
||||
$ cc68 STRNCMP
|
||||
$ cc68 STRNCPY
|
||||
$ cc68 signal
|
||||
$ cc68 xstrcmp
|
||||
$ as68 -l -u ABORT.s
|
||||
$ as68 -l -u ALDIV.s
|
||||
$ as68 -l -u ALMUL.s
|
||||
$ as68 -l -u ALREM.s
|
||||
$ as68 -l -u LMUL.s
|
||||
$ as68 -l -u LDIV.s
|
||||
$ as68 -l -u LREM.s
|
||||
$ as68 -l -u ULDIV.s
|
||||
$ as68 -l -u setjmp.s
|
||||
$ as68 -l -u s.s
|
||||
$ as68 -l -u w.s
|
||||
$ as68 -l -u nofloat.s
|
||||
$ as68 -l -u blivot.s
|
||||
$ as68 -l -u xsignal.s
|
||||
$ @rear
|
||||
1060
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/make.sub
Normal file
1060
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/make.sub
Normal file
File diff suppressed because it is too large
Load Diff
263
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/malloc.c
Normal file
263
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/malloc.c
Normal file
@@ -0,0 +1,263 @@
|
||||
/********************************************************************
|
||||
* malloc, free - memory allocator mechanism
|
||||
*
|
||||
* 9/83: fixed free bug, added check word whf
|
||||
* 10/83: added debugging features: DEBUGMEM and MALLOCND hooks whf
|
||||
*
|
||||
* BYTE *malloc(numbytes)
|
||||
* WORD numbytes
|
||||
* Returns a pointer to an area of memory at least 'numbytes'
|
||||
* in length. Returns NULLPTR if out of memory or corrupted freelist.
|
||||
* Warning: the size of the area is right below the region:
|
||||
* do not overwrite!
|
||||
*
|
||||
*
|
||||
* WORD free(mptr)
|
||||
* BYTE *mptr
|
||||
* Frees the region pointed to by 'mptr'. Returns 0 (SUCCESS) if ok,
|
||||
* FAILURE (-1) if corrupted freelist (or if mptr was not previously
|
||||
* allocated by malloc).
|
||||
*
|
||||
*
|
||||
* BYTE *realloc(mptr,numbytes)
|
||||
* BYTE *mptr
|
||||
* WORD numbytes
|
||||
* Returns a pointer to a (probably different) region of memory
|
||||
* (numbytes long) containing the same data as the old region
|
||||
* pointed to by mptr. Returns NULLPTR if not enough memory, or
|
||||
* if freelist was corrupted.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
/************************* #include "malloc.h" *****************************/
|
||||
#define FB_HDR struct hdr /* free block header type */
|
||||
#define NULLFBH ((FB_HDR *)0) /* Null of above struct */
|
||||
/* */
|
||||
FB_HDR { /* mem_block header */
|
||||
struct hdr *ptr; /* ptr next blk (when freed)*/
|
||||
UWORD size; /* block size (always) */
|
||||
UWORD chksize; /* 1's complement of size */
|
||||
}; /****************************/
|
||||
/* */
|
||||
FB_HDR _afreebase = {&_afreebase,0,~0 }; /* initial (empty) block */
|
||||
FB_HDR *_aflistptr = &_afreebase; /* ptr into ring of freeblks*/
|
||||
/* */
|
||||
#define AOFFS 1L /* alignment offset: 0=byte, 1=word, 3=quad */
|
||||
#define AMASK(c) ((char *)((long)(c) & ~AOFFS)) /* mask alignment bits */
|
||||
#define AFUDGE 4 /* leeway for passing block as is */
|
||||
#define ACHUNKS 64 /* chunks to alloc from O.S.*/
|
||||
/* */
|
||||
#define ERR_FINDBLOCK 1 /* error in 'findblock()' */
|
||||
#define ERR_GETMEM 2 /* error in 'getmemory()' */
|
||||
#define ERR_FREE 3 /* error in 'free()' */
|
||||
/* */
|
||||
/*** end of "malloc.h" ******/
|
||||
/****************************************************************************/
|
||||
/* malloc - general purpose memory allocator
|
||||
* This function allocates the requested number of bytes (nbytes) and returns
|
||||
* a pointer to this space to the calling function.
|
||||
* The memory is requested from the O.S. in larger chunks, and
|
||||
* free space is managed as a ring of free blocks. Each block
|
||||
* contains a pointer to the next block (s.ptr), a block size (s.size),
|
||||
* a check word (1's complement of size), and the space itself.
|
||||
* Alignment is handled by assuming that sizeof(FB_HDR) is an aligned
|
||||
* quantity, and allocating in multiples of that size.
|
||||
************************************************** */
|
||||
BYTE * malloc(nbytes) /* CLEAR FUNCTION ***********/
|
||||
UWORD nbytes; /* number bytes requested */
|
||||
{ /****************************/
|
||||
REG UWORD nmults; /* multiples of FB_HDR size */
|
||||
REG FB_HDR *pp; /* temporary ptr */
|
||||
FB_HDR *findblock(); /* find free block */
|
||||
BYTE *cutup(); /* cut free block to fit */
|
||||
/* */
|
||||
nmults = (nbytes+sizeof(FB_HDR)-1)/sizeof(FB_HDR)+1; /* */
|
||||
if( (pp=findblock(nmults)) == NULLFBH ) /* find ptr to ptr to block */
|
||||
return NULLPTR; /* no luck... */
|
||||
return cutup(pp,nmults); /* cut block to fit & return*/
|
||||
} /****************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/* findblock - local subr to find a free block that's big enough. */
|
||||
/* It returns a pointer to the freeblock BEFORE the desired freeblock, */
|
||||
/* in order to fix the pointer of the this freeblock. */
|
||||
/************************************************* */
|
||||
MLOCAL FB_HDR * /* */
|
||||
findblock(units) /* find a free block */
|
||||
UWORD units; /* at least this big */
|
||||
{ /****************************/
|
||||
REG FB_HDR *cp; /* ptr to current block */
|
||||
REG FB_HDR *pp; /* ptr to previous block */
|
||||
FB_HDR *getmemory(); /* get from OS, add to list */
|
||||
/* */
|
||||
pp = _aflistptr; /* start search here */
|
||||
cp = pp->ptr; /* init current ptr */
|
||||
while(1) /* do forever */
|
||||
{ /* */
|
||||
if(~(cp->size^cp->chksize)) /* does cp pt to valid blk? */
|
||||
{ /* no... */
|
||||
_errmalloc(ERR_FINDBLOCK); /* handle this error */
|
||||
return NULLFBH; /* */
|
||||
} /* */
|
||||
if( cp->size >= units ) /* is this block big enough?*/
|
||||
return pp; /* yes! NOTE: return prevptr*/
|
||||
if( cp == _aflistptr ) /* end of list? */
|
||||
if( (cp=getmemory(units)) == NULLFBH ) /* is there more? */
|
||||
{ /* */
|
||||
_errmalloc(ERR_GETMEM); /* */
|
||||
return NULLFBH; /* no more memory... */
|
||||
} /* */
|
||||
pp = cp; /* */
|
||||
cp = cp->ptr; /* move on down the list */
|
||||
} /* */
|
||||
} /****************************/
|
||||
|
||||
/****************************************************************************/
|
||||
/* cutup - a local fn to cut up the free block (if its much bigger than the */
|
||||
/* number of units requested), and to convert blk ptr to byte ptr. */
|
||||
/************************************************* */
|
||||
MLOCAL BYTE * /* */
|
||||
cutup(pp,units) /* cut the block to fit */
|
||||
FB_HDR *pp; /* ptr to ptr to block */
|
||||
UWORD units; /* num units to cut to */
|
||||
{ /****************************/
|
||||
REG FB_HDR *cp; /* cur ptr */
|
||||
REG FB_HDR *np; /* new ptr (if needed) */
|
||||
/* */
|
||||
cp = pp->ptr; /* get ptr to big block */
|
||||
if( cp->size <= units+AFUDGE ) /* is size close enough? */
|
||||
pp->ptr = cp->ptr; /* yes: cut cp from list */
|
||||
else { /* o.w. cut block up */
|
||||
np = cp + units; /* where it starts */
|
||||
np->size = cp->size - units; /* how big it is */
|
||||
np->chksize = ~np->size; /* it's a valid blk */
|
||||
np->ptr = cp->ptr; /* it's linked into freelist*/
|
||||
pp->ptr = np; /* from both sides */
|
||||
cp->size = units; /* new size for cur block */
|
||||
cp->chksize = ~cp->size; /* and make valid */
|
||||
} /****************************/
|
||||
_aflistptr = pp; /* search from here next tim*/
|
||||
return cp+1; /* point to after header */
|
||||
} /****************************/
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* getmemory - gets memory from O.S. */
|
||||
/* This function requests memory from the O.S. in multiples (ACHUNKS) */
|
||||
/* of the requested number of units (numu), in order to minimize */
|
||||
/* the number of calls to the O.S. */
|
||||
/* Function cleans up pointer alignment and adds to free list. */
|
||||
/************************************************* */
|
||||
MLOCAL FB_HDR *
|
||||
getmemory(numu)
|
||||
UWORD numu; /* number of units */
|
||||
{
|
||||
BYTE *sbrk(); /* obtain memory from O.S. */
|
||||
REG BYTE *mmp; /* more memory pointer */
|
||||
REG FB_HDR *fbp; /* free block pointer */
|
||||
REG WORD utg; /* units to get */
|
||||
|
||||
utg = ((numu+(ACHUNKS-1)) / ACHUNKS) * ACHUNKS;
|
||||
|
||||
mmp = sbrk(utg * sizeof(FB_HDR)); /* sbrk wants number of bytes */
|
||||
|
||||
if( mmp == (char *)-1 ) /* sbrk = -1 means no memory available */
|
||||
return( NULLFBH );
|
||||
mmp = AMASK(mmp + AOFFS); /* alignment handling: nop if good sbrk */
|
||||
fbp = (FB_HDR *)mmp;
|
||||
fbp->size = utg;
|
||||
fbp->chksize = ~fbp->size;
|
||||
free( (BYTE *)(fbp+1) ); /* add to free list */
|
||||
return(_aflistptr); /* set in 'free' */
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* free - adds memory back to free block list.
|
||||
* This function assumes freed memory pointer (fmp) points to free space
|
||||
* preceeded by a FB_HDR structure.
|
||||
* Note that free block is inserted in memory address order,
|
||||
* to facilitate compaction.
|
||||
* Fails (-1 return) if you link in a random ptr.
|
||||
************************************************* */
|
||||
WORD free(fmp) /* CLEAR FUNCTION ***********/
|
||||
BYTE *fmp; /* freed memory ptr */
|
||||
{ /****************************/
|
||||
REG FB_HDR *cp, /* current freeblk ptr */
|
||||
*pp; /* previous freeblk ptr */
|
||||
/****************************/
|
||||
cp = (FB_HDR *)fmp - 1; /* ptr to (hdr of) freed blk*/
|
||||
if(~(cp->size^cp->chksize)) /* is blk valid? */
|
||||
{ /* */
|
||||
_errmalloc(ERR_FREE); /* */
|
||||
return FAILURE; /* no: fail... */
|
||||
} /****************************/
|
||||
for( pp=_aflistptr; ; pp=pp->ptr ) /* start through the list */
|
||||
{ /* */
|
||||
if( cp >= pp && cp < pp->ptr ) /* are we at correct place? */
|
||||
break; /* yes... */
|
||||
if( pp >= pp->ptr && /* at end of list? and */
|
||||
(cp <= pp->ptr || cp >= pp) ) /* blk is off either end? */
|
||||
break; /* yes... */
|
||||
} /****************************/
|
||||
if( cp>=pp && cp+cp->size <= pp+pp->size )/* block already freed? */
|
||||
{ /* */
|
||||
_aflistptr = pp; /* search from here next */
|
||||
return SUCCESS; /* and do no more */
|
||||
} /****************************/
|
||||
/************************************************* */
|
||||
/* Insert freed block back into list. Try to coalesce (merge) adjacent */
|
||||
/* regions. */
|
||||
/************************************************* */
|
||||
if( cp+cp->size == pp->ptr ) /* end freed blk==start nxt?*/
|
||||
{ /* then merge with nxt */
|
||||
cp->size += pp->ptr->size; /* */
|
||||
cp->chksize = ~cp->size; /* */
|
||||
cp->ptr = pp->ptr->ptr; /* */
|
||||
} else /***** */
|
||||
cp->ptr = pp->ptr; /* else just point to nxt */
|
||||
/****************************/
|
||||
if( pp+pp->size == cp ) /* end prev plk==start cur? */
|
||||
{ /* then merge with prev*/
|
||||
pp->size += cp->size; /* */
|
||||
pp->chksize = ~pp->size; /* */
|
||||
pp->ptr = cp->ptr; /* */
|
||||
} else /***** */
|
||||
pp->ptr = cp; /* else point prev to cur */
|
||||
/****************************/
|
||||
_aflistptr = pp; /* search from here next time*/
|
||||
return SUCCESS; /* say its ok */
|
||||
} /****************************/
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* realloc - free memory, allocate again (with changed size maybe), */
|
||||
/* preserve contents. */
|
||||
/************************************************* */
|
||||
BYTE * realloc(ptr,siz) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *ptr; /* ptr to (prev malloc'd)mem*/
|
||||
UWORD siz; /* size of mem */
|
||||
{ /****************************/
|
||||
REG BYTE *np; /* ptr to new allocation */
|
||||
REG UWORD nmults; /* multiples if FB_HDR size */
|
||||
FB_HDR *pp, *findblock(); /* find free block */
|
||||
BYTE *cutup(); /* cut free block to fit */
|
||||
/* */
|
||||
free(ptr); /* stuff back into free list: any coalesce will not */
|
||||
/* affect original data region */
|
||||
nmults = (siz+sizeof(FB_HDR)-1)/sizeof(FB_HDR)+1; /* */
|
||||
if( (pp=findblock(nmults)) == NULLFBH ) /* find ptr to ptr to block */
|
||||
return NULLPTR; /* no luck... */
|
||||
np = (pp->ptr)+1; /* convert to BYTE ptr */
|
||||
if( ptr != np ) { /* if ptr changed */
|
||||
if( np < ptr ) /* if new ptr in lower mem */
|
||||
for( ; siz; siz-- ) /* copy up */
|
||||
*np++ = *ptr++; /* */
|
||||
else /* if new ptr in higher mem */
|
||||
for( np+=siz, ptr+=siz; siz; siz-- ) /* copy down */
|
||||
*--np = *--ptr; /* */
|
||||
} /****************************/
|
||||
return cutup(pp,nmults); /* cut block to fit & return*/
|
||||
} /****************************/
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
/************************************************************************
|
||||
* _errmalloc / MALLOCDB.C : prints error messages for malloc()
|
||||
* To be included in OPTION?.lib
|
||||
*
|
||||
* 10/83 whf
|
||||
************************************************************************/
|
||||
|
||||
#include <portab.h>
|
||||
|
||||
/************************* #include "malloc.h" *****************************/
|
||||
#define FB_HDR struct hdr /* free block header type */
|
||||
/* */
|
||||
FB_HDR { /* mem_block header */
|
||||
struct hdr *ptr; /* ptr next blk (when freed)*/
|
||||
UWORD size; /* block size (always) */
|
||||
UWORD chksize; /* 1's complement of size */
|
||||
}; /****************************/
|
||||
/* */
|
||||
EXTERN FB_HDR _afreebase; /* initial (empty) block */
|
||||
EXTERN FB_HDR *_aflistptr; /* ptr into ring of freeblks*/
|
||||
/* */
|
||||
#define AOFFS 1L /* alignment offset: 0=byte, 1=word, 3=quad */
|
||||
#define AMASK(c) ((char *)((long)(c) & ~AOFFS)) /* mask alignment bits */
|
||||
#define AFUDGE 4 /* leeway for passing block as is */
|
||||
#define ACHUNKS 64 /* chunks to alloc from O.S.*/
|
||||
/* */
|
||||
#define ERR_FINDBLOCK 1 /* error in 'findblock()' */
|
||||
#define ERR_GETMEM 2 /* error in 'getmemory()' */
|
||||
#define ERR_FREE 3 /* error in 'free()' */
|
||||
/* */
|
||||
/*** end of "malloc.h" ******/
|
||||
/****************************************************************************/
|
||||
|
||||
_errmalloc(etype)
|
||||
int etype; /* type of error */
|
||||
{
|
||||
switch(etype)
|
||||
{
|
||||
case ERR_FINDBLOCK:
|
||||
printf("malloc() error: corrupt arena\n");
|
||||
break;
|
||||
case ERR_GETMEM:
|
||||
printf("malloc() error: out of memory\n");
|
||||
break;
|
||||
case ERR_FREE:
|
||||
printf("free() error: pointer was not from malloc()\n");
|
||||
break;
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* malloc_debug(): checks the free list to see if everything is ok. */
|
||||
/************************************************* */
|
||||
WORD malloc_debug() /* */
|
||||
{ /****************************/
|
||||
REG FB_HDR *cp; /* ptr to current block */
|
||||
/* */
|
||||
cp = _aflistptr; /* start search here */
|
||||
while(1) /* do forever */
|
||||
{ /* */
|
||||
if(~(cp->size^cp->chksize)) /* does cp pt to valid blk? */
|
||||
{ /* no... */
|
||||
_errmalloc(ERR_FINDBLOCK); /* handle this error */
|
||||
return FAILURE; /* */
|
||||
} /* */
|
||||
cp = cp->ptr; /* move on down the list */
|
||||
if( cp == _aflistptr ) /* end of list? */
|
||||
return SUCCESS; /* */
|
||||
} /* */
|
||||
} /****************************/
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
/****************************************************************************
|
||||
* _errmalloc / MALLOCND.C : stubroutine for malloc() error handler
|
||||
* Let the user program handle it.
|
||||
*
|
||||
* 10/83 whf
|
||||
*****************************************************************************/
|
||||
|
||||
malloc_debug() {} /* stubroutine tag */
|
||||
|
||||
_errmalloc() {}
|
||||
@@ -0,0 +1,40 @@
|
||||
/***********************************************************************
|
||||
*
|
||||
* m k t e m p F u n c t i o n
|
||||
* -----------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* "mktemp" assumes it is called with a string ending in 6 X's.
|
||||
* It will replace the last 6 chars with the process id
|
||||
* and a letter (different on each invocation).
|
||||
* REALLY "mktemp" replaces everything after the 1st x...
|
||||
* this is a feature...
|
||||
* Note that the process id does not change under CP/M,
|
||||
* therefore the name itself will not be very unique...
|
||||
*
|
||||
* Calling sequence:
|
||||
* string = mktemp(string)
|
||||
* Where:
|
||||
*
|
||||
* string -> null terminated string with 6 x's
|
||||
*
|
||||
*************************************************************************/
|
||||
|
||||
#include "portab.h"
|
||||
|
||||
MLOCAL BYTE _mktchar = { 'A' };
|
||||
|
||||
BYTE * mktemp(template) /* CLEAR FUNCTION ***********/
|
||||
REG BYTE *template;
|
||||
{
|
||||
REG BYTE *ss;
|
||||
|
||||
for( ss=template; *ss != 'x' && *ss != 'X'; ss++)
|
||||
if(*ss == NULL)
|
||||
return(template); /* resign */
|
||||
if( _mktchar < 'A' || _mktchar >'Z' )
|
||||
_mktchar = 'A';
|
||||
sprintf(ss,"X%04.4d%c",getpid(),_mktchar);
|
||||
_mktchar++;
|
||||
return(template);
|
||||
}
|
||||
161
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/mopen.mar
Normal file
161
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v102a/clib/mopen.mar
Normal file
@@ -0,0 +1,161 @@
|
||||
.title mopen
|
||||
; copyright (c) 1980 by Whitesmiths, Ltd.
|
||||
; allocate fab+rab and open/create
|
||||
|
||||
.globl $_close, $_merase, $_mopen, $_read, $_write
|
||||
.globl lib$get_vm
|
||||
$devdef
|
||||
|
||||
.psect c$text,shr,nowrt,quad
|
||||
$_close:
|
||||
.word ^O0 ; (&rab)
|
||||
movl 4(ap),r0
|
||||
movl rab$l_fab(r0),r0
|
||||
$close fab=r0
|
||||
extzv #0,#1,r0,r0
|
||||
ret
|
||||
|
||||
$_merase:
|
||||
.word ^O0 ; (name, len)
|
||||
$fab_store fab=tfab,fna=@4(ap),fns=8(ap)
|
||||
$erase fab=tfab
|
||||
blbc r0,$0
|
||||
clrl r0
|
||||
ret
|
||||
$0:
|
||||
mcoml #0,r0
|
||||
ret
|
||||
|
||||
$_mopen:
|
||||
.word ^O774 ; (name, len, &facc, rsize, &rab, &eofblk)
|
||||
movl 20(ap),r6
|
||||
bneq $1
|
||||
pushl #0
|
||||
pushal (sp)
|
||||
pushal rfsize
|
||||
calls #2,G^lib$get_vm
|
||||
movl (sp)+,r6
|
||||
blbs r0,$1
|
||||
clrl r0
|
||||
ret
|
||||
$1:
|
||||
addl3 r6,#profab-prorab,r7
|
||||
movl @12(ap),r8
|
||||
movc3 rfsize,prorab,(r6)
|
||||
$fab_store fab=r7,fna=@4(ap),fns=8(ap)
|
||||
movl 16(ap),r1
|
||||
beql $2
|
||||
$fab_store fab=r7,rfm=fix,mrs=r1
|
||||
brb $3
|
||||
$2:
|
||||
$fab_store fab=r7,rfm=var
|
||||
$3:
|
||||
tstl r1
|
||||
beql $4
|
||||
movl #fab$m_bio,r1
|
||||
$rab_store rab=r6,rop=bio
|
||||
$4:
|
||||
blbc r8,$5
|
||||
bisl2 #fab$m_get,r1
|
||||
$5:
|
||||
bitl #2,r8
|
||||
beql $6
|
||||
bisl2 #fab$m_put,r1
|
||||
$6:
|
||||
movb r1,fab$b_fac(r7)
|
||||
bitl #4,r8
|
||||
beql $7
|
||||
$fab_store fab=r7,xab=hdrxab
|
||||
$open fab=r7
|
||||
movl hdrxab+xab$l_ebk,@24(ap)
|
||||
brb $8
|
||||
$7:
|
||||
$create fab=r7
|
||||
$8:
|
||||
blbs r0,$81
|
||||
clrl r0
|
||||
ret
|
||||
$81:
|
||||
$rab_store rab=r6,fab=(r7)
|
||||
$connect rab=r6
|
||||
blbs r0,$82
|
||||
clrl r0
|
||||
ret
|
||||
$82:
|
||||
bitl #dev$m_trm,fab$l_dev(r7)
|
||||
beql $9
|
||||
bisl2 #8,r8
|
||||
$9:
|
||||
bitb #fab$m_cr,fab$b_rat(r7)
|
||||
beql $10
|
||||
bisl2 #16,r8
|
||||
$10:
|
||||
movl r8,@12(ap)
|
||||
movl r6,r0
|
||||
ret
|
||||
|
||||
$_read:
|
||||
.word ^O0 ; (&rab, &buf, size, bno)
|
||||
movl 4(ap),r0
|
||||
$rab_store rab=r0,ubf=@8(ap),usz=12(ap)
|
||||
movl 16(ap),r1
|
||||
bneq $12
|
||||
$get rab=r0
|
||||
brb $13
|
||||
$12:
|
||||
$rab_store rab=r0,bkt=r1
|
||||
$read rab=r0
|
||||
$13:
|
||||
blbc r0,$14
|
||||
movl 4(ap),r0
|
||||
movzwl rab$w_rsz(r0),r0
|
||||
ret
|
||||
$14:
|
||||
cmpl #rms$_eof,r0
|
||||
bneq $15
|
||||
mcoml #0,r0
|
||||
ret
|
||||
$15:
|
||||
movl #-2,r0
|
||||
ret
|
||||
|
||||
$_write:
|
||||
.word ^O0 ; (&rab, &buf, size, bno)
|
||||
movl 4(ap),r0
|
||||
$rab_store rab=r0,rbf=@8(ap),rsz=12(ap)
|
||||
movl 16(ap),r1
|
||||
bneq $16
|
||||
$put rab=r0
|
||||
brb $17
|
||||
$16:
|
||||
$rab_store rab=r0,bkt=r1
|
||||
$write rab=r0
|
||||
$17:
|
||||
blbc r0,$18
|
||||
movl 12(ap),r0
|
||||
ret
|
||||
$18:
|
||||
cmpl #rms$_ext,r0
|
||||
beql $21
|
||||
$20:
|
||||
mcoml #0,r0
|
||||
ret
|
||||
$21:
|
||||
movl 4(ap),r0
|
||||
movl rab$l_fab(r0),r0
|
||||
$extend fab=r0
|
||||
blbc r0,$20
|
||||
brw $_write+2
|
||||
|
||||
.psect c$data,noexe,quad
|
||||
hdrxab:
|
||||
$xabfhc
|
||||
prorab:
|
||||
$rab
|
||||
profab:
|
||||
$fab
|
||||
rfsize:
|
||||
.long .-prorab
|
||||
tfab:
|
||||
$fab
|
||||
.end
|
||||
@@ -0,0 +1 @@
|
||||
user 12 ! make
|
||||
@@ -0,0 +1,12 @@
|
||||
/* NOASCII: pulls out as much ASCII disk i/o as possible. */
|
||||
|
||||
|
||||
noascii() { ; } /* stubroutine 'tag' */
|
||||
|
||||
|
||||
char * __noascii_io_msg = "ascii disk i/o rtns";
|
||||
|
||||
_rdasc() { _optoff(__noascii_io_msg); }
|
||||
_wrtasc() { _optoff(__noascii_io_msg); }
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/* NOBINARY: pulls out as much BINARY disk i/o as possible. */
|
||||
|
||||
|
||||
nobinary() { ; } /* stubroutine 'tag' */
|
||||
|
||||
|
||||
char * __nobinary_io_msg = "binary disk i/o rtns";
|
||||
|
||||
_rdbin() { _optoff(__nobinary_io_msg); }
|
||||
_wrtbin() { _optoff(__nobinary_io_msg); }
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/* NODISK: pulls out as much disk i/o as possible. */
|
||||
|
||||
|
||||
nodisk() { ; } /* stubroutine 'tag' */
|
||||
|
||||
|
||||
char * __nodisk_io_msg = "disk i/o rtns";
|
||||
|
||||
_rdasc() { _optoff(__nodisk_io_msg); }
|
||||
_rdbin() { _optoff(__nodisk_io_msg); }
|
||||
_wrtasc() { _optoff(__nodisk_io_msg); }
|
||||
_wrtbin() { _optoff(__nodisk_io_msg); }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/* NOFILESZ: eliminates routine to calculate filesize (used in lseek()) */
|
||||
|
||||
|
||||
nofilesz() { ; } /* stubroutine 'tag' */
|
||||
|
||||
|
||||
int _filesz() { return 32767; }
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/* NOFLOAT: provides 'stubroutines' to satisfy floating point library */
|
||||
/* references from 'printf' et al. */
|
||||
|
||||
|
||||
nofloat() { ; } /* stubroutine 'tag' */
|
||||
|
||||
char * __nofloat_msg = "floating point";
|
||||
|
||||
_petoa() { _optoff(__nofloat_msg); }
|
||||
_pftoa() { _optoff(__nofloat_msg); }
|
||||
_pgtoa() { _optoff(__nofloat_msg); }
|
||||
_atof() { _optoff(__nofloat_mst); }
|
||||
@@ -0,0 +1,21 @@
|
||||
*
|
||||
* This module is designed to allow the use of "printf" without
|
||||
* dragging in the entire floating point RTL.
|
||||
*
|
||||
.globl nofloat
|
||||
.globl _petoa * Called from "_doprt"
|
||||
.globl _pftoa * Called from "_doprt"
|
||||
nofloat:
|
||||
_petoa:
|
||||
_pftoa:
|
||||
move.l #9,d0 * Print string BDOS Call
|
||||
move.l #fpstring,d1 * d1 -> string to print
|
||||
trap #2 * Print the error
|
||||
clr.l d0 * Now
|
||||
trap #2 * exit
|
||||
|
||||
.data *
|
||||
fpstring:
|
||||
.dc.b 'C RTL -- Program not linked for floating point'
|
||||
.dc.b $0d,$0a,'$'
|
||||
.even
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user