%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Plain-Tex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%
%% lib-card.tex -- Reference Card for Atari ST GNU C Library Functions
%% SCCS Status     : %W%        %G%
%% Author          : Frank Ridderbusch Tel. 4685
%% Created On      : Mon Mar 12 10:55:38 1990
%% Last Modified By: Frank Ridderbusch Tel. 4685
%% Last Modified On: Wed May  2 22:52:00 1990
%% Update Count    : 93
%% Status          : This is, what I consider the final version.
%% HISTORY 
%%  2-May-1990		Frank Ridderbusch
%%    Fiddling with the format and insertation of sysvars
%%  1-May-1990		Frank Ridderbusch
%%    Inserting remarks about fgets and gets concerning the NL character.
%% 29-Apr-1990		Frank Ridderbusch
%%    Including the vt52 escape sequences
%% 24-Apr-1990		Jwahar R. Bammi
%%    Corrections & additional functions (linea, lstat, profiling, etc)
%% 11-Mar-1990          Frank Ridderbusch Tel. 4685     
%%    Starting point. Creating macros \func. \lfunc and \expl.
%% COMMENTS
%%    I modified the original format to produce headlines, which show
%%    the current section. I did that with only a limited knowledge of
%%    TeX. So, if anyone can suggest ways, to do it better, just let
%%    me know. Also the modifications only work for the 2 column
%%    format. At the moment I'm about 95% happy with the overall
%%    format. Perhaps someone can show me a better layout.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Reference Card for GNU C Library on the Atari ST
%**start of header
\newcount\columnsperpage

% This file can be printed with 1, 2, or 3 columns per page (see below).
% Specify how many you want here.  Nothing else needs to be changed.

\columnsperpage=2

% Copyright (c) 1987 Free Software Foundation, Inc.

% This file is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY.  No author or distributor
% accepts responsibility to anyone for the consequences of using it
% or for whether it serves any particular purpose or describes
% any piece of software unless they say so in writing.  Refer to the
% GNU Emacs General Public License for full details.
%
% Permission is granted to copy, modify and redistribute this source
% file provided the copyright notice and permission notices are
% preserved on all copies.
%
% Permission is granted to process this file through TeX and print the
% results, provided the printed document carries copyright and
% permission notices identical to the ones below.

% This file is intended to be processed by plain TeX (TeX82).
%
% The final reference card has six columns, three on each side.
% This file can be used to produce it in any of three ways:
% 1 column per page
%    produces six separate pages, each of which needs to be reduced to 80%.
%    This gives the best resolution.
% 2 columns per page
%    produces three already-reduced pages.
%    You will still need to cut and paste.
% 3 columns per page
%    produces two pages which must be printed sideways to make a
%    ready-to-use 8.5 x 11 inch reference card.
%    For this you need a dvi device driver that can print sideways.
% Which mode to use is controlled by setting \columnsperpage above.
%
% Author:
%  Stephen Gildea
%  UUCP: mit-erl!gildea
%  Internet: gildea@erl.mit.edu
%
% Thanks to Paul Rubin, Bob Chassell, Len Tower, and Richard Mlynarik
% for their many good ideas.
%
% Modified for the Atari ST GNU C Library
%  Frank Ridderbusch
%  UUCP: !USA ...!unido!nixpbe!ridderbusch.pad
%         USA ...!philabs!linus!nixbur!ridderbusch.pad
%  Snail:
%	 Sander Str. 17
%	 D-4970 Paderborn, Federal Republic of Germany

\def\versionnumber{1.1}
\def\year{1990}
\def\version{May \year\ v\versionnumber}

\def\shortcopyrightnotice{\vskip 1ex plus 2 fill
  \centerline{\small \copyright\ \year\ Free Software Foundation, Inc.
  Permissions on back.  v\versionnumber}}

\def\copyrightnotice{
\vskip 1ex plus 2 fill\begingroup\small
\centerline{Copyright \copyright\ \year\ Free Software Foundation, Inc.}
\centerline{originally designed by Stephen Gildea}
\centerline{modified for Atari ST GNU C Library by Frank Ridderbusch}

Permission is granted to make and distribute copies of
this card provided the copyright notice and this permission notice
are preserved on all copies.

\endgroup}

% make \bye not \outer so that the \def\bye in the \else clause below
% can be scanned without complaint.
\def\bye{\par\vfill\supereject\end}

\newdimen\intercolumnskip
\newbox\columna
\newbox\columnb

\newbox\rightcolhead
\newbox\leftcolhead

\newif\ifusefirstmark
\usefirstmarktrue

\def\ncolumns{\the\columnsperpage}

\message{[\ncolumns\space
  column\if 1\ncolumns\else s\fi\space per page]}

\def\scaledmag#1{ scaled \magstep #1}

% This multi-way format was designed by Stephen Gildea
% October 1986.
\if 1\ncolumns
  \hsize 4in
  \vsize 10in
  \voffset -.7in
  \font\titlefont=\fontname\tenbf \scaledmag3
  \font\headingfont=\fontname\tenbf \scaledmag2
  \font\smallfont=\fontname\sevenrm
  \font\smallsy=\fontname\sevensy

  \footline{\hss\folio}
  \def\makefootline{\baselineskip10pt\hsize6.5in\line{\the\footline}}
\else
  \hsize 3.2in
  \vsize 7.95in
  \hoffset -.75in
  %\voffset -.745in
  \font\titlefont=cmbx10 \scaledmag2
  \font\headingfont=cmbx10 \scaledmag1
  \font\smallfont=cmr6
  \font\smallsy=cmsy6
  \font\eightrm=cmr8
  \font\eightbf=cmbx8
  \font\eightsl=cmsl8
  \font\eightit=cmti8
  \font\eighttt=cmtt8
  \font\eightsy=cmsy8
  \textfont0=\eightrm
  \textfont2=\eightsy
  \def\rm{\eightrm}
  \def\sl{\eightsl}
  \def\bf{\eightbf}
  \def\it{\eightit}
  \def\tt{\eighttt}
  \normalbaselineskip=.8\normalbaselineskip
  \normallineskip=.8\normallineskip
  \normallineskiplimit=.8\normallineskiplimit
  \normalbaselines\rm           %make definitions take effect

  % decrease height of strut
  \setbox\strutbox=\hbox{\vrule height6.5pt depth2.5pt width0pt}

  \if 2\ncolumns
    \let\maxcolumn=b
    \headline{\rm\box\leftcolhead\hss\box\rightcolhead}
    \footline{\hss\rm\folio\hss}
    \def\makefootline{\vskip 2in \hsize=6.86in\line{\the\footline}}
    \def\makeheadline{\hsize=6.86in\line{\the\headline}}
    \nopagenumbers
  \else \if 3\ncolumns
    \let\maxcolumn=c
    \nopagenumbers
  \else
    \errhelp{You must set \columnsperpage equal to 1, 2, or 3.}
    \errmessage{Illegal number of columns per page}
  \fi\fi

  \intercolumnskip=.46in
  \def\abc{a}
  \output={%
      % This next line is useful when designing the layout.
      % \immediate\write16{Column \folio\abc\space starts with \firstmark}
      \if \maxcolumn\abc
	\global\setbox\rightcolhead\vbox{
	  \hbox to \hsize{\strut\hss\ifusefirstmark\firstmark%
	    \global\usefirstmarkfalse\else\topmark\fi\hss}
	  \vskip 2pt \hrule\vskip 3pt}
	\multicolumnformat \global\def\abc{a}
      \else\if a\abc
        \global\setbox\columna\columnbox \global\def\abc{b}
	\global\setbox\leftcolhead\vbox{
	  \hbox to \hsize{\strut\hss\ifusefirstmark\firstmark
	      \global\usefirstmarkfalse\else\topmark\fi\hss}
            \vskip 2pt \hrule\vskip 3pt}
        %% in case we never use \columnb (two-column mode)
        \global\setbox\columnb\hbox to -\intercolumnskip{}
      \else
        \global\setbox\columnb\columnbox \global\def\abc{c}\fi\fi}
  \def\multicolumnformat{\shipout\vbox{\makeheadline
      \hbox{\box\columna\hskip\intercolumnskip
        \box\columnb\hskip\intercolumnskip\columnbox}
      \makefootline}\advancepageno}
  \def\columnbox{\leftline{\pagebody}}

  \def\bye{\par\vfill\supereject
    \if a\abc \else\null\vfill\eject\fi
    \if a\abc \else\null\vfill\eject\fi
    \end}
