Wednesday, 8 July 2015

modier in programming and references in c

18.2 Modified Files
BUF.C
Altered so that It uses malloc() instead of sbrk().
CLEANUP.C
Altered so that compiled code supports I/O redirection OK.
Alt C Alt C
Alt C
18-1 C Tutorial HiTech C updates
CLOSE.C
Now prevents trhe inherited descriptors for standard in, standard out, and standard error from
being closed. These are closed by 1616/OS.
GETARGS.C
Altered so that it uses malloc() instead of sbrk().
MAKE
An excellent public domain make program, which ported very easily. Source code and
(microscopic) documentation are in the Applix Utility Disk #2.
MALLOC.C
Altered to use the getmem system call, rather than sbrk(), and all of its own memory management
stuff.
MRD_CRTAPP.AS
This is the normal runtime startup code hacked about so that it does not clear the BBS on entry
to the code. Use this only for memory resident drivers (MRD) written in C. If the normal startup
code is used, the MRD’s global storage will get zapped every time the MRD is called by the
callmrd system call. Specify -jmrd_crtapp.obj on the command line to fix this. Never
use this except when doing an MRD.
NEW_CRTAPP.AS
The runtime code fiddled for normal C programs. It used to leave the environment pointer as
a nil pointer. But getenv() expects it to point to a nil pointer if there is no environment table.
SBRK.AS
The sbrk() function attempts to allocate more storage beyond the end of the program’s BBS
segment. Under the 1616’s memory system, this will tramp on reserved memory., causing
ear-splitting crashes. The modified version here asks the system for the memory before using
it. If the code is an .xrel file, then the memory will inevitably be unavailable. If you cannot
rework a program to use malloc() instread of sbrk(), the code will only run as an .exec file at
$4000, from which it can grow its memory upwards.
SYSCALLS.H
This is a header file which $defines every 1616/OS syscall in upper case, with the same usage
and argument order as in the Programmers Manual Andrew also wrote. Note that the printf(),
sprintf(), and fprintf() calls use a trick which enables them to bypass the normal system call
mechanism, so that they may be used with any number of arguments. They work with I/O
redirection also. You must use STDERR and STDOUT with fprintf(), not stderr and stdout.
Also any file I/O is a bit hairy; do not mix C’s file descriptors, reads, writes, etc., with the
systems’ native ones.
TOUPPER.AS
TOLOWER.AS
Obviously a bad day when these were written. The comparisons were gruesomely wrong. I
fixed them up. Watch out for the #define’d toupper() and tolower() in ctype.h. They do
not check that the char is in range before performing the addition or subtraction. They are a

No comments:

Post a Comment