Borland Turbo C v2
This commit is contained in:
parent
8d991454af
commit
4ff13ea2ef
BIN
Borland Turbo C v2/ATT.BGI
Normal file
BIN
Borland Turbo C v2/ATT.BGI
Normal file
Binary file not shown.
1401
Borland Turbo C v2/BGIDEMO.C
Normal file
1401
Borland Turbo C v2/BGIDEMO.C
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Borland Turbo C v2/BGIDEMO.EXE
Normal file
BIN
Borland Turbo C v2/BGIDEMO.EXE
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/BGIDEMO.OBJ
Normal file
BIN
Borland Turbo C v2/BGIDEMO.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/BGIOBJ.EXE
Normal file
BIN
Borland Turbo C v2/BGIOBJ.EXE
Normal file
Binary file not shown.
32
Borland Turbo C v2/BUILD-C0.BAT
Normal file
32
Borland Turbo C v2/BUILD-C0.BAT
Normal file
@ -0,0 +1,32 @@
|
||||
echo off
|
||||
if x%1 == xTINY goto ok
|
||||
if x%1 == xSMALL goto ok
|
||||
if x%1 == xCOMPACT goto ok
|
||||
if x%1 == xMEDIUM goto ok
|
||||
if x%1 == xLARGE goto ok
|
||||
if x%1 == xHUGE goto ok
|
||||
echo BUILD-C0 must have argument: TINY, SMALL, COMPACT, MEDIUM, LARGE or HUGE
|
||||
goto done
|
||||
:ok
|
||||
echo on
|
||||
goto make-%1
|
||||
:make-TINY
|
||||
TASM C0,C0T /D__TINY__ /MX;
|
||||
goto done
|
||||
:make-SMALL
|
||||
TASM C0,C0S /D__SMALL__ /MX;
|
||||
goto done
|
||||
:make-COMPACT
|
||||
TASM C0,C0C /D__COMPACT__ /MX;
|
||||
goto done
|
||||
:make-MEDIUM
|
||||
TASM C0,C0M /D__MEDIUM__ /MX;
|
||||
goto done
|
||||
:make-LARGE
|
||||
TASM C0,C0L /D__LARGE__ /MX;
|
||||
goto done
|
||||
:make-HUGE
|
||||
TASM C0,C0H /D__HUGE__ /MX;
|
||||
echo on
|
||||
:done
|
||||
|
671
Borland Turbo C v2/C0.ASM
Normal file
671
Borland Turbo C v2/C0.ASM
Normal file
@ -0,0 +1,671 @@
|
||||
NAME c0
|
||||
PAGE 60,132
|
||||
;[]------------------------------------------------------------[]
|
||||
;| C0.ASM -- Start Up Code |
|
||||
;| |
|
||||
;| Turbo-C Run Time Library version 2.0 |
|
||||
;| |
|
||||
;| Copyright (c) 1988 by Borland International Inc. |
|
||||
;| All Rights Reserved. |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
INCLUDE RULES.ASI
|
||||
|
||||
_Strict87_ equ false ; emulation skips peculiar details
|
||||
|
||||
; Segment and Group declarations
|
||||
|
||||
_TEXT SEGMENT BYTE PUBLIC 'CODE'
|
||||
_TEXT ENDS
|
||||
_DATA SEGMENT PARA PUBLIC 'DATA'
|
||||
_DATA ENDS
|
||||
IFNDEF __NOFLOAT__
|
||||
_EMUSEG SEGMENT WORD COMMON 'DATA'
|
||||
_EMUSEG ENDS
|
||||
ENDIF
|
||||
_CRTSEG SEGMENT WORD COMMON 'DATA'
|
||||
_CRTSEG ENDS
|
||||
_CVTSEG SEGMENT WORD PUBLIC 'DATA'
|
||||
_CVTSEG ENDS
|
||||
_SCNSEG SEGMENT WORD PUBLIC 'DATA'
|
||||
_SCNSEG ENDS
|
||||
IFNDEF __HUGE__
|
||||
_BSS SEGMENT WORD PUBLIC 'BSS'
|
||||
_BSS ENDS
|
||||
_BSSEND SEGMENT BYTE PUBLIC 'STACK'
|
||||
_BSSEND ENDS
|
||||
ENDIF
|
||||
IFNDEF __TINY__
|
||||
_STACK SEGMENT STACK 'STACK'
|
||||
_STACK ENDS
|
||||
ENDIF
|
||||
|
||||
IFNDEF __NOFLOAT__
|
||||
|
||||
IF LDATA
|
||||
IFNDEF __HUGE__
|
||||
DGROUP GROUP _DATA, _EMUSEG, _CRTSEG, _CVTSEG, _SCNSEG, _BSS, _BSSEND
|
||||
ELSE
|
||||
DGROUP GROUP _DATA, _EMUSEG, _CRTSEG, _CVTSEG, _SCNSEG
|
||||
ENDIF
|
||||
ELSE
|
||||
IFNDEF __TINY__
|
||||
DGROUP GROUP _DATA, _EMUSEG, _CRTSEG, _CVTSEG, _SCNSEG, _BSS, _BSSEND
|
||||
ELSE
|
||||
DGROUP GROUP _TEXT, _DATA, _EMUSEG, _CRTSEG, _CVTSEG, _SCNSEG, _BSS, _BSSEND
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
ELSE
|
||||
|
||||
IF LDATA
|
||||
IFNDEF __HUGE__
|
||||
DGROUP GROUP _DATA, _CRTSEG, _CVTSEG, _SCNSEG, _BSS, _BSSEND
|
||||
ELSE
|
||||
DGROUP GROUP _DATA, _CRTSEG, _CVTSEG, _SCNSEG
|
||||
ENDIF
|
||||
ELSE
|
||||
IFNDEF __TINY__
|
||||
DGROUP GROUP _DATA, _CRTSEG, _CVTSEG, _SCNSEG, _BSS, _BSSEND
|
||||
ELSE
|
||||
DGROUP GROUP _TEXT, _DATA, _CRTSEG, _CVTSEG, _SCNSEG, _BSS, _BSSEND
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
ENDIF
|
||||
|
||||
ASSUME CS:_TEXT, DS:DGROUP
|
||||
|
||||
; External References
|
||||
|
||||
ExtProc@ main, __CDECL__
|
||||
ExtProc@ _setargv, __CDECL__
|
||||
ExtProc@ _setenvp, __CDECL__
|
||||
ExtProc@ exit, __CDECL__
|
||||
|
||||
IF LDATA EQ false
|
||||
ExtSym@ _heaplen, WORD, __CDECL__
|
||||
ENDIF
|
||||
ExtSym@ _stklen, WORD, __CDECL__
|
||||
|
||||
SUBTTL Start Up Code
|
||||
PAGE
|
||||
;/* */
|
||||
;/*-----------------------------------------------------*/
|
||||
;/* */
|
||||
;/* Start Up Code */
|
||||
;/* ------------- */
|
||||
;/* */
|
||||
;/*-----------------------------------------------------*/
|
||||
;/* */
|
||||
PSPHigh equ 00002h
|
||||
PSPEnv equ 0002ch
|
||||
PSPCmd equ 00080h
|
||||
|
||||
IFDEF __NOFLOAT__
|
||||
MINSTACK equ 128 ; minimal stack size in words
|
||||
ELSE
|
||||
MINSTACK equ 256 ; minimal stack size in words
|
||||
ENDIF
|
||||
;
|
||||
; At the start, DS and ES both point to the segment prefix.
|
||||
; SS points to the stack segment except in TINY model where
|
||||
; SS is equal to CS
|
||||
;
|
||||
_TEXT SEGMENT
|
||||
IFDEF __TINY__
|
||||
ORG 100h
|
||||
ENDIF
|
||||
STARTX PROC NEAR
|
||||
; Save general information, such as :
|
||||
; DGROUP segment address
|
||||
; DOS version number
|
||||
; Program Segment Prefix address
|
||||
; Environment address
|
||||
; Top of far heap
|
||||
|
||||
IFDEF __TINY__
|
||||
mov dx, cs ; DX = GROUP Segment address
|
||||
ELSE
|
||||
mov dx, DGROUP ; DX = GROUP Segment address
|
||||
ENDIF
|
||||
mov cs:DGROUP@@, dx
|
||||
mov ah, 30h
|
||||
int 21h
|
||||
mov bp, ds:[PSPHigh]; BP = Highest Memory Segment Addr
|
||||
mov bx, ds:[PSPEnv] ; BX = Environment Segment address
|
||||
mov ds, dx
|
||||
mov _version@, ax ; Keep major and minor version number
|
||||
mov _psp@, es ; Keep Program Segment Prefix address
|
||||
mov _envseg@, bx ; Keep Environment Segment address
|
||||
mov word ptr _heaptop@ + 2, bp
|
||||
mov _8087@, -1
|
||||
;
|
||||
; Save several vectors and install default divide by zero handler.
|
||||
;
|
||||
call SaveVectors
|
||||
|
||||
; Look for a '87' environment variable, and use this loop to
|
||||
; count the number of environment variables and to compute the
|
||||
; environment size.
|
||||
; Each variable is ended by a 0 and a zero-length variable stops
|
||||
; the environment. The environment can NOT be greater than 32k.
|
||||
|
||||
les di, dword ptr _envLng@
|
||||
mov ax, di
|
||||
mov bx, ax
|
||||
mov cx, 07FFFh ; Environment cannot be > 32 Kbytes
|
||||
IsIt87Var label near
|
||||
cmp word ptr es:[di], '78'
|
||||
jne GetVarLng
|
||||
mov dx, es:[di+2]
|
||||
cmp dl, '='
|
||||
jne GetVarLng
|
||||
and dh, not ' '
|
||||
inc _8087@
|
||||
cmp dh, 'Y'
|
||||
jne GetVarLng
|
||||
inc _8087@
|
||||
GetVarLng label near
|
||||
repnz scasb
|
||||
jcxz InitFailed ; Bad environment !!!
|
||||
inc bx ; BX = Nb environment variables
|
||||
cmp es:[di], al
|
||||
jne IsIt87Var ; Next variable ...
|
||||
or ch, 10000000b
|
||||
neg cx
|
||||
mov _envLng@, cx ; Save Environment size
|
||||
mov cx, dPtrSize / 2
|
||||
shl bx, cl
|
||||
add bx, dPtrSize * 4
|
||||
and bx, not ((dPtrSize * 4) - 1)
|
||||
mov _envSize@, bx ; Save Environment Variables Nb.
|
||||
|
||||
; Determine the amount of memory that we need to keep
|
||||
|
||||
IF LDATA
|
||||
mov dx, ss
|
||||
sub bp, dx ; BP = remaining size in paragraphs
|
||||
IFDEF __HUGE__
|
||||
mov di, seg _stklen@
|
||||
mov es, di
|
||||
mov di, es:_stklen@ ; DI = Requested stack size
|
||||
ELSE
|
||||
mov di, _stklen@ ; DI = Requested stack size
|
||||
ENDIF
|
||||
;
|
||||
; Make sure that the requested stack size is at least MINSTACK words.
|
||||
;
|
||||
cmp di, 2*MINSTACK ; requested stack big enough ?
|
||||
jae AskedStackOK
|
||||
mov di, 2*MINSTACK ; no --> use minimal value
|
||||
IFDEF __HUGE__
|
||||
mov es:_stklen@, di ; override requested stack size
|
||||
ELSE
|
||||
mov _stklen@, di ; override requested stack size
|
||||
ENDIF
|
||||
AskedStackOK label near
|
||||
mov cl, 4
|
||||
shr di, cl ; $$$ Do not destroy CL $$$
|
||||
inc di ; DI = Stack size in paragraphs
|
||||
cmp bp, di
|
||||
jnb ExcessOfMemory ; Much more available than needed
|
||||
ELSE
|
||||
mov dx, ds
|
||||
sub bp, dx ; BP = remaining size in paragraphs
|
||||
mov di, _stklen@ ; DI = Requested stack size
|
||||
;
|
||||
; Make sure that the requested stack size is at least MINSTACK words.
|
||||
;
|
||||
cmp di, 2*MINSTACK ; requested stack big enough ?
|
||||
jae AskedStackOK
|
||||
mov di, 2*MINSTACK ; no --> use minimal value
|
||||
mov _stklen@, di ; override requested stack size
|
||||
AskedStackOK label near
|
||||
add di, offset DGROUP: edata@
|
||||
jb InitFailed ; DATA segment can NOT be > 64 Kbytes
|
||||
add di, _heaplen@
|
||||
jb InitFailed ; DATA segment can NOT be > 64 Kbytes
|
||||
mov cl, 4
|
||||
shr di, cl ; $$$ Do not destroy CL $$$
|
||||
inc di ; DI = DS size in paragraphs
|
||||
cmp bp, di
|
||||
jb InitFailed ; Not enough memory
|
||||
cmp _stklen@, 0
|
||||
je ExpandDS ; Expand DS up to 64 Kb
|
||||
cmp _heaplen@, 0
|
||||
jne ExcessOfMemory ; Much more available than needed
|
||||
ExpandDS label near
|
||||
mov di, 1000h
|
||||
cmp bp, di
|
||||
ja ExcessOfMemory ; Enough to run the program
|
||||
mov di, bp
|
||||
jmp short ExcessOfMemory ; Enough to run the program
|
||||
ENDIF
|
||||
|
||||
; All initialization errors arrive here
|
||||
|
||||
InitFailed label near
|
||||
jmp near ptr abort@
|
||||
|
||||
; Return to DOS the amount of memory in excess
|
||||
; Set far heap base and pointer
|
||||
|
||||
ExcessOfMemory label near
|
||||
mov bx, di
|
||||
add bx, dx
|
||||
mov word ptr _heapbase@ + 2, bx
|
||||
mov word ptr _brklvl@ + 2, bx
|
||||
mov ax, _psp@
|
||||
sub bx, ax ; BX = Number of paragraphs to keep
|
||||
mov es, ax ; ES = Program Segment Prefix address
|
||||
mov ah, 04Ah
|
||||
push di ; preserve DI
|
||||
int 021h ; this call clobbers SI,DI,BP !!!!!!
|
||||
pop di ; restore DI
|
||||
;
|
||||
; Set the program stack. Take care to prevent the disastrous
|
||||
; interrupt that could happen with a stack that is half switched.
|
||||
;
|
||||
shl di, cl ; $$$ CX is still equal to 4 $$$
|
||||
|
||||
cli
|
||||
mov ss, dx
|
||||
mov sp, di
|
||||
sti
|
||||
|
||||
IFNDEF __HUGE__
|
||||
|
||||
; Reset uninitialized data area
|
||||
|
||||
xor ax, ax
|
||||
mov es, cs:DGROUP@@
|
||||
mov di, offset DGROUP: bdata@
|
||||
mov cx, offset DGROUP: edata@
|
||||
sub cx, di
|
||||
rep stosb
|
||||
ENDIF
|
||||
|
||||
IFNDEF __NOFLOAT__
|
||||
|
||||
; Install floating point software
|
||||
|
||||
push cs ;Simulation of a FAR call
|
||||
call ds:[__emu1st]
|
||||
ENDIF
|
||||
|
||||
; Prepare main arguments
|
||||
|
||||
call _setargv@
|
||||
call _setenvp@
|
||||
|
||||
mov ah, 0
|
||||
int 1ah ; get current BIOS time in ticks
|
||||
mov word ptr _StartTime@,dx ; save it for clock() fn
|
||||
mov word ptr _StartTime@+2,cx
|
||||
|
||||
IFNDEF __OLDCONIO__
|
||||
IF LPROG
|
||||
push cs ; Simulation of a FAR call
|
||||
ENDIF
|
||||
call ds:[__crt1st] ; Initialize window sizes, etc.
|
||||
ENDIF
|
||||
|
||||
; ExitCode = main(argc,argv,envp);
|
||||
|
||||
IF LDATA
|
||||
push word ptr environ@+2
|
||||
push word ptr environ@
|
||||
push word ptr _argv@+2
|
||||
push word ptr _argv@
|
||||
ELSE
|
||||
push word ptr environ@
|
||||
push word ptr _argv@
|
||||
ENDIF
|
||||
push _argc@
|
||||
call main@
|
||||
|
||||
; Flush and close streams and files
|
||||
|
||||
push ax
|
||||
call exit@
|
||||
|
||||
;---------------------------------------------------------------------------
|
||||
; _exit()
|
||||
;
|
||||
; Restore interrupt vectors taken during startup. signal() functions
|
||||
; could have grabbed vectors 0, 4, 5 or 6.
|
||||
;
|
||||
; Check for NULL pointer errors.
|
||||
;
|
||||
; Exit to DOS.
|
||||
;
|
||||
;NOTE : _exit() doesn't close any files or run exit functions. This is a
|
||||
; minimal 'cleanup & quit' program exit.
|
||||
;---------------------------------------------------------------------------
|
||||
PubProc@ _exit, __CDECL__
|
||||
mov ds, cs:DGROUP@@
|
||||
|
||||
IF LPROG
|
||||
call far ptr _restorezero@ ; restore captured INT vectors
|
||||
ELSE
|
||||
call near ptr _restorezero@
|
||||
ENDIF
|
||||
|
||||
IFNDEF __NOFLOAT__
|
||||
|
||||
; Restore interrupt vectors taken by __emu1st
|
||||
|
||||
push cs ;Simulation of a FAR call
|
||||
call ds:[__emuLast]
|
||||
ENDIF
|
||||
|
||||
IF LDATA EQ false
|
||||
IFNDEF __TINY__
|
||||
|
||||
; Check for null pointers before exit
|
||||
|
||||
xor ax, ax
|
||||
mov si, ax
|
||||
mov cx, lgth_CopyRight
|
||||
cld
|
||||
ComputeChecksum label near
|
||||
add al, [si]
|
||||
adc ah, 0
|
||||
inc si
|
||||
loop ComputeChecksum
|
||||
sub ax, CheckSum
|
||||
jz ExitToDOS
|
||||
mov cx, lgth_NullCheck
|
||||
mov dx, offset DGROUP: NullCheck
|
||||
call ErrorDisplay
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
; Exit to DOS
|
||||
|
||||
ExitToDOS label near
|
||||
mov bp,sp
|
||||
mov ah,4Ch
|
||||
mov al,[bp+cPtrSize]
|
||||
int 21h ; Exit to DOS
|
||||
EndProc@ _exit, __CDECL__
|
||||
STARTX ENDP
|
||||
|
||||
SUBTTL Vector save/restore & default Zero divide routines
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Interrupt Save/Restore routines and default divide by zero |
|
||||
;| handler. |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
ZeroDivision PROC FAR
|
||||
mov cx, lgth_ZeroDivMSG
|
||||
mov dx, offset DGROUP: ZeroDivMSG
|
||||
jmp MsgExit3
|
||||
ZeroDivision ENDP
|
||||
|
||||
;--------------------------------------------------------------------------
|
||||
; savevectors()
|
||||
;
|
||||
; Save vectors for 0, 4, 5 & 6 interrupts. This is for extended
|
||||
; signal()/raise() support as the signal functions can steal these
|
||||
; vectors during runtime.
|
||||
;--------------------------------------------------------------------------
|
||||
SaveVectors PROC NEAR
|
||||
push ds
|
||||
; Save INT 0
|
||||
mov ax, 3500h
|
||||
int 021h
|
||||
mov word ptr _Int0Vector@, bx
|
||||
mov word ptr _Int0Vector@+2, es
|
||||
; Save INT 4
|
||||
mov ax, 3504h
|
||||
int 021h
|
||||
mov word ptr _Int4Vector@, bx
|
||||
mov word ptr _Int4Vector@+2, es
|
||||
; Save INT 5
|
||||
mov ax, 3505h
|
||||
int 021h
|
||||
mov word ptr _Int5Vector@, bx
|
||||
mov word ptr _Int5Vector@+2, es
|
||||
; Save INT 6
|
||||
mov ax, 3506h
|
||||
int 021h
|
||||
mov word ptr _Int6Vector@, bx
|
||||
mov word ptr _Int6Vector@+2, es
|
||||
;
|
||||
; Install default divide by zero handler.
|
||||
;
|
||||
mov ax, 2500h
|
||||
mov dx, cs
|
||||
mov ds, dx
|
||||
mov dx, offset ZeroDivision
|
||||
int 21h
|
||||
|
||||
pop ds
|
||||
ret
|
||||
SaveVectors ENDP
|
||||
|
||||
;--------------------------------------------------------------------------
|
||||
; restorezero() puts back all the vectors that SaveVectors took.
|
||||
;
|
||||
;NOTE : TSRs must BE AWARE that signal() functions which take these
|
||||
; vectors will be deactivated if the keep() function is executed.
|
||||
; If a TSR wants to use the signal functions when it is active it
|
||||
; will have to save/restore these vectors itself when activated and
|
||||
; deactivated.
|
||||
;--------------------------------------------------------------------------
|
||||
PubProc@ _restorezero, __CDECL__
|
||||
|
||||
IFDEF __HUGE__
|
||||
push ds
|
||||
mov ds, cs: DGROUP@@
|
||||
ENDIF
|
||||
push ds
|
||||
mov ax, 2500h
|
||||
lds dx, _Int0Vector@
|
||||
int 21h
|
||||
pop ds
|
||||
|
||||
push ds
|
||||
mov ax, 2504h
|
||||
lds dx, _Int4Vector@
|
||||
int 21h
|
||||
pop ds
|
||||
|
||||
push ds
|
||||
mov ax, 2505h
|
||||
lds dx, _Int5Vector@
|
||||
int 21h
|
||||
pop ds
|
||||
|
||||
IFNDEF __HUGE__
|
||||
push ds
|
||||
ENDIF
|
||||
mov ax, 2506h
|
||||
lds dx, _Int6Vector@
|
||||
int 21h
|
||||
pop ds
|
||||
|
||||
ret
|
||||
EndProc@ _restorezero, __CDECL__
|
||||
|
||||
SUBTTL Miscellaneous
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Miscellaneous functions |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
IFNDEF __NOFLOAT__
|
||||
NoEmulator PROC FAR
|
||||
mov _8087@, 0
|
||||
ret
|
||||
NoEmulator ENDP
|
||||
ENDIF
|
||||
|
||||
IFNDEF __OLDCONIO__
|
||||
Proc@ NoConsole, __CDECL__
|
||||
ret
|
||||
EndProc@ NoConsole, __CDECL__
|
||||
ENDIF
|
||||
|
||||
ErrorDisplay PROC NEAR
|
||||
mov ah, 040h
|
||||
mov bx, 2
|
||||
int 021h
|
||||
ret
|
||||
ErrorDisplay ENDP
|
||||
|
||||
PubProc@ abort, __CDECL__
|
||||
mov cx, lgth_abortMSG
|
||||
mov dx, offset DGROUP: abortMSG
|
||||
MsgExit3 label near
|
||||
mov ds, cs: DGROUP@@
|
||||
call ErrorDisplay
|
||||
CallExit3 label near
|
||||
mov ax, 3
|
||||
push ax
|
||||
call _exit@ ; _exit(3);
|
||||
EndProc@ abort, __CDECL__
|
||||
|
||||
; The DGROUP@ variable is used to reload DS with DGROUP
|
||||
|
||||
PubSym@ DGROUP@, <dw ?>, __PASCAL__
|
||||
_TEXT ENDS
|
||||
|
||||
SUBTTL Start Up Data Area
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| Start Up Data Area |
|
||||
;| |
|
||||
;| WARNING Do not move any variables in the data |
|
||||
;| segment unless you're absolutely sure |
|
||||
;| that it does not matter. |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
_DATA SEGMENT
|
||||
|
||||
; The CopyRight string must NOT be moved or changed without
|
||||
; changing the null pointer check logic
|
||||
|
||||
CopyRight db 4 dup(0)
|
||||
db 'Turbo-C - Copyright (c) 1988 Borland Intl.',0
|
||||
lgth_CopyRight equ $ - CopyRight
|
||||
|
||||
IF LDATA EQ false
|
||||
IFNDEF __TINY__
|
||||
CheckSum equ 00D37h
|
||||
NullCheck db 'Null pointer assignment', 13, 10
|
||||
lgth_NullCheck equ $ - NullCheck
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
ZeroDivMSG db 'Divide error', 13, 10
|
||||
lgth_ZeroDivMSG equ $ - ZeroDivMSG
|
||||
|
||||
abortMSG db 'Abnormal program termination', 13, 10
|
||||
lgth_abortMSG equ $ - abortMSG
|
||||
|
||||
;
|
||||
; Interrupt vector save areas
|
||||
;
|
||||
; Interrupt vectors 0,4,5 & 6 are saved at startup and then restored
|
||||
; when the program terminates. The signal/raise functions might
|
||||
; steal these vectors during execution.
|
||||
;
|
||||
PubSym@ _Int0Vector <dd 0>, __CDECL__
|
||||
PubSym@ _Int4Vector <dd 0>, __CDECL__
|
||||
PubSym@ _Int5Vector <dd 0>, __CDECL__
|
||||
PubSym@ _Int6Vector <dd 0>, __CDECL__
|
||||
;
|
||||
; Miscellaneous variables
|
||||
;
|
||||
PubSym@ _argc, <dw 0>, __CDECL__
|
||||
dPtrPub@ _argv, 0, __CDECL__
|
||||
dPtrPub@ environ, 0, __CDECL__
|
||||
PubSym@ _envLng, <dw 0>, __CDECL__
|
||||
PubSym@ _envseg, <dw 0>, __CDECL__
|
||||
PubSym@ _envSize, <dw 0>, __CDECL__
|
||||
PubSym@ _psp, <dw 0>, __CDECL__
|
||||
PubSym@ _version, <label word>, __CDECL__
|
||||
PubSym@ _osmajor, <db 0>, __CDECL__
|
||||
PubSym@ _osminor, <db 0>, __CDECL__
|
||||
PubSym@ errno, <dw 0>, __CDECL__
|
||||
PubSym@ _8087, <dw 0>, __CDECL__
|
||||
PubSym@ _StartTime, <dw 0,0>, __CDECL__
|
||||
|
||||
|
||||
; Memory management variables
|
||||
|
||||
IF LDATA EQ false
|
||||
PubSym@ __heapbase, <dw DGROUP:edata@>, __CDECL__
|
||||
PubSym@ __brklvl, <dw DGROUP:edata@>, __CDECL__
|
||||
PubSym@ __heaptop, <dw DGROUP:edata@>, __CDECL__
|
||||
ENDIF
|
||||
PubSym@ _heapbase, <dd 0>, __CDECL__
|
||||
PubSym@ _brklvl, <dd 0>, __CDECL__
|
||||
PubSym@ _heaptop, <dd 0>, __CDECL__
|
||||
|
||||
IF LDATA EQ false
|
||||
IFNDEF __NOFLOAT__
|
||||
; Emulator variables
|
||||
INCLUDE emuvars.asi
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
_DATA ENDS
|
||||
|
||||
IFNDEF __NOFLOAT__
|
||||
_EMUSEG SEGMENT
|
||||
__emu1st dw NoEmulator
|
||||
__emuLast dw NoEmulator
|
||||
_EMUSEG ENDS
|
||||
ENDIF
|
||||
|
||||
IFNDEF __OLDCONIO__
|
||||
_CRTSEG SEGMENT
|
||||
__crt1st dw NoConsole@
|
||||
_CRTSEG ENDS
|
||||
ENDIF
|
||||
|
||||
_CVTSEG SEGMENT
|
||||
PubSym@ _RealCvtVector, <label word>, __CDECL__
|
||||
_CVTSEG ENDS
|
||||
|
||||
_SCNSEG SEGMENT
|
||||
PubSym@ _ScanTodVector, <label word>, __CDECL__
|
||||
_SCNSEG ENDS
|
||||
|
||||
IFNDEF __HUGE__
|
||||
_BSS SEGMENT
|
||||
bdata@ label byte
|
||||
_BSS ENDS
|
||||
|
||||
_BSSEND SEGMENT
|
||||
edata@ label byte
|
||||
_BSSEND ENDS
|
||||
ENDIF
|
||||
|
||||
IFNDEF __TINY__
|
||||
_STACK SEGMENT
|
||||
dw 64 dup (?)
|
||||
IF LDATA
|
||||
org 0
|
||||
IFNDEF __NOFLOAT__
|
||||
; Emulator variables
|
||||
INCLUDE emuvars.asi
|
||||
even
|
||||
ENDIF
|
||||
PUBLIC emuTop@ ; for use in stack-underflow checks.
|
||||
emuTop@ label byte
|
||||
ENDIF
|
||||
_STACK ENDS
|
||||
ENDIF
|
||||
END STARTX
|
||||
|
130
Borland Turbo C v2/CBAR.C
Normal file
130
Borland Turbo C v2/CBAR.C
Normal file
@ -0,0 +1,130 @@
|
||||
/* CBAR.C
|
||||
|
||||
Sample program for interfacing Turbo C with Turbo Prolog
|
||||
|
||||
Copyright (c) Borland International 1987,88
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include <dos.h>
|
||||
|
||||
videodot(int x, int y, int color)
|
||||
{
|
||||
union REGS inr,outr;
|
||||
|
||||
inr.h.ah = 12; /* write pixel */
|
||||
inr.h.al = color;
|
||||
inr.x.cx = x;
|
||||
inr.x.dx = y;
|
||||
_int86(16,&inr,&outr); /* call video intr */
|
||||
}
|
||||
|
||||
/* Draws a line on the screen from (x1, y1) to (x2, y2) in a selected color */
|
||||
line(int x1, int y1, int x2, int y2, int color)
|
||||
{
|
||||
int xdelta; /* The change in x coordinates */
|
||||
int ydelta; /* The change in y coordinates */
|
||||
int xstep; /* The change to make in the x coordinate in each step */
|
||||
int ystep; /* The change to make in the y coordinate in each step */
|
||||
int change; /* The amount that the x or y coordinate has changed */
|
||||
|
||||
xdelta = x2 - x1; /* Calculate the change in x coordinates */
|
||||
ydelta = y2 - y1; /* Calculate the change in y coordinates */
|
||||
if (xdelta < 0)
|
||||
{ /* The line will be drawn from right to left */
|
||||
xdelta = -xdelta;
|
||||
xstep = -1;
|
||||
}
|
||||
else /* The line will be drawn from left to right */
|
||||
xstep = 1;
|
||||
if (ydelta < 0)
|
||||
{ /* The line will be drawn from bottom to top */
|
||||
ydelta = -ydelta;
|
||||
ystep = -1;
|
||||
}
|
||||
else /* The line will be drawn from top to bottom */
|
||||
ystep = 1;
|
||||
if (xdelta > ydelta) /* x changes quicker than y */
|
||||
{
|
||||
change = xdelta >> 1; /* change set to twice the value of xdelta */
|
||||
while (x1 != x2) /* Draw until the terminating dot is reached */
|
||||
{
|
||||
videodot(x1, y1, color); /* Draw a dot on the screen */
|
||||
x1 += xstep; /* Update x coordinate */
|
||||
change += ydelta; /* Update change */
|
||||
if (change > xdelta)
|
||||
{
|
||||
y1 += ystep; /* Update the y coordinate */
|
||||
change -= xdelta; /* Reset change */
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* y changes quicker than x */
|
||||
{
|
||||
change = ydelta >> 1; /* change set to twice the value of ydelta */
|
||||
while (y1 != y2) /* Draw until the terminating dot is reached */
|
||||
{
|
||||
videodot(x1, y1, color); /* Draw a dot on the screen */
|
||||
y1 += ystep; /* Update y coordinate */
|
||||
change += xdelta; /* Update change */
|
||||
if (change > ydelta)
|
||||
/* If change is large enough to update the x coordinate */
|
||||
{
|
||||
x1 += xstep; /* Update the x coordinate */
|
||||
change -= ydelta; /* Reset change */
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* line */
|
||||
|
||||
cbar_0(int x1, int y1, int width, int height, int color)
|
||||
{
|
||||
int count; /* Counter variable used in filling bar */
|
||||
int x2, y2, x3, y3, x4, y4; /* Additional points on the bar */
|
||||
int wfactor; /* The number of pixels to shift the bar to the right */
|
||||
int hfactor; /* The number of pixels to shift the bar up */
|
||||
/*
|
||||
|
||||
The x and y values are as follows:
|
||||
|
||||
x1 x2 x3 x4
|
||||
| | | |
|
||||
| v | v
|
||||
y2--|>/ÚÄÄÄÄ|ÄÄ¿
|
||||
v/ ³ v /³
|
||||
y1->ÉÍÍÍÍÍÍÍ»/ ³
|
||||
º ³ º ³
|
||||
º ³ º ³
|
||||
º ³ º ³
|
||||
º ³ º ³
|
||||
º ³ º ³
|
||||
y3---->ÀÄÄÄĺÄÄÙ
|
||||
º / º /
|
||||
y4->ÈÍÍÍÍÍÍͼ/
|
||||
|
||||
*/
|
||||
|
||||
wfactor = width / 5; /* figure out wfactor and hfactor */
|
||||
hfactor = height / 12;
|
||||
x2 = x1 + wfactor; /* compute the location of the points on the bar */
|
||||
x3 = x1 + width;
|
||||
x4 = x3 + wfactor;
|
||||
y2 = y1 - hfactor;
|
||||
y3 = y1 + height - hfactor;
|
||||
y4 = y1 + height;
|
||||
line(x1, y1, x3, y1, 2); /* draw front of the bar */
|
||||
line(x3, y1, x3, y4, 2);
|
||||
line(x3, y4, x1, y4, 2);
|
||||
line(x1, y4, x1, y1, 2);
|
||||
line(x3, y1, x4, y2, 2); /* draw side of the bar */
|
||||
line(x4, y2, x4, y3, 2);
|
||||
line(x4, y3, x3, y4, 2);
|
||||
line(x1, y1, x2, y2, 2); /* draw top of the bar */
|
||||
line(x2, y2, x4, y2, 2);
|
||||
line(x1, y4, x2, y3, 3);
|
||||
line(x2, y3, x4, y3, 3); /* draw back of the bar */
|
||||
line(x2, y3, x2, y2, 3);
|
||||
for (count = y1 + 1; count < y4; count++) /* fill in the bar */
|
||||
line(x1 + 1, count, x3, count, color);
|
||||
} /* cbar_0 */
|
||||
|
BIN
Borland Turbo C v2/CGA.BGI
Normal file
BIN
Borland Turbo C v2/CGA.BGI
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/CINSTXFR.EXE
Normal file
BIN
Borland Turbo C v2/CINSTXFR.EXE
Normal file
Binary file not shown.
75
Borland Turbo C v2/CPASDEMO.C
Normal file
75
Borland Turbo C v2/CPASDEMO.C
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
/* Copyright (c) 1987,88 by Borland International, Inc.
|
||||
|
||||
This module demonstrates how to write Turbo C routines that
|
||||
can be linked into a Turbo Pascal program. Routines in this
|
||||
module call Turbo Pascal routines in CPASDEMO.PAS.
|
||||
|
||||
See the instructions in the file CPASDEMO.PAS on running
|
||||
this demonstration program */
|
||||
|
||||
typedef unsigned int word;
|
||||
typedef unsigned char byte;
|
||||
typedef unsigned long longword;
|
||||
|
||||
extern void setcolor(byte newcolor); /* procedure defined in
|
||||
Turbo Pascal program */
|
||||
extern word factor; /* variable declared in Turbo Pascal program */
|
||||
|
||||
word sqr(int i)
|
||||
{
|
||||
setcolor(1);
|
||||
return(i * i);
|
||||
} /* sqr */
|
||||
|
||||
word hibits(word w)
|
||||
{
|
||||
setcolor(2);
|
||||
return(w >> 8);
|
||||
} /* hibits */
|
||||
|
||||
byte suc(byte b)
|
||||
{
|
||||
setcolor(3);
|
||||
return(++b);
|
||||
} /* suc */
|
||||
|
||||
byte upr(byte c)
|
||||
{
|
||||
setcolor(4);
|
||||
return((c >= 'a') && (c <= 'z') ? c - 32 : c);
|
||||
} /* upr */
|
||||
|
||||
char prd(char s)
|
||||
{
|
||||
setcolor(5);
|
||||
return(--s);
|
||||
} /* prd */
|
||||
|
||||
long lobits(long l)
|
||||
{
|
||||
setcolor(6);
|
||||
return((longword)l & 65535L);
|
||||
} /* lobits */
|
||||
|
||||
void strupr(char *s)
|
||||
{
|
||||
int counter;
|
||||
|
||||
for (counter = 1; counter <= s[0]; counter++) /* Note that the routine */
|
||||
s[counter] = upr(s[counter]); /* skips Turbo Pascal's */
|
||||
setcolor(7); /* length byte */
|
||||
} /* strupr */
|
||||
|
||||
byte boolnot(byte b)
|
||||
{
|
||||
setcolor(8);
|
||||
return(b == 0 ? 1 : 0);
|
||||
} /* boolnot */
|
||||
|
||||
word multbyfactor(word w)
|
||||
{
|
||||
setcolor(9); /* note that this function accesses the Turbo Pascal */
|
||||
return(w * factor); /* declared variable factor */
|
||||
} /* multbyfactor */
|
||||
|
126
Borland Turbo C v2/CPASDEMO.PAS
Normal file
126
Borland Turbo C v2/CPASDEMO.PAS
Normal file
@ -0,0 +1,126 @@
|
||||
|
||||
{ Copyright (c) 1987,88 by Borland International, Inc. }
|
||||
|
||||
program CPASDEMO;
|
||||
(*
|
||||
This program demonstrates how to interface Turbo Pascal and Turbo C.
|
||||
Turbo C is used to generate an .OBJ file (CPASDEMO.OBJ). Then
|
||||
this .OBJ is linked into this Turbo Pascal program using the {$L}
|
||||
compiler directive.
|
||||
|
||||
NOTES:
|
||||
1. Data declared in the Turbo C module cannot be accessed from
|
||||
the Turbo Pascal program. Shared data must be declared in
|
||||
Pascal.
|
||||
|
||||
2. If the C functions are only used in the implementation section
|
||||
of a unit, declare them NEAR. If they are declared in the
|
||||
interface section of a unit, declare them FAR. Always compile
|
||||
the Turbo C modules using the small memory model.
|
||||
|
||||
3. Turbo C runtime library routines cannot be used because their
|
||||
modules do not have the correct segment names. However, if you have
|
||||
the Turbo C runtime library source (available from Borland),
|
||||
you can use individual library modules by recompiling
|
||||
them using CTOPAS.BAT. If you do recompile them, make sure
|
||||
that you include prototypes in your C module for all C
|
||||
library functions that you use.
|
||||
|
||||
4. Some of the code that Turbo C generates are calls to internal
|
||||
routines. These cannot be used without recompiling the relevant
|
||||
parts of the Turbo C runtime library source code.
|
||||
|
||||
In order to run this demonstration program you will need the following
|
||||
files:
|
||||
|
||||
TCC.EXE and TURBO.CFG or
|
||||
TC.EXE and CTOPAS.TC
|
||||
|
||||
To run the demonstration program CPASDEMO.EXE do the following:
|
||||
|
||||
1. First create a CPASDEMO.OBJ file compatible with Turbo Pascal 4.0
|
||||
or later using Turbo C.
|
||||
|
||||
a) If you are using the Turbo C integrated environment (TC.EXE)
|
||||
then at the DOS prompt execute:
|
||||
|
||||
TC /CCTOPAS.TC CPASDEMO.C
|
||||
|
||||
then create the .OBJ file by pressing ALT-F9.
|
||||
|
||||
b) If you are using the Turbo C command line version (TCC.EXE)
|
||||
then at the DOS prompt execute:
|
||||
|
||||
TCC CPASDEMO.C
|
||||
|
||||
Note: Use the same configuration file (TURBO.CFG or CTOPAS.TC)
|
||||
when you create your own Turbo C modules for use with
|
||||
Turbo Pascal
|
||||
|
||||
2. Compile and execute the Turbo Pascal program CPASDEMO.PAS
|
||||
|
||||
This simple program calls each of the functions defined in the Turbo C
|
||||
module. Each of the Turbo C functions changes the current display color
|
||||
by calling the Turbo Pascal procedure SetColor. }
|
||||
*)
|
||||
|
||||
uses Crt;
|
||||
|
||||
var
|
||||
Factor : Word;
|
||||
|
||||
{$L CPASDEMO.OBJ} { link in the Turbo C-generated .OBJ module }
|
||||
|
||||
function Sqr(I : Integer) : Word; external;
|
||||
{ Change the text color and return the square of I }
|
||||
|
||||
function HiBits(W : Word) : Word; external;
|
||||
{ Change the text color and return the high byte of W }
|
||||
|
||||
function Suc(B : Byte) : Byte; external;
|
||||
{ Change the text color and return B + 1 }
|
||||
|
||||
function Upr(C : Char) : Char; external;
|
||||
{ Change the text color and return the upper case of C }
|
||||
|
||||
function Prd(S : ShortInt) : ShortInt; external;
|
||||
{ Change the text color and return S - 1 }
|
||||
|
||||
function LoBits(L : LongInt) : LongInt; external;
|
||||
{ Change the text color and return the low word of L }
|
||||
|
||||
procedure StrUpr(var S : string); external;
|
||||
{ Change the text color and return the upper case of S - Note that the Turbo }
|
||||
{ C routine must skip the length byte of the string. }
|
||||
|
||||
function BoolNot(B : Boolean) : Boolean; external;
|
||||
{ Change the text color and return NOT B }
|
||||
|
||||
function MultByFactor(W : Word) : Word; external;
|
||||
{ Change the text color and return W * Factor - note Turbo C's access of }
|
||||
{ Turbo Pascal's global variable. }
|
||||
|
||||
procedure SetColor(NewColor : Byte); { A procedure that changes the current }
|
||||
begin { display color by changing the CRT }
|
||||
TextAttr := NewColor; { variable TextAttr }
|
||||
end; { SetColor }
|
||||
|
||||
var
|
||||
S : string;
|
||||
|
||||
begin
|
||||
Writeln(Sqr(10)); { Call each of the functions defined }
|
||||
Writeln(HiBits(30000)); { passing it the appropriate info. }
|
||||
Writeln(Suc(200));
|
||||
Writeln(Upr('x'));
|
||||
Writeln(Prd(-100));
|
||||
Writeln(LoBits(100000));
|
||||
S := 'abcdefg';
|
||||
StrUpr(S);
|
||||
Writeln(S);
|
||||
Writeln(BoolNot(False));
|
||||
Factor := 100;
|
||||
Writeln(MultbyFactor(10));
|
||||
SetColor(LightGray);
|
||||
end.
|
||||
|
BIN
Borland Turbo C v2/CPP.EXE
Normal file
BIN
Borland Turbo C v2/CPP.EXE
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/CTOPAS.TC
Normal file
BIN
Borland Turbo C v2/CTOPAS.TC
Normal file
Binary file not shown.
35
Borland Turbo C v2/E.C
Normal file
35
Borland Turbo C v2/E.C
Normal file
@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef MWC
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define DIGITS_TO_FIND 200 /*9009*/
|
||||
|
||||
int main() {
|
||||
|
||||
int N = DIGITS_TO_FIND;
|
||||
int x = 0;
|
||||
int a[ DIGITS_TO_FIND ];
|
||||
int n;
|
||||
|
||||
for (n = N - 1; n > 0; --n) {
|
||||
a[n] = 1;
|
||||
}
|
||||
|
||||
a[1] = 2, a[0] = 0;
|
||||
while (N > 9) {
|
||||
n = N--;
|
||||
while (--n) {
|
||||
a[n] = x % n;
|
||||
|
||||
x = 10 * a[n-1] + x/n;
|
||||
}
|
||||
printf("%d", x);
|
||||
}
|
||||
|
||||
printf( "\ndone\n" );
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Borland Turbo C v2/EGAVGA.BGI
Normal file
BIN
Borland Turbo C v2/EGAVGA.BGI
Normal file
Binary file not shown.
158
Borland Turbo C v2/EMUVARS.ASI
Normal file
158
Borland Turbo C v2/EMUVARS.ASI
Normal file
@ -0,0 +1,158 @@
|
||||
; emuVars.asi last modified :- 13 Jul 88
|
||||
|
||||
; Turbo-C Run Time Library version 2.0
|
||||
|
||||
; Copyright (c) 1986,87,88 by Borland International Inc.
|
||||
; All Rights Reserved.
|
||||
|
||||
; This file is designed to be included both by the start-up
|
||||
; module (C0.asm, for TC) and by the emulator. The data is
|
||||
; actually allocated in startup, and externally referenced
|
||||
; from the emulator.
|
||||
|
||||
; 4/15/88 ah:
|
||||
; Modified for Turbo Pascal using _Pascal_ conditional.
|
||||
; 7/13/88 rss:
|
||||
; Data initialization removed, moved to emualor FINIT code.
|
||||
; Added Safety Stamp so debugger can detect emulator.
|
||||
|
||||
IFNDEF _Pascal_ ; if Turbo C version
|
||||
|
||||
IFNDEF _InsideEmu87_
|
||||
PUBLIC emws_limitSP, emws_initialSP,
|
||||
PUBLIC emws_saveVector,emws_nmiVector
|
||||
PUBLIC emws_status, emws_control, emws_TOS, emws_adjust
|
||||
PUBLIC emws_fixSeg, emws_BPsafe
|
||||
PUBLIC emws_stamp, emws_version
|
||||
|
||||
IF _Strict87_
|
||||
PUBLIC emws_instrnPtr, emws_dataPtr, emws_instruction
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
; The Use of Interrupt Vectors
|
||||
|
||||
; There are 11 interrupt vectors. The first 8 map onto the 8 floating
|
||||
; point instruction patterns:
|
||||
|
||||
; {WAIT ESC n } --> INT (34h + n), where n is in (0..7)
|
||||
|
||||
; No segment prefixes may apply to these patterns.
|
||||
|
||||
; The ninth interrupt provides instructions with segment prefixes:
|
||||
|
||||
; {WAIT ES: ESC n } --> INT (3Ch), byte (C0h + n)
|
||||
; {WAIT CS: ESC n } --> INT (3Ch), byte (80h + n)
|
||||
; {WAIT SS: ESC n } --> INT (3Ch), byte (40h + n)
|
||||
; {WAIT DS: ESC n } --> INT (3Ch), byte (00h + n)
|
||||
|
||||
|
||||
; The tenth interrupt corresponds to the sequence NOP, FWAIT, and
|
||||
; is a no-op for emulation purposes.
|
||||
|
||||
; The eleventh interrupt provides Borland-defined shortcuts.
|
||||
|
||||
|
||||
|
||||
; Data space is actually allocated in the stack segment by C0.asm,
|
||||
; the start-up module, and accessed by the emulator via externs.
|
||||
; It is initialized during the first emulated FINIT instruction.
|
||||
|
||||
IFNDEF _InsideEmu87_ ; if we are building C0.obj
|
||||
|
||||
; Allocate a set of 8 iNDP registers, plus extras for workspace
|
||||
|
||||
emws_limitSP label word
|
||||
|
||||
db (16 * 12) DUP (?)
|
||||
|
||||
emws_initialSP label word
|
||||
|
||||
; Append a spare for underflow situations.
|
||||
|
||||
dw 6 dup (?)
|
||||
|
||||
|
||||
emws_saveVector dd ? ; prior contents of NMI vector
|
||||
emws_nmiVector dd ? ; PC/AT error vector for 80287 exceptions
|
||||
|
||||
emws_status dw ? ; result of comparisons
|
||||
emws_control dw ? ; processing options and exceptions.
|
||||
|
||||
emws_TOS dw ? ; current level of e87 register stack
|
||||
emws_adjust dw ? ; adjusts TOS at exit
|
||||
|
||||
emws_fixSeg dw ? ; selector implied by segFix
|
||||
emws_BPsafe dw ? ; keep BP --> userRegs here for safety.
|
||||
emws_stamp dd ? ; after initialization, 'emu', 87h
|
||||
emws_version dw ? ; 1 for TC2, TP5; 2 for TB2
|
||||
|
||||
IF _Strict87_
|
||||
emws_instrnPtr dd ? ; used with error recovery
|
||||
emws_dataPtr dd ? ; --------- " ------------
|
||||
emws_instruction dw ? ; bytes swapped, used for error recovery
|
||||
ENDIF
|
||||
|
||||
ELSE ; _InsideEmu87_, we are building the emulator
|
||||
|
||||
EXTRN emws_limitSP : WORD
|
||||
EXTRN emws_initialSP : WORD
|
||||
EXTRN emws_saveVector : DWORD
|
||||
EXTRN emws_nmiVector : DWORD
|
||||
EXTRN emws_status : WORD
|
||||
EXTRN emws_control : WORD
|
||||
EXTRN emws_TOS : WORD
|
||||
EXTRN emws_adjust : WORD
|
||||
EXTRN emws_fixSeg : WORD
|
||||
EXTRN emws_BPsafe : WORD
|
||||
EXTRN emws_stamp : DWORD
|
||||
EXTRN emws_version : WORD
|
||||
|
||||
IF _Strict87_
|
||||
EXTRN emws_instrnPtr : DWORD
|
||||
EXTRN emws_dataPtr : DWORD
|
||||
EXTRN emws_instruction: DWORD
|
||||
ENDIF
|
||||
|
||||
EmuAssume@ MACRO aSeg
|
||||
ASSUME aSeg : SEG emws_TOS
|
||||
ENDM
|
||||
EmuNothing@ MACRO aSeg
|
||||
ASSUME aSeg : NOTHING
|
||||
ENDM
|
||||
ENDIF
|
||||
|
||||
ELSE ; _Pascal_, Turbo Pascal version
|
||||
|
||||
; Turbo Pascal's linker does not allow explicit references to the
|
||||
; stack segment, so instead of the above PUBLICs and EXTRNs we
|
||||
; define the following equates for the emulators variables. These
|
||||
; declarations cause the assembler to use DS as the default segment
|
||||
; register, so an SS: override MUST be coded in places where DS is
|
||||
; not yet set up.
|
||||
|
||||
; Note: The Turbo Pascal runtime library assumes that an FINIT will
|
||||
; correctly initialize all emulator variables. Turbo Pascal never
|
||||
; initializes them, nor does it ever directly reference any of them.
|
||||
|
||||
emws_limitSP equ (word ptr DS: 0)
|
||||
emws_initialSP equ (word ptr DS: 192)
|
||||
emws_saveVector equ (dword ptr DS: 204)
|
||||
emws_nmiVector equ (dword ptr DS: 208)
|
||||
emws_status equ (word ptr DS: 212)
|
||||
emws_control equ (word ptr DS: 214)
|
||||
emws_TOS equ (word ptr DS: 216)
|
||||
emws_adjust equ (word ptr DS: 218)
|
||||
emws_fixSeg equ (word ptr DS: 220)
|
||||
emws_BPsafe equ (word ptr DS: 222)
|
||||
emws_stamp equ (word ptr DS: 224)
|
||||
emws_version equ (word ptr DS: 228)
|
||||
|
||||
EmuAssume@ MACRO aSeg
|
||||
ASSUME aSeg : NOTHING
|
||||
ENDM
|
||||
EmuNothing@ MACRO aSeg
|
||||
ASSUME aSeg : NOTHING
|
||||
ENDM
|
||||
|
||||
ENDIF
|
136
Borland Turbo C v2/GETOPT.C
Normal file
136
Borland Turbo C v2/GETOPT.C
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
getopt.c -- Turbo C
|
||||
|
||||
Copyright (c) 1986,87,88 by Borland International Inc.
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <dos.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int optind = 1; /* index of which argument is next */
|
||||
char *optarg; /* pointer to argument of current option */
|
||||
int opterr = 1; /* allow error message */
|
||||
|
||||
static char *letP = NULL; /* remember next option char's location */
|
||||
static char SW = 0; /* DOS switch character, either '-' or '/' */
|
||||
|
||||
/*
|
||||
Parse the command line options, System V style.
|
||||
|
||||
Standard option syntax is:
|
||||
|
||||
option ::= SW [optLetter]* [argLetter space* argument]
|
||||
|
||||
where
|
||||
- SW is either '/' or '-', according to the current setting
|
||||
of the MSDOS switchar (int 21h function 37h).
|
||||
- there is no space before any optLetter or argLetter.
|
||||
- opt/arg letters are alphabetic, not punctuation characters.
|
||||
- optLetters, if present, must be matched in optionS.
|
||||
- argLetters, if present, are found in optionS followed by ':'.
|
||||
- argument is any white-space delimited string. Note that it
|
||||
can include the SW character.
|
||||
- upper and lower case letters are distinct.
|
||||
|
||||
There may be multiple option clusters on a command line, each
|
||||
beginning with a SW, but all must appear before any non-option
|
||||
arguments (arguments not introduced by SW). Opt/arg letters may
|
||||
be repeated: it is up to the caller to decide if that is an error.
|
||||
|
||||
The character SW appearing alone as the last argument is an error.
|
||||
The lead-in sequence SWSW ("--" or "//") causes itself and all the
|
||||
rest of the line to be ignored (allowing non-options which begin
|
||||
with the switch char).
|
||||
|
||||
The string *optionS allows valid opt/arg letters to be recognized.
|
||||
argLetters are followed with ':'. Getopt () returns the value of
|
||||
the option character found, or EOF if no more options are in the
|
||||
command line. If option is an argLetter then the global optarg is
|
||||
set to point to the argument string (having skipped any white-space).
|
||||
|
||||
The global optind is initially 1 and is always left as the index
|
||||
of the next argument of argv[] which getopt has not taken. Note
|
||||
that if "--" or "//" are used then optind is stepped to the next
|
||||
argument before getopt() returns EOF.
|
||||
|
||||
If an error occurs, that is an SW char precedes an unknown letter,
|
||||
then getopt() will return a '?' character and normally prints an
|
||||
error message via perror(). If the global variable opterr is set
|
||||
to false (zero) before calling getopt() then the error message is
|
||||
not printed.
|
||||
|
||||
For example, if the MSDOS switch char is '/' (the MSDOS norm) and
|
||||
|
||||
*optionS == "A:F:PuU:wXZ:"
|
||||
|
||||
then 'P', 'u', 'w', and 'X' are option letters and 'F', 'U', 'Z'
|
||||
are followed by arguments. A valid command line may be:
|
||||
|
||||
aCommand /uPFPi /X /A L someFile
|
||||
|
||||
where:
|
||||
- 'u' and 'P' will be returned as isolated option letters.
|
||||
- 'F' will return with "Pi" as its argument string.
|
||||
- 'X' is an isolated option.
|
||||
- 'A' will return with "L" as its argument.
|
||||
- "someFile" is not an option, and terminates getOpt. The
|
||||
caller may collect remaining arguments using argv pointers.
|
||||
*/
|
||||
|
||||
int getopt(int argc, char *argv[], char *optionS)
|
||||
{
|
||||
unsigned char ch;
|
||||
char *optP;
|
||||
|
||||
if (SW == 0) {
|
||||
/* get SW using dos call 0x37 */
|
||||
_AX = 0x3700;
|
||||
geninterrupt(0x21);
|
||||
SW = _DL;
|
||||
}
|
||||
|
||||
if (argc > optind) {
|
||||
if (letP == NULL) {
|
||||
if ((letP = argv[optind]) == NULL ||
|
||||
*(letP++) != SW) goto gopEOF;
|
||||
if (*letP == SW) {
|
||||
optind++; goto gopEOF;
|
||||
}
|
||||
}
|
||||
if (0 == (ch = *(letP++))) {
|
||||
optind++; goto gopEOF;
|
||||
}
|
||||
if (':' == ch || (optP = strchr(optionS, ch)) == NULL)
|
||||
goto gopError;
|
||||
if (':' == *(++optP)) {
|
||||
optind++;
|
||||
if (0 == *letP) {
|
||||
if (argc <= optind) goto gopError;
|
||||
letP = argv[optind++];
|
||||
}
|
||||
optarg = letP;
|
||||
letP = NULL;
|
||||
} else {
|
||||
if (0 == *letP) {
|
||||
optind++;
|
||||
letP = NULL;
|
||||
}
|
||||
optarg = NULL;
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
gopEOF:
|
||||
optarg = letP = NULL;
|
||||
return EOF;
|
||||
|
||||
gopError:
|
||||
optarg = NULL;
|
||||
errno = EINVAL;
|
||||
if (opterr)
|
||||
perror ("get command line option");
|
||||
return ('?');
|
||||
}
|
||||
|
BIN
Borland Turbo C v2/GOTH.CHR
Normal file
BIN
Borland Turbo C v2/GOTH.CHR
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/GREP.COM
Normal file
BIN
Borland Turbo C v2/GREP.COM
Normal file
Binary file not shown.
12
Borland Turbo C v2/HELLO.C
Normal file
12
Borland Turbo C v2/HELLO.C
Normal file
@ -0,0 +1,12 @@
|
||||
/* HELLO.C -- Hello, world */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
main()
|
||||
{
|
||||
printf("Hello, world\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
479
Borland Turbo C v2/HELPME!.DOC
Normal file
479
Borland Turbo C v2/HELPME!.DOC
Normal file
@ -0,0 +1,479 @@
|
||||
TURBO C 2.0: ANSWERS TO COMMON QUESTIONS
|
||||
|
||||
|
||||
G e t t i n g S t a r t e d
|
||||
----------------------------------------------------------------------
|
||||
Q. How do I install Turbo C?
|
||||
A. Run the INSTALL program from the INSTALL/HELP disk. To start
|
||||
the installation, change your current drive to the one that
|
||||
has the install program on it and type INSTALL. You will be
|
||||
given instructions in a box at the bottom of the screen for
|
||||
each prompt. For example, if you will be installing from
|
||||
drive A:, type:
|
||||
|
||||
A:
|
||||
INSTALL
|
||||
|
||||
At this point, the INSTALL program will appear with menus
|
||||
selections and descriptions to guide you through the installation
|
||||
process.
|
||||
|
||||
Q. How do I run Turbo C?
|
||||
A. After you have installed Turbo C, type "TC" from the DOS
|
||||
prompt and you're ready to go. Chapter 2 (Getting Started)
|
||||
of the Turbo C User's Guide will guide you through your
|
||||
first Turbo C program.
|
||||
|
||||
Q. What is the difference between TC.EXE and TCC.EXE?
|
||||
A. The Turbo C package comes with two compilers, an Integrated
|
||||
Environment named TC.EXE and a command-line compiler named
|
||||
TCC.EXE. The Integrated Environment is essentially
|
||||
the command-line compiler with an integrated editor,
|
||||
linker, and debugger. Please refer to the Turbo C
|
||||
User's Guide for details on using both systems.
|
||||
|
||||
Q. What is a configuration file?
|
||||
A. A configuration file tells Turbo C what options to default to
|
||||
and where to look for its library and header files. TC.EXE
|
||||
looks for a configuration file named TCCONFIG.TC, and
|
||||
TCC.EXE looks for a file named TURBOC.CFG. See the User's
|
||||
Guide, pages 40 and 143 for more information.
|
||||
|
||||
Q. How do I create a configuration file?
|
||||
A. When you run the INSTALL program it creates a configuration
|
||||
file named TURBOC.CFG for TCC.EXE. This file is just an
|
||||
ASCII file which you can change with any text editor. It
|
||||
contains the path information for the library and header
|
||||
files for TCC.EXE to use. The INSTALL program does not
|
||||
create a TCCONFIG.TC file for TC.EXE because it installs
|
||||
the directory information directly into TC.EXE. You can
|
||||
create a configuration file for TC.EXE by running TC,
|
||||
setting your options however you want to set them, and
|
||||
typing Alt-O/S.
|
||||
|
||||
I n t e g r a t e d E n v i r o n m e n t
|
||||
----------------------------------------------------------------------
|
||||
Q. Why is Turbo C not able to find any of my #include files?
|
||||
A. The compiler searches for include files in the Turbo C Include
|
||||
Directories. This option is specified under the Options/Directories
|
||||
menu. The INSTALL program initially sets this option to the
|
||||
directory where it copied all the Turbo C *.h files.
|
||||
|
||||
|
||||
Q. Why do I get the message:
|
||||
Linker Error: Unable to open input file 'C0x.OBJ'
|
||||
A. The linker searches for Turbo C start-up and library files in the
|
||||
Turbo C Library Directories. This option is specified under the
|
||||
Options/Directories menu. The INSTALL program initially sets this
|
||||
option to a directory where it copied the start-up and library
|
||||
files.
|
||||
|
||||
|
||||
Q. How do I get Turbo C to link in my own libraries or use multiple
|
||||
source files?
|
||||
A. Turbo C's Project facility is designed to allow you to work with
|
||||
multiple files. Refer to Chapter 3 of the Turbo C User's Guide,
|
||||
under "Projects: Using Multiple Source Programs".
|
||||
|
||||
|
||||
Q. Why does the linker tell me that all the graphics library
|
||||
routines are undefined?
|
||||
A. The Options/Linker/Graphics Library item must be set ON, if
|
||||
you are using any Turbo C graphics functions and have not
|
||||
specifyed GRAPHICS.LIB in a project file.
|
||||
|
||||
|
||||
Q. Why does Turbo C report "Unable to open include file 'stdarg.h'"
|
||||
when I try to #include <stdio.h>?
|
||||
A. The most probable reason is that you have exceeded the number
|
||||
of files that DOS can have open simultaneously. Add the line
|
||||
|
||||
FILES=20
|
||||
|
||||
to your DOS CONFIG.SYS file. This allows DOS to open up to 20
|
||||
files at the same time. CONFIG.SYS will only be effective
|
||||
after you have rebooted your computer. See the IBM DOS Reference
|
||||
Manual for details on the CONFIG.SYS file.
|
||||
|
||||
|
||||
Q. How do I change the colors of the editor and menus in TC?
|
||||
A. The utility TCINST.EXE allows you to customize your colors.
|
||||
|
||||
|
||||
Q. How do I get a listing of my source code to my printer?
|
||||
A. From within the Turbo C editor hit <Ctrl><K><P>. This will
|
||||
print a marked block to the printer. If no block is marked
|
||||
this key sequence will print the entire file in your editor.
|
||||
|
||||
|
||||
Q. When I Make, Run, or Trace a program Turbo C sometimes goes
|
||||
through the compile and link process even when the object files
|
||||
are up-to-date.
|
||||
A. Turbo C's MAKE logic works solely on a file's date and time
|
||||
stamp. If one of your source files is marked with a date
|
||||
that's sometime in the future, the object files that are
|
||||
created from it will always be older than the source file,
|
||||
and Turbo C will always try to rebuild the file. You can fix
|
||||
this by using TOUCH.COM to set the file to the current date
|
||||
and time. You should also make sure that your system's date
|
||||
and time are always properly set.
|
||||
|
||||
|
||||
C o m m a n d - L i n e C o m p i l e r
|
||||
----------------------------------------------------------------------
|
||||
Q. Why is Turbo C not able to find any of my #include files?
|
||||
A. The compiler searches for include files in the Turbo C Include
|
||||
Directories. This option is specified by the -I switch. The INSTALL
|
||||
program initially writes a configuration file (TURBOC.CFG) that
|
||||
sets this to the directory where it copied all the Turbo C *.h
|
||||
files.
|
||||
|
||||
|
||||
Q. Why do I get the message:
|
||||
Linker Error: Unable to open input file 'C0x.OBJ'
|
||||
A. The linker searches for Turbo C start-up and library files in the
|
||||
Turbo C Library Directories. This option is specified by the -L
|
||||
switch. If you allow TCC to invoke the linker, it will search the
|
||||
directories in the configuration file (TURBOC.CFG) written by the
|
||||
INSTALL program. If you run TLINK, the configuration file is not read.
|
||||
|
||||
Q. Why does the linker tell me that all the graphics library
|
||||
routines are undefined?
|
||||
A. TCC will not search the graphics library unless you tell it to.
|
||||
You should specify the graphics library on the command line. For
|
||||
example, to compile BGIDEMO, type
|
||||
|
||||
TCC BGIDEMO.C GRAPHICS.LIB<Enter>
|
||||
|
||||
|
||||
G e n e r a l I / O
|
||||
----------------------------------------------------------------------
|
||||
Q. The '\n' in cprintf() does not return the cursor to the
|
||||
beginning of the line. It only moves the cursor down one line.
|
||||
A. cprintf() no longer interprets '\n' as a Carriage Return/
|
||||
Line Feed combination. The '\n' only outputs a Line Feed. To
|
||||
force the cursor to the beginning of the line, manually
|
||||
insert a Carriage Return:
|
||||
|
||||
cprintf("\n\r");
|
||||
|
||||
|
||||
Q. How do I print to the printer from a Turbo C program?
|
||||
A. Turbo C uses a FILE pointer (stdprn) defined in the STDIO.H
|
||||
file. You do not need to open stdprn before using it:
|
||||
|
||||
#include <stdio.h>
|
||||
main()
|
||||
{
|
||||
fprintf(stdprn, "Hello, world\n");
|
||||
}
|
||||
|
||||
Note that if your printer is line-buffered, the output is
|
||||
flushed only after a '\n' is sent.
|
||||
|
||||
|
||||
Q. I am reading and writing binary files. My program is
|
||||
translating the Carriage Return (0x0D) and Line Feed (0x0A)
|
||||
characters. How do I prevent this from happening?
|
||||
A. Files opened in text mode will translate these characters for
|
||||
DOS. To read a file in binary mode, open it in binary mode.
|
||||
For example
|
||||
|
||||
#include <stdio.h>
|
||||
main()
|
||||
{
|
||||
FILE *binary_fp;
|
||||
char buffer[100];
|
||||
|
||||
binary_fp = fopen("MYFILE.BIN", "rb");
|
||||
|
||||
fread(buffer, sizeof(char), 100, binary_fp);
|
||||
|
||||
:
|
||||
}
|
||||
|
||||
The default file mode is text.
|
||||
|
||||
|
||||
Q. Why don't printf() and puts() print text in color?
|
||||
A. Use the console I/O functions cprintf() and cputs() for color output.
|
||||
|
||||
#include <conio.h>
|
||||
main()
|
||||
{
|
||||
textcolor(BLUE);
|
||||
cprintf("I'm blue.");
|
||||
}
|
||||
|
||||
|
||||
Q. How do I print a long integer?
|
||||
A. Use the "%ld" format:
|
||||
|
||||
long int l = 70000L;
|
||||
printf("%ld", l);
|
||||
|
||||
|
||||
Q. How do I print a long double?
|
||||
A. Use the "%Lf" format.
|
||||
|
||||
long double ldbl = 1E500;
|
||||
printf("%Lf", ldbl);
|
||||
|
||||
|
||||
E x a m p l e P r o g r a m s
|
||||
----------------------------------------------------------------------
|
||||
Q. How do I compile the MICROCALC spread sheet?
|
||||
A. See Appendix G of the Turbo C Reference Manual.
|
||||
|
||||
|
||||
Q. How do I compile the BGIDEMO program?
|
||||
A. 1. Make sure that the following Turbo C files are in your
|
||||
current directory:
|
||||
|
||||
BGIDEMO.C
|
||||
*.BGI
|
||||
*.CHR
|
||||
|
||||
2. Run TC.
|
||||
|
||||
3. Load BGIDEMO.C into the Editor by hitting F3 then typing
|
||||
BGIDEMO<Enter>
|
||||
|
||||
3. Go to the Run menu and choose the Run item.
|
||||
|
||||
|
||||
Q. How do I create a COM file?
|
||||
A. DOS versions 3.2 and earlier include an EXE2BIN utility that
|
||||
converts EXE files to COM files. For users who do not have
|
||||
EXE2BIN, the Turbo C command-line linker, TLINK will create
|
||||
a COM file instead of an EXE file if the /t option is
|
||||
specified. For example:
|
||||
|
||||
tcc -mt -lt tiny
|
||||
|
||||
will create TINY.COM instead of TINY.EXE.
|
||||
|
||||
There are certain limitations in converting an EXE file to a COM
|
||||
file. These limitations are documented in the IBM Disk Operating
|
||||
System manual under EXE2BIN.
|
||||
|
||||
Turbo C's TINY model is compatible with the COM format, but programs
|
||||
that use Turbo C's floating point routines cannot be converted to a
|
||||
COM file.
|
||||
|
||||
|
||||
G r a p h i c s
|
||||
----------------------------------------------------------------------
|
||||
Q. Why do I get the error message:
|
||||
|
||||
BGI Error: graphics not initialized (use 'initgraph')
|
||||
|
||||
when I use a graphics function? My program has already
|
||||
called initgraph().
|
||||
A. For some reason initgraph() failed. To find out why, check
|
||||
the return value of graphresult(). For example:
|
||||
|
||||
#include <graphics.h>
|
||||
main()
|
||||
{
|
||||
int gerr; /* graphics error */
|
||||
int gdriver = DETECT, gmode;
|
||||
|
||||
/* Initialize graphics using auto-detection and look
|
||||
for the .BGI and .CHR files in the C:\TURBOC directory.
|
||||
*/
|
||||
initgraph(&gdriver, &gmode, "C:\\TURBOC");
|
||||
|
||||
if ((gerr = graphresult()) != grOk)
|
||||
{
|
||||
printf("Error : %s\n", grapherrormsg(gerr));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
:
|
||||
}
|
||||
|
||||
|
||||
M a t h / F l o a t i n g P o i n t
|
||||
----------------------------------------------------------------------
|
||||
Q. Why do I get incorrect results from all the math library
|
||||
functions like cos() and tan()?
|
||||
A. You must #include <math.h> before you call any of the standard
|
||||
Turbo C math functions. In general, Turbo C assumes that a function
|
||||
that is not declared returns an int. In the case of math functions,
|
||||
they usually return a double. For example
|
||||
|
||||
/* WRONG */ /* RIGHT */
|
||||
#include <math.h>
|
||||
main() main()
|
||||
{ {
|
||||
printf("%f", cos(0)); printf("%f", cos(0));
|
||||
} }
|
||||
|
||||
|
||||
Q. How do I "trap" a floating point error?
|
||||
A. See the signal() and matherr() functions in the Turbo C Reference
|
||||
Guide. The signal() function may be used to trap errors in the
|
||||
80x87 or the 80x87 emulator. The matherr() function traps errors
|
||||
in the Math Library functions.
|
||||
|
||||
|
||||
L i n k e r E r r o r s
|
||||
----------------------------------------------------------------------
|
||||
Q. Why do I get the message:
|
||||
Linker Error: Unable to open input file 'C0x.OBJ'
|
||||
A. See "Integrated Environment" section above.
|
||||
|
||||
|
||||
Q. Why do I get the message:
|
||||
Linker Error: Undefined symbol '_main' in module C0
|
||||
A. Every C program must contain a function called main(). This
|
||||
is the first function executed in your program. The function
|
||||
name must be all in lower case. If your program does not
|
||||
have one, create one. If you are using multiple source files,
|
||||
the file that contains the function main() must be one of
|
||||
the files listed in the Project.
|
||||
|
||||
Note that an underscore character '_' is prepended to all
|
||||
external Turbo C symbols.
|
||||
|
||||
|
||||
Q. Why does the linker tell me that all the graphics library
|
||||
routines are undefined?
|
||||
A. See the "Integrated Environment" and "Command-line Compiler"
|
||||
sections above.
|
||||
|
||||
|
||||
Q. What is a 'Fixup overflow'?
|
||||
A. See the listing of TLINK error messages in Appendix D of the
|
||||
Turbo C Reference Guide.
|
||||
|
||||
|
||||
Q. I am linking my own assembly language functions with Turbo C.
|
||||
The linker reports that all of my functions are undefined.
|
||||
A. Make sure that you have put an underbar character '_' in front of all
|
||||
assembly language function names to be called by Turbo C. Your assembly
|
||||
language program should be assembled with Case Sensitivity. See
|
||||
the Chapter 12, "Advanced Programming," in the Turbo C User's Guide
|
||||
for details.
|
||||
|
||||
|
||||
O t h e r Q u e s t i o n s
|
||||
----------------------------------------------------------------------
|
||||
Q. How do I change the stack size?
|
||||
A. The size of the stack of a Turbo C program is determined at
|
||||
run-time by the global variable _stklen. To change the size
|
||||
to, for example 10000 bytes, include the following line in
|
||||
your program:
|
||||
|
||||
extern unsigned _stklen = 10000;
|
||||
|
||||
This statement must not be inside any function definition.
|
||||
The default stack size is 4096 bytes (4K).
|
||||
|
||||
Q. I'm getting a 'Stack Overflow!' message when I run my program.
|
||||
How can I work around this?
|
||||
A. You may increase the stack size by following the procedure above. Stack
|
||||
overflows are usually caused by a large amount of local data or
|
||||
recursive functions. You can decrease the amount of stack space
|
||||
used by declaring your local variables static:
|
||||
|
||||
main() main()
|
||||
{ {
|
||||
char x[5000]; --> static char x[5000];
|
||||
: :
|
||||
} }
|
||||
|
||||
Of course, you should be aware that there are other effects
|
||||
that the "static" keyword has, as applied here.
|
||||
|
||||
Q. My program comes up with the message 'Null pointer assignment'
|
||||
after it terminates. What does this mean?
|
||||
A. Before a small-data model Turbo C program returns to DOS, it will
|
||||
check to see if the beginning of its data segment has been corrupted.
|
||||
This message is to warn you that you have used uninitialized pointers
|
||||
or that your program has corrupted memory in some other way.
|
||||
|
||||
Q. Why are .EXE files generated by TC.EXE larger than those
|
||||
generated by TCC.EXE?
|
||||
A. In the default configuration, TC.EXE includes debugging
|
||||
information in the .EXE files that it creates, and TCC.EXE
|
||||
does not. If you don't want to produce this debugging
|
||||
information, you can shut it off in the Integrated
|
||||
Development Environment by selecting Alt-D/S/N.
|
||||
|
||||
|
||||
Q. Why do I get "declaration syntax error" messages on DOS.H?
|
||||
A. You have set the "Ansi keywords only" option ON. Keep this option
|
||||
OFF when using any keywords specific to Turbo C .
|
||||
|
||||
|
||||
Q. I have a working program that dynamically allocates memory
|
||||
using malloc() or calloc() in small data models (tiny, small,
|
||||
and medium). When I compile this program in large data models
|
||||
(compact, large, and huge) my program hangs.
|
||||
A. Make sure that you have #include <alloc.h> in your program.
|
||||
|
||||
|
||||
Q. I am linking my own assembly language functions with Turbo C.
|
||||
But the linker reports that all of my functions are undefined.
|
||||
A. See answer above in the "Linker" section.
|
||||
|
||||
|
||||
Q. My far pointers "wrap around" when they are incremented over 64K.
|
||||
How do I reference a data object that is greater than 64K?
|
||||
A. Use huge pointers.
|
||||
|
||||
|
||||
Q. Can I declare more than 64K of global variables?
|
||||
A. You may have a total of up to 64K global and static data in
|
||||
the Tiny, Small, Medium, Compact and Large memory models. In
|
||||
the Huge model, the maximum is 64K per source module.
|
||||
|
||||
|
||||
Q. How do I declare an array that's greater than 64K?
|
||||
A. Arrays greater than 64K must be allocated off the heap. If,
|
||||
for example you wanted a two-dimensional array of characters
|
||||
that was 1024 by 128, the declaration you would expect to
|
||||
write would be:
|
||||
|
||||
char array[1024][128];
|
||||
|
||||
But since the size of this array is greater than 64K, it must
|
||||
be allocated off the heap. An example of this is:
|
||||
|
||||
#include <alloc.h>
|
||||
|
||||
char (huge *array)[128];
|
||||
:
|
||||
main()
|
||||
{
|
||||
:
|
||||
array = farcalloc(sizeof(*array), 1024);
|
||||
:
|
||||
}
|
||||
|
||||
The array can be accessed with the same code as an array not
|
||||
allocated off the heap. For example:
|
||||
|
||||
i = array[30][56];
|
||||
|
||||
will assign "i" the value stored at the 31st by 57th element
|
||||
in "array".
|
||||
|
||||
The use of the "huge" keyword is necessary in the declaration
|
||||
of "array" since only a huge pointer can address objects
|
||||
greater than 64k. For further discussion of huge pointers,
|
||||
refer to the User's Guide.
|
||||
|
||||
|
||||
Q. How do I interface Turbo C routines to a Turbo Pascal program?
|
||||
A. See the example programs CPASDEMO.PAS and CPASDEMO.C on disk.
|
||||
These files are packed in the file EXAMPLES.ARC and you will
|
||||
need to UNPACK them before using them.
|
||||
|
||||
|
||||
Q. How do I get Clipper to link with Turbo C?
|
||||
A. If you are having trouble, contact Nantucket Technical Support.
|
||||
|
||||
|
BIN
Borland Turbo C v2/HERC.BGI
Normal file
BIN
Borland Turbo C v2/HERC.BGI
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/IBM8514.BGI
Normal file
BIN
Borland Turbo C v2/IBM8514.BGI
Normal file
Binary file not shown.
59
Borland Turbo C v2/INCLUDE/ALLOC.H
Normal file
59
Borland Turbo C v2/INCLUDE/ALLOC.H
Normal file
@ -0,0 +1,59 @@
|
||||
/* alloc.h
|
||||
|
||||
memory management functions and variables.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _STDDEF
|
||||
#define _STDDEF
|
||||
#ifndef _PTRDIFF_T
|
||||
#define _PTRDIFF_T
|
||||
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
|
||||
typedef long ptrdiff_t;
|
||||
#else
|
||||
typedef int ptrdiff_t;
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL 0L
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int _Cdecl brk (void *addr);
|
||||
void *_Cdecl calloc (size_t nitems, size_t size);
|
||||
|
||||
#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
|
||||
unsigned long _Cdecl coreleft (void);
|
||||
#else
|
||||
unsigned _Cdecl coreleft (void);
|
||||
#endif
|
||||
|
||||
void _Cdecl free (void *block);
|
||||
void *_Cdecl malloc (size_t size);
|
||||
void *_Cdecl realloc (void *block, size_t size);
|
||||
void *_Cdecl sbrk (int incr);
|
||||
|
||||
#if !__STDC__
|
||||
void far * _Cdecl farcalloc (unsigned long nunits, unsigned long unitsz);
|
||||
unsigned long _Cdecl farcoreleft(void);
|
||||
void _Cdecl farfree (void far *block);
|
||||
void far *_Cdecl farmalloc (unsigned long nbytes);
|
||||
void far *_Cdecl farrealloc (void far *oldblock, unsigned long nbytes);
|
||||
#endif
|
||||
|
20
Borland Turbo C v2/INCLUDE/ASSERT.H
Normal file
20
Borland Turbo C v2/INCLUDE/ASSERT.H
Normal file
@ -0,0 +1,20 @@
|
||||
/* assert.h
|
||||
|
||||
assert macro
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* fprintf() prototype & 'stderr' definition */
|
||||
#include <stdlib.h> /* abort() prototype */
|
||||
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
#define assert(p) if(!(p)){fprintf(stderr,\
|
||||
"Assertion failed: %s, file %s, line %d\n",\
|
||||
#p, __FILE__, __LINE__);abort();}
|
||||
#else
|
||||
#define assert(p)
|
||||
#endif
|
||||
|
22
Borland Turbo C v2/INCLUDE/BIOS.H
Normal file
22
Borland Turbo C v2/INCLUDE/BIOS.H
Normal file
@ -0,0 +1,22 @@
|
||||
/* bios.h
|
||||
|
||||
Access to bios services.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
int _Cdecl bioscom(int cmd, char abyte, int port);
|
||||
int _Cdecl biosdisk(int cmd, int drive, int head, int track, int sector,
|
||||
int nsects, void *buffer);
|
||||
int _Cdecl biosequip(void);
|
||||
int _Cdecl bioskey(int cmd);
|
||||
int _Cdecl biosmemory(void);
|
||||
int _Cdecl biosprint(int cmd, int abyte, int port);
|
||||
long _Cdecl biostime(int cmd, long newtime);
|
||||
|
98
Borland Turbo C v2/INCLUDE/CONIO.H
Normal file
98
Borland Turbo C v2/INCLUDE/CONIO.H
Normal file
@ -0,0 +1,98 @@
|
||||
/* conio.h
|
||||
|
||||
Direct MSDOS console input/output.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if !defined(__VIDEO)
|
||||
#define __VIDEO
|
||||
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef __OLDCONIO__
|
||||
|
||||
struct text_info {
|
||||
unsigned char winleft;
|
||||
unsigned char wintop;
|
||||
unsigned char winright;
|
||||
unsigned char winbottom;
|
||||
unsigned char attribute;
|
||||
unsigned char normattr;
|
||||
unsigned char currmode;
|
||||
unsigned char screenheight;
|
||||
unsigned char screenwidth;
|
||||
unsigned char curx;
|
||||
unsigned char cury;
|
||||
};
|
||||
|
||||
enum text_modes { LASTMODE=-1, BW40=0, C40, BW80, C80, MONO=7 };
|
||||
|
||||
#if !defined(__COLORS)
|
||||
#define __COLORS
|
||||
|
||||
enum COLORS {
|
||||
BLACK, /* dark colors */
|
||||
BLUE,
|
||||
GREEN,
|
||||
CYAN,
|
||||
RED,
|
||||
MAGENTA,
|
||||
BROWN,
|
||||
LIGHTGRAY,
|
||||
DARKGRAY, /* light colors */
|
||||
LIGHTBLUE,
|
||||
LIGHTGREEN,
|
||||
LIGHTCYAN,
|
||||
LIGHTRED,
|
||||
LIGHTMAGENTA,
|
||||
YELLOW,
|
||||
WHITE
|
||||
};
|
||||
#endif
|
||||
|
||||
#define BLINK 128 /* blink bit */
|
||||
|
||||
extern int _Cdecl directvideo;
|
||||
|
||||
void _Cdecl clreol (void);
|
||||
void _Cdecl clrscr (void);
|
||||
void _Cdecl delline (void);
|
||||
int _Cdecl gettext (int left, int top, int right, int bottom,
|
||||
void *destin);
|
||||
void _Cdecl gettextinfo (struct text_info *r);
|
||||
void _Cdecl gotoxy (int x, int y);
|
||||
void _Cdecl highvideo (void);
|
||||
void _Cdecl insline (void);
|
||||
void _Cdecl lowvideo (void);
|
||||
int _Cdecl movetext (int left, int top, int right, int bottom,
|
||||
int destleft, int desttop);
|
||||
void _Cdecl normvideo (void);
|
||||
int _Cdecl puttext (int left, int top, int right, int bottom,
|
||||
void *source);
|
||||
void _Cdecl textattr (int newattr);
|
||||
void _Cdecl textbackground (int newcolor);
|
||||
void _Cdecl textcolor (int newcolor);
|
||||
void _Cdecl textmode (int newmode);
|
||||
int _Cdecl wherex (void);
|
||||
int _Cdecl wherey (void);
|
||||
void _Cdecl window (int left, int top, int right, int bottom);
|
||||
#endif
|
||||
|
||||
char *_Cdecl cgets (char *str);
|
||||
int _Cdecl cprintf (const char *format, ...);
|
||||
int _Cdecl cputs (const char *str);
|
||||
int _Cdecl cscanf (const char *format, ...);
|
||||
int _Cdecl getch (void);
|
||||
int _Cdecl getche (void);
|
||||
char *_Cdecl getpass (const char *prompt);
|
||||
int _Cdecl kbhit (void);
|
||||
int _Cdecl putch (int c);
|
||||
int _Cdecl ungetch (int ch);
|
||||
|
||||
#endif
|
||||
|
43
Borland Turbo C v2/INCLUDE/CTYPE.H
Normal file
43
Borland Turbo C v2/INCLUDE/CTYPE.H
Normal file
@ -0,0 +1,43 @@
|
||||
/* ctype.h
|
||||
|
||||
Defines the ctype macros.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#define _IS_SP 1 /* is space */
|
||||
#define _IS_DIG 2 /* is digit indicator */
|
||||
#define _IS_UPP 4 /* is upper case */
|
||||
#define _IS_LOW 8 /* is lower case */
|
||||
#define _IS_HEX 16 /* [A-F or [a-f] */
|
||||
#define _IS_CTL 32 /* Control */
|
||||
#define _IS_PUN 64 /* punctuation */
|
||||
|
||||
extern char _Cdecl _ctype[]; /* Character type array */
|
||||
|
||||
#define isalnum(c) (_ctype[(c) + 1] & (_IS_DIG | _IS_UPP | _IS_LOW))
|
||||
#define isalpha(c) (_ctype[(c) + 1] & (_IS_UPP | _IS_LOW))
|
||||
#define isascii(c) ((unsigned)(c) < 128)
|
||||
#define iscntrl(c) (_ctype[(c) + 1] & _IS_CTL)
|
||||
#define isdigit(c) (_ctype[(c) + 1] & _IS_DIG)
|
||||
#define isgraph(c) ((c) >= 0x21 && (c) <= 0x7e)
|
||||
#define islower(c) (_ctype[(c) + 1] & _IS_LOW)
|
||||
#define isprint(c) ((c) >= 0x20 && (c) <= 0x7e)
|
||||
#define ispunct(c) (_ctype[(c) + 1] & _IS_PUN)
|
||||
#define isspace(c) (_ctype[(c) + 1] & _IS_SP)
|
||||
#define isupper(c) (_ctype[(c) + 1] & _IS_UPP)
|
||||
#define isxdigit(c) (_ctype[(c) + 1] & (_IS_DIG | _IS_HEX))
|
||||
|
||||
#define _toupper(c) ((c) + 'A' - 'a')
|
||||
#define _tolower(c) ((c) + 'a' - 'A')
|
||||
#define toascii(c) ((c) & 0x7f)
|
||||
|
||||
int _Cdecl tolower(int ch);
|
||||
int _Cdecl toupper(int ch);
|
||||
|
57
Borland Turbo C v2/INCLUDE/DIR.H
Normal file
57
Borland Turbo C v2/INCLUDE/DIR.H
Normal file
@ -0,0 +1,57 @@
|
||||
/* dir.h
|
||||
|
||||
Defines structures, macros, and functions for dealing with
|
||||
directories and pathnames.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__DIR_DEF_)
|
||||
#define __DIR_DEF_
|
||||
|
||||
struct ffblk {
|
||||
char ff_reserved[21];
|
||||
char ff_attrib;
|
||||
unsigned ff_ftime;
|
||||
unsigned ff_fdate;
|
||||
long ff_fsize;
|
||||
char ff_name[13];
|
||||
};
|
||||
|
||||
#define WILDCARDS 0x01
|
||||
#define EXTENSION 0x02
|
||||
#define FILENAME 0x04
|
||||
#define DIRECTORY 0x08
|
||||
#define DRIVE 0x10
|
||||
|
||||
#define MAXPATH 80
|
||||
#define MAXDRIVE 3
|
||||
#define MAXDIR 66
|
||||
#define MAXFILE 9
|
||||
#define MAXEXT 5
|
||||
|
||||
int _Cdecl chdir (const char *path);
|
||||
int _Cdecl findfirst (const char *path, struct ffblk *ffblk,
|
||||
int attrib);
|
||||
int _Cdecl findnext (struct ffblk *ffblk);
|
||||
void _Cdecl fnmerge (char *path,const char *drive,const char *dir,
|
||||
const char *name, const char *ext);
|
||||
int _Cdecl fnsplit (const char *path, char *drive, char *dir,
|
||||
char *name, char *ext);
|
||||
int _Cdecl getcurdir (int drive, char *directory);
|
||||
char *_Cdecl getcwd (char *buf, int buflen);
|
||||
int _Cdecl getdisk (void);
|
||||
int _Cdecl mkdir (const char *path);
|
||||
char *_Cdecl mktemp (char *template);
|
||||
int _Cdecl rmdir (const char *path);
|
||||
char *_Cdecl searchpath (const char *file);
|
||||
int _Cdecl setdisk (int drive);
|
||||
|
||||
#endif
|
||||
|
252
Borland Turbo C v2/INCLUDE/DOS.H
Normal file
252
Borland Turbo C v2/INCLUDE/DOS.H
Normal file
@ -0,0 +1,252 @@
|
||||
/* dos.h
|
||||
|
||||
Defines structs, unions, macros, and functions for dealing
|
||||
with MSDOS and the Intel iAPX86 microprocessor family.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__DOS_DEF_)
|
||||
#define __DOS_DEF_
|
||||
|
||||
/* Variables */
|
||||
extern int _Cdecl _8087;
|
||||
extern int _Cdecl _argc;
|
||||
extern char **_Cdecl _argv;
|
||||
extern char **_Cdecl environ;
|
||||
extern int _Cdecl _doserrno;
|
||||
extern unsigned _Cdecl _heaplen;
|
||||
extern unsigned char _Cdecl _osmajor;
|
||||
extern unsigned char _Cdecl _osminor;
|
||||
extern unsigned _Cdecl _psp;
|
||||
extern unsigned _Cdecl _stklen;
|
||||
extern unsigned _Cdecl _version;
|
||||
|
||||
#define FA_RDONLY 0x01 /* Read only attribute */
|
||||
#define FA_HIDDEN 0x02 /* Hidden file */
|
||||
#define FA_SYSTEM 0x04 /* System file */
|
||||
#define FA_LABEL 0x08 /* Volume label */
|
||||
#define FA_DIREC 0x10 /* Directory */
|
||||
#define FA_ARCH 0x20 /* Archive */
|
||||
|
||||
#define NFDS 20 /* Maximum number of fds */
|
||||
|
||||
struct fcb {
|
||||
char fcb_drive; /* 0 = default, 1 = A, 2 = B */
|
||||
char fcb_name[8]; /* File name */
|
||||
char fcb_ext[3]; /* File extension */
|
||||
short fcb_curblk; /* Current block number */
|
||||
short fcb_recsize; /* Logical record size in bytes */
|
||||
long fcb_filsize; /* File size in bytes */
|
||||
short fcb_date; /* Date file was last written */
|
||||
char fcb_resv[10]; /* Reserved for DOS */
|
||||
char fcb_currec; /* Current record in block */
|
||||
long fcb_random; /* Random record number */
|
||||
};
|
||||
|
||||
struct xfcb {
|
||||
char xfcb_flag; /* Contains 0xff to indicate xfcb */
|
||||
char xfcb_resv[5]; /* Reserved for DOS */
|
||||
char xfcb_attr; /* Search attribute */
|
||||
struct fcb xfcb_fcb; /* The standard fcb */
|
||||
};
|
||||
|
||||
struct country {
|
||||
int co_date;
|
||||
char co_curr[5];
|
||||
char co_thsep[2];
|
||||
char co_desep[2];
|
||||
char co_dtsep[2];
|
||||
char co_tmsep[2];
|
||||
char co_currstyle;
|
||||
char co_digits;
|
||||
char co_time;
|
||||
long co_case;
|
||||
char co_dasep[2];
|
||||
char co_fill[10];
|
||||
};
|
||||
|
||||
struct DOSERROR {
|
||||
int exterror;
|
||||
char class;
|
||||
char action;
|
||||
char locus;
|
||||
};
|
||||
|
||||
struct dfree {
|
||||
unsigned df_avail;
|
||||
unsigned df_total;
|
||||
unsigned df_bsec;
|
||||
unsigned df_sclus;
|
||||
};
|
||||
|
||||
struct fatinfo {
|
||||
char fi_sclus;
|
||||
char fi_fatid;
|
||||
int fi_nclus;
|
||||
int fi_bysec;
|
||||
};
|
||||
|
||||
struct devhdr {
|
||||
long dh_next; /* Next device pointer */
|
||||
short dh_attr; /* Attributes */
|
||||
unsigned short dh_strat; /* Driver strategy routine */
|
||||
unsigned short dh_inter; /* Driver interrupt routine */
|
||||
char dh_name[8]; /* Device name */
|
||||
};
|
||||
|
||||
struct time {
|
||||
unsigned char ti_min; /* Minutes */
|
||||
unsigned char ti_hour; /* Hours */
|
||||
unsigned char ti_hund; /* Hundredths of seconds */
|
||||
unsigned char ti_sec; /* Seconds */
|
||||
};
|
||||
|
||||
struct date {
|
||||
int da_year; /* Year - 1980 */
|
||||
char da_day; /* Day of the month */
|
||||
char da_mon; /* Month (1 = Jan) */
|
||||
};
|
||||
|
||||
struct WORDREGS {
|
||||
unsigned int ax, bx, cx, dx, si, di, cflag, flags;
|
||||
};
|
||||
|
||||
struct BYTEREGS {
|
||||
unsigned char al, ah, bl, bh, cl, ch, dl, dh;
|
||||
};
|
||||
|
||||
union REGS {
|
||||
struct WORDREGS x;
|
||||
struct BYTEREGS h;
|
||||
};
|
||||
|
||||
struct SREGS {
|
||||
unsigned int es;
|
||||
unsigned int cs;
|
||||
unsigned int ss;
|
||||
unsigned int ds;
|
||||
};
|
||||
|
||||
struct REGPACK {
|
||||
unsigned r_ax, r_bx, r_cx, r_dx;
|
||||
unsigned r_bp, r_si, r_di, r_ds, r_es, r_flags;
|
||||
};
|
||||
|
||||
#define FP_OFF(fp) ((unsigned)(fp))
|
||||
#define FP_SEG(fp) ((unsigned)((unsigned long)(fp) >> 16))
|
||||
|
||||
|
||||
typedef struct {
|
||||
char drive; /* do not change */
|
||||
char pattern [13]; /* these fields, */
|
||||
char reserved [7]; /* Microsoft reserved */
|
||||
char attrib;
|
||||
short time;
|
||||
short date;
|
||||
long size;
|
||||
char nameZ [13]; /* result of the search, asciiz */
|
||||
} dosSearchInfo; /* used with DOS functions 4E, 4F */
|
||||
|
||||
|
||||
int _Cdecl absread (int drive, int nsects, int lsect, void *buffer);
|
||||
int _Cdecl abswrite(int drive, int nsects, int lsect, void *buffer);
|
||||
int _Cdecl allocmem(unsigned size, unsigned *segp);
|
||||
int _Cdecl bdos (int dosfun, unsigned dosdx, unsigned dosal);
|
||||
int _Cdecl bdosptr (int dosfun, void *argument, unsigned dosal);
|
||||
struct country *_Cdecl country (int xcode, struct country *cp);
|
||||
void _Cdecl ctrlbrk (int _Cdecl (*handler)(void));
|
||||
void _Cdecl delay (unsigned milliseconds);
|
||||
void _Cdecl disable (void);
|
||||
int _Cdecl dosexterr (struct DOSERROR *eblkp);
|
||||
long _Cdecl dostounix (struct date *d, struct time *t);
|
||||
void __emit__();
|
||||
void _Cdecl enable (void);
|
||||
int _Cdecl freemem (unsigned segx);
|
||||
int _Cdecl getcbrk (void);
|
||||
void _Cdecl getdate (struct date *datep);
|
||||
void _Cdecl getdfree(unsigned char drive, struct dfree *dtable);
|
||||
void _Cdecl getfat (unsigned char drive, struct fatinfo *dtable);
|
||||
void _Cdecl getfatd (struct fatinfo *dtable);
|
||||
unsigned _Cdecl getpsp (void);
|
||||
int _Cdecl getswitchar (void);
|
||||
void _Cdecl gettime (struct time *timep);
|
||||
void interrupt (* _Cdecl getvect(int interruptno)) ();
|
||||
int _Cdecl getverify (void);
|
||||
void _Cdecl harderr (int _Cdecl (*handler)());
|
||||
void _Cdecl hardresume (int axret);
|
||||
void _Cdecl hardretn(int retn);
|
||||
int _Cdecl inport (int portid);
|
||||
unsigned char _Cdecl inportb(int portid);
|
||||
int _Cdecl int86 (int intno, union REGS *inregs, union REGS *outregs);
|
||||
int _Cdecl int86x (int intno, union REGS *inregs, union REGS *outregs,
|
||||
struct SREGS *segregs);
|
||||
int _Cdecl intdos (union REGS *inregs, union REGS *outregs);
|
||||
int _Cdecl intdosx (union REGS *inregs, union REGS *outregs,
|
||||
struct SREGS *segregs);
|
||||
void _Cdecl intr (int intno, struct REGPACK *preg);
|
||||
void _Cdecl keep (unsigned char status, unsigned size);
|
||||
void _Cdecl nosound (void);
|
||||
void _Cdecl outport (int portid, int value);
|
||||
void _Cdecl outportb(int portid, unsigned char value);
|
||||
char *_Cdecl parsfnm (const char *cmdline, struct fcb *fcb, int opt);
|
||||
int _Cdecl peek (unsigned segment, unsigned offset);
|
||||
char _Cdecl peekb (unsigned segment, unsigned offset);
|
||||
void _Cdecl poke (unsigned segment, unsigned offset, int value);
|
||||
void _Cdecl pokeb (unsigned segment, unsigned offset, char value);
|
||||
int _Cdecl randbrd (struct fcb *fcb, int rcnt);
|
||||
int _Cdecl randbwr (struct fcb *fcb, int rcnt);
|
||||
void _Cdecl segread (struct SREGS *segp);
|
||||
int _Cdecl setblock(unsigned segx, unsigned newsize);
|
||||
int _Cdecl setcbrk (int cbrkvalue);
|
||||
void _Cdecl setdate (struct date *datep);
|
||||
void _Cdecl setswitchar (char ch);
|
||||
void _Cdecl settime (struct time *timep);
|
||||
void _Cdecl setvect (int interruptno, void interrupt (*isr) ());
|
||||
void _Cdecl setverify (int value);
|
||||
void _Cdecl sleep (unsigned seconds);
|
||||
void _Cdecl sound (unsigned frequency);
|
||||
void _Cdecl unixtodos (long time, struct date *d, struct time *t);
|
||||
int _Cdecl unlink (const char *path);
|
||||
|
||||
/* These are in-line functions. These prototypes just clean up
|
||||
some syntax checks and code generation.
|
||||
*/
|
||||
|
||||
void _Cdecl __cli__ (void);
|
||||
void _Cdecl __sti__ (void);
|
||||
unsigned char _Cdecl __inportb__(int portid);
|
||||
void _Cdecl __outportb__ (int portid, unsigned char value);
|
||||
void _Cdecl __int__ (int interruptnum);
|
||||
|
||||
#define disable() __cli__() /* Clear interrupt flag */
|
||||
#define enable() __sti__() /* Set interrupt flag */
|
||||
#define inportb(portid) __inportb__(portid) /* Byte IN instruction */
|
||||
#define outportb(portid, v) __outportb__(portid,v)/* Byte OUT instruction */
|
||||
#define geninterrupt(i) __int__(i) /* Interrupt instruction */
|
||||
|
||||
/* some other compilers use inp, outp for inportb, outportb */
|
||||
#define inp(portid) inportb(portid)
|
||||
#define outp(portid,v) outportb(portid,v)
|
||||
|
||||
#if !__STDC__
|
||||
char far *cdecl getdta(void);
|
||||
void cdecl setdta(char far *dta);
|
||||
|
||||
#define MK_FP(seg,ofs) ((void far *) \
|
||||
(((unsigned long)(seg) << 16) | (unsigned)(ofs)))
|
||||
|
||||
#define poke(a,b,c) (*((int far*)MK_FP((a),(b))) = (int)(c))
|
||||
#define pokeb(a,b,c) (*((char far*)MK_FP((a),(b))) = (char)(c))
|
||||
#define peek(a,b) (*((int far*)MK_FP((a),(b))))
|
||||
#define peekb(a,b) (*((char far*)MK_FP((a),(b))))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
77
Borland Turbo C v2/INCLUDE/ERRNO.H
Normal file
77
Borland Turbo C v2/INCLUDE/ERRNO.H
Normal file
@ -0,0 +1,77 @@
|
||||
/* errno.h
|
||||
|
||||
Defines the system error variable errno and the error
|
||||
numbers set by system calls. Errors which exist in Unix(tm)
|
||||
but not MSDOS have value -1.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
|
||||
/* Dos Error Codes */
|
||||
|
||||
#define EZERO 0 /* Error 0 */
|
||||
#define EINVFNC 1 /* Invalid function number */
|
||||
#define ENOFILE 2 /* File not found */
|
||||
#define ENOPATH 3 /* Path not found */
|
||||
#define ECONTR 7 /* Memory blocks destroyed */
|
||||
#define EINVMEM 9 /* Invalid memory block address */
|
||||
#define EINVENV 10 /* Invalid environment */
|
||||
#define EINVFMT 11 /* Invalid format */
|
||||
#define EINVACC 12 /* Invalid access code */
|
||||
#define EINVDAT 13 /* Invalid data */
|
||||
#define EINVDRV 15 /* Invalid drive specified */
|
||||
#define ECURDIR 16 /* Attempt to remove CurDir */
|
||||
#define ENOTSAM 17 /* Not same device */
|
||||
#define ENMFILE 18 /* No more files */
|
||||
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define EMFILE 4 /* Too many open files */
|
||||
#define EACCES 5 /* Permission denied */
|
||||
#define EBADF 6 /* Bad file number */
|
||||
#define ENOMEM 8 /* Not enough core */
|
||||
#define ENODEV 15 /* No such device */
|
||||
#define EINVAL 19 /* Invalid argument */
|
||||
#define E2BIG 20 /* Arg list too long */
|
||||
#define ENOEXEC 21 /* Exec format error */
|
||||
#define EXDEV 22 /* Cross-device link */
|
||||
#define EDOM 33 /* Math argument */
|
||||
#define ERANGE 34 /* Result too large */
|
||||
#define EEXIST 35 /* File already exists */
|
||||
|
||||
#define EFAULT -1 /* Unknown error */
|
||||
#define EPERM -1 /* UNIX - not MSDOS */
|
||||
#define ESRCH -1 /* UNIX - not MSDOS */
|
||||
#define EINTR -1 /* UNIX - not MSDOS */
|
||||
#define EIO -1 /* UNIX - not MSDOS */
|
||||
#define ENXIO -1 /* UNIX - not MSDOS */
|
||||
#define ECHILD -1 /* UNIX - not MSDOS */
|
||||
#define EAGAIN -1 /* UNIX - not MSDOS */
|
||||
#define ENOTBLK -1 /* UNIX - not MSDOS */
|
||||
#define EBUSY -1 /* UNIX - not MSDOS */
|
||||
#define ENOTDIR -1 /* UNIX - not MSDOS */
|
||||
#define EISDIR -1 /* UNIX - not MSDOS */
|
||||
#define ENFILE -1 /* UNIX - not MSDOS */
|
||||
#define ENOTTY -1 /* UNIX - not MSDOS */
|
||||
#define ETXTBSY -1 /* UNIX - not MSDOS */
|
||||
#define EFBIG -1 /* UNIX - not MSDOS */
|
||||
#define ENOSPC -1 /* UNIX - not MSDOS */
|
||||
#define ESPIPE -1 /* UNIX - not MSDOS */
|
||||
#define EROFS -1 /* UNIX - not MSDOS */
|
||||
#define EMLINK -1 /* UNIX - not MSDOS */
|
||||
#define EPIPE -1 /* UNIX - not MSDOS */
|
||||
#define EUCLEAN -1 /* UNIX - not MSDOS */
|
||||
|
||||
|
||||
|
||||
#define _sys_nerr 35 /* highest defined system error number */
|
||||
|
||||
extern int _Cdecl errno;
|
||||
extern int _Cdecl _doserrno;
|
||||
|
53
Borland Turbo C v2/INCLUDE/FCNTL.H
Normal file
53
Borland Turbo C v2/INCLUDE/FCNTL.H
Normal file
@ -0,0 +1,53 @@
|
||||
/* fcntl.h
|
||||
|
||||
Define flag values accessible to open.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
extern int _Cdecl _fmode;
|
||||
|
||||
/* The first three can only be set by open */
|
||||
|
||||
#define O_RDONLY 1
|
||||
#define O_WRONLY 2
|
||||
#define O_RDWR 4
|
||||
|
||||
/* Flag values for open only */
|
||||
|
||||
#define O_CREAT 0x0100 /* create and open file */
|
||||
#define O_TRUNC 0x0200 /* open with truncation */
|
||||
#define O_EXCL 0x0400 /* exclusive open */
|
||||
|
||||
/* The "open flags" defined above are not needed after open, hence they
|
||||
are re-used for other purposes when the file is running. Sorry, its
|
||||
getting crowded !
|
||||
*/
|
||||
#define _O_RUNFLAGS 0x0700
|
||||
#define _O_EOF 0x0200 /* set when text file hits ^Z */
|
||||
|
||||
/* a file in append mode may be written to only at its end.
|
||||
*/
|
||||
#define O_APPEND 0x0800 /* to end of file */
|
||||
|
||||
/* MSDOS special bits */
|
||||
|
||||
#define O_CHANGED 0x1000 /* user may read these bits, but */
|
||||
#define O_DEVICE 0x2000 /* only RTL\io functions may touch. */
|
||||
#define O_TEXT 0x4000 /* CR-LF translation */
|
||||
#define O_BINARY 0x8000 /* no translation */
|
||||
|
||||
/* DOS 3.x options */
|
||||
|
||||
#define O_NOINHERIT 0x80
|
||||
#define O_DENYALL 0x10
|
||||
#define O_DENYWRITE 0x20
|
||||
#define O_DENYREAD 0x30
|
||||
#define O_DENYNONE 0x40
|
||||
|
131
Borland Turbo C v2/INCLUDE/FLOAT.H
Normal file
131
Borland Turbo C v2/INCLUDE/FLOAT.H
Normal file
@ -0,0 +1,131 @@
|
||||
/* float.h
|
||||
|
||||
Defines implementation specific macros for dealing with
|
||||
floating point.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#define FLT_RADIX 2
|
||||
#define FLT_ROUNDS 1
|
||||
#define FLT_GUARD 1
|
||||
#define FLT_NORMALIZE 1
|
||||
|
||||
#define DBL_DIG 15
|
||||
#define FLT_DIG 6
|
||||
#define LDBL_DIG 19
|
||||
|
||||
#define DBL_MANT_DIG 53
|
||||
#define FLT_MANT_DIG 24
|
||||
#define LDBL_MANT_DIG 64
|
||||
|
||||
#define DBL_EPSILON 2.2204460492503131E-16
|
||||
#define FLT_EPSILON 1.19209290E-07F
|
||||
#define LDBL_EPSILON 1.084202172485504E-19
|
||||
|
||||
/* smallest positive IEEE normal numbers */
|
||||
#define DBL_MIN 2.2250738585072014E-308
|
||||
#define FLT_MIN 1.17549435E-38F
|
||||
#define LDBL_MIN _tiny_ldble
|
||||
|
||||
#define DBL_MAX _huge_dble
|
||||
#define FLT_MAX _huge_flt
|
||||
#define LDBL_MAX _huge_ldble
|
||||
|
||||
#define DBL_MAX_EXP +1024
|
||||
#define FLT_MAX_EXP +128
|
||||
#define LDBL_MAX_EXP +16384
|
||||
|
||||
#define DBL_MAX_10_EXP +308
|
||||
#define FLT_MAX_10_EXP +38
|
||||
#define LDBL_MAX_10_EXP +4932
|
||||
|
||||
#define DBL_MIN_10_EXP -307
|
||||
#define FLT_MIN_10_EXP -37
|
||||
#define LDBL_MIN_10_EXP -4931
|
||||
|
||||
#define DBL_MIN_EXP -1021
|
||||
#define FLT_MIN_EXP -125
|
||||
#define LDBL_MIN_EXP -16381
|
||||
|
||||
extern float _Cdecl _huge_flt;
|
||||
extern double _Cdecl _huge_dble;
|
||||
extern long double _Cdecl _huge_ldble;
|
||||
extern long double _Cdecl _tiny_ldble;
|
||||
|
||||
unsigned int _Cdecl _clear87(void);
|
||||
unsigned int _Cdecl _control87(unsigned int new, unsigned int mask);
|
||||
void _Cdecl _fpreset(void);
|
||||
unsigned int _Cdecl _status87(void);
|
||||
|
||||
/* 8087/80287 Status Word format */
|
||||
|
||||
#define SW_INVALID 0x0001 /* Invalid operation */
|
||||
#define SW_DENORMAL 0x0002 /* Denormalized operand */
|
||||
#define SW_ZERODIVIDE 0x0004 /* Zero divide */
|
||||
#define SW_OVERFLOW 0x0008 /* Overflow */
|
||||
#define SW_UNDERFLOW 0x0010 /* Underflow */
|
||||
#define SW_INEXACT 0x0020 /* Precision (Inexact result) */
|
||||
|
||||
/* 8087/80287 Control Word format */
|
||||
|
||||
#define MCW_EM 0x003f /* interrupt Exception Masks */
|
||||
#define EM_INVALID 0x0001 /* invalid */
|
||||
#define EM_DENORMAL 0x0002 /* denormal */
|
||||
#define EM_ZERODIVIDE 0x0004 /* zero divide */
|
||||
#define EM_OVERFLOW 0x0008 /* overflow */
|
||||
#define EM_UNDERFLOW 0x0010 /* underflow */
|
||||
#define EM_INEXACT 0x0020 /* inexact (precision) */
|
||||
|
||||
#define MCW_IC 0x1000 /* Infinity Control */
|
||||
#define IC_AFFINE 0x1000 /* affine */
|
||||
#define IC_PROJECTIVE 0x0000 /* projective */
|
||||
|
||||
#define MCW_RC 0x0c00 /* Rounding Control */
|
||||
#define RC_CHOP 0x0c00 /* chop */
|
||||
#define RC_UP 0x0800 /* up */
|
||||
#define RC_DOWN 0x0400 /* down */
|
||||
#define RC_NEAR 0x0000 /* near */
|
||||
|
||||
#define MCW_PC 0x0300 /* Precision Control */
|
||||
#define PC_24 0x0000 /* 24 bits */
|
||||
#define PC_53 0x0200 /* 53 bits */
|
||||
#define PC_64 0x0300 /* 64 bits */
|
||||
|
||||
/* 8087/80287 Initial Control Word */
|
||||
/* use affine infinity, mask underflow and precision exceptions */
|
||||
|
||||
#define CW_DEFAULT (RC_NEAR+PC_64+IC_AFFINE+EM_UNDERFLOW+EM_INEXACT)
|
||||
|
||||
/*
|
||||
SIGFPE signal error types (for integer & float exceptions).
|
||||
*/
|
||||
#define FPE_INTOVFLOW 126 /* 80x86 Interrupt on overflow */
|
||||
#define FPE_INTDIV0 127 /* 80x86 Integer divide by zero */
|
||||
|
||||
#define FPE_INVALID 129 /* 80x87 invalid operation */
|
||||
#define FPE_ZERODIVIDE 131 /* 80x87 divide by zero */
|
||||
#define FPE_OVERFLOW 132 /* 80x87 arithmetic overflow */
|
||||
#define FPE_UNDERFLOW 133 /* 80x87 arithmetic underflow */
|
||||
#define FPE_INEXACT 134 /* 80x87 precision loss */
|
||||
#define FPE_EXPLICITGEN 140 /* When SIGFPE is raise()'d */
|
||||
|
||||
/*
|
||||
SIGSEGV signal error types.
|
||||
*/
|
||||
#define SEGV_BOUND 10 /* A BOUND violation (SIGSEGV) */
|
||||
#define SEGV_EXPLICITGEN 11 /* When SIGSEGV is raise()'d */
|
||||
|
||||
/*
|
||||
SIGILL signal error types.
|
||||
*/
|
||||
#define ILL_EXECUTION 20 /* Illegal operation exception */
|
||||
#define ILL_EXPLICITGEN 21 /* When SIGILL is raise()'d */
|
||||
|
||||
|
377
Borland Turbo C v2/INCLUDE/GRAPHICS.H
Normal file
377
Borland Turbo C v2/INCLUDE/GRAPHICS.H
Normal file
@ -0,0 +1,377 @@
|
||||
/* graphics.h
|
||||
|
||||
Definitions for Graphics Package.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__GRAPHX_DEF_)
|
||||
#define __GRAPHX_DEF_
|
||||
|
||||
enum graphics_errors { /* graphresult error return codes */
|
||||
grOk = 0,
|
||||
grNoInitGraph = -1,
|
||||
grNotDetected = -2,
|
||||
grFileNotFound = -3,
|
||||
grInvalidDriver = -4,
|
||||
grNoLoadMem = -5,
|
||||
grNoScanMem = -6,
|
||||
grNoFloodMem = -7,
|
||||
grFontNotFound = -8,
|
||||
grNoFontMem = -9,
|
||||
grInvalidMode = -10,
|
||||
grError = -11, /* generic error */
|
||||
grIOerror = -12,
|
||||
grInvalidFont = -13,
|
||||
grInvalidFontNum = -14,
|
||||
grInvalidVersion = -18
|
||||
};
|
||||
|
||||
enum graphics_drivers { /* define graphics drivers */
|
||||
DETECT, /* requests autodetection */
|
||||
CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, /* 1 - 6 */
|
||||
HERCMONO, ATT400, VGA, PC3270, /* 7 - 10 */
|
||||
CURRENT_DRIVER = -1
|
||||
};
|
||||
|
||||
enum graphics_modes { /* graphics modes for each driver */
|
||||
CGAC0 = 0, /* 320x200 palette 0; 1 page */
|
||||
CGAC1 = 1, /* 320x200 palette 1; 1 page */
|
||||
CGAC2 = 2, /* 320x200 palette 2: 1 page */
|
||||
CGAC3 = 3, /* 320x200 palette 3; 1 page */
|
||||
CGAHI = 4, /* 640x200 1 page */
|
||||
MCGAC0 = 0, /* 320x200 palette 0; 1 page */
|
||||
MCGAC1 = 1, /* 320x200 palette 1; 1 page */
|
||||
MCGAC2 = 2, /* 320x200 palette 2; 1 page */
|
||||
MCGAC3 = 3, /* 320x200 palette 3; 1 page */
|
||||
MCGAMED = 4, /* 640x200 1 page */
|
||||
MCGAHI = 5, /* 640x480 1 page */
|
||||
EGALO = 0, /* 640x200 16 color 4 pages */
|
||||
EGAHI = 1, /* 640x350 16 color 2 pages */
|
||||
EGA64LO = 0, /* 640x200 16 color 1 page */
|
||||
EGA64HI = 1, /* 640x350 4 color 1 page */
|
||||
EGAMONOHI = 0, /* 640x350 64K on card, 1 page - 256K on card, 4 pages */
|
||||
HERCMONOHI = 0, /* 720x348 2 pages */
|
||||
ATT400C0 = 0, /* 320x200 palette 0; 1 page */
|
||||
ATT400C1 = 1, /* 320x200 palette 1; 1 page */
|
||||
ATT400C2 = 2, /* 320x200 palette 2; 1 page */
|
||||
ATT400C3 = 3, /* 320x200 palette 3; 1 page */
|
||||
ATT400MED = 4, /* 640x200 1 page */
|
||||
ATT400HI = 5, /* 640x400 1 page */
|
||||
VGALO = 0, /* 640x200 16 color 4 pages */
|
||||
VGAMED = 1, /* 640x350 16 color 2 pages */
|
||||
VGAHI = 2, /* 640x480 16 color 1 page */
|
||||
PC3270HI = 0, /* 720x350 1 page */
|
||||
IBM8514LO = 0, /* 640x480 256 colors */
|
||||
IBM8514HI = 1 /*1024x768 256 colors */
|
||||
};
|
||||
|
||||
/* Colors for setpalette and setallpalette */
|
||||
|
||||
#if !defined(__COLORS)
|
||||
#define __COLORS
|
||||
|
||||
enum COLORS {
|
||||
BLACK, /* dark colors */
|
||||
BLUE,
|
||||
GREEN,
|
||||
CYAN,
|
||||
RED,
|
||||
MAGENTA,
|
||||
BROWN,
|
||||
LIGHTGRAY,
|
||||
DARKGRAY, /* light colors */
|
||||
LIGHTBLUE,
|
||||
LIGHTGREEN,
|
||||
LIGHTCYAN,
|
||||
LIGHTRED,
|
||||
LIGHTMAGENTA,
|
||||
YELLOW,
|
||||
WHITE
|
||||
};
|
||||
#endif
|
||||
|
||||
enum CGA_COLORS {
|
||||
CGA_LIGHTGREEN = 1, /* Palette C0 Color Names */
|
||||
CGA_LIGHTRED = 2,
|
||||
CGA_YELLOW = 3,
|
||||
|
||||
CGA_LIGHTCYAN = 1, /* Palette C1 Color Names */
|
||||
CGA_LIGHTMAGENTA = 2,
|
||||
CGA_WHITE = 3,
|
||||
|
||||
CGA_GREEN = 1, /* Palette C2 Color Names */
|
||||
CGA_RED = 2,
|
||||
CGA_BROWN = 3,
|
||||
|
||||
CGA_CYAN = 1, /* Palette C3 Color Names */
|
||||
CGA_MAGENTA = 2,
|
||||
CGA_LIGHTGRAY = 3
|
||||
};
|
||||
|
||||
|
||||
enum EGA_COLORS {
|
||||
EGA_BLACK = 0, /* dark colors */
|
||||
EGA_BLUE = 1,
|
||||
EGA_GREEN = 2,
|
||||
EGA_CYAN = 3,
|
||||
EGA_RED = 4,
|
||||
EGA_MAGENTA = 5,
|
||||
EGA_BROWN = 20,
|
||||
EGA_LIGHTGRAY = 7,
|
||||
EGA_DARKGRAY = 56, /* light colors */
|
||||
EGA_LIGHTBLUE = 57,
|
||||
EGA_LIGHTGREEN = 58,
|
||||
EGA_LIGHTCYAN = 59,
|
||||
EGA_LIGHTRED = 60,
|
||||
EGA_LIGHTMAGENTA = 61,
|
||||
EGA_YELLOW = 62,
|
||||
EGA_WHITE = 63
|
||||
};
|
||||
|
||||
enum line_styles { /* Line styles for get/setlinestyle */
|
||||
SOLID_LINE = 0,
|
||||
DOTTED_LINE = 1,
|
||||
CENTER_LINE = 2,
|
||||
DASHED_LINE = 3,
|
||||
USERBIT_LINE = 4, /* User defined line style */
|
||||
};
|
||||
|
||||
enum line_widths { /* Line widths for get/setlinestyle */
|
||||
NORM_WIDTH = 1,
|
||||
THICK_WIDTH = 3,
|
||||
};
|
||||
|
||||
enum font_names {
|
||||
DEFAULT_FONT = 0, /* 8x8 bit mapped font */
|
||||
TRIPLEX_FONT = 1, /* "Stroked" fonts */
|
||||
SMALL_FONT = 2,
|
||||
SANS_SERIF_FONT = 3,
|
||||
GOTHIC_FONT = 4
|
||||
};
|
||||
|
||||
#define HORIZ_DIR 0 /* left to right */
|
||||
#define VERT_DIR 1 /* bottom to top */
|
||||
|
||||
#define USER_CHAR_SIZE 0 /* user-defined char size */
|
||||
|
||||
enum fill_patterns { /* Fill patterns for get/setfillstyle */
|
||||
EMPTY_FILL, /* fills area in background color */
|
||||
SOLID_FILL, /* fills area in solid fill color */
|
||||
LINE_FILL, /* --- fill */
|
||||
LTSLASH_FILL, /* /// fill */
|
||||
SLASH_FILL, /* /// fill with thick lines */
|
||||
BKSLASH_FILL, /* \\\ fill with thick lines */
|
||||
LTBKSLASH_FILL, /* \\\ fill */
|
||||
HATCH_FILL, /* light hatch fill */
|
||||
XHATCH_FILL, /* heavy cross hatch fill */
|
||||
INTERLEAVE_FILL, /* interleaving line fill */
|
||||
WIDE_DOT_FILL, /* Widely spaced dot fill */
|
||||
CLOSE_DOT_FILL, /* Closely spaced dot fill */
|
||||
USER_FILL /* user defined fill */
|
||||
};
|
||||
|
||||
enum putimage_ops { /* BitBlt operators for putimage */
|
||||
COPY_PUT, /* MOV */
|
||||
XOR_PUT, /* XOR */
|
||||
OR_PUT, /* OR */
|
||||
AND_PUT, /* AND */
|
||||
NOT_PUT /* NOT */
|
||||
};
|
||||
|
||||
enum text_just { /* Horizontal and vertical justification
|
||||
for settextjustify */
|
||||
LEFT_TEXT = 0,
|
||||
CENTER_TEXT = 1,
|
||||
RIGHT_TEXT = 2,
|
||||
|
||||
BOTTOM_TEXT = 0,
|
||||
/* CENTER_TEXT = 1, already defined above */
|
||||
TOP_TEXT = 2
|
||||
};
|
||||
|
||||
|
||||
#define MAXCOLORS 15
|
||||
|
||||
struct palettetype {
|
||||
unsigned char size;
|
||||
signed char colors[MAXCOLORS+1];
|
||||
};
|
||||
|
||||
struct linesettingstype {
|
||||
int linestyle;
|
||||
unsigned upattern;
|
||||
int thickness;
|
||||
};
|
||||
|
||||
struct textsettingstype {
|
||||
int font;
|
||||
int direction;
|
||||
int charsize;
|
||||
int horiz;
|
||||
int vert;
|
||||
};
|
||||
|
||||
struct fillsettingstype {
|
||||
int pattern;
|
||||
int color;
|
||||
};
|
||||
|
||||
struct pointtype {
|
||||
int x, y;
|
||||
};
|
||||
|
||||
struct viewporttype {
|
||||
int left, top, right, bottom;
|
||||
int clip;
|
||||
};
|
||||
|
||||
struct arccoordstype {
|
||||
int x, y;
|
||||
int xstart, ystart, xend, yend;
|
||||
};
|
||||
|
||||
void far _Cdecl arc(int x, int y, int stangle, int endangle,
|
||||
int radius);
|
||||
void far _Cdecl bar(int left, int top, int right, int bottom);
|
||||
void far _Cdecl bar3d(int left, int top, int right, int bottom,
|
||||
int depth, int topflag);
|
||||
void far _Cdecl circle(int x, int y, int radius);
|
||||
void far _Cdecl cleardevice(void);
|
||||
void far _Cdecl clearviewport(void);
|
||||
void far _Cdecl closegraph(void);
|
||||
void far _Cdecl detectgraph(int far *graphdriver,int far *graphmode);
|
||||
void far _Cdecl drawpoly(int numpoints, int far *polypoints);
|
||||
void far _Cdecl ellipse(int x, int y, int stangle, int endangle,
|
||||
int xradius, int yradius);
|
||||
void far _Cdecl fillellipse( int x, int y, int xradius, int yradius );
|
||||
void far _Cdecl fillpoly(int numpoints, int far *polypoints);
|
||||
void far _Cdecl floodfill(int x, int y, int border);
|
||||
void far _Cdecl getarccoords(struct arccoordstype far *arccoords);
|
||||
void far _Cdecl getaspectratio(int far *xasp, int far *yasp);
|
||||
int far _Cdecl getbkcolor(void);
|
||||
int far _Cdecl getcolor(void);
|
||||
struct palettetype * far _Cdecl getdefaultpalette( void );
|
||||
char * far _Cdecl getdrivername( void );
|
||||
void far _Cdecl getfillpattern(char far *pattern);
|
||||
void far _Cdecl getfillsettings(struct fillsettingstype far *fillinfo);
|
||||
int far _Cdecl getgraphmode(void);
|
||||
void far _Cdecl getimage(int left, int top, int right, int bottom,
|
||||
void far *bitmap);
|
||||
void far _Cdecl getlinesettings(struct linesettingstype far *lineinfo);
|
||||
int far _Cdecl getmaxcolor(void);
|
||||
int far _Cdecl getmaxmode(void);
|
||||
int far _Cdecl getmaxx(void);
|
||||
int far _Cdecl getmaxy(void);
|
||||
char * far _Cdecl getmodename( int mode_number );
|
||||
void far _Cdecl getmoderange(int graphdriver, int far *lomode,
|
||||
int far *himode);
|
||||
unsigned far _Cdecl getpixel(int x, int y);
|
||||
void far _Cdecl getpalette(struct palettetype far *palette);
|
||||
int far _Cdecl getpalettesize( void );
|
||||
void far _Cdecl gettextsettings(struct textsettingstype far *texttypeinfo);
|
||||
void far _Cdecl getviewsettings(struct viewporttype far *viewport);
|
||||
int far _Cdecl getx(void);
|
||||
int far _Cdecl gety(void);
|
||||
void far _Cdecl graphdefaults(void);
|
||||
char * far _Cdecl grapherrormsg(int errorcode);
|
||||
void far _Cdecl _graphfreemem(void far *ptr, unsigned size);
|
||||
void far * far _Cdecl _graphgetmem(unsigned size);
|
||||
int far _Cdecl graphresult(void);
|
||||
unsigned far _Cdecl imagesize(int left, int top, int right, int bottom);
|
||||
void far _Cdecl initgraph(int far *graphdriver,
|
||||
int far *graphmode,
|
||||
char far *pathtodriver);
|
||||
int far _Cdecl installuserdriver( char far *name, int huge (*detect)(void) );
|
||||
int far _Cdecl installuserfont( char far *name );
|
||||
void far _Cdecl line(int x1, int y1, int x2, int y2);
|
||||
void far _Cdecl linerel(int dx, int dy);
|
||||
void far _Cdecl lineto(int x, int y);
|
||||
void far _Cdecl moverel(int dx, int dy);
|
||||
void far _Cdecl moveto(int x, int y);
|
||||
void far _Cdecl outtext(char far *textstring);
|
||||
void far _Cdecl outtextxy(int x, int y, char far *textstring);
|
||||
void far _Cdecl pieslice(int x, int y, int stangle, int endangle,
|
||||
int radius);
|
||||
void far _Cdecl putimage(int left, int top, void far *bitmap, int op);
|
||||
void far _Cdecl putpixel(int x, int y, int color);
|
||||
void far _Cdecl rectangle(int left, int top, int right, int bottom);
|
||||
void far _Cdecl restorecrtmode(void);
|
||||
void far _Cdecl sector( int X, int Y, int StAngle, int EndAngle,
|
||||
int XRadius, int YRadius );
|
||||
void far _Cdecl setactivepage(int page);
|
||||
void far _Cdecl setallpalette(struct palettetype far *palette);
|
||||
void far _Cdecl setaspectratio( int xasp, int yasp );
|
||||
void far _Cdecl setbkcolor(int color);
|
||||
void far _Cdecl setcolor(int color);
|
||||
void far _Cdecl setfillpattern(char far *upattern, int color);
|
||||
void far _Cdecl setfillstyle(int pattern, int color);
|
||||
unsigned far _Cdecl setgraphbufsize(unsigned bufsize);
|
||||
void far _Cdecl setgraphmode(int mode);
|
||||
void far _Cdecl setlinestyle(int linestyle, unsigned upattern,
|
||||
int thickness);
|
||||
void far _Cdecl setpalette(int colornum, int color);
|
||||
void far _Cdecl setrgbpalette(int colornum,
|
||||
int red, int green, int blue);
|
||||
void far _Cdecl settextjustify(int horiz, int vert);
|
||||
void far _Cdecl settextstyle(int font, int direction, int charsize);
|
||||
void far _Cdecl setusercharsize(int multx, int divx,
|
||||
int multy, int divy);
|
||||
void far _Cdecl setviewport(int left, int top, int right, int bottom,
|
||||
int clip);
|
||||
void far _Cdecl setvisualpage(int page);
|
||||
void far _Cdecl setwritemode( int mode );
|
||||
int far _Cdecl textheight(char far *textstring);
|
||||
int far _Cdecl textwidth(char far *textstring);
|
||||
|
||||
/***** graphics drivers *****/
|
||||
|
||||
int _Cdecl registerbgidriver(void (*driver)(void));
|
||||
int far _Cdecl registerfarbgidriver(void far *driver);
|
||||
|
||||
/* !! These "functions" are NOT user-callable !! */
|
||||
/* !! They are there just so you can link in graphics drivers !! */
|
||||
|
||||
void _Cdecl CGA_driver(void);
|
||||
void _Cdecl EGAVGA_driver(void);
|
||||
void _Cdecl IBM8514_driver(void);
|
||||
void _Cdecl Herc_driver(void);
|
||||
void _Cdecl ATT_driver(void);
|
||||
void _Cdecl PC3270_driver(void);
|
||||
|
||||
extern int far _Cdecl CGA_driver_far[];
|
||||
extern int far _Cdecl EGAVGA_driver_far[];
|
||||
extern int far _Cdecl IBM8514_driver_far[];
|
||||
extern int far _Cdecl Herc_driver_far[];
|
||||
extern int far _Cdecl ATT_driver_far[];
|
||||
extern int far _Cdecl PC3270_driver_far[];
|
||||
|
||||
|
||||
/***** graphics fonts *****/
|
||||
|
||||
int _Cdecl registerbgifont(void (*font)(void));
|
||||
int far _Cdecl registerfarbgifont(void far *font);
|
||||
|
||||
/* !! These "functions" are NOT user-callable, !! */
|
||||
/* !! they are there just so you can link in fonts !! */
|
||||
|
||||
void _Cdecl triplex_font(void);
|
||||
void _Cdecl small_font(void);
|
||||
void _Cdecl sansserif_font(void);
|
||||
void _Cdecl gothic_font(void);
|
||||
|
||||
extern int far _Cdecl triplex_font_far[];
|
||||
extern int far _Cdecl small_font_far[];
|
||||
extern int far _Cdecl sansserif_font_far[];
|
||||
extern int far _Cdecl gothic_font_far[];
|
||||
|
||||
|
||||
#endif
|
||||
|
71
Borland Turbo C v2/INCLUDE/IO.H
Normal file
71
Borland Turbo C v2/INCLUDE/IO.H
Normal file
@ -0,0 +1,71 @@
|
||||
/* io.h
|
||||
|
||||
Definitions for low level I/O functions.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _IO_H
|
||||
#define _IO_H 1
|
||||
|
||||
#define HANDLE_MAX 20U
|
||||
|
||||
extern unsigned int _Cdecl _openfd[];
|
||||
|
||||
struct ftime {
|
||||
unsigned ft_tsec : 5; /* Two second interval */
|
||||
unsigned ft_min : 6; /* Minutes */
|
||||
unsigned ft_hour : 5; /* Hours */
|
||||
unsigned ft_day : 5; /* Days */
|
||||
unsigned ft_month : 4; /* Months */
|
||||
unsigned ft_year : 7; /* Year */
|
||||
};
|
||||
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
#define SEEK_SET 0
|
||||
|
||||
int _Cdecl access (const char *path, int amode);
|
||||
int _Cdecl _chmod (const char *path, int func, ... /* int attr */);
|
||||
int _Cdecl chmod (const char *path, int amode);
|
||||
int _Cdecl chsize (int handle, long size);
|
||||
int _Cdecl _close (int handle);
|
||||
int _Cdecl close (int handle);
|
||||
int _Cdecl _creat (const char *path, int attribute);
|
||||
int _Cdecl creat (const char *path, int amode);
|
||||
int _Cdecl creatnew (const char *path, int mode); /* DOS 3.0 or later */
|
||||
int _Cdecl creattemp (char *path, int amode); /* DOS 3.0 or later */
|
||||
int _Cdecl dup (int handle);
|
||||
int _Cdecl dup2 (int oldhandle, int newhandle);
|
||||
int _Cdecl eof (int handle);
|
||||
long _Cdecl filelength (int handle);
|
||||
int _Cdecl getftime (int handle, struct ftime *ftimep);
|
||||
int _Cdecl ioctl (int handle, int func, ...);
|
||||
/* optional 3rd and 4th args are: void * argdx, int argcx */
|
||||
int _Cdecl isatty (int handle);
|
||||
int _Cdecl lock (int handle, long offset, long length);
|
||||
long _Cdecl lseek (int handle, long offset, int fromwhere);
|
||||
int _Cdecl _open (const char *path, int oflags);
|
||||
int _Cdecl open (const char *path, int access,... /*unsigned mode*/);
|
||||
int _Cdecl _read (int handle, void *buf, unsigned len);
|
||||
int _Cdecl read (int handle, void *buf, unsigned len);
|
||||
int _Cdecl setftime (int handle, struct ftime *ftimep);
|
||||
int _Cdecl setmode (int handle, int amode);
|
||||
long _Cdecl tell (int handle);
|
||||
unsigned _Cdecl umask (unsigned cmask);
|
||||
int _Cdecl unlink (const char *path);
|
||||
int _Cdecl unlock (int handle, long offset, long length);
|
||||
int _Cdecl _write (int handle, void *buf, unsigned len);
|
||||
int _Cdecl write (int handle, void *buf, unsigned len);
|
||||
|
||||
/* macros for compatibility with earlier versions & other compilers. */
|
||||
#define sopen(path,access,shflag,mode) open (path, (access)|(shflag), mode)
|
||||
|
||||
#endif /* _IO_H */
|
||||
|
39
Borland Turbo C v2/INCLUDE/LIMITS.H
Normal file
39
Borland Turbo C v2/INCLUDE/LIMITS.H
Normal file
@ -0,0 +1,39 @@
|
||||
/* limits.h
|
||||
|
||||
Defines implementation specific limits on type values.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#define CHAR_BIT 8
|
||||
|
||||
#if (((int)((char)0x80)) < 0)
|
||||
#define CHAR_MAX 0x7F
|
||||
#define CHAR_MIN 0x80
|
||||
#else
|
||||
#define CHAR_MAX 0xFFU
|
||||
#define CHAR_MIN 0x00
|
||||
#endif
|
||||
|
||||
#define SCHAR_MAX 0x7F
|
||||
#define SCHAR_MIN -128
|
||||
#define UCHAR_MAX 0xFFU
|
||||
|
||||
#define SHRT_MAX 0x7FFF
|
||||
#define SHRT_MIN ((int)0x8000)
|
||||
#define USHRT_MAX 0xFFFFU
|
||||
|
||||
#define INT_MAX 0x7FFF
|
||||
#define INT_MIN ((int)0x8000)
|
||||
#define UINT_MAX 0xFFFFU
|
||||
|
||||
#define LONG_MAX 0x7FFFFFFFL
|
||||
#define LONG_MIN ((long)0x80000000L)
|
||||
#define ULONG_MAX 0xFFFFFFFFUL
|
||||
|
59
Borland Turbo C v2/INCLUDE/MALLOC.H
Normal file
59
Borland Turbo C v2/INCLUDE/MALLOC.H
Normal file
@ -0,0 +1,59 @@
|
||||
/* alloc.h
|
||||
|
||||
memory management functions and variables.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _STDDEF
|
||||
#define _STDDEF
|
||||
#ifndef _PTRDIFF_T
|
||||
#define _PTRDIFF_T
|
||||
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
|
||||
typedef long ptrdiff_t;
|
||||
#else
|
||||
typedef int ptrdiff_t;
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL 0L
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int _Cdecl brk (void *addr);
|
||||
void *_Cdecl calloc (size_t nitems, size_t size);
|
||||
|
||||
#if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
|
||||
unsigned long _Cdecl coreleft (void);
|
||||
#else
|
||||
unsigned _Cdecl coreleft (void);
|
||||
#endif
|
||||
|
||||
void _Cdecl free (void *block);
|
||||
void *_Cdecl malloc (size_t size);
|
||||
void *_Cdecl realloc (void *block, size_t size);
|
||||
void *_Cdecl sbrk (int incr);
|
||||
|
||||
#if !__STDC__
|
||||
void far * _Cdecl farcalloc (unsigned long nunits, unsigned long unitsz);
|
||||
unsigned long _Cdecl farcoreleft(void);
|
||||
void _Cdecl farfree (void far *block);
|
||||
void far *_Cdecl farmalloc (unsigned long nbytes);
|
||||
void far *_Cdecl farrealloc (void far *oldblock, unsigned long nbytes);
|
||||
#endif
|
||||
|
107
Borland Turbo C v2/INCLUDE/MATH.H
Normal file
107
Borland Turbo C v2/INCLUDE/MATH.H
Normal file
@ -0,0 +1,107 @@
|
||||
/* math.h
|
||||
|
||||
Definitions for the math floating point package.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _MATH_H
|
||||
#define _MATH_H 1
|
||||
|
||||
#define EDOM 33 /* Math argument */
|
||||
#define ERANGE 34 /* Result too large */
|
||||
|
||||
#define HUGE_VAL _huge_dble
|
||||
extern double _Cdecl _huge_dble;
|
||||
|
||||
int _Cdecl abs (int x);
|
||||
double _Cdecl acos (double x);
|
||||
double _Cdecl asin (double x);
|
||||
double _Cdecl atan (double x);
|
||||
double _Cdecl atan2 (double y, double x);
|
||||
double _Cdecl atof (const char *s);
|
||||
double _Cdecl ceil (double x);
|
||||
double _Cdecl cos (double x);
|
||||
double _Cdecl cosh (double x);
|
||||
double _Cdecl exp (double x);
|
||||
double _Cdecl fabs (double x);
|
||||
double _Cdecl floor (double x);
|
||||
double _Cdecl fmod (double x, double y);
|
||||
double _Cdecl frexp (double x, int *exponent);
|
||||
long _Cdecl labs (long x);
|
||||
double _Cdecl ldexp (double x, int exponent);
|
||||
double _Cdecl log (double x);
|
||||
double _Cdecl log10 (double x);
|
||||
double _Cdecl modf (double x, double *ipart);
|
||||
double _Cdecl pow (double x, double y);
|
||||
double _Cdecl sin (double x);
|
||||
double _Cdecl sinh (double x);
|
||||
double _Cdecl sqrt (double x);
|
||||
double _Cdecl tan (double x);
|
||||
double _Cdecl tanh (double x);
|
||||
|
||||
struct exception
|
||||
{
|
||||
int type;
|
||||
char *name;
|
||||
double arg1, arg2, retval;
|
||||
};
|
||||
|
||||
int _Cdecl matherr (struct exception *e);
|
||||
|
||||
#if !__STDC__
|
||||
double cdecl hypot (double x, double y);
|
||||
double cdecl poly (double x, int degree, double coeffs []);
|
||||
double cdecl pow10 (int p);
|
||||
|
||||
struct complex /* as used by "cabs" function */
|
||||
{
|
||||
double x, y;
|
||||
};
|
||||
|
||||
#define cabs(z) (hypot ((z).x, (z).y))
|
||||
|
||||
/* The customary matherr() exception handler for maths functions is
|
||||
not compatible with the x3j11 draft standard for C. _matherr() is
|
||||
provided as a compromise.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DOMAIN = 1, /* argument domain error -- log (-1) */
|
||||
SING, /* argument singularity -- pow (0,-2)) */
|
||||
OVERFLOW, /* overflow range error -- exp (1000) */
|
||||
UNDERFLOW, /* underflow range error -- exp (-1000) */
|
||||
TLOSS, /* total loss of significance -- sin(10e70) */
|
||||
PLOSS, /* partial loss of signif. -- not used */
|
||||
} _mexcep;
|
||||
|
||||
double _Cdecl _matherr (_mexcep why, char *fun, double *arg1p,
|
||||
double *arg2p, double retval);
|
||||
|
||||
/* Constants rounded for 21 decimals. */
|
||||
#define M_E 2.71828182845904523536
|
||||
#define M_LOG2E 1.44269504088896340736
|
||||
#define M_LOG10E 0.434294481903251827651
|
||||
#define M_LN2 0.693147180559945309417
|
||||
#define M_LN10 2.30258509299404568402
|
||||
#define M_PI 3.14159265358979323846
|
||||
#define M_PI_2 1.57079632679489661923
|
||||
#define M_PI_4 0.785398163397448309116
|
||||
#define M_1_PI 0.318309886183790671538
|
||||
#define M_2_PI 0.636619772367581343076
|
||||
#define M_1_SQRTPI 0.564189583547756286948
|
||||
#define M_2_SQRTPI 1.12837916709551257390
|
||||
#define M_SQRT2 1.41421356237309504880
|
||||
#define M_SQRT_2 0.707106781186547524401
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif
|
||||
|
49
Borland Turbo C v2/INCLUDE/MEM.H
Normal file
49
Borland Turbo C v2/INCLUDE/MEM.H
Normal file
@ -0,0 +1,49 @@
|
||||
/* mem.h
|
||||
|
||||
Memory manipulation functions
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _STDDEF
|
||||
#define _STDDEF
|
||||
#ifndef _PTRDIFF_T
|
||||
#define _PTRDIFF_T
|
||||
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
|
||||
typedef long ptrdiff_t;
|
||||
#else
|
||||
typedef int ptrdiff_t;
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL 0L
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void *_Cdecl memccpy(void *dest, const void *src, int c, size_t n);
|
||||
void *_Cdecl memchr (const void *s, int c, size_t n);
|
||||
int _Cdecl memcmp (const void *s1, const void *s2, size_t n);
|
||||
void *_Cdecl memcpy (void *dest, const void *src, size_t n);
|
||||
int _Cdecl memicmp (const void *s1, const void *s2, size_t n);
|
||||
void *_Cdecl memmove (void *dest, const void *src, size_t n);
|
||||
void *_Cdecl memset (void *s, int c, size_t n);
|
||||
void _Cdecl movedata (unsigned srcseg, unsigned srcoff, unsigned dstseg,
|
||||
unsigned dstoff, size_t n);
|
||||
void _Cdecl movmem (void *src, void *dest, unsigned length);
|
||||
void _Cdecl setmem (void *dest, unsigned length, char value);
|
||||
|
52
Borland Turbo C v2/INCLUDE/PROCESS.H
Normal file
52
Borland Turbo C v2/INCLUDE/PROCESS.H
Normal file
@ -0,0 +1,52 @@
|
||||
/* process.h
|
||||
|
||||
Symbols and structures for process management.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
/* Modes available as first argument to the spawnxx functions. */
|
||||
|
||||
#define P_WAIT 0 /* child runs separately, parent waits until exit */
|
||||
#define P_NOWAIT 1 /* both concurrent -- not implemented */
|
||||
#define P_OVERLAY 2 /* child replaces parent, parent no longer exists */
|
||||
|
||||
|
||||
/* MSDOS does not have any abstract identifier for a process, but the
|
||||
process Program Segment Prefix location provides a similar token.
|
||||
*/
|
||||
|
||||
#ifndef _psp
|
||||
extern unsigned _Cdecl _psp; /* provided unconditionally in dos.h */
|
||||
#endif
|
||||
|
||||
#define getpid() (_psp)
|
||||
|
||||
void _Cdecl abort(void);
|
||||
int _Cdecl execl(char *path, char *arg0, ...);
|
||||
int _Cdecl execle(char *path, char *arg0, ...);
|
||||
int _Cdecl execlp(char *path, char *arg0, ...);
|
||||
int _Cdecl execlpe(char *path, char *arg0, ...);
|
||||
int _Cdecl execv(char *path, char *argv[]);
|
||||
int _Cdecl execve(char *path, char *argv[], char **env);
|
||||
int _Cdecl execvp(char *path, char *argv[]);
|
||||
int _Cdecl execvpe(char *path, char *argv[], char **env);
|
||||
void _Cdecl exit(int status);
|
||||
void _Cdecl _exit(int status);
|
||||
int _Cdecl spawnl(int mode, char *path, char *arg0, ...);
|
||||
int _Cdecl spawnle(int mode, char *path, char *arg0, ...);
|
||||
int _Cdecl spawnlp(int mode, char *path, char *arg0, ...);
|
||||
int _Cdecl spawnlpe(int mode, char *path, char *arg0, ...);
|
||||
int _Cdecl spawnv(int mode, char *path, char *argv[]);
|
||||
int _Cdecl spawnve(int mode, char *path, char *argv[], char **env);
|
||||
int _Cdecl spawnvp(int mode, char *path, char *argv[]);
|
||||
int _Cdecl spawnvpe(int mode, char *path, char *argv[], char **env);
|
||||
int _Cdecl system(const char *command);
|
||||
|
||||
|
33
Borland Turbo C v2/INCLUDE/SETJMP.H
Normal file
33
Borland Turbo C v2/INCLUDE/SETJMP.H
Normal file
@ -0,0 +1,33 @@
|
||||
/* setjmp.h
|
||||
|
||||
Defines typedef and functions for setjmp/longjmp.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _SETJMP
|
||||
#define _SETJMP
|
||||
typedef struct {
|
||||
unsigned j_sp;
|
||||
unsigned j_ss;
|
||||
unsigned j_flag;
|
||||
unsigned j_cs;
|
||||
unsigned j_ip;
|
||||
unsigned j_bp;
|
||||
unsigned j_di;
|
||||
unsigned j_es;
|
||||
unsigned j_si;
|
||||
unsigned j_ds;
|
||||
} jmp_buf[1];
|
||||
|
||||
void _Cdecl longjmp(jmp_buf jmpb, int retval);
|
||||
int _Cdecl setjmp(jmp_buf jmpb);
|
||||
#endif
|
||||
|
||||
|
22
Borland Turbo C v2/INCLUDE/SHARE.H
Normal file
22
Borland Turbo C v2/INCLUDE/SHARE.H
Normal file
@ -0,0 +1,22 @@
|
||||
/* share.h
|
||||
|
||||
File sharing mode for use with sopen.
|
||||
See DOS function 3Dh for definition.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#define SH_COMPAT 0x0000
|
||||
#define SH_DENYRW 0x0010
|
||||
#define SH_DENYWR 0x0020
|
||||
#define SH_DENYRD 0x0030
|
||||
#define SH_DENYNONE 0x0040
|
||||
|
||||
#define SH_DENYNO SH_DENYNONE /* MS documentation uses both */
|
||||
|
49
Borland Turbo C v2/INCLUDE/SIGNAL.H
Normal file
49
Borland Turbo C v2/INCLUDE/SIGNAL.H
Normal file
@ -0,0 +1,49 @@
|
||||
/* signal.h
|
||||
|
||||
Definitions for ANSI defined signaling capability
|
||||
|
||||
Copyright (c) Borland International 1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __SIGNAL_H
|
||||
#define __SIGNAL_H
|
||||
|
||||
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
|
||||
|
||||
#define SIG_DFL ((void (* _Cdecl)(int))0) /* Default action */
|
||||
#define SIG_IGN ((void (* _Cdecl)(int))1) /* Ignore action */
|
||||
|
||||
#ifdef __OS2__
|
||||
#define SIG_SGE ((void (* _Cdecl)(int))3) /* Signal gets error */
|
||||
#define SIG_ACK ((void (* _Cdecl)(int))4) /* Signal acknowlege */
|
||||
#endif
|
||||
|
||||
#define SIG_ERR ((void (* _Cdecl)(int))-1) /* Error return */
|
||||
|
||||
#define SIGABRT 22
|
||||
#define SIGFPE 8 /* Floating point trap */
|
||||
#define SIGILL 4 /* Illegal instruction */
|
||||
#define SIGINT 2
|
||||
#define SIGSEGV 11 /* Memory access violation */
|
||||
#define SIGTERM 15
|
||||
|
||||
#ifdef __OS2__
|
||||
#define SIGBREAK 21 /* OS/2 Ctrl-Brk signal */
|
||||
#define SIGUSR1 16 /* OS/2 process flag A */
|
||||
#define SIGUSR2 17 /* OS/2 process flag B */
|
||||
#define SIGUSR3 20 /* OS/2 process flag C */
|
||||
#endif
|
||||
|
||||
int _Cdecl raise(int sig);
|
||||
void (* _Cdecl signal(int sig, void (*func)(/* int */))) (int);
|
||||
|
||||
#endif
|
||||
|
25
Borland Turbo C v2/INCLUDE/STDARG.H
Normal file
25
Borland Turbo C v2/INCLUDE/STDARG.H
Normal file
@ -0,0 +1,25 @@
|
||||
/* stdarg.h
|
||||
|
||||
Definitions for accessing parameters in functions that accept
|
||||
a variable number of arguments.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__STDARG)
|
||||
#define __STDARG
|
||||
|
||||
typedef void *va_list;
|
||||
|
||||
#define va_start(ap, parmN) (ap = ...)
|
||||
#define va_arg(ap, type) (*((type *)(ap))++)
|
||||
#define va_end(ap)
|
||||
#define _va_ptr (...)
|
||||
#endif
|
||||
|
40
Borland Turbo C v2/INCLUDE/STDDEF.H
Normal file
40
Borland Turbo C v2/INCLUDE/STDDEF.H
Normal file
@ -0,0 +1,40 @@
|
||||
/* stddef.h
|
||||
|
||||
Definitions for common types, NULL, and errno.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _STDDEF
|
||||
#define _STDDEF
|
||||
#ifndef _PTRDIFF_T
|
||||
#define _PTRDIFF_T
|
||||
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
|
||||
typedef long ptrdiff_t;
|
||||
#else
|
||||
typedef int ptrdiff_t;
|
||||
#endif
|
||||
#endif
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL 0L
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern int _Cdecl errno;
|
||||
|
||||
#endif
|
||||
|
187
Borland Turbo C v2/INCLUDE/STDIO.H
Normal file
187
Borland Turbo C v2/INCLUDE/STDIO.H
Normal file
@ -0,0 +1,187 @@
|
||||
/* stdio.h
|
||||
|
||||
Definitions for stream input/output.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__STDIO_DEF_)
|
||||
#define __STDIO_DEF_
|
||||
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
#ifndef NULL
|
||||
# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
# define NULL 0
|
||||
# else
|
||||
# define NULL 0L
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(__STDARG)
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
/* Definition of the file position type
|
||||
*/
|
||||
typedef long fpos_t;
|
||||
|
||||
/* Definition of the control structure for streams
|
||||
*/
|
||||
typedef struct {
|
||||
short level; /* fill/empty level of buffer */
|
||||
unsigned flags; /* File status flags */
|
||||
char fd; /* File descriptor */
|
||||
unsigned char hold; /* Ungetc char if no buffer */
|
||||
short bsize; /* Buffer size */
|
||||
unsigned char *buffer; /* Data transfer buffer */
|
||||
unsigned char *curp; /* Current active pointer */
|
||||
unsigned istemp; /* Temporary file indicator */
|
||||
short token; /* Used for validity checking */
|
||||
} FILE; /* This is the FILE object */
|
||||
|
||||
/* Bufferisation type to be used as 3rd argument for "setvbuf" function
|
||||
*/
|
||||
#define _IOFBF 0
|
||||
#define _IOLBF 1
|
||||
#define _IONBF 2
|
||||
|
||||
/* "flags" bits definitions
|
||||
*/
|
||||
#define _F_RDWR 0x0003 /* Read/write flag */
|
||||
#define _F_READ 0x0001 /* Read only file */
|
||||
#define _F_WRIT 0x0002 /* Write only file */
|
||||
#define _F_BUF 0x0004 /* Malloc'ed Buffer data */
|
||||
#define _F_LBUF 0x0008 /* line-buffered file */
|
||||
#define _F_ERR 0x0010 /* Error indicator */
|
||||
#define _F_EOF 0x0020 /* EOF indicator */
|
||||
#define _F_BIN 0x0040 /* Binary file indicator */
|
||||
#define _F_IN 0x0080 /* Data is incoming */
|
||||
#define _F_OUT 0x0100 /* Data is outgoing */
|
||||
#define _F_TERM 0x0200 /* File is a terminal */
|
||||
|
||||
/* End-of-file constant definition
|
||||
*/
|
||||
#define EOF (-1) /* End of file indicator */
|
||||
|
||||
/* Number of files that can be open simultaneously
|
||||
*/
|
||||
#define OPEN_MAX 20 /* Total of 20 open files */
|
||||
#define SYS_OPEN 20
|
||||
|
||||
/* Default buffer size use by "setbuf" function
|
||||
*/
|
||||
#define BUFSIZ 512 /* Buffer size for stdio */
|
||||
|
||||
/* Size of an arry large enough to hold a temporary file name string
|
||||
*/
|
||||
#define L_ctermid 5 /* CON: plus null byte */
|
||||
#define L_tmpnam 13 /* tmpnam buffer size */
|
||||
|
||||
/* Constants to be used as 3rd argument for "fseek" function
|
||||
*/
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
#define SEEK_SET 0
|
||||
|
||||
/* Number of unique file names that shall be generated by "tmpnam" function
|
||||
*/
|
||||
#define TMP_MAX 0xFFFF
|
||||
|
||||
/* Standard I/O predefined streams
|
||||
*/
|
||||
extern FILE _Cdecl _streams[];
|
||||
|
||||
#define stdin (&_streams[0])
|
||||
#define stdout (&_streams[1])
|
||||
#define stderr (&_streams[2])
|
||||
#define stdaux (&_streams[3])
|
||||
#define stdprn (&_streams[4])
|
||||
|
||||
void _Cdecl clearerr (FILE *stream);
|
||||
int _Cdecl fclose (FILE *stream);
|
||||
int _Cdecl fflush (FILE *stream);
|
||||
int _Cdecl fgetc (FILE *stream);
|
||||
int _Cdecl fgetpos (FILE *stream, fpos_t *pos);
|
||||
char *_Cdecl fgets (char *s, int n, FILE *stream);
|
||||
FILE *_Cdecl fopen (const char *path, const char *mode);
|
||||
int _Cdecl fprintf (FILE *stream, const char *format, ...);
|
||||
int _Cdecl fputc (int c, FILE *stream);
|
||||
int _Cdecl fputs (const char *s, FILE *stream);
|
||||
size_t _Cdecl fread (void *ptr, size_t size, size_t n, FILE *stream);
|
||||
FILE *_Cdecl freopen (const char *path, const char *mode,
|
||||
FILE *stream);
|
||||
int _Cdecl fscanf (FILE *stream, const char *format, ...);
|
||||
int _Cdecl fseek (FILE *stream, long offset, int whence);
|
||||
int _Cdecl fsetpos (FILE *stream, const fpos_t *pos);
|
||||
long _Cdecl ftell (FILE *stream);
|
||||
size_t _Cdecl fwrite (const void *ptr, size_t size, size_t n,
|
||||
FILE *stream);
|
||||
char *_Cdecl gets (char *s);
|
||||
void _Cdecl perror (const char *s);
|
||||
int _Cdecl printf (const char *format, ...);
|
||||
int _Cdecl puts (const char *s);
|
||||
int _Cdecl rename (const char *oldname, const char *newname);
|
||||
void _Cdecl rewind (FILE *stream);
|
||||
int _Cdecl scanf (const char *format, ...);
|
||||
void _Cdecl setbuf (FILE *stream, char *buf);
|
||||
int _Cdecl setvbuf (FILE *stream, char *buf, int type, size_t size);
|
||||
int _Cdecl sprintf (char *buffer, const char *format, ...);
|
||||
int _Cdecl sscanf (const char *buffer, const char *format, ...);
|
||||
char *_Cdecl strerror (int errnum);
|
||||
FILE *_Cdecl tmpfile (void);
|
||||
char *_Cdecl tmpnam (char *s);
|
||||
int _Cdecl ungetc (int c, FILE *stream);
|
||||
int _Cdecl vfprintf (FILE *stream, const char *format, va_list arglist);
|
||||
int _Cdecl vfscanf (FILE *stream, const char *format, va_list arglist);
|
||||
int _Cdecl vprintf (const char *format, va_list arglist);
|
||||
int _Cdecl vscanf (const char *format, va_list arglist);
|
||||
int _Cdecl vsprintf (char *buffer, const char *format, va_list arglist);
|
||||
int _Cdecl vsscanf (const char *buffer, const char *format, va_list arglist);
|
||||
|
||||
#if !__STDC__
|
||||
int _Cdecl fcloseall(void);
|
||||
FILE *_Cdecl fdopen (int handle, char *type);
|
||||
int _Cdecl fgetchar (void);
|
||||
int _Cdecl flushall (void);
|
||||
int _Cdecl fputchar (int c);
|
||||
int _Cdecl getw (FILE *stream);
|
||||
int _Cdecl putw (int w, FILE *stream);
|
||||
char *_Cdecl _strerror(const char *s);
|
||||
int _Cdecl unlink (const char *path);
|
||||
|
||||
#endif
|
||||
|
||||
int _Cdecl _fgetc (FILE *stream); /* used by getc() macro */
|
||||
int _Cdecl _fputc (char c, FILE *stream); /* used by putc() macro */
|
||||
|
||||
/* The following macros provide for common functions */
|
||||
|
||||
#define ferror(f) ((f)->flags & _F_ERR)
|
||||
#define feof(f) ((f)->flags & _F_EOF)
|
||||
#define fileno(f) ((f)->fd)
|
||||
#define remove(path) unlink(path)
|
||||
|
||||
#define getc(f) \
|
||||
((--((f)->level) >= 0) ? (unsigned char)(++(f)->curp)[-1] : \
|
||||
_fgetc (f))
|
||||
#define putc(c,f) \
|
||||
((++((f)->level) < 0) ? (unsigned char)((++(f)->curp)[-1]=(c)) : \
|
||||
_fputc ((c),f))
|
||||
|
||||
#define getchar() getc(stdin)
|
||||
#define putchar(c) putc((c), stdout)
|
||||
|
||||
#define ungetc(c,f) ungetc((c),f) /* traditionally a macro */
|
||||
|
||||
#endif
|
||||
|
||||
|
132
Borland Turbo C v2/INCLUDE/STDLIB.H
Normal file
132
Borland Turbo C v2/INCLUDE/STDLIB.H
Normal file
@ -0,0 +1,132 @@
|
||||
/* stdlib.h
|
||||
|
||||
Definitions for common types, variables, and functions.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#if !defined(__STDLIB)
|
||||
#define __STDLIB
|
||||
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
|
||||
#ifndef _DIV_T
|
||||
#define _DIV_T
|
||||
typedef struct {
|
||||
int quot;
|
||||
int rem;
|
||||
} div_t;
|
||||
#endif
|
||||
|
||||
#ifndef _LDIV_T
|
||||
#define _LDIV_T
|
||||
typedef struct {
|
||||
long quot;
|
||||
long rem;
|
||||
} ldiv_t;
|
||||
#endif
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
|
||||
/* Maximum value returned by "rand" function
|
||||
*/
|
||||
#define RAND_MAX 0x7FFF
|
||||
|
||||
typedef void _Cdecl (* atexit_t)(void);
|
||||
|
||||
void _Cdecl abort (void);
|
||||
int _Cdecl abs (int x);
|
||||
int _Cdecl atexit (atexit_t func);
|
||||
double _Cdecl atof (const char *s);
|
||||
int _Cdecl atoi (const char *s);
|
||||
long _Cdecl atol (const char *s);
|
||||
void *_Cdecl bsearch(const void *key, const void *base,
|
||||
size_t nelem, size_t width,
|
||||
int _Cdecl (*fcmp)(/* const void *, const void * */));
|
||||
void *_Cdecl calloc (size_t nitems, size_t size);
|
||||
div_t _Cdecl div (int numer, int denom);
|
||||
void _Cdecl exit (int status);
|
||||
void _Cdecl free (void *block);
|
||||
char *_Cdecl getenv (const char *name);
|
||||
long _Cdecl labs (long x);
|
||||
ldiv_t _Cdecl ldiv (long numer, long denom);
|
||||
void *_Cdecl malloc (size_t size);
|
||||
void _Cdecl qsort (void *base, size_t nelem, size_t width,
|
||||
int _Cdecl (*fcmp)(/* const void *, const void * */));
|
||||
int _Cdecl rand (void);
|
||||
void *_Cdecl realloc(void *block, size_t size);
|
||||
void _Cdecl srand (unsigned seed);
|
||||
double _Cdecl strtod (const char *s, char **endptr);
|
||||
long _Cdecl strtol (const char *s, char **endptr, int radix);
|
||||
unsigned long _Cdecl strtoul (const char *s, char **endptr, int radix);
|
||||
int _Cdecl system (const char *command);
|
||||
|
||||
#if !__STDC__
|
||||
|
||||
#ifndef NULL
|
||||
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL 0L
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Variables */
|
||||
extern int _Cdecl _doserrno;
|
||||
extern char **_Cdecl environ;
|
||||
extern int _Cdecl errno;
|
||||
extern int _Cdecl _fmode;
|
||||
extern unsigned char _Cdecl _osmajor;
|
||||
extern unsigned char _Cdecl _osminor;
|
||||
extern unsigned _Cdecl _psp;
|
||||
extern char *_Cdecl sys_errlist[];
|
||||
extern int _Cdecl sys_nerr;
|
||||
extern unsigned int _Cdecl _version;
|
||||
|
||||
int _Cdecl __abs__(int x); /* This is an in-line function */
|
||||
#define abs(x) __abs__(x)
|
||||
#define atoi(s) ((int) atol (s))
|
||||
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#define random(num) (rand() % (num))
|
||||
#define randomize() srand((unsigned)time(NULL))
|
||||
|
||||
char *_Cdecl ecvt (double value, int ndig, int *dec, int *sign);
|
||||
void _Cdecl _exit (int status);
|
||||
char *_Cdecl fcvt (double value, int ndig, int *dec, int *sign);
|
||||
char *_Cdecl gcvt (double value, int ndec, char *buf);
|
||||
char *_Cdecl itoa (int value, char *string, int radix);
|
||||
void *_Cdecl lfind (const void *key, const void *base,
|
||||
size_t *num, size_t width,
|
||||
int _Cdecl (*fcmp)(/* const void *, const void * */));
|
||||
|
||||
unsigned long _Cdecl _lrotl(unsigned long val, int count);
|
||||
unsigned long _Cdecl _lrotr(unsigned long val, int count);
|
||||
|
||||
void *_Cdecl lsearch (const void *key, void *base,
|
||||
size_t *num, size_t width,
|
||||
int _Cdecl (*fcmp)(/* const void *, const void * */));
|
||||
char *_Cdecl ltoa (long value, char *string, int radix);
|
||||
int _Cdecl putenv (const char *name);
|
||||
|
||||
unsigned _Cdecl _rotl (unsigned value, int count);
|
||||
unsigned _Cdecl _rotr (unsigned value, int count);
|
||||
|
||||
void _Cdecl swab (char *from, char *to, int nbytes);
|
||||
char *_Cdecl ultoa (unsigned long value, char *string, int radix);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
61
Borland Turbo C v2/INCLUDE/STRING.H
Normal file
61
Borland Turbo C v2/INCLUDE/STRING.H
Normal file
@ -0,0 +1,61 @@
|
||||
/* string.h
|
||||
|
||||
Definitions for memory and string functions.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned size_t;
|
||||
#endif
|
||||
|
||||
void *_Cdecl memccpy (void *dest, const void *src, int c, size_t n);
|
||||
void *_Cdecl memchr (const void *s, int c, size_t n);
|
||||
int _Cdecl memcmp (const void *s1, const void *s2, size_t n);
|
||||
void *_Cdecl memcpy (void *dest, const void *src, size_t n);
|
||||
int _Cdecl memicmp (const void *s1, const void *s2, size_t n);
|
||||
void *_Cdecl memmove (void *dest, const void *src, size_t n);
|
||||
void *_Cdecl memset (void *s, int c, size_t n);
|
||||
void _Cdecl movedata(unsigned srcseg, unsigned srcoff, unsigned dstseg,
|
||||
unsigned dstoff, size_t n);
|
||||
char *_Cdecl stpcpy (char *dest, const char *src);
|
||||
char *_Cdecl strcat (char *dest, const char *src);
|
||||
char *_Cdecl strchr (const char *s, int c);
|
||||
int _Cdecl strcmp (const char *s1, const char *s2);
|
||||
char *_Cdecl strcpy (char *dest, const char *src);
|
||||
size_t _Cdecl strcspn (const char *s1, const char *s2);
|
||||
char *_Cdecl strdup (const char *s);
|
||||
char *_Cdecl strerror(int errnum);
|
||||
int _Cdecl stricmp (const char *s1, const char *s2);
|
||||
size_t _Cdecl strlen (const char *s);
|
||||
char *_Cdecl strlwr (char *s);
|
||||
char *_Cdecl strncat (char *dest, const char *src, size_t maxlen);
|
||||
int _Cdecl strncmp (const char *s1, const char *s2, size_t maxlen);
|
||||
char *_Cdecl strncpy (char *dest, const char *src, size_t maxlen);
|
||||
int _Cdecl strnicmp(const char *s1, const char *s2, size_t maxlen);
|
||||
char *_Cdecl strnset (char *s, int ch, size_t n);
|
||||
char *_Cdecl strpbrk (const char *s1, const char *s2);
|
||||
char *_Cdecl strrchr (const char *s, int c);
|
||||
char *_Cdecl strrev (char *s);
|
||||
char *_Cdecl strset (char *s, int ch);
|
||||
size_t _Cdecl strspn (const char *s1, const char *s2);
|
||||
char *_Cdecl strstr (const char *s1, const char *s2);
|
||||
char *_Cdecl strtok (char *s1, const char *s2);
|
||||
char *_Cdecl strupr (char *s);
|
||||
|
||||
/* compatibility with other compilers */
|
||||
|
||||
#define strcmpi(s1,s2) stricmp(s1,s2)
|
||||
#define strncmpi(s1,s2,n) strnicmp(s1,s2,n)
|
||||
|
||||
#if !__STDC__
|
||||
char *_Cdecl _strerror (const char *s);
|
||||
#endif
|
||||
|
46
Borland Turbo C v2/INCLUDE/SYS/STAT.H
Normal file
46
Borland Turbo C v2/INCLUDE/SYS/STAT.H
Normal file
@ -0,0 +1,46 @@
|
||||
/* stat.h
|
||||
|
||||
Definitions used for file status functions
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _STAT_H
|
||||
#define _STAT_H 1
|
||||
|
||||
#define S_IFMT 0xF000 /* file type mask */
|
||||
#define S_IFDIR 0x4000 /* directory */
|
||||
#define S_IFIFO 0x1000 /* FIFO special */
|
||||
#define S_IFCHR 0x2000 /* character special */
|
||||
#define S_IFBLK 0x3000 /* block special */
|
||||
#define S_IFREG 0x8000 /* or just 0x0000, regular */
|
||||
#define S_IREAD 0x0100 /* owner may read */
|
||||
#define S_IWRITE 0x0080 /* owner may write */
|
||||
#define S_IEXEC 0x0040 /* owner may execute <directory search> */
|
||||
|
||||
struct stat
|
||||
{
|
||||
short st_dev;
|
||||
short st_ino;
|
||||
short st_mode;
|
||||
short st_nlink;
|
||||
int st_uid;
|
||||
int st_gid;
|
||||
short st_rdev;
|
||||
long st_size;
|
||||
long st_atime;
|
||||
long st_mtime;
|
||||
long st_ctime;
|
||||
};
|
||||
|
||||
int _Cdecl fstat (int handle, struct stat *statbuf);
|
||||
int _Cdecl stat (char *path, struct stat *statbuf);
|
||||
|
||||
#endif /* _STAT_H */
|
||||
|
28
Borland Turbo C v2/INCLUDE/SYS/TIMEB.H
Normal file
28
Borland Turbo C v2/INCLUDE/SYS/TIMEB.H
Normal file
@ -0,0 +1,28 @@
|
||||
/* timeb.h
|
||||
|
||||
Struct and function declarations for ftime().
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef __TIMEB_DEFINED
|
||||
#define __TIMEB_DEFINED
|
||||
|
||||
struct timeb {
|
||||
long time;
|
||||
short millitm;
|
||||
short timezone;
|
||||
short dstflag;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void _Cdecl ftime(struct timeb *);
|
||||
|
13
Borland Turbo C v2/INCLUDE/SYS/TYPES.H
Normal file
13
Borland Turbo C v2/INCLUDE/SYS/TYPES.H
Normal file
@ -0,0 +1,13 @@
|
||||
/* types.h
|
||||
|
||||
Types for dealing with time.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __TIME_T
|
||||
#define __TIME_T
|
||||
typedef long time_t;
|
||||
#endif
|
||||
|
57
Borland Turbo C v2/INCLUDE/TIME.H
Normal file
57
Borland Turbo C v2/INCLUDE/TIME.H
Normal file
@ -0,0 +1,57 @@
|
||||
/* time.h
|
||||
|
||||
Struct and function declarations for dealing with time.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _TM_DEFINED
|
||||
#define _TM_DEFINED
|
||||
|
||||
#ifndef __TIME_T
|
||||
#define __TIME_T
|
||||
typedef long time_t;
|
||||
#endif
|
||||
|
||||
#ifndef __CLOCK_T
|
||||
#define __CLOCK_T
|
||||
typedef long clock_t;
|
||||
#define CLK_TCK 18.2
|
||||
#endif
|
||||
|
||||
struct tm {
|
||||
int tm_sec;
|
||||
int tm_min;
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_wday;
|
||||
int tm_yday;
|
||||
int tm_isdst;
|
||||
};
|
||||
|
||||
char *_Cdecl asctime (const struct tm *tblock);
|
||||
char *_Cdecl ctime (const time_t *time);
|
||||
double _Cdecl difftime(time_t time2, time_t time1);
|
||||
struct tm *_Cdecl gmtime(const time_t *timer);
|
||||
struct tm *_Cdecl localtime(const time_t *timer);
|
||||
time_t _Cdecl time (time_t *timer);
|
||||
clock_t _Cdecl clock(void);
|
||||
|
||||
#if !__STDC__
|
||||
extern int _Cdecl daylight;
|
||||
extern long _Cdecl timezone;
|
||||
|
||||
int _Cdecl stime(time_t *tp);
|
||||
void _Cdecl tzset(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
51
Borland Turbo C v2/INCLUDE/VALUES.H
Normal file
51
Borland Turbo C v2/INCLUDE/VALUES.H
Normal file
@ -0,0 +1,51 @@
|
||||
/* values.h
|
||||
|
||||
Symbolic names for important constants, including machine
|
||||
dependencies. A System V compatible header.
|
||||
|
||||
Copyright (c) Borland International 1987,1988
|
||||
All Rights Reserved.
|
||||
*/
|
||||
#if __STDC__
|
||||
#define _Cdecl
|
||||
#else
|
||||
#define _Cdecl cdecl
|
||||
#endif
|
||||
|
||||
#ifndef _VALUES_H
|
||||
#define _VALUES_H
|
||||
|
||||
#define BITSPERBYTE 8
|
||||
#define MAXSHORT 0x7FFF
|
||||
#define MAXINT 0x7FFF
|
||||
#define MAXLONG 0x7FFFFFFFL
|
||||
#define HIBITS 0x8000
|
||||
#define HIBITI 0x8000
|
||||
#define HIBITL 0x80000000
|
||||
|
||||
#define DMAXEXP 308
|
||||
#define FMAXEXP 38
|
||||
#define DMINEXP -307
|
||||
#define FMINEXP -37
|
||||
|
||||
#define MAXDOUBLE 1.797693E+308
|
||||
#define MAXFLOAT 3.37E+38
|
||||
#define MINDOUBLE 2.225074E-308
|
||||
#define MINFLOAT 8.43E-37
|
||||
|
||||
#define DSIGNIF 53
|
||||
#define FSIGNIF 24
|
||||
|
||||
#define DMAXPOWTWO 0x3FF
|
||||
#define FMAXPOWTWO 0x7F
|
||||
#define _DEXPLEN 11
|
||||
#define _FEXPLEN 8
|
||||
#define _EXPBASE 2
|
||||
#define _IEEE 1
|
||||
#define _LENBASE 1
|
||||
#define HIDDENBIT 1
|
||||
#define LN_MAXDOUBLE 7.0978E+2
|
||||
#define LN_MINDOUBLE -7.0840E+2
|
||||
|
||||
#endif
|
||||
|
BIN
Borland Turbo C v2/LIB/C0C.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/C0C.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/C0H.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/C0H.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/C0L.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/C0L.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/C0M.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/C0M.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/C0S.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/C0S.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/C0T.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/C0T.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/CC.LIB
Normal file
BIN
Borland Turbo C v2/LIB/CC.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/CH.LIB
Normal file
BIN
Borland Turbo C v2/LIB/CH.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/CL.LIB
Normal file
BIN
Borland Turbo C v2/LIB/CL.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/CM.LIB
Normal file
BIN
Borland Turbo C v2/LIB/CM.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/CS.LIB
Normal file
BIN
Borland Turbo C v2/LIB/CS.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/EMU.LIB
Normal file
BIN
Borland Turbo C v2/LIB/EMU.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/FP87.LIB
Normal file
BIN
Borland Turbo C v2/LIB/FP87.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/GRAPHICS.LIB
Normal file
BIN
Borland Turbo C v2/LIB/GRAPHICS.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/INIT.OBJ
Normal file
BIN
Borland Turbo C v2/LIB/INIT.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/MATHC.LIB
Normal file
BIN
Borland Turbo C v2/LIB/MATHC.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/MATHH.LIB
Normal file
BIN
Borland Turbo C v2/LIB/MATHH.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/MATHL.LIB
Normal file
BIN
Borland Turbo C v2/LIB/MATHL.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/MATHM.LIB
Normal file
BIN
Borland Turbo C v2/LIB/MATHM.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LIB/MATHS.LIB
Normal file
BIN
Borland Turbo C v2/LIB/MATHS.LIB
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/LITT.CHR
Normal file
BIN
Borland Turbo C v2/LITT.CHR
Normal file
Binary file not shown.
49
Borland Turbo C v2/MAIN.C
Normal file
49
Borland Turbo C v2/MAIN.C
Normal file
@ -0,0 +1,49 @@
|
||||
/* MAIN.C
|
||||
|
||||
Alternate, standalone main() file. Demonstrates
|
||||
linking to the startup code without having to link
|
||||
to any of the Turbo C library routines.
|
||||
|
||||
Copyright (c) 1987,88 Borland International. All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Compile and link with:
|
||||
|
||||
tcc -c -ms main
|
||||
tasm c0 /D__SMALL__ /D__NOFLOAT /t/mx;
|
||||
tasm setargv /D__SMALL__ /t/mx;
|
||||
tlink c0 main setargv /c/m,main
|
||||
|
||||
For another memory model, replace __SMALL__ with one of
|
||||
__MEDIUM__, __COMPACT__, __LARGE__, __HUGE__
|
||||
|
||||
If using tiny model, replace __SMALL__ with __TINY__ and run
|
||||
exe2bin main.exe main.com
|
||||
del main.exe
|
||||
|
||||
Resulting main.exe has no references to the library.
|
||||
Caution: This example works only with no floating point code.
|
||||
*/
|
||||
|
||||
#include <dos.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void exit(int c)
|
||||
{ _exit(c);}
|
||||
|
||||
void _setenvp(void){} /* dummy out _setenvp */
|
||||
|
||||
unsigned _stklen = 0x200;
|
||||
unsigned _heaplen = 0;
|
||||
|
||||
void main()
|
||||
{
|
||||
/* print Hello, world using int 21, function 9 */
|
||||
_DX = (unsigned) "Hello, world.\r\n$";
|
||||
_AX = 0x900;
|
||||
__int__(0x21); /* use built-in, inline function */
|
||||
exit(0);
|
||||
}
|
||||
|
BIN
Borland Turbo C v2/MAKE.EXE
Normal file
BIN
Borland Turbo C v2/MAKE.EXE
Normal file
Binary file not shown.
144
Borland Turbo C v2/MATHERR.C
Normal file
144
Borland Turbo C v2/MATHERR.C
Normal file
@ -0,0 +1,144 @@
|
||||
/*------------------------------------------------------------------------
|
||||
* filename - matherr.c
|
||||
*
|
||||
* function(s)
|
||||
* matherr - user-modifiable math error handler
|
||||
*-----------------------------------------------------------------------*/
|
||||
|
||||
/*[]---------------------------------------------------[]*/
|
||||
/*| |*/
|
||||
/*| Turbo C Run Time Library - Version 2.0 |*/
|
||||
/*| |*/
|
||||
/*| |*/
|
||||
/*| Copyright (c) 1988 by Borland International |*/
|
||||
/*| All Rights Reserved. |*/
|
||||
/*| |*/
|
||||
/*[]---------------------------------------------------[]*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifdef UNIX_matherr
|
||||
#include <stdio.h>
|
||||
#include <process.h>
|
||||
|
||||
char *whyS [] =
|
||||
{
|
||||
"argument domain error",
|
||||
"argument singularity ",
|
||||
"overflow range error ",
|
||||
"underflow range error",
|
||||
"total loss of significance",
|
||||
"partial loss of significance"
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------*
|
||||
|
||||
Name matherr - user-modifiable math error handler
|
||||
|
||||
Usage #include <math.h>
|
||||
int matherr(struct exception *e);
|
||||
|
||||
Prototype in math.h
|
||||
|
||||
Description When exceptions are detected in the math library then a
|
||||
call is made to _matherr() with all the available
|
||||
information.
|
||||
|
||||
That function does very little, except to map the exception
|
||||
"why" into either ERANGE or EDOMAIN in errno. Its main
|
||||
purpose is to act as a focal point for changes in error
|
||||
handling.
|
||||
|
||||
For example, if you were writing a spreadsheet you might
|
||||
replace this function with one which pops up an error
|
||||
window explaining something like:
|
||||
|
||||
"log (-2.0) caused domain error, in cell J7"
|
||||
|
||||
and then longjmp() to a reset state in the spreadsheet and
|
||||
await the next command from the user.
|
||||
|
||||
The default version of Turbo C's matherr routine masks
|
||||
underflow and precision errors; others errors are considered
|
||||
fatal. It serves as a hook that you can replace when
|
||||
writing your own math error handling routine.
|
||||
|
||||
The rationale for masking underflow and precision errors
|
||||
is that these are not errors according to the ANSI C spec.
|
||||
Consequently, you will get
|
||||
exp(-1000) = 0
|
||||
sin(1e100) = NAN
|
||||
without any error or warning, even though there is a total
|
||||
loss of precision in both cases. You can trap these errors
|
||||
by modifying matherr.
|
||||
|
||||
The possible errors are
|
||||
DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS
|
||||
and listed in <math.h>. As explained above, UNDERFLOW and
|
||||
TLOSS are masked by the default matherr. PLOSS is not
|
||||
supported by TC and is not generated by any library functions.
|
||||
The remaining errors, DOMAIN, SING, and OVERFLOW, are fatal
|
||||
with the default matherr.
|
||||
|
||||
You can modify matherr to be a custom error handling
|
||||
routine (such as one that catches and resolves certain type
|
||||
of errors); the modified matherr should return 0 if it
|
||||
failed to resolve the error, or non-zero if the error was
|
||||
resolved. When matherr returns non-zero, no error message
|
||||
is printed, and errno is not changed.
|
||||
|
||||
The important thing is that we don't know what error
|
||||
handling you want, but you are assured that all errors will
|
||||
arrive at matherr() with all the information you need to
|
||||
design a custom format.
|
||||
|
||||
We do not ship as standard the function named matherr()
|
||||
which may be familiar to UNIX users, since the ANSI x3j11
|
||||
draft specifies an incompatible style. This version is as
|
||||
close as we could get without breaking the ANSI rules. You
|
||||
can, however, convert this version to the UNIX style if you
|
||||
prefer. The necessary code is included but switched off.
|
||||
|
||||
Return value The default return value for matherr is simply 0.
|
||||
matherr can also modify e->retval, which propagates through
|
||||
_matherr back to the original caller.
|
||||
|
||||
When matherr returns 0, (indicating that it was not able to
|
||||
resolve the error) _matherr sets errno and prints an error
|
||||
message.
|
||||
|
||||
When matherr returns non-zero, (indicating that it was able
|
||||
to resolve the error) errno is not set and no messages are
|
||||
printed.
|
||||
|
||||
*-------------------------------------------------------------------------*/
|
||||
int matherr (struct exception *e)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s (%8g,%8g): %s\n", e->name, e->arg1, e->arg2, whyS [e->type - 1]);
|
||||
|
||||
exit (1);
|
||||
}
|
||||
#else
|
||||
|
||||
int matherr(struct exception *e)
|
||||
{
|
||||
if (e->type == UNDERFLOW)
|
||||
{
|
||||
/* flush underflow to 0 */
|
||||
e->retval = 0;
|
||||
return 1;
|
||||
}
|
||||
if (e->type == TLOSS)
|
||||
{
|
||||
/* total loss of precision, but ignore the problem */
|
||||
return 1;
|
||||
}
|
||||
/* all other errors are fatal */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
171
Borland Turbo C v2/MCALC.C
Normal file
171
Borland Turbo C v2/MCALC.C
Normal file
@ -0,0 +1,171 @@
|
||||
/* Turbo C - (C) Copyright 1987,1988 by Borland International */
|
||||
|
||||
#define MAIN
|
||||
|
||||
#include <string.h>
|
||||
#include <alloc.h>
|
||||
#include <stdarg.h>
|
||||
#include <dos.h>
|
||||
#include <conio.h>
|
||||
#include "mcalc.h"
|
||||
|
||||
CELLPTR cell[MAXCOLS][MAXROWS], curcell;
|
||||
unsigned char format[MAXCOLS][MAXROWS];
|
||||
unsigned char colwidth[MAXCOLS];
|
||||
unsigned char colstart[SCREENCOLS];
|
||||
int leftcol, rightcol, toprow, bottomrow, curcol, currow, lastcol, lastrow;
|
||||
char changed = FALSE;
|
||||
char formdisplay = FALSE;
|
||||
char autocalc = TRUE;
|
||||
char stop = FALSE;
|
||||
char colortable[128];
|
||||
char colorcard;
|
||||
char snow;
|
||||
char far *displayptr;
|
||||
long memleft;
|
||||
unsigned int oldcursor, shortcursor, tallcursor, nocursor = 0x2000;
|
||||
|
||||
void run()
|
||||
/* The main program loop */
|
||||
{
|
||||
int input;
|
||||
|
||||
do
|
||||
{
|
||||
displaycell(curcol, currow, HIGHLIGHT, NOUPDATE);
|
||||
curcell = cell[curcol][currow];
|
||||
showcelltype();
|
||||
input = getkey();
|
||||
switch(input)
|
||||
{
|
||||
case '/' :
|
||||
mainmenu();
|
||||
break;
|
||||
case F1 :
|
||||
recalc();
|
||||
break;
|
||||
case F2 :
|
||||
editcell(curcell);
|
||||
break;
|
||||
case DELKEY :
|
||||
deletecell(curcol, currow, UPDATE);
|
||||
printfreemem();
|
||||
if (autocalc)
|
||||
recalc();
|
||||
break;
|
||||
case PGUPKEY :
|
||||
toprow -= 20;
|
||||
currow -= 20;
|
||||
if (currow < 0)
|
||||
currow = toprow = 0;
|
||||
else if (toprow < 0)
|
||||
{
|
||||
currow -= toprow;
|
||||
toprow = 0;
|
||||
}
|
||||
setbottomrow();
|
||||
displayscreen(NOUPDATE);
|
||||
break;
|
||||
case PGDNKEY :
|
||||
toprow += 20;
|
||||
currow += 20;
|
||||
if ((currow >= MAXROWS) && (toprow >= MAXROWS))
|
||||
{
|
||||
currow = MAXROWS - 1;
|
||||
toprow = MAXROWS - 20;
|
||||
}
|
||||
else if (toprow > (MAXROWS - 20))
|
||||
{
|
||||
currow -= (toprow + 20 - MAXROWS);
|
||||
toprow = MAXROWS - 20;
|
||||
}
|
||||
setbottomrow();
|
||||
displayscreen(NOUPDATE);
|
||||
break;
|
||||
case CTRLLEFTKEY :
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
if (leftcol == 0)
|
||||
curcol = 0;
|
||||
else
|
||||
{
|
||||
curcol = rightcol = leftcol - 1;
|
||||
setleftcol();
|
||||
setrightcol();
|
||||
displayscreen(NOUPDATE);
|
||||
}
|
||||
break;
|
||||
case CTRLRIGHTKEY :
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
if (rightcol == MAXCOLS - 1)
|
||||
curcol = rightcol;
|
||||
else
|
||||
{
|
||||
curcol = leftcol = rightcol + 1;
|
||||
setrightcol();
|
||||
setleftcol();
|
||||
displayscreen(NOUPDATE);
|
||||
}
|
||||
break;
|
||||
case HOMEKEY :
|
||||
currow = curcol = leftcol = toprow = 0;
|
||||
setrightcol();
|
||||
setbottomrow();
|
||||
displayscreen(NOUPDATE);
|
||||
break;
|
||||
case ENDKEY :
|
||||
rightcol = curcol = lastcol;
|
||||
currow = bottomrow = lastrow;
|
||||
settoprow();
|
||||
setleftcol();
|
||||
setrightcol();
|
||||
displayscreen(NOUPDATE);
|
||||
break;
|
||||
case UPKEY :
|
||||
moverowup();
|
||||
break;
|
||||
case DOWNKEY :
|
||||
moverowdown();
|
||||
break;
|
||||
case LEFTKEY :
|
||||
movecolleft();
|
||||
break;
|
||||
case RIGHTKEY :
|
||||
movecolright();
|
||||
break;
|
||||
default :
|
||||
if ((input >= ' ') && (input <= '~'))
|
||||
getinput(input);
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
while (!stop);
|
||||
} /* run */
|
||||
|
||||
void main(int argc, char *argv[])
|
||||
{
|
||||
window(1, 1, 80, 25);
|
||||
initcursor();
|
||||
initcolortable();
|
||||
setcursor(nocursor);
|
||||
setcolor(WHITE);
|
||||
clrscr();
|
||||
writef((80 - strlen(MSGHEADER)) >> 1, 11, MSGHEADERCOLOR, strlen(MSGHEADER),
|
||||
MSGHEADER);
|
||||
writef((80 - strlen(MSGKEYPRESS)) >> 1, 13, PROMPTCOLOR,
|
||||
strlen(MSGKEYPRESS), MSGKEYPRESS);
|
||||
gotoxy(80, 25);
|
||||
getkey();
|
||||
setcolor(WHITE);
|
||||
clrscr();
|
||||
initvars();
|
||||
memleft = memsize;
|
||||
redrawscreen();
|
||||
if (argc > 1)
|
||||
loadsheet(argv[1]);
|
||||
clearinput();
|
||||
run();
|
||||
setcolor(LIGHTGRAY);
|
||||
clrscr();
|
||||
setcursor(oldcursor);
|
||||
}
|
||||
|
102
Borland Turbo C v2/MCALC.DOC
Normal file
102
Borland Turbo C v2/MCALC.DOC
Normal file
@ -0,0 +1,102 @@
|
||||
How to compile MicroCalc
|
||||
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
|
||||
|
||||
With TC.EXE:
|
||||
|
||||
1. Run TC.EXE
|
||||
2. In the Project pulldown menu specify the project name "MCALC.PRJ"
|
||||
3. From the main menu select the Run option from the Run menu
|
||||
|
||||
With TCC.EXE:
|
||||
|
||||
Compile from DOS with the following command line:
|
||||
TCC mcalc mcparser mcdisply mcinput mcommand mcutil
|
||||
|
||||
In both cases, compiling under a large data model (COMPACT, LARGE, or HUGE)
|
||||
will give you much more memory for your spreadsheets.
|
||||
|
||||
The compiler may run out of file handles when compiling MicroCalc.
|
||||
To allow the compiler to open as many files as possible, put the
|
||||
statement "FILES = 20" in the file CONFIG.SYS in the root directory
|
||||
of the disk that you start your computer with.
|
||||
|
||||
The MicroCalc parser
|
||||
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
|
||||
|
||||
The state and goto information for the parser was created using the UNIX YACC
|
||||
utility. The input to YACC was as follows:
|
||||
|
||||
%token CONST CELL FUNC
|
||||
%%
|
||||
e : e '+' t
|
||||
| e '-' t
|
||||
| t
|
||||
;
|
||||
t : t '*' f
|
||||
| t '/' f
|
||||
| f
|
||||
;
|
||||
f : x '^' f
|
||||
| x
|
||||
;
|
||||
x : '-' u
|
||||
| u
|
||||
;
|
||||
u : CELL ':' CELL
|
||||
| o
|
||||
;
|
||||
o : CELL
|
||||
| '(' e ')'
|
||||
| CONST
|
||||
| FUNC '(' e ')'
|
||||
;
|
||||
%%
|
||||
|
||||
Additional MicroCalc information
|
||||
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
|
||||
|
||||
Formulas are entered as text. MicroCalc will determine if what you entered
|
||||
is a legal formula or text.
|
||||
|
||||
Cell names in formulas are typed in with the column followed by the row.
|
||||
|
||||
Examples:
|
||||
|
||||
A1+A2
|
||||
B6^5
|
||||
|
||||
To sum a group of cells, put a colon between the first cell and the last
|
||||
cell in the group.
|
||||
|
||||
Example:
|
||||
|
||||
A1:A10 sums all of the cells from A1 to A10 and puts the result in the
|
||||
current cell.
|
||||
|
||||
The available MicroCalc functions are:
|
||||
|
||||
ABS - absolute value
|
||||
ACOS - arc cosine
|
||||
ASIN - arc sine
|
||||
ATAN - arc tangent
|
||||
COS - cosine
|
||||
COSH - hyperbolic cosine
|
||||
EXP - exponential function
|
||||
LOG - logarithm
|
||||
LOG10 - base 10 logarithm
|
||||
POW10 - raise argument to the 10th power
|
||||
ROUND - round to the nearest whole number
|
||||
SIN - sine
|
||||
SINH - hyperbolic sine
|
||||
SQR - square
|
||||
SQRT - square root
|
||||
TAN - tangent
|
||||
TANH - hyperbolic tangent
|
||||
TRUNC - return the whole part of a number
|
||||
|
||||
Examples:
|
||||
|
||||
TRUNC(A1)
|
||||
SQRT(SQR(34.5))
|
||||
ABS(TRUNC(B16))
|
||||
|
257
Borland Turbo C v2/MCALC.H
Normal file
257
Borland Turbo C v2/MCALC.H
Normal file
@ -0,0 +1,257 @@
|
||||
/* Turbo C - (C) Copyright 1987, 1988 by Borland International */
|
||||
|
||||
#define S_IREAD 0x0100 /* from SYS\STAT.H */
|
||||
#define S_IWRITE 0x0080 /* from SYS\STAT.H */
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define MSGHEADER "MICROCALC - A Turbo C Demonstration Program"
|
||||
#define MSGKEYPRESS "Press any key to continue."
|
||||
#define MSGCOMMAND "Press / for the list of commands"
|
||||
#define MSGMEMORY "Memory Available:"
|
||||
#define MSGERROR "ERROR"
|
||||
#define MSGLOMEM "Not enough memory to allocate cell."
|
||||
#define MSGEMPTY "Empty"
|
||||
#define MSGTEXT "Text"
|
||||
#define MSGVALUE "Value"
|
||||
#define MSGFORMULA "Formula"
|
||||
#define MSGAUTOCALC "AutoCalc"
|
||||
#define MSGFORMDISPLAY "Form"
|
||||
#define MSGFILENAME "Enter the file name of the spreadsheet:"
|
||||
#define MSGNAME "Turbo C MicroCalc Spreadsheet"
|
||||
#define MSGCOLWIDTH "Enter the new column width:"
|
||||
#define MSGNOOPEN "Can't open the file."
|
||||
#define MSGOVERWRITE "The file exists. Do you want to overwrite it?"
|
||||
#define MSGFILELOMEM "Not enough memory for entire spreadsheet."
|
||||
#define MSGNOMICROCALC "That is not a Turbo C MicroCalc spreadsheet."
|
||||
#define MSGNOEXIST "The file does not exist."
|
||||
#define MSGGOTO "Enter the cell to go to:"
|
||||
#define MSGBADNUMBER "You must enter a number from %d to %d."
|
||||
#define MSGBADCELL "That is not a legal cell."
|
||||
#define MSGCELL1 "Enter the first cell to format:"
|
||||
#define MSGCELL2 "Enter the last cell to format:"
|
||||
#define MSGDIFFCOLROW "The row or the column must be the same."
|
||||
#define MSGRIGHTJUST "Do you want the cell right-justified?"
|
||||
#define MSGDOLLAR "Do you want numbers in a dollar format?"
|
||||
#define MSGCOMMAS "Do you want commas in numbers?"
|
||||
#define MSGPLACES "How many decimal places should the number be rounded to?"
|
||||
#define MSGCOLUMNS "Do you want to print in 132 columns?"
|
||||
#define MSGPRINT "Enter the file name to print to, or press ENTER to print on the printer."
|
||||
#define MSGBORDER "Print the border?"
|
||||
#define MSGLOADING "Loading..."
|
||||
#define MSGSAVING "Saving..."
|
||||
#define MSGSAVESHEET "Save current spreadsheet?"
|
||||
#define MSGSTACKERROR "Parser stack overflow."
|
||||
|
||||
#define MENU "Spreadsheet, Format, Delete, Goto, Col, Row, Edit, Utility, Auto, Quit"
|
||||
#define COMMAND "SFDGCREUAQ"
|
||||
#define SMENU "Load, Save, Print, Clear"
|
||||
#define SCOMMAND "LSPC"
|
||||
#define CMENU "Insert, Delete, Width"
|
||||
#define CCOMMAND "IDW"
|
||||
#define RMENU "Insert, Delete"
|
||||
#define RCOMMAND "ID"
|
||||
#define UMENU "Recalc, Formula display"
|
||||
#define UCOMMAND "RF"
|
||||
|
||||
#define MAXCOLS 100 /* Maximum is 702 */
|
||||
#define MAXROWS 100
|
||||
#define LEFTMARGIN 3
|
||||
#define MINCOLWIDTH 3
|
||||
#define MAXCOLWIDTH 80 - LEFTMARGIN
|
||||
#define SCREENCOLS (80 - LEFTMARGIN) / MINCOLWIDTH + 1
|
||||
#define SCREENROWS 20
|
||||
#define DEFAULTWIDTH 10
|
||||
#define DEFAULTFORMAT 0X42
|
||||
#define MAXINPUT 79
|
||||
#define MAXPLACES 8
|
||||
#define TOPMARGIN 5
|
||||
#define PARSERSTACKSIZE 20
|
||||
|
||||
#define TEXTCOLOR WHITE
|
||||
#define ERRORCOLOR LIGHTRED + BLINK
|
||||
#define VALUECOLOR LIGHTCYAN
|
||||
#define FORMULACOLOR LIGHTMAGENTA
|
||||
#define BLANKCOLOR BLACK
|
||||
#define HEADERCOLOR WHITE + (RED << 4)
|
||||
#define HIGHLIGHTCOLOR WHITE + (BLUE << 4)
|
||||
#define HIGHLIGHTERRORCOLOR WHITE + (BLUE << 4) + BLINK
|
||||
#define MSGAUTOCALCCOLOR LIGHTCYAN
|
||||
#define MSGFORMDISPLAYCOLOR LIGHTMAGENTA
|
||||
#define MSGMEMORYCOLOR LIGHTGREEN
|
||||
#define MSGHEADERCOLOR LIGHTCYAN
|
||||
#define PROMPTCOLOR YELLOW
|
||||
#define COMMANDCOLOR LIGHTCYAN
|
||||
#define LOWCOMMANDCOLOR WHITE
|
||||
#define MEMORYCOLOR LIGHTRED
|
||||
#define CELLTYPECOLOR LIGHTGREEN
|
||||
#define CELLCONTENTSCOLOR YELLOW
|
||||
|
||||
#define HIGHLIGHT TRUE
|
||||
#define NOHIGHLIGHT FALSE
|
||||
#define UPDATE TRUE
|
||||
#define NOUPDATE FALSE
|
||||
#define FORMAT TRUE
|
||||
#define NOFORMAT FALSE
|
||||
#define LEFT 0
|
||||
#define RIGHT 1
|
||||
#define UP 2
|
||||
#define DOWN 3
|
||||
#define TEXT 0
|
||||
#define VALUE 1
|
||||
#define FORMULA 2
|
||||
#define COLADD 0
|
||||
#define COLDEL 1
|
||||
#define ROWADD 2
|
||||
#define ROWDEL 3
|
||||
#define OVERWRITE 0X80
|
||||
#define RJUSTIFY 0X40
|
||||
#define COMMAS 0X20
|
||||
#define DOLLAR 0X10
|
||||
|
||||
struct CELLREC
|
||||
{
|
||||
char attrib;
|
||||
union
|
||||
{
|
||||
char text[MAXINPUT + 1];
|
||||
double value;
|
||||
struct
|
||||
{
|
||||
double fvalue;
|
||||
char formula[MAXINPUT + 1];
|
||||
} f;
|
||||
} v;
|
||||
};
|
||||
|
||||
typedef struct CELLREC *CELLPTR;
|
||||
|
||||
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
|
||||
|
||||
#define memsize coreleft() - 1000
|
||||
#define textcellsize(s) (((strlen(s) >> 1) + 3) << 1)
|
||||
#define valuecellsize 12
|
||||
#define formulacellsize(s) (((strlen(s) >> 1) + 7) << 1)
|
||||
|
||||
#else
|
||||
|
||||
#define memsize farcoreleft() - 1000
|
||||
#define textcellsize(s) (((strlen(s) >> 1) + 5) << 1)
|
||||
#define valuecellsize 16
|
||||
#define formulacellsize(s) (((strlen(s) >> 1) + 9) << 1)
|
||||
|
||||
#endif
|
||||
|
||||
#define BS 8
|
||||
#define FORMFEED 12
|
||||
#define CR 13
|
||||
#define ESC 27
|
||||
#define HOMEKEY 327
|
||||
#define ENDKEY 335
|
||||
#define UPKEY 328
|
||||
#define DOWNKEY 336
|
||||
#define PGUPKEY 329
|
||||
#define PGDNKEY 337
|
||||
#define LEFTKEY 331
|
||||
#define INSKEY 338
|
||||
#define RIGHTKEY 333
|
||||
#define DELKEY 339
|
||||
#define CTRLLEFTKEY 371
|
||||
#define CTRLRIGHTKEY 372
|
||||
#define F1 315
|
||||
#define F2 316
|
||||
#define F3 317
|
||||
#define F4 318
|
||||
#define F5 319
|
||||
#define F6 320
|
||||
#define F7 321
|
||||
#define F8 322
|
||||
#define F9 323
|
||||
#define F10 324
|
||||
|
||||
void initcursor(void);
|
||||
int getkey(void);
|
||||
int editstring(char *s, char *legal, int maxlength);
|
||||
int getint(int *number, int low, int high);
|
||||
void getinput(int c);
|
||||
void setcolor(int color);
|
||||
void scroll(int direction, int lines, int x1, int y1, int x2, int y2,
|
||||
int attrib);
|
||||
void setcursor(unsigned int shape);
|
||||
void writef(int col, int row, int color, int width, va_list arg_list, ...);
|
||||
void printcol(void);
|
||||
void printrow(void);
|
||||
void displaycell(int col, int row, int highlighting, int updating);
|
||||
void displaycol(int col, int updating);
|
||||
void displayrow(int row, int updating);
|
||||
void displayscreen(int updating);
|
||||
void clearinput(void);
|
||||
void changecursor(int insmode);
|
||||
void showcelltype(void);
|
||||
void initcolortable(void);
|
||||
double parse(char *s, int *att);
|
||||
int alloctext(int col, int row, char *s);
|
||||
int allocvalue(int col, int row, double amt);
|
||||
int allocformula(int col, int row, char *s, double amt);
|
||||
void deletecell(int col, int row, int display);
|
||||
void printfreemem(void);
|
||||
void moverowup(void);
|
||||
void moverowdown(void);
|
||||
void movecolleft(void);
|
||||
void movecolright(void);
|
||||
void recalc(void);
|
||||
void changeautocalc(int newmode);
|
||||
void changeformdisplay(int newmode);
|
||||
void errormsg(char *s);
|
||||
void colstring(int col, char *colstr);
|
||||
void centercolstring(int col, char *colstr);
|
||||
void setleftcol(void);
|
||||
void setrightcol(void);
|
||||
void settoprow(void);
|
||||
void setbottomrow(void);
|
||||
void movehighlight(void);
|
||||
void setlastcol(void);
|
||||
void setlastrow(void);
|
||||
void act(char *s);
|
||||
void initvars(void);
|
||||
int getcommand(char *msgstr, char *comstr);
|
||||
void mainmenu(void);
|
||||
void editcell(CELLPTR ecell);
|
||||
int setoflags(int col, int row, int display);
|
||||
void clearoflags(int col, int row, int display);
|
||||
void updateoflags(int col, int row, int display);
|
||||
void loadsheet(char *filename);
|
||||
int getcell(int *col, int *row);
|
||||
char *cellstring(int col, int row, int *color, int formatting);
|
||||
void writeprompt(char *prompt);
|
||||
int getyesno(int *yesno, char *prompt);
|
||||
void swap(int *val1, int *val2);
|
||||
void redrawscreen(void);
|
||||
void checkforsave(void);
|
||||
void savesheet(void);
|
||||
int formulastart(char **input, int *col, int *row);
|
||||
int rowwidth(int row);
|
||||
void fixformula(int col, int row, int action, int place);
|
||||
void clearlastcol(void);
|
||||
void run(void);
|
||||
void gotocell(void);
|
||||
|
||||
#if !defined(MAIN)
|
||||
|
||||
extern CELLPTR cell[MAXCOLS][MAXROWS], curcell;
|
||||
extern unsigned char format[MAXCOLS][MAXROWS];
|
||||
extern unsigned char colwidth[MAXCOLS];
|
||||
extern unsigned char colstart[SCREENCOLS];
|
||||
extern char formdisplay;
|
||||
extern char changed;
|
||||
extern char autocalc;
|
||||
extern int leftcol, rightcol, toprow, bottomrow, curcol, currow, lastcol,
|
||||
lastrow, direction;
|
||||
extern long memleft;
|
||||
extern char stop;
|
||||
extern char matherror;
|
||||
extern unsigned int oldcursor, shortcursor, tallcursor, nocursor;
|
||||
|
||||
#endif
|
||||
|
7
Borland Turbo C v2/MCALC.PRJ
Normal file
7
Borland Turbo C v2/MCALC.PRJ
Normal file
@ -0,0 +1,7 @@
|
||||
mcalc (mcalc.h)
|
||||
mcparser (mcalc.h)
|
||||
mcdisply (mcalc.h)
|
||||
mcinput (mcalc.h)
|
||||
mcommand (mcalc.h)
|
||||
mcutil (mcalc.h)
|
||||
|
286
Borland Turbo C v2/MCDISPLY.C
Normal file
286
Borland Turbo C v2/MCDISPLY.C
Normal file
@ -0,0 +1,286 @@
|
||||
/* Turbo C - (C) Copyright 1987,1988 by Borland International */
|
||||
|
||||
#include <dos.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <mem.h>
|
||||
#include <conio.h>
|
||||
#include "mcalc.h"
|
||||
|
||||
static unsigned char colortable[256];
|
||||
|
||||
void setcolor(int color)
|
||||
/* Sets the current color using the color table */
|
||||
{
|
||||
textattr(colortable[color]);
|
||||
} /* setcolor */
|
||||
|
||||
void writef(int col, int row, int color, int width, va_list arg_list, ...)
|
||||
/* Prints a string in video memory at a selected location in a color */
|
||||
{
|
||||
va_list arg_ptr;
|
||||
char *format;
|
||||
char output[81];
|
||||
int len;
|
||||
|
||||
va_start(arg_ptr, arg_list);
|
||||
format = arg_list;
|
||||
vsprintf(output, format, arg_ptr);
|
||||
output[width] = 0;
|
||||
if ((len = strlen(output)) < width)
|
||||
setmem(&output[len], width - len, ' ');
|
||||
setcolor(color);
|
||||
gotoxy(col, row);
|
||||
cprintf(output);
|
||||
} /* writef */
|
||||
|
||||
void scroll(int direction, int lines, int x1, int y1, int x2, int y2,
|
||||
int attrib)
|
||||
/* Scrolls an area of the screen */
|
||||
{
|
||||
if (lines == 0)
|
||||
window(x1, y1, x2, y2);
|
||||
else switch(direction)
|
||||
{
|
||||
case UP :
|
||||
movetext(x1, y1 + lines, x2, y2, x1, y1);
|
||||
window(x1, y2 - lines + 1, x2, y2);
|
||||
break;
|
||||
case DOWN :
|
||||
movetext(x1, y1, x2, y2 - lines, x1, y1 + lines);
|
||||
window(x1, y1, x2, y1 + lines - 1);
|
||||
break;
|
||||
case LEFT :
|
||||
movetext(x1 + lines, y1, x2, y2, x1, y1);
|
||||
window(x2 - lines + 1, y1, x2, y2);
|
||||
break;
|
||||
case RIGHT :
|
||||
movetext(x1, y1, x2 - lines, y2, x1 + lines, y1);
|
||||
window(x1, y1, x1 + lines - 1, y2);
|
||||
break;
|
||||
} /* switch */
|
||||
setcolor(attrib);
|
||||
clrscr();
|
||||
window(1, 1, 80, 25);
|
||||
} /* scroll */
|
||||
|
||||
void setcursor(unsigned int shape)
|
||||
/* Sets the shape of the cursor */
|
||||
{
|
||||
union REGS reg;
|
||||
|
||||
reg.h.ah = 1;
|
||||
reg.x.cx = shape;
|
||||
int86(0X10, ®, ®);
|
||||
} /* setcursor */
|
||||
|
||||
unsigned int getcursor(void)
|
||||
/* Returns the shape of the current cursor */
|
||||
{
|
||||
union REGS reg;
|
||||
|
||||
reg.h.ah = 3;
|
||||
reg.h.bh = 0;
|
||||
int86(0X10, ®, ®);
|
||||
return(reg.x.cx);
|
||||
} /* getcursor */
|
||||
|
||||
void changecursor(insmode)
|
||||
/* Changes the cursor shape based on the current insert mode */
|
||||
{
|
||||
if (insmode)
|
||||
setcursor(tallcursor);
|
||||
else
|
||||
setcursor(shortcursor);
|
||||
} /* changecursor */
|
||||
|
||||
void printcol(void)
|
||||
/* Prints the column headings */
|
||||
{
|
||||
int col;
|
||||
char colstr[MAXCOLWIDTH + 1];
|
||||
|
||||
scroll(UP, 0, 1, 2, 80, 2, HEADERCOLOR);
|
||||
for (col = leftcol; col <= rightcol; col++)
|
||||
{
|
||||
centercolstring(col, colstr);
|
||||
writef(colstart[col - leftcol] + 1, 2, HEADERCOLOR, colwidth[col], colstr);
|
||||
}
|
||||
} /* printcol */
|
||||
|
||||
void clearlastcol()
|
||||
/* Clears any data left in the last column */
|
||||
{
|
||||
int col;
|
||||
|
||||
if ((col = colstart[rightcol - leftcol] + colwidth[rightcol]) < 80)
|
||||
scroll(UP, 0, col + 1, 3, 80, SCREENROWS + 2, WHITE);
|
||||
} /* clearlastcol */
|
||||
|
||||
void printrow(void)
|
||||
/* Prints the row headings */
|
||||
{
|
||||
int row;
|
||||
|
||||
for (row = 0; row < SCREENROWS; row++)
|
||||
writef(1, row + 3, HEADERCOLOR, LEFTMARGIN, "%-d", row + toprow + 1);
|
||||
} /* printrow */
|
||||
|
||||
void displaycell(int col, int row, int highlighting, int updating)
|
||||
/* Displays the contents of a cell */
|
||||
{
|
||||
int color;
|
||||
char *s;
|
||||
|
||||
if ((updating) &&
|
||||
((cell[col][row] == NULL) || (cell[col][row]->attrib != FORMULA)))
|
||||
return;
|
||||
s = cellstring(col, row, &color, FORMAT);
|
||||
if (highlighting)
|
||||
{
|
||||
if (color == ERRORCOLOR)
|
||||
color = HIGHLIGHTERRORCOLOR;
|
||||
else
|
||||
color = HIGHLIGHTCOLOR;
|
||||
}
|
||||
writef(colstart[col - leftcol] + 1, row - toprow + 3, color, colwidth[col],
|
||||
"%s", s);
|
||||
} /* displaycell */
|
||||
|
||||
void displaycol(int col, int updating)
|
||||
/* Displays a column on the screen */
|
||||
{
|
||||
int row;
|
||||
|
||||
for (row = toprow; row <= bottomrow; row++)
|
||||
displaycell(col, row, NOHIGHLIGHT, updating);
|
||||
} /* displaycol */
|
||||
|
||||
void displayrow(int row, int updating)
|
||||
/* Displays a row on the screen */
|
||||
{
|
||||
int col;
|
||||
|
||||
for (col = leftcol; col <= rightcol; col++)
|
||||
displaycell(col, row, NOHIGHLIGHT, updating);
|
||||
} /* displayrow */
|
||||
|
||||
void displayscreen(int updating)
|
||||
/* Displays the current screen of the spreadsheet */
|
||||
{
|
||||
int row;
|
||||
|
||||
for (row = toprow; row <= bottomrow; row++)
|
||||
displayrow(row, updating);
|
||||
clearlastcol();
|
||||
} /* displayscreen */
|
||||
|
||||
void clearinput(void)
|
||||
/* Clears the input line */
|
||||
{
|
||||
scroll(UP, 0, 1, 25, 80, 25, WHITE);
|
||||
gotoxy(1, 25);
|
||||
} /* clearinput */
|
||||
|
||||
void showcelltype(void)
|
||||
/* Prints the type of cell and what is in it */
|
||||
{
|
||||
char colstr[3], *s;
|
||||
int color;
|
||||
|
||||
formdisplay = !formdisplay;
|
||||
s = cellstring(curcol, currow, &color, NOFORMAT);
|
||||
colstring(curcol, colstr);
|
||||
if (curcell == NULL)
|
||||
writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGEMPTY);
|
||||
else switch(curcell->attrib)
|
||||
{
|
||||
case TEXT :
|
||||
writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1,
|
||||
MSGTEXT);
|
||||
break;
|
||||
case VALUE :
|
||||
writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1,
|
||||
MSGVALUE);
|
||||
break;
|
||||
case FORMULA :
|
||||
writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1,
|
||||
MSGFORMULA);
|
||||
break;
|
||||
} /* switch */
|
||||
writef(1, 24, CELLCONTENTSCOLOR, 80, "%s", s);
|
||||
formdisplay = !formdisplay;
|
||||
} /* showcelltype */
|
||||
|
||||
void redrawscreen(void)
|
||||
/* Displays the entire screen */
|
||||
{
|
||||
setrightcol();
|
||||
setbottomrow();
|
||||
writef(1, 1, MSGMEMORYCOLOR, strlen(MSGMEMORY), MSGMEMORY);
|
||||
writef(29, 1, PROMPTCOLOR, strlen(MSGCOMMAND), MSGCOMMAND);
|
||||
changeautocalc(autocalc);
|
||||
changeformdisplay(formdisplay);
|
||||
printfreemem();
|
||||
displayscreen(NOUPDATE);
|
||||
} /* redrawscreen */
|
||||
|
||||
void initcursor(void)
|
||||
/* Initializes the different cursor types */
|
||||
{
|
||||
struct text_info ti;
|
||||
|
||||
gettextinfo(&ti);
|
||||
oldcursor = getcursor();
|
||||
if (ti.currmode == MONO)
|
||||
{
|
||||
shortcursor = 0x0A0C;
|
||||
tallcursor = 0x090C;
|
||||
}
|
||||
else
|
||||
{
|
||||
shortcursor = 0x0607;
|
||||
tallcursor = 0x0507;
|
||||
}
|
||||
} /* initcursor */
|
||||
|
||||
void initcolortable(void)
|
||||
/* Sets up the color table */
|
||||
{
|
||||
int color, fg, bg, fcolor, bcolor;
|
||||
struct text_info ti;
|
||||
|
||||
gettextinfo(&ti);
|
||||
if (ti.currmode == C80)
|
||||
{
|
||||
for (color = 0; color <= 255; color++)
|
||||
colortable[color] = color;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (fg = BLACK; fg <= WHITE; fg++)
|
||||
{
|
||||
if (fg == BLACK)
|
||||
fcolor = BLACK;
|
||||
else if (fg <= LIGHTGRAY)
|
||||
fcolor = LIGHTGRAY;
|
||||
else
|
||||
fcolor = WHITE;
|
||||
for (bg = BLACK; bg <= LIGHTGRAY; bg++)
|
||||
{
|
||||
if (bg == BLACK)
|
||||
bcolor = BLACK;
|
||||
else
|
||||
{
|
||||
if (fcolor == WHITE)
|
||||
fcolor = BLACK;
|
||||
bcolor = LIGHTGRAY;
|
||||
}
|
||||
colortable[fg + (bg << 4)] = fcolor + (bcolor << 4);
|
||||
}
|
||||
}
|
||||
for (fg = 128; fg <= 255; fg++)
|
||||
colortable[fg] = colortable[fg - 128] | 0x80;
|
||||
}
|
||||
} /* initcolortable */
|
||||
|
211
Borland Turbo C v2/MCINPUT.C
Normal file
211
Borland Turbo C v2/MCINPUT.C
Normal file
@ -0,0 +1,211 @@
|
||||
/* Turbo C - (C) Copyright 1987,1988 by Borland International */
|
||||
|
||||
#include <string.h>
|
||||
#include <mem.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <bios.h>
|
||||
#include <conio.h>
|
||||
#include <string.h>
|
||||
#include "mcalc.h"
|
||||
|
||||
int getkey(void)
|
||||
/* Uses the BIOS to read the next keyboard character */
|
||||
{
|
||||
int key, lo, hi;
|
||||
|
||||
key = bioskey(0);
|
||||
lo = key & 0X00FF;
|
||||
hi = (key & 0XFF00) >> 8;
|
||||
return((lo == 0) ? hi + 256 : lo);
|
||||
} /* getkey */
|
||||
|
||||
int editstring(char *s, char *legal, int maxlength)
|
||||
/* Allows the user to edit a string with only certain characters allowed -
|
||||
Returns TRUE if ESC was not pressed, FALSE is ESC was pressed.
|
||||
*/
|
||||
{
|
||||
int c, len = strlen(s), pos = len, insert = TRUE;
|
||||
|
||||
changecursor(insert);
|
||||
do
|
||||
{
|
||||
writef(1, 25, WHITE, 79, "%s", s);
|
||||
gotoxy(pos + 1, 25);
|
||||
switch(c = getkey())
|
||||
{
|
||||
case HOMEKEY :
|
||||
pos = 0;
|
||||
break;
|
||||
case ENDKEY :
|
||||
pos = len;
|
||||
break;
|
||||
case INSKEY :
|
||||
insert = !insert;
|
||||
changecursor(insert);
|
||||
break;
|
||||
case LEFTKEY :
|
||||
if (pos > 0)
|
||||
pos--;
|
||||
break;
|
||||
case RIGHTKEY :
|
||||
if (pos < len)
|
||||
pos++;
|
||||
break;
|
||||
case BS :
|
||||
if (pos > 0)
|
||||
{
|
||||
movmem(&s[pos], &s[pos - 1], len - pos + 1);
|
||||
pos--;
|
||||
len--;
|
||||
}
|
||||
break;
|
||||
case DELKEY :
|
||||
if (pos < len)
|
||||
{
|
||||
movmem(&s[pos + 1], &s[pos], len - pos);
|
||||
len--;
|
||||
}
|
||||
break;
|
||||
case CR :
|
||||
break;
|
||||
case UPKEY :
|
||||
c = CR;
|
||||
break;
|
||||
case DOWNKEY :
|
||||
c = CR;
|
||||
break;
|
||||
case ESC :
|
||||
len = 0;
|
||||
break;
|
||||
default :
|
||||
if (((legal[0] == 0) || (strchr(legal, c) != NULL)) &&
|
||||
((c >= ' ') && (c <= '~')) &&
|
||||
(len < maxlength))
|
||||
{
|
||||
if (insert)
|
||||
{
|
||||
memmove(&s[pos + 1], &s[pos], len - pos + 1);
|
||||
len++;
|
||||
}
|
||||
else if (pos >= len)
|
||||
len++;
|
||||
s[pos++] = c;
|
||||
}
|
||||
break;
|
||||
} /* switch */
|
||||
s[len] = 0;
|
||||
}
|
||||
while ((c != CR) && (c != ESC));
|
||||
clearinput();
|
||||
changecursor(FALSE);
|
||||
setcursor(nocursor);
|
||||
return(c != ESC);
|
||||
} /* editstring */
|
||||
|
||||
void getinput(int c)
|
||||
/* Reads and acts on an input string from the keyboard that started with c. */
|
||||
{
|
||||
char s[MAXINPUT + 1];
|
||||
|
||||
s[0] = c;
|
||||
s[1] = 0;
|
||||
if (!editstring(s, "", MAXINPUT) || (s[0] == 0))
|
||||
return;
|
||||
act(s);
|
||||
changed = TRUE;
|
||||
} /* getinput */
|
||||
|
||||
int getint(int *number, int low, int high)
|
||||
/* Reads in a positive integer from low to high */
|
||||
{
|
||||
int i, good = FALSE;
|
||||
char s[5], message[81];
|
||||
|
||||
s[0] = 0;
|
||||
sprintf(message, MSGBADNUMBER, low, high);
|
||||
do
|
||||
{
|
||||
if (!editstring(s, "1234567890", 4))
|
||||
return(FALSE);
|
||||
i = atoi(s);
|
||||
if ((good = ((i >= low) && (i <= high))) == 0)
|
||||
errormsg(message);
|
||||
}
|
||||
while (!good);
|
||||
*number = i;
|
||||
return(TRUE);
|
||||
} /* getint */
|
||||
|
||||
int getcell(int *col, int *row)
|
||||
/* Reads in a cell name that was typed in - Returns FALSE if ESC was pressed */
|
||||
{
|
||||
int first = TRUE, good = FALSE, len, numlen = rowwidth(MAXROWS),
|
||||
oldcol = *col, oldrow = *row;
|
||||
char data[10], *input, *start, numstring[6];
|
||||
|
||||
data[0] = 0;
|
||||
do
|
||||
{
|
||||
if (!first)
|
||||
errormsg(MSGBADCELL);
|
||||
first = FALSE;
|
||||
input = data;
|
||||
if (!editstring(data, "", numlen + 2))
|
||||
{
|
||||
*col = oldcol;
|
||||
*row = oldrow;
|
||||
return(FALSE);
|
||||
}
|
||||
*col = toupper(*(input++)) - 'A';
|
||||
if (isalpha(*input))
|
||||
{
|
||||
*col *= 26;
|
||||
*col += toupper(*(input++)) - 'A' + 26;
|
||||
}
|
||||
if (*col >= MAXCOLS)
|
||||
continue;
|
||||
start = input;
|
||||
for (len = 0; len < numlen; len++)
|
||||
{
|
||||
if (!isdigit(*(input++)))
|
||||
{
|
||||
input--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (len == 0)
|
||||
continue;
|
||||
strncpy(numstring, start, len);
|
||||
numstring[len] = 0;
|
||||
*row = atoi(numstring) - 1;
|
||||
if ((*row >= MAXROWS) || (*row == -1) || (*input != 0))
|
||||
continue;
|
||||
good = TRUE;
|
||||
}
|
||||
while (!good);
|
||||
return(TRUE);
|
||||
} /* getcell */
|
||||
int getyesno(int *yesno, char *prompt)
|
||||
/* Prints a prompt and gets a yes or no answer - returns TRUE if ESC was
|
||||
pressed, FALSE if not.
|
||||
*/
|
||||
{
|
||||
writeprompt(prompt);
|
||||
setcursor(shortcursor);
|
||||
do
|
||||
{
|
||||
*yesno = toupper(getkey());
|
||||
if (*yesno == ESC)
|
||||
{
|
||||
setcursor(nocursor);
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
while (strchr("YN", *yesno) == NULL);
|
||||
setcursor(nocursor);
|
||||
return(TRUE);
|
||||
} /* getyesno */
|
||||
|
||||
|
830
Borland Turbo C v2/MCOMMAND.C
Normal file
830
Borland Turbo C v2/MCOMMAND.C
Normal file
@ -0,0 +1,830 @@
|
||||
/* Turbo C - (C) Copyright 1987, 1988 by Borland International */
|
||||
|
||||
#include <string.h>
|
||||
#include <mem.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <conio.h>
|
||||
#include "mcalc.h"
|
||||
|
||||
char *name = MSGNAME;
|
||||
|
||||
void moverowup(void)
|
||||
/* Moves up 1 row */
|
||||
{
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
if (currow > toprow)
|
||||
currow--;
|
||||
else if (toprow != 0)
|
||||
{
|
||||
scroll(DOWN, 1, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE);
|
||||
displayrow(--toprow, NOUPDATE);
|
||||
currow--;
|
||||
setbottomrow();
|
||||
}
|
||||
} /* moverowup */
|
||||
|
||||
void moverowdown(void)
|
||||
/* Moves down one row */
|
||||
{
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
if (currow < bottomrow)
|
||||
currow++;
|
||||
else if (bottomrow < (MAXROWS - 1))
|
||||
{
|
||||
scroll(UP, 1, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE);
|
||||
toprow++;
|
||||
currow++;
|
||||
setbottomrow();
|
||||
displayrow(bottomrow, NOUPDATE);
|
||||
}
|
||||
} /* moverowdown */
|
||||
|
||||
void movecolleft(void)
|
||||
/* Moves left one column */
|
||||
{
|
||||
int col, oldleftcol;
|
||||
unsigned char oldcolstart[SCREENCOLS];
|
||||
|
||||
oldleftcol = leftcol;
|
||||
movmem(colstart, oldcolstart, sizeof(colstart));
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
if (curcol > leftcol)
|
||||
curcol--;
|
||||
else if (leftcol != 0)
|
||||
{
|
||||
curcol--;
|
||||
leftcol--;
|
||||
setrightcol();
|
||||
setleftcol();
|
||||
if (oldleftcol <= rightcol)
|
||||
scroll(RIGHT, colstart[oldleftcol - leftcol] - LEFTMARGIN, LEFTMARGIN + 1,
|
||||
3, 80, SCREENROWS + 2, WHITE);
|
||||
clearlastcol();
|
||||
for (col = leftcol; col <= oldleftcol - 1; col++)
|
||||
displaycol(col, NOUPDATE);
|
||||
}
|
||||
} /* movecolleft */
|
||||
|
||||
void movecolright(void)
|
||||
/* Moves right one column */
|
||||
{
|
||||
int col, oldleftcol, oldrightcol;
|
||||
unsigned char oldcolstart[SCREENCOLS];
|
||||
|
||||
movmem(colstart, oldcolstart, sizeof(colstart));
|
||||
oldleftcol = leftcol;
|
||||
oldrightcol = rightcol;
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
if (curcol < rightcol)
|
||||
curcol++;
|
||||
else if (rightcol < (MAXCOLS - 1))
|
||||
{
|
||||
curcol++;
|
||||
rightcol++;
|
||||
setleftcol();
|
||||
setrightcol();
|
||||
if (oldrightcol >= leftcol)
|
||||
scroll(LEFT, oldcolstart[leftcol - oldleftcol] - LEFTMARGIN,
|
||||
LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE);
|
||||
clearlastcol();
|
||||
for (col = oldrightcol + 1; col <= rightcol; col++)
|
||||
displaycol(col, NOUPDATE);
|
||||
}
|
||||
} /* movecolright */
|
||||
|
||||
void recalc(void)
|
||||
/* Recalculates all of the numbers in the speadsheet */
|
||||
{
|
||||
int col, row, dummy;
|
||||
|
||||
for (col = 0; col <= lastcol; col++)
|
||||
{
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
if ((cell[col][row] != NULL) && (cell[col][row]->attrib == FORMULA))
|
||||
cell[col][row]->v.f.fvalue = parse(cell[col][row]->v.f.formula, &dummy);
|
||||
}
|
||||
}
|
||||
displayscreen(UPDATE);
|
||||
} /* recalc */
|
||||
|
||||
void changeautocalc(int newmode)
|
||||
/* Changes and prints the current AutoCalc value on the screen */
|
||||
{
|
||||
char s[15];
|
||||
|
||||
if (!autocalc && newmode)
|
||||
recalc();
|
||||
autocalc = newmode;
|
||||
if (autocalc)
|
||||
strcpy(s, MSGAUTOCALC);
|
||||
else
|
||||
s[0] = 0;
|
||||
writef(73, 1, MSGAUTOCALCCOLOR, strlen(MSGAUTOCALC), s);
|
||||
} /* autocalc */
|
||||
|
||||
void changeformdisplay(int newmode)
|
||||
/* Changes and prints the current formula display value on the screen */
|
||||
{
|
||||
char s[15];
|
||||
|
||||
formdisplay = newmode;
|
||||
if (formdisplay)
|
||||
strcpy(s, MSGFORMDISPLAY);
|
||||
else
|
||||
s[0] = 0;
|
||||
writef(65, 1, MSGFORMDISPLAYCOLOR, strlen(MSGFORMDISPLAY), s);
|
||||
} /* autocalc */
|
||||
|
||||
void editcell(CELLPTR ecell)
|
||||
/* Edits a selected cell */
|
||||
{
|
||||
char s[MAXINPUT + 1];
|
||||
|
||||
if (ecell == NULL)
|
||||
return;
|
||||
switch(ecell->attrib)
|
||||
{
|
||||
case TEXT :
|
||||
strcpy(s, ecell->v.text);
|
||||
break;
|
||||
case VALUE :
|
||||
if (ecell->v.value == HUGE_VAL)
|
||||
strcpy(s, "0");
|
||||
else
|
||||
sprintf(s, "%.*f", MAXPLACES, ecell->v.value);
|
||||
break;
|
||||
case FORMULA :
|
||||
strcpy(s, ecell->v.f.formula);
|
||||
break;
|
||||
} /* switch */
|
||||
if (!editstring(s, "", MAXINPUT) || (s[0] == 0))
|
||||
return;
|
||||
act(s);
|
||||
changed = TRUE;
|
||||
} /* editcell */
|
||||
|
||||
void clearsheet(void)
|
||||
/* Clears the current spreadsheet */
|
||||
{
|
||||
int col, row;
|
||||
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
for (col = 0; col <= lastcol; col++)
|
||||
deletecell(col, row, NOUPDATE);
|
||||
}
|
||||
initvars();
|
||||
setrightcol();
|
||||
setbottomrow();
|
||||
displayscreen(NOUPDATE);
|
||||
printfreemem();
|
||||
changed = FALSE;
|
||||
} /* clearsheet */
|
||||
|
||||
struct CELLREC rec;
|
||||
|
||||
void loadsheet(char *filename)
|
||||
/* Loads a new spreadsheet */
|
||||
{
|
||||
int size, allocated, reallastcol = 0, reallastrow = 0, file;
|
||||
char check[81];
|
||||
|
||||
if (filename[0] == 0)
|
||||
{
|
||||
writeprompt(MSGFILENAME);
|
||||
if (!editstring(filename, "", MAXINPUT))
|
||||
return;
|
||||
}
|
||||
if (access(filename, 0))
|
||||
{
|
||||
errormsg(MSGNOEXIST);
|
||||
return;
|
||||
}
|
||||
if ((file = open(filename, O_RDWR | O_BINARY)) == -1)
|
||||
{
|
||||
errormsg(MSGNOOPEN);
|
||||
return;
|
||||
}
|
||||
read(file, check, strlen(name) + 1);
|
||||
if (strcmp(check, name) != 0)
|
||||
{
|
||||
errormsg(MSGNOMICROCALC);
|
||||
close(file);
|
||||
return;
|
||||
}
|
||||
writef(1, 25, PROMPTCOLOR, 79, MSGLOADING);
|
||||
gotoxy(strlen(MSGLOADING) + 1, 25);
|
||||
clearsheet();
|
||||
read(file, (char *)&size, 1);
|
||||
read(file, (char *)&lastcol, 2);
|
||||
read(file, (char *)&lastrow, 2);
|
||||
read(file, (char *)&size, 2);
|
||||
read(file, colwidth, sizeof(colwidth));
|
||||
do
|
||||
{
|
||||
if (read(file, (char *)&curcol, 2) <= 0)
|
||||
break;
|
||||
read(file, (char *)&currow, 2);
|
||||
read(file, &format[curcol][currow], 1);
|
||||
read(file, (char *)&size, 2);
|
||||
read(file, (char *)&rec, size);
|
||||
switch (rec.attrib)
|
||||
{
|
||||
case TEXT :
|
||||
if ((allocated = alloctext(curcol, currow, rec.v.text)) == TRUE)
|
||||
setoflags(curcol, currow, NOUPDATE);
|
||||
break;
|
||||
case VALUE :
|
||||
allocated = allocvalue(curcol, currow, rec.v.value);
|
||||
break;
|
||||
case FORMULA :
|
||||
allocated = allocformula(curcol, currow, rec.v.f.formula, rec.v.f.fvalue);
|
||||
break;
|
||||
} /* switch */
|
||||
if (!allocated)
|
||||
{
|
||||
errormsg(MSGFILELOMEM);
|
||||
lastrow = reallastrow;
|
||||
lastcol = reallastcol;
|
||||
format[curcol][currow] = DEFAULTFORMAT;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (curcol > reallastcol)
|
||||
reallastcol = curcol;
|
||||
if (currow > reallastrow)
|
||||
reallastrow = currow;
|
||||
}
|
||||
}
|
||||
while (TRUE);
|
||||
writef(1, 25, WHITE, strlen(MSGLOADING), "");
|
||||
gotoxy(1, 25);
|
||||
printfreemem();
|
||||
close(file);
|
||||
curcol = currow = 0;
|
||||
setrightcol();
|
||||
displayscreen(NOUPDATE);
|
||||
changed = FALSE;
|
||||
} /* loadsheet */
|
||||
|
||||
void savesheet(void)
|
||||
/* Saves the current spreadsheet */
|
||||
{
|
||||
char filename[MAXINPUT+1], eof = 26;
|
||||
int size, col, row, overwrite, file;
|
||||
CELLPTR cellptr;
|
||||
|
||||
filename[0] = 0;
|
||||
writeprompt(MSGFILENAME);
|
||||
if (!editstring(filename, "", MAXINPUT))
|
||||
return;
|
||||
if (!access(filename, 0))
|
||||
{
|
||||
if (!getyesno(&overwrite, MSGOVERWRITE) || (overwrite == 'N'))
|
||||
return;
|
||||
}
|
||||
if ((file = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
|
||||
S_IREAD | S_IWRITE)) == -1)
|
||||
{
|
||||
errormsg(MSGNOOPEN);
|
||||
return;
|
||||
}
|
||||
writef(1, 25, PROMPTCOLOR, 79, MSGSAVING);
|
||||
gotoxy(strlen(MSGSAVING) + 1, 25);
|
||||
write(file, name, strlen(name) + 1);
|
||||
write(file, &eof, 1);
|
||||
write(file, (char *)&lastcol, 2);
|
||||
write(file, (char *)&lastrow, 2);
|
||||
size = MAXCOLS;
|
||||
write(file, (char *)&size, 2);
|
||||
write(file, colwidth, sizeof(colwidth));
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
for (col = lastcol; col >= 0; col--)
|
||||
{
|
||||
if (cell[col][row] != NULL)
|
||||
{
|
||||
cellptr = cell[col][row];
|
||||
switch(cellptr->attrib)
|
||||
{
|
||||
case TEXT :
|
||||
size = strlen(cellptr->v.text) + 2;
|
||||
break;
|
||||
case VALUE :
|
||||
size = sizeof(double) + 1;
|
||||
break;
|
||||
case FORMULA :
|
||||
size = strlen(cellptr->v.f.formula) + 2 + sizeof(double);
|
||||
break;
|
||||
} /* switch */
|
||||
write(file, (char *)&col, 2);
|
||||
write(file, (char *)&row, 2);
|
||||
write(file, (char *)&format[col][row], 1);
|
||||
write(file, (char *)&size, 2);
|
||||
write(file, (char *)cellptr, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
close(file);
|
||||
writef(1, 25, WHITE, strlen(MSGSAVING), "");
|
||||
gotoxy(1, 25);
|
||||
changed = FALSE;
|
||||
} /* savesheet */
|
||||
|
||||
int pagerows(int row, int toppage, int border)
|
||||
/* Returns the number of rows to print */
|
||||
{
|
||||
int rows;
|
||||
|
||||
rows = toppage ? 66 - TOPMARGIN : 66;
|
||||
if (border)
|
||||
rows--;
|
||||
if (row + rows - 1 > lastrow)
|
||||
return(lastrow - row + 1);
|
||||
else
|
||||
return(rows);
|
||||
} /* pagerows */
|
||||
|
||||
int pagecols(int col, int border, int columns)
|
||||
/* Returns the number of columns to print starting at col */
|
||||
{
|
||||
int len = ((col == 0) && (border)) ? columns - LEFTMARGIN : columns;
|
||||
int firstcol = col;
|
||||
|
||||
while ((len > 0) && (col <= lastcol))
|
||||
len -= colwidth[col++];
|
||||
if (len < 0)
|
||||
col--;
|
||||
return(col - firstcol);
|
||||
} /* pagecols */
|
||||
|
||||
void printsheet(void)
|
||||
/* Prints a copy of the spreadsheet to a file or to the printer */
|
||||
{
|
||||
char filename[MAXINPUT + 1], s[133], colstr[MAXCOLWIDTH + 1];
|
||||
FILE *file;
|
||||
int columns, counter1, counter2, counter3, col = 0, row, border, toppage,
|
||||
lcol, lrow, dummy, printed, oldlastcol;
|
||||
|
||||
filename[0] = 0;
|
||||
writeprompt(MSGPRINT);
|
||||
if (!editstring(filename, "", MAXINPUT))
|
||||
return;
|
||||
if (filename[0] == 0)
|
||||
strcpy(filename, "PRN");
|
||||
if ((file = fopen(filename, "wt")) == NULL)
|
||||
{
|
||||
errormsg(MSGNOOPEN);
|
||||
return;
|
||||
}
|
||||
oldlastcol = lastcol;
|
||||
for (counter1 = 0; counter1 <= lastrow; counter1++)
|
||||
{
|
||||
for (counter2 = lastcol; counter2 < MAXCOLS; counter2++)
|
||||
{
|
||||
if (format[counter2][counter1] >= OVERWRITE)
|
||||
lastcol = counter2;
|
||||
}
|
||||
}
|
||||
if (!getyesno(&columns, MSGCOLUMNS))
|
||||
return;
|
||||
columns = (columns == 'Y') ? 131 : 79;
|
||||
if (!getyesno(&border, MSGBORDER))
|
||||
return;
|
||||
border = (border == 'Y');
|
||||
while (col <= lastcol)
|
||||
{
|
||||
row = 0;
|
||||
toppage = TRUE;
|
||||
lcol = pagecols(col, border, columns) + col;
|
||||
while (row <= lastrow)
|
||||
{
|
||||
lrow = pagerows(row, toppage, border) + row;
|
||||
printed = 0;
|
||||
if (toppage)
|
||||
{
|
||||
for (counter1 = 0; counter1 < TOPMARGIN; counter1++)
|
||||
{
|
||||
fprintf(file, "\n");
|
||||
printed++;
|
||||
}
|
||||
}
|
||||
for (counter1 = row; counter1 < lrow; counter1++)
|
||||
{
|
||||
if ((border) && (counter1 == row) && (toppage))
|
||||
{
|
||||
if ((col == 0) && (border))
|
||||
sprintf(s, "%*s", LEFTMARGIN, "");
|
||||
else
|
||||
s[0] = 0;
|
||||
for (counter3 = col; counter3 < lcol; counter3++)
|
||||
{
|
||||
centercolstring(counter3, colstr);
|
||||
strcat(s, colstr);
|
||||
}
|
||||
fprintf(file, "%s\n", s);
|
||||
printed++;
|
||||
}
|
||||
if ((col == 0) && (border))
|
||||
sprintf(s, "%-*d", LEFTMARGIN, counter1 + 1);
|
||||
else
|
||||
s[0] = 0;
|
||||
for (counter2 = col; counter2 < lcol; counter2++)
|
||||
strcat(s, cellstring(counter2, counter1, &dummy, FORMAT));
|
||||
fprintf(file, "%s\n", s);
|
||||
printed++;
|
||||
}
|
||||
row = lrow;
|
||||
toppage = FALSE;
|
||||
if (printed < 66)
|
||||
fprintf(file, "%c", FORMFEED);
|
||||
}
|
||||
col = lcol;
|
||||
}
|
||||
fclose(file);
|
||||
lastcol = oldlastcol;
|
||||
} /* printsheet */
|
||||
|
||||
void setcolwidth(int col)
|
||||
/* Sets the new column width for a selected column */
|
||||
{
|
||||
int width, row;
|
||||
|
||||
writeprompt(MSGCOLWIDTH);
|
||||
if (!getint(&width, MINCOLWIDTH, MAXCOLWIDTH))
|
||||
return;
|
||||
colwidth[col] = width;
|
||||
setrightcol();
|
||||
if (rightcol < col)
|
||||
{
|
||||
rightcol = col;
|
||||
setleftcol();
|
||||
setrightcol();
|
||||
}
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
if ((cell[col][row] != NULL) && (cell[col][row]->attrib == TEXT))
|
||||
clearoflags(col + 1, row, NOUPDATE);
|
||||
else
|
||||
clearoflags(col, row, NOUPDATE);
|
||||
updateoflags(col, row, NOUPDATE);
|
||||
}
|
||||
displayscreen(NOUPDATE);
|
||||
changed = TRUE;
|
||||
} /* setcolwidth */
|
||||
|
||||
void gotocell()
|
||||
/* Moves to a selected cell */
|
||||
{
|
||||
writeprompt(MSGGOTO);
|
||||
if (!getcell(&curcol, &currow))
|
||||
return;
|
||||
leftcol = curcol;
|
||||
toprow = currow;
|
||||
setbottomrow();
|
||||
setrightcol();
|
||||
setleftcol();
|
||||
displayscreen(NOUPDATE);
|
||||
} /* gotocell */
|
||||
|
||||
void formatcells(void)
|
||||
/* Prompts the user for a selected format and range of cells */
|
||||
{
|
||||
int col, row, col1, col2, row1, row2, temp, newformat = 0;
|
||||
|
||||
writeprompt(MSGCELL1);
|
||||
if (!getcell(&col1, &row1))
|
||||
return;
|
||||
writeprompt(MSGCELL2);
|
||||
if (!getcell(&col2, &row2))
|
||||
return;
|
||||
if ((col1 != col2) && (row1 != row2))
|
||||
errormsg(MSGDIFFCOLROW);
|
||||
else
|
||||
{
|
||||
if (col1 > col2)
|
||||
swap(&col1, &col2);
|
||||
if (row1 > row2)
|
||||
swap(&row1, &row2);
|
||||
if (!getyesno(&temp, MSGRIGHTJUST))
|
||||
return;
|
||||
newformat += (temp == 'Y') * RJUSTIFY;
|
||||
if (!getyesno(&temp, MSGDOLLAR))
|
||||
return;
|
||||
newformat += (temp == 'Y') * DOLLAR;
|
||||
if (!getyesno(&temp, MSGCOMMAS))
|
||||
return;
|
||||
newformat += (temp == 'Y') * COMMAS;
|
||||
if (newformat & DOLLAR)
|
||||
newformat += 2;
|
||||
else
|
||||
{
|
||||
writeprompt(MSGPLACES);
|
||||
if (!getint(&temp, 0, MAXPLACES))
|
||||
return;
|
||||
newformat += temp;
|
||||
}
|
||||
for (col = col1; col <= col2; col++)
|
||||
{
|
||||
for (row = row1; row <= row2; row++)
|
||||
{
|
||||
format[col][row] = (format[col][row] & OVERWRITE) | newformat;
|
||||
if ((col >= leftcol) && (col <= rightcol) &&
|
||||
(row >= toprow) && (row <= bottomrow))
|
||||
displaycell(col, row, NOHIGHLIGHT, NOUPDATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
changed = TRUE;
|
||||
} /* formatcells */
|
||||
|
||||
void deletecol(int col)
|
||||
/* Deletes a column */
|
||||
{
|
||||
int counter, row;
|
||||
|
||||
for (counter = 0; counter <= lastrow; counter++)
|
||||
deletecell(col, counter, NOUPDATE);
|
||||
printfreemem();
|
||||
if (col != MAXCOLS - 1)
|
||||
{
|
||||
movmem(&cell[col + 1][0], &cell[col][0], MAXROWS * sizeof(CELLPTR) *
|
||||
(MAXCOLS - col - 1));
|
||||
movmem(&format[col + 1][0], &format[col][0], MAXROWS * (MAXCOLS - col - 1));
|
||||
movmem(&colwidth[col + 1], &colwidth[col], MAXCOLS - col - 1);
|
||||
}
|
||||
setmem(&cell[MAXCOLS - 1][0], MAXROWS * sizeof(CELLPTR), 0);
|
||||
setmem(&format[MAXCOLS - 1][0], MAXROWS, DEFAULTFORMAT);
|
||||
colwidth[MAXCOLS - 1] = DEFAULTWIDTH;
|
||||
if ((lastcol >= col) && (lastcol > 0))
|
||||
lastcol--;
|
||||
setrightcol();
|
||||
if (curcol > rightcol)
|
||||
{
|
||||
rightcol++;
|
||||
setleftcol();
|
||||
}
|
||||
clearlastcol();
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
{
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
if ((cell[counter][row] != NULL) &&
|
||||
(cell[counter][row]->attrib == FORMULA))
|
||||
fixformula(counter, row, COLDEL, col);
|
||||
updateoflags(col, row, NOUPDATE);
|
||||
}
|
||||
}
|
||||
while (col <= rightcol)
|
||||
displaycol(col++, NOUPDATE);
|
||||
changed = TRUE;
|
||||
recalc();
|
||||
} /* deletecol */
|
||||
|
||||
void insertcol(int col)
|
||||
/* Inserts a column */
|
||||
{
|
||||
int counter, row;
|
||||
|
||||
if (lastcol == MAXCOLS - 1)
|
||||
{
|
||||
for (counter = 0; counter <= lastrow; counter++)
|
||||
deletecell(lastcol, counter, NOUPDATE);
|
||||
printfreemem();
|
||||
}
|
||||
if (col != MAXCOLS - 1)
|
||||
{
|
||||
movmem(&cell[col][0], &cell[col + 1][0], MAXROWS * sizeof(CELLPTR) *
|
||||
(MAXCOLS - col - 1));
|
||||
movmem(&format[col][0], &format[col + 1][0], MAXROWS * (MAXCOLS - col - 1));
|
||||
movmem(&colwidth[col], &colwidth[col + 1], MAXCOLS - col - 1);
|
||||
}
|
||||
setmem(&cell[col][0], MAXROWS * sizeof(CELLPTR), 0);
|
||||
setmem(&format[col][0], MAXROWS, DEFAULTFORMAT);
|
||||
colwidth[col] = DEFAULTWIDTH;
|
||||
lastcol = MAXCOLS - 1;
|
||||
setlastcol();
|
||||
setrightcol();
|
||||
if (curcol > rightcol)
|
||||
{
|
||||
rightcol++;
|
||||
setleftcol();
|
||||
}
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
{
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
if ((cell[counter][row] != NULL) &&
|
||||
(cell[counter][row]->attrib == FORMULA))
|
||||
fixformula(counter, row, COLADD, col);
|
||||
updateoflags(col, row, NOUPDATE);
|
||||
}
|
||||
}
|
||||
while (col <= rightcol)
|
||||
displaycol(col++, NOUPDATE);
|
||||
changed = TRUE;
|
||||
recalc();
|
||||
} /* insertcol */
|
||||
|
||||
void deleterow(int row)
|
||||
/* Deletes a row */
|
||||
{
|
||||
int counter, rowc;
|
||||
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
deletecell(counter, row, NOUPDATE);
|
||||
printfreemem();
|
||||
if (row != MAXROWS - 1)
|
||||
{
|
||||
for (counter = 0; counter < MAXCOLS; counter++)
|
||||
{
|
||||
movmem(&cell[counter][row + 1], &cell[counter][row],
|
||||
sizeof(CELLPTR) * (MAXROWS - row - 1));
|
||||
movmem(&format[counter][row + 1], &format[counter][row], MAXROWS - row - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
{
|
||||
cell[counter][MAXROWS - 1] = NULL;
|
||||
format[counter][MAXROWS - 1] = DEFAULTFORMAT;
|
||||
}
|
||||
}
|
||||
if ((lastrow >= row) && (lastrow > 0))
|
||||
lastrow--;
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
{
|
||||
for (rowc = 0; rowc <= lastrow; rowc++)
|
||||
{
|
||||
if ((cell[counter][rowc] != NULL) &&
|
||||
(cell[counter][rowc]->attrib == FORMULA))
|
||||
fixformula(counter, rowc, ROWDEL, row);
|
||||
}
|
||||
}
|
||||
while (row <= bottomrow)
|
||||
displayrow(row++, NOUPDATE);
|
||||
changed = TRUE;
|
||||
recalc();
|
||||
} /* deleterow */
|
||||
|
||||
void insertrow(int row)
|
||||
/* Inserts a row */
|
||||
{
|
||||
int counter, rowc;
|
||||
|
||||
if (lastrow == MAXROWS - 1)
|
||||
{
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
deletecell(counter, lastrow, NOUPDATE);
|
||||
printfreemem();
|
||||
}
|
||||
if (row != MAXROWS - 1)
|
||||
{
|
||||
for (counter = 0; counter < MAXCOLS; counter++)
|
||||
{
|
||||
movmem(&cell[counter][row], &cell[counter][row + 1],
|
||||
sizeof(CELLPTR) * (MAXROWS - row - 1));
|
||||
movmem(&format[counter][row], &format[counter][row + 1], MAXROWS - row - 1);
|
||||
}
|
||||
}
|
||||
for (counter = 0; counter < MAXCOLS; counter++)
|
||||
{
|
||||
cell[counter][row] = NULL;
|
||||
format[counter][row] = DEFAULTFORMAT;
|
||||
}
|
||||
lastrow = MAXROWS - 1;
|
||||
setlastrow();
|
||||
for (counter = 0; counter <= lastcol; counter++)
|
||||
{
|
||||
for (rowc = 0; rowc <= lastrow; rowc++)
|
||||
{
|
||||
if ((cell[counter][rowc] != NULL) &&
|
||||
(cell[counter][rowc]->attrib == FORMULA))
|
||||
fixformula(counter, rowc, ROWADD, row);
|
||||
}
|
||||
}
|
||||
while (row <= bottomrow)
|
||||
displayrow(row++, NOUPDATE);
|
||||
changed = TRUE;
|
||||
recalc();
|
||||
} /* insertrow */
|
||||
|
||||
void smenu(void)
|
||||
/* Executes the commands in the spreadsheet menu */
|
||||
{
|
||||
char filename[MAXINPUT + 1];
|
||||
|
||||
filename[0] = 0;
|
||||
switch(getcommand(SMENU, SCOMMAND))
|
||||
{
|
||||
case 0 :
|
||||
checkforsave();
|
||||
loadsheet(filename);
|
||||
break;
|
||||
case 1 :
|
||||
savesheet();
|
||||
break;
|
||||
case 2 :
|
||||
printsheet();
|
||||
break;
|
||||
case 3 :
|
||||
checkforsave();
|
||||
clearsheet();
|
||||
break;
|
||||
} /* switch */
|
||||
} /* smenu */
|
||||
|
||||
void cmenu(void)
|
||||
/* Executes the commands in the column menu */
|
||||
{
|
||||
switch(getcommand(CMENU, CCOMMAND))
|
||||
{
|
||||
case 0 :
|
||||
insertcol(curcol);
|
||||
break;
|
||||
case 1 :
|
||||
deletecol(curcol);
|
||||
break;
|
||||
case 2 :
|
||||
setcolwidth(curcol);
|
||||
break;
|
||||
} /* switch */
|
||||
} /* cmenu */
|
||||
|
||||
void rmenu(void)
|
||||
/* Executes the commands in the row menu */
|
||||
{
|
||||
switch(getcommand(RMENU, RCOMMAND))
|
||||
{
|
||||
case 0 :
|
||||
insertrow(currow);
|
||||
break;
|
||||
case 1 :
|
||||
deleterow(currow);
|
||||
break;
|
||||
} /* switch */
|
||||
} /* rmenu */
|
||||
|
||||
void umenu(void)
|
||||
/* Executes the commands in the utility menu */
|
||||
{
|
||||
switch(getcommand(UMENU, UCOMMAND))
|
||||
{
|
||||
case 0 :
|
||||
recalc();
|
||||
break;
|
||||
case 1 :
|
||||
changeformdisplay(!formdisplay);
|
||||
displayscreen(UPDATE);
|
||||
break;
|
||||
} /* switch */
|
||||
} /* umenu */
|
||||
|
||||
void mainmenu(void)
|
||||
/* Executes the commands in the main menu */
|
||||
{
|
||||
switch(getcommand(MENU, COMMAND))
|
||||
{
|
||||
case 0 :
|
||||
smenu();
|
||||
break;
|
||||
case 1 :
|
||||
formatcells();
|
||||
break;
|
||||
case 2 :
|
||||
deletecell(curcol, currow, UPDATE);
|
||||
printfreemem();
|
||||
if (autocalc)
|
||||
recalc();
|
||||
break;
|
||||
case 3 :
|
||||
gotocell();
|
||||
break;
|
||||
case 4 :
|
||||
cmenu();
|
||||
break;
|
||||
case 5 :
|
||||
rmenu();
|
||||
break;
|
||||
case 6 :
|
||||
editcell(curcell);
|
||||
break;
|
||||
case 7 :
|
||||
umenu();
|
||||
break;
|
||||
case 8 :
|
||||
changeautocalc(!autocalc);
|
||||
break;
|
||||
case 9 :
|
||||
checkforsave();
|
||||
stop = TRUE;
|
||||
break;
|
||||
} /* switch */
|
||||
} /* mainmenu */
|
||||
|
602
Borland Turbo C v2/MCPARSER.C
Normal file
602
Borland Turbo C v2/MCPARSER.C
Normal file
@ -0,0 +1,602 @@
|
||||
/* Turbo C - (C) Copyright 1987,1988 by Borland International */
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include "mcalc.h"
|
||||
|
||||
#define PLUS 0
|
||||
#define MINUS 1
|
||||
#define TIMES 2
|
||||
#define DIVIDE 3
|
||||
#define EXP 4
|
||||
#define COLON 5
|
||||
#define OPAREN 6
|
||||
#define CPAREN 7
|
||||
#define NUM 8
|
||||
#define CELL 9
|
||||
#define FUNC 10
|
||||
#define EOLN 11
|
||||
#define BAD 12
|
||||
#define MAXFUNCNAMELEN 5
|
||||
|
||||
struct TOKENREC
|
||||
{
|
||||
char state;
|
||||
union
|
||||
{
|
||||
double value;
|
||||
struct
|
||||
{
|
||||
int row, col;
|
||||
} c;
|
||||
char funcname[MAXFUNCNAMELEN + 1];
|
||||
} x;
|
||||
};
|
||||
|
||||
static struct TOKENREC stack[PARSERSTACKSIZE], curtoken;
|
||||
int stacktop, tokentype, error;
|
||||
char *input, isformula;
|
||||
|
||||
int matherr(struct exception *e)
|
||||
{
|
||||
e->retval = HUGE_VAL;
|
||||
return(1);
|
||||
} /* matherr */
|
||||
|
||||
int isfunc(char *s)
|
||||
/* Returns TRUE if the string is a legal function, FALSE otherwise. */
|
||||
{
|
||||
int len = strlen(s);
|
||||
|
||||
if (strncmp(s, input, len) == 0)
|
||||
{
|
||||
strncpy(curtoken.x.funcname, input, len);
|
||||
curtoken.x.funcname[len] = 0;
|
||||
input += len;
|
||||
return(TRUE);
|
||||
}
|
||||
return(FALSE);
|
||||
} /* isfunc */
|
||||
|
||||
int nexttoken(void)
|
||||
/* Gets the next token from the input stream */
|
||||
{
|
||||
char *start, numstring[80];
|
||||
int decimal, len, numlen;
|
||||
|
||||
while (*input == ' ')
|
||||
input++;
|
||||
if (*input == 0)
|
||||
return(EOLN);
|
||||
if (strchr("0123456789.", *input))
|
||||
{
|
||||
start = input;
|
||||
len = 0;
|
||||
decimal = FALSE;
|
||||
while ((isdigit(*input)) ||
|
||||
((*input == '.') && (!decimal)))
|
||||
{
|
||||
if (*input == '.')
|
||||
decimal = TRUE;
|
||||
input++;
|
||||
len++;
|
||||
}
|
||||
if ((len == 1) && (start[0] == '.'))
|
||||
return(BAD);
|
||||
if (*input == 'E')
|
||||
{
|
||||
input++;
|
||||
len++;
|
||||
if (strchr("+-", *input) != NULL)
|
||||
{
|
||||
input++;
|
||||
len++;
|
||||
}
|
||||
numlen = 0;
|
||||
while ((isdigit(*input)) && (++numlen <= 3))
|
||||
{
|
||||
input++;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
strncpy(numstring, start, len);
|
||||
numstring[len] = 0;
|
||||
curtoken.x.value = atof(numstring);
|
||||
if (errno == ERANGE)
|
||||
return(BAD);
|
||||
return(NUM);
|
||||
}
|
||||
else if (isalpha(*input))
|
||||
{
|
||||
if
|
||||
(isfunc("ABS") ||
|
||||
isfunc("ACOS") ||
|
||||
isfunc("ASIN") ||
|
||||
isfunc("ATAN") ||
|
||||
isfunc("COSH") ||
|
||||
isfunc("COS") ||
|
||||
isfunc("EXP") ||
|
||||
isfunc("LOG10") ||
|
||||
isfunc("LOG") ||
|
||||
isfunc("POW10") ||
|
||||
isfunc("ROUND") ||
|
||||
isfunc("SINH") ||
|
||||
isfunc("SIN") ||
|
||||
isfunc("SQRT") ||
|
||||
isfunc("SQR") ||
|
||||
isfunc("TANH") ||
|
||||
isfunc("TAN") ||
|
||||
isfunc("TRUNC"))
|
||||
return(FUNC);
|
||||
if (formulastart(&input, &curtoken.x.c.col, &curtoken.x.c.row))
|
||||
{
|
||||
isformula = TRUE;
|
||||
return(CELL);
|
||||
}
|
||||
else
|
||||
return(BAD);
|
||||
}
|
||||
else switch(*(input++))
|
||||
{
|
||||
case '+' : return(PLUS);
|
||||
case '-' : return(MINUS);
|
||||
case '*' : return(TIMES);
|
||||
case '/' : return(DIVIDE);
|
||||
case '^' : return(EXP);
|
||||
case ':' : return(COLON);
|
||||
case '(' : return(OPAREN);
|
||||
case ')' : return(CPAREN);
|
||||
default : return(BAD);
|
||||
} /* switch */
|
||||
} /* nexttoken */
|
||||
|
||||
void push(struct TOKENREC *token)
|
||||
/* Pushes a new token onto the stack */
|
||||
{
|
||||
if (stacktop == PARSERSTACKSIZE - 1)
|
||||
{
|
||||
errormsg(MSGSTACKERROR);
|
||||
error = TRUE;
|
||||
}
|
||||
else
|
||||
stack[++stacktop] = *token;
|
||||
} /* push */
|
||||
|
||||
struct TOKENREC pop(void)
|
||||
/* Pops the top token off of the stack */
|
||||
{
|
||||
return(stack[stacktop--]);
|
||||
} /* pop */
|
||||
|
||||
int gotostate(int production)
|
||||
/* Finds the new state based on the last production and the top state. */
|
||||
{
|
||||
int state = stack[stacktop].state;
|
||||
|
||||
if (production <= 3)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case 0 : return(1);
|
||||
case 9 : return(19);
|
||||
case 20 : return(28);
|
||||
} /* switch */
|
||||
}
|
||||
else if (production <= 6)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case 0 :
|
||||
case 9 :
|
||||
case 20 : return(2);
|
||||
case 12 : return(21);
|
||||
case 13 : return(22);
|
||||
} /* switch */
|
||||
}
|
||||
else if (production <= 8)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case 0 :
|
||||
case 9 :
|
||||
case 12 :
|
||||
case 13 :
|
||||
case 20 : return(3);
|
||||
case 14 : return(23);
|
||||
case 15 : return(24);
|
||||
case 16 : return(25);
|
||||
} /* switch */
|
||||
}
|
||||
else if (production <= 10)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case 0 :
|
||||
case 9 :
|
||||
case 12 :
|
||||
case 13 :
|
||||
case 14 :
|
||||
case 15 :
|
||||
case 16 :
|
||||
case 20 : return(4);
|
||||
} /* switch */
|
||||
}
|
||||
else if (production <= 12)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case 0 :
|
||||
case 9 :
|
||||
case 12 :
|
||||
case 13 :
|
||||
case 14 :
|
||||
case 15 :
|
||||
case 16 :
|
||||
case 20 : return(6);
|
||||
case 5 : return(17);
|
||||
} /* switch */
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case 0 :
|
||||
case 5 :
|
||||
case 9 :
|
||||
case 12 :
|
||||
case 13 :
|
||||
case 14 :
|
||||
case 15 :
|
||||
case 16 :
|
||||
case 20 : return(8);
|
||||
} /* switch */
|
||||
}
|
||||
return(30);
|
||||
} /* gotostate */
|
||||
|
||||
double cellvalue(int col, int row)
|
||||
/* Finds the value of a particular cell */
|
||||
{
|
||||
if (cell[col][row] == NULL)
|
||||
return(0);
|
||||
if (cell[col][row]->attrib == TEXT)
|
||||
return(HUGE_VAL);
|
||||
if (cell[col][row]->attrib == FORMULA)
|
||||
return(cell[col][row]->v.f.fvalue);
|
||||
return(cell[col][row]->v.value);
|
||||
} /* cellvalue */
|
||||
|
||||
void shift(int state)
|
||||
/* Shifts a token onto the stack */
|
||||
{
|
||||
curtoken.state = state;
|
||||
push(&curtoken);
|
||||
tokentype = nexttoken();
|
||||
} /* shift */
|
||||
|
||||
void reduce(int reduction)
|
||||
/* Completes a reduction */
|
||||
{
|
||||
struct TOKENREC token1, token2;
|
||||
int counter;
|
||||
|
||||
switch (reduction)
|
||||
{
|
||||
case 1 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
token2 = pop();
|
||||
curtoken.x.value = token1.x.value + token2.x.value;
|
||||
break;
|
||||
case 2 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
token2 = pop();
|
||||
curtoken.x.value = token2.x.value - token1.x.value;
|
||||
break;
|
||||
case 4 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
token2 = pop();
|
||||
curtoken.x.value = token1.x.value * token2.x.value;
|
||||
break;
|
||||
case 5 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
token2 = pop();
|
||||
if (token1.x.value == 0)
|
||||
curtoken.x.value = HUGE_VAL;
|
||||
else
|
||||
curtoken.x.value = token2.x.value / token1.x.value;
|
||||
break;
|
||||
case 7 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
token2 = pop();
|
||||
curtoken.x.value = pow(token2.x.value, token1.x.value);
|
||||
break;
|
||||
case 9 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
curtoken.x.value = -token1.x.value;
|
||||
break;
|
||||
case 11 :
|
||||
token1 = pop();
|
||||
pop();
|
||||
token2 = pop();
|
||||
curtoken.x.value = 0;
|
||||
if (token1.x.c.row == token2.x.c.row)
|
||||
{
|
||||
if (token1.x.c.col < token2.x.c.col)
|
||||
error = TRUE;
|
||||
else
|
||||
{
|
||||
for (counter = token2.x.c.col; counter <= token1.x.c.col; counter++)
|
||||
curtoken.x.value += cellvalue(counter, token1.x.c.row);
|
||||
}
|
||||
}
|
||||
else if (token1.x.c.col == token2.x.c.col)
|
||||
{
|
||||
if (token1.x.c.row < token2.x.c.row)
|
||||
error = TRUE;
|
||||
else
|
||||
{
|
||||
for (counter = token2.x.c.row; counter <= token1.x.c.row; counter++)
|
||||
curtoken.x.value += cellvalue(token1.x.c.col, counter);
|
||||
}
|
||||
}
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 13 :
|
||||
curtoken = pop();
|
||||
curtoken.x.value = cellvalue(curtoken.x.c.col, curtoken.x.c.row);
|
||||
break;
|
||||
case 14 :
|
||||
pop();
|
||||
curtoken = pop();
|
||||
pop();
|
||||
break;
|
||||
case 16 :
|
||||
pop();
|
||||
curtoken = pop();
|
||||
pop();
|
||||
token1 = pop();
|
||||
if (strcmp(token1.x.funcname, "ABS") == 0)
|
||||
curtoken.x.value = fabs(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "ACOS") == 0)
|
||||
curtoken.x.value = acos(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "ASIN") == 0)
|
||||
curtoken.x.value = asin(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "ATAN") == 0)
|
||||
curtoken.x.value = atan(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "COSH") == 0)
|
||||
curtoken.x.value = cosh(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "COS") == 0)
|
||||
curtoken.x.value = cos(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "EXP") == 0)
|
||||
curtoken.x.value = exp(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "LOG10") == 0)
|
||||
curtoken.x.value = log10(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "LOG") == 0)
|
||||
curtoken.x.value = log(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "ROUND") == 0)
|
||||
curtoken.x.value = (int)(curtoken.x.value + 0.5);
|
||||
else if (strcmp(token1.x.funcname, "POW10") == 0)
|
||||
curtoken.x.value = pow10(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "SINH") == 0)
|
||||
curtoken.x.value = sinh(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "SIN") == 0)
|
||||
curtoken.x.value = sin(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "SQRT") == 0)
|
||||
curtoken.x.value = sqrt(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "SQR") == 0)
|
||||
curtoken.x.value *= curtoken.x.value;
|
||||
else if (strcmp(token1.x.funcname, "TANH") == 0)
|
||||
curtoken.x.value = tanh(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "TAN") == 0)
|
||||
curtoken.x.value = tan(curtoken.x.value);
|
||||
else if (strcmp(token1.x.funcname, "TRUNC") == 0)
|
||||
curtoken.x.value = (int)curtoken.x.value;
|
||||
break;
|
||||
case 3 :
|
||||
case 6 :
|
||||
case 8 :
|
||||
case 10 :
|
||||
case 12 :
|
||||
case 15 :
|
||||
curtoken = pop();
|
||||
break;
|
||||
} /* switch */
|
||||
curtoken.state = gotostate(reduction);
|
||||
push(&curtoken);
|
||||
} /* reduce */
|
||||
|
||||
double parse(char *s, int *att)
|
||||
/* Parses the string s - returns the value of the evaluated string, and puts
|
||||
the attribute in att: TEXT = 0, CONSTANT = 1, FORMULA = 2.
|
||||
*/
|
||||
{
|
||||
struct TOKENREC firsttoken;
|
||||
char accepted = FALSE;
|
||||
char copy[80];
|
||||
|
||||
error = FALSE;
|
||||
isformula = FALSE;
|
||||
input = copy;
|
||||
strupr(strcpy(copy, s));
|
||||
stacktop = -1;
|
||||
firsttoken.state = 0;
|
||||
firsttoken.x.value = 0;
|
||||
push(&firsttoken);
|
||||
tokentype = nexttoken();
|
||||
do
|
||||
{
|
||||
switch (stack[stacktop].state)
|
||||
{
|
||||
case 0 :
|
||||
case 9 :
|
||||
case 12 :
|
||||
case 13 :
|
||||
case 14 :
|
||||
case 15 :
|
||||
case 16 :
|
||||
case 20 :
|
||||
if (tokentype == NUM)
|
||||
shift(10);
|
||||
else if (tokentype == CELL)
|
||||
shift(7);
|
||||
else if (tokentype == FUNC)
|
||||
shift(11);
|
||||
else if (tokentype == MINUS)
|
||||
shift(5);
|
||||
else if (tokentype == OPAREN)
|
||||
shift(9);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 1 :
|
||||
if (tokentype == EOLN)
|
||||
accepted = TRUE;
|
||||
else if (tokentype == PLUS)
|
||||
shift(12);
|
||||
else if (tokentype == MINUS)
|
||||
shift(13);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 2 :
|
||||
if (tokentype == TIMES)
|
||||
shift(14);
|
||||
else if (tokentype == DIVIDE)
|
||||
shift(15);
|
||||
else
|
||||
reduce(3);
|
||||
break;
|
||||
case 3 :
|
||||
reduce(6);
|
||||
break;
|
||||
case 4 :
|
||||
if (tokentype == EXP)
|
||||
shift(16);
|
||||
else
|
||||
reduce(8);
|
||||
break;
|
||||
case 5 :
|
||||
if (tokentype == NUM)
|
||||
shift(10);
|
||||
else if (tokentype == CELL)
|
||||
shift(7);
|
||||
else if (tokentype == FUNC)
|
||||
shift(11);
|
||||
else if (tokentype == OPAREN)
|
||||
shift(9);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 6 :
|
||||
reduce(10);
|
||||
break;
|
||||
case 7 :
|
||||
if (tokentype == COLON)
|
||||
shift(18);
|
||||
else
|
||||
reduce(13);
|
||||
break;
|
||||
case 8 :
|
||||
reduce(12);
|
||||
break;
|
||||
case 10 :
|
||||
reduce(15);
|
||||
break;
|
||||
case 11 :
|
||||
if (tokentype == OPAREN)
|
||||
shift(20);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 17 :
|
||||
reduce(9);
|
||||
break;
|
||||
case 18 :
|
||||
if (tokentype == CELL)
|
||||
shift(26);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 19 :
|
||||
if (tokentype == PLUS)
|
||||
shift(12);
|
||||
else if (tokentype == MINUS)
|
||||
shift(13);
|
||||
else if (tokentype == CPAREN)
|
||||
shift(27);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 21 :
|
||||
if (tokentype == TIMES)
|
||||
shift(14);
|
||||
else if (tokentype == DIVIDE)
|
||||
shift(15);
|
||||
else
|
||||
reduce(1);
|
||||
break;
|
||||
case 22 :
|
||||
if (tokentype == TIMES)
|
||||
shift(14);
|
||||
else if (tokentype == DIVIDE)
|
||||
shift(15);
|
||||
else
|
||||
reduce(2);
|
||||
break;
|
||||
case 23 :
|
||||
reduce(4);
|
||||
break;
|
||||
case 24 :
|
||||
reduce(5);
|
||||
break;
|
||||
case 25 :
|
||||
reduce(7);
|
||||
break;
|
||||
case 26 :
|
||||
reduce(11);
|
||||
break;
|
||||
case 27 :
|
||||
reduce(14);
|
||||
break;
|
||||
case 28 :
|
||||
if (tokentype == PLUS)
|
||||
shift(12);
|
||||
else if (tokentype == MINUS)
|
||||
shift(13);
|
||||
else if (tokentype == CPAREN)
|
||||
shift(29);
|
||||
else
|
||||
error = TRUE;
|
||||
break;
|
||||
case 29 :
|
||||
reduce(16);
|
||||
break;
|
||||
case 30 :
|
||||
error = TRUE;
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
while ((!accepted) && (!error));
|
||||
if (error)
|
||||
{
|
||||
*att = TEXT;
|
||||
return(0);
|
||||
}
|
||||
if (isformula)
|
||||
*att = FORMULA;
|
||||
else
|
||||
*att = VALUE;
|
||||
strcpy(s, copy);
|
||||
return(stack[stacktop].x.value);
|
||||
} /* parse */
|
||||
|
630
Borland Turbo C v2/MCUTIL.C
Normal file
630
Borland Turbo C v2/MCUTIL.C
Normal file
@ -0,0 +1,630 @@
|
||||
/* Turbo C - (C) Copyright 1987,1988 by Borland International */
|
||||
|
||||
#include <math.h>
|
||||
#include <alloc.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <mem.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include "mcalc.h"
|
||||
|
||||
int alloctext(int col, int row, char *s)
|
||||
/* Allocates space for a text cell */
|
||||
{
|
||||
int size;
|
||||
CELLPTR cellptr;
|
||||
|
||||
if (memleft < (size = textcellsize(s)))
|
||||
return(FALSE);
|
||||
memleft -= size;
|
||||
cellptr = (CELLPTR)(malloc(strlen(s) + 2));
|
||||
cellptr->attrib = TEXT;
|
||||
strcpy(cellptr->v.text, s);
|
||||
cell[col][row] = cellptr;
|
||||
return(TRUE);
|
||||
} /* alloctext */
|
||||
|
||||
int allocvalue(int col, int row, double amt)
|
||||
/* Allocates space for a value cell */
|
||||
{
|
||||
CELLPTR cellptr;
|
||||
|
||||
if (memleft < valuecellsize)
|
||||
return(FALSE);
|
||||
memleft -= valuecellsize;
|
||||
cellptr = (CELLPTR)(malloc(sizeof(double) + 1));
|
||||
cellptr->attrib = VALUE;
|
||||
cellptr->v.value = amt;
|
||||
cell[col][row] = cellptr;
|
||||
return(TRUE);
|
||||
} /* allocvalue */
|
||||
|
||||
int allocformula(int col, int row, char *s, double amt)
|
||||
/* Allocates space for a formula cell */
|
||||
{
|
||||
int size;
|
||||
CELLPTR cellptr;
|
||||
|
||||
if (memleft < (size = formulacellsize(s)))
|
||||
return(FALSE);
|
||||
memleft -= size;
|
||||
cellptr = (CELLPTR)(malloc(strlen(s) + sizeof(double) + 2));
|
||||
cellptr->attrib = FORMULA;
|
||||
strcpy(cellptr->v.f.formula, s);
|
||||
cellptr->v.f.fvalue = amt;
|
||||
cell[col][row] = cellptr;
|
||||
return(TRUE);
|
||||
} /* allocformula */
|
||||
|
||||
void deletecell(int col, int row, int display)
|
||||
/* Deletes a cell */
|
||||
{
|
||||
CELLPTR cellptr = cell[col][row];
|
||||
|
||||
if (cellptr == NULL)
|
||||
return;
|
||||
switch (cellptr->attrib)
|
||||
{
|
||||
case TEXT :
|
||||
memleft += textcellsize(cellptr->v.text);
|
||||
clearoflags(col + 1, row, display);
|
||||
break;
|
||||
case VALUE :
|
||||
memleft += valuecellsize;
|
||||
break;
|
||||
case FORMULA :
|
||||
memleft += formulacellsize(cellptr->v.f.formula);
|
||||
break;
|
||||
} /* switch */
|
||||
format[col][row] &= ~OVERWRITE;
|
||||
free(cell[col][row]);
|
||||
cell[col][row] = NULL;
|
||||
if (col == lastcol)
|
||||
setlastcol();
|
||||
if (row == lastrow)
|
||||
setlastrow();
|
||||
updateoflags(col, row, display);
|
||||
changed = TRUE;
|
||||
} /* deletecell */
|
||||
|
||||
void printfreemem(void)
|
||||
/* Prints the amount of free memory */
|
||||
{
|
||||
writef(strlen(MSGMEMORY) + 2, 1, MEMORYCOLOR, 6, "%6ld", memleft);
|
||||
} /* printfreemem */
|
||||
|
||||
int rowwidth(int row)
|
||||
/* Returns the width in spaces of row */
|
||||
{
|
||||
return((row == 0) ? 1 : (int)log10(row + 1) + 1);
|
||||
} /* rowwidth */
|
||||
|
||||
int formulastart(char **input, int *col, int *row)
|
||||
/* Returns TRUE if the string is the start of a formula, FALSE otherwise.
|
||||
Also returns the column and row of the formula.
|
||||
*/
|
||||
{
|
||||
int len, maxlen = rowwidth(MAXROWS);
|
||||
char *start, numstring[10];
|
||||
|
||||
if (!isalpha(**input))
|
||||
return(FALSE);
|
||||
*col = *((*input)++) - 'A';
|
||||
if (isalpha(**input))
|
||||
{
|
||||
*col *= 26;
|
||||
*col += *((*input)++) - 'A' + 26;
|
||||
}
|
||||
if (*col >= MAXCOLS)
|
||||
return(FALSE);
|
||||
start = *input;
|
||||
for (len = 0; len < maxlen; len++)
|
||||
{
|
||||
if (!isdigit(*((*input)++)))
|
||||
{
|
||||
(*input)--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (len == 0)
|
||||
return(FALSE);
|
||||
strncpy(numstring, start, len);
|
||||
numstring[len] = 0;
|
||||
*row = atoi(numstring) - 1;
|
||||
if ((*row >= MAXROWS) || (*row == -1))
|
||||
return(FALSE);
|
||||
return(TRUE);
|
||||
} /* formulastart */
|
||||
|
||||
void errormsg(char *s)
|
||||
/* Prints an error message at the bottom of the screen */
|
||||
{
|
||||
printf("%c", 7); /* Beeps the speaker */
|
||||
writef(1, 25, ERRORCOLOR, 79, "%s %s", s, MSGKEYPRESS);
|
||||
gotoxy(strlen(s) + strlen(MSGKEYPRESS) + 3, 25);
|
||||
getkey();
|
||||
gotoxy(1, 25);
|
||||
writef(1, 25, WHITE, 79, "");
|
||||
} /* errormsg */
|
||||
|
||||
void fixformula(int col, int row, int action, int place)
|
||||
/* Modifies a formula when its column or row designations need to change. */
|
||||
{
|
||||
char *colstart, *rowstart, s[6], newformula[MAXINPUT + 1],
|
||||
*curpos = newformula;
|
||||
int fcol, frow;
|
||||
CELLPTR cellptr = cell[col][row];
|
||||
double value;
|
||||
|
||||
strcpy(newformula, cellptr->v.f.formula);
|
||||
while (*curpos != 0)
|
||||
{
|
||||
if (formulastart(&curpos, &fcol, &frow))
|
||||
{
|
||||
rowstart = curpos - rowwidth(frow);
|
||||
colstart = rowstart - ((fcol > 25) ? 2 : 1);
|
||||
switch (action)
|
||||
{
|
||||
case COLADD :
|
||||
if (fcol < place)
|
||||
break;
|
||||
if (fcol == 25)
|
||||
{
|
||||
if (strlen(newformula) == MAXINPUT)
|
||||
{
|
||||
deletecell(col, row, NOUPDATE);
|
||||
alloctext(col, row, newformula);
|
||||
return;
|
||||
}
|
||||
movmem(colstart, colstart + 1, strlen(colstart) + 1);
|
||||
}
|
||||
colstring(fcol + 1, s);
|
||||
movmem(s, colstart, strlen(s));
|
||||
break;
|
||||
case ROWADD :
|
||||
if (frow < place)
|
||||
break;
|
||||
if (rowwidth(frow + 1) != rowwidth(frow))
|
||||
{
|
||||
if (strlen(newformula) == MAXINPUT)
|
||||
{
|
||||
deletecell(col, row, NOUPDATE);
|
||||
alloctext(col, row, newformula);
|
||||
return;
|
||||
}
|
||||
movmem(rowstart, rowstart + 1, strlen(rowstart) + 1);
|
||||
}
|
||||
sprintf(s, "%d", frow + 2);
|
||||
movmem(s, rowstart, strlen(s));
|
||||
break;
|
||||
case COLDEL :
|
||||
if (fcol <= place)
|
||||
break;
|
||||
if (fcol == 26)
|
||||
movmem(colstart + 1, colstart, strlen(colstart) + 1);
|
||||
colstring(fcol - 1, s);
|
||||
movmem(s, colstart, strlen(s));
|
||||
break;
|
||||
case ROWDEL :
|
||||
if (frow <= place)
|
||||
break;
|
||||
if (rowwidth(frow) != rowwidth(frow - 1))
|
||||
movmem(rowstart + 1, rowstart, strlen(rowstart) + 1);
|
||||
sprintf(s, "%d", frow);
|
||||
movmem(s, rowstart, strlen(s));
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
else
|
||||
curpos++;
|
||||
}
|
||||
if (strlen(newformula) != strlen(cellptr->v.f.formula))
|
||||
{
|
||||
value = cellptr->v.f.fvalue;
|
||||
deletecell(col, row, NOUPDATE);
|
||||
allocformula(col, row, newformula, value);
|
||||
}
|
||||
else
|
||||
strcpy(cellptr->v.f.formula, newformula);
|
||||
} /* fixformula */
|
||||
|
||||
void colstring(int col, char *colstr)
|
||||
/* Changes a column number to a string */
|
||||
{
|
||||
setmem(colstr, 3, 0);
|
||||
if (col < 26)
|
||||
colstr[0] = col + 'A';
|
||||
else
|
||||
{
|
||||
colstr[0] = (col / 26) - 1 + 'A';
|
||||
colstr[1] = (col % 26) + 'A';
|
||||
}
|
||||
} /* colstring */
|
||||
|
||||
void centercolstring(int col, char *colstr)
|
||||
/* Changes a column to a centered string */
|
||||
{
|
||||
char s[3];
|
||||
int spaces1, spaces2;
|
||||
|
||||
colstring(col, s);
|
||||
spaces1 = (colwidth[col] - strlen(s)) >> 1;
|
||||
spaces2 = colwidth[col] - strlen(s) - spaces1;
|
||||
sprintf(colstr, "%*s%s%*s", spaces1, "", s, spaces2, "");
|
||||
} /* centercolstring */
|
||||
|
||||
void setleftcol(void)
|
||||
/* Sets the value of leftcol based on the value of rightcol */
|
||||
{
|
||||
int total = 80, col = 0;
|
||||
|
||||
while ((total >= LEFTMARGIN) && (rightcol - col >= 0))
|
||||
{
|
||||
colstart[SCREENCOLS - col - 1] = total - colwidth[rightcol - col];
|
||||
total -= colwidth[rightcol - col++];
|
||||
}
|
||||
if (total >= LEFTMARGIN)
|
||||
col++;
|
||||
movmem(&colstart[SCREENCOLS - col + 1], colstart, col - 1);
|
||||
leftcol = rightcol - col + 2;
|
||||
total = colstart[0] - LEFTMARGIN;
|
||||
if (total != 0)
|
||||
{
|
||||
for (col = leftcol; col <= rightcol; col++)
|
||||
colstart[col - leftcol] -= total;
|
||||
}
|
||||
printcol();
|
||||
} /* setleftcol */
|
||||
|
||||
void setrightcol(void)
|
||||
/* Sets the value of rightcol based on the value of leftcol */
|
||||
{
|
||||
int total = LEFTMARGIN, col = 0;
|
||||
|
||||
do
|
||||
{
|
||||
colstart[col] = total;
|
||||
total += colwidth[leftcol + col++];
|
||||
}
|
||||
while ((total <= 80) && (leftcol + col <= MAXCOLS));
|
||||
rightcol = leftcol + col - 2;
|
||||
printcol();
|
||||
} /* setrightcol */
|
||||
|
||||
void settoprow(void)
|
||||
/* Figures out the value of toprow based on the value of bottomrow */
|
||||
{
|
||||
if (bottomrow - SCREENROWS < -1)
|
||||
bottomrow = 19;
|
||||
toprow = bottomrow - 19;
|
||||
printrow();
|
||||
} /* settoprow */
|
||||
|
||||
void setbottomrow(void)
|
||||
/* Figures out the value of bottomrow based on the value of toprow */
|
||||
{
|
||||
if (toprow + SCREENROWS > MAXROWS)
|
||||
toprow = MAXROWS - 20;
|
||||
bottomrow = toprow + 19;
|
||||
printrow();
|
||||
} /* setbottomrow */
|
||||
|
||||
void setlastcol(void)
|
||||
/* Sets the value of lastcol based on the current value */
|
||||
{
|
||||
register int row, col;
|
||||
|
||||
for (col = lastcol; col >= 0; col--)
|
||||
{
|
||||
for (row = 0; row <= lastrow; row++)
|
||||
{
|
||||
if (cell[col][row] != NULL)
|
||||
{
|
||||
lastcol = col;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastcol = 0;
|
||||
} /* setlastcol */
|
||||
|
||||
void setlastrow(void)
|
||||
/* Sets the value of lastrow based on the current value */
|
||||
{
|
||||
register int row, col;
|
||||
|
||||
for (row = lastrow; row >= 0; row--)
|
||||
{
|
||||
for (col = 0; col <= lastcol; col++)
|
||||
{
|
||||
if (cell[col][row] != NULL)
|
||||
{
|
||||
lastrow = row;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastrow = 0;
|
||||
} /* setlastrow */
|
||||
|
||||
void act(char *s)
|
||||
/* Acts on a particular input */
|
||||
{
|
||||
int attrib, allocated;
|
||||
double value;
|
||||
|
||||
deletecell(curcol, currow, UPDATE);
|
||||
value = parse(s, &attrib);
|
||||
switch(attrib)
|
||||
{
|
||||
case TEXT :
|
||||
allocated = alloctext(curcol, currow, s);
|
||||
if (allocated)
|
||||
displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
|
||||
break;
|
||||
case VALUE :
|
||||
allocated = allocvalue(curcol, currow, value);
|
||||
break;
|
||||
case FORMULA :
|
||||
allocated = allocformula(curcol, currow, s, value);
|
||||
break;
|
||||
} /* switch */
|
||||
if (allocated)
|
||||
{
|
||||
format[curcol][currow] &= ~OVERWRITE;
|
||||
clearoflags(curcol + 1, currow, UPDATE);
|
||||
if (attrib == TEXT)
|
||||
setoflags(curcol, currow, UPDATE);
|
||||
if (curcol > lastcol)
|
||||
lastcol = curcol;
|
||||
if (currow > lastrow)
|
||||
lastrow = currow;
|
||||
if (autocalc)
|
||||
recalc();
|
||||
}
|
||||
else
|
||||
errormsg(MSGLOMEM);
|
||||
printfreemem();
|
||||
} /* act */
|
||||
|
||||
int setoflags(int col, int row, int display)
|
||||
/* Sets the overwrite flag on cells starting at (col + 1, row) - returns
|
||||
the number of the column after the last column set.
|
||||
*/
|
||||
{
|
||||
int len;
|
||||
|
||||
len = strlen(cell[col][row]->v.text) - colwidth[col];
|
||||
while ((++col < MAXCOLS) && (len > 0) && (cell[col][row] == NULL))
|
||||
{
|
||||
format[col][row] |= OVERWRITE;
|
||||
len -= colwidth[col];
|
||||
if (display && (col >= leftcol) && (col <= rightcol))
|
||||
displaycell(col, row, NOHIGHLIGHT, NOUPDATE);
|
||||
}
|
||||
return(col);
|
||||
} /* setoflags */
|
||||
|
||||
void clearoflags(int col, int row, int display)
|
||||
/* Clears the overwrite flag on cells starting at (col, row) */
|
||||
{
|
||||
while ((format[col][row] >= OVERWRITE) && (col < MAXCOLS) &&
|
||||
(cell[col][row] == NULL))
|
||||
{
|
||||
format[col][row] &= ~OVERWRITE;
|
||||
if (display && (col >= leftcol) && (col <= rightcol))
|
||||
displaycell(col, row, NOHIGHLIGHT, NOUPDATE);
|
||||
col++;
|
||||
}
|
||||
} /* clearoflags */
|
||||
|
||||
void updateoflags(int col, int row, int display)
|
||||
/* Starting in col, moves back to the last TEXT cell and updates all flags */
|
||||
{
|
||||
while ((cell[col][row] == NULL) && (col-- > 0));
|
||||
if ((cell[col][row] != NULL) && (cell[col][row]->attrib == TEXT) &&
|
||||
(col >= 0))
|
||||
setoflags(col, row, display);
|
||||
} /* updateoflags */
|
||||
|
||||
void textstring(char *instring, char *outstring, int col, int fvalue,
|
||||
int formatting)
|
||||
/* Sets the string representation of text */
|
||||
{
|
||||
char *just, *ljust = "%-*s", *rjust = "%*s";
|
||||
|
||||
if ((fvalue & RJUSTIFY) && (formatting))
|
||||
just = rjust;
|
||||
else
|
||||
just = ljust;
|
||||
sprintf(outstring, just, colwidth[col], instring);
|
||||
if (formatting)
|
||||
outstring[colwidth[col]] = 0;
|
||||
} /* textstring */
|
||||
|
||||
void valuestring(CELLPTR cellptr, double value, char *vstring, int col,
|
||||
int fvalue, int *color, int formatting)
|
||||
/* Sets the string representation of a value */
|
||||
{
|
||||
char s[81];
|
||||
char *fstring;
|
||||
int width, pos;
|
||||
|
||||
if (value == HUGE_VAL)
|
||||
{
|
||||
strcpy(vstring, MSGERROR);
|
||||
*color = ERRORCOLOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (formatting)
|
||||
{
|
||||
sprintf(vstring, "%1.*f", fvalue & 15, cellptr->v.value);
|
||||
if (fvalue & COMMAS)
|
||||
{
|
||||
pos = strcspn(vstring, ".");
|
||||
while (pos > 3)
|
||||
{
|
||||
pos -= 3;
|
||||
if (vstring[pos - 1] != '-')
|
||||
{
|
||||
movmem(&vstring[pos], &vstring[pos + 1], strlen(vstring) - pos + 1);
|
||||
vstring[pos] = ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fvalue & DOLLAR)
|
||||
{
|
||||
if (vstring[0] == '-')
|
||||
{
|
||||
fstring = " $";
|
||||
width = colwidth[col] - 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fstring = " $ ";
|
||||
width = colwidth[col] - 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fstring = "";
|
||||
width = colwidth[col];
|
||||
}
|
||||
strcpy(s, vstring);
|
||||
if (fvalue & RJUSTIFY)
|
||||
{
|
||||
if (strlen(vstring) > width)
|
||||
vstring[width] = 0;
|
||||
else
|
||||
sprintf(vstring, "%*s", width, s);
|
||||
}
|
||||
else
|
||||
sprintf(vstring, "%-*s", width, s);
|
||||
movmem(vstring, &vstring[strlen(fstring)], strlen(vstring) + 1);
|
||||
strncpy(vstring, fstring, strlen(fstring));
|
||||
}
|
||||
else
|
||||
sprintf(vstring, "%.*f", MAXPLACES, value);
|
||||
*color = VALUECOLOR;
|
||||
}
|
||||
} /* valuestring */
|
||||
|
||||
char *cellstring(int col, int row, int *color, int formatting)
|
||||
/* Creates an output string for the data in the cell in (col, row), and
|
||||
also returns the color of the cell */
|
||||
{
|
||||
CELLPTR cellptr = cell[col][row];
|
||||
int newcol, formatvalue;
|
||||
static char s[81], temp[MAXCOLWIDTH + 1];
|
||||
char *p;
|
||||
double value;
|
||||
|
||||
if (cellptr == NULL)
|
||||
{
|
||||
if (!formatting || (format[col][row] < OVERWRITE))
|
||||
{
|
||||
sprintf(s, "%*s", colwidth[col], "");
|
||||
*color = BLANKCOLOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
newcol = col;
|
||||
while (cell[--newcol][row] == NULL);
|
||||
p = cell[newcol][row]->v.text;
|
||||
while (newcol < col)
|
||||
p += colwidth[newcol++];
|
||||
strncpy(temp, p, colwidth[col]);
|
||||
temp[colwidth[col]] = 0;
|
||||
sprintf(s, "%s%*s", temp, colwidth[col] - strlen(temp), "");
|
||||
*color = TEXTCOLOR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
formatvalue = format[col][row];
|
||||
switch (cellptr->attrib)
|
||||
{
|
||||
case TEXT :
|
||||
textstring(cellptr->v.text, s, col, formatvalue, formatting);
|
||||
*color = TEXTCOLOR;
|
||||
break;
|
||||
case FORMULA :
|
||||
if (formdisplay)
|
||||
{
|
||||
textstring(cellptr->v.f.formula, s, col, formatvalue, formatting);
|
||||
*color = FORMULACOLOR;
|
||||
break;
|
||||
}
|
||||
else
|
||||
value = cellptr->v.f.fvalue;
|
||||
case VALUE :
|
||||
if (cellptr->attrib == VALUE)
|
||||
value = cellptr->v.value;
|
||||
valuestring(cellptr, value, s, col, formatvalue, color,
|
||||
formatting);
|
||||
break;
|
||||
} /* switch */
|
||||
}
|
||||
return(s);
|
||||
} /* cellstring */
|
||||
|
||||
void writeprompt(char *prompt)
|
||||
/* Prints a prompt on the screen */
|
||||
{
|
||||
writef(1, 24, PROMPTCOLOR, 80, prompt);
|
||||
} /* writeprompt */
|
||||
|
||||
void swap(int *val1, int *val2)
|
||||
/* Swaps the first and second values */
|
||||
{
|
||||
int temp;
|
||||
|
||||
temp = *val1;
|
||||
*val1 = *val2;
|
||||
*val2 = temp;
|
||||
} /* swap */
|
||||
|
||||
void checkforsave(void)
|
||||
/* If the spreadsheet has been changed, will ask the user if they want to
|
||||
save it.
|
||||
*/
|
||||
{
|
||||
int save;
|
||||
|
||||
if (changed && getyesno(&save, MSGSAVESHEET) && (save == 'Y'))
|
||||
savesheet();
|
||||
} /* checkforsave */
|
||||
|
||||
void initvars(void)
|
||||
/* Initializes various global variables */
|
||||
{
|
||||
leftcol = toprow = curcol = currow = lastcol = lastrow = 0;
|
||||
setmem(colwidth, sizeof(colwidth), DEFAULTWIDTH);
|
||||
setmem(cell, sizeof(cell), 0);
|
||||
setmem(format, sizeof(format), DEFAULTFORMAT);
|
||||
} /* initvars */
|
||||
|
||||
int getcommand(char *msgstr, char *comstr)
|
||||
/* Reads in a command and acts on it */
|
||||
{
|
||||
int ch, counter, len = strlen(msgstr);
|
||||
|
||||
scroll(UP, 0, 1, 24, 80, 24, WHITE);
|
||||
for (counter = 0; counter < len; counter++)
|
||||
{
|
||||
if (isupper(msgstr[counter]))
|
||||
writef(counter + 1, 24, COMMANDCOLOR, 1, "%c", msgstr[counter]);
|
||||
else
|
||||
writef(counter + 1, 24, LOWCOMMANDCOLOR, 1, "%c", msgstr[counter]);
|
||||
}
|
||||
do
|
||||
ch = toupper(getkey());
|
||||
while ((strchr(comstr, ch) == NULL) && (ch != ESC));
|
||||
clearinput();
|
||||
return((ch == ESC) ? -1 : strlen(comstr) - strlen(strchr(comstr, ch)));
|
||||
} /* getcommand */
|
||||
|
||||
|
BIN
Borland Turbo C v2/NONAME.EXE
Normal file
BIN
Borland Turbo C v2/NONAME.EXE
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/NONAME.OBJ
Normal file
BIN
Borland Turbo C v2/NONAME.OBJ
Normal file
Binary file not shown.
BIN
Borland Turbo C v2/OBJXREF.COM
Normal file
BIN
Borland Turbo C v2/OBJXREF.COM
Normal file
Binary file not shown.
85
Borland Turbo C v2/PBAR.PRO
Normal file
85
Borland Turbo C v2/PBAR.PRO
Normal file
@ -0,0 +1,85 @@
|
||||
/* PBAR.PRO -- sample Turbo Prolog program to be used with BAR.C
|
||||
|
||||
Copyright (c) 1987,88 Borland International. All rights reserved.
|
||||
*/
|
||||
|
||||
database
|
||||
barchart(integer)
|
||||
chartbar(integer,integer,integer,integer,integer,integer)
|
||||
|
||||
global predicates
|
||||
cbar(integer,integer,integer,integer,integer)-(i,i,i,i,i) language c
|
||||
predicates
|
||||
process(char)
|
||||
repeat
|
||||
myretractall
|
||||
drawbar(integer,integer,integer,integer)
|
||||
|
||||
goal
|
||||
graphics(1,0,0),
|
||||
asserta(barchart(0)),
|
||||
makewindow(1,1,1,"Bar",0,0,20,40),
|
||||
makewindow(2,1,1,"",20,0,4,40),
|
||||
repeat,
|
||||
write("Press any key to continue"), readchar(_),
|
||||
clearwindow,
|
||||
makewindow(1,1,1,"Bar",0,0,20,40),
|
||||
write("m. Make a bar Chart.\n"),
|
||||
write("s. Save your bar Chart.\n"),
|
||||
write("l. Load your bar Chart.\n"),
|
||||
write("d. Draw your bar Chart.\n"),
|
||||
write("e. End\nEnter Choice: "),
|
||||
readchar(Choice),
|
||||
clearwindow,
|
||||
shiftwindow(2),
|
||||
process(Choice),
|
||||
bios(16,reg(3,0,0,0,0,0,0,0),_).
|
||||
|
||||
clauses
|
||||
process('m'):-
|
||||
barchart(Nu),
|
||||
retract(barchart(Nu)),
|
||||
NewNu = Nu+1,
|
||||
asserta(barchart(NewNu)),
|
||||
write("Enter the number of bars: "),
|
||||
readint(NuOfBars),clearwindow,
|
||||
write("Enter max value on Y scale: "),
|
||||
readint(Max),clearwindow,
|
||||
YScale = 140/Max,
|
||||
Width = 265/NuOfBars,
|
||||
Start = 305-Width,
|
||||
clearwindow,
|
||||
drawbar(NuOfBars, Width, Start, Yscale),
|
||||
fail.
|
||||
process('s'):-
|
||||
write("Enter file name of chart: "),readln(Name),
|
||||
concat(Name,".CHT",FName),save(Fname),fail.
|
||||
process('l'):-
|
||||
myretractall,
|
||||
write("Enter file name of chart: "),readln(Name),
|
||||
concat(Name,".CHT",FName),consult(FName),fail.
|
||||
process('d'):-
|
||||
barchart(Chart),
|
||||
chartbar(Chart,XPosition,Ypos,Width,YBarSize,1),
|
||||
cbar(XPosition,Ypos,Width,YBarSize,1),fail.
|
||||
process('e').
|
||||
|
||||
drawbar(0,_,_,_):-!.
|
||||
drawbar(Nu,Width,XPosition,Yscale):-
|
||||
XNuNew=Nu-1,clearwindow,
|
||||
write("Enter the value associated bar ",Nu ,": "),
|
||||
readint(Y),
|
||||
YBarSize=Y*YScale,
|
||||
Ypos=140 - YBarSize,
|
||||
cbar(XPosition,Ypos,Width,YBarSize,1),
|
||||
barchart(Chart),
|
||||
asserta(chartbar(Chart,XPosition,Ypos,Width,YBarSize,1)),
|
||||
XNewPos= XPosition-Width-5,
|
||||
drawbar(XNuNew,Width,XNewPos,Yscale).
|
||||
|
||||
repeat.
|
||||
repeat:- repeat.
|
||||
myretractall:- retract(_),fail.
|
||||
myretractall.
|
||||
|
||||
|
BIN
Borland Turbo C v2/PC3270.BGI
Normal file
BIN
Borland Turbo C v2/PC3270.BGI
Normal file
Binary file not shown.
558
Borland Turbo C v2/README
Normal file
558
Borland Turbo C v2/README
Normal file
@ -0,0 +1,558 @@
|
||||
WELCOME TO TURBO C 2.0
|
||||
----------------------
|
||||
|
||||
This README file contains important, last minute information
|
||||
about Turbo C 2.0. The HELPME!.DOC file on the COMMAND LINE/UTILITIES
|
||||
disk also answers many common Technical Support questions.
|
||||
|
||||
|
||||
TABLE OF CONTENTS
|
||||
-----------------
|
||||
1. How to Get Help
|
||||
2. Installation
|
||||
3. Important Notes
|
||||
4. Corrections to the Manuals
|
||||
5. Additional Notes
|
||||
6. Notes for Turbo Prolog Users
|
||||
7. Files on the Disks
|
||||
|
||||
|
||||
1. HOW TO GET HELP
|
||||
-------------------
|
||||
|
||||
If you have any problems, please read this file, the
|
||||
HELPME!.DOC file, and the Turbo C manuals first. If you still
|
||||
have a question and need assistance, help is available from
|
||||
the following sources:
|
||||
|
||||
1. Type GO BOR on the CompuServe bulletin board system for
|
||||
instant access to the Borland forums with their libraries of
|
||||
technical information and answers to common questions.
|
||||
|
||||
If you are not a member of CompuServe, see the enclosed special
|
||||
offer, and write for full details on how to receive a free
|
||||
IntroPak containing a $15 credit toward your first month's on-
|
||||
line charges.
|
||||
|
||||
2. Check with your local software dealer or users' group.
|
||||
|
||||
3. Write to us at the following address:
|
||||
|
||||
Borland International
|
||||
Turbo C Technical Support
|
||||
1800 Green Hills Road
|
||||
P.O. Box 660001
|
||||
Scotts Valley, CA 95066-0001
|
||||
|
||||
Please remember to include your serial number or we will be
|
||||
unable to process your letter.
|
||||
|
||||
4. If you have an urgent problem that cannot wait and you have sent
|
||||
in the license agreement from the front of your manual, you may
|
||||
call the Borland Technical Support Department at (408) 438-5300.
|
||||
Please have the following information ready before calling:
|
||||
|
||||
a. Product name and serial number on your original distribution
|
||||
disk. Please have your serial number ready or we will be
|
||||
unable to process your call.
|
||||
|
||||
b. Product version number. The version number for Turbo C is
|
||||
displayed when you first load the program and before you
|
||||
press any keys.
|
||||
|
||||
c. Computer brand, model, and the brands and model numbers of
|
||||
any additional hardware.
|
||||
|
||||
d. Operating system and version number. (The version number can
|
||||
be determined by typing VER at the MSDOS prompt.)
|
||||
|
||||
e. Contents of your AUTOEXEC.BAT file.
|
||||
|
||||
f. Contents of your CONFIG.SYS file.
|
||||
|
||||
|
||||
2. INSTALLATION
|
||||
----------------
|
||||
The INSTALL/HELP disk contains a program called INSTALL.EXE that
|
||||
will assist you with the installation of Turbo C 2.0. There are
|
||||
three options for installation:
|
||||
|
||||
1. Hard Disk - This option allows you to pick the subdirectories
|
||||
where the files will be loaded. It will create a TURBOC.CFG
|
||||
file based on those directories.
|
||||
|
||||
2. Update from TC 1.5 - This allows for an easy update from version
|
||||
1.5. After the files are copied, all the installed options
|
||||
from your current TC.EXE will be transferred to the new one.
|
||||
This is especially useful if you have modified the colors or
|
||||
editor keys.
|
||||
|
||||
3. Floppy Disk - This option will build either a command line or
|
||||
Integrated Development Environment version for a two drive
|
||||
system. Be sure to have three formatted disks ready before
|
||||
you start.
|
||||
|
||||
To start the installation, change your current drive to the one
|
||||
that has the install program on it and type INSTALL. You will
|
||||
be given instructions in a box at the bottom of the screen for
|
||||
each prompt. For example, if you will be installing from drive
|
||||
A:, type:
|
||||
|
||||
A:
|
||||
INSTALL
|
||||
|
||||
You should read the rest of this README file to get further
|
||||
information about this release before you do the installation.
|
||||
|
||||
|
||||
3. IMPORTANT NOTES
|
||||
-------------------
|
||||
|
||||
o The file HELPME!.DOC contains discussions of common questions
|
||||
and answers concerning Turbo C 2.0. You should consult it for
|
||||
answers to problems that aren't covered in this file or in
|
||||
the manuals.
|
||||
|
||||
o If you are running INSTALL or TCINST on a laptop or any other
|
||||
system that uses an LCD or composite display, you should set
|
||||
your system to black and white mode before running INSTALL
|
||||
or TCINST. You can do this from DOS with the following command
|
||||
line:
|
||||
|
||||
mode bw80
|
||||
|
||||
or, you can force INSTALL or TCINST to come up in black and
|
||||
white mode by using the /b switch:
|
||||
|
||||
tcinst /b
|
||||
|
||||
o /P PARAMETER FOR TC.EXE. A new command-line switch controls
|
||||
palette swapping on EGA video adapters. Using this switch
|
||||
|
||||
tc /p hello
|
||||
|
||||
is recommended only when the user program modifies the EGA
|
||||
palette registers. When /P is specified, the EGA palette will be
|
||||
restored each time the screen is swapped. In general, you don't
|
||||
need to use this switch unless your program modifies the EGA
|
||||
palette registers, or unless your program uses BGI to change
|
||||
the palette.
|
||||
|
||||
o A program that takes over interrupt 9 cannot be debugged
|
||||
with the integrated debugger. Use the standalone Turbo Debugger
|
||||
instead.
|
||||
|
||||
o exec() WITH NOVELL NETWORK. Versions of the Novell network
|
||||
system software earlier than 2.01-2 do not support a DOS
|
||||
call used by exec(), spawn(), and system(). If you are using
|
||||
the Integrated Development Environment to run a program that
|
||||
uses any of these functions and you have early Novell system
|
||||
software, run the program from DOS. To do this from the
|
||||
Integrated Development Environment you can use Alt-F/O.
|
||||
|
||||
o If you used the INSTALL program to upgrade from version 1.5,
|
||||
or if you used CINSTXFR to transfer options from an
|
||||
installation of version 1.5, check the setting of the
|
||||
standard stack frame option in the Integrated Development
|
||||
Environment (Alt-O/C/C/S). If you are going to use the
|
||||
integrated debugger this option should be turned ON.
|
||||
|
||||
o If you are having problems with the call stack or qualified
|
||||
names, make sure you have compiled with the standard stack
|
||||
frame option turned on.
|
||||
|
||||
o The ANSI draft has changed the syntax of labels. A label now
|
||||
must always be followed by a statement. This means that code
|
||||
like this is no longer accepted:
|
||||
|
||||
{
|
||||
.
|
||||
.
|
||||
.
|
||||
jump_label:
|
||||
}
|
||||
|
||||
If you have code like this, change it to look like this:
|
||||
|
||||
{
|
||||
.
|
||||
.
|
||||
.
|
||||
jump_label:
|
||||
; /* need a statement here! */
|
||||
}
|
||||
|
||||
o TCC has a switch to specify which assembler to look for. By
|
||||
default, it will look for TASM.EXE. If you want to use a
|
||||
different assembler, use -E<filename>, as described in the
|
||||
Reference Guide.
|
||||
|
||||
o When using THELP on an AT&T 6300, be sure to use the /L25
|
||||
command-line option, as described in the file THELP.DOC.
|
||||
|
||||
o When you use qualified variable names as described on page
|
||||
57 of the User's Guide you don't need to use the module
|
||||
name to access a variable that is local to a global
|
||||
function. The module name is only needed when you access a
|
||||
static variable or a variable that is local to a static
|
||||
function.
|
||||
|
||||
o Because of the limited memory available in the Tiny model,
|
||||
it no longer supports graphics functions.
|
||||
|
||||
o The Version 1.5 graphics drivers (*.BGI) are not compatible
|
||||
with the Version 2.0 graphics library. Use the graphics drivers
|
||||
distributed with Version 2.0.
|
||||
|
||||
o When used with a Zenith Z-449 card, the BGI autodetection code
|
||||
will always select the 640X480 enhanced EGA mode. If you are
|
||||
using the Z-449 with a monitor that is not compatible with
|
||||
this mode, it will be necessary to override the GraphDriver
|
||||
and GraphMode parameters used in the BGI initgraph() call.
|
||||
|
||||
|
||||
4. CORRECTIONS TO THE MANUALS
|
||||
------------------------------
|
||||
|
||||
REFERENCE GUIDE:
|
||||
|
||||
Page
|
||||
|
||||
159 The prototype for the function getdefaultpallette() is
|
||||
incorrect. It should be
|
||||
|
||||
struct palettetype * far _Cdecl getdefaultpalette( void );
|
||||
|
||||
|
||||
USER'S GUIDE:
|
||||
|
||||
Page
|
||||
|
||||
57 In the section entitled "Qualifying Variable Names," the
|
||||
last sentence should read "...need to type only myfunc.myvar."
|
||||
|
||||
66 The directions for compiling the WORDCNT program are
|
||||
incorrect. There is no WORDCNT.PRJ file; all you need to do
|
||||
is load the file WORDCNT.C into the editor. Once you have
|
||||
done that, the rest of the instructions are correct.
|
||||
|
||||
5. ADDITIONAL NOTES
|
||||
--------------------
|
||||
|
||||
5.1 NOTES FOR VERSION 1.0 & 1.5 USERS
|
||||
-------------------------------------
|
||||
|
||||
o You must use the Version 2.0 libraries with the 2.0 compilers.
|
||||
|
||||
o The Integrated Development Environment no longer displays the
|
||||
message "Press any key to return to Turbo C..." when your
|
||||
program terminates. Instead, at the end of your program the
|
||||
User screen is replaced by the Integrated Development
|
||||
Environment. To view the User screen, press Alt-F5 or
|
||||
select Alt-R/S. When you are viewing the User screen,
|
||||
pressing any key will return you to the Integrated
|
||||
Development Environment.
|
||||
|
||||
o A new pseudo-variable has been added. _FLAGS now contains the
|
||||
value of the flags register so you can test the flags at any
|
||||
point in your program.
|
||||
|
||||
o The ssignal() and gsignal() functions are no longer
|
||||
supported. See the section in this README on how to convert
|
||||
programs that use them.
|
||||
|
||||
o The cprintf() function now works as documented. It does not
|
||||
translate line-feeds into CR/LF combinations.
|
||||
|
||||
o Some compatibles had a problem under Version 1.5 because it
|
||||
used interrupt 18H. Version 2.0 does not use this interrupt,
|
||||
so you shouldn't encounter this problem anymore.
|
||||
|
||||
o The program TCINST.COM in Version 1.0 has been changed to an
|
||||
.EXE file. You should delete the TCINST.COM program before
|
||||
trying to run the new TCINST.EXE. Otherwise, MS-DOS will actually
|
||||
run the old one.
|
||||
|
||||
o The FILE structure for streams in Version 1.0 (but not 1.5) has
|
||||
been changed, so that the function tmpfile() could be implemented.
|
||||
You should recompile any modules that use stream I/O.
|
||||
|
||||
5.2 THELP
|
||||
----------
|
||||
|
||||
THELP is a memory-resident utility program that gives you
|
||||
access to the Turbo C context-sensitive help system from any
|
||||
program. You don't need to use THELP if you're in the
|
||||
Integrated Development Environment, but it is especially useful
|
||||
if you use the command line compiler and your own text editor,
|
||||
or if you are debugging with the standalone Turbo Debugger. To
|
||||
use THELP, load THELP.COM into memory by typing at the DOS
|
||||
command line:
|
||||
|
||||
thelp
|
||||
|
||||
You activate ("pop-up") THELP by typing its hot key -- by
|
||||
default numeric keypad <5>. All Turbo C help commands apply
|
||||
(F1, Ctrl-F1, Alt-F1). For a complete description of THELP,
|
||||
refer to THELP.DOC in the Documentation Subdirectory.
|
||||
|
||||
5.3 USING CINSTXFR.EXE
|
||||
----------------------
|
||||
|
||||
Your Turbo C 2.0 package contains a program named CINSTXFR.EXE,
|
||||
which can be used to transfer the configuration of the
|
||||
Integrated Development Environment from your copy of Turbo C
|
||||
1.5 (not for 1.0) to your new installation of Turbo C 2.0. This
|
||||
program is run automatically by INSTALL.EXE if you select the
|
||||
option to "Update Hard Drive Copy of Turbo C 1.5 to Turbo C 2.0."
|
||||
If you prefer to do this yourself, you can run CINSTXFR.EXE from
|
||||
the DOS command line.
|
||||
|
||||
CINSTXFR.EXE takes two arguments: the first is the name of your
|
||||
Turbo C 1.5 Integrated Development Environment file (usually
|
||||
TC.EXE), and the second is the name of your Turbo C 2.0
|
||||
Integrated Development Environment file (also usually TC.EXE).
|
||||
Either one of these names can also include a path name.
|
||||
|
||||
For example, if your copy of the Turbo C 1.5 Integrated
|
||||
Development Environment file is named TC.EXE and is in a
|
||||
directory named \TURBOC and your copy of the Turbo C 2.0
|
||||
Integrated Development Environment file is also named TC.EXE
|
||||
but is located in a directory named \TC2, the command line to
|
||||
copy the configuration from 1.5 to 2.0 would look like this:
|
||||
|
||||
CINSTXFR \TURBOC\TC.EXE \TC2\TC.EXE
|
||||
|
||||
This will transfer all the options that you installed in
|
||||
your copy of Turbo C 1.5 to your copy of Turbo C 2.0.
|
||||
|
||||
CINSTXFR.EXE does not work with Turbo C 1.0. If you are
|
||||
upgrading from Turbo C 1.0, you will have to install the
|
||||
options yourself.
|
||||
|
||||
5.4 CHANGED SWITCHES FOR OBJXREF
|
||||
--------------------------------
|
||||
|
||||
OBJXREF is an object module cross reference utility and is
|
||||
described on page 528 of the Turbo C Reference Guide.
|
||||
The /O option (object files directory) has been changed to the
|
||||
/D (directories) option. The switch now allows for multiple
|
||||
search directories to be specified. The new syntax is:
|
||||
|
||||
OBJXREF /Ddir1[;dir2[;dir3]]
|
||||
or
|
||||
OBJXREF /Ddir1 [/Ddir2] [/Ddir3]
|
||||
|
||||
OBJXREF will search each of the directories in the specified
|
||||
order for all object and library files. If no /D option is
|
||||
used, only the current directory will be searched. However,
|
||||
if a /D option is used, the current directory will NOT be
|
||||
searched unless it is included in the directory list. For
|
||||
example, to first search the BORLAND directory for files and
|
||||
then search the current directory, you would type
|
||||
|
||||
OBJXREF /Dborland;.
|
||||
|
||||
If multiple search directories are specified and a file
|
||||
matching the file specification is found, OBJXREF will include
|
||||
the file as part of the cross-reference. OBJXREF will only
|
||||
continue to search the other directories for the same file
|
||||
specification if the file specification contains wildcards.
|
||||
|
||||
A new option has been added to allow you to specify an output
|
||||
file where OBJXREF will send any reports generated. The new
|
||||
option is the /O option, and has the following syntax:
|
||||
|
||||
OBJXREF myfile.obj /RU /Ofilename.ext
|
||||
|
||||
By default, all output is sent to the console.
|
||||
|
||||
5.5 CONVERSION INFORMATION FOR ssignal() AND gsignal()
|
||||
------------------------------------------------------
|
||||
|
||||
Note: The C library and SIGNAL.H no longer support the ssignal()
|
||||
and gsignal() functions.
|
||||
|
||||
ssignal() and gsignal() were from the old UNIX System III
|
||||
days. The ANSI standard no longer supports them nor does the
|
||||
current UNIX System V Interface Definition specification. To
|
||||
ease portation problems for people moving older code to Turbo
|
||||
C, we supply the source for the functions that came with TC
|
||||
1.0 and TC 1.5. Also, the following discussion describes how
|
||||
code can be converted to do the same sort of things that
|
||||
ssignal() and gsignal() do without actually using them.
|
||||
|
||||
NOTE: The constants defined in SIGNAL.H for SIG_IGN and
|
||||
SIG_DFL are different from the constants that were in
|
||||
TC 1.0 and TC 1.5.
|
||||
|
||||
By using a globally declared array of function pointers, you
|
||||
can simulate the actions of ssignal() and gsignal() by using
|
||||
the following macros. Notice how the global table entry [0] is
|
||||
used as a temporary variable in the ssignal macro allowing the
|
||||
macro to swap the values and still return the original one.
|
||||
|
||||
int (*_sigTable[16]) =
|
||||
{
|
||||
SIG_IGN, SIG_IGN, SIG_IGN, SIG_IGN,
|
||||
SIG_IGN, SIG_IGN, SIG_IGN, SIG_IGN,
|
||||
SIG_IGN, SIG_IGN, SIG_IGN, SIG_IGN,
|
||||
SIG_IGN, SIG_IGN, SIG_IGN, SIG_IGN,
|
||||
};
|
||||
|
||||
#define ssignal(num, action) \
|
||||
( \
|
||||
(((num) < 1) || ((num) > 15)) ? SIG_DFL : \
|
||||
( \
|
||||
(_sigTable[0] = _sigTable[(num)]), /* List of actions */ \
|
||||
_sigTable[(num)] = (action), /* The last expression */ \
|
||||
_sigTable[0] /* is the return value */ \
|
||||
) \
|
||||
) \
|
||||
|
||||
#define gsignal(num) \
|
||||
( \
|
||||
(((num) < 1) || ((num) > 15)) ? 0 : \
|
||||
( \
|
||||
(_sigTable[(num)] == SIG_IGN) ? 1 : \
|
||||
( \
|
||||
(_sigTable[(num)] == SIG_DFL) ? 0 : (*_sigTable[(num)])() \
|
||||
) \
|
||||
) \
|
||||
) \
|
||||
|
||||
|
||||
6. NOTES FOR TURBO PROLOG USERS
|
||||
--------------------------------
|
||||
|
||||
o If you are linking C code with programs generated by Turbo
|
||||
Prolog 2.0, use the file INIT.OBJ provided on the
|
||||
EXAMPLES/BGI/MISC disk of the Turbo C 2.0 package instead of
|
||||
the file provided with Turbo Prolog 2.0. There have been some
|
||||
changes made in Turbo C 2.0 that require the use of this new file.
|
||||
|
||||
o If your C code uses floating point math and you link with the
|
||||
emulator library, Prolog will not automatically detect a math
|
||||
coprocessor chip. If you want to force the program to use the
|
||||
coprocessor, link it with FP87.LIB instead of EMU.LIB.
|
||||
|
||||
|
||||
7. FILES ON THE DISKS
|
||||
----------------------
|
||||
|
||||
INSTALL/HELP
|
||||
------------
|
||||
INSTALL EXE - Installation program
|
||||
README COM - Reads this README
|
||||
TCHELP TCH - Help file for Turbo C
|
||||
THELP COM - Pop-up utility to access TCHELP.TCH
|
||||
THELP DOC - Documentation for THELP.COM
|
||||
README - This file
|
||||
|
||||
INTEGRATED DEVELOPMENT ENVIRONMENT
|
||||
----------------------------------
|
||||
TC EXE - Turbo C Compiler
|
||||
TCCONFIG EXE - Program to convert configuration files
|
||||
MAKE EXE - Program for managing projects
|
||||
GREP COM - Turbo GREP program
|
||||
TOUCH COM - Program that updates a file's date and time
|
||||
|
||||
COMMAND LINE/UTILITIES
|
||||
----------------------
|
||||
TCC EXE - Command-line version of Turbo C Compiler
|
||||
CPP EXE - Turbo C preprocessor
|
||||
TCINST EXE - Installation program for TC.EXE
|
||||
TLINK EXE - Borland Turbo Linker
|
||||
HELPME! DOC - Common questions and answers
|
||||
|
||||
LIBRARIES
|
||||
---------
|
||||
C0S OBJ - Small model startup code
|
||||
C0T OBJ - Tiny model startup code
|
||||
C0L OBJ - Large model startup code
|
||||
MATHS LIB - Small model math library
|
||||
MATHL LIB - Large model math library
|
||||
CS LIB - Small model run-time library
|
||||
CL LIB - Large model run-time library
|
||||
EMU LIB - 8087 emulator library
|
||||
GRAPHICS LIB - Graphics library
|
||||
FP87 LIB - 8087 library
|
||||
TLIB EXE - Borland Turbo Librarian
|
||||
|
||||
HEADER FILES/LIBRARIES
|
||||
----------------------
|
||||
???????? H - Turbo C header files
|
||||
<SYS> - Subdirectory with SYS\*.H header files
|
||||
C0C OBJ - Compact model startup code
|
||||
C0M OBJ - Medium model startup code
|
||||
MATHC LIB - Compact model math library
|
||||
MATHM LIB - Medium model math library
|
||||
CC LIB - Compact model run-time library
|
||||
CM LIB - Medium model run-time library
|
||||
|
||||
EXAMPLES/BGI/MISC
|
||||
-----------------
|
||||
UNPACK COM - Program to unpack the .ARC files
|
||||
OBJXREF COM - Object file cross-reference utility
|
||||
C0H OBJ - Huge model startup code
|
||||
MATHH LIB - Huge model math library
|
||||
CH LIB - Huge model run-time library
|
||||
GETOPT C - Parses options in command line
|
||||
HELLO C - Example Turbo C program
|
||||
MATHERR C - Source code for handling math library exceptions
|
||||
SSIGNAL C - Source code for ssignal and gsignal functions
|
||||
CINSTXFR EXE - Program to copy TC 1.5 installation to TC 2.0
|
||||
INIT OBJ - Initialization code for use when linking with Prolog
|
||||
|
||||
BGI ARC - BGI drivers and fonts
|
||||
BGIOBJ EXE - Conversion program for fonts and drivers
|
||||
ATT BGI - Graphics driver for ATT400 graphics card
|
||||
CGA BGI - Graphics driver for CGA
|
||||
EGAVGA BGI - Graphics driver for EGA and VGA
|
||||
HERC BGI - Graphics driver for Hercules
|
||||
IBM8514 BGI - Graphics driver for IBM 8514 graphics card
|
||||
PC3270 BGI - Graphics driver for PC3270
|
||||
GOTH CHR - Font for gothic character set
|
||||
LITT CHR - Font for small character set
|
||||
SANS CHR - Font for sans serif character set
|
||||
TRIP CHR - Font for triplex character set
|
||||
BGIDEMO C - Graphics demonstration program
|
||||
|
||||
STARTUP ARC - ARC file with startup source code and related files
|
||||
RULES ASI - Assembler include file for interfacing with Turbo C
|
||||
C0 ASM - Assembler source for startup code
|
||||
SETARGV ASM - Assembler source code for parsing the command line
|
||||
SETENVP ASM - Assembler source code for preparing the environment
|
||||
BUILD-C0 BAT - Batch file for building the startup code modules
|
||||
MAIN C - Alternative, stripped-down C main file
|
||||
EMUVARS ASI - Assembler variable declarations for emulator
|
||||
WILDARGS OBJ - Object code for module to expand wildcard arguments
|
||||
|
||||
EXAMPLES ARC - Various C examples code
|
||||
CPASDEMO PAS - Pascal program that demonstrates Turbo Pascal 4.0 -
|
||||
Turbo C interface
|
||||
CPASDEMO C - C example module for the Turbo Pascal 4.0 - Turbo C
|
||||
interface demonstration
|
||||
CTOPAS TC - Configuration file for use with TC.EXE that
|
||||
creates Turbo C modules in the correct format
|
||||
for linking with Turbo Pascal 4.0 programs
|
||||
CBAR C - Example function to be used with PBAR.PRO
|
||||
PBAR PRO - Example Turbo Prolog program demonstrating interface
|
||||
with Turbo C
|
||||
WORDCNT C - Example program demonstrating source level debugging.
|
||||
NOTE: DO NOT RUN THIS PROGRAM WITHOUT READING THE
|
||||
DISCUSSION IN THE MANUAL. IT CONTAINS
|
||||
DELIBERATE ERRORS.
|
||||
WORDCNT DAT - Data file for use by WORDCNT.C
|
||||
|
||||
MCALC ARC - Mcalc sources and doc
|
||||
MCALC DOC - MicroCalc documentation
|
||||
MCALC C - MicroCalc main program source code
|
||||
MCINPUT C - MicroCalc input routines source code
|
||||
MCOMMAND C - MicroCalc commands source code
|
||||
MCPARSER C - MicroCalc input parser source code
|
||||
MCUTIL C - MicroCalc utilities source code
|
||||
MCDISPLY C - MicroCalc screen display source code
|
||||
MCALC H - The header file for MicroCalc
|
||||
MCALC PRJ - The MicroCalc project file
|
||||
|
BIN
Borland Turbo C v2/README.COM
Normal file
BIN
Borland Turbo C v2/README.COM
Normal file
Binary file not shown.
533
Borland Turbo C v2/RULES.ASI
Normal file
533
Borland Turbo C v2/RULES.ASI
Normal file
@ -0,0 +1,533 @@
|
||||
.XLIST
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| RULES.ASI -- Rules & Structures for assembler |
|
||||
;| |
|
||||
;| Turbo-C Run Time Library version 2.0 |
|
||||
;| |
|
||||
;| Copyright (c) 1987,1988 by Borland International Inc. |
|
||||
;| All Rights Reserved. |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
; 4/15/88 ah:
|
||||
; Emulator segment directives modified for Turbo Pascal
|
||||
; using _Pascal_ conditional.
|
||||
|
||||
;*** First we begin with a few of the major constants of C.
|
||||
|
||||
false equ 0 ; Beware ! For incoming parameters, non-false = true.
|
||||
true equ 1 ; For results, we generate the proper numbers.
|
||||
|
||||
lesser equ -1 ; Incoming, lesser < 0
|
||||
equal equ 0
|
||||
greater equ 1 ; Incoming, greater > 0
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Conditional Assembly Directives |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
IFDEF __TINY__ ; *** Special case ***
|
||||
__SMALL__ equ true
|
||||
ENDIF
|
||||
|
||||
IFDEF __HUGE__ ; *** Special case ***
|
||||
__LARGE__ equ true
|
||||
ENDIF
|
||||
|
||||
IFNDEF __TINY__
|
||||
IFNDEF __SMALL__
|
||||
IFNDEF __MEDIUM__
|
||||
IFNDEF __COMPACT__
|
||||
IFNDEF __LARGE__
|
||||
IFNDEF __HUGE__
|
||||
%OUT You must supply a model symbol.
|
||||
.ERR
|
||||
ENDIF
|
||||
ENDIF
|
||||
ENDIF
|
||||
ENDIF
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
IFDEF __SMALL__ ; Small Code - Small Data
|
||||
LPROG equ false
|
||||
LDATA equ false
|
||||
ENDIF
|
||||
|
||||
IFDEF __MEDIUM__ ; Small Code - Large Data
|
||||
LPROG equ true
|
||||
LDATA equ false
|
||||
ENDIF
|
||||
|
||||
IFDEF __COMPACT__ ; Large Code - Small Data
|
||||
LPROG equ false
|
||||
LDATA equ true
|
||||
ENDIF
|
||||
|
||||
IFDEF __LARGE__ ; Large Code - Large Data
|
||||
LPROG equ true
|
||||
LDATA equ true
|
||||
ENDIF
|
||||
|
||||
IFNDEF LPROG ; *** Default = __COMPACT__ ***
|
||||
__COMPACT__ equ true
|
||||
LPROG equ false
|
||||
LDATA equ true
|
||||
ENDIF
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Segment Declarations Macros |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
CSeg@ MACRO ;; Open a Code Segment
|
||||
_TEXT SEGMENT BYTE PUBLIC 'CODE'
|
||||
ASSUME CS:_TEXT
|
||||
ENDM
|
||||
|
||||
CSegEnd@ MACRO ;; Close a Code Segment
|
||||
_TEXT ENDS
|
||||
ENDM
|
||||
|
||||
DSeg@ MACRO ;; Open a Data Segment (initialized)
|
||||
_DATA SEGMENT WORD PUBLIC 'DATA'
|
||||
ENDM
|
||||
|
||||
DSegEnd@ MACRO ;; Close a Data Segment (initialized)
|
||||
_DATA ENDS
|
||||
ENDM
|
||||
|
||||
IFDEF __BSS__
|
||||
IFNDEF __HUGE__
|
||||
BSeg@ MACRO ;; Open a Data Segment (un-initialized)
|
||||
_BSS SEGMENT WORD PUBLIC 'BSS'
|
||||
ENDM
|
||||
|
||||
BSegEnd@ MACRO ;; Close a Data Segment (un-initialized)
|
||||
_BSS ENDS
|
||||
ENDM
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
Header@ MACRO
|
||||
_TEXT SEGMENT BYTE PUBLIC 'CODE'
|
||||
_TEXT ENDS
|
||||
_DATA SEGMENT WORD PUBLIC 'DATA'
|
||||
_DATA ENDS
|
||||
IFDEF __BSS__
|
||||
IFNDEF __HUGE__
|
||||
_BSS SEGMENT WORD PUBLIC 'BSS'
|
||||
_BSS ENDS
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
IFDEF __BSS__
|
||||
IFDEF __TINY__
|
||||
DGROUP GROUP _TEXT, _DATA, _BSS
|
||||
ELSE
|
||||
IFDEF __HUGE__
|
||||
DGROUP GROUP _DATA
|
||||
ELSE
|
||||
DGROUP GROUP _DATA, _BSS
|
||||
ENDIF
|
||||
ENDIF
|
||||
ELSE
|
||||
IFDEF __TINY__
|
||||
DGROUP GROUP _TEXT, _DATA
|
||||
ELSE
|
||||
DGROUP GROUP _DATA
|
||||
ENDIF
|
||||
ENDIF
|
||||
ASSUME CS:_TEXT, DS:DGROUP
|
||||
ENDM
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| C Naming Convention Macros |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
UNDERSCORE EQU 1
|
||||
|
||||
ExtSym@ MACRO Sym, sType, sName
|
||||
IFNB <sName>
|
||||
IFIDN <sName>, <__PASCAL__>
|
||||
NAMING = 0
|
||||
ELSE
|
||||
NAMING = UNDERSCORE
|
||||
ENDIF
|
||||
ENDIF
|
||||
IF NAMING
|
||||
EXTRN _&Sym : sType
|
||||
Sym&@ equ _&Sym
|
||||
ELSE
|
||||
EXTRN Sym : sType
|
||||
Sym&@ equ Sym
|
||||
ENDIF
|
||||
ENDM
|
||||
|
||||
PubSym@ MACRO Sym, Definition, sName
|
||||
IFNB <sName>
|
||||
IFIDN <sName>, <__PASCAL__>
|
||||
NAMING = 0
|
||||
ELSE
|
||||
NAMING = UNDERSCORE
|
||||
ENDIF
|
||||
ENDIF
|
||||
IF NAMING
|
||||
PUBLIC _&Sym
|
||||
_&Sym Definition
|
||||
Sym&@ equ _&Sym
|
||||
ELSE
|
||||
PUBLIC Sym
|
||||
Sym Definition
|
||||
Sym&@ equ Sym
|
||||
ENDIF
|
||||
ENDM
|
||||
|
||||
Static@ MACRO Sym, Definition, sName
|
||||
IFNB <sName>
|
||||
IFIDN <sName>, <__PASCAL__>
|
||||
NAMING = 0
|
||||
ELSE
|
||||
NAMING = UNDERSCORE
|
||||
ENDIF
|
||||
ENDIF
|
||||
IF NAMING
|
||||
_&Sym Definition
|
||||
Sym&@ equ _&Sym
|
||||
ELSE
|
||||
Sym Definition
|
||||
Sym&@ equ Sym
|
||||
ENDIF
|
||||
ENDM
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Macros which are Data Size Dependent |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
IF LDATA
|
||||
DPTR_ equ DWORD PTR
|
||||
dPtrSize equ 4
|
||||
LES_ equ LES
|
||||
ES_ equ ES:
|
||||
SS_ equ SS:
|
||||
LDS_ equ LDS
|
||||
|
||||
pushDS_ MACRO
|
||||
PUSH DS
|
||||
ENDM
|
||||
|
||||
popDS_ MACRO
|
||||
POP DS
|
||||
ENDM
|
||||
|
||||
PushPtr MACRO dPtrOff, dPtrSeg
|
||||
PUSH dPtrSeg
|
||||
PUSH dPtrOff
|
||||
ENDM
|
||||
|
||||
|
||||
dPtr@ MACRO Sym, VALUE, sName ;; Static Data pointer
|
||||
Static@ Sym, <DD VALUE>, sName
|
||||
ENDM
|
||||
|
||||
dPtrPub@ MACRO Sym, VALUE, sName ;; Global Data Pointer
|
||||
PubSym@ Sym, <DD VALUE>, sName
|
||||
ENDM
|
||||
|
||||
dPtrExt@ MACRO Sym, sName ;; External Data Pointer
|
||||
ExtSym@ Sym, DWORD, sName
|
||||
ENDM
|
||||
ELSE
|
||||
DPTR_ equ WORD PTR
|
||||
dPtrSize equ 2
|
||||
LES_ equ MOV
|
||||
ES_ equ DS:
|
||||
SS_ equ DS:
|
||||
LDS_ equ MOV
|
||||
|
||||
pushDS_ MACRO
|
||||
ENDM
|
||||
|
||||
popDS_ MACRO
|
||||
ENDM
|
||||
|
||||
PushPtr MACRO dPtrOff, dPtrSeg
|
||||
PUSH dPtrOff
|
||||
ENDM
|
||||
|
||||
dPtr@ MACRO Sym, VALUE, sName ;; Static Data pointer
|
||||
Static@ Sym, <DW VALUE>, sName
|
||||
ENDM
|
||||
|
||||
dPtrPub@ MACRO Sym, VALUE, sName ;; Global Data Pointer
|
||||
PubSym@ Sym, <DW VALUE>, sName
|
||||
ENDM
|
||||
|
||||
dPtrExt@ MACRO Sym, sName ;; External Data Pointer
|
||||
ExtSym@ Sym, WORD, sName
|
||||
ENDM
|
||||
ENDIF
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Macros which are Code Size Dependent |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
IF LPROG
|
||||
CPTR_ equ DWORD PTR
|
||||
cPtrSize equ 4
|
||||
|
||||
Proc@ MACRO Sym, sName ;; Open a Static function
|
||||
Static@ Sym, <PROC FAR>, sName
|
||||
ENDM
|
||||
|
||||
PubProc@ MACRO Sym, sName ;; Open a Public function
|
||||
PubSym@ Sym, <PROC FAR>, sName
|
||||
ENDM
|
||||
|
||||
ExtProc@ MACRO Sym, sName ;; External Function
|
||||
ExtSym@ Sym, FAR, sName
|
||||
ENDM
|
||||
|
||||
cPtr@ MACRO Sym, VALUE, sName ;; Static Function pointer
|
||||
Static@ Sym, <DD VALUE>, sName
|
||||
ENDM
|
||||
|
||||
cPtrPub@ MACRO Sym, VALUE, sName;; Global Function Pointer
|
||||
PubSym@ Sym, <DD VALUE>, sName
|
||||
ENDM
|
||||
|
||||
cPtrExt@ MACRO Sym, sName ;; External Function Pointer
|
||||
ExtSym@ Sym, DWORD, sName
|
||||
ENDM
|
||||
ELSE
|
||||
CPTR_ equ WORD PTR
|
||||
cPtrSize equ 2
|
||||
|
||||
Proc@ MACRO Sym, sName ;; Open a Static function
|
||||
Static@ Sym, <PROC NEAR>, sName
|
||||
ENDM
|
||||
|
||||
PubProc@ MACRO Sym, sName ;; Open a Public function
|
||||
PubSym@ Sym, <PROC NEAR>, sName
|
||||
ENDM
|
||||
|
||||
ExtProc@ MACRO Sym, sName ;; External Function
|
||||
ExtSym@ Sym, NEAR, sName
|
||||
ENDM
|
||||
|
||||
cPtr@ MACRO Sym, VALUE, sName ;; Static Function pointer
|
||||
Static@ Sym, <DW VALUE>, sName
|
||||
ENDM
|
||||
|
||||
cPtrPub@ MACRO Sym, VALUE, sName ;; Global Function Pointer
|
||||
PubSym@ Sym, <DW VALUE>, sName
|
||||
ENDM
|
||||
|
||||
cPtrExt@ MACRO Sym, sName ;; External Function Pointer
|
||||
ExtSym@ Sym, WORD, sName
|
||||
ENDM
|
||||
ENDIF
|
||||
|
||||
EndProc@ MACRO Sym, sName ;; Close a function
|
||||
Static@ Sym, ENDP, sName
|
||||
ENDM
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Miscellaneous Definitions |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
;*** Set up some macros for procedure parameters and export/import
|
||||
|
||||
nearCall STRUC
|
||||
nearBP dw ?
|
||||
nearIP dw ?
|
||||
nearParam dw ?
|
||||
nearCall ENDS
|
||||
|
||||
farCall STRUC
|
||||
farBP dw ?
|
||||
farCSIP dd ?
|
||||
aParam dw ?
|
||||
farCall ENDS
|
||||
|
||||
;*** Next, we define some convenient structures to access the parts
|
||||
; of larger objects.
|
||||
|
||||
_twoBytes STRUC
|
||||
BY0 db ?
|
||||
BY1 db ?
|
||||
_twoBytes ENDS
|
||||
|
||||
_fourWords STRUC
|
||||
W0 dw ?
|
||||
W1 dw ?
|
||||
W2 dw ?
|
||||
W3 dw ?
|
||||
_fourWords ENDS
|
||||
|
||||
_twoDwords STRUC
|
||||
DD0 dd ?
|
||||
DD1 dd ?
|
||||
_twoDwords ENDS
|
||||
|
||||
_aFloat STRUC
|
||||
double dq ?
|
||||
_aFloat ENDS
|
||||
|
||||
; How to invoke MSDOS.
|
||||
|
||||
MSDOS@ MACRO
|
||||
int 21h
|
||||
ENDM
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| Emulator Segments and Definitions |
|
||||
;| |
|
||||
;| The Emu287 module is in a separate model from other |
|
||||
;| code. It uses the DSeg@ data segment, but since it |
|
||||
;| does not actually share data the important aspect of |
|
||||
;| the Data is the class name 'DATA'. It has its own |
|
||||
;| stack inside the data segment. The code segment is |
|
||||
;| completely separate from other code segments. The |
|
||||
;| only contact between Emu287 and other code is via |
|
||||
;| soft interrupts 34h..3Eh. |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
IFNDEF _Pascal_
|
||||
|
||||
EmuSeg@ MACRO
|
||||
EMU_PROG SEGMENT PARA PUBLIC 'CODE'
|
||||
ASSUME CS : EMU_PROG
|
||||
ENDM
|
||||
|
||||
EmuSegEnd@ MACRO
|
||||
EMU_PROG ENDS
|
||||
ENDM
|
||||
|
||||
E87Seg@ MACRO
|
||||
E87_PROG SEGMENT PARA PUBLIC 'CODE'
|
||||
ASSUME CS : E87_PROG
|
||||
ENDM
|
||||
|
||||
E87SegEnd@ MACRO
|
||||
E87_PROG ENDS
|
||||
ENDM
|
||||
|
||||
ELSE
|
||||
|
||||
EmuSeg@ MACRO
|
||||
CODE SEGMENT BYTE PUBLIC
|
||||
ASSUME CS:CODE
|
||||
ENDM
|
||||
|
||||
EmuSegEnd@ MACRO
|
||||
CODE ENDS
|
||||
ENDM
|
||||
|
||||
E87Seg@ MACRO
|
||||
CODE SEGMENT BYTE PUBLIC
|
||||
ASSUME CS:CODE
|
||||
ENDM
|
||||
|
||||
E87SegEnd@ MACRO
|
||||
CODE ENDS
|
||||
ENDM
|
||||
|
||||
ENDIF
|
||||
|
||||
; The next section concerns the use of registers. SI and DI are used
|
||||
; for register variables, and must be conserved.
|
||||
|
||||
; Registers AX, BX, CX, DX will not be preserved across function calls.
|
||||
|
||||
; Firstly, the registers to be conserved through function calls, including
|
||||
; the setup of local variables.
|
||||
|
||||
link@ MACRO _si,_di,_ES,locals
|
||||
push bp
|
||||
mov bp, sp
|
||||
IFNB <locals>
|
||||
lea sp, locals
|
||||
ENDIF
|
||||
IFNB <_si>
|
||||
push si
|
||||
ENDIF
|
||||
IFNB <_di>
|
||||
push di
|
||||
ENDIF
|
||||
ENDM
|
||||
|
||||
unLink@ MACRO _si,_di,_ES,locals
|
||||
IFNB <_di>
|
||||
pop di
|
||||
ENDIF
|
||||
IFNB <_si>
|
||||
pop si
|
||||
ENDIF
|
||||
IFNB <locals>
|
||||
mov sp, bp
|
||||
ENDIF
|
||||
pop bp
|
||||
ENDM
|
||||
PAGE
|
||||
;[]------------------------------------------------------------[]
|
||||
;| |
|
||||
;| iNDP Status and Control words definitions |
|
||||
;| |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
;/* 8087/80287 Status Word format */
|
||||
|
||||
SW_INVALID equ 00001h ;/* Invalid operation */
|
||||
SW_DENORMAL equ 00002h ;/* Denormalized operand */
|
||||
SW_ZERODIVIDE equ 00004h ;/* Zero divide */
|
||||
SW_OVERFLOW equ 00008h ;/* Overflow */
|
||||
SW_UNDERFLOW equ 00010h ;/* Underflow */
|
||||
SW_INEXACT equ 00020h ;/* Precision (Inexact result) */
|
||||
|
||||
;/* 8087/80287 Control Word format */
|
||||
|
||||
MCW_EM equ 0003Fh ;/* interrupt Exception Masks */
|
||||
EM_INVALID equ 00001h ;/* invalid */
|
||||
EM_DENORMAL equ 00002h ;/* denormal */
|
||||
EM_ZERODIVIDE equ 00004h ;/* zero divide */
|
||||
EM_OVERFLOW equ 00008h ;/* overflow */
|
||||
EM_UNDERFLOW equ 00010h ;/* underflow */
|
||||
EM_INEXACT equ 00020h ;/* inexact (precision) */
|
||||
|
||||
MCW_IC equ 01000h ;/* Infinity Control */
|
||||
IC_AFFINE equ 01000h ;/* affine */
|
||||
IC_PROJECTIVE equ 00000h ;/* projective */
|
||||
|
||||
MCW_RC equ 00C00h ;/* Rounding Control */
|
||||
RC_CHOP equ 00C00h ;/* chop */
|
||||
RC_UP equ 00800h ;/* up */
|
||||
RC_DOWN equ 00400h ;/* down */
|
||||
RC_NEAR equ 00000h ;/* near */
|
||||
|
||||
MCW_PC equ 00300h ;/* Precision Control */
|
||||
PC_24 equ 00000h ;/* 24 bits */
|
||||
PC_53 equ 00200h ;/* 53 bits */
|
||||
PC_64 equ 00300h ;/* 64 bits */
|
||||
|
||||
;/* 8087/80287 Initial Control Word */
|
||||
;/* use affine infinity, mask underflow and precision exceptions */
|
||||
;/* should be same as in float.h */
|
||||
|
||||
CW_DEFAULT equ (RC_NEAR+PC_64+IC_AFFINE+EM_UNDERFLOW+EM_INEXACT)
|
||||
|
||||
.LIST
|
||||
|
BIN
Borland Turbo C v2/SANS.CHR
Normal file
BIN
Borland Turbo C v2/SANS.CHR
Normal file
Binary file not shown.
729
Borland Turbo C v2/SETARGV.ASM
Normal file
729
Borland Turbo C v2/SETARGV.ASM
Normal file
@ -0,0 +1,729 @@
|
||||
NAME SETARGV
|
||||
PAGE 60,132
|
||||
;[]------------------------------------------------------------[]
|
||||
;| SETARGV.ASM -- Parse Command Line |
|
||||
;| |
|
||||
;| Turbo-C Run Time Library version 2.0 |
|
||||
;| |
|
||||
;| Copyright (c) 1988 by Borland International Inc. |
|
||||
;| All Rights Reserved. |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
INCLUDE RULES.ASI
|
||||
|
||||
; Segment and Group declarations
|
||||
|
||||
Header@
|
||||
|
||||
; External references
|
||||
|
||||
ExtSym@ _argc, WORD, __CDECL__
|
||||
dPtrExt@ _argv, __CDECL__
|
||||
ExtSym@ _psp, WORD, __CDECL__
|
||||
ExtSym@ _envseg, WORD, __CDECL__
|
||||
ExtSym@ _envLng, WORD, __CDECL__
|
||||
ExtSym@ _osmajor, BYTE, __CDECL__
|
||||
ExtProc@ abort, __CDECL__
|
||||
|
||||
ifdef WILD
|
||||
ExtProc@ sbrk, __CDECL__
|
||||
endif
|
||||
|
||||
SUBTTL Parse Command Line
|
||||
PAGE
|
||||
;/* */
|
||||
;/*-----------------------------------------------------*/
|
||||
;/* */
|
||||
;/* Parse Command Line */
|
||||
;/* ------------------ */
|
||||
;/* */
|
||||
;/*-----------------------------------------------------*/
|
||||
;/* */
|
||||
PSPCmd equ 00080h
|
||||
|
||||
CSeg@
|
||||
|
||||
IF LPROG
|
||||
SavedReturn dd ?
|
||||
ELSE
|
||||
SavedReturn dw ?
|
||||
ENDIF
|
||||
SavedDS dw ?
|
||||
SavedBP dw ?
|
||||
|
||||
|
||||
ifdef WILD
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Not enough space on stack for the program name.
|
||||
;
|
||||
BadProgName label near
|
||||
jmp abort@
|
||||
|
||||
endif
|
||||
|
||||
;==============================================================================
|
||||
|
||||
ifdef WILD
|
||||
PubProc@ _wildargv, __CDECL__
|
||||
else
|
||||
PubProc@ _setargv, __CDECL__
|
||||
endif
|
||||
|
||||
; First, save caller context and Return Address
|
||||
|
||||
pop word ptr SavedReturn
|
||||
IF LPROG
|
||||
pop word ptr SavedReturn+2
|
||||
ENDIF
|
||||
mov SavedDS, ds
|
||||
cld
|
||||
|
||||
; Compute Command Line size
|
||||
|
||||
mov es, _psp@
|
||||
mov si, PSPCmd ; ES: SI = Command Line address
|
||||
xor ah, ah
|
||||
lods byte ptr es:[si]
|
||||
inc ax ; AX = Command Line size including \r
|
||||
mov bp, es
|
||||
xchg dx, si ; BP:DX = Command Line address
|
||||
xchg bx, ax ; BX = Command line size
|
||||
|
||||
; Compute Program Name size
|
||||
|
||||
mov si, _envLng@
|
||||
add si, 2 ; SI = Program name offset
|
||||
mov cx, 1 ; CX = Filename size (includes \0)
|
||||
cmp _osmajor@, 3
|
||||
jb NoProgramName
|
||||
mov es, _envseg@
|
||||
mov di, si ; SI = argv[0] address
|
||||
mov cl, 07fh
|
||||
xor al, al
|
||||
repnz scasb
|
||||
jcxz BadProgName
|
||||
xor cl, 07fh ; CX = Filename size (includes \0)
|
||||
NoProgramName label near
|
||||
|
||||
; Reserve space for the arguments
|
||||
|
||||
sub sp, 2 ; To be sure nothing in SS:FFFF
|
||||
mov ax, 1
|
||||
ifndef WILD
|
||||
add ax, bx
|
||||
endif
|
||||
add ax, cx
|
||||
and ax, not 1
|
||||
mov di, sp
|
||||
sub di, ax
|
||||
jb BadProgName
|
||||
mov sp, di ; SS:DI = Command Line storage address
|
||||
|
||||
; Copy ProgName to the stack
|
||||
|
||||
mov ax, es
|
||||
mov ds, ax
|
||||
mov ax, ss
|
||||
mov es, ax
|
||||
ifndef WILD
|
||||
push cx
|
||||
endif
|
||||
dec cx
|
||||
rep movsb
|
||||
xor al, al
|
||||
stosb ; ASCIIZ string
|
||||
|
||||
; Process Command Line.
|
||||
|
||||
;==============================================================================
|
||||
ifdef WILD
|
||||
;==============================================================================
|
||||
|
||||
;
|
||||
; The value of "wild_attr" is used in the "findfirst" call as the file
|
||||
; attribute.
|
||||
;
|
||||
; The default value is 0, which will only include "regular" files.
|
||||
;
|
||||
; Adding 10H to this value will include directories, 04h will include system
|
||||
; files, and 02h will include hidden files.
|
||||
;
|
||||
|
||||
wild_attr equ 0 ; include only regular files
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
ffblk struc
|
||||
|
||||
ff_reserved db 21 dup (?)
|
||||
ff_attrib db ?
|
||||
ff_ftime dw ?
|
||||
ff_fdate dw ?
|
||||
ff_fsize dd ?
|
||||
ff_name db 14 dup (?)
|
||||
|
||||
ffblk ends
|
||||
|
||||
wild_init_space equ 128 ; initial buffer allocation
|
||||
wild_more_space equ 256 ; buffer size increment
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
wild_buff_addr equ [bp]
|
||||
wild_buff_size equ [bp+4]
|
||||
wild_buff_max equ [bp+6]
|
||||
wild_arg_src equ [bp+8]
|
||||
wild_arg_dst equ [bp+10]
|
||||
|
||||
wild_argument equ [bp+12]
|
||||
wild_destin equ [bp+16]
|
||||
wild_path_len equ [bp+20]
|
||||
wild_argc equ [bp+22]
|
||||
|
||||
wild_DTA_save equ [bp+24]
|
||||
wild_ffblk equ [bp+28]
|
||||
|
||||
wild_frame_size equ 28 + TYPE ffblk
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
mov cx, bp ; save segment of command line
|
||||
dec bx ; don't need trailing \0
|
||||
|
||||
sub sp, wild_frame_size
|
||||
mov bp, sp ; bp points at local variables
|
||||
|
||||
push dx ; save cmd line addr
|
||||
push cx ; save cmd line seg
|
||||
push bx ; save cmd line size
|
||||
mov ax, wild_init_space
|
||||
mov wild_buff_size, ax ; save initial size
|
||||
ifndef __HUGE__
|
||||
mov ds, savedDS
|
||||
endif
|
||||
push ax
|
||||
call sbrk@
|
||||
pop cx ; toss parameter
|
||||
pop cx ; restore cmd line size
|
||||
pop ds ; restore cmd line seg
|
||||
pop si ; restore cmd line addr
|
||||
|
||||
mov wild_buff_addr, ax ; save offset
|
||||
if LDATA
|
||||
mov wild_buff_addr+2, dx ; save segment
|
||||
and ax, dx
|
||||
else
|
||||
mov wild_buff_addr+2, ss ; seg = SS
|
||||
endif
|
||||
cmp ax, -1
|
||||
je NoSbrkSpace ; abort if not enough space
|
||||
add ax, wild_buff_size
|
||||
mov wild_buff_max, ax ; save max offset
|
||||
|
||||
mov ah, 2fh
|
||||
int 21h ; get current DTA
|
||||
mov wild_DTA_save, bx
|
||||
mov wild_DTA_save+2, es
|
||||
push ds
|
||||
push ss ; fflbk is on stack
|
||||
pop ds
|
||||
lea dx, wild_ffblk
|
||||
mov ah, 1ah
|
||||
int 21h ; switch DTA to ffblk
|
||||
pop ds
|
||||
|
||||
les di, dword ptr wild_buff_addr
|
||||
xor dx, dx ; dx = # of arguments
|
||||
;
|
||||
; Start new argument.
|
||||
;
|
||||
NewArg: mov wild_arg_dst, di
|
||||
xor bh, bh ; bh = wildcard flag
|
||||
;
|
||||
; Skip leading whitespace.
|
||||
;
|
||||
ArgCopy: mov wild_arg_src, si ; save address of argument
|
||||
call GetChar
|
||||
jc ArgCopyDone ; jump if no more characters
|
||||
jz ArgCopyLoop
|
||||
cmp al, ' '
|
||||
je ArgCopy ; skip whitespace
|
||||
cmp al, 9
|
||||
je ArgCopy
|
||||
cmp al, 13
|
||||
je ArgCopy
|
||||
cmp al, '"'
|
||||
je ArgQuote ; jump if quoted string
|
||||
;
|
||||
; Loop to copy unquoted argument.
|
||||
;
|
||||
ArgCopyLoop: call ArgPushChar ; store character in destination
|
||||
call GetChar
|
||||
jc ArgComplete ; jump if end of line
|
||||
jz ArgCopyLoop ; jump if \"
|
||||
cmp al, ' '
|
||||
je ArgComplete ; whitespace terminates
|
||||
cmp al, 9
|
||||
je ArgComplete
|
||||
cmp al, 13
|
||||
je ArgComplete ; whitespace terminates
|
||||
cmp al, '"'
|
||||
jne ArgCopyLoop
|
||||
ArgComplete: call ProcessArg ; copy or expand argument
|
||||
jmp SHORT NewArg
|
||||
|
||||
NoSbrkSpace: jmp abort@ ; error jump
|
||||
|
||||
;
|
||||
; Here if quoted argument.
|
||||
;
|
||||
ArgQuote: call GetChar
|
||||
jc QuoteDone
|
||||
jz QuoteNext
|
||||
cmp al, '"' ; terminating quote ?
|
||||
je QuoteDone
|
||||
QuoteNext: call ArgPushChar ; store character in destination
|
||||
jmp SHORT ArgQuote
|
||||
;
|
||||
; End of a quoted argument. Push terminating null, do not expand.
|
||||
;
|
||||
QuoteDone: xor al, al
|
||||
call ArgPushChar ; push terminating null
|
||||
inc dx ; bump arg count
|
||||
jmp SHORT NewArg ; go get more
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Here when done expanding command line. Go build the argv array.
|
||||
;
|
||||
ArgCopyDone: mov ax, di ; ax = unused space
|
||||
sub ax, wild_buff_max
|
||||
jz ArgNoWaste ; skip if all used
|
||||
push dx
|
||||
push di
|
||||
ifndef __HUGE__
|
||||
mov ds, savedDS
|
||||
endif
|
||||
push ax
|
||||
call sbrk@ ; release unused memory
|
||||
pop cx ; toss parameter
|
||||
pop di
|
||||
pop dx
|
||||
ArgNoWaste: lds si, dword ptr wild_buff_addr
|
||||
mov cx, di
|
||||
sub cx, si ; cx = number of bytes in expanded line
|
||||
inc dx ; count program name
|
||||
jmp BuildArgv
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Routine to retrieve the next character from the command line.
|
||||
; Sets CF when end of line reached.
|
||||
; Sets ZF when \ character found (i.e. \")
|
||||
;
|
||||
; bh.bit0 set if wildcard chars found (* or ?)
|
||||
; bh.bit1 set if \ character found (\")
|
||||
;
|
||||
GetChar proc near
|
||||
|
||||
jcxz GchEnd ; jump if no more
|
||||
lodsb
|
||||
dec cx
|
||||
cmp al, '\' ; escape ?
|
||||
je GchEsc
|
||||
cmp al, '?'
|
||||
je GchWild
|
||||
cmp al, '*'
|
||||
je GchWild
|
||||
GchRet: or ah, 1 ; clear CF and ZF
|
||||
ret
|
||||
GchWild: test bh, bh
|
||||
jnz GchRet ; give up if \" has been found
|
||||
or bh, 1
|
||||
ret
|
||||
GchEsc: jcxz GchRet ; check for \ at end of line
|
||||
cmp byte ptr [si],'"'
|
||||
jne GchRet ; only \" is special
|
||||
lodsb
|
||||
dec cx
|
||||
mov bh, 2 ; set \ flag
|
||||
xor ah, ah ; clear CF, set ZF
|
||||
ret
|
||||
GchEnd: stc
|
||||
ret
|
||||
|
||||
GetChar endp
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Routine to expand a wildcard parameter.
|
||||
;
|
||||
; DS:SI = argument address
|
||||
; ES:DI = destination
|
||||
; Returns:
|
||||
; CX = number of expanded arguments (0 = no match)
|
||||
;
|
||||
WildExpand proc near
|
||||
|
||||
push ds
|
||||
mov wild_argument, si
|
||||
mov wild_argument+2, ds
|
||||
mov wild_destin, di
|
||||
mov wild_destin+2, es
|
||||
mov word ptr wild_argc, 0
|
||||
;
|
||||
; Find the length of the path prefix, if any.
|
||||
;
|
||||
mov bx, si
|
||||
WildFindPath: lodsb
|
||||
and al, al
|
||||
jz WildEndPath
|
||||
cmp al, '\'
|
||||
je WildDelimiter
|
||||
cmp al, ':'
|
||||
je WildDelimiter
|
||||
cmp al, '\'
|
||||
jne WildFindPath
|
||||
WildDelimiter: mov bx, si ; save addr past last delimiter
|
||||
jmp SHORT WildFindPath
|
||||
WildEndPath: sub bx, wild_argument
|
||||
mov wild_path_len, bx
|
||||
|
||||
mov ah, 4eh
|
||||
mov cx, wild_attr ; file attribute
|
||||
lds dx, dword ptr wild_argument
|
||||
int 21h ; find first matching file ...
|
||||
jc WildDone
|
||||
;
|
||||
; We have a matching file. Add it to the destination string (unless "." or "..")
|
||||
;
|
||||
WildAddArg:
|
||||
;
|
||||
; If directories are included (10h set in wild_attr), ignore "." and ".."
|
||||
;
|
||||
if wild_attr AND 10h
|
||||
push ss
|
||||
pop ds
|
||||
lea si,wild_ffblk.ff_name
|
||||
cmp byte ptr [si],'.' ; skip if doesn't start with "."
|
||||
jne WildNoDir
|
||||
cmp byte ptr [si+1],0 ; check for "."
|
||||
je WildNameNext
|
||||
cmp word ptr [si+1],'.' ; check for ".."
|
||||
je WildNameNext
|
||||
WildNoDir:
|
||||
endif
|
||||
|
||||
inc word ptr wild_argc
|
||||
les di, dword ptr wild_destin
|
||||
mov cx, wild_path_len ; prefix filename with path
|
||||
jcxz WildCopyName
|
||||
lds si, dword ptr wild_argument
|
||||
WildCopyPath: lodsb
|
||||
call ArgPushChar
|
||||
loop WildCopyPath
|
||||
WildCopyName: lea si,wild_ffblk.ff_name ; copy filename from ffblk
|
||||
WildNameLoop: lods byte ptr ss:[si]
|
||||
push ax
|
||||
call ArgPushChar ; store char in destination
|
||||
pop ax
|
||||
and al, al ; continue until \0
|
||||
jnz WildNameLoop
|
||||
mov wild_destin, di
|
||||
WildNameNext: mov ah, 4fh
|
||||
int 21h ; find next matching file
|
||||
jnc WildAddArg
|
||||
;
|
||||
; Done with expansion. Restore ES:DI, set CX, and return.
|
||||
;
|
||||
WildDone: mov cx, wild_argc
|
||||
les di, dword ptr wild_destin
|
||||
pop ds
|
||||
ret
|
||||
|
||||
WildExpand endp
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Routine to store a character in the destination string.
|
||||
;
|
||||
ArgPushChar proc near
|
||||
|
||||
cmp di, wild_buff_max ; space available ?
|
||||
jae ArgMoreSpace
|
||||
stosb ; yes --> store character
|
||||
ret
|
||||
;
|
||||
; No more argument space. Grab some more memory through sbrk.
|
||||
;
|
||||
ArgMoreSpace: push ds
|
||||
push es
|
||||
push si
|
||||
push di
|
||||
push ax
|
||||
push bx
|
||||
push cx
|
||||
push dx
|
||||
|
||||
ifndef __HUGE__
|
||||
mov ds, savedDS
|
||||
endif
|
||||
mov ax, wild_more_space
|
||||
add wild_buff_size, ax ; bump allocated size
|
||||
add wild_buff_max, ax ; bump end pointer
|
||||
push ax
|
||||
call sbrk@
|
||||
pop cx
|
||||
if LDATA
|
||||
and ax, dx
|
||||
endif
|
||||
cmp ax, -1
|
||||
je NoArgSpace ; abort if not enough space
|
||||
|
||||
pop dx
|
||||
pop cx
|
||||
pop bx
|
||||
pop ax
|
||||
pop di
|
||||
pop si
|
||||
pop es
|
||||
pop ds
|
||||
stosb ; store character
|
||||
ret
|
||||
|
||||
ArgPushChar endp
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Not enough space to process the command line .... abort.
|
||||
;
|
||||
NoArgSpace: jmp abort@
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Routine to process an argument.
|
||||
;
|
||||
ProcessArg proc near
|
||||
|
||||
push bx
|
||||
xor al, al
|
||||
call ArgPushChar ; null-terminate
|
||||
pop bx
|
||||
test bh, 1 ; wildcards present ?
|
||||
jnz ArgWild
|
||||
inc dx ; bump arg count
|
||||
ret
|
||||
;
|
||||
; We have a wildcard argument. Expand it.
|
||||
;
|
||||
ArgWild: push cx
|
||||
push [si] ; save word following argument
|
||||
mov byte ptr [si],0 ; null-terminate argument
|
||||
xchg si, wild_arg_src ; si = argument address
|
||||
push di
|
||||
mov di, wild_arg_dst
|
||||
push dx
|
||||
call WildExpand
|
||||
pop dx
|
||||
pop bx
|
||||
and cx, cx ; see if any matched
|
||||
jnz ArgWildSome
|
||||
mov di, bx ; none ---> use unexpanded argument
|
||||
mov cx, 1 ; bump arg count by 1
|
||||
ArgWildSome: add dx, cx
|
||||
mov si, wild_arg_src
|
||||
pop [si] ; restore word following argument
|
||||
pop cx
|
||||
ret
|
||||
|
||||
ProcessArg endp
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
;
|
||||
; Build the argv array. [DS:SI] is the expanded command line, CX its length.
|
||||
; DX has the number of arguments (including the program name).
|
||||
;
|
||||
BuildArgv: push ds
|
||||
push dx
|
||||
lds dx, dword ptr wild_DTA_save
|
||||
mov ah, 1ah
|
||||
int 21h ; switch to original DTA
|
||||
pop dx
|
||||
pop ds
|
||||
|
||||
add sp, wild_frame_size ; remove local variables
|
||||
|
||||
mov es,savedDS
|
||||
mov es:[_argc@], dx
|
||||
inc dx ; argv ends with a NULL pointer
|
||||
shl dx, 1 ; argc * 2 (LDATA = 0)
|
||||
IF LDATA
|
||||
shl dx, 1 ; argc * 4 (LDATA = 1)
|
||||
ENDIF
|
||||
mov bx, sp ; point to program name
|
||||
mov bp, sp
|
||||
sub bp, dx
|
||||
jb NoArgSpace
|
||||
mov sp, bp ; SS:BP = argv array address
|
||||
mov word ptr es:[_argv@], bp
|
||||
IF LDATA
|
||||
mov word ptr es:[_argv@+2], ss
|
||||
ENDIF
|
||||
mov [bp], bx ; set argv[0] to program name
|
||||
IF LDATA
|
||||
mov [bp+2], ss ; program name is on the stack
|
||||
ENDIF
|
||||
add bp, dPtrSize
|
||||
|
||||
SetArgvX label near
|
||||
jcxz SetLastArg
|
||||
mov [bp], si ; Set argv[n]
|
||||
IF LDATA
|
||||
mov [bp+2], ds
|
||||
ENDIF
|
||||
add bp, dPtrSize
|
||||
CopyArg label near
|
||||
lodsb
|
||||
or al, al
|
||||
loopnz CopyArg
|
||||
jz SetArgvX
|
||||
SetLastArg label near
|
||||
xor ax, ax
|
||||
mov [bp], ax
|
||||
IF LDATA
|
||||
mov [bp+2], ax
|
||||
ENDIF
|
||||
mov ds, savedDS
|
||||
|
||||
;==============================================================================
|
||||
else
|
||||
;==============================================================================
|
||||
|
||||
mov ds, bp
|
||||
xchg si, dx ; DS: SI = Command Line address
|
||||
xchg bx, cx ; CX = Command Line size including \r
|
||||
mov ax, bx
|
||||
mov dx, ax ; AX = BX = DX = 0
|
||||
inc bx ; BX = Nb of arguments (at least 1)
|
||||
Processing label near
|
||||
call NextChar
|
||||
ja NotQuote ; Not a quote and there are more
|
||||
InString label near
|
||||
jb BuildArgv ; Command line is empty now
|
||||
call NextChar
|
||||
ja InString ; Not a quote and there are more
|
||||
NotQuote label near
|
||||
cmp al, ' '
|
||||
je EndArgument ; Space is an argument separator
|
||||
cmp al, 13
|
||||
je EndArgument ; \r is an argument separator
|
||||
cmp al, 9
|
||||
jne Processing ; \t is an argument separator
|
||||
EndArgument label near
|
||||
xor al, al ; Space and TAB are argument separators
|
||||
jmp short Processing
|
||||
|
||||
; Character test function used in SetArgs
|
||||
; On entry AL holds the previous character
|
||||
; On exit AL holds the next character
|
||||
; ZF on if the next character is quote (") and AL = 0
|
||||
; CF on if end of command line and AL = 0
|
||||
|
||||
NextChar PROC NEAR
|
||||
or ax, ax
|
||||
jz NextChar0
|
||||
inc dx ; DX = Actual length of CmdLine
|
||||
stosb
|
||||
or al, al
|
||||
jnz NextChar0
|
||||
inc bx ; BX = Number of parameters
|
||||
NextChar0 label near
|
||||
xchg ah, al
|
||||
xor al, al
|
||||
stc
|
||||
jcxz NextChar2 ; End of command line --> CF ON
|
||||
lodsb
|
||||
dec cx
|
||||
sub al, '"'
|
||||
jz NextChar2 ; Quote found --> AL = 0 and ZF ON
|
||||
add al, '"'
|
||||
cmp al,'\'
|
||||
jne NextChar1 ; It is not a \
|
||||
cmp byte ptr ds:[si], '"'
|
||||
jne NextChar1 ; Only " is transparent after \
|
||||
lodsb
|
||||
dec cx
|
||||
NextChar1 label near
|
||||
or si, si ; Be sure both CF & ZF are OFF
|
||||
NextChar2 label near
|
||||
ret
|
||||
NextChar ENDP
|
||||
|
||||
; Invalid program name
|
||||
|
||||
BadProgName label near
|
||||
jmp abort@
|
||||
|
||||
; Now, build the argv array
|
||||
|
||||
BuildArgv label near
|
||||
pop cx
|
||||
add cx, dx ; CX = Argument area size
|
||||
mov ds, SavedDS
|
||||
mov _argc@, bx
|
||||
inc bx ; argv ends with a NULL pointer
|
||||
add bx, bx ; argc * 2 (LDATA = 0)
|
||||
IF LDATA
|
||||
add bx, bx ; argc * 4 (LDATA = 1)
|
||||
ENDIF
|
||||
mov si, sp
|
||||
mov bp, sp
|
||||
sub bp, bx
|
||||
jb BadProgName
|
||||
mov sp, bp ; SS:BP = argv array address
|
||||
mov word ptr _argv@, bp
|
||||
IF LDATA
|
||||
mov word ptr _argv@+2, ss
|
||||
ENDIF
|
||||
SetArgvX label near
|
||||
jcxz SetLastArg
|
||||
mov [bp], si ; Set argv[n]
|
||||
IF LDATA
|
||||
mov [bp+2], ss
|
||||
ENDIF
|
||||
add bp, dPtrSize
|
||||
CopyArg label near
|
||||
lods byte ptr ss:[si]
|
||||
or al, al
|
||||
loopnz CopyArg
|
||||
jz SetArgvX
|
||||
SetLastArg label near
|
||||
xor ax, ax
|
||||
mov [bp], ax
|
||||
IF LDATA
|
||||
mov [bp+2], ax
|
||||
ENDIF
|
||||
|
||||
;==============================================================================
|
||||
endif ; ifdef WILD
|
||||
;==============================================================================
|
||||
|
||||
; Restore caller context and exit
|
||||
|
||||
IF LPROG
|
||||
jmp dword ptr SavedReturn
|
||||
ELSE
|
||||
jmp word ptr SavedReturn
|
||||
ENDIF
|
||||
|
||||
ifdef WILD
|
||||
EndProc@ _wildargv, __CDECL__
|
||||
else
|
||||
EndProc@ _setargv, __CDECL__
|
||||
endif
|
||||
|
||||
CSegEnd@
|
||||
END
|
||||
|
118
Borland Turbo C v2/SETENVP.ASM
Normal file
118
Borland Turbo C v2/SETENVP.ASM
Normal file
@ -0,0 +1,118 @@
|
||||
NAME SETENVP
|
||||
PAGE 60,132
|
||||
;[]------------------------------------------------------------[]
|
||||
;| SETENVP.ASM -- Prepare Environment |
|
||||
;| |
|
||||
;| Turbo-C Run Time Library version 2.0 |
|
||||
;| |
|
||||
;| Copyright (c) 1988 by Borland International Inc. |
|
||||
;| All Rights Reserved. |
|
||||
;[]------------------------------------------------------------[]
|
||||
|
||||
INCLUDE RULES.ASI
|
||||
|
||||
; Segment and Group declarations
|
||||
|
||||
Header@
|
||||
|
||||
; External references
|
||||
|
||||
ExtProc@ malloc, __CDECL__
|
||||
ExtProc@ abort, __CDECL__
|
||||
|
||||
ExtSym@ _envseg, WORD, __CDECL__
|
||||
ExtSym@ _envLng, WORD, __CDECL__
|
||||
ExtSym@ _envSize, WORD, __CDECL__
|
||||
dPtrExt@ environ, __CDECL__
|
||||
|
||||
SUBTTL Prepare Environment
|
||||
PAGE
|
||||
;/* */
|
||||
;/*-----------------------------------------------------*/
|
||||
;/* */
|
||||
;/* Prepare Environment */
|
||||
;/* ------------------- */
|
||||
;/* */
|
||||
;/*-----------------------------------------------------*/
|
||||
;/* */
|
||||
|
||||
CSeg@
|
||||
|
||||
PubProc@ _setenvp, __CDECL__
|
||||
|
||||
; Allocate a buffer to hold environment variables
|
||||
|
||||
IF LDATA EQ 0
|
||||
mov cx, _envLng@
|
||||
push cx
|
||||
call malloc@
|
||||
pop cx
|
||||
mov di, ax
|
||||
or ax, ax
|
||||
jz _Failed ; Memory allocation failed
|
||||
push ds
|
||||
push ds
|
||||
pop es
|
||||
mov ds, _envseg@
|
||||
xor si, si
|
||||
cld
|
||||
rep movsb
|
||||
pop ds
|
||||
mov di, ax
|
||||
ELSE
|
||||
mov es, _envseg@
|
||||
xor di, di
|
||||
ENDIF
|
||||
|
||||
; Allocate a buffer to hold envp array
|
||||
|
||||
push es ; Save Environment Segment address
|
||||
push _envSize@
|
||||
call malloc@
|
||||
add sp, 2
|
||||
mov bx, ax
|
||||
pop es ; Restore Environment Segment address
|
||||
IF LDATA
|
||||
mov word ptr environ@, ax
|
||||
mov word ptr environ@+2, dx
|
||||
push ds
|
||||
mov ds, dx
|
||||
or ax, dx
|
||||
ELSE
|
||||
mov word ptr environ@, ax
|
||||
or ax, ax
|
||||
ENDIF
|
||||
jnz SetEnviron ; Memory allocation failed
|
||||
_Failed label near ; Memory allocation failed
|
||||
jmp abort@
|
||||
|
||||
|
||||
; Now, store environment variables address
|
||||
|
||||
SetEnviron label near
|
||||
xor ax, ax
|
||||
mov cx, -1
|
||||
SetEnviron0 label near
|
||||
mov [bx], di
|
||||
IF LDATA
|
||||
mov [bx+2], es
|
||||
add bx, 4
|
||||
ELSE
|
||||
add bx, 2
|
||||
ENDIF
|
||||
repnz scasb
|
||||
cmp es:[di], al
|
||||
jne SetEnviron0 ; Set next pointer
|
||||
IF LDATA
|
||||
mov [bx], ax
|
||||
mov [bx+2], ax
|
||||
pop ds
|
||||
ELSE
|
||||
mov [bx], ax
|
||||
ENDIF
|
||||
ret
|
||||
EndProc@ _setenvp, __CDECL__
|
||||
|
||||
CsegEnd@
|
||||
END
|
||||
|
35
Borland Turbo C v2/SIEVE.C
Normal file
35
Borland Turbo C v2/SIEVE.C
Normal file
@ -0,0 +1,35 @@
|
||||
/* sieve.c */
|
||||
|
||||
/* Eratosthenes Sieve Prime Number Program in C from Byte Jan 1983
|
||||
to compare the speed. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define SIZE 8190
|
||||
typedef int bool;
|
||||
|
||||
char flags[SIZE+1];
|
||||
|
||||
int main()
|
||||
{
|
||||
int i,k;
|
||||
int prime,count,iter;
|
||||
|
||||
for (iter = 1; iter <= 10; iter++) { /* do program 10 times */
|
||||
count = 0; /* initialize prime counter */
|
||||
for (i = 0; i <= SIZE; i++) /* set all flags TRUE */
|
||||
flags[i] = TRUE;
|
||||
for (i = 0; i <= SIZE; i++) {
|
||||
if (flags[i]) { /* found a prime */
|
||||
prime = i + i + 3; /* twice index + 3 */
|
||||
for (k = i + prime; k <= SIZE; k += prime)
|
||||
flags[k] = FALSE; /* kill all multiples */
|
||||
count++; /* primes found */
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d primes.\n",count); /*primes found in 10th pass */
|
||||
return 0;
|
||||
}
|
127
Borland Turbo C v2/SSIGNAL.C
Normal file
127
Borland Turbo C v2/SSIGNAL.C
Normal file
@ -0,0 +1,127 @@
|
||||
/*-----------------------------------------------------------------------*
|
||||
* filename - ssignal.c
|
||||
*
|
||||
* function(s)
|
||||
* ssignal - implements software signals
|
||||
* gsignal - implements software signals
|
||||
*-----------------------------------------------------------------------*/
|
||||
|
||||
/*[]---------------------------------------------------[]*/
|
||||
/*| |*/
|
||||
/*| Turbo C Run Time Library - Version 1.5 |*/
|
||||
/*| |*/
|
||||
/*| |*/
|
||||
/*| Copyright (c) 1987,88 by Borland International |*/
|
||||
/*| All Rights Reserved. |*/
|
||||
/*| |*/
|
||||
/*[]---------------------------------------------------[]*/
|
||||
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#pragma warn -sus
|
||||
|
||||
static int (*Sigtbl[16])() =
|
||||
{
|
||||
0,
|
||||
SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL,
|
||||
SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL,
|
||||
SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL, SIG_DFL,
|
||||
};
|
||||
|
||||
#pragma warn .sus
|
||||
|
||||
/*---------------------------------------------------------------------*
|
||||
|
||||
Name ssignal - implements software signals
|
||||
|
||||
Usage int (*ssignal(int sig, int (*action)( ))( );
|
||||
|
||||
Related
|
||||
functions usage int gsignal(int sig);
|
||||
|
||||
Prototype in signal.h
|
||||
|
||||
Description ssignal and gsignal implement a software-signalling
|
||||
facility. Software signals are associated with integers in the
|
||||
range from 1 to 15.
|
||||
|
||||
gsignal raises the signal given by sig and executes the action
|
||||
routine.
|
||||
|
||||
ssignal is used to establish an action routine for servicing a
|
||||
signal. The first argument to ssignal, sig, is a number
|
||||
identifying the type of signal for which an action is
|
||||
established.
|
||||
|
||||
The second argument, action, defines the action; it is either
|
||||
the name of a user-defined action function or one of the
|
||||
constants SIG_DFL (default) or SIG_IGN (ignore). These constants
|
||||
are defined in signal.h.
|
||||
|
||||
If an action function has been established for sig, then that
|
||||
action is reset to SIG_DFL, and the action function is entered
|
||||
with argument sig.
|
||||
|
||||
Return value ssignal returns the action previously established
|
||||
or, if the signal number is illegal, returns SIG_DFL.
|
||||
|
||||
gsignal returns the value returned to it by the action
|
||||
function. gsignal's return values for actions assigned to sig
|
||||
are listed in the following:
|
||||
|
||||
Action Return
|
||||
|
||||
SIG_IGN 1
|
||||
SIG_DFL 0
|
||||
Illegal value or 0
|
||||
no action specified
|
||||
|
||||
In all cases, gsignal takes no action other than returning a
|
||||
value.
|
||||
|
||||
*---------------------------------------------------------------------*/
|
||||
int (*ssignal(register int sig, int (*action)()))()
|
||||
{
|
||||
int (*oldact)();
|
||||
|
||||
#pragma warn -sus
|
||||
if (sig < 1 || sig > 15)
|
||||
return (SIG_DFL);
|
||||
#pragma warn .sus
|
||||
|
||||
oldact = Sigtbl[sig];
|
||||
Sigtbl[sig] = action;
|
||||
|
||||
return (oldact);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------*
|
||||
|
||||
Name gsignal - implements software signals
|
||||
|
||||
Usage int gsignal(int sig);
|
||||
|
||||
Prototype in signal.h
|
||||
|
||||
Description see ssignal above
|
||||
|
||||
*---------------------------------------------------------------------*/
|
||||
int gsignal(register int sig)
|
||||
{
|
||||
int (*action)(int);
|
||||
|
||||
if (sig < 1 || sig > 15)
|
||||
return (0);
|
||||
#pragma warn -sus
|
||||
action = Sigtbl[sig];
|
||||
if (action == SIG_IGN)
|
||||
return (1);
|
||||
if (action == SIG_DFL)
|
||||
return (0);
|
||||
Sigtbl[sig] = SIG_DFL;
|
||||
#pragma warn .sus
|
||||
return ((*action)(sig));
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user