\fi

% we won't be using math mode much, so redefine some of the characters
% we might want to talk about
\catcode`\^=12
\catcode`\_=12

%\chardef\\=`\\
\chardef\{=`\{
\chardef\}=`\}

\parindent 0pt
\parskip 1ex plus .5ex minus .5ex

\def\small{\smallfont\textfont2=\smallsy\baselineskip=.8\baselineskip}

\outer\def\newcolumn{\vfill\eject\usefirstmarktrue}

\outer\def\title#1{{\titlefont\centerline{#1}}\vskip 1ex plus .5ex}

\outer\def\section#1{\mark{#1}\par\goodbreak%\filbreak
  \vskip 3ex plus 2ex minus 2ex {\headingfont #1}%\mark{#1}%
  \vskip 2ex plus 1ex minus 1.5ex}

\newdimen\keyindent

\newdimen\myindent
\myindent=.10\hsize

\def\beginindentedkeys{\keyindent=\myindent}
\def\endindentedkeys{\keyindent=0em}
\endindentedkeys

\def\paralign{\vskip\parskip\halign}

\def\<#1>{$\langle${\rm #1}$\rangle$}

\def\kbd#1{{\tt#1}\null}        %\null so not an abbrev even if period follows

\def\beginexample{\par\leavevmode\begingroup
  \obeylines\obeyspaces\parskip0pt\tt}
{\obeyspaces\global\let =\ }
\def\endexample{\endgroup}

\def\key#1#2{\leavevmode\hbox to \hsize{\vtop
  {\hsize=.75\hsize\rightskip=1em
  \hskip\keyindent\relax#1}\kbd{#2}\hfil}}

\def\expl#1{\leavevmode\baselineskip=.80\baselineskip\tolerance=2000
  \hbox to \hsize{\hskip\myindent\vtop
  {\advance\hsize by -\myindent\relax#1}\hfil}\goodbreak}

\newbox\metaxbox
\setbox\metaxbox\hbox{\kbd{M-x }}
\newdimen\metaxwidth
\metaxwidth=\wd\metaxbox

\def\metax#1#2{\leavevmode\hbox to \hsize{\hbox to .75\hsize
  {\hskip\keyindent\relax#1\hfil}%
  \hskip -\metaxwidth minus 1fil
  \kbd{#2}\hfil}}

\def\twocol#1#2{\hskip\keyindent\relax#1&#2\cr}
% two column table element with vrule
\def\twocolrule#1#2{#1&&#2\cr}

\def\threecol#1#2#3{\hskip\keyindent\relax#1&#2&#3\cr}
% three column table element with vrule
\def\threecolrule#1#2#3{#1&&#2&&#3\cr}

\def\comma{,~}

%function
\def\func#1 #2(#3);{\leavevmode\hbox to \hsize{%
  {\sl #1}\enskip{\bf #2} (\enskip{\sl #3}\enskip);\null\hfill}}
%function with a large definition
\def\lfunc#1 #2(#3,#4);{\paralign{##\enskip &##\hfil\cr
  {\sl #1}\enskip\relax{\bf #2} (&{\sl #3},\cr
  \hfil & {\sl #4}\enskip);\cr\noalign{\vskip -\parskip}}}


%**end of header

\title{Tos--GNU C Library Functions}

This reference card describes the available library functions of GNU C
on the Atari ST.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Standard I/O}

\#include \<stdio.h>

\lfunc FILE *fopen(const char *fname, const char *mode);
\expl{Open file {\sl fname} with mode {\sl mode} for stream I/O.}

\lfunc FILE *freopen(const char *fname, const char *mode, FILE *fp);
\expl{Reopen {\sl fp} with file {\sl fname} and mode {\sl mode}.}

\func FILE *fdopen(int fd, const char *mode);
\expl{Connect a filepointer to the filedescriptor {\sl fd} with mode
{\sl mode}.}

\func int fgetc(FILE *fp);
\expl{Get a character from stream {\sl fp}.}

\func char *fgets(char *buf, int max, FILE *fp);
\expl{Get a string including the NL character from stream {\sl fp}
with {\sl max} byte into {\sl buf}.}

\func char *gets(char *buf);
\expl{Get a string from \<stdin> into {\sl buf}. The NL character is 
discarded.}

\func int fputc(int c, FILE *fp);
\expl{Write a character {\sl c} into stream {\sl fp}.}

\func int fputs(const char *buf, FILE *fp);
\expl{Write the string in {\sl buf} into stream {\sl fp}.}

\func int puts(const char *buf);
\expl{Write the string in {\sl buf} to \<stdout> appending a NL 
character.}

\func int fungetc(int c, FILE *fp);
\expl{Push the character {\sl c} back onto stream {\sl fp}.}

{\leftskip=\myindent The following aliases for the above functions are
defined.\par}

\beginindentedkeys
\paralign to \hsize{#\tabskip=10pt plus 1 fil\hfil&#\hfil\cr
  \twocol{getc}{fgetc}
  \twocol{ungetc}{fungetc}
  \twocol{putc}{fputc}
  \twocol{getchar()}{fgetc(stdin)}
  \twocol{ungetchar(c)}{fungetc((c),stdin)}
  \twocol{putchar(c)}{fputc((c),stdout)}
}\endindentedkeys

\func long getl(FILE *fp);
\expl{Read a long value from stream {\sl fp}.}

\func long putl(long c, FILE *fp);
\expl{Output the long value {\sl c} into the stream {\sl fp}.}

\func short getw(FILE *fp);
\expl{Read a short value from stream {\sl fp}.}

\func short putw(short c, FILE *fp);
\expl{Output the short value {\sl c} into the stream {\sl fp}.}

\lfunc size\_t fread(void *buf, size\_t sz, size\_t no, FILE *fp);
\expl{Read {\sl no} items of size {\sl sz} from stream {\sl fp} into 
{\sl buf}.}

\lfunc size\_t fwrite(const void *buf, size\_t size, size\_t no , FILE *fp);
\expl{Write {\sl no} items of size {\sl sz} from {\sl buf} into stream
{\sl fp}.}

\func int fgetpos(FILE *fp, fpos\_t *ptr);
\expl{Put the current position of the filepointer of stream {\sl fp}
into the address {\sl ptr}.}

\func int fsetpos(FILE *fp, fpos\_t *ptr);
\expl{Set the position of the filepointer of stream {\sl fp} to the
value at address {\sl ptr}.}

\func int fflush(FILE *fp);
\expl{Write data from internal buffer of stream {\sl fp} to the file.}

\func int fclose(FILE *fp);
\expl{Close the stream {\sl fp}.}

\func int printf(const char *fmt, $\ldots$);
\func int fprintf(FILE *fp, const char *fmt, $\ldots$);
\func int sprintf(char *buf, const char *fmt, $\ldots$);
\func int vprintf(const char *fmt, char *);
\func int vfprintf(FILE *fp, const char *fmt, char *);
\func int vsprintf(char *buf, const char *fmt, char *);
\expl{Formated output to either \<stdout>, {\sl fp} or {\sl buf} with fixed 
or variable number of arguments.}

\func int scanf(const char *fmt, $\ldots$);
\func int fscanf(FILE *fp, const char *fmt, $\ldots$);
\func int sscanf(const char *buf, const char *fmt, $\ldots$);
\expl{Formated input from either \<stdin>, {\sl fp} or {\sl buf}.}

{\leftskip=\myindent The following table lists the identifying letters of
the {\sl fmt} string.\par}

\beginindentedkeys
\hskip\keyindent\relax
\vbox{\offinterlineskip
  \paralign{\strut\quad#\hfil\quad&\vrule#&
                  \quad#\hfil\quad&\vrule#&\quad#\hfil\cr
    \threecolrule{scanf}{printf}{Meaning}
    \noalign{\hrule}
    \threecolrule{d}{d,i}{Decimal number}
    \threecolrule{o}{o}{Octal number}
    \threecolrule{x}{x,X}{Hexadecimal number}
    \threecolrule{u}{u}{Unsigned decimal n.}
    \threecolrule{b}{\omit}{Unsigned binary int.}
    \threecolrule{i}{\omit}{Any base num.}
    \threecolrule{D}{D}{Long Decimal number}
    \threecolrule{O}{O}{Long Octal number}
    \threecolrule{U}{U}{Unsigned long decimal}
    \threecolrule{X}{\omit}{Long Hexadecimal}
    \threecolrule{ld,lo,lx}{ld,li,lo,lx,lX}{Long $\ldots$ number}
    \threecolrule{lb}{\omit}{Unsigned binary long}
    \threecolrule{li}{\omit}{Any base num. long}
    \threecolrule{hd,ho,hx}{d,o,x,X}{Short $\ldots$ number}
    \threecolrule{c}{c}{Character}
    \threecolrule{s}{s}{String}
    \threecolrule{\omit}{p}{Pointer}
    \threecolrule{[$\ldots$]}{\omit}{Str. consist. of char.}
    \threecolrule{e,f,g}{f}{Fixed-point number}
    \threecolrule{e,f,g}{e,E}{Floating-point number}
    \threecolrule{le,lf,lg}{\omit}{Double prec. $\ldots$ n.}
    \threecolrule{E,F,G}{\omit}{Double prec. $\ldots$ n.}
    \threecolrule{Le,Lf,Lg}{Le,LE,Lf}{Long Double $\ldots$ n.}
    \threecolrule{\omit}{g,G,Lg,LG}{e/E or f - shortest used}
    \noalign{\smallskip}
  }
}\endindentedkeys

\func int fseek(FILE *fp, long pos, int whence);
\expl{Move the the filepointer from stream {\sl fp} to position {\sl pos}
relative to {\sl whence}.}

\func long ftell(FILE *fp);
\expl{Get the current position of the filepointer from stream {\sl fp}.}

\func void rewind(FILE *fp);
\expl{Reset the filepointer from stream {\sl fp} to position 0.}

\func FILE *popen(const char *command, const char *mode);
\expl{Open a pipe with {\sl mode} to {\sl command}. (Faked by temporary
files)}

\func int pclose(FILE *fp);
\expl{Close the stream created by {\bf popen()}.}

\func void setbuf(FILE *fp, char *buf);
\expl{Set buffer of stream {\sl fp} to {\sl buf}.}

\func int setvbuf(FILE *fp, char *buf, int mode, size\_t sz);
\expl{Set buffer of stream {\sl fp} to {\sl buf} with size {\sl sz} and
mode {\sl mode}.}

\func void \_binmode(int bool);
\expl{Set default open mode to binary (bool = true) or text.}

\func int remove(const char *fname);
\expl{Remove file with name {\sl fname}.}

\func int rename(const char *old, const char *new);
\expl{Change name of file from {\sl old} to {\sl new}.}

\func char *tmpnam(char *buf);
\expl{Create a string for a temporary filename.}

\func FILE *tmpfile(void);
\expl{Create a temporary file. File is deleted on normal termination.}

\func void perror(const char *str);
\expl{Display error message starting with {\sl str} depending on {\sl errno}.}

The following functions are defined as macros.

\func void clearerr(FILE *fp);
\expl{Clear error and EOF status of stream {\sl fp}.}

\func int feof(FILE *fp);
\expl{Test EOF status of stream {\sl fp}.}

\func int ferror(FILE *fp);
\expl{Test error status of stream {\sl fp}.}

\func int fileno(FILE *fp);
\expl{Get filedescriptor of stream {\sl fp}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{I/O Control}

\#include \<ioctl.h>

\func int ioctl(int fd, int cmd, void *arg);
\expl{Set or inquire i/o dependend parameter.}

\func int stty(int fd, struct sgttyb *\_tty);
\func int gtty(int fd, struct sgttyb *\_tty);
\expl{Set or inquire i/o parameters for descriptor {\sl fd}.}
\medskip
\#include \<fcntl.h>

\func int fcntl(int fd, int cmd, void *arg);
\expl{Set or inquire file i/o dependend parameter.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Memory Management}

\#include \<stdlib.h>

\func void *calloc(size\_t no, size\_t sz);
\func void *clalloc(long no, long sz);
\expl{Allocate and initialize memory for {\sl no} items of size {\sl size}.}

\func void *malloc(size\_t sz);
\func void *mlalloc(long sz);
\expl{Allocate {\sl sz} bytes of memory.}

\func void *realloc(void *ptr, size\_t sz);
\func void *relalloc(void *ptr, long sz);
\expl{Resize memory pointed to by {\sl ptr} to size {\sl sz}.}

\func void free(void *ptr);
\expl{Free memory obtained by {\bf calloc}, {\bf malloc} or {\bf realloc}.}

\func void *alloca(size\_t sz);
\expl{Allocate {\sl sz} bytes from the current function stack.}

\func void \_malloczero(int bool);
\expl{Zero allocated memory blocks. Default==false.}

\func void \_mallocChunkSize(size\_t Siz);
\expl{Get memory from OS in atleast {\sl Siz} sized blocks. Default==4K}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Character Classification and Conversion}

The following functions return $\ne$ 0, if character {\sl c} belongs
to the specified character set; 0 otherwise.

\#include \<ctype.h>

\paralign{{\bf #}({\sl c})\hfil\quad&#\hfil\cr
  \omit\rm function\hfil\quad&set\cr\noalign{\vskip 3pt}
  \twocol{isalnum}{Letter or Digit}
  \twocol{isalpha}{Letter}
  \twocol{isascii}{ASCII character (Codes: 0$\ldots$0177)}
  \twocol{iscntrl}{Control character (Codes: 0$\ldots$037, 0177)}
  \twocol{isdigit}{Digit}
  \twocol{isgraph}{Printable character except space}
  \twocol{islower}{Lowercase letter}
  \twocol{isprint}{Printable character}
  \twocol{ispunct}{Punctuation char. (not letter, digit or control)}
  \twocol{isspace}{Space, Tab, CR, NL, VT, FF or BS}
  \twocol{isupper}{Uppercase letter}
  \twocol{isxdigit}{Hexadecimal digit}
  \twocol{iswhite}{same as ispace()}
  \twocol{isodigit}{Octal digit}
  \twocol{iscymf}{Character starting a C identifier}
  \twocol{iscym}{Characters continuing a C identifier}
}

Character conversion functions

\paralign{{\bf #}({\sl c})\hfil\quad&#\hfil\cr
  \omit\rm function\hfil\quad&Meaning\cr\noalign{\vskip 3pt}
  \twocol{toupper}{Convert to uppercase letter}
  \twocol{\_toupper}{Convert to uppercase letter (macro)}
  \twocol{tolower}{Convert to lowercase letter}
  \twocol{\_tolower}{Convert to lowercase letter (macro)}
  \twocol{toint}{Convert digit to integer}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{String Handling}

\#include \<string.h>

\func char *strcpy(char *dst, const char *src);
\expl{Copy string at {\sl src} to {\sl dst}.}

\func char *strncpy(char *dst, const char *src, size\_t no);
\expl{Copy string at {\sl src} to {\sl dst}, but at most {sl no} character.}

\func char *strcat(char *dst, const char *src);
\expl{Concatenate the string at {\sl src} to the string at {\sl dst}.}

\func char *strncat(char *dst, const char *src, size\_t no);
\expl{Concatenate the string at {\sl src} to the string at {\sl dst}, but copy
at most {\sl no} character.}

\func int strcmp(const char *str1, const char *str2);
\expl{Compare string {\sl str1} with string {\sl str1}.}

\func int strncmp(const char *str1, const char *str2, size\_t no);
\expl{Compare string {\sl str1} with string {\sl str1}, but compare at most
{\sl no} character.}

\func char *strchr(const char *str, int charw);
\expl{Find first occurence of character {\sl charw} in string {\sl str}.}

\func char *strrchr(const char *str, int charw);
\expl{Find last occurence of character {\sl charw} in string {\sl str}.}

\func size\_t strcspn(const char *str, const char *rej);
\expl{Find length of initial segment of {\sl str} consisting entirely
of characters not from {\sl rej}.}

\func char *strpbrk(const char *str, const char *breakat);
\expl{First occurrence of a character from string {\sl breakat} in string
{\sl str}.}

\func size\_t strspn(const char *str, const char *accept);
\expl{Find length of initial segment of {\sl str} consisting entirely
of characters from {\sl accept}.}

\func char *strstr(const char *str, const char *wanted);
\expl{Find first occurence of string {\sl wanted} in string {\sl
str}.} 

\func char *strtok(char *str, const char *delim);
\expl{Retrieve fields from string {\sl str}, that are delimited by
characters from string {\sl delim}.}

\func size\_t strlen(const char *str);
\expl{Return length of string {\sl str}.}

\func char *strerror(int errno);
\expl{Map error number {\sl errno} to descriptive string.}

\func char *strlwr(char *str);
\expl{Change all character from string {\sl str} to lowercase.}

\func char *strrev(char *str);
\expl{Reverse all charcters in string {\sl str}. First character
becomes last character.}

\func char *strdup(const char *str);
\expl{Return a duplicate of string {\sl str}.}

\lfunc int memcmp(const void *ptr1, const void *ptr2, size\_t no);
\expl{Compare {\sl no} bytes from memory area at {\sl ptr1} with area
at {\sl ptr2}.}

\func void *memset(void *ptr, int ucharfill, size\_t no);
\expl{Set {\sl no} of bytes at position {\sl ptr} to character {\sl
ucharfill}.}

\lfunc void *memchr(const void *ptr, int ucharwanted, size\_t no);
\expl{Find character {\sl ucharwanted} in area at {\sl ptr}, but
compare at most {\sl no} character.}

\func void *memcpy(void *dst, const void *src, size\_t no);
\expl{Copy {\sl no} of bytes from area at {\sl src} to {\sl dst}.}

\lfunc void *memccpy(void *dst, const void *src, int ucharstop, size\_t no);
\expl{Copy characters from {\sl src} to {\sl dst} until character {\sl
uchar\-stop}, but copy at most {\sl no} bytes.}

\func char *index(const char *str, int charw);
\expl{Same as {\bf strchr}.}

\func char *rindex(const char *str, int charw);
\expl{Same as {\bf strrchr}.}

\func void bcopy(const void *src, void *dst, size\_t len);
\expl{Copy {\sl len} bytes from position {\sl src} to {\sl dst}.}

\func int bcmp(const void *ptr1, const void *ptr2, size\_t no);
\expl{Compare {\sl no} of bytes at position {\sl ptr1} with {\sl ptr2}.}

\func void bzero(void *dst, size\_t len);
\expl{Set {\sl len} bytes at position {\sl dst} to 0.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Process Management}

\#include \<stdlib.h>

\func int system(const char *prog);
\expl{Execute command {\sl prog} passed as a string.}
\medskip
\#include \<process.h>

\func int spawnl(int mode, char *path, $\ldots$);
\func int spawnv(int mode, char *path, char **argv);
\func int spawnle(int mode, char *path, $\ldots$);
\lfunc int spawnve(int mode\comma char *path, char **argv, char **envp);
\expl{Spawn a new process. (Only {\tt P\_WAIT} is allowed for {\sl
mode}).}

\func int spawnvp(int mode, char *name, char **argv);
\func int spawnlp(int mode, char *name, $\ldots$);
\expl{Execute a program on the defautl system execution path. (The
current directory is always searched first.)}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Date and Time}

\#include \<time.h>

\func clock\_t clock();
\expl{Return process time used so far in units of CLK\_TCK ticks per
second (under TOS, 200 per second).}

\func double difftime(time\_t t1, time\_t t2);
\expl{Return difference between two ``time\_t'' types.}

\func time\_t mktime(const struct tm *t);
\expl{Take a time structure and convert it into representation ``seconds
since midnight January 1 1970, GMT''.}

\func time\_t time(time\_t *t);
\expl{Return time in seconds since midnight January 1 1970, GMT.}

\func char *asctime(const struct tm *t);
\expl{Convert ``time'' structure to a string.}

\func char *ctime(const time\_t *t);
\expl{Convert time in seconds since 1970 to a string.}

\func struct~tm *gmtime(const time\_t *t);
\expl{Get the Greenwich Mean time.}

\func struct~tm *localtime(const time\_t *t);
\expl{Convert given time in seconds since 1970 to local time.}

\lfunc size\_t strftime(char *s\comma size\_t maxsize\comma const char *format,
const struct tm *timeptr);
\expl{Print formatted information about a given time.}

\func void tzset();
\expl{Set the timezone and dst flag to the local rules (depending on
environment variable ``TZ'').}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{File and Directory Information}

\#include \<types.h>\par
\#include \<stat.h>

\func int  stat(const char *fname, struct stat *info);
\expl{Obtain information about file {\sl fname}.}

\func int  lstat(const char *fname, struct stat *info);
\expl{Like {\sl stat} but return info about {\sl symbolic links}.}

\func int  fstat(int fd, struct stat *info);
\expl{Obtain information about file assosiated with filedescriptor {\sl fd}.}
\medskip
\#include \<dirent.h>

\func DIR *opendir(const char *dirname);
\expl{Open directory {\sl dirname} for reading.}

\func struct~dirent *readdir(DIR *dirp);
\expl{Read an entry from directory assosiated with {\sl dirp}.}

\func off\_t telldir(DIR *dirp);
\expl{Get the current position in directory assosiated with {\sl
dirp}.} 

\func void seekdir(DIR *dirp, off\_t loc);
\expl{Seek to position {\sl loc} in the directory assosiated with {\sl
dirp}.}

\func void rewinddir(DIR *dirp);
\expl{Seek to the beginning of directory assosiated with {\sl dirp}.}

\func int closedir(DIR *dirp);
\expl{Close directory assosiated with {\sl dirp}.}

\func int ftw(char *path, int (*fn )(), int param);
\expl{Recursively walk tree rooted at {\sl path} applying function {\sl fn}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{U*IX Compatibility Routines}

\#include \<unixlib.h>

\func void \_exit(int ret);
\expl{Exit the current process without cleaning up. (This is a {\bf
Pterm()})}

\func int access(const char *fname, int mode);
\expl{Check, if file {\sl fname} is accessable with mode {\sl mode}.}

\func int chdir(const char *dname);
\expl{Chane the current working directory to {\sl dname} including drive
specification.}

\func int chmod(const char *fname, int mode);
\expl{Change permissions of file {\sl fname} to {\sl mode}.}

\func int chown(const char *fname, int uid, int gid);
\expl{Change owner and group of file {\sl fname}. (Fake for now)}

\func int close(int fd);
\expl{Close the file assosiated with file descriptor {\sl fd}.}

\func int creat(const char *fname, unsigned mode);
\expl{Create the file {\sl fname} with mode {\sl mode}.}

\func int dup(int fd);
\expl{Duplicate filedescriptor {\sl fd}.}

\func int dup2(int fd1, int fd2);
\expl{Duplicate filedescriptor {\sl fd1} to {\sl fd2}.}

\func int execve(char *path, char **argv, char **envp);
\func int execv(char *path, char **argv);
\expl{Execute a new process from {\sl path} after a {\sl fork()}.}

\func int fork();
\func int vfork();
\expl{Simulate a non mul\-ti\-task\-ing fork. {\sl vfork} shares
data + stack with parent.}

\func char *getcwd(char *buf, int size);
\func char *getwd(char *buf);
\expl{Get the current working directory.}

\func int getgid();
\func int getuid();
\expl{Get user and group id's. (Fake for now, returning alsways
root).} 

\func int getegid();
\func int geteuid();
\expl{Get effective user and group id's.}

\func char *getlogin();
\expl{Return the user's login name. (Password file and environment are
seached in order).}

\func int getopt(int argc, const char **argv, const char *opt);
\expl{Extract the command line options described by {\sl opt} from
{\sl argv}.}

\func int getpgrp();
\func int setpgrp();
\expl{Get or create a process group (This basically a fake; both
return {\bf getpid()}).}

\func int getpid();
\expl{Return a process id for the currently running process (from the
basepage).} 

\func int isatty(int fd);
\expl{Check, if {\sl fd} is associated with a terminal (screen).}

\func int kill(int, int);

\func int link(const char *old , const char *new);
\expl{Make a new link from {\sl new} to {\sl old}. Always fails.}

\func int symlink(char *old , char *new);
\expl{Make a new symbolic link from {\sl new} to {\sl old}.
Env. UNIXMODE determines behavior.}

\func int readlink(char *fname , char *buf, int siz);
\expl{Read the link for {\sl fname} into {\sl buf}.}

\func long lseek(int fd, long pos, int whence);
\expl{Set the current file posistion to position {\sl pos} relative to
{\sl whence}.}

\func int mkdir(const char *dname);
\expl{Make a directory with name {\sl dname}.}

\func char *mktemp(char *pattern);
\expl{Return a filename for a temporary file, build after {\sl
pattern}.}

\func int open(const char *fname, int mode, $\ldots$);
\expl{Open the file {\sl fname} with mode {\sl mode}.}

\func void psignal(int signal, const char *prefix);
\expl{Print a error message describing the signal with a user
comment.}

\func int rmdir(const char *dname);
\expl{Remove the directory with name {\sl dname}.}

\func int read(int fd, void *buf, int cnt);
\func long lread(int fd, void *buf, long cnt);
\expl{Read {\sl cnt} bytes from file descriptor {\sl fd} into buffer
{\sl buf}.}

\func void *sbrk(size\_t size);
\func void *lsbrk(long size);
\expl{Emulation of the U*ix {\bf sbrk()} system call.}

\func void setlinebuf(FILE *fp);
\expl{Change the buffering on stream {\sl fp} from block/unbuffered to
line buffered.}

\func int setgid(int gid);
\func int setuid(int uid);
\expl{Set the effective user and group id.}

\func void (*{\rm\bf signal}(int signum, void (*func)(int)))(int);
\expl{Make {\sl func} the handler for signal {\sl signum}. Returns
previous setting.}

\func int sleep(int n);
\expl{Sleep for {\sl n} number of seconds.}

\func int stime(long *time);
\expl{Set the current time to {\sl time} in U*ix format.}

\func long tell(int fd);
\expl{Get the current file position of the file associated with {\sl
fd}.}

\func int times(struct tms *buf);
\expl{Get process times into {\sl buf}.}

\func int umask(int mode);
\expl{Set access mask. (Fake for now)}

\func int unlink(const char *fname);
\expl{Remove the file with name {\sl fname}.}

\func int usleep(long n);
\expl{Sleep for {\sl n} number of milliseconds.}

\func int utime(const char *fname, const struct utimbuf *ftime);
\expl{Set the modification time and date of file {\sl fname} to {\sl
ftime}.}

\func int write(int fd, const void *buf, int cnt);
\func long lwrite(int fd, const void *buf, long cnt);
\expl{Write {\sl cnt} bytes from buffer {\sl buf} to file descriptor
{\sl fd}.}

\func int wait(int *exit\_code);
\expl{Wait for child process.}

\newcolumn

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Password and Group Handling}

\#include \<unixlib.h>

\func int endpwent();
\expl{Close password file.}

\func int setpwent();
\expl{Open password file for further operations.}

\func void setpwfile(char *fname);
\expl{Use the {\sl fname} instead of {\tt /etc/passwd} as password
file.}
\medskip
The following routines already use the above functions.

\#include \<pwd.h>

\func struct~passwd *getpwent();
\expl{Return an entry from the password file.}

\func struct~passwd *getpwuid(int uid);
\expl{Return the entry from the password file for {\sl uid}.}

\func struct~passwd *getpwnam(char *user);
\expl{Return the entry from the password file for {\sl user}.}
\medskip
\#include \<grp.h>

\func struct~group *getgrgid(int gid);
\expl{Return the entry from the group file for {\sl gid}. (Mostly fake,
returning root or user as groupnames)}

\func struct~group *getgrnam(char *gname);
\expl{Return the entry from the group file for {\sl gname}. (Mostly
fake, returning root or user as groupnames)}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Value Conversion}

\#include \<stdlib.h>

\func double atof(const char *str);
\expl{Return double value of number presented in {\sl str}.}

\func int atoi(const char *str);
\expl{Return int value of number presented in {\sl str}.}

\func long atol(const char *str);
\expl{Return long value of number presented in {\sl str}.}

\func int abs(int val);
\func long labs(long val);
\expl{Return absolute value of {\sl val}.}

\func long strtol(const char *nptr, char **endptr, int base);
\lfunc unsigned~long strtoul(const char *nptr\comma char **endptr, int base);
\expl{Return the value of the number in {\sl nptr} with {\sl base}
putting the endaddress of the numerical string into {\sl endptr}.}

\func double strtod(const char *nptr, const char **endptr);
\expl{Return the double value of the number in {\sl nptr} putting the
endaddress of the numerical string into {\sl endptr}.}
\medskip
\#include \<support.h>

\func char *\_itoa(int val, char *buf, int radix);
\func char *\_ltoa(long val, char *buf, int radix);
\func char *\_ultoa(unsigned long val, char *buf, int radix);
\expl{Convert the value {\sl val} to a string in {\sl buf}
according to {\sl radix}.} 
\medskip
\#include \<locale.h>

\func struct lconv *localeconv();
\expl{Get rules of the current locale}

\func char *setlocale(int category , const char *name);
\expl{Define locale named in {\sl name}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Miscellaneous}

\#include \<stdlib.h>

\func void abort();
\expl{Immediatly abort the running program.}

\func int atexit(void (*func)());
\expl{Register a function for execution on termination.}

\func void exit(int ret);
\expl{Exit current process with return value {\sl ret}.}

\func div\_t div(int num, int denom);
\func ldiv\_t ldiv(long num, long denom);
\expl{Perform division and return both quotient and remainder.}

\func int rand();
\expl{Return a pseudo random number in the range from 0 to {\tt RAND\_MAX}.}

\func void srand(unsigned int seed);
\expl{Use {\sl seed} to initialize the pseudo-random number generator.}

\func long random();
\expl{Return a pseudo random number in the range from 0 to $2^31$ - 1.}

\func int srandom(unsigned int x);
\expl{Seed generator for {\sl random}.}

\func char *initstate(unsigned seed, char *arg\_state, int n);
\expl {Initialize state array of generator for {\sl random}.}

\func char *setstate(char *arg\_state);
\expl{Switch state of generator for {\sl random}.}

\func char *getenv(const char *name);
\expl{Get the contents of the environment variable {\sl name}.}

%\func void setenv(const char *name);
%\expl{Update or put the variable in {\sl name} into the environment.}

\lfunc void *bsearch(const void *key\comma const void *base,
size\_t num, size\_t size, int (*cmp)()); 
\expl{Binary search a field starting at {\sl base} with {\sl num}
elements each size {\sl size} for {\sl key}.}

\lfunc void qsort(void *base\comma size\_t num, size\_t size, int (*cmp)()); 
\expl{Quick sort an array of {\sl num} elements with size {\sl size}
starting at {\sl base}.}
\medskip
\#include \<support.h>

\func int console\_input\_status(int handle);
\expl{Check, if character is available from standard CON:. (This is
the same as {\bf Cconis})}

\func unsigned~int console\_read\_byte(int handle);
\expl{Raw input from standard CON: without echoing to screen. (This is
the same as {\bf Crawcin})}

\func void console\_write\_byte(int handle, int character);
\expl{Write character {\sl c} to handle {\sl handle}. (This is a {\bf
Fwrite} with count 1)}

\func void dos2unx(const char *t\_fname, char *u\_fname);
\expl{Convert filenames from TOS format to U*ix format.}

\func time\_t dostime(time\_t);
\expl{Convert U*ix time to TOS time and date (lower word = time, upper
word = date).}

\func char *findfile(char *fname, char *path, char **ext);
\expl{Locate the file {\sl fname} along the paths in {\sl path} with
{\sl ext} containing possible extensions.}

\func time\_t unixtime(unsigned tostime, unsigned tosdate);
\expl{Convert a TOS time/date pair into a U*ix time.}

\func void unx2dos(const char *u\_fname, char *t\_fname);
\expl{Convert filenames from U*ix format to TOS format.}

\func void fnmapfunc(fnmapfunc\_t u2dos, fnmapfunc\_t dos2u);
\expl{Set mapping functions for the {\bf unx2dos} and {\bf dos2unx}
routines.}

\func long get\_sysvar(void *var);
\expl{Get the contents of the system variable {\sl var}.}

\func void set\_sysvar\_to\_long(void *var, long val);
\expl{Set the system variable {\sl var} to the long value {\sl val}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Profiling}

also see {\sl gprof.ttp} and {\sl -pg} option to {\sl gcc}

\func void monstartup(void *lpc, void *hpc);
\expl{High level interface to {\sl profil}. {\sl [lpc,hpc]} is the
range to sample. Necessary memory is dynamically allocated.}

\lfunc void monitor(void *lpc\comma void *hpc\comma void *buf,
size\_t bsiz, unsigned int nfunc);
\expl{Low level interface to profil. {\sl buf} is a user supplied
buffer. PC samples over {\sl[lpc,hpc]} and {\sl mcount()} call records
are accumulated in {\sl buf}.}

\func void moncontrol(long flag);
\expl{Selectively control profiling in a program.}

\func int profil(void *buf, size\_t bsiz, size\_t off, int shift);
\expl{Execution time profil. Pc is examined every 20ms, (PC-off)$\gg$ shift
if in range, will increment short in {\sl buf}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{GEMDOS Calls via Trap 1}

\#include \<osbind.h>

The following assignment is valid by default:

\vbox{\offinterlineskip
  \paralign{\strut\quad#\hfil\quad&\vrule#&
                  \quad\hfil#\hfil\quad&\vrule#&\quad#\hfil\quad\cr
    \threecolrule{Device}{handle}{}
    \noalign{\hrule}
    \threecolrule{CON:}{0}{Keyboard}
    \threecolrule{CON:}{1}{Screen}
    \threecolrule{AUX:}{2}{Serial port}
    \threecolrule{PRN:}{3}{Parallel port}
  }
}

\func long Cauxin();
\expl{Read character from standard AUX:.}

\func short Cauxis();
\expl{Check, if character is available from standard AUX:.}

\func short Cauxos();
\expl{Check, if character can be written to standard AUX:.}

\func void Cauxout(short c);
\expl{Write character {\sl c} to standard AUX:.}

\func long Cconin();
\expl{Read a character from standard CON:.}

\func short Cconis();
\expl{Check, if character is available from standard CON:.}

\func short Cconos();
\expl{Check, if character can be written to standard CON:.}

\func void Cconout(short c);
\expl{Write character {\sl c} to standard CON:.}

\func void Cconrs(char *buf);
\expl{Read edited data from standard CON:. {\sl buf[0]} contains number
of characters minus 1 to read.}

\func void Cconws(const char *str);
\expl{Write string {\sl str} to standard CON:.}

\func long Cnecin();
\expl{Raw input from standard CON: without echoing to screen, but
with interpretation of CTRL-S, CRTL-Q and CRTL-C.}

\func short Cprnos();
\expl{Check, if character can be written to standard PRN:.}

\func void Cprnout(short c);
\expl{Write character {\sl c} to standard PRN:.}

\func long Crawcin();
\expl{Raw input from standard CON: without echoing to screen.}

\func long Crawio(short data);
\expl{Raw I/O to standard CON:. If {\sl data} = 0xff read from CON:,
otherwise output to CON:.}

\func short Dcreate(const char *dname);
\expl{Create a directory with name {\sl dname}.}

\func long Ddelete(const char *dname);
\expl{Remove a directory with name {\sl dname}.}

\func long Dfree(DISKINFO *buf, short drv);
\expl{Get available space of drive {\sl drv} into {\sl buf}.
{\sl drv} = 0 means current drive.}

\func short Dgetdrv();
\expl{Get the number of the default drive.}

\func long Dgetpath(void *buf, short drv);
\expl{Get the current directory of drive {\sl drv}.
{\sl drv} = 0 means current drive.}

\func long Dsetdrv(short d);
\expl{Set the number of the default drive.}

\func long Dsetpath(const char *path);
\expl{Set path for current drive to {\sl path}.}

\func short Fattrib(const char *fname, short rwflag, short attr);
\expl{Get ({\sl rwflag} = 0) or set ({\sl rwflag} = 1)
attribute byte of file {\sl fname}.}

\func long Fclose(short handle);
\expl{Close the file assosiated with {\sl handle}.}

\func struct~\_dta *Fgetdta();
\expl{Get the current disk transfer address.}

\func long Fcreate(const char *fname, short mode);
\expl{Create file {\sl fname} with mode {\sl mode}.}

\func long Fdatime(DOSTIME *timeptr, short hdl, short rwflg);
\expl{Get ({\sl rwflag} = 0) or set ({\sl rwflg} = 1) the time
structure of the file associated by handle {\sl hdl}.}

\func long Fdelete(const char *fname);
\expl{Delete file with name {\sl fname}.}

\func long Fdup(short handle);
\expl{Return a second handle for a standard handle (0$\ldots$5).}

\func long Fforce(short Hstd, short Hnew);
\expl{Replace one of the standard handles (0$\ldots$5) with {\sl Hnew}.}

\func long Fopen(const char *fname, short mode);
\expl{Open file {\sl fname} with mode {\sl mode}.}

\func long Fread(short handle, long cnt, void *buf);
\expl{Read {\sl cnt} bytes into {\sl buf} from file assosiated
with {\sl handle}.}

\func short Frename(const char *old, const char *new);
\expl{Change name of file from {\sl old} to {\sl new}. Also directories}

\func long Fseek(long pos, short handle, short whence);
\expl{Set access pointer to position {\sl pos} relative to
{\sl whence}.}

\func void Fsetdta(struct \_dta *ptr);
\expl{Set the current disk tranfer address to {\sl ptr}.}

\func long Fsfirst(const char *filespec, short attr);
\expl{Get first directory slot, which matches {\sl filespec} and {\sl
attr}.}

\func long Fsnext();
\expl{Get next match of search started by {\bf Fsfirst}.}

\func long Fwrite(short handle, long cnt, const void *buf);
\expl{Write {\sl cnt} bytes from {\sl buf} to file assosiated with
{\sl handle}.}

\func long Malloc(long size);
\expl{Allocate {\sl size} bytes of memory.}

\func long Mfree(void *ptr);
\expl{Release block of memory.}

\func long Mshrink(long ptr, long size);
\expl{Shrink size of memory block obtained by {\bf Malloc}.}

\lfunc long Pexec(short mode\comma const char *prog\comma const char
*tail, char **env); 
\expl{Execute {\sl prog} with mode {\sl mode}.}

\func void Pterm(short rv);
\expl{Terminate current process with return value {\sl rv}.}

\func void Pterm0();
\expl{Terminate current and return to calling process.}

\func void Ptermres(long save, short ret);
\expl{Terminate and stay resident, but keep {\sl save} bytes of memory.}

\func long Super(void *stack);
\expl{Inquire ({\sl stack} = 1), set ({\sl stack} = 0) or return from
({\sl stack} $>$ 0) supervisor mode.}

\func short Sversion();
\expl{Get the version number of GEMDOS.}

\func short Tgetdate();
\expl{Get the GEMDOS internal date. The harware clock is read in 
MEGA ST's.}

{\leftskip=\myindent The return value is composed of the following
fields:\par}

\beginindentedkeys
\hskip\keyindent\relax
\vbox{\offinterlineskip
  \paralign{\strut\quad\hfil#\quad&\vrule#&\quad#\hfil\quad\cr
    \twocolrule{Bits}{Meaning (Range)}
    \noalign{\hrule}
    \twocolrule{0$\ldots$4}{Day (0$\ldots$31)}
    \twocolrule{5$\ldots$8}{Month (1$\ldots$12)}
    \twocolrule{9$\ldots$15}{Year (0$\ldots$119)(+1980)}
    \noalign{\smallskip}
  }
}\endindentedkeys
 
\func short Tgettime();
\expl{Get the GEMDOS internal time.}

{\leftskip=\myindent The return value is composed of the following
fields:\par} 

\beginindentedkeys
\hskip\keyindent\relax
\vbox{\offinterlineskip
  \paralign{\strut\quad\hfil#\quad&\vrule#&\quad#\hfil\quad\cr
    \twocolrule{Bits}{Meaning (Range)}
    \noalign{\hrule}
    \twocolrule{0$\ldots$4}{Seconds (0$\ldots$29) have to be doubled}
    \twocolrule{5$\ldots$10}{Minutes (0$\ldots$59)}
    \twocolrule{11$\ldots$15}{Hours (0$\ldots$23)}
    \noalign{\smallskip}
  }
}\endindentedkeys

\func long Tsetdate(short date);
\expl{Set the GEMDOS internal date.}

\func long Tsettime(short time);
\expl{Set the GEMDOS internal time.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{BIOS Calls via Trap 13}

\#include \<osbind.h>

Available devices for BIOS calls are:

\vbox{\offinterlineskip
  \paralign{\strut\quad#\hfil\quad&\vrule#&
                  \quad\hfil#\hfil\quad&\vrule#&\quad#\hfil\quad\cr
    \threecolrule{Device}{\#}{}
    \noalign{\hrule}
    \threecolrule{PRT:}{0}{parallel port}
    \threecolrule{AUX:}{1}{serial port}
    \threecolrule{CON:}{2}{console}
    \threecolrule{MIDI:}{3}{MIDI port}
    \threecolrule{IKBD:}{4}{keyboard processor}
    \threecolrule{RAWCON:}{5}{console (no terminal emulation)}
    \noalign{\smallskip}
  }
}

\func long Bconin(short dev);
\expl{Read a character from device {\sl dev}. (Allowed devices:
0$\ldots$3}

\func void Bconout(short dev, short c);
\expl{Write character {\sl c} to device {\sl dev}. (Allowed 
devices: 0$\ldots$5)}

\func short Bconstat(short dev);
\expl{Get the status of the input device {\sl dev}. (Allowed 
devices: 1$\ldots$3).}

\func short Bcostat(short dev);
\expl{Get the status of the output device {\sl dev}. (Allowed
devices: 0$\ldots$4)}

\func long Drvmap();
\expl{Get the bitmap of available drives.}

\func BPB *Getbpb(short dev);
\expl{Get the BIOS parameter block of device {\sl dev}.}

\func void Getmpb(void *ptr);
\expl{The memory parameter block pointed to by {\sl ptr} is filled.}

\func long Kbshift(short mode);
\expl{Get ({\sl mode} = -1) or set the current keyboard status.}

{\leftskip=\myindent The return value is composed of the following
fields:\par} 

\beginindentedkeys
\hskip\keyindent\relax
\vbox{\offinterlineskip
  \paralign{\strut\quad\hfil#\quad&\vrule#&\quad#\hfil\quad\cr
    \twocolrule{Bit}{Meaning}
    \noalign{\hrule}
    \twocolrule{0}{Right shift key}
    \twocolrule{1}{Left shift key}
    \twocolrule{2}{Control key}
    \twocolrule{3}{Alternate key}
    \twocolrule{4}{Caps lock key}
    \twocolrule{5}{r. mouse buttton (ClrHome)}
    \twocolrule{6}{l. mouse button (Insert)}
    \twocolrule{7}{Reserved (0)}
    \noalign{\smallskip}
  }
}\endindentedkeys

\func short Mediach(short dev);
\expl{Check, if disk in device {\sl dev} has changed.}

\lfunc short Rwabs(short rwflag\comma long buf\comma short n, short
sector, short dev);
\expl{Read ({\sl rwflag} = 0) or write ({\sl rwflag} = 1) {\sl n}
logical sectors from device {\sl dev}.}
 
\func void~(*)() Setexc(short vecnum, long vecptr);
\expl{Get (vecptr = -1) or set an M68000 exception vector.}

\func long Tickcal();
\expl{Get the number of milliseconds between two calls of {\bf tickcal}.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{XBIOS Calls via Trap 14}

\#include \<osbind.h>

\func void Bioskeys();
\expl{Reset to initial keyboard mapping tables.}

\func short Blitmode(short flag);
\expl{Configure the blitter chip.}

\func short Cursconf(short rate, short attr);
\expl{Configure the cursor and blinking speed.}

\func void Dosound(void *ptr);
\expl{Output a number of bytes to the soundchip.}

\lfunc short Floprd(void *buf\comma long filler\comma short drv, short
sect, short trk, short side, short n);
\expl{Read physically {\sl n} sectors from floppy drive {\sl drv}.}

\lfunc short Flopwr(void *buf\comma long filler\comma short drv, short
sect, short trk, short side, short n);
\expl{Write physically {\sl n} sectors to floppy drive {\sl drv}.}

\lfunc short Flopfmt(void *buf\comma long filler\comma short drv\comma short
spt, short trk, short side, short i, long m, short v);
\expl{Format track {\sl trk} on drive {\sl drv} with {\sl spt} sectors
per track.}

\lfunc short Flopver(void *buf\comma long filler\comma short drv\comma short
spt, short trk, short side, short n);
\expl{Read a number of sectors and compare with memory.}

\func short Getrez();
\expl{Get the current display resolution (0 = low, 1 = mid, 2 = high).}

\func long Gettime();
\expl{Get the time from the hardware clock (lower word = time, upper
word = date).}

\func short Giaccess(short data, short reg);
\expl{Get or set a register of the GI sound chip.
Set bit 8 of {\sl reg} for write operation.}

\func void Ikbdws(short cnt, void *ptr);
\expl{Write a sequence of {\sl cnt}+1 bytes to the keyboard processor.}

\func void Initmous(short type, void *param, void *vptr);
\expl{Initialize the mouse cursor routines.}

\func IOREC *Iorec(short ioDEV);
\expl{Get a pointer to a device specific buffer.}

\func void Jdisint(short vnum);
\expl{Disable interrupt {\sl vnum} of the MFP 68901 chip.}

\func void Jenabint(short vnum);
\expl{Enable interrupt {\sl vnum} of the MFP 68901 chip.}

\func KBDVECS *Kbdvbase();
\expl{Get a pointer to the KBDVECS structure.}

\func short Kbrate(short delay, short reprate);
\expl{Get or set keyboard repeat rate.}

\func KEYTAB *Keytbl(void *nrml, void *shft, void *caps);
\expl{Set the addresses of the keyboard mapping tables (-1 = don't change).}

\func void *Logbase();
\expl{Get the start address of the logical display memory.}

\func void Mfpint(short vnum, void *vptr);
\expl{Set the interrupt vectors of the MFP 68901 chip.}

\func void Midiws(short cnt, void *ptr);
\expl{Write a sequence of {\sl cnt}+1 bytes to the MIDI-port.}

\func void Offgibit(short ormask);
\expl{Clear a bit in ``PORT A'' register of the GI chip.}

\func void Ongibit(short andmask);
\expl{Set a bit in ``PORT A'' register of the GI chip.}

\func void *Physbase();
\expl{Get the start address of the physical display memory.}

\lfunc void Protobt(void *buf\comma long serial, short dsktyp,
short exec);
\expl{Create a boot sector in memory.}

\func void Prtblk(void *pblkptr);
\expl{Special hardcopy routine, not unlike the {\bf Scrdmp()} routine.}

\func long Random();
\expl{Get a 24 bit random number.}

\lfunc long Rsconf(short baud\comma short flow\comma short uc, short
rs, short ts, short sc);
\expl{Set the communication parameters for the serial port.}

\func void Scrdmp();
\expl{Dump the current screen to the printer.}

\func short Setcolor(short colornum, short color);
\expl{Get ({\sl color} = -1) or set contents of color register.}

\func void Setpallete(void *palptr);
\expl{Set the color palette of the video hardware.}
 
\func short Setprt(short config);
\expl{Get or set the current printer configuration.}

{\leftskip=\myindent The bits of the return value are assigned as
follows:\par}

\beginindentedkeys 
\hskip\keyindent\relax
\vbox{\offinterlineskip
  \paralign{\strut\quad\hfil#\quad&\vrule#&
                  \quad#\hfil\quad&\vrule#&\quad#\hfil\quad\cr
    \threecolrule{Bit}{Off}{On}
    \noalign{\hrule}
    \threecolrule{0}{Matrix-}{Daisy Wheel printer}
    \threecolrule{1}{color}{monochrom}
    \threecolrule{2}{Atari-}{Epson printer}
    \threecolrule{3}{Draft-}{High quality}
    \threecolrule{4}{Centronics-}{RS232 interface}
    \threecolrule{5}{Endless}{Single sheet paper}
    \noalign{\smallskip}
  }
}\endindentedkeys

\func void Setscreen(void *lscrn, void *pscrn, short rez);
\expl{Set the logical and physical display memory start address and 
the current screen resolution.}
 
\func void Settime(long time\_date);
\expl{Set the hardware clock to {\sl time\_date}(lower word = time,
upper word = date.}

\func void *Ssbrk(short size);
\expl{Reserve {\sl size} bytes at the end of the physical memory (Dummy
routine in all TOS versions).}

\func long Supexec(void *funcptr);
\expl{Execute a subroutine in supervisor mode.}

\func void Vsync();
\expl{Wait until the verical blank interrupt has bitten.}

\lfunc void Xbtimer(short timer\comma short ctrl, long data, void *vptr);
\expl{Set and start the MFP 68901 timer.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{lineA Calls}

\#include \<linea.h>

\func void linea0();
\expl{Initialize lineA.}

\func void linea1();
\expl{Put pixel.}

\func int linea2();
\expl{Get pixel.}

\func void linea3();
\expl{Draw line.}

\func void linea4();
\expl{Horizontal line.}

\func void linea5();
\expl{Draw rectangle.}

\func void linea6();
\expl{Filled polygon.}

\func void linea7(BBPB *ptr);
\expl{Bit blit.}

\func void linea8();
\expl{Text blit.}

\func void linea9();
\expl{Show mouse.}

\func void lineaa();
\expl{Hide mouse.}

\func void lineab();
\expl{Mouse form.}

\func void lineac(void *ptr);
\expl{Undraw sprite.}

\func void linead(int x, int y, SFORM *sprite, void *ptr);
\expl{Draw sprite.}

\func void lineae();
\expl{Copy raster.}

\func void lineaf();
\expl{Seed fill.}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{VT52 Escape Seqences}

\#include \<vt52.h>

\vbox{\offinterlineskip
  \paralign{\strut\enskip#\hfil\enskip&\vrule#&
                  \enskip\hfil$\backslash$#\hfil
		  \enskip&\vrule#&\enskip#\hfil\enskip\cr
  \threecolrule{Mnemonic}{\omit\hfil Sequence\hfil}{Meaning}
  \noalign{\hrule}
  \threecolrule{C\_UP}{033A}{cursor one line up}
  \threecolrule{C\_DOWN}{033B}{cursor one line down}
  \threecolrule{C\_RIGHT}{033C}{cursor one column right}
  \threecolrule{C\_LEFT}{033D}{cursor one column left}
  \threecolrule{CLEAR\_HOME}{033E}{clear screen, cursor home}
  \threecolrule{HOME}{033H}{cursor home}
  \threecolrule{SCROLL\_UP}{033I}{cursor one line up (scroll)}
  \threecolrule{CLEAR\_DOWN}{033J}{clear to end of screen}
  \threecolrule{DEL\_EOL}{033K}{clear until end of line}
  \threecolrule{INS\_LINE}{033L}{insert line}
  \threecolrule{DEL\_LINE}{033M}{delete line}
  \threecolrule{CURS\_LOC}{033Y\%c\%c}{set cursor to position}
  \threecolrule{CHAR\_COLOR}{033b\%c}{set char. color}
  \threecolrule{BG\_COLOR}{033c\%c}{set background color}
  \threecolrule{DEL\_BOP}{033d}{erase to start of page}
  \threecolrule{C\_ON}{033e}{switch cursor on}
  \threecolrule{C\_OFF}{033f}{switch cursor off}
  \threecolrule{C\_SAVE}{033j}{store cursor position}
  \threecolrule{C\_RESTORE}{033k}{restore cursor position}
  \threecolrule{ERASE\_L}{033l}{clear cursor line}
  \threecolrule{DEL\_BOL}{033o}{clear until beg. of line}
  \threecolrule{REV\_ON}{033p}{inverse on}
  \threecolrule{REV\_OFF}{033q}{inverse off}
  \threecolrule{WRAP\_ON}{033v}{automatic line wrap on}
  \threecolrule{WRAP\_OFF}{033w}{automatic line wrap off}
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{System Variables and Magic Numbers}

\#include \<sysvars.h>

{\offinterlineskip
 \paralign{\strut#\hfil\quad&\hfil#\cr
  \twocol{Name}{\omit\hfil Address\hfil}\noalign{\vskip 3pt}
  \twocol{proc\_lives}{(unsigned long *) 0x380}
  \twocol{etv\_timer}{(void (**)()) 0x400}
  \twocol{etv\_critic}{(void (**)()) 0x404}
  \twocol{etv\_term}{(void (**)()) 0x408}
  \twocol{memvalid}{(unsigned long *) 0x420}
  \twocol{mencntlr}{(unsigned char *) 0x424}
  \twocol{resvalid}{(unsigned long *) 0x426}
  \twocol{resvector}{(void (**)()) 0x42a}
  \twocol{phystop}{(unsigned long *) 0x42e}
  \twocol{\_membot}{(unsigned long *) 0x432}
  \twocol{\_memtop}{(unsigned long *) 0x436}
  \twocol{memval2}{(unsigned long *) 0x43a}
  \twocol{flock}{(short *) 0x43e}
  \twocol{seekrate}{(short *) 0x440}
  \twocol{\_timr\_ms}{(short *) 0x442}
  \twocol{\_fverify}{(short *) 0x444}
  \twocol{\_bootdev}{(short *) 0x446}
  \twocol{palmode}{(short *) 0x448}
  \twocol{defshiftmd}{(unsigned char *) 0x44a}
  \twocol{sshiftmd}{(short *) 0x44c}
  \twocol{\_v\_bas\_ad}{(void *) 0x44e}
  \twocol{vblsem}{short *) 0x452}
  \twocol{nvbls}{(short *) 0x454}
  \twocol{\_vblqueue}{(void (***)()) 0x456}
  \twocol{colorptr}{(short **) 0x45a}
  \twocol{\_vbclock}{(unsigned long *) 0x462}
  \twocol{\_frclock}{(unsigned long *) 0x466}
  \twocol{\_hz\_200}{(unsigned long *) 0x4ba}
  \twocol{conterm}{*((char *) 0x484}
  \twocol{savptr}{(long *) 0x4a2}
  \twocol{\_sysbase}{(long *) 0x4f2}
  \twocol{\_shell\_p}{(long *) 0x4f6}\noalign{\vskip 3pt}
  \twocol{PROC\_LIVES\_MAGIC}{0x12345678L}
  \twocol{MEMVALID\_MAGIC}{0x752019F3L}
  \twocol{MEMVAL2\_MAGIC}{0x237698AAL}
  \twocol{RESVALID\_MAGIC}{0x31415926L}
}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Error Numbers}

\#include \<errno.h>

{\offinterlineskip
 \paralign{\strut#\hfil\enskip&\hfil#\hfil\enskip&#\hfil\cr
  \threecol{ENOERR}{0}{no error}
  \threecol{EERROR}{1}{generic error}
  \threecol{EDRNRDY}{2}{drive not ready}
  \threecol{EUKCMD}{3}{unknown command}
  \threecol{ECRC}{4}{crc error}
  \threecol{EBADREQ}{5}{bad request}
  \threecol{ESEEK}{6}{seek error}
  \threecol{EUKMEDIA}{7}{unknown media}
  \threecol{ESECTOR}{8}{sector not found}
  \threecol{EPAPER}{9}{no paper}
  \threecol{EWRITE}{10}{write fault}
  \threecol{EREAD}{11}{read fault}
  \threecol{EGENERIC}{12}{general mishap}
  \threecol{EROFS}{13}{write protect}
  \threecol{ECHMEDIA}{14}{media change}
  \threecol{EUKDEV}{15}{unknown device}
  \threecol{EBADSEC}{16}{bad sectors}
  \threecol{EIDISK}{17}{insert disk}\noalign{\vskip 3pt}
  \threecol{EINVAL}{32}{invalid function number}
  \threecol{ENOENT}{33}{file not found}
  \threecol{EPATH}{34}{path not found}
  \threecol{EMFILE}{35}{too many open files}
  \threecol{EACCESS}{36}{access denied}
  \threecol{EBADF}{37}{invalid handle}
  \threecol{ENOMEM}{39}{insufficient memory}
  \threecol{EFAULT}{40}{invalid memory block request}
  \threecol{ENXIO}{46}{invalid drive}
  \threecol{EXDEV}{48}{cross device rename}
  \threecol{ENMFILES}{49}{no more files (Fnext)}\noalign{\vskip 3pt}
  \threecol{ERANGE}{62}{range error}
  \threecol{EDOM}{63}{domain error}
  \threecol{EBADARG}{64}{range error/context unknown}
  \threecol{EINTERNAL}{65}{internal error}
  \threecol{ENOEXEC}{66}{invalid program load format}
  \threecol{ESBLOCK}{67}{set block failed/growth restraints}
  \threecol{EEXIST}{80}{file exists (open)}
  \threecol{ENAMETOOLONG}{81}{file exists (open)}
  \threecol{ENOTTY}{82}{not a tty (ioctl)}
  \threecol{EAGAIN}{EDRNRDY}{try again later}
  \threecol{ENOTDIR}{EPATH}{* preliminary *}
}}

%\newcolumn

\copyrightnotice

\bye

% Local variables:
% compile-command: "tex lib-card"
% End:
