home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / FC20C.ZIP / MC.DOC < prev    next >
Text File  |  1990-08-20  |  262KB  |  7,445 lines

  1.     
  2.     
  3.     
  4.     
  5.     
  6.     
  7.     
  8.     
  9.     
  10.     
  11.     
  12.     
  13.     
  14.     
  15.     
  16.     
  17.     
  18.     
  19.     
  20.     
  21.                                     MICRO-C
  22.     
  23.                              A compact 'C' compiler
  24.                                for small systems.
  25.     
  26.                                 Technical Manual
  27.     
  28.     
  29.     
  30.     
  31.     
  32.                                   Release 2.0
  33.     
  34.                                Revised 10-Aug-90
  35.     
  36.     
  37.     
  38.     
  39.     
  40.     
  41.     
  42.     
  43.     
  44.     
  45.     
  46.     
  47.     
  48.     
  49.     
  50.                        Copyright 1988,1990 Dave Dunfield
  51.                               All rights reserved
  52.     MICRO-C                                                          Page: 1
  53.  
  54.  
  55.     1. INTRODUCTION
  56.     
  57.           MICRO-C is a compact, portable compiler for a subset  of  the  'C'
  58.        language which is suitable for implementation on small 8  or  16  bit
  59.        computer systems. It may be used as a resident or cross compiler, and
  60.        is capable of generating ROMable code. It is  distributed  in  source
  61.        form, and thus provides a learning tool for those wishing to  examine
  62.        the internals of a working compiler.
  63.     
  64.           The main goal in the development of MICRO-C, has been to provide a
  65.        reasonably powerful language  which  will  be  portable  with  little
  66.        difficulty to many  target  systems.  The  'C'  language  was  chosen
  67.        because  it  was  designed  to  be  portable,  and   provides   ample
  68.        programming power. MICRO-C provides  an  alternative  to  interpreted
  69.        BASIC or assembly language  programming  which  are  often  the  only
  70.        languages available on small 8 bit systems.
  71.     
  72.           With today's focus on larger computers and workstations,  software
  73.        support for small  systems  and  micro-controller  sized  devices  is
  74.        getting hard to find. MICRO-C helps fill that gap, because all  files
  75.        necessary to port and maintain  the  compiler  are  included  on  the
  76.        distribution disk, allowing it to be  moved  to  ANY  system  without
  77.        dependance on a software vendor.
  78.     
  79.           Sample code generators  and  runtime  librarys  are  included  for
  80.        several popular microprocessors.
  81.     
  82.           Also included with the compiler is the 'C' and 'ASM'  source  code
  83.        for a complete library of system functions, as well  several  example
  84.        programs.
  85.     
  86.           The MICRO-C "package" (software and documentation) is copyrighted,
  87.        and may  not  be  re-distributed  in  any  form  without  my  written
  88.        permission. If you have received the  "DEMO"  archive,  and  wish  to
  89.        obtain the entire MICRO-C package complete with source code, fill out
  90.        and send the order form contained in the "READ.ME" file,  along  with
  91.        the required payment to:
  92.     
  93.                            Dave Dunfield
  94.                            56 Burnetts Grove Circle,
  95.                            Nepean, Ont. (Canada)
  96.                            K2J 1N6
  97.     
  98.           If you choose not to order the complete MICRO-C package, you  MUST
  99.        discontinue using MICRO-C within thirty days.
  100.     
  101.           MICRO-C is provided on an "as is" basis, with no warranty  of  any
  102.        kind. In no event shall the author be liable for any damages  arising
  103.        from its use or distribution.
  104.     MICRO-C                                                          Page: 2
  105.  
  106.  
  107.        1.1 Code Portability
  108.     
  109.              With few exceptions, this compiler follows the  syntax  of  the
  110.           "standard" UNIX compiler (within  its  subset  of  the  language).
  111.           Programs written in MICRO-C should compile with few changes  under
  112.           other "standard" compilers.
  113.     
  114.           1.1.1 Unsupported Features:
  115.     
  116.                 MICRO-C does not currently support the following features of
  117.              standard 'C':
  118.     
  119.                     Long, Double, Float and Enumerated data types,
  120.                     Structures, Unions, Typedef and Bit fields.
  121.     
  122.           1.1.2 Additional Features
  123.     
  124.                 MICRO-C provides a few additional  features  which  are  not
  125.              always included in "standard" 'C' compilers:
  126.     
  127.                     Unsigned character variables, Nested comments, 16 bit
  128.                     character constants, Inline assembly code capability.
  129.     
  130.        1.2 Compiler Portability
  131.     
  132.              MICRO-C is written in standard 'C', and is capable of compiling
  133.           itself. This allows any system  with  a  'C'  compiler  (including
  134.           MICRO-C) to be used to port MICRO-C to another processor.
  135.     
  136.              The  parser  makes  very  few  assumptions  about  the   target
  137.           processor  or  operating  system  architecture,  allowing  a  code
  138.           generator  to  be  written  for  virtually   any   processor   and
  139.           environment.
  140.     
  141.              With the exception of required I/O routines (described  later),
  142.           the MICRO-C compiler uses no library functions, and relies  on  no
  143.           system services.
  144.     
  145.              Assuming that the code generator is fairly efficent,  and  that
  146.           the I/O routines and code generator are not unreasonably large,  a
  147.           full MICRO-C compiler may be implemented on systems with as little
  148.           as 32K of free ram and a single floppy disk.
  149.     MICRO-C                                                          Page: 3
  150.  
  151.  
  152.        1.3 The MCC command
  153.     
  154.              When  created  using  the  'io'  routines   supplied   on   the
  155.           distribution disk, the format of the MICRO-C Compiler command line
  156.           is:
  157.     
  158.                     MCC [input_file] [output_file] [options]
  159.     
  160.              [input_file] is the name of  the  source  file  containing  'C'
  161.           statements to read. If no filenames are given, MCC will read  from
  162.           standard input.
  163.     
  164.              [output_file] is the name of the file to  write  the  generated
  165.           assembly  language  code  to.  If  less  than  two  filenames  are
  166.           specified, MCC will write to standard output.
  167.     
  168.           1.3.1 Command Line Options
  169.     
  170.                 -q      - Instructs MCC to be quiet, and not display the
  171.                           startup message when it is executed.
  172.     MICRO-C                                                          Page: 4
  173.  
  174.  
  175.     2. THE MICRO-C PROGRAMMING LANGUAGE
  176.     
  177.           The following pages contain a brief summary of  the  features  and
  178.        constructs implemented in MICRO-C.
  179.     
  180.           This document does not  attempt  to  teach  'C'  programming,  and
  181.        assumes that the reader is familiar with the language.
  182.     
  183.        2.1 Constants
  184.     
  185.              The following forms of constants are supported by the compiler:
  186.     
  187.                 <num>       - Decimal number        (0 - 65535)
  188.                 0<num>      - Octal number          (0 - 0177777)
  189.                 0x<num>     - Hexidecimal number    (0x0 - 0xffff)
  190.                 '<char>'    - Character             (1 or 2 chars)
  191.                 "<string>"  - Address of literal string.
  192.     
  193.              The following "special" characters may be used within character
  194.           constants or strings:
  195.     
  196.                 \n          - Newline (line-feed)   (0x0a)
  197.                 \r          - Carriage Return       (0x0d)
  198.                 \t          - Tab                   (0x09)
  199.                 \f          - Formfeed              (0x0c)
  200.                 \b          - Backspace             (0x08)
  201.                 \<num>      - Octal value <num>     (Max. three digits)
  202.                 \x<num>     - Hex value <num>       (Max. two digits)
  203.                 \<char>     - Protect character <char> from input scanner.
  204.     
  205.        2.2 Symbols
  206.     
  207.              Symbol names  may  include  the  characters  'a'-'z',  'A'-'Z',
  208.           '0'-'9', and '_'. The characters '0'-'9' may not be  used  as  the
  209.           first character in the  symbol  name.  Symbol  names  may  be  any
  210.           length, however, only the first 15 characters are significant.
  211.     
  212.              The "char" modifier may be used to declare a symbol as an 8 bit
  213.           wide value, otherwise it is assumed to be 16 bits.
  214.     
  215.                               eg: char input_char;
  216.     
  217.              The "int" modifier may be used to declare a symbol as a 16  bit
  218.           wide value. This is assumed if neither "int" or "char" is given.
  219.     
  220.                                   eg: int abc;
  221.     
  222.              The "unsigned" modifier may be used to declare a symbol  as  an
  223.           unsigned positive only value. Note that unlike some 'C' compilers,
  224.           this modifier may be applied to a character (8 bit) variable.
  225.     
  226.                             eg: unsigned char count;
  227.     MICRO-C                                                          Page: 5
  228.  
  229.  
  230.              The "extern" modifier causes the compiler to be  aware  of  the
  231.           existance and  type  of  a  global  symbol,  but  not  generate  a
  232.           definition for that symbol. This allows the module being  compiled
  233.           to reference a symbol which is defined  in  another  module.  This
  234.           modifier may not be used with local symbols.
  235.     
  236.                             eg: extern char getc();
  237.     
  238.              A  symbol  declared  as  external  may  be  re-declared  as   a
  239.           non-external at a later  point  in  the  code,  in  which  case  a
  240.           definition for it will be generated. This allows  "extern"  to  be
  241.           used to inform the compiler of a function or variable type so that
  242.           it can be referenced  properly  before  that  symbol  is  actually
  243.           defined.
  244.     
  245.              The "static" modifier causes global variables to  be  available
  246.           only in the file where they are defined.  Variables  or  functions
  247.           declared  as  "static"  will  not  be   accessable   as   "extern"
  248.           declarations in other object files, nor will they cause  conflicts
  249.           with duplicate names in those files.
  250.     
  251.                          eg: static int variable_name;
  252.     
  253.              The "register" modifier indicates to the  code  generator  that
  254.           this is a high priority variable, and should be kept where  it  is
  255.           easy to get at. Since  its  interpretation  depends  on  the  code
  256.           generator, it is often  ignored  in  simple  implementations.  See
  257.           "Functions" for a  special  use  of  "register"  when  defining  a
  258.           function.
  259.     
  260.                           eg: register unsigned count;
  261.     
  262.              Symbols declared with a preceeding '*' are assumed to be 16 bit
  263.           pointers to the declared type.
  264.     
  265.                              eg: int *pointer_name;
  266.     
  267.              Symbol names declared followed by square brackets  are  assumed
  268.           to be arrays with a number of dimensions equal to  the  number  of
  269.           '[]' pairs that follow. The size of each dimension  is  identified
  270.           by a constant value  contained  within  the  corresponding  square
  271.           brackets.
  272.     
  273.                           eg: char array_name[5][10];
  274.     
  275.           2.2.1 More Symbol Examples
  276.     
  277.                 char a;                 /* 8 bit signed */
  278.                 unsigned char b;        /* 8 bit unsigned */
  279.                 int c;                  /* 16 bit signed */
  280.                 unsigned int d;         /* 16 bit unsigned */
  281.                 unsigned e;             /* also 16 bit unsigned */
  282.                 extern char f();        /* external function returning char */
  283.     MICRO-C                                                          Page: 6
  284.  
  285.  
  286.           2.2.2 Global Symbols
  287.     
  288.                 Symbols  declared  outside  of  a  function  definition  are
  289.              considered to  be  global  and  will  have  memory  permanently
  290.              reserved for them. Global symbols are defined by  name  in  the
  291.              output file, allowing other modules to access them.
  292.     
  293.                 Note that the compiler IS case  sensitive,  however  if  the
  294.              assembler you are using is NOT, you  must  be  careful  not  to
  295.              declare any global symbols with names that differ only in case.
  296.     
  297.                 All non-initialized global variables are  generated  at  the
  298.              very end of the output file, after the literal pool is  dumped.
  299.              Since non-initialized globals do not generate object code, this
  300.              allows them to be excluded from the image file when it is saved
  301.              to disk.
  302.     
  303.                 Global variables may be initialized with one or more values,
  304.              which are expressed as a single array of  integers  REGUARDLESS
  305.              of the size and shape of the variable. If more than  one  value
  306.              is expressed, '{' and '}' must be used.
  307.     
  308.                    eg: int i = 10, j[2][2] = { 1, 2, 3, 4 };
  309.     
  310.                 When arrays are declared, a null dimension may  be  used  as
  311.              the dimension size, in which case the size of  the  array  will
  312.              default to the number of initialized values.
  313.     
  314.                          eg: int array[] = { 1, 2, 3 };
  315.     
  316.                 Initialized global variables are automatically saved  within
  317.              the code image,  insuring  that  the  initial  values  will  be
  318.              available at run time. Any non-initialized elements of an array
  319.              which has been partly initialized will be set to zero.
  320.     
  321.                 Non-initialized global variables are not preset in any  way,
  322.              and will be undefined at the beginning of program execution.
  323.     
  324.           2.2.3 Local Symbols
  325.     
  326.                 Symbols declared within a function definition are  allocated
  327.              on the stack, and  exist  only  during  the  execution  of  the
  328.              function.
  329.     
  330.                 To simplify the allocation and de-allocation of stack space,
  331.              all local symbols must be declared  at  the  beginning  of  the
  332.              function before any code producing statements are encountered.
  333.     
  334.                 MICRO-C does not support initialization of  local  variables
  335.              in the declaration statement. Since local variables have to  be
  336.              initialized every time the function is entered, you can get the
  337.              same effect using assignment statements at the beginning of the
  338.              function.
  339.     
  340.                 No type is assumed for  arguments  to  functions.  Arguments
  341.              must be explicitly declared, otherwise they will  be  undefined
  342.              within the scope of the function definition.
  343.     MICRO-C                                                          Page: 7
  344.  
  345.  
  346.        2.3 Arrays & Pointers
  347.     
  348.              When MICRO-C passes an array to a function, it actually  passes
  349.           a POINTER to the array. References to arrays which  are  arguments
  350.           are automatically performed through the pointer.
  351.     
  352.              This allows the use of pointers and arrays to be interchangable
  353.           through the context of a function call. Ie: An array passed  to  a
  354.           function may be declared and used as  a  pointer,  and  a  pointer
  355.           passed to a function may be declared and used as an array.
  356.     
  357.        2.4 Functions
  358.     
  359.              Functions are  essentially  initialized  global  symbols  which
  360.           contain executable code.
  361.     
  362.              MICRO-C accepts  any  valid  value  as  a  function  reference,
  363.           allowing  some  rather  unique  (although  non-standard)  function
  364.           calls.
  365.     
  366.           For example:
  367.     
  368.                 function();     /* call function */
  369.                 variable();     /* call contents of a variable */
  370.                 (*var)();       /* call indirect through variable */
  371.                 (*var[x])();    /* call indirect through indexed array */
  372.                 0x5000();       /* call address 0x5000 */
  373.     
  374.              Since this is a single pass compiler, operands to functions are
  375.           evaluated and pushed on the stack in the order in which  they  are
  376.           encountered, leaving the last operand closest to the  top  of  the
  377.           stack. This is the opposite order from which  many  'C'  compilers
  378.           push operands.
  379.     
  380.              For functions with a fixed number of arguments,  the  order  of
  381.           which operands  are  passed  is  of  no  importance,  because  the
  382.           compiler looks after generating  the  proper  stack  addresses  to
  383.           reference variables.  HOWEVER,  functions  which  use  a  variable
  384.           number of arguments are affected for two reasons:
  385.     
  386.           1) The location of the LAST arguments are known (as fixed  offsets
  387.              from the stack pointer) instead of the FIRST.
  388.     
  389.           2) The symbols defined as arguments  in  the  function  definition
  390.              represent the LAST arguments instead of the FIRST.
  391.     
  392.              If a function is declared as "register", it  serves  a  special
  393.           purpose and causes the accumulator to be loaded with the number of
  394.           arguments passed whenever the function is called. This allows  the
  395.           function to know how many  arguments  were  passed  and  therefore
  396.           determine the location of the first argument.
  397.     MICRO-C                                                          Page: 8
  398.  
  399.  
  400.        2.5 Control Statements
  401.     
  402.              The following control statements are implemented in MICRO-C:
  403.     
  404.                 if(expression)
  405.                     statement;
  406.     
  407.                 if(expression)
  408.                     statement;
  409.                 else
  410.                     statement;
  411.     
  412.                 while(expression)
  413.                     statement;
  414.     
  415.                 do
  416.                     statement;
  417.                 while expression;
  418.     
  419.                 for(expression; expression; expression)
  420.                     statement;
  421.     
  422.                 return;
  423.     
  424.                 return expression;
  425.     
  426.                 break;
  427.     
  428.                 continue;
  429.     
  430.                 switch(expression) {
  431.                     case constant_expression :
  432.                         statement;
  433.                         ...
  434.                         break;
  435.                     case constant_expression :
  436.                         statement;
  437.                         ...
  438.                         break;
  439.                         .
  440.                         .
  441.                         .
  442.                     default:
  443.                         statement; }
  444.     
  445.                 label: statement;
  446.     
  447.                 goto label;
  448.     MICRO-C                                                          Page: 9
  449.  
  450.  
  451.     2.5.1 Notes on Control Structures
  452.     
  453.         1)  Any "statement" may be a single statement or a compound
  454.             statement enclosed within '{' and '}'.
  455.     
  456.         2)  All three "expression"s in the "for" command are optional.
  457.     
  458.         3)  If a "case" selection does not end with "break;", it will
  459.             "fall through" and execute the following case as well.
  460.     
  461.         4)  Expressions following 'return' and 'do/while' do not have
  462.             to be contained in brackets (although this is permitted).
  463.     
  464.         5)  Label names may preceed any statement, and must be any
  465.             valid symbol name, followed IMMEDIATELY by ':' (No spaces
  466.             are allowed). Labels are considered LOCAL to a function
  467.             definition and will only be accessable within the scope
  468.             of that function.
  469.     MICRO-C                                                          Page: 10
  470.  
  471.  
  472.        2.6 Expression Operators
  473.     
  474.              The following expression operators are implemented in MICRO-C:
  475.     
  476.     2.6.1 Unary Operators
  477.     
  478.         -           - Negate
  479.         ~           - Complement
  480.         !           - Logical complement
  481.         ++          - Pre or Post increment
  482.         --          - Pre or post decrement
  483.         *           - Indirection
  484.         &           - Address of
  485.         (type)      - Typecast
  486.     
  487.     2.6.2 Binary Operators
  488.     
  489.         +           - Addition
  490.         -           - Subtraction
  491.         *           - Multiplication
  492.         /           - Division
  493.         %           - Modulus
  494.         &           - Bitwise AND
  495.         |           - Bitwise OR
  496.         ^           - Bitwise EXCLUSIVE OR
  497.         <<          - Shift left
  498.         >>          - Shift right
  499.         ==          - Test for equality
  500.         !=          - Test for inequality
  501.         >           - Test for greater than
  502.         <           - Test for less than
  503.         >=          - Test for greater than or equal to
  504.         <=          - Test for less than or equal to
  505.         &&          - Logical AND
  506.         ||          - Logical OR
  507.         =           - Assignment
  508.         +=          - Add to self assignment
  509.         -=          - Subtract from self assignment
  510.         *=          - Multiply by self assignment
  511.         /=          - Divide by and reassign assignment
  512.         %=          - Modular self assignment
  513.         &=          - AND with self assignment
  514.         |=          - OR with self assignment
  515.         ^=          - EXCLUSIVE OR with self assignment
  516.         <<=         - Shift left self assignment
  517.         >>=         - Shift right self assignment
  518.     MICRO-C                                                          Page: 11
  519.  
  520.  
  521.     NOTES:
  522.     
  523.         1)  The expression "a && b" returns 0 if "a" is zero, otherwise the
  524.             value of "b" is returned. The "b" operand is NOT evaluated if
  525.             "a" is zero.
  526.     
  527.         2)  The expression "a || b" returns the value of "a" if it is not 0,
  528.             otherwise the value of "b" is returned. The "b" operand is NOT
  529.             evaluated if "a" is non-zero.
  530.     
  531.     2.6.3 Other Operators
  532.     
  533.         ;           - Ends a statement.
  534.         ,           - Allows several expressions in one statement.
  535.                     + Separates symbol names in multiple declarations.
  536.                     + Separates constants in multi-value initialization.
  537.                     + Separates operands in function calls.
  538.         ?           - Conditional expression.
  539.         :           - Delimits labels, ends CASE and separates conditionals.
  540.         { }         - Defines a block of statements.
  541.         ( )         - Forces priority in expression, indicates function calls.
  542.         [ ]         - Indexes arrays. If fewer index values are given than the
  543.                       number of dimensions which are defined for the array, the
  544.                       the value returned will be a pointer to the appropriate
  545.                       address.
  546.     
  547.                     Eg:
  548.                         char a[5][2];
  549.     
  550.                         a[3] returns address of forth row of two elements.
  551.                         (remember index's start from zero)
  552.     
  553.                         a[3][0] returns the character at index [3][0];
  554.     MICRO-C                                                          Page: 12
  555.  
  556.  
  557.        2.7 Preprocessor Commands
  558.     
  559.              The  MICRO-C  compiler  supports  the  following  pre-processor
  560.           commands. These commands are recognized only if they occur at  the
  561.           beginning of the input line.
  562.     
  563.              NOTE:  This  describes  the  limited  pre-processor  which   is
  564.           integral to the  compiler,  see  also  the  section  on  the  more
  565.           powerful external processor (MCP).
  566.     
  567.           2.7.1 #asm
  568.     
  569.                 Causes the compiler to copy all subsequent lines directly to
  570.              the output  file  without  translation.  This  allows  assembly
  571.              language code to be included in the 'C' program.
  572.     
  573.           2.7.2 #endasm
  574.     
  575.                 Terminates a "#asm",  and  causes  the  compiler  to  resume
  576.              compiling from the input file.
  577.     
  578.           2.7.3 #define <name> <replacement_text>
  579.     
  580.                 The "#define" command allows a global name  to  be  defined,
  581.              which will be replaced with the indicated text whenever  it  is
  582.              encountered in the input file. This occurs prior to  processing
  583.              by the compiler.
  584.     
  585.           2.7.4 #include <filename>
  586.     
  587.                 This command causes the indicated file to be opened and read
  588.              in as the source  text.  When  the  end  of  the  new  file  is
  589.              encountered, processing will continue with the  line  following
  590.              "#include" in the original file.
  591.     
  592.           2.7.5 #ifdef <name>
  593.     
  594.                 Processes the following lines (up to #else or  #endif)  only
  595.              if the given name is defined.
  596.     
  597.           2.7.6 #ifndef <name>
  598.     
  599.                 Processes the following lines (up to #else or  #endif)  only
  600.              if the given name is NOT defined.
  601.     
  602.           2.7.7 #else
  603.     
  604.                 Processes the following lines (up to  #endif)  only  if  the
  605.              preceeding #ifdef or #ifndef was false.
  606.     
  607.           2.7.8 #endif
  608.     
  609.                 Terminates #ifdef and #ifndef
  610.     
  611.                 NOTE: The #ifdef and #ifndef contructs may not be nested.
  612.     MICRO-C                                                          Page: 13
  613.  
  614.  
  615.        2.8 Error Messages
  616.     
  617.              When MICRO-C detects an  error,  it  outputs  an  informational
  618.           message indicating the type of problem encountered.
  619.     
  620.              The error message is preceeded by the  line  number(s)  of  the
  621.           line containing the error in all files being processed.
  622.     
  623.                              eg: 5:3: Syntax error
  624.     
  625.              In the above example, the main input file "#included" a file at
  626.           line 5, and a syntax error was discovered in that file at line 3.
  627.     
  628.              The following error messages are produced by the compiler:
  629.     
  630.           2.8.1 Compilation aborted
  631.     
  632.                 The preceeding error was so severe than the compiler  cannot
  633.              proceed.
  634.     
  635.           2.8.2 Constant expression required
  636.     
  637.                 The compiler requires a constant  expression  which  can  be
  638.              evaluated at compile time (ie: no variables).
  639.     
  640.           2.8.3 Declaration must preceed code.
  641.     
  642.                 All local variables must be defined at the beginning of  the
  643.              function, before any code producing statements are processed.
  644.     
  645.           2.8.4 Dimension table exhausted
  646.     
  647.                 The compiler has encountered more  active  array  dimensions
  648.              than it can handle.
  649.     
  650.           2.8.5 Duplicate local: 'name'
  651.     
  652.                 You have declared the named  local  symbol  more  than  once
  653.              within the same function definition.
  654.     
  655.           2.8.6 Duplicate global: 'name'
  656.     
  657.                 You have declared the named global symbol more than once.
  658.     
  659.           2.8.7 Expected '<token>'
  660.     
  661.                 The compiler  was  expecting  the  given  token,  but  found
  662.              something else.
  663.     
  664.           2.8.8 Expression stack overflow
  665.     
  666.                 The compiler has found a more complicated expression than it
  667.              can handle. Check that it is of  correct  syntax,  and  if  so,
  668.              break it up into two simpler expressions.
  669.     MICRO-C                                                          Page: 14
  670.  
  671.  
  672.           2.8.9 Expression stack underflow
  673.     
  674.                 The compiler has made an error in  parsing  the  expression.
  675.              Check that it is of correct syntax.
  676.     
  677.           2.8.10 Illegal indirection
  678.     
  679.                 You have attempted to perform an indirect operation ('*'  or
  680.              '[]') on an entity which is not a pointer or array. This  error
  681.              will also result if you attempt to index  an  array  with  more
  682.              indices than it has dimensions.
  683.     
  684.           2.8.11 Illegal initialization
  685.     
  686.                 Local variables may not be initialized  in  the  declaration
  687.              statement. Use assignments at the  beginning  of  the  function
  688.              code to perform the initialization.
  689.     
  690.           2.8.12 Illegal nested function
  691.     
  692.                 You may not declare a  function  within  the  definition  of
  693.              another function.
  694.     
  695.           2.8.13 Improper #else/#endif
  696.     
  697.                 A #else or #endif statement is out of place.
  698.     
  699.           2.8.14 Inconsistant re-declaration: 'name'
  700.     
  701.                 You have attempted to redefine  the  named  external  symbol
  702.              with a type which does not match its previously declared type.
  703.     
  704.           2.8.15 Incorrect declaration
  705.     
  706.                 A statement occuring outside of a function definition is not
  707.              a valid declaration for a function or global variable.
  708.     
  709.           2.8.16 Invalid '&' operation
  710.     
  711.                 You have attempted to reference  the  address  of  something
  712.              that has no address. This error also occurs when you attempt to
  713.              take the address of an array without giving it a  full  set  of
  714.              indicies. Since the address is already returned in  this  case,
  715.              simply drop the '&'. (The error occurs because you  are  trying
  716.              to take the address of an address).
  717.     
  718.           2.8.17 Macro expansion too deep
  719.     
  720.                 The compiler has encountered a nested macro reference  which
  721.              is too deep to be resolved.
  722.     
  723.           2.8.18 Macro space exhausted
  724.     
  725.                 The compiler has encountered  more  macro  ("#define")  text
  726.              than it has room to store.
  727.     MICRO-C                                                          Page: 15
  728.  
  729.  
  730.           2.8.19 No active loop
  731.     
  732.                 A "continue" or "break" statement was  encountered  when  no
  733.              loop is active.
  734.     
  735.           2.8.20 No active switch
  736.     
  737.                 A "case" or "default"  statement  was  encountered  when  no
  738.              "switch" statement is active.
  739.     
  740.           2.8.21 Not an argument: 'name'
  741.     
  742.                 You have declared the named variable as an argument, but  it
  743.              does not appear in the argument list.
  744.     
  745.           2.8.22 Non-assignable
  746.     
  747.                 You have attempted an operation which results in  assignment
  748.              of a value to an entity which cannot be assigned. (eg: 1 = 2);
  749.     
  750.           2.8.23 Numeric constant required
  751.     
  752.                 The compiler requires a constant expression which returns  a
  753.              simple numeric value.
  754.     
  755.           2.8.24 String space exhausted
  756.     
  757.                 The compiler has encountered more literal  strings  than  it
  758.              has room store.
  759.     
  760.           2.8.25 Symbol table full
  761.     
  762.                 The compiler has encountered more symbol definitions than it
  763.              can handle.
  764.     
  765.           2.8.26 Syntax error
  766.     
  767.                 The statement shown does not follow syntax rules and  cannot
  768.              be parsed.
  769.     
  770.           2.8.27 Too many active cases
  771.     
  772.                 The compiler has run out of space  for  storing  switch/case
  773.              tables. Reduce the number of active "cases".
  774.     
  775.           2.8.28 Too many defines
  776.     
  777.                 The compiler has encountered more '#define' statements  than
  778.              it can handle. Reduce the number of #defines.
  779.     
  780.           2.8.29 Too many errors
  781.     
  782.                 The compiler is aborting because of excessive errors.
  783.     MICRO-C                                                          Page: 16
  784.  
  785.  
  786.           2.8.30 Too many includes
  787.     
  788.                 The compiler has encountered more  nested  "#include"  files
  789.              than it can handle.
  790.     
  791.           2.8.31 Too many initializers
  792.     
  793.                 You have specified more initialization values than there are
  794.              locations in the global variable.
  795.     
  796.           2.8.32 Type clash
  797.     
  798.                 You  have  attempted  to  combine  values   which   are   of
  799.              incompatible types.
  800.     
  801.           2.8.33 Unable to open: 'name'
  802.     
  803.                 A "#include" command specified the named file,  which  could
  804.              not be opened.
  805.     
  806.           2.8.34 Undefined: 'name'
  807.     
  808.                 You have referenced a name which is not defined as  a  local
  809.              or global symbol.
  810.     
  811.           2.8.35 Unreferenced: 'name'
  812.     
  813.                 The named  symbol  was  defined  as  a  local  symbol  in  a
  814.              function, but was never used in that function. This error  will
  815.              occur at the end of  the  function  definition  containing  the
  816.              symbol declaration. It is only a warning, and  will  not  cause
  817.              the compile to abort.
  818.     
  819.           2.8.36 Unresolved: 'name'
  820.     
  821.                 The named symbol was forward  referenced  (Such  as  a  GOTO
  822.              label), and was never defined. This error will occur at the end
  823.              of the function definition containing the reference.
  824.     
  825.           2.8.37 Unterminated conditional
  826.     
  827.                 The end of file was encountered  when  a  "#if"  or  "#else"
  828.              conditional block was being processed.
  829.     
  830.           2.8.38 Unterminated function
  831.     
  832.                 The  end  of  the  file  was  encountered  when  a  function
  833.              definition was still open.
  834.     MICRO-C                                                          Page: 17
  835.  
  836.  
  837.        2.9 Quirks
  838.     
  839.              In its effort to provide the maximum  amount  of  functionality
  840.           with the minimum amount of code, MICRO-C  deviates  from  standard
  841.           'C' in some areas. The following is a short summary of  the  major
  842.           infractions and quirks:
  843.     
  844.              The operands to '#' commands are  parsed  based  on  separating
  845.           spaces, and any portion of the line not required  is  ignored.  In
  846.           particular, the '#define' command only accepts a definition up  to
  847.           the next space or tab character.
  848.     
  849.             eg: #define APLUSONE A+1        <-- uses "A+1"
  850.                 #define APLUSONE A +1       <-- uses "A"
  851.     
  852.              Comments are stripped by the token scanner, which occurs  AFTER
  853.           the '#' commands are processed.
  854.     
  855.             eg: #define NULL    /* comment */   <-- uses "/*"
  856.     
  857.              Note that since comments can therefore be included in "#define"
  858.           symbols, you can use "/**/" to simulate spaces between tokens.
  859.     
  860.             eg: #define BYTE unsigned/**/char
  861.     
  862.              Include filenames are not delimited by '""'  or  '<>'  and  are
  863.           passed to the operating system exactly as entered.
  864.     
  865.             eg: #include /mc/stdio.h
  866.     
  867.              NOTE:  The  above  quirks  do  not  apply  when  the   external
  868.           pre-processor (MCP) is used.
  869.     
  870.              The appearance of a variable name in the argument  list  for  a
  871.           function  declaration  serves  only  to  identify  that  variables
  872.           location on the stack. MICRO-C will not define the variable unless
  873.           it is explicitly declared (between the argument list and the  main
  874.           function body). In other words, all arguments to a  function  must
  875.           be explicitly declared.
  876.     
  877.              MICRO-C is more  strict  about  its  handling  of  the  ADDRESS
  878.           operator ('&') than most other compilers. It will produce an error
  879.           message if you attempt to take the address of  a  value  which  is
  880.           already a fixed address (such as an array name without a full  set
  881.           of indicies). Since an address is already produced in such  cases,
  882.           simply drop the '&'.
  883.     
  884.              The 'x' in '0x' and '\x' is accepted in lower case only.
  885.     MICRO-C                                                          Page: 18
  886.  
  887.  
  888.              When operating on pointers, MICRO-C only scales  the  increment
  889.           (++), decrement (--) and index ([]) operations to account for  the
  890.           size of the pointer:
  891.     
  892.             eg: char cptr;      /* pointer to character */
  893.                 int  cptr;      /* pointer to integer */
  894.                 ++cptr;         /* Advance one character */
  895.                 ++iptr;         /* Advance one integer */
  896.                 cptr[10];       /* Access the tenth character */
  897.                 iptr[10];       /* Access the tenth integer */
  898.                 cptr += 10;     /* Advance 10 characters */
  899.                 iptr += 10;     /* Advance ONLY FIVE integers */
  900.     
  901.         NOTE: A portable way to advance "iptr" by integers is:
  902.     
  903.                 iptr = &iptr[10];   /* Advance 10 integers */
  904.     
  905.              When using MICRO-C to create  a  function  which  will  contain
  906.           assembly language code, remember that MICRO-C allocates all  local
  907.           variables at the beginning of a function definition, and will  not
  908.           generate the function entry code until a non-declarative statement
  909.           is encountered. In particular, since  "#asm"  is  handled  by  the
  910.           pre-processor and not seen as  a  statement  by  the  parser,  you
  911.           should use a "null" statement (';') to ensure that the entry  code
  912.           is generated prior to using "#asm" at the beginning of a function.
  913.     
  914.             eg: func()
  915.                 { ;     /* ensures "entry" code is generated */
  916.                 #asm
  917.                     assembly statements
  918.                 #endasm
  919.                 }
  920.     
  921.              Also note, that MICRO-C will not output  external  declarations
  922.           to the output file  for  any  variables  or  functions  which  are
  923.           declared as "extern", unless that symbol is actually referenced in
  924.           the 'C' source code. This prevents "extern" declarations in system
  925.           header files (such as "stdio.h") which are used as prototypes  for
  926.           some library functions from causing those functions to  be  loaded
  927.           into the object file. Therefore, any "extern"  symbols  which  are
  928.           referenced only by assembly code (using "#asm") must  be  declared
  929.           in assembly code, not by the MICRO-C "extern" statement.
  930.     MICRO-C                                                          Page: 19
  931.  
  932.  
  933.              Unlike some  'C'  compilers,  MICRO-C  will  process  character
  934.           expressions using only  BYTE  values.  Character  values  are  not
  935.           promoted to INT unless there is  an  INT  value  involved  in  the
  936.           expression. This results in much more efficent code  when  dealing
  937.           with characters, particularily  on  small  processors  which  have
  938.           limited 16 bit instructions. Consider the statement:
  939.     
  940.                                  return c + 1;
  941.     
  942.              On some compilers, this will sign extend the character variable
  943.           'c' into an integer value, and then ADD an integer  1  and  return
  944.           the  result.  MICRO-C  will  ADD  the  character  variable  and  a
  945.           character 1, and then promote the result to INT  before  returning
  946.           it (results of expressions as  operands  to  'return'  are  always
  947.           promoted to int).
  948.     
  949.              Unfortunately, programs have been written  which  rely  on  the
  950.           automatic promotion of characters to INTs to  work  properly.  The
  951.           most common source of problems is code  which  attempts  to  treat
  952.           CHAR variables as UNSIGNED values (older compilers did not support
  953.           UNSIGNED CHAR). For example:
  954.     
  955.                                 return c & 255;
  956.     
  957.              In a compiler which always evaluates character  expressions  as
  958.           INT, the above statement will extract the value of 'c' as positive
  959.           integer ranging from 0 to 255.
  960.     
  961.              In MICRO-C, ANDing a character with 255  results  in  the  same
  962.           character, which gets promoted to an integer  value  ranging  from
  963.           -128 to 127. To force the promotion  within  the  expression,  you
  964.           could CAST the variable to an INT:
  965.     
  966.                               return (int)c & 255;
  967.     
  968.              The same objective can be achieved  in  a  more  efficent  (and
  969.           correct) manner by declaring the variable 'c' as UNSIGNED CHAR, or
  970.           by CASTing the variable to an UNSIGNED value:
  971.     
  972.                               return (unsigned)c;
  973.     
  974.              Note that this is not only more clearly shows the intent of the
  975.           programmer, but also results is more efficent code generated.
  976.     MICRO-C                                                          Page: 20
  977.  
  978.  
  979.     3. ADVANCED TOPICS
  980.     
  981.           This section provides information on the more advanced aspects  of
  982.        MICRO-C, which  is  generally  not  needed  for  casual  use  of  the
  983.        language.
  984.     
  985.        3.1 Conversion Rules
  986.     
  987.              MICRO-C keep track of the "type" of  each  value  used  in  all
  988.           expressions. This type identifies certain characteristics  of  the
  989.           value,  such  as   size   range   (8/16   bits),   numeric   scope
  990.           (signed/unsigned), reference (value/pointer) etc.
  991.     
  992.              When an  operation  is  performed  on  two  values  which  have
  993.           identical "types", MICRO-C assigns that same "type" to the result.
  994.     
  995.              When the  two  value  "types"  involved  in  an  operation  are
  996.           different, MICRO-C calculates the "type" of the result  using  the
  997.           following rules:
  998.     
  999.           3.1.1 Size range
  1000.     
  1001.                 If both values are  direct  (not  pointer)  references,  the
  1002.              result will be 8 bits only if  both  values  were  8  bits.  If
  1003.              either value was 16 bits, the result will be 16 bits.
  1004.     
  1005.                 If one value is a pointer, and  the  other  is  direct,  the
  1006.              result will be a pointer to the same size value as the original
  1007.              pointer.
  1008.     
  1009.                 If both values were pointers, the result will be  a  pointer
  1010.              to 16 bits only if both original  pointers  referenced  16  bit
  1011.              values. If either pointer referenced an 8 bit value, the result
  1012.              will reference an 8 bit value.
  1013.     
  1014.           3.1.2 Numeric Scope
  1015.     
  1016.                 The result of an expression is considered to be signed  only
  1017.              if both original values were signed. If  either  value  was  an
  1018.              unsigned value, the result is unsigned.
  1019.     
  1020.           3.1.3 Reference
  1021.     
  1022.                 If either of the original values was a pointer,  the  result
  1023.              will be a pointer.
  1024.     
  1025.              Note that this "calculated" result type  is  used  for  partial
  1026.           results within an expression. Whenever a symbol such as a variable
  1027.           or function is referenced, the type of that symbol is  taken  from
  1028.           its declaration, no matter what "type" of value  was  last  stored
  1029.           (variable) or returned (function).
  1030.     MICRO-C                                                          Page: 21
  1031.  
  1032.  
  1033.        3.2 Assembly Language Interface
  1034.     
  1035.              Assembly language programs may be called from 'C' functions and
  1036.           vice versa. These programs may be in the form of "#asm" statements
  1037.           in the 'C' source code, or separately linked modules.
  1038.     
  1039.              When MICRO-C calls any routine ('C'  or  assembler),  it  first
  1040.           pushes all arguments to the routine onto the processor  stack,  in
  1041.           the order in  which  they  occur  in  the  argument  list  to  the
  1042.           function. This means that the LAST argument  to  the  function  is
  1043.           LOWEST on the processor stack.
  1044.     
  1045.              Arguments are always pushed as 16 bit values. Character  values
  1046.           are extended to 16 bits, and arrays are passed as 16 bit  pointers
  1047.           to the array. (MICRO-C knows that arrays which are  arguments  are
  1048.           actually  pointers,  and  automatically  references  through   the
  1049.           pointer).
  1050.     
  1051.              After pushing the arguments, MICRO-C then generates  a  machine
  1052.           language subroutine  call,  thereby  executing  the  code  of  the
  1053.           routine.
  1054.     
  1055.              Since the compiler uses the ACCUMULATOR and INDEX REGISTER,  it
  1056.           will automatically save them (if necessary) during  processing  of
  1057.           the arguments to the function (even if no arguments are  present),
  1058.           and therefore these registers do not have to be preserved  by  the
  1059.           called routine.
  1060.     
  1061.              NOTE that any other  registers  used  by  the  code  generation
  1062.           routines (register variables etc) will not be  saved  by  MICRO-C,
  1063.           and should be preserved by called functions if their content is to
  1064.           be relied on between function calls.
  1065.     
  1066.              Once the called routine returns, the arguments are removed from
  1067.           the stack by the calling program. This usually consists of  simply
  1068.           adding the number of  bytes  pushed  as  arguments  to  the  stack
  1069.           pointer.
  1070.     
  1071.              When the called function executes, the first thing usually done
  1072.           is to push any registers which must be preserved, and  to  reserve
  1073.           space on the stack for any local variables which are required.  In
  1074.           some implementations, a "base" register may also be established to
  1075.           provide a stable reference to the local variables and arguments.
  1076.     
  1077.              It is the responsibility of the called function to  remove  any
  1078.           saved registers and local variable space from the stack before  it
  1079.           returns. If a value is to be returned to the calling  program,  it
  1080.           is expected to be in the ACCUMULATOR register.
  1081.     MICRO-C                                                          Page: 22
  1082.  
  1083.  
  1084.              Local variables in a  function  may  be  referenced  as  direct
  1085.           offsets from the "base" register or stack pointer.  Note  that  if
  1086.           the stack pointer is used, offsets must be adjusted for the number
  1087.           of bytes which are pushed and  popped  on  the  stack  during  the
  1088.           execution of the function.
  1089.     
  1090.              The address of a particular local variable is calculated as:
  1091.     
  1092.                                 "base register"
  1093.                                        -
  1094.                      (Size of all local variables in bytes)
  1095.                                        + 
  1096.                (size of all preceeding local variables in bytes)
  1097.     
  1098.                                     -- OR --
  1099.     
  1100.                                 "stack pointer"
  1101.                                        +
  1102.                    (# bytes pushed during function execution)
  1103.                                        +
  1104.                (size of all preceeding local variables in bytes)
  1105.     
  1106.              Arguments to a  function  may  also  be  referenced  as  direct
  1107.           offsets from the "base" register or stack  pointer,  in  much  the
  1108.           same way as local variables are.
  1109.     
  1110.              The address of a particular argument is calculated as:
  1111.     
  1112.                                 "base register"
  1113.                                        +
  1114.         (# bytes pushed at entry of function to preserve registers etc.)
  1115.                                        +
  1116.                  (Size of return address on stack (usually 2))
  1117.                                        +
  1118.                       (# arguments from LAST argument) * 2
  1119.     
  1120.                                     -- OR --
  1121.     
  1122.                                 "stack pointer"
  1123.                                        +
  1124.                    (# bytes pushed during function execution)
  1125.                                        +
  1126.                      (size of all local variables in bytes)
  1127.                                        +
  1128.         (# bytes pushed at entry of function to preserve registers etc.)
  1129.                                        +
  1130.                  (Size of return address on stack (usually 2))
  1131.                                        +
  1132.                       (# arguments from LAST argument) * 2
  1133.     
  1134.              NOTE: The (number of bytes pushed at entry of  function)  is  a
  1135.           function of the code generator,  and  depends  on  the  particular
  1136.           MICRO-C implementation. Examine  some  assembly  output  from  the
  1137.           compiler to determine the actual number on your system.
  1138.     MICRO-C                                                          Page: 23
  1139.  
  1140.  
  1141.              If a function has been declared  as  "register",  MICRO-C  will
  1142.           load the accumulator with  the  number  of  arguments  which  were
  1143.           passed, each time the function is called. This allows the function
  1144.           to determine the location of the first argument.
  1145.     
  1146.              The address of  the  first  argument  passed  to  a  "register"
  1147.           function may be calculated as:
  1148.     
  1149.                            (accumulator contents) * 2
  1150.                                        + 
  1151.                                 "base register"
  1152.                                        +
  1153.         (# bytes pushed at entry of function to preserve registers etc.)
  1154.                                        +
  1155.                  (Size of return address on stack (usually 2))
  1156.     
  1157.                                     -- OR --
  1158.     
  1159.                            (accumulator contents) * 2
  1160.                                        +
  1161.                                 "stack pointer"
  1162.                                        +
  1163.                    (# bytes pushed during function execution)
  1164.                                        +
  1165.                      (size of all local variables in bytes)
  1166.                                        +
  1167.         (# bytes pushed at entry of function to preserve registers etc.)
  1168.                                        +
  1169.                  (Size of return address on stack (usually 2))
  1170.     
  1171.              Global  variables  exist  at  absolute  addresses  and  may  be
  1172.           referenced directly by name from within assembler  programs.  Keep
  1173.           in mind however, that MICRO-C uses only the first 15 characters of
  1174.           a symbol's name. Also, many code generators will reduce  the  size
  1175.           of names even further, often using an algorithm  to  compress  the
  1176.           name rather than simply truncating it. For this reason,  it  is  a
  1177.           good idea to avoid using global symbol names which are longer than
  1178.           6 or 8 characters  if  they  are  to  be  referenced  from  within
  1179.           assembly language programs.
  1180.     MICRO-C                                                          Page: 24
  1181.  
  1182.  
  1183.        3.3 Compiling for ROM
  1184.     
  1185.              Assuming the code generator does not use such "nasty" things as
  1186.           self modifying code, the output  from  the  compiler  is  entirely
  1187.           "clean", and may be placed in Read Only Memory (ROM).
  1188.     
  1189.              The compiler places all initialized  global  variables  in  the
  1190.           output file as part of the code image. When the program is  stored
  1191.           in ROM, those variables are also stored in ROM, and  will  not  be
  1192.           modifiable.
  1193.     
  1194.              When the program is to be placed in ROM, you may not initialize
  1195.           any variables which you intend to modify  later.  Those  variables
  1196.           must be explicitly initialized by code executed at  the  beginning
  1197.           of the program.
  1198.     
  1199.              Initialized variables which you do not intend to  modify  (such
  1200.           as tables etc.) may be initialized in the declaration, and will be
  1201.           permanently saved in the ROM as part of the static code image.
  1202.     
  1203.              The  processor  stack  pointer  must  be  set  up  before   any
  1204.           expressions are evaluated, or any function  calls  are  performed.
  1205.           This may be performed via '#asm' statements.
  1206.     
  1207.              All non-initialized global variables must be  located  in  RAM.
  1208.           The compiler usually outputs all such variables at the very end of
  1209.           the compilation, just after dumping the literal pool.  The  global
  1210.           variables may be moved to RAM by  editing  the  output  file,  and
  1211.           placing an appropriate "ORG" statement at  the  beginning  of  the
  1212.           globals.
  1213.     
  1214.              If extensive compilation for ROM is being  performed,  you  may
  1215.           want to use a version of the compiler which uses  an  intermediate
  1216.           output file (see "PORTING THE COMPILER"). This allows  a  separate
  1217.           code generator to be customized for ROM applications,  which  will
  1218.           output the appropriate stack setup instructions (this can be  done
  1219.           in "def_module()"), and locate the global variables in  RAM  (this
  1220.           can be done at the end of "def_literal()").
  1221.     MICRO-C                                                          Page: 25
  1222.  
  1223.  
  1224.     4. PORTING THE COMPILER
  1225.     
  1226.           There are two major goals to accomplish when porting  the  MICRO-C
  1227.        compiler to a new machine. The first is to make the compiler  run  in
  1228.        the new environment, and the second is to make it  produce  code  for
  1229.        that environment.
  1230.     
  1231.           These two goals do not always go hand in hand. For example, it may
  1232.        be desirable to implement a CROSS COMPILER which generates code for a
  1233.        different system from that on which it runs.
  1234.     
  1235.           The usual method of porting a compiler to system A when a  version
  1236.        of the compiler is already running on system B, is to first create  a
  1237.        compiler which runs on system B, producing code for  system  A.  This
  1238.        "new" compiler may then be used to create a compiler  which  runs  on
  1239.        system A.
  1240.     
  1241.           The compiler consists of a module "compile"  which  contains,  the
  1242.        main compiler, input scanner, regular expression parser,  and  symbol
  1243.        table management routines.  This  is  the  "static"  portion  of  the
  1244.        compiler which does not change in different implementations.
  1245.     
  1246.           To create a working compiler, the above module  must  be  compiled
  1247.        and linked with an "io" module and "code"  module.  The  "io"  module
  1248.        performs the necessary initialization and I/O to allow  the  compiler
  1249.        to run in a particular  environment  (goal  #1).  The  "code"  module
  1250.        generates  the  assembly  language  output  code  for  a   particular
  1251.        environment (goal #2).
  1252.     
  1253.           The compiler uses NO system library functions, and  relies  on  NO
  1254.        system services (other  than  those  used  by  the  "io"  and  "code"
  1255.        modules). This allows the compiler to  be  ported  to  virtually  any
  1256.        system.
  1257.     
  1258.           All fixed compiler  parameters  (such  as  table  sizes  etc)  are
  1259.        contained in the header file "compile.h".  When  porting  to  systems
  1260.        with very limited RAM (less than 64k), you may have to reduce some of
  1261.        these sizes in order to get it to fit.
  1262.     
  1263.           Two additional modules are provided with the  compiler.  The  file
  1264.        "intercg.c", may be linked into the compiler in  place  of  the  code
  1265.        generator, and writes a "generic" intermediate  file  which  contains
  1266.        the pseudo operation and type tokens (See Code Generator).  The  file
  1267.        "genasm.c", may be linked with the regular "io" and  "code"  routines
  1268.        to produce a utility program which reads the  intermediate  file  and
  1269.        produces the assembly language code for a specific processor.
  1270.     
  1271.           NOTE: If your system makes a distinction between TEXT  and  BINARY
  1272.        files, the "io.c" routines must be modified for each program so  that
  1273.        the intermediate file will be accessed  in  BINARY  mode.  All  other
  1274.        files are accessed as TEXT.
  1275.     MICRO-C                                                          Page: 26
  1276.  
  1277.  
  1278.           Although this "split" compiling approach is slower than the  usual
  1279.        mode of direct assembly  language  production,  it  provides  several
  1280.        useful capabilities:
  1281.     
  1282.        1) The amount of ram required to  run  the  "separate"  compiler  and
  1283.           genasm programs can be considerably less than required to run  the
  1284.           "stand alone" compiler.
  1285.     
  1286.        2) A single parser may be used to generate code  for  several  target
  1287.           systems, by simply running a different  version  of  the  "genasm"
  1288.           utility, which is customized for each target.
  1289.     
  1290.        3) Use of the intermediate file  allows  distribution  of  "portable"
  1291.           programs which may be processed by "genasm" for different  targets
  1292.           WITHOUT distribution of the source code.
  1293.     
  1294.        4) A program may be written which processes this  intermediate  file,
  1295.           and "optimizes" the code. Additional "pseudo operation" codes  may
  1296.           be added to the output file if the target processor is capable  of
  1297.           operations which  the  more  "generic"  MICRO-C  output  does  not
  1298.           utilize.
  1299.     
  1300.        4.1 The "io" module
  1301.     
  1302.              The "io" module required  by  the  compiler  must  contain  the
  1303.           following function definitions:
  1304.     
  1305.              The function "main()" is called by the  operating  system  when
  1306.           the MICRO-C compiler is executed. It is  responsable  for  parsing
  1307.           any parmeters and command qualifiers, opening the input and output
  1308.           files,  performing  any  other  initializations  that   might   be
  1309.           required, and then  invoking  the  function  "compile()"  with  no
  1310.           arguments. The "compile" function is internal to  the  "compile.c"
  1311.           module, and will never return. For UNIX and  other  systems  which
  1312.           support I/O redirection, "stdin" and "stdout" are often  used  for
  1313.           the input and output files.
  1314.     
  1315.              The  function  "exit(rc)"  is  called  when  the  compiler  has
  1316.           finished all processing and wishes to terminate. The value "rc" is
  1317.           a return code: 0 = Success, program compiled without error,  -1  =
  1318.           Compile was aborted due to severe errors, n  =  Compile  finished,
  1319.           but had 'n' errors.
  1320.     
  1321.              The function "put_chr(chr, flag)"  is  passed  a  character  to
  1322.           output, as well as a flag. The flag will always be zero  when  the
  1323.           character is being sent to the console terminal, or non-zero  when
  1324.           the character is to be written to the output file.
  1325.     
  1326.              The function "put_str(*ptr, flag)" is passed  a  pointer  to  a
  1327.           zero terminated string, which is to be written to the  console  or
  1328.           output file as determined by "flag".
  1329.     
  1330.              The function "put_num(number, flag)" is passed a 16 bit number,
  1331.           which is to be written in printable form to the console or  output
  1332.           file as determined by "flag".
  1333.     MICRO-C                                                          Page: 27
  1334.  
  1335.  
  1336.           4.1.1 Compiler only routines
  1337.     
  1338.                 The following I/O routines are required by the compiler, but
  1339.              not by the "genasm" program.
  1340.     
  1341.                 The function  "get_lin(*ptr)"  is  passed  a  pointer  to  a
  1342.              character array,  and  should  read  a  single  line  from  the
  1343.              currently  open  input  file  into  that  array.  The  manifest
  1344.              definition "LINE_SIZE", found in "compile.h"  may  be  used  to
  1345.              determine the maximum line length acceptable to  the  compiler.
  1346.              Return of a non-zero value indicates the end of file condition.
  1347.     
  1348.                 The  function  "f_open(*ptr)"  is  passed  a  pointer  to  a
  1349.              filename. The new file should be opened, and if successful, the
  1350.              old input file should remain open and be "stacked", so that  it
  1351.              can be later returned to. If the file was opened  successfully,
  1352.              a non-zero value should be returned. A zero value indicates  to
  1353.              the compiler that the file could not be opened.
  1354.     
  1355.                 The function "f_close()"  is  responsible  for  closing  the
  1356.              currently open input  file,  and  returning  to  the  "stacked"
  1357.              previously open one. It receives no parameters. Note:  multiple
  1358.              "opens" may  be  stacked  -  see  the  manifest  definition  of
  1359.              "INCL_DEPTH" in the "compile.h" file.
  1360.     
  1361.           4.1.2 Genasm only routines
  1362.     
  1363.                 The following  I/O  routine  is  required  by  the  "genasm"
  1364.              program, but not by the compiler.
  1365.     
  1366.                 The function "get_char()" must  return  a  single  character
  1367.              from the input file as a 16 bit number with  a  positive  value
  1368.              between 0 and 255. A '-1' is  returned  for  the  end  of  file
  1369.              condition.
  1370.     
  1371.           4.1.3 Notes on I/O module
  1372.     
  1373.              1) It is the responsibility of the "put" routines to  translate
  1374.                 the  NEWLINE  '\n'  (0x0a)  character  into  whatever   line
  1375.                 termination  character(s)  are  required   by   the   target
  1376.                 operating system.
  1377.     
  1378.              2) If unix "stdin"  and  "stdout"  are  not  used,  it  is  the
  1379.                 responsibility  of  "main"  to  display  appropriate   error
  1380.                 messages if the input or output files could not be opened.
  1381.     
  1382.                 Refer to  the  sample  "io"  modules  distributed  with  the
  1383.              compiler.
  1384.     MICRO-C                                                          Page: 28
  1385.  
  1386.  
  1387.        4.2 The "code" module
  1388.     
  1389.              In order to insure that MICRO-C is portable  to  virtually  any
  1390.           environment,  the  compiler  makes  few  assumptions   about   the
  1391.           processor or system software of  the  target  system.  The  "code"
  1392.           module is  relied  on  to  produce  all  machine  instruction  and
  1393.           assembler directives written to the output file.
  1394.     
  1395.              The only two real "assumptions" made about the target processor
  1396.           are:
  1397.     
  1398.           1) It is assumed that the target processor  has  an  "accumulator"
  1399.              register in which all math operations are performed,  and  that
  1400.              the  lower  8  bits  of   this   register   may   be   accessed
  1401.              independantly.
  1402.     
  1403.           2) It is  assumed  that  the  target  processor  has  one  "index"
  1404.              register which may be loaded with a  16  bit  value,  and  that
  1405.              memory references may be made indirectly through this register.
  1406.     
  1407.              If the target processor does not support the above features, it
  1408.           may be possible to write a code generator for it using some  other
  1409.           features of the processor.
  1410.     
  1411.              For example, if an "index" register  does  not  exist,  it  may
  1412.           often be implemented using two bytes of reserved memory.
  1413.     
  1414.              The code  generation  module  required  by  the  compiler  must
  1415.           contain the following function definitions:
  1416.     
  1417.              The function "do_asm(*ptr)" is passed a pointer to a  character
  1418.           string, which it should  write  to  the  output  file  EXACTLY  as
  1419.           passed, followed by a '\n' NEWLINE  character.  This  function  is
  1420.           used by the "#asm" directive to write directly to the output file.
  1421.     
  1422.              The function "def_module()"  is  called  at  the  beginning  of
  1423.           compilation, before any other code generator functions are called.
  1424.           It is used to output any pre-amble needed by the assembler.
  1425.     
  1426.              The function "end_module()"  is  called  at  the  very  end  of
  1427.           compilation, and is the last code generator function called. It is
  1428.           used to output any post-amble needed by the assembler.
  1429.     
  1430.              The function "def_static(symbol)" is passed am index  into  the
  1431.           compiler symbol tables for a global variable, which is about to be
  1432.           initialized as static storage. The call to this function  will  be
  1433.           immediately followed by a call to "init_static" or "end_static".
  1434.     
  1435.              The "init_static(token, value,  word)"  function  is  passed  a
  1436.           token and value, with which it should initialize a single  element
  1437.           of static storage. The "word" flag will be non-zero if  the  value
  1438.           is a 16 bit element. Only the "constant" tokens  (NUMBER,  STRING,
  1439.           LABEL) need be handled by this routine.
  1440.     MICRO-C                                                          Page: 29
  1441.  
  1442.  
  1443.              The  "end_static()"  function  is  called  to   terminate   the
  1444.           definition of static storage.
  1445.     
  1446.              NOTE: "init_static"  should  not  rely  on  "def_static"  being
  1447.           called first,  since  it  is  also  called  immediately  following
  1448.           "def_label" to define "switch" tables (See "do_switch"). After the
  1449.           table  is  defined,  the  compiler  will  call  "end_static()"  to
  1450.           terminate the initialization and set up for the next.
  1451.     
  1452.              The function "def_global(symbol, size)" is called at the end of
  1453.           the compile, once for each non-static global  variable  which  was
  1454.           defined. The "size" paremeter indicates the  number  of  BYTES  of
  1455.           memory to be reserved for that variable.
  1456.     
  1457.              The function "def_extern(symbol)" is called at the end  of  the
  1458.           compile, once for each  non-resolved  external  symbol  which  was
  1459.           defined. This routine should examine the type of  the  symbol  and
  1460.           output the appriopriate assembler directives to  allow  it  to  be
  1461.           referenced in another module.
  1462.     
  1463.              The "def_func(symbol, size)"  routine  is  called  to  start  a
  1464.           function definition. The "symbol" parameter is an index  into  the
  1465.           compiler symbol tables for the function entry being  defined.  The
  1466.           "size" parameter indicates how many  bytes  of  memory  should  be
  1467.           allocated  on  the  stack  for  local  variables.  When   defining
  1468.           "register" functions, care must  be  taken  that  the  entry  code
  1469.           preserves the contents of the accumulator.
  1470.     
  1471.              The "end_func()" routine is  called  to  terminate  a  function
  1472.           definition.  It  should  remove  anything  placed  on  the   stack
  1473.           (including the local variable space allocated by "def_func"),  and
  1474.           terminate the function with a "return" instruction.
  1475.     
  1476.              The "def_label(label)" function is called whenever the compiler
  1477.           wants to generate a label in the output file. Each label generated
  1478.           by the compiler is identified by a 16 bit unsigned number.  It  is
  1479.           up to the code generator to generate a unique label  suitable  for
  1480.           the target assembler.
  1481.     
  1482.              The "def_literal(*ptr, size)" function is called at the end  of
  1483.           the  compile,  just  before  non-initialized  global  symbols  are
  1484.           generated. This routine is  given  a  pointer  to  the  compiler's
  1485.           "literal pool", which contains all the character strings  occuring
  1486.           during the compilation. The "size" parameter  indicates  how  many
  1487.           characters are in the pool. This pool must  be  generated  in  the
  1488.           output file as a string of byte constants.
  1489.     
  1490.              The "call(token, value,  type,  clean)"  function  is  used  to
  1491.           generate  a  machine  language  subroutine  call  to  the   entity
  1492.           indicated by the "token, value & type" parameters (See later). The
  1493.           "clean" parameter indicates how many entries were pushed onto  the
  1494.           stack as arguments, which should be removed following the function
  1495.           call.  Note:  Since  stack  entries  are   TWO   bytes   in   most
  1496.           implementations, the "clean" value must be multiplied  by  two  to
  1497.           get the actual number of bytes to be removed from the stack.
  1498.     MICRO-C                                                          Page: 30
  1499.  
  1500.  
  1501.              The function "jump(label,  ljmp)"  is  called  to  generate  an
  1502.           unconditional jump instruction to the indicated compiler generated
  1503.           label. The "ljmp" flag will be set to zero if the jump  references
  1504.           code within the same expression from which it  is  generated,  and
  1505.           non-zero if one or more statements may occur between the jump  and
  1506.           the destination label. This allows  the  code  generator  to  take
  1507.           advantage of "short" jumps if they are available on the target.
  1508.     
  1509.              The function "jump_if(cond, label, ljmp) is called to  generate
  1510.           a conditional jump to a compiler generated label. The "cond" value
  1511.           indicates the condition: FALSE = Jump if accumulator is zero, TRUE
  1512.           = jump if accumulator is non-zero. Remaining  parameters  are  the
  1513.           same as above.
  1514.     
  1515.              The function "do_switch(label)" is  passed  the  address  of  a
  1516.           "switch" table, which contains 16  bit  entries,  and  is  of  the
  1517.           following format:
  1518.     
  1519.                         label-1, value-1, label-2, value-2, ....
  1520.                         label-n, value-n, 0, default_label
  1521.     
  1522.              This routine should search the table for the value currently in
  1523.           the accumulator, and if found, it  should  proceed  to  the  label
  1524.           associated with that value. If the value is not found  before  the
  1525.           end of the table is encountered (identified by a  label  value  of
  1526.           zero), execution should  proceed  at  the  address  identified  by
  1527.           "default_label".
  1528.     
  1529.              The "index_ptr(token, value, type)"  routine  should  load  the
  1530.           index register with the value  of  the  entity  indicated  by  the
  1531.           "token, value & type" parameters. This will always  be  a  16  bit
  1532.           wide quantity.
  1533.     
  1534.              The "index_adr(token, value, type)"  routine  should  load  the
  1535.           index register with the 16 bit address of the  symbol  represented
  1536.           by "token, value & type".
  1537.     
  1538.              The routine "expand(type)" is called following  the  evaluation
  1539.           of expressions in "return" and "switch" statements, and is used to
  1540.           insure that the result is a 16 bit value.
  1541.     
  1542.              The routine "accop(oper, type)" is  called  to  perform  a  "no
  1543.           operand" operation on the accumulator. See "compile.h" for a  list
  1544.           of these operations. The "type" passed indicates the type of value
  1545.           expected as a result.
  1546.     
  1547.              The routine "accval(oper, rtype, token, value, type)" is called
  1548.           to perform a "one  operand"  operation  on  the  accumulator.  See
  1549.           "compile.h" for a list of these operations. "rtype" indicates  the
  1550.           type of value expected as a result. "token",  "value"  and  "type"
  1551.           indicate  the  location  and  type  of  operand  which  is   being
  1552.           processed.
  1553.     MICRO-C                                                          Page: 31
  1554.  
  1555.  
  1556.           4.2.1 Notes on code generation
  1557.     
  1558.                 The meaning of the individual bits  in  the  16  bit  "type"
  1559.              value which is passed to many of the code generation  routines,
  1560.              is documented in the "compile.h" file.
  1561.     
  1562.                 The meaning of "token"  is  documented  in  the  "compile.h"
  1563.              file. For  each  type  of  "token",  "value"  has  a  different
  1564.              meaning:
  1565.     
  1566.                 Token           Meaning of "value"
  1567.                 ----------------------------------------------------------
  1568.                 NUMBER          The numeric value of the constant.
  1569.                 STRING          The offset into the literal pool.
  1570.                 LABEL           The value of the compiler generated label.
  1571.                 SYMBOL          Index into global symbol tables.
  1572.                 All others      Undefined.
  1573.     
  1574.                 When token is a SYMBOL, the "value" passed is used to  index
  1575.              into the global symbol tables (contained within  the  "compile"
  1576.              module) to determine information about the variable:
  1577.     
  1578.                 s_name[value]   - Name of symbol (up to SYMBOL_SIZE characters).
  1579.                 s_type[value]   - Type of symbol (bits defined in "compile.h").
  1580.                 s_index[value]  - Variable index:
  1581.                     Global:     Index indicates symbol was the n'th one defined.
  1582.                     Local:      Index is stack offset from def_func.
  1583.                     Argument:   Index is stack offset from last argument pushed.
  1584.     
  1585.                 When calculating the stack offset for  ARGUMENTs,  you  must
  1586.              add the number of bytes placed on the stack when  the  function
  1587.              was called. This  includes  the  local  variables,  the  return
  1588.              address, and any other values that "def_func" might push.
  1589.     
  1590.                 There are two popular ways of  providing  addressability  to
  1591.              local variables:
  1592.     
  1593.                 If the processor has many registers, you can reserve one  as
  1594.              a "base" pointer, and point it at the top of the stack when the
  1595.              function  is  entered.  This  allows  local  variables  to   be
  1596.              referenced as negative offsets from that "base"  register,  and
  1597.              arguments to be referenced as positive offsets  from  it.  This
  1598.              approach also allows the stack to  be  restored  directly  from
  1599.              this base  register  when  the  function  terminates.  See  the
  1600.              section on assembly language interfacing.
  1601.     
  1602.                 Another approach is to have the  code  generator  "remember"
  1603.              exactly how many bytes have been pushed onto  the  stack  since
  1604.              "def_func", and adjust the offsets it generates  based  on  the
  1605.              stack contents. This has  the  advantage  of  not  tying  up  a
  1606.              register.
  1607.     MICRO-C                                                          Page: 32
  1608.  
  1609.  
  1610.                 If you intend to use the MICRO-C Source Linker (SLINK), then
  1611.              you have to insure that whatever variable you use to  reference
  1612.              the "literal pool" qualifies as a "compiler  generated"  label,
  1613.              allowing SLINK to adjust it when processing the  source  files.
  1614.              Compiler  generated  labels  normally  consist  of   a   single
  1615.              character (usually '?'), followed by a  decimal  number.  Since
  1616.              the compiler begins generating its labels with the  value  '1',
  1617.              you may safely use '0' as the literal pool variable (Ie: '?0').
  1618.     
  1619.                 It is the responsibility of the code generator to keep track
  1620.              of the validity  of  the  upper  8  bits  of  the  accumulator.
  1621.              Appropriate sign extension or clearing of  high  bits  must  be
  1622.              performed as necessary to convert signed and unsigned character
  1623.              values when 16 bit results when required.
  1624.     
  1625.                 To improve the effiency of conditional statements, the  code
  1626.              generator should keep track of the validity of the "zero"  flag
  1627.              in  the  processor's  condition  code  register,  and  generate
  1628.              appropriate  "test"  instructions  only  if  necessary  when  a
  1629.              conditional jump is compiled.
  1630.     
  1631.                 For  processors  not  supporting   operations   with   stack
  1632.              contents, the "ON_STACK" and "ION_STACK" tokens may implemented
  1633.              by first popping the top of the  stack  into  a  register.  The
  1634.              "ISTACK_TOP" token is a special case, because  the  address  on
  1635.              the top of the stack must  not  be  lost.  This  token  may  be
  1636.              efficiently implemented, because "ISTACK_TOP" is only used  for
  1637.              read/write operations to  a  stacked  calculated  address.  For
  1638.              example:
  1639.     
  1640.                             array1[i] += array2[i];
  1641.     
  1642.                 This statement calculates the address of "array1[i]" (in the
  1643.              index register). Since the "index" register is  again  used  in
  1644.              calculating the address of "array2[i]", the first "index"  will
  1645.              be placed on the stack. Once the contents  of  "array2[i]"  are
  1646.              retrieved, it  will  be  added  using  "ISTACK_TOP",  and  then
  1647.              re-stored using "ION_STACK".
  1648.     
  1649.                 The "ISTACK_TOP" token may  thus  pop  the  address  into  a
  1650.              register, and set a flag indicating to the code generator  that
  1651.              the next "ION_STACK" token  is  to  go  through  that  register
  1652.              rather than the top of the stack. Note that since an arithmetic
  1653.              operation may be performed between the two references, you must
  1654.              not use a register which is  modified  in  code  generated  for
  1655.              arithmetic operations.
  1656.     
  1657.                 Refer to the sample code  generators  distributed  with  the
  1658.              compiler.
  1659.     MICRO-C                                                          Page: 33
  1660.  
  1661.  
  1662.        4.3 The "compile" module
  1663.     
  1664.              The "compile" module  contains  the  main  statement  analyser,
  1665.           input  scanner,  expression  parser  and  symbol  table  managment
  1666.           routines for the MICRO-C compiler. This module is  common  to  all
  1667.           implementations, and should NOT require any  changes.  The  source
  1668.           code for this module is contained in the "compile.c" file on  your
  1669.           distribution diskette, and may be examined for  insight  into  the
  1670.           internal operation of the compiler.
  1671.     
  1672.              This module must be compiled and linked with your I/O and  code
  1673.           generation routines to  generate  a  complete  executable  MICRO-C
  1674.           compiler.
  1675.     
  1676.              To test your code generator,  the  file  "test.c"  is  provided
  1677.           which when compiled using the new compiler, performs a  number  of
  1678.           simple tests  to  verify  your  code  generator.  This  is  not  a
  1679.           comprehensive analysis, as  it  makes  no  assumptions  about  the
  1680.           processor, however, it provides a good indication that  your  code
  1681.           generator is on the right track.
  1682.     
  1683.              A number of fixed parameters to the  compiler  (such  as  table
  1684.           sizes etc.) are contained in the header file "compile.h". The most
  1685.           common reason for changing  these  parameters  is  to  reduce  the
  1686.           memory requirements, in order to get  MICRO-C  to  fit  into  very
  1687.           small systems.
  1688.     
  1689.              If any of the parameters in "compile.h" are to be changed,  you
  1690.           must  make  the  changes  BEFORE  compiling  any  of  the  modules
  1691.           (compile, io or codegen).
  1692.     
  1693.              The file  "tokens.h"  contains  symbolic  definitions  for  the
  1694.           tokens parsed by the  compiler,  the  text  of  which  is  in  the
  1695.           character array variable "tokens". If you make any changes to this
  1696.           token table, MAKE SURE that the contents of the "tokens"  variable
  1697.           and the "tokens.h" file agree, otherwise, you will end up  with  a
  1698.           compiler for a very strange language.
  1699.     MICRO-C                                                          Page: 34
  1700.  
  1701.  
  1702.        4.4 Porting without a compiler
  1703.     
  1704.              If you have the MICRO-C  distribution  files,  but  no  running
  1705.           compiler,  it  is  still  possible  to  port  MICRO-C,  using  the
  1706.           following steps:
  1707.     
  1708.           1) You must write the code generator and I/O routines  in  another
  1709.              language. Using assembly language is  preferable,  because  you
  1710.              can then follow the MICRO-C function calling  conventions  (See
  1711.              "Assembly Language Interface  under  "Advanced  Topics").  This
  1712.              allows you to use the same routines with the compiler later.
  1713.     
  1714.           2) The "genasm.c" program should then be re-written  in  the  same
  1715.              language as above. This should not be difficult, since it is  a
  1716.              fairly simple program.
  1717.     
  1718.           3) Link "genasm" with your code generator  and  I/O  routines,  to
  1719.              create the "genasm" utility which reads intermediate files  and
  1720.              produces assembly language output.
  1721.     
  1722.           4) The "intermediate"  file  for  the  main  "compile"  module  is
  1723.              provided in the file "compile.i". When this file  is  processed
  1724.              by "genasm", and the resultant file assembled,  you  will  have
  1725.              the "compile" module which may be  linked  with  the  "io"  and
  1726.              "code" modules to produce the final compiler.
  1727.     
  1728.        4.5 Porting without a linker
  1729.     
  1730.              It is possible to port MICRO-C using a system  which  does  not
  1731.           support a linker. To do this, you must concatinate all the  source
  1732.           files "compile.c", "code.c" and "io.c" into  one  large  file  (in
  1733.           that order), and compile them all as one program.
  1734.     
  1735.              When this is done, the ".h" include files need only be included
  1736.           once, and external definitions  of  variables  occuring  in  other
  1737.           source files should not  be  used.  The  source  programs  on  the
  1738.           distribution disk all contain conditional  compilation  statements
  1739.           (#ifndef), which only perform the necessary #include and  external
  1740.           definition statements when compiling as a single file.
  1741.     MICRO-C                                                          Page: 35
  1742.  
  1743.  
  1744.        4.6 Optimization Techniques
  1745.     
  1746.              The MICRO-C compiler performs the following machine independant
  1747.           optimizations of the output file:
  1748.     
  1749.           1) All constant expressions are evaluated  at  compile  time,  and
  1750.              expressed as a single constant value in the output code.
  1751.     
  1752.           2) Operations which are not sensitive to order (eg:  '+')  may  be
  1753.              reversed to take advantage of partial results  already  in  the
  1754.              accumulator.
  1755.     
  1756.           3) Redundant jumps as a result of "return" or  "break"  statements
  1757.              are suppressed.
  1758.     
  1759.           4) The sense of jumps in conditional statements are  reversed  for
  1760.              logically negated expressions, code for '!' is  only  generated
  1761.              if the value returned by that operator is actually used.
  1762.     
  1763.           5) Jumps between code generated within  a  single  expression  are
  1764.              flagged as "short".
  1765.     
  1766.              Although the MICRO-C compiler produces fairly  reasonable  code
  1767.           for the  processor  model  it  uses,  that  model  is  necessarily
  1768.           limited, in order that it might fit a  large  number  of  physical
  1769.           targets. There are  several  simple  optimizations  which  may  be
  1770.           performed to further enhance the code generated by the compiler in
  1771.           a specific implementation.
  1772.     
  1773.           4.6.1 Register Usage
  1774.     
  1775.                 MICRO-C assumes a single accumulator,  and  a  single  index
  1776.              register.  Additional  terms  in  complicated  expressions  are
  1777.              handled by placing temporary results on  the  processor  stack,
  1778.              and re-using those registers. All data placed on the  stack  is
  1779.              accessed on a "last in - first out" basis.
  1780.     
  1781.                 If the target processor has a  full  compliment  of  general
  1782.              purpose registers, an optimization may be performed  by  simply
  1783.              selecting another general purpose register as  the  accumulator
  1784.              or index register instead of placing the value  on  the  stack.
  1785.              The code generator must  keep  track  of  the  order  in  which
  1786.              registers are selected, and which register represents the "top"
  1787.              of the stack. If the number  of  values  "pushed"  exceeds  the
  1788.              number of available registers, the "oldest" register should  be
  1789.              placed on the stack, thereby allowing it to be re-used.
  1790.     MICRO-C                                                          Page: 36
  1791.  
  1792.  
  1793.           4.6.2 Jump Optimization
  1794.     
  1795.                 Although MICRO-C identifies jumps to instructions which span
  1796.              more than one expression as "long",  often  the  addresses  are
  1797.              close enough together that short jumps may  actually  be  used.
  1798.              This optimization is particularily useful for  processors  such
  1799.              as the 8086, which does not support "long"  conditional  jumps,
  1800.              and therefore must simulate them with a short conditional  jump
  1801.              of the opposite sense around a long unconditional jump.
  1802.     
  1803.           4.6.3 Redundant Load Elimination
  1804.     
  1805.                 Since  MICRO-C  evaluates  and  processes   each   statement
  1806.              individually, it  does  not  carry  partial  results  from  one
  1807.              statement to another.
  1808.     
  1809.                 Consider the following statements:
  1810.     
  1811.                                  a = x;
  1812.                                  b = a + 1;
  1813.     
  1814.                 MICRO-C generates the code:
  1815.     
  1816.                                  LOAD x
  1817.                                  STORE a
  1818.                                  LOAD a
  1819.                                  ADD 1
  1820.                                  STORE b
  1821.     
  1822.                 An optimization may be performed  by  recognizing  that  the
  1823.              second "load" instruction is redundant, and can be  eliminated.
  1824.              Note: A more efficent (but less readable)  way  of  coding  the
  1825.              above statements which would result in the latter code  without
  1826.              optimization is:
  1827.     
  1828.                                  b = (a = x) + 1;
  1829.     MICRO-C                                                          Page: 37
  1830.  
  1831.  
  1832.           4.6.4 Peephole Optimization
  1833.     
  1834.                 Consider the statement:
  1835.     
  1836.                                  a = *++ptr;
  1837.     
  1838.                 MICRO-C generates the code:
  1839.     
  1840.                                  LOAD ptr
  1841.                                  INCREMENT
  1842.                                  STORE ptr
  1843.                                  MOVE ACCUMULATOR TO INDEX
  1844.                                  LOAD [INDEX]
  1845.                                  STORE a
  1846.     
  1847.                 For a processor supporting  a  rich  set  of  direct  memory
  1848.              addressing modes, the above sequence can be shortened to:
  1849.     
  1850.                                  INCREMENT_MEMORY ptr
  1851.                                  LOAD [ptr]
  1852.                                  STORE a
  1853.     
  1854.                 One of the most  successful  techniques  of  optimizing  the
  1855.              output code is also one of the simplest.  Known  as  "peephole"
  1856.              optimization, the method consists of keeping a  window  of  the
  1857.              last few instructions generated,  and  scanning  the  list  for
  1858.              known patterns every time a new instruction is added to it.
  1859.     
  1860.                 As long as the instructions in the list at  least  partially
  1861.              match one or more  of  the  "predefined"  patterns,  additional
  1862.              instructions are collected  until  either  a  complete  pattern
  1863.              match occurs, or all known patterns are eliminated.
  1864.     
  1865.                 If no matches occur, the "oldest" instruction is written  to
  1866.              the output file, and the next one  becomes  the  first  in  the
  1867.              "window".
  1868.     
  1869.                 Whenever a pattern is discovered, it is replaced  by  a  new
  1870.              series of instructions which perform the same function, but  in
  1871.              a more efficent manner.
  1872.     
  1873.                 The new instruction sequences  are  replaced  on  the  list,
  1874.              which may then be  again  scanned,  allowing  further  possible
  1875.              reductions to be discovered.
  1876.     
  1877.                 Handling of labels in the "window" and  their  corresponding
  1878.              placement in the output file must be carefully done,  in  order
  1879.              to preserve the "logical" context of the original code.
  1880.     MICRO-C                                                          Page: 38
  1881.  
  1882.  
  1883.     5. THE MICRO-C PREPROCESSOR
  1884.     
  1885.           The MICRO-C Preprocessor is a source code filter,  which  provides
  1886.        greater capabilities than the preprocessor which is integral  to  the
  1887.        MICRO-C compiler. It has been implemented as a  stand  alone  utility
  1888.        program which processes the source code before it is compiled.
  1889.     
  1890.           Due to the higher complexity of  this  preprocessor,  it  operates
  1891.        slightly slower than the the integral MICRO-C preprocessor.  This  is
  1892.        mainly due to the fact that it reads each line from the file and then
  1893.        copies it to a new line while performing the macro substitution. This
  1894.        is necessary since each macro may contain parameters  which  must  be
  1895.        replaced "on the fly" when it is referenced.
  1896.     
  1897.           The integral MICRO-C preprocessor is very FAST,  because  it  does
  1898.        not copy the input line. When it encounters a '#define'd  symbol,  it
  1899.        simply adjusts the input scanner pointer to point to  the  definition
  1900.        of that symbol.
  1901.     
  1902.           Keeping the extended preprocessor as a stand alone utility  allows
  1903.        you  to  choose  between  greater   MACRO   capability   and   faster
  1904.        compilation. It also allows the system to continue  to  run  on  very
  1905.        small hardware platforms.
  1906.     
  1907.           The additional capabilities of the extended preprocessor are:
  1908.     
  1909.             - Parameterized MACROs.
  1910.     
  1911.             - Nested conditionals.
  1912.     
  1913.             - Ability to undefine MACRO symbols.
  1914.     
  1915.             - Library reference in include file names.
  1916.     MICRO-C                                                          Page: 39
  1917.  
  1918.  
  1919.        5.1 The MCP command
  1920.     
  1921.              The format of the MICRO-C Preprocessor command line is:
  1922.     
  1923.                     MCP [input_file] [output_file] [options]
  1924.     
  1925.              [input_file] is the name of  the  source  file  containing  'C'
  1926.           statements to read. If no filenames are given, MCP will read  from
  1927.           standard input.
  1928.     
  1929.              [output_file] is the name of the file to  write  the  processed
  1930.           source code to. If less than two filenames are specified, MCP will
  1931.           write to standard output.
  1932.     
  1933.           5.1.1 Command Line Options
  1934.     
  1935.                 MCP accepts the following command line [options]:
  1936.     
  1937.                 -c      - Instructs MCP to keep comments from  the input
  1938.                           file (except for those in '#' statements which
  1939.                           are always removed). Normally, MCP will remove
  1940.                           all comments.
  1941.     
  1942.                 l=path  - Defines the directory path which will be taken
  1943.                           to reference  "library"  files when  '<>'  are
  1944.                           used around an  '#include'  file name.  Unless
  1945.                           otherwise specified, the path defaults to:
  1946.                                         '/mc'
  1947.     
  1948.                 -q      - Instructs MCP to be quiet, and not display the
  1949.                           startup message when it is executed.
  1950.     
  1951.         <name>=<text>   - Pre-defines a non-parameterized macro  of  the
  1952.                           specified <name> with the string value <text>.
  1953.     MICRO-C                                                          Page: 40
  1954.  
  1955.  
  1956.        5.2 Preprocesor Commands
  1957.     
  1958.              The following commands are recognized by the MCP utility,  only
  1959.           if they occur at the beginning of the source file line:
  1960.     
  1961.           5.2.1 #define <name>(parameters) <replacement text>
  1962.     
  1963.                 Defines a global macro name which will be replaced with  the
  1964.              indicated <replacement text> wherever it occurs in  the  source
  1965.              file.
  1966.     
  1967.                 Macro  names  may  be  any  length,  and  may  contain   the
  1968.              characters 'a'-'z', 'A'-'Z', '0'-'9' and '_'.  Names  must  not
  1969.              begin with the characters '0'-'9'.
  1970.     
  1971.                 If the macro name is IMMEDIATELY followed by a list of up to
  1972.              10 parameter names contained in brackets, those parameter names
  1973.              will be substituted with parameters passed to the macro when it
  1974.              is referenced. Parameter names follow the same rules  as  macro
  1975.              names.
  1976.     
  1977.                      eg: #define min(a, b) (a < b ? a : b)
  1978.     
  1979.                 If any spaces exist between the macro name and  the  opening
  1980.              '(', the macro will not be  parameterized,  and  all  following
  1981.              text (including '(' and ')') will be  entered  into  the  macro
  1982.              definition.
  1983.     
  1984.           5.2.2 #undef <symbol>
  1985.     
  1986.                 Undefines the named macro symbol. further references to this
  1987.              symbol will not be replaced.
  1988.     
  1989.                 NOTE: With MCP, macro definitions operate on a STACK. IE: If
  1990.              you define a macro  symbol,  and  then  re-define  it  (without
  1991.              '#undef'ing it first), subsequently '#undef'ing it  will  cause
  1992.              it to revert to its  previous  definition.  A  second  '#undef'
  1993.              would then cause it to be completely undefined.
  1994.     
  1995.           5.2.3 #forget <symbol>
  1996.     
  1997.                 Similar  to  '#undef',  except  that  the  symbol  and   ALL
  1998.              SUBSEQUENTLY DEFINED SYMBOLS will be undefined.
  1999.     
  2000.                 Useful for releasing any local symbols (used only  within  a
  2001.              single include file).
  2002.     
  2003.                 For example:
  2004.     
  2005.                         #define GLOBAL "xxx"    /* first global symbol */
  2006.                             ...                 /* more globals */
  2007.                         #define LOCAL   "xxx"   /* first local symbol */
  2008.                             ...                 /* more locals */
  2009.                         /* body of include file goes here */
  2010.                         #forget LOCAL           /* release locals */
  2011.     MICRO-C                                                          Page: 41
  2012.  
  2013.  
  2014.           5.2.4 #ifdef <symbol>
  2015.     
  2016.                 Causes the following lines (up to '#else' of '#endif') to be
  2017.              processed and included in the source file  only  if  the  named
  2018.              symbol is defined as a macro.
  2019.     
  2020.           5.2.5 #ifndef <symbol>
  2021.     
  2022.                 Causes the following lines (up to '#else' of '#endif') to be
  2023.              processed and included in the source file  only  if  the  named
  2024.              symbol is NOT defined as a macro.
  2025.     
  2026.                 NOTE: '#ifdef/#ifndef#else/#endif' may be nested.
  2027.     
  2028.           5.2.6 #else
  2029.     
  2030.                 Toggles the state of the "if_flag", controlling  conditional
  2031.              processing. Only has effect in the highest level  of  suspended
  2032.              processing. IE: Nested conditionals will work properly.
  2033.     
  2034.                 If the previous  '#ifdef/#ifndef'  failed,  processing  will
  2035.              begin again following the '#else'.
  2036.     
  2037.                 If the previous '#ifdef/#ifndef' passed, processing will  be
  2038.              suspended until the '#endif' is encountered.
  2039.     
  2040.                 NOTE: Since '#else' acts as a toggle, it may be used outside
  2041.              of any '#ifdef/#ifndef' to unconditionally  suspend  processing
  2042.              up to '#endif'.
  2043.     
  2044.           5.2.7 #endif
  2045.     
  2046.                 Resets  the  "if_flag"  controlling  conditionals,   causing
  2047.              processing to resume. Only has effect in the highest  level  of
  2048.              suspended  processing.  IE:  Nested  conditionals   will   work
  2049.              properly.
  2050.     MICRO-C                                                          Page: 42
  2051.  
  2052.  
  2053.           5.2.8 #include <filename>
  2054.     
  2055.                 Causes MCP to open the named file and include  its  contents
  2056.              as part of the input source.
  2057.     
  2058.                 If the filename is contained within '"' characters, it  will
  2059.              be opened exactly as  specified,  and  (unless  it  contains  a
  2060.              directory path) will reference a file in the current directory.
  2061.     
  2062.                 If the filename is contained within the characters  '<'  and
  2063.              '>', it will be  prefixed  with  the  library  path  (See  'l='
  2064.              option), and will therefore reference a file  in  that  library
  2065.              directory. The default  library  directory  is  assumed  to  be
  2066.              '/mc'.
  2067.     
  2068.                 For example:
  2069.     
  2070.                         #include "header.h"     /* from current directory */
  2071.                         #include <stdio.h>      /* from library directory */
  2072.     
  2073.           5.2.9 #asm / #endasm
  2074.     
  2075.                 The  '#asm'  and  '#endasm'  statements  are  not   actually
  2076.              recognized by MCP. They are passed through unchanged,  allowing
  2077.              them to be recognized and acted upon by  the  integral  MICRO-C
  2078.              preprocessor.
  2079.     MICRO-C                                                          Page: 43
  2080.  
  2081.  
  2082.        5.3 Error messages
  2083.     
  2084.              When MCP detects an error during processing of an include file,
  2085.           it displays an error message,  which  is  preceeded  by  the  line
  2086.           numbers of the files in which the error occurs. If  more  than  10
  2087.           errors are encountered, MCP will terminate.
  2088.     
  2089.              The following error messages are reported by MCP:
  2090.     
  2091.           5.3.1 Cannot open include file
  2092.     
  2093.                 A '#include' statement on the  indicated  line  specified  a
  2094.              file which could not be opened for reading.
  2095.     
  2096.           5.3.2 Invalid include file name
  2097.     
  2098.                 A '#include' statement on the  indicated  line  specified  a
  2099.              file  name  which  was  not  contained  within  '"'   or   '<>'
  2100.              characters.
  2101.     
  2102.           5.3.3 Invalid macro name
  2103.     
  2104.                 A '#define' statement on the indicated line contains a macro
  2105.              name which does not follow the name rules.
  2106.     
  2107.           5.3.4 Invalid macro parameter
  2108.     
  2109.                 A '#define' statement on the indicated line contains a macro
  2110.              parameter name which does not follow the name rules.
  2111.     
  2112.                 A reference to a macro does not have a proper ')'  character
  2113.              to terminate the parameter list.
  2114.     
  2115.           5.3.5 Too many errors
  2116.     
  2117.                 More  than  10  errors  has  been  encountered  and  MCP  is
  2118.              terminating.
  2119.     
  2120.           5.3.6 Too many macro definitions
  2121.     
  2122.                 MCP has encountered more '#define' statements  than  it  can
  2123.              handle.
  2124.     
  2125.           5.3.7 Too many macro parameters
  2126.     
  2127.                 A '#define' statement on the indicated line  specifies  more
  2128.              parameters to the macro than MCP can handle.
  2129.     
  2130.           5.3.8 Too many include files
  2131.     
  2132.                 MCP has encountered more nested '#include'  statements  than
  2133.              it can handle.
  2134.     MICRO-C                                                          Page: 44
  2135.  
  2136.  
  2137.           5.3.9 Undefined macro
  2138.     
  2139.                 A '#undef' or '#forget'  statement  on  the  indicated  line
  2140.              references a macro name which has not been defined.
  2141.     
  2142.           5.3.10 Unterminated comment
  2143.     
  2144.                 The END OF FILE has  been  encountered  while  processing  a
  2145.              comment.
  2146.     
  2147.           5.3.11 Unterminated string
  2148.     
  2149.                 A quoted string on the indicated line has no end.
  2150.     MICRO-C                                                          Page: 45
  2151.  
  2152.  
  2153.     6. THE MICRO-C OPTIMIZER
  2154.     
  2155.           The MICRO-C optimizer is an output code filter which examines  the
  2156.        assembly code produced by the compiler, recognizing known patterns of
  2157.        inefficent code (using the "peephole" technique), and  replaces  them
  2158.        with more optimal code  which  performs  the  same  function.  It  is
  2159.        entirely table driven, allowing it to be modified for  virtually  any
  2160.        processor.
  2161.     
  2162.           Due its many table lookup operations, the  optimizer  may  perform
  2163.        quite slowly when processing a large  file.  For  this  reason,  most
  2164.        people prefer not to optimize during the debugging of a program,  and
  2165.        utilize the optimizer only when creating the final copy.
  2166.     
  2167.        6.1 The MCO command
  2168.     
  2169.              The format of the MICRO-C Optimizer command line is:
  2170.     
  2171.                     MCO [input_file] [output_file] [options]
  2172.     
  2173.              [input_file] is the name of the source file containing assembly
  2174.           statements to read. If no filenames are given, MCO will read  from
  2175.           standard input.
  2176.     
  2177.              [output_file] is the name of the file to  which  the  optimized
  2178.           assembly code is to be written. If less  than  two  filenames  are
  2179.           specified, MCO will write to standard output.
  2180.     
  2181.           6.1.1 Command Line Options
  2182.     
  2183.                 MCO accepts the following command line [options]:
  2184.     
  2185.                 -d      - Instructs MCO to produce a  'debug' display on
  2186.                           standard output showing the source code  which
  2187.                           it is removing and replacing in the input file.
  2188.                           NOTE: If you do not specify an explict  output
  2189.                                 file, you will get the debug  statements
  2190.                                 intermixed with the  optimized  code  on
  2191.                                 standard output.
  2192.     
  2193.                 -q      - Instructs MCO to be quiet, and not display the
  2194.                           startup message when it is executed.
  2195.     MICRO-C                                                          Page: 46
  2196.  
  2197.  
  2198.        6.2 Porting to a new processor
  2199.     
  2200.              The MICRO-C Optimizer is completely table driven, and should be
  2201.           fairly easy to port to a new processor.
  2202.     
  2203.              The peephole optimization table  is  called  'peep_table',  and
  2204.           consists of two  sequential  character  string  entries  for  each
  2205.           optimization.
  2206.     
  2207.              The first is the "take" entry, and  represents  an  instruction
  2208.           sequence which (if found) is to be removed from the  output  file.
  2209.           The second  is  the  "give"  entry,  and  defines  a  sequence  of
  2210.           instructions to be placed in the output file at that  point.  NOTE
  2211.           that due to the way the optimizer removes and replaces instruction
  2212.           in the circular "peephole" buffer, the instructions in the  "give"
  2213.           entry ARE CODED IN REVERSE ORDER.
  2214.     
  2215.              Characters in the "take" entry  with  the  high  bit  set  (eg:
  2216.           '\200','\201') are special characters which represent any variable
  2217.           string which may occur in the instruction sequence,  and  will  be
  2218.           replaced with the same string wherever that  character  occurs  in
  2219.           the "give" entry. If  the  same  special  character  (eg:  '\200')
  2220.           occurs more than once  in  the  "take"  entry,  the  corresponding
  2221.           strings must be exactly the same or else the entire sequence  will
  2222.           not be matched.
  2223.     
  2224.              The processor will stop scanning  a  variable  string  when  it
  2225.           encounters the character which  immediately  follows  the  special
  2226.           character in the "take" entry, or at the end of the input line.
  2227.     
  2228.              The  manifest  SYMBOLS  defines  how  many  different   special
  2229.           characters are allowed in a peephole entry. You must not  use  any
  2230.           special characters which have  a  value  greater  than  ('\200'  +
  2231.           SYMBOLS - 1).
  2232.     MICRO-C                                                          Page: 47
  2233.  
  2234.  
  2235.     7. THE COMMAND CO-ORDINATOR
  2236.     
  2237.           'CC' is a program which co-ordinates the other commands (MCP, MCC,
  2238.        MCO, ASM and LINK),  to  provide  a  simple  "one  step"  compilation
  2239.        command.
  2240.     
  2241.        7.1 The CC command
  2242.     
  2243.              The format of the Command Co-ordinator command line is:
  2244.     
  2245.                               CC <name> [options]
  2246.     
  2247.           7.1.1 Command line options
  2248.     
  2249.                 -a      - produce ASSEMBLER (.ASM) output file
  2250.                 -l      - produce LINKABLE  (.OBJ) output file
  2251.                 -o      - OPTIMIZE the output file (using MCO)
  2252.                 -p      - use the extended PRE-PROCESSOR (MCP)
  2253.                 -q      - QUIET mode (suppress informational messages)
  2254.                 -s      - produce SMALL-MODEL (.EXE) output file
  2255.                 m=mcdir - specify MICRO-C home directory
  2256.                 t=mctmp - specify prefix for TEMPORARY files
  2257.     
  2258.                 When executing the sub-commands, CC will search the  MICRO-C
  2259.              home directory, as well as any  directories  specified  in  the
  2260.              'PATH' environment variable. Libraries are  accessed  from  the
  2261.              MICRO-C home directory only.
  2262.     
  2263.                 The environment variable 'MCDIR' is  examined  to  determine
  2264.              the path to  the  MICRO-C  home  directory.  If  MCDIR  is  not
  2265.              defined, CC will assume the string '\MC'. You may override this
  2266.              directory by using the 'm=' option on the command line.
  2267.     
  2268.                 Intermediate  results  from  each  command  are  stored   in
  2269.              "temporary" files, which are fed as input to the next  command.
  2270.              Temporary files will be deleted once they are no longer needed,
  2271.              except in the case where a command fails.  When  this  happens,
  2272.              any temporary file which  was  being  used  as  input  to  that
  2273.              command will not be deleted, allowing you to examine it for the
  2274.              cause of the error.
  2275.     
  2276.                 The environment variable 'MCTMP' is examined to determine  a
  2277.              prefix to prepend to temporary file  names.  If  MCTMP  is  not
  2278.              defined, CC assumes the default prefix of '$'. You may override
  2279.              this prefix by using the 't=' option on the command line.
  2280.     
  2281.                 Here are example 'SET' commands suitable  for  inclusion  in
  2282.              the AUTOEXEC.BAT file, of an IBM/PC based MICRO-C system  which
  2283.              has the home directory in 'C:\MC', and a RAMDISK as drive 'D':
  2284.     
  2285.                     SET MCDIR=C:\MC
  2286.                     SET MCTMP=D:\$
  2287.     MICRO-C                                                          Page: 48
  2288.  
  2289.  
  2290.                 The '-p' option causes the extended pre-processor  (MCP)  to
  2291.              be used. This provides greater pre-processor capability, at the
  2292.              expense of longer compile time.
  2293.     
  2294.                 NOTE: If any compiler errors occur when using  this  option,
  2295.              the line numbers contained in the error messages will refer  to
  2296.              the temporary file containing the output from the pre-processor
  2297.              ($<name>.CP). You must examine this file in order to  determine
  2298.              the actual cause of the error.
  2299.     
  2300.                 The '-o' option causes the optimizer (MCO) to be used, which
  2301.              results in more efficent code, at the expense of longer compile
  2302.              time.
  2303.     
  2304.                 The '-a' option  causes  CC  to  bypass  the  assembler  and
  2305.              linker, and produce an assembly source file (<name>.ASM) as the
  2306.              output file.
  2307.     
  2308.                 The '-l' option causes CC to  bypass  the  link  stage,  and
  2309.              produce a linkable object module  (<name>.OBJ)  as  the  output
  2310.              file.
  2311.     
  2312.                 The '-s' option causes CC to  link  the  program  using  the
  2313.              SMALL  memory  model,   and   produce   an   executable   image
  2314.              (<name>.EXE) as the output file. This option  applies  only  to
  2315.              those  processors  which  have  a  segmented  architecture  and
  2316.              multiple memory models such as the 8086.
  2317.     
  2318.                 If none of '-a', '-l' or '-s' is specified, CC will link the
  2319.              program using the TINY memory  model,  and  produce  a  command
  2320.              image (<name>.COM) as the output file.
  2321.     
  2322.        7.2 Using multiple object modules
  2323.     
  2324.              The 'LC' command file takes one or more object modules produced
  2325.           by 'CC' with the '-l' option, and links them with the libraries to
  2326.           produce an executable module. This module will be given  the  name
  2327.           of the first file specified in the argument list.
  2328.     
  2329.              When compiling large programs which have more than  one  source
  2330.           file, you must first compile all modules using 'CC' with the  '-l'
  2331.           option, and the use 'LC' to link the resultant object  files  into
  2332.           the final executable program.
  2333.     
  2334.              The '-s' option may be used as the FIRST argument, to cause  LC
  2335.           to link in the SMALL model (8086 only).
  2336.                 eg: CC FIRST -l
  2337.                     CC SECOND -l
  2338.                     LC FIRST SECOND         <-- TINY  Model
  2339.                     LC -s FIRST SECOND      <-- SMALL Model
  2340.     
  2341.              The exact syntax and options available for 'CC'  and  'LC'  may
  2342.           differ in different  implementations  of  the  compiler.  See  the
  2343.           'READ.ME' file on your distribution disk for details.
  2344.     MICRO-C                                                          Page: 49
  2345.  
  2346.  
  2347.     8. THE MAKE UTILITY
  2348.     
  2349.           The MAKE utility provides a method of automating the  building  of
  2350.        larger programs consisting of more that one object module.  The  main
  2351.        benefit of MAKE is that it keeps track of the files that each  module
  2352.        is dependant on, and will rebuild a module if any of those files have
  2353.        been modified since  the  module  was  last  built.  This  frees  the
  2354.        programmer from  the  task  of  remembering  which  files  have  been
  2355.        changed, and the commands needed to rebuild the dependant modules.
  2356.     
  2357.        8.1 MAKEfiles
  2358.     
  2359.              To use MAKE, you must first create a MAKEFILE, which is a  text
  2360.           file containing entries for each module in the program. Each entry
  2361.           consists of a DEPENDANCY list, and a series of COMMANDS.
  2362.     
  2363.           8.1.1 MAKEfile Entries
  2364.     
  2365.                 A dependency list in MAKE is a line which contains the  name
  2366.              of the module, followed by a ':', followed by the names of  any
  2367.              files on which it depends. The module name MUST begin in column
  2368.              1.
  2369.     
  2370.                 When MAKE is invoked, it will process each dependancy  list,
  2371.              and  will  execute  any  following  commands  (up  to   another
  2372.              dependancy list) if (1) the module does not exist,  or  (2)  if
  2373.              any of the files to the right of the ':' have a timestamp which
  2374.              is later than that of the module. For example:
  2375.     
  2376.                 main.obj : main.c main.h \\mc\\stdio.h
  2377.                     \\mc\\mcc main.c main.asm
  2378.                     masm/ml main;
  2379.                     -del main.asm
  2380.     
  2381.                 In the above example, the  'main.obj'would  be  rebuilt  (by
  2382.              compiling and assembling 'main.c') if either it did not already
  2383.              exist, or any of 'main.c', 'main.h' or '\mc\stdio.h' was  found
  2384.              to have a later timestamp.
  2385.     
  2386.                 The '-' preceeding the 'del' command prevents it from  being
  2387.              displayed. Unless the '-q' option is enabled, MAKE will display
  2388.              any commands not preceeded by '-' as they are executed.
  2389.     
  2390.                 NOTE: To enter a single '\' in the MAKEFILE,  you  must  use
  2391.              '\\', this is because like 'C',  MAKE  uses  '\'  to  "protect"
  2392.              special  characters  which  otherwise  are  used  for   special
  2393.              functions (such as '\', '$' and '#'). The first '\'  "protects"
  2394.              the second one, allowing it to pass through as source text.
  2395.     MICRO-C                                                          Page: 50
  2396.  
  2397.  
  2398.           8.1.2 Macro Substitutions
  2399.     
  2400.                 Sometimes in a MAKEFILE, you have a single file or directory
  2401.              path that you use  over  and  over  again.  If  it  is  a  long
  2402.              directory path, this may  involve  a  lot  of  typing,  and  it
  2403.              becomes inconvenient to change that name (if you want to use  a
  2404.              different directory etc.) because it is repeated many times.
  2405.     
  2406.                 MAKE includes a MACRO facility, which allows you  to  define
  2407.              variable names which will be replaced with a text  string  when
  2408.              used in subsequent MAKEfile lines. Names are defined by placing
  2409.              them in the MAKEfile, followed by '=',  and  the  text  string.
  2410.              Macro names being defined MUST begin in  column  one,  and  may
  2411.              consist of the characters ('a'-'z', 'A'-'Z', '0'-'9', and '_').
  2412.     
  2413.                 Whenever MAKE encounters a '$' in the  file,  it  takes  the
  2414.              name immediately following, and performs the macro replacement:
  2415.     
  2416.                 mcdir = \\mc
  2417.                 main.obj : main.c main.h $mcdir\\stdio.h
  2418.                     $mcdir\\mcc main.c main.asm
  2419.                     masm/ml main;
  2420.                     del main.asm
  2421.     
  2422.     
  2423.                 When a macro name is immediately  followed  by  alphanumeric
  2424.              text, use a single '\' to  separate  it  from  the  text.  This
  2425.              "protects"  the  first  character  of  the  text   from   being
  2426.              interpreted as part of the macro name:
  2427.     
  2428.                 mcdir = \\mc\\
  2429.                 main.obj : main.c main.h $mcdir\stdio.h
  2430.                     $mcdir\mcc main.c main.asm
  2431.                     masm/ml main;
  2432.                     del main.asm
  2433.     
  2434.                 There  are  several  predefined  macro  symbols  which   are
  2435.              available:
  2436.     
  2437.     
  2438.                 $*      = The full name of the dependant module (name.type).
  2439.                 $@      = The name only of the dependany module.
  2440.                 $.      = The full name of each file in the dependancy list,
  2441.                           separated from each other by a single space.
  2442.                 $,      = The full name of each file in the dependancy list,
  2443.                           separated from each other by a single comma.
  2444.                 $:      = The name only of each file in the dependancy list,
  2445.                           separated from each other by a single space.
  2446.                 $;      = The name only of each file in the dependancy list,
  2447.                           separated from each other by a single comma.
  2448.     MICRO-C                                                          Page: 51
  2449.  
  2450.  
  2451.                 File names in the dependancy list which are preceeded by '-'
  2452.              will not be included in the '$. $, $: $;' macro expansions:
  2453.     
  2454.                 mcdir = \\mc
  2455.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  2456.                     $mcdir\\mcc $. $@.ASM
  2457.                     masm/ml $@;
  2458.                     del $@.ASM
  2459.     
  2460.           8.1.3 MAKEfile Comments
  2461.     
  2462.                 Whenever MAKE encounters the '#' character in the  MAKEFILE,
  2463.              it treats the remainder of the line as a comment, and does  not
  2464.              process it:
  2465.     
  2466.                 # Define Directories
  2467.                 mcdir = \\mc
  2468.     
  2469.                 # Build the MAIN module
  2470.                 main.obj : main.c -main.h -$mcdir\\stdio.h  # Dependants
  2471.                     $mcdir\\mcc $. $@.ASM                   # Compile
  2472.                     masm/ml $@;                             # Assemble
  2473.                     del $@.ASM                              # Delete tmp
  2474.     
  2475.           8.1.4 Ordering the MAKEfile
  2476.     
  2477.                 MAKE processes the MAKEfile is sequential fashion, with  the
  2478.              entries near the top being processed before  the  entries  near
  2479.              the bottom. To insure that each module is built  properly,  any
  2480.              files appearing in the dependancy list for a module  which  are
  2481.              themselves dependant  on  other  files,  should  have  MAKEfile
  2482.              entries which occur BEFORE the entries for  the  modules  which
  2483.              are dependant on them:
  2484.     
  2485.                 # Define Directories
  2486.                 mcdir = \\mc
  2487.                 # Build the MAIN module
  2488.                 main.obj : main.c -main.h -$mcdir\\stdio.h
  2489.                     $mcdir\\mcc $. $@.ASM
  2490.                     masm/ml $@;
  2491.                     del $@.ASM
  2492.                 # Build the SUB module
  2493.                 sub.obj : sub.c -sub.h
  2494.                     $mcdir\\mcc $. $@.ASM
  2495.                     masm/ml $@;
  2496.                     del $@.ASM
  2497.                 # Bind the executable file
  2498.                 # NOTE: If either of the above modules is rebuilt,
  2499.                 #       this entry will be guarenteed to execute.
  2500.                 main.exe : main.obj sub.obj
  2501.                     LINK $:;
  2502.     MICRO-C                                                          Page: 52
  2503.  
  2504.  
  2505.        8.2 Directives
  2506.     
  2507.              Like 'C', MAKE recognizes several "directives" in the MAKEfile.
  2508.           These  directives  are  only  recognized  if  they  occur  at  the
  2509.           beginning of the input line:
  2510.     
  2511.           8.2.1 @include <filename>
  2512.     
  2513.                 This command causes the indicated file to be opened and read
  2514.              in as the source  text.  When  the  end  of  the  new  file  is
  2515.              encountered, processing will continue with the  line  following
  2516.              "@include" in the original MAKEfile.
  2517.     
  2518.           8.2.2 @ifdef <name>
  2519.     
  2520.                 Processes the following lines (up to @else of  @endif)  only
  2521.              if the given MACRO name is defined. NOTE: <name> should not  be
  2522.              preceeded by '$', otherwise its CONTENTS will be tested.
  2523.     
  2524.           8.2.3 @ifndef <name>
  2525.     
  2526.                 Processes the following lines (up to @else of  @endif)  only
  2527.              if the given MACRO name is NOT defined.
  2528.     
  2529.           8.2.4 @ifeq <word1> <word2>
  2530.     
  2531.                 Processes the following lines (up to @else of  @endif)  only
  2532.              if the following two words match exactly. This  is  useful  for
  2533.              testing the value of a defined MACRO symbol.
  2534.     
  2535.           8.2.5 @ifne <word1> <word2>
  2536.     
  2537.                 Processes the following lines (up to @else or  @endif)  only
  2538.              if the following two words do not match.
  2539.     
  2540.           8.2.6 @else
  2541.     
  2542.                 Processes the following lines (up to  @endif)  only  if  the
  2543.              preceeding @ifdef, @ifndef, @ifeq or @ifne was false.
  2544.     
  2545.           8.2.7 @endif
  2546.     
  2547.                 Terminates @ifdef, @ifndef, @ifeq and @ifne.
  2548.     
  2549.           8.2.8 @type <text>
  2550.     
  2551.                 Displays the following text.
  2552.     
  2553.           8.2.9 @abort [text]
  2554.     
  2555.                 Terminates MAKE with an 'Aborted!' message. Any text on  the
  2556.              remainder of the line will be appended to the message.
  2557.     MICRO-C                                                          Page: 53
  2558.  
  2559.  
  2560.        8.3 The MAKE command
  2561.     
  2562.              The format of the MAKE command line is:
  2563.     
  2564.                            MAKE [makefile] [options]
  2565.     
  2566.              [makefile] is the name of the MAKEfile to process. If  no  name
  2567.           is given, MAKE assumes the default name 'MAKEFILE'.
  2568.     
  2569.           8.3.1 Command Line Options
  2570.     
  2571.                 MAKE accepts the following command line [options]:
  2572.     
  2573.                 -d      - Instructs MAKE to operate in "debug" mode, and
  2574.                           display the commands which it  would  execute,
  2575.                           without actually executing them. This provides
  2576.                           a method of quickly testing the MAKEFILE.
  2577.     
  2578.                 -q      - Instructs MAKE to be quiet, and not display the
  2579.                           informational messages and commands executed as
  2580.                           it progresses.
  2581.     
  2582.         <name>=<text>   - Pre-defines a macro  of  the  specified  <name>
  2583.                           with the string value  <text>.  This  OVERRIDES
  2584.                           any definition within the MAKEfile,  which  may
  2585.                           be used to establish a "default" value.
  2586.     MICRO-C                                                          Page: 54
  2587.  
  2588.  
  2589.        8.4 The TOUCH command
  2590.     
  2591.              TOUCH is a small utility program which sets  the  timestamp  of
  2592.           one or more files to the current or  specified  time/date.  It  is
  2593.           useful as a  method  of  forcing  MAKE  to  recognize  a  file  as
  2594.           "changed", even when it has not.
  2595.     
  2596.              For example, if  you  had  decided  to  "undo"  several  recent
  2597.           changes by restoring a backup of "main.c", the restored file  will
  2598.           probably have a timestamp which is  older  than  the  last  module
  2599.           which was built. In this case, MAKE would be unaware that the file
  2600.           has changed, and would therefore not rebuild the module.
  2601.     
  2602.              The TOUCH command could then be used to "update" the  timestamp
  2603.           of 'main.c' to the current time, causing MAKE to recognize it as a
  2604.           changed file.
  2605.     
  2606.                                   TOUCH main.c
  2607.     
  2608.              You could also use TOUCH to force rebuilding of several files:
  2609.     
  2610.                            TOUCH main.c sub1.c sub2.c
  2611.     
  2612.              Or even ALL '.C' files:
  2613.     
  2614.                                    TOUCH *.c
  2615.     
  2616.              TOUCH can also be used to set the timestamp of  a  file  to  an
  2617.           arbritrary value, this may be useful  to  PREVENT  a  change  from
  2618.           causing an update:
  2619.     
  2620.                          TOUCH main.c t=0:00 d=31/10/80
  2621.     
  2622.              NOTE: Use of the 't=' or 'd=' parameters to  TOUCH  allows  the
  2623.           possibility that a changed file  will  go  unnoticed.  CAUTION  is
  2624.           advised.
  2625.     MICRO-C                                                          Page: 55
  2626.  
  2627.  
  2628.     9. THE SOURCE LINKER
  2629.     
  2630.           Many small development environments have assemblers which  do  not
  2631.        directly support an object linker. This causes  a  problem  with  'C'
  2632.        development, because the library functions must be  included  in  the
  2633.        source code, with several drawbacks:
  2634.     
  2635.         1)  There is no way to tell which library functions to include,
  2636.             therefore, you must to it manually.
  2637.     
  2638.         2)  'C' library functions must be  re-compiled every  time,  in
  2639.             order to avoid conflict between compiler generated labels.
  2640.     
  2641.         3)  Assembly language library functions must be modified to
  2642.             include the "#asm" and "#endasm" directives.
  2643.     
  2644.           The MICRO-C Source Linker (SLINK) helps overcome  these  problems,
  2645.        by automatically  joining  previously  compiled  (assembly  language)
  2646.        source code from the library to your programs compiler  output.  Only
  2647.        those files containing  functions  which  you  reference  are  joined
  2648.        (Taking into consideration of course  any  functions  called  by  the
  2649.        included library functions etc...). As the files are joined, compiler
  2650.        generated labels are automatically adjusted to be unique within  each
  2651.        file.
  2652.     
  2653.        9.1 The SLINK Command
  2654.     
  2655.              The format of the SLINK command line is:
  2656.     
  2657.                    SLINK [input_file] [output_file] [options]
  2658.     
  2659.              [input_file] is the name of  the  source  file  containing  the
  2660.           compiler output from your program. If no filenames is given, SLINK
  2661.           will read from standard input.
  2662.     
  2663.              [output_file] is the name of  the  file  to  write  the  linked
  2664.           source code to. If less that two filenames are given,  SLINK  will
  2665.           write to standard output.
  2666.     
  2667.           9.1.1 Command line options
  2668.     
  2669.                 SLINK accepts the following command line [options]:
  2670.     
  2671.                 g=char  - Informs SLINK of the lead-in character for
  2672.                           compiler generated symbols.  This defaults
  2673.                           to '?' unless otherwise specified.
  2674.     
  2675.                 -l      - Instructs SLINK to list each  library  file
  2676.                           being included in your program.
  2677.     
  2678.                 l=path  - Identifies the directory path which will be
  2679.                           taken to reference "library" files. If this
  2680.                           path is not specified, it defaults to:
  2681.                                         '/mc/slib'
  2682.     
  2683.                 -q      - Instructs SLINK to be quiet, and not display
  2684.                           the startup message when it is executed.
  2685.     MICRO-C                                                          Page: 56
  2686.  
  2687.  
  2688.        9.2 The External Index File
  2689.     
  2690.              SLINK uses a special file from the library to  determine  which
  2691.           sysmbols are in which files. This files  is  called  the  EXTERNAL
  2692.           INDEX FILE, and is  found  in  the  library  directory  (see  'l='
  2693.           option), under the name "EXTINDEX.LIB".
  2694.     
  2695.              This  file  contains  entries  which  cross-reference  external
  2696.           symbols to files. Each entry is as follows:
  2697.     
  2698.             1)  Any lines beginning with '+' contain the names of files
  2699.                 which are to be processed and included at the beginning
  2700.                 of the program (Before your source file). This the best
  2701.                 way to include the startup code and any runtime library
  2702.                 routines which are required at all times. The files are
  2703.                 included in the order in which they appear in the index
  2704.                 file.
  2705.                     eg: +6809rl.asm
  2706.     
  2707.             2)  Any lines beginning with '-' contain the names of files
  2708.                 which are to  be  included  if  any  of  the  following
  2709.                 symbols (Up to another '+' or '-') are referenced.
  2710.                     eg: -printf.asm format.asm fput.asm
  2711.     
  2712.                 NOTE: In most cases, the library functions will contain
  2713.                 indications of any external references that they do, in
  2714.                 which case SLINK will automatically include those files
  2715.                 even of the names are not mentioned on the '-' line. In
  2716.                 the example above, the following would suffice:
  2717.                         -printf.asm
  2718.     
  2719.             3)  The names  of  each  symbol  which  may  be  referenced
  2720.                 externally must follow the '+'  or  '-' entry.  Symbols
  2721.                 must occur one per line, with no  leading  or  trailing
  2722.                 spaces.
  2723.                     eg: printf
  2724.                         fprintf
  2725.                         sprintf
  2726.     
  2727.             4)  A line beginning with '$' is used to define the pseudo-
  2728.                 opcode used by SLINK to reserve uninitialized  data  at
  2729.                 the end of the output file. One one line beginning with
  2730.                 '$' should be entered into the EXTINDEX.LIB  file.  The
  2731.                 remainder of this line, including all  spaces  etc.  is
  2732.                 entered between each symbol name, and the decimal  size
  2733.                 (in bytes) which is written to the output file.
  2734.                     eg: '$ RMB '    <- Quotes are for clarity
  2735.     MICRO-C                                                          Page: 57
  2736.  
  2737.  
  2738.             A complete example:
  2739.     
  2740.                     +6809rl.asm
  2741.                     -printf.asm
  2742.                     printf
  2743.                     fprintf
  2744.                     sprintf
  2745.                     -scanf.asm
  2746.                     scanf
  2747.                     fscanf
  2748.                     sscanf
  2749.                     $ RMB
  2750.     
  2751.        9.3 Multiple source files
  2752.     
  2753.              SLINK processes only one source  file,  and  resolves  external
  2754.           references only to the library files. This is because  the  public
  2755.           symbol information is available in the EXTINDEX.LIB  files,  which
  2756.           contains no entries for the user supplied programs.
  2757.     
  2758.              If you wish to use source code  linking  for  a  program  which
  2759.           contains multiple source files, use "#include" statements  at  the
  2760.           end if your main program to include all of the other parts into  a
  2761.           single source file.
  2762.     
  2763.        9.4 Source file information
  2764.     
  2765.           9.4.1 Special Comments
  2766.     
  2767.                 SLINK  identifies  external  symbol  references  by  special
  2768.              comments in the input source file. These comments must begin in
  2769.              column one, and are of the form:
  2770.     
  2771.                                  *EXT*<symbol>
  2772.     
  2773.              where <symbol> is the name  of  the  symbol  being  referenced.
  2774.              These  comments  are  placed  into  the  source  file  by   the
  2775.              "def_extern" routine in the MICRO-C code generator.
  2776.     MICRO-C                                                          Page: 58
  2777.  
  2778.  
  2779.                 SLINK also identifies uninitialized  data  area  by  special
  2780.              comments placed in the input source  file.  The  comments  must
  2781.              begin in column one, and are of the form:
  2782.     
  2783.                               *DAT*<symbol> <size>
  2784.     
  2785.              where <symbol> is the name of the symbol used to reference  the
  2786.              data area, and <size> is the number of bytes  to  be  reserved.
  2787.              SLINK will output statements to allocate the data area  at  the
  2788.              very end of the assembly language output  file.  This  prevents
  2789.              the uninitialized data from occupying space within  the  bounds
  2790.              of executable code generated, and thus allows it to be excluded
  2791.              from the image when it is saved to  disk.  These  comments  are
  2792.              placed into the source file by the "def_global" routine in  the
  2793.              MICRO-C code generator.
  2794.     
  2795.                 The reserved data area are  allocated  at  the  end  of  the
  2796.              output file, in the REVERSE order of which they are encountered
  2797.              in the input files. This insures that the FIRST "*DAT*" comment
  2798.              found the LAST symbol name output. This allows you to  place  a
  2799.              "*DAT*" comment at the beginning of the startup file,  and  use
  2800.              it to allocate heap space at the end of all other data.
  2801.     
  2802.                 If you  are  writing  assembly  language  programs  for  the
  2803.              library, be  sure  include  "*EXT*<symbol>"  comments  for  any
  2804.              symbols which  you  externally  reference,  and  "*DAT*<symbol>
  2805.              <size>" comments for any uninitialized data area you  may  wish
  2806.              to allocate. If you wish to place an assembly language  comment
  2807.              on the same line, make sure it is separated from the  remainder
  2808.              of the special comment line  by  at  least  one  space  or  tab
  2809.              character.
  2810.     
  2811.                 Note that since SLINK removes these "special" comments  from
  2812.              the output file, they do not have to be in a form acceptable to
  2813.              the assembler. Ie: if your assembler uses ';' for comments, you
  2814.              don't not have to change the code generator  and  SLINK,  since
  2815.              the assembler will not see the special comments it generates.
  2816.     
  2817.           9.4.2 Compiler generated labels
  2818.     
  2819.                 As it processes each source file, SLINK scans each line  for
  2820.              symbols which consist of the '?' character (See  'g='  option),
  2821.              followed by a number. If it finds such as symbol, it inserts  a
  2822.              two character sequence ranging from 'AA' to  'ZZ'  between  the
  2823.              '?', and the number. This sequence will be incremented for each
  2824.              source file processed,  and  thus  insures  that  the  compiler
  2825.              generated symbols will be unique for each file.
  2826.     
  2827.                 If you  are  writing  assembly  language  programs  for  the
  2828.              library, you must be careful to  avoid  using  identical  local
  2829.              symbols in any of the library files, one way to do this  is  to
  2830.              use symbols which meet the above criteria.
  2831.     MICRO-C                                                          Page: 59
  2832.  
  2833.  
  2834.        9.5 The SINDEX utility
  2835.     
  2836.              SINDEX is a utility  which  assists  in  the  creation  of  the
  2837.           EXTINDEX.LIB file used by SLINK. When you run SINDEX, it  examines
  2838.           all of the '.ASM' files in the current  directory,  and  writes  a
  2839.           EXTINDEX.LIB file which contains a '-' type entry for  each  file,
  2840.           and  external  symbol  entries  for  any  labels  which  it  finds
  2841.           conforming to the 'C' naming conventions (Starts with 'a-z', 'A-Z'
  2842.           or '_', and contains only 'a-z', 'A-Z', '0-9' or '_').
  2843.     
  2844.              Once  you  have  run  SINDEX,  you  must  manually   edit   the
  2845.           EXTINDEX.LIB file, and remove any file or symbol entries which you
  2846.           do not wish to have available as external references, as  well  as
  2847.           change any necessary entries to the '+' type.
  2848.     
  2849.              NOTE: There is no information recorded in the  assembly  source
  2850.           file which indicates that a symbol was  declared  as  "static"  in
  2851.           'C'. For this reason, you must manually remove any  symbols  which
  2852.           you do not want to be accessable as external references,  EVEN  IF
  2853.           THEY WERE ORIGINALLY DECLARED AS "static" IN 'C'.
  2854.     
  2855.              You may instruct SINDEX to search for a file pattern other than
  2856.           '*.ASM' by passing it as a command line parameter.
  2857.     
  2858.                                 eg: SINDEX *.A86
  2859.     MICRO-C                                                          Page: 60
  2860.  
  2861.  
  2862.     10. LIBRARY FUNCTIONS
  2863.     
  2864.           The MICRO-C distribution disk includes the 'C'  and  'ASM'  source
  2865.        code for a number of useful "library" functions. These  routines  may
  2866.        be also be used as "example" programs, providing insight into MICRO-C
  2867.        programming techniques.
  2868.     
  2869.           All functions except for the lowest level I/O routines  are  coded
  2870.        in 'C', and should compile on any MICRO-C system. Note that some  low
  2871.        level functions in the library are written in 'C' using  still  lower
  2872.        level routines. Although this makes the library highly  portable  and
  2873.        reduces the number of routines you have to re-write  for  a  specific
  2874.        system, the resultant function will be less efficent than  one  which
  2875.        directly uses the operating system services.
  2876.     
  2877.           If you are implementing MICRO-C an a small system  and  intend  to
  2878.        use it for serious programming, I strongly recommend that you re-code
  2879.        all of the low level library functions in assembly language.
  2880.     
  2881.           Note that since library routines are often used,  in  applications
  2882.        where code size and execution speed are of primary importance, it may
  2883.        be desirable to recode some or all of the other library  routines  in
  2884.        assembly language as well.
  2885.     
  2886.           For those who intend to make only casual use of  MICRO-C,  or  who
  2887.        wish to experiment with it simply for the  learning  experience,  the
  2888.        'C' versions of the low level library functions should be  more  than
  2889.        sufficient.
  2890.     
  2891.        10.1 Standard Library Functions
  2892.     
  2893.              These routines are currently available in the  MICRO-C  library
  2894.           as  "standard"  functions  which  should  be  available   in   all
  2895.           implementations.
  2896.     
  2897.              The exact syntax and capabilities of the  system  or  processor
  2898.           dependant functions may vary  in  different  implementations,  see
  2899.           your  implementation  notes  (READ.ME)  for   details.   Different
  2900.           possible forms of such functions are shown using (1), (2), ...
  2901.     ABORT                                                             ABORT
  2902.     
  2903.     
  2904.     
  2905.     PROTOTYPE:
  2906.     
  2907.         abort(char *message)
  2908.     
  2909.     
  2910.     ARGUMENTS:
  2911.     
  2912.         message - Pointer to message to display
  2913.     
  2914.     
  2915.     RETURN VALUE:
  2916.     
  2917.         N/A - Function never returns
  2918.     
  2919.     
  2920.     DESCRIPTION:
  2921.     
  2922.           This function writes the string passed as an argument to  standard
  2923.        error, and then terminates the program with a  return  code  of  '-1'
  2924.        (Indicating general  failure).  This  provides  a  simple  method  of
  2925.        terminating a program on an error condition with a message explaining
  2926.        why.
  2927.     
  2928.     
  2929.     EXAMPLES:
  2930.     
  2931.         abort("Invalid operand\n");
  2932.     ABS                                                                 ABS
  2933.     
  2934.     
  2935.     
  2936.     PROTOTYPE:
  2937.     
  2938.         int abs(int number)
  2939.     
  2940.     
  2941.     ARGUMENTS:
  2942.     
  2943.         number  - Any integer value
  2944.     
  2945.     
  2946.     RETURN VALUE:
  2947.     
  2948.         The absolute value of "number"
  2949.     
  2950.     
  2951.     DESCRIPTION:
  2952.     
  2953.           The "abs" function returns the absolute value of the argument.  If
  2954.        "number" is a positive value, it is returned unchanged. If  negative,
  2955.        the negate of that value is returned (giving a positive result).
  2956.     
  2957.     
  2958.     EXAMPLES:
  2959.     
  2960.         difference = abs(value1 - value2);
  2961.     ATOI                                                               ATOI
  2962.     
  2963.     
  2964.     
  2965.     PROTOTYPE:
  2966.     
  2967.         int atoi(char *string)
  2968.     
  2969.     
  2970.     ARGUMENTS:
  2971.     
  2972.         string  - Pointer to a string containing a decimal number
  2973.     
  2974.     
  2975.     RETURN VALUE:
  2976.     
  2977.         16 bit integer value
  2978.     
  2979.     
  2980.     DESCRIPTION:
  2981.     
  2982.           The "atoi" function converts an ASCII string containing  a  signed
  2983.        decimal number (-32768 to 32767) to a 16 bit value which is returned.
  2984.        An unsigned number of the range (0 to 65535) may also  be  used,  and
  2985.        the result if assigned to an "unsigned" variable will be correct.
  2986.     
  2987.     
  2988.     EXAMPLES:
  2989.     
  2990.         value = atoi("1234");
  2991.         value = atoi("-1");
  2992.     CD                                                                   CD
  2993.     
  2994.     
  2995.     
  2996.     PROTOTYPE:
  2997.     
  2998.         int cd(char *pathname)
  2999.     
  3000.     
  3001.     ARGUMENTS:
  3002.     
  3003.         pathname- Name of directory to make current
  3004.     
  3005.     
  3006.     RETURN VALUE:
  3007.     
  3008.         0 if successful, otherwise an operating system error code
  3009.     
  3010.     
  3011.     DESCRIPTION:
  3012.     
  3013.           This function sets the "current" directory, causing all subsequent
  3014.        file references which do not explicitly indicate a directory path  to
  3015.        access the path specified by "pathname".
  3016.     
  3017.     
  3018.     EXAMPLES:
  3019.     
  3020.         cd("/mc/c_source");     /* UNIX */
  3021.         cd("\\mc\\l_source");   /* MS-DOS */
  3022.     CONCAT                                                           CONCAT
  3023.     
  3024.     
  3025.     
  3026.     PROTOTYPE:
  3027.     
  3028.         register concat(char *dest, char *source, ...)
  3029.     
  3030.     
  3031.     ARGUMENTS:
  3032.     
  3033.         dest    - Pointer to destination string
  3034.         source  - Pointer to source string
  3035.         ...     - Additional sources may be given
  3036.     
  3037.     
  3038.     RETURN VALUE:
  3039.     
  3040.         None
  3041.     
  3042.     
  3043.     DESCRIPTION:
  3044.     
  3045.           The "concat" function concatinates the given source  strings  into
  3046.        one destination string. The destination string must be  large  enough
  3047.        to hold all of the source strings plus the string  terminator  (zero)
  3048.        byte. No value is returned.
  3049.     
  3050.           NOTE: This function uses a variable number of arguments, and  must
  3051.        be declared as "register" (See "stdio.h").
  3052.     
  3053.     
  3054.     EXAMPLES:
  3055.     
  3056.         concat(filename,"/tmp/", input_name);
  3057.     CREATE                                                           CREATE
  3058.     
  3059.     
  3060.     
  3061.     PROTOTYPE:
  3062.     
  3063.         int create(char *pathname, int attrs)
  3064.     
  3065.     
  3066.     
  3067.     ARGUMENTS:
  3068.     
  3069.         pathname- Name of file to create
  3070.         attrs   - Attributes for new file
  3071.     
  3072.     
  3073.     RETURN VALUE:
  3074.     
  3075.         0 if successful, otherwise an operating system error code
  3076.     
  3077.     
  3078.     DESCRIPTION:
  3079.     
  3080.           The "create" function creates a new file with the specified system
  3081.        attributes.
  3082.     
  3083.           The meaning of the individual bits in the "attrs" value is  system
  3084.        dependant, and is defined in the "file.h" header file.
  3085.     
  3086.     
  3087.     EXAMPLES:
  3088.     
  3089.         create("temp", HIDDEN);
  3090.     DELETE                                                           DELETE
  3091.     
  3092.     
  3093.     
  3094.     PROTOTYPE:
  3095.     
  3096.         int delete(char *pathname)
  3097.     
  3098.     
  3099.     
  3100.     ARGUMENTS:
  3101.     
  3102.         pathname- Name of file to delete
  3103.     
  3104.     
  3105.     RETURN VALUE:
  3106.     
  3107.         0 if successful, otherwise an operating system error code
  3108.     
  3109.     
  3110.     DESCRIPTION:
  3111.     
  3112.           The "delete" function removes an existing file from the disk.  Any
  3113.        disk space occupied by the file is released.
  3114.     
  3115.     
  3116.     EXAMPLES:
  3117.     
  3118.         delete("temp");
  3119.     EXIT                                                               EXIT
  3120.     
  3121.     
  3122.     
  3123.     PROTOTYPE:
  3124.     
  3125.         exit(int rc);
  3126.     
  3127.     
  3128.     ARGUMENTS:
  3129.     
  3130.         rc      - Termination return code
  3131.     
  3132.     
  3133.     RETURN VALUE:
  3134.     
  3135.         N/A - Function never returns
  3136.     
  3137.     
  3138.     DESCRIPTION:
  3139.     
  3140.           This function terminates the execution of the program and passes a
  3141.        specific return code back to the  operating  system.  A  return  code
  3142.        value of zero is used  to  indicate  successful  program  completion.
  3143.        Non-zero return code values may be used to indicate a particular type
  3144.        of failure. A value of '-1' is often used to indicate a  non-specific
  3145.        failure. Note that  the  "rc"  value  is  very  system  specific,  in
  3146.        particular, some systems support only 8 bit return codes,  so  values
  3147.        which are greater than 255 should be avoided.
  3148.     
  3149.     
  3150.     EXAMPLES:
  3151.     
  3152.         exit(0);        /* success */
  3153.         exit(-1);       /* failure */
  3154.     FCLOSE                                                           FCLOSE
  3155.     
  3156.     
  3157.     
  3158.     PROTOTYPE:
  3159.     
  3160.         fclose(FILE *fp);
  3161.     
  3162.     
  3163.     ARGUMENTS:
  3164.     
  3165.         fp      - File pointer to an open file
  3166.     
  3167.     
  3168.     RETURN VALUE:
  3169.     
  3170.         None
  3171.     
  3172.     
  3173.     DESCRIPTION:
  3174.     
  3175.           This function closes a file  which  was  previously  opened  using
  3176.        "fopen". The I/O buffer space used by the file is  released.  In  the
  3177.        case of a file open for write ('w'), the last disk buffer is  flushed
  3178.        and written to disk.
  3179.     
  3180.     
  3181.     EXAMPLES:
  3182.     
  3183.         fclose(fp);
  3184.     FGET                                                               FGET
  3185.     
  3186.     
  3187.     
  3188.     PROTOTYPE:
  3189.     
  3190.         int fget(char *buffer, int size, FILE *fp)
  3191.     
  3192.     
  3193.     ARGUMENTS:
  3194.     
  3195.         buffer  - Pointer to buffer to receive data
  3196.         size    - Number of bytes to read
  3197.         fp      - File pointer to an input file
  3198.     
  3199.     
  3200.     RETURN VALUE:
  3201.     
  3202.         Number of bytes read from file
  3203.     
  3204.     
  3205.     DESCRIPTION:
  3206.     
  3207.           This function reads a block of data from a file and places  it  in
  3208.        memory at the address of "buffer". Data is read in "raw"  form,  with
  3209.        no interpretation of "newline" characters etc. If the number of bytes
  3210.        returned is less than the number of bytes requested, either  the  end
  3211.        of the file was encountered or an error condition occured  (in  which
  3212.        case the value will be zero).
  3213.     
  3214.     
  3215.     EXAMPLES:
  3216.     
  3217.         fget(block, 512, input_fp);
  3218.     FGETS                                                             FGETS
  3219.     
  3220.     
  3221.     
  3222.     PROTOTYPE:
  3223.     
  3224.         char *fgets(char *buffer, int size, FILE *fp)
  3225.     
  3226.     
  3227.     ARGUMENTS:
  3228.     
  3229.         buffer  - Pointer to string to receive line
  3230.         size    - Maximum size of line to read
  3231.         fp      - File pointer to an input file
  3232.     
  3233.     
  3234.     RETURN VALUE:
  3235.     
  3236.         Pointer to "buffer", or 0 if end of file
  3237.     
  3238.     
  3239.     DESCRIPTION:
  3240.     
  3241.           The "fgets" function reads characters  from  the  specified  input
  3242.        file, and places them in the character  buffer  until  one  of  three
  3243.        things happens:
  3244.     
  3245.           1) A NEWLINE character is encountered.
  3246.     
  3247.           2) The END of the file is encountered.
  3248.     
  3249.           3) The limit of "size" character is read.
  3250.     
  3251.           The string is terminated with the standard  NULL  (00)  character.
  3252.        The trailing NEWLINE '\n' character is NOT  included  in  the  output
  3253.        buffer.
  3254.     
  3255.     
  3256.     EXAMPLES:
  3257.     
  3258.         fgets(input_line, 80, input_file);
  3259.     FIND_FIRST                                                   FIND_FIRST
  3260.     
  3261.     
  3262.     
  3263.     PROTOTYPE:
  3264.     
  3265.         int find_first(char *pattern, int mattrs, char name[], int &sizeh,
  3266.                        int &sizel, int &attrs, int &time, int &date)
  3267.     
  3268.     
  3269.     ARGUMENTS:
  3270.     
  3271.         pattern - File name pattern to match
  3272.         mattrs  - File attributes to match
  3273.         name    - Address of string to receive file name
  3274.         &sizeh  - Address of int to receive high word of size
  3275.         &sizel  - Address of int to receive low word of size
  3276.         &attrs  - Address of int to receive attributes
  3277.         &time   - Address of int to receive time stamp
  3278.         &date   - Address of int to receive date stamp
  3279.     
  3280.     
  3281.     RETURN VALUE:
  3282.     
  3283.         0 if successful, otherwise an operating system error code
  3284.     
  3285.     
  3286.     DESCRIPTION:
  3287.     
  3288.           This function locates the first file on the disk which matches the
  3289.        given pattern. The "mattrs" field specifies  any  special  attributes
  3290.        the files must have  in  order  to  be  matched,  use  0  for  normal
  3291.        directory searches.
  3292.     
  3293.           Subsequent files may be located using the "find_next" function.
  3294.     
  3295.           The above function prototype describes the  MS-DOS  implementation
  3296.        of the function. With other operating systems, the function may  have
  3297.        slightly  different  parameters,   due   to   differing   information
  3298.        available. See your implementation notes.
  3299.     
  3300.     
  3301.     EXAMPLES:
  3302.     
  3303.         if(find_first(pattern, 0, name, &sh, &sl, &a, &t, &d))
  3304.             abort("No matching files found\n");
  3305.     FIND_NEXT                                                     FIND_NEXT
  3306.     
  3307.     
  3308.     
  3309.     PROTOTYPE:
  3310.     
  3311.         int find_next(char name[], int &sizeh, int &sizel, int &attrs,
  3312.                       int &time, int &date)
  3313.     
  3314.     
  3315.     ARGUMENTS:
  3316.     
  3317.         name    - Address of string to receive file name
  3318.         &sizeh  - Address of int to receive high word of size
  3319.         &sizel  - Address of int to receive low word of size
  3320.         &attrs  - Address of int to receive attributes
  3321.         &time   - Address of int to receive time stamp
  3322.         &date   - Address of int to receive date stamp
  3323.     
  3324.     
  3325.     RETURN VALUE:
  3326.     
  3327.         0 if successful, otherwise an operating system error code
  3328.     
  3329.     
  3330.     DESCRIPTION:
  3331.     
  3332.           The function must be preceeded by a call to "find_first", and will
  3333.        locate the next file on  the  disk  which  matches  the  pattern  and
  3334.        attributes given to that function call.
  3335.     
  3336.           The above function prototype describes the  MS-DOS  implementation
  3337.        of the function. With other operating systems, the function may  have
  3338.        slightly  different  parameters,   due   to   differing   information
  3339.        available. See your implementation notes.
  3340.     
  3341.     
  3342.     EXAMPLES:
  3343.     
  3344.         do
  3345.             printf("%s\n", name);
  3346.         while(!find_next(name, &sh, &sl, &a, &t, &d));
  3347.     FOPEN                                                             FOPEN
  3348.     
  3349.     
  3350.     
  3351.     PROTOTYPE:
  3352.     
  3353.         FILE *fopen(char *filename, char *options)
  3354.     
  3355.     
  3356.     ARGUMENTS:
  3357.     
  3358.         filename- Name of the file to open
  3359.         options - String containing open options, valid modes are:
  3360.                     "r"  - Open file for read
  3361.                     "w"  - Open file for write
  3362.                     "rw" - Open for read/write update
  3363.                     "wa" - Open for write & append
  3364.     
  3365.     
  3366.     RETURN VALUE:
  3367.     
  3368.         File pointer to the file buffer for the open file
  3369.         Zero (0) if file could not be opened
  3370.     
  3371.     
  3372.     DESCRIPTION:
  3373.     
  3374.           This function opens a  file  for  input  ('r')  or  output  ('w'),
  3375.        allowing subsequent I/O operations to read or write the file.
  3376.     
  3377.     
  3378.     EXAMPLES:
  3379.     
  3380.         fp = fopen("input_file", "r");
  3381.     FPRINTF                                                         FPRINTF
  3382.     
  3383.     
  3384.     
  3385.     PROTOTYPE:
  3386.     
  3387.         register fprintf(FILE *fp, char *format, arg, ...)
  3388.     
  3389.     
  3390.     ARGUMENTS:
  3391.     
  3392.         fp      - File pointer to an output file
  3393.         format  - Pointer to format string
  3394.         arg     - Argument as determined by format string
  3395.         ...     - Additional arguments may be required
  3396.     
  3397.     
  3398.     RETURN VALUE:
  3399.     
  3400.         None
  3401.     
  3402.     
  3403.     DESCRIPTION:
  3404.     
  3405.           This routine performs a formatted print to  a  file  specified  by
  3406.        "fp". The "format" string is written to the file with  the  arguments
  3407.        substituted for special "conversion  characters".  These  "conversion
  3408.        characters" are identified by a preceeding '%', and may be one of the
  3409.        following:
  3410.     
  3411.                     b       - Binary number
  3412.                     c       - Character
  3413.                     d       - Decimal (signed) number
  3414.                     o       - Octal number
  3415.                     s       - String
  3416.                     u       - Unsigned decimal number
  3417.                     x       - Hexidecimal number
  3418.                     %       - A single percent sign (No argument used)
  3419.     
  3420.           A numeric "field width" specifier may be placed in between the '%'
  3421.        and the conversion character, in which case the value will be  output
  3422.        in a field of that width. If the "field width" is a negative  number,
  3423.        the output will be left justified in the field, otherwise it is right
  3424.        justified. If the field width contains a leading '0', then the output
  3425.        field will be padded with zero's, otherwise spaces are used.
  3426.     
  3427.           If no "field width" is given, the output  is  free  format,  using
  3428.        only as much space as required.
  3429.     
  3430.           NOTE: This function uses a variable number of arguments, and  must
  3431.        be declared as "register" (See "stdio.h").
  3432.     
  3433.     
  3434.     EXAMPLES:
  3435.     
  3436.         fprintf(stderr,"Filename='%s'\n", filename);
  3437.         fprintf(stdout,"Address=%04x\n", address);
  3438.         fprintf(outfile,"Amount: $%3u.%02u\n", amount / 100, amount % 100);
  3439.     FPUT                                                               FPUT
  3440.     
  3441.     
  3442.     
  3443.     PROTOTYPE:
  3444.     
  3445.         int fput(char *block, int size, FILE *fp)
  3446.     
  3447.     
  3448.     ARGUMENTS:
  3449.     
  3450.         block   - Pointer to a block of data to write
  3451.         size    - Number of bytes to write
  3452.         fp      - File pointer to an output file
  3453.     
  3454.     
  3455.     RETURN VALUE:
  3456.     
  3457.         0 if successful, otherwise an operating system error code
  3458.     
  3459.     
  3460.     DESCRIPTION:
  3461.     
  3462.           This function writes a block of data to the  indicated  file  from
  3463.        memory at the specified address. Data is written in "raw" form,  with
  3464.        no translations of "newline" characters etc. If the value returned is
  3465.        less than the value of the "size" parameter, some error condition has
  3466.        occured (Such as disk full).
  3467.     
  3468.     
  3469.     EXAMPLES:
  3470.     
  3471.         if(fput(buffer, 100, fp) < 100)
  3472.             abort("File write error\n");
  3473.     FPUTS                                                             FPUTS
  3474.     
  3475.     
  3476.     
  3477.     PROTOTYPE:
  3478.     
  3479.         fputs(char *string, FILE *fp)
  3480.     
  3481.     
  3482.     ARGUMENTS:
  3483.     
  3484.         string  - Pointer to a character string
  3485.         fp      - FIle pointer to output file
  3486.     
  3487.     
  3488.     RETURN VALUE:
  3489.     
  3490.         0 if successful, otherwise an operating system error code
  3491.     
  3492.     
  3493.     DESCRIPTION:
  3494.     
  3495.           The "fputs" function writes the specified string to the  indicated
  3496.        output file. The zero terminating the string is NOT written.
  3497.     
  3498.     
  3499.     EXAMPLES:
  3500.     
  3501.         fputs("Text message", output_file);
  3502.     FREE                                                               FREE
  3503.     
  3504.     
  3505.     
  3506.     PROTOTYPE:
  3507.     
  3508.         free(char *ptr)
  3509.     
  3510.     
  3511.     ARGUMENTS:
  3512.     
  3513.         ptr     - Pointer to a previously allocated memory block
  3514.     
  3515.     
  3516.     RETURN VALUE:
  3517.     
  3518.         None
  3519.     
  3520.     
  3521.     DESCRIPTION:
  3522.     
  3523.           The "free" function releases (de-allocates) a block of memory that
  3524.        was obtained via a call to "malloc", and returns it to the heap. This
  3525.        makes it available for use by other memory allocations.
  3526.     
  3527.     
  3528.     EXAMPLES:
  3529.     
  3530.         if(!(ptr = malloc(BUFSIZ)))     /* Allocate a temporary buffer */
  3531.             abort("Not enough memory");
  3532.         do {                            /* Copy the file over */
  3533.             size = fget(ptr, BUFSIZ, in_fp);
  3534.             fput(ptr, size, out_fp); }
  3535.         while(size == BUFSIZ);
  3536.         free(ptr);                      /* Release temporary buffer */
  3537.     FSCANF                                                           FSCANF
  3538.     
  3539.     
  3540.     
  3541.     PROTOTYPE:
  3542.     
  3543.         register int fscanf(FILE *fp, char *format, &arg, ...)
  3544.     
  3545.     
  3546.     ARGUMENTS:
  3547.     
  3548.         fp      - File pointer to an input file
  3549.         format  - Pointer to format string
  3550.         arg     - Argument as determined by format string
  3551.         ...     - Additional arguments may be required
  3552.     
  3553.     
  3554.     RETURN VALUE:
  3555.     
  3556.         The number of successful matches
  3557.         EOF (-1) if end of file or an error condition occurs
  3558.     
  3559.     
  3560.     DESCRIPTION:
  3561.     
  3562.           This routine reads a line from the specified file and scans it for
  3563.        specific values which  are  then  assigned  to  the  passed  argument
  3564.        addresses. The types of values  scanned  are  determined  by  special
  3565.        "conversion characters" within the "format" string. These "conversion
  3566.        characters" are identified by a preceeding '%', and may be one of the
  3567.        following:
  3568.     
  3569.                     b       - Binary number
  3570.                     c       - Character
  3571.                     d       - Decimal (signed) number
  3572.                     o       - Octal number
  3573.                     s       - String
  3574.                     u       - Unsigned decimal number
  3575.                     x       - Hexidecimal number
  3576.                     %       - A single percent sign (No argument used)
  3577.     
  3578.           Before scanning for  any  value,  any  leading  "space"  or  "tab"
  3579.        characters in the input line are automatically flushed.
  3580.     
  3581.           Scanning of a particular value type will terminate when either the
  3582.        end of  the  line  or  a  non-applicible  character  is  encountered.
  3583.        Scanning of strings (%s) stops with a "space" or "tab" character, and
  3584.        the stored string will be zero terminated.
  3585.     
  3586.           A numeric "field width" specifier may be placed in between the '%'
  3587.        and the conversion character, in which case  scanning  of  the  value
  3588.        will  also  terminate  if  that  many  input  characters  have   been
  3589.        processed.
  3590.     
  3591.           Scanning  for  characters  (%c)  assumes  a  "field  width"  of  1
  3592.        character (%1c) unless it is otherwise specified.
  3593.     
  3594.     
  3595.     
  3596.     
  3597.     
  3598.     
  3599.     
  3600.     
  3601.     
  3602.     
  3603.           Any other (non-conversion) characters in the  format  string  will
  3604.        cause the next character in the input string which is not  a  "space"
  3605.        or "tab" to be skipped if it matches that character.
  3606.     
  3607.           Any variable values from the input line  which  are  not  required
  3608.        must be cleared by scanning them into a "dummy" variable.
  3609.     
  3610.           The most common mistake when using "fscanf" is forgetting  to  use
  3611.        the '&'  operator  with  a  simple  variable  argument.  This  causes
  3612.        "fscanf" to store the value INDIRECTLY at the  address  contained  in
  3613.        that variable (Similar to  using  '*'  with  a  pointer)  instead  of
  3614.        storing the value into the actual variable  itself.  Arguments  which
  3615.        are array names do not require the '&' operator, since the address of
  3616.        the array is already generated by reference to its name.
  3617.     
  3618.           Unlike "fscanf" in most  other  compiler  libraries,  the  MICRO-C
  3619.        function always reads and scans a single line from the input file.
  3620.     
  3621.           NOTE: This function uses a variable number of arguments, and  must
  3622.        be declared as "register".
  3623.     
  3624.     
  3625.     EXAMPLES:
  3626.     
  3627.         if(fscanf(infile,"%s %s %u", first_name, last_name, &age) != 3)
  3628.             abort("Error in user record\n");
  3629.     FSEEK                                                             FSEEK
  3630.     
  3631.     
  3632.     
  3633.     PROTOTYPE:
  3634.     
  3635.         (1) int fseek(FILE *fp, int h_offset, unsigned l_offset, int mode)
  3636.         (2) int fseek(FILE *fp, int offset, mode)
  3637.     
  3638.     
  3639.     ARGUMENTS:
  3640.     
  3641.         fp      - File pointer to an open file
  3642.         h_offset- Highest 16 bits of offset value
  3643.         l_offset- Lowest 16 bits of offset value
  3644.         offset  - 16 bit offset value
  3645.         mode    - Type of seek
  3646.                     0 = Absolute from start of file
  3647.                     1 = Signed offset from current position
  3648.                     2 = Signed offset from end of file
  3649.     
  3650.     
  3651.     RETURN VALUE:
  3652.     
  3653.         0 if successful, otherwise an operating system error code
  3654.     
  3655.     
  3656.     DESCRIPTION:
  3657.     
  3658.           This function positions the operating system internal pointer into
  3659.        a file so that any read or write will take  place  at  the  specified
  3660.        position in the file.
  3661.     
  3662.           Most operating systems which support files of > 64K bytes in  size
  3663.        will support form (1) of the function, using both high and low offset
  3664.        values.
  3665.     
  3666.           Smaller operating  systems  may  only  support  form  (2)  of  the
  3667.        function, allowing seeking of only +/- 32K bytes.
  3668.     
  3669.           Also, some implementations may not support  all  "modes",  or  may
  3670.        only allow unsigned (positive) offsets.
  3671.     
  3672.     
  3673.     EXAMPLES:
  3674.     
  3675.         fseek(in_file, 0, 2);   /* Advance to end of file */
  3676.     FTELL                                                             FTELL
  3677.     
  3678.     
  3679.     
  3680.     PROTOTYPE:
  3681.     
  3682.         (1) int ftell(FILE *fp, int &h_offset, unsigned &l_offset)
  3683.         (2) int ftell(FILE *fp, int &offset)
  3684.     
  3685.     
  3686.     ARGUMENTS:
  3687.     
  3688.         fp      - File pointer to an open file
  3689.         h_offset- Address of int to receive high word of offset
  3690.         l_offset- Address of int to receive low word of offset
  3691.         offset  - Address of int to receive offset
  3692.     
  3693.     
  3694.     RETURN VALUE:
  3695.     
  3696.         0 if successful, otherwise an operating system error code
  3697.     
  3698.     
  3699.     DESCRIPTION:
  3700.     
  3701.           This function gets the current read/write position within a  file.
  3702.        The position returned indicates the absolute character (byte)  offset
  3703.        from the start of the file where the next read  or  write  will  take
  3704.        place.
  3705.     
  3706.           Most operating systems which support files of > 64K bytes in  size
  3707.        will support form (1) of the function, returning both  high  and  low
  3708.        offset values.
  3709.     
  3710.           Smaller operating  systems  may  only  support  form  (2)  of  the
  3711.        function,  allowing  access  to  only  the  first   65535   character
  3712.        positions.
  3713.     
  3714.     
  3715.     EXAMPLES:
  3716.     
  3717.         ftell(fp, &oldh, &oldl);    /* Save file position */
  3718.             . . .                   /* Perform some operations on the file */
  3719.         fseek(fp, oldh, oldl, 0);   /* Return to previous position */
  3720.     GETC                                                               GETC
  3721.     
  3722.     
  3723.     
  3724.     PROTOTYPE:
  3725.     
  3726.         int getc(FILE *fp)
  3727.     
  3728.     
  3729.     ARGUMENTS:
  3730.     
  3731.         fp      - File pointer to an input file
  3732.     
  3733.     
  3734.     RETURN VALUE:
  3735.     
  3736.         Value of a character read from the file (0-255)
  3737.         EOF (-1) if end of file or an error condition occurs
  3738.     
  3739.     
  3740.     DESCRIPTION:
  3741.     
  3742.           This function reads a single character from  an  input  file,  and
  3743.        returns it as a positive value in the range of 0 to 255.  A  full  16
  3744.        bit value is returned, allowing the  end  of  file  condition  to  be
  3745.        distinct from the character value 255.
  3746.     
  3747.     
  3748.     EXAMPLES:
  3749.     
  3750.         if((c = getc(input_file)) < 0)
  3751.             abort("End of file encountered\n");
  3752.     GETDIR                                                           GETDIR
  3753.     
  3754.     
  3755.     
  3756.     PROTOTYPE:
  3757.     
  3758.         int getdir(char pathname[])
  3759.     
  3760.     
  3761.     ARGUMENTS:
  3762.     
  3763.         pathname- Address of string to receive directory path
  3764.     
  3765.     
  3766.     RETURN VALUE:
  3767.     
  3768.         0 if successful, otherwise an operating system error code
  3769.     
  3770.     
  3771.     DESCRIPTION:
  3772.     
  3773.           This function retreives from the system the name of the  "current"
  3774.        directory path.
  3775.     
  3776.           The "pathname" string must be long  enough  to  hold  the  largest
  3777.        pathname supported by the system, as  indicated  by  the  "PATH_SIZE"
  3778.        definition in the "file.h" header file.
  3779.     
  3780.     
  3781.     EXAMPLES:
  3782.     
  3783.         getdir(¤t_dir);
  3784.     GETENV                                                           GETENV
  3785.     
  3786.     
  3787.     
  3788.     PROTOTYPE:
  3789.     
  3790.         int getenv(char *ename, char *dest)
  3791.     
  3792.     
  3793.     ARGUMENTS:
  3794.     
  3795.         ename   - String containing name of environment variable
  3796.         dest    - Buffer to receive variable string value
  3797.     
  3798.     
  3799.     RETURN VALUE:
  3800.     
  3801.         1 if environment variable was found, 0 if not.
  3802.     
  3803.     
  3804.     DESCRIPTION:
  3805.     
  3806.           The GETENV function gets the value of a variable in  the  programs
  3807.        environment, and returns it as a string. If the environment  variable
  3808.        is not found, zero is returned, and the destination buffer is set  to
  3809.        a null (zero length) string.
  3810.     
  3811.           Use of this  function  allows  a  programs  fixed  parameters  and
  3812.        options to be specified once in environment variables, which may then
  3813.        be extracted by the program, eliminating the need  to  specify  those
  3814.        values every time the program is executed.
  3815.     
  3816.           When operating  MICRO-C  under  operating  systems  which  do  not
  3817.        support environment variables, this function will not be available.
  3818.     
  3819.     
  3820.     EXAMPLES:
  3821.     
  3822.         if(!getenv("COMSPEC", command))
  3823.             abort("No command processor defined\n");
  3824.     IN                                                                   IN
  3825.     
  3826.     
  3827.     
  3828.     PROTOTYPE:
  3829.     
  3830.         int in(unsigned port)
  3831.     
  3832.     
  3833.     ARGUMENTS:
  3834.     
  3835.         port    - I/O port address
  3836.     
  3837.     
  3838.     RETURN VALUE:
  3839.     
  3840.         The 8 bit value read from the given I/O port address
  3841.     
  3842.     
  3843.     DESCRIPTION:
  3844.     
  3845.           The "in" function reads and returns a byte (8 bits)  from  an  I/O
  3846.        port as an integer value between 0 and 255.
  3847.     
  3848.           The valid range of values for "port" depends on  the  I/O  address
  3849.        space of the processor.
  3850.     
  3851.           This function is not provided for processors which do not  support
  3852.        a separate I/O address space.
  3853.     
  3854.     
  3855.     EXAMPLES:
  3856.     
  3857.         while(in(0));   /* Wait for flag to clear */
  3858.     INW                                                                 INW
  3859.     
  3860.     
  3861.     
  3862.     PROTOTYPE:
  3863.     
  3864.         int inw(unsigned port)
  3865.     
  3866.     
  3867.     ARGUMENTS:
  3868.     
  3869.         port    - I/O port address
  3870.     
  3871.     
  3872.     RETURN VALUE:
  3873.     
  3874.         The 16 bit value read from the given I/O port address
  3875.     
  3876.     
  3877.     DESCRIPTION:
  3878.     
  3879.           The "inw" function reads and returns a word (16 bits) from an  I/O
  3880.        port as an integer value between 0 and 65535 (-1).
  3881.     
  3882.           The valid range of values for "port" depends on  the  I/O  address
  3883.        space of the processor.
  3884.     
  3885.           This function is not provided for processors which do not  support
  3886.        a separate I/O address space.
  3887.     
  3888.     
  3889.     EXAMPLES:
  3890.     
  3891.         var = inw(0);
  3892.     ISALNUM                                                         ISALNUM
  3893.     
  3894.     
  3895.     
  3896.     PROTOTYPE:
  3897.     
  3898.         int isalnum(char c)
  3899.     
  3900.     
  3901.     ARGUMENTS:
  3902.     
  3903.         c       - Any character value
  3904.     
  3905.     
  3906.     RETURN VALUE:
  3907.     
  3908.         1 if 'c' is alphabetic or numeric
  3909.         0 if 'c' is not alphabetic or numeric
  3910.     
  3911.     
  3912.     DESCRIPTION:
  3913.     
  3914.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  3915.        alphabetic letter in either upper or  lower  case  or  if  'c'  is  a
  3916.        numeric digit, otherwise FALSE (0) is returned.
  3917.     
  3918.     
  3919.     EXAMPLES:
  3920.     
  3921.         while(isalnum(*ptr))        /* Copy over symbol name */
  3922.             *name++ = *ptr++;
  3923.     ISALPHA                                                         ISALPHA
  3924.     
  3925.     
  3926.     
  3927.     PROTOTYPE:
  3928.     
  3929.         int isalpha(char c)
  3930.     
  3931.     
  3932.     ARGUMENTS:
  3933.     
  3934.         c       - Any character value
  3935.     
  3936.     
  3937.     RETURN VALUE:
  3938.     
  3939.         1 if 'c' is alphabetic
  3940.         0 if 'c' is not alphabetic
  3941.     
  3942.     
  3943.     DESCRIPTION:
  3944.     
  3945.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  3946.        alphabetic letter in either upper or lower case, otherwise FALSE  (0)
  3947.        is returned.
  3948.     
  3949.     
  3950.     EXAMPLES:
  3951.     
  3952.         flag = isalpha(input_char);
  3953.     ISCNTRL                                                         ISCNTRL
  3954.     
  3955.     
  3956.     
  3957.     PROTOTYPE:
  3958.     
  3959.         int iscntrl(char c)
  3960.     
  3961.     
  3962.     ARGUMENTS:
  3963.     
  3964.         c       - Any character value
  3965.     
  3966.     
  3967.     RETURN VALUE:
  3968.     
  3969.         1 if 'c' is a "control" character
  3970.         0 if 'c' is not a "control" character
  3971.     
  3972.     
  3973.     DESCRIPTION:
  3974.     
  3975.           Returns TRUE (1) is the passed character 'c' is an ASCII "control"
  3976.        character (0x00-0x1F or 0x7F), otherwise FALSE (0) is returned.
  3977.     
  3978.     
  3979.     EXAMPLES:
  3980.     
  3981.         putc(iscntrl(c) ? '.' : c, stdout); /* Display controls as '.' */
  3982.     ISDIGIT                                                         ISDIGIT
  3983.     
  3984.     
  3985.     
  3986.     PROTOTYPE:
  3987.     
  3988.         int isdigit(char c)
  3989.     
  3990.     
  3991.     ARGUMENTS:
  3992.     
  3993.         c       - Any character value
  3994.     
  3995.     
  3996.     RETURN VALUE:
  3997.     
  3998.         1 if 'c' is numeric
  3999.         0 if 'c' is not numeric
  4000.     
  4001.     
  4002.     DESCRIPTION:
  4003.     
  4004.           Returns TRUE (1) is the passed character 'c'  is  an  ASCII  digit
  4005.        ('0'-'9'), otherwise FALSE (0) is returned.
  4006.     
  4007.     
  4008.     EXAMPLES:
  4009.     
  4010.         value = 0;
  4011.         while(isdigit(*ptr))
  4012.             value = (value * 10) + (*ptr++ - '0');
  4013.     ISGRAPH                                                         ISGRAPH
  4014.     
  4015.     
  4016.     
  4017.     PROTOTYPE:
  4018.     
  4019.         int isgraph(char c)
  4020.     
  4021.     
  4022.     ARGUMENTS:
  4023.     
  4024.         c       - Any character value
  4025.     
  4026.     
  4027.     RETURN VALUE:
  4028.     
  4029.         1 if 'c' is a non-space printable character
  4030.         0 if 'c' is a space or not printable
  4031.     
  4032.     
  4033.     DESCRIPTION:
  4034.     
  4035.           Returns TRUE (1) if the passed character 'c' is a printable  ASCII
  4036.        character other than  a  space  character,  otherwise  FALSE  (0)  is
  4037.        returned.
  4038.     
  4039.     
  4040.     EXAMPLES:
  4041.     
  4042.         putc(isgraph(c) ? c : '.', stdout);
  4043.     ISLOWER                                                         ISLOWER
  4044.     
  4045.     
  4046.     
  4047.     PROTOTYPE:
  4048.     
  4049.         int islower(char c)
  4050.     
  4051.     
  4052.     ARGUMENTS:
  4053.     
  4054.         c       - Any character value
  4055.     
  4056.     
  4057.     RETURN VALUE:
  4058.     
  4059.         1 if 'c' is lower case alphabetic
  4060.         0 if 'c' is not lower case alphabetic
  4061.     
  4062.     
  4063.     DESCRIPTION:
  4064.     
  4065.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  4066.        alphabetic letter of lower case, otherwise FALSE (0) is returned.
  4067.     
  4068.     
  4069.     EXAMPLES:
  4070.     
  4071.         flag = islower(input_char);
  4072.     ISPUNCT                                                         ISPUNCT
  4073.     
  4074.     
  4075.     
  4076.     PROTOTYPE:
  4077.     
  4078.         int ispunct(char c)
  4079.     
  4080.     
  4081.     ARGUMENTS:
  4082.     
  4083.         c       - Any character value
  4084.     
  4085.     
  4086.     RETURN VALUE:
  4087.     
  4088.         1 if 'c' is a printable non-alphanumeric character
  4089.         0 if 'c' is not printable or alphanumeric
  4090.     
  4091.     
  4092.     DESCRIPTION:
  4093.     
  4094.           Returns TRUE (1) if the passed character 'c' is a printable  ASCII
  4095.        character which is not a letter of the alphabet or a  numeric  digit,
  4096.        otherwise FALSE (0) is returned.
  4097.     
  4098.     
  4099.     EXAMPLES:
  4100.     
  4101.         while(ispunct(*ptr))
  4102.             ++ptr;
  4103.     ISSPACE                                                         ISSPACE
  4104.     
  4105.     
  4106.     
  4107.     PROTOTYPE:
  4108.     
  4109.         int isspace(char c)
  4110.     
  4111.     
  4112.     ARGUMENTS:
  4113.     
  4114.         c       - Any character value
  4115.     
  4116.     
  4117.     RETURN VALUE:
  4118.     
  4119.         1 if 'c' is a space character (space, tab or newline)
  4120.         0 if 'c' is not a space character
  4121.     
  4122.     
  4123.     DESCRIPTION:
  4124.     
  4125.           Returns TRUE (1) if the passed character 'c' is one  of  a  space,
  4126.        tab or newline, otherwise FALSE (0) is returned.
  4127.     
  4128.     
  4129.     EXAMPLES:
  4130.     
  4131.         while(isspace(*ptr))
  4132.             ++ptr;
  4133.     ISUPPER                                                         ISUPPER
  4134.     
  4135.     
  4136.     
  4137.     PROTOTYPE:
  4138.     
  4139.         int isupper(char c)
  4140.     
  4141.     
  4142.     ARGUMENTS:
  4143.     
  4144.         c       - Any character value
  4145.     
  4146.     
  4147.     RETURN VALUE:
  4148.     
  4149.         1 if 'c' is upper case alphabetic
  4150.         0 if 'c' is not upper case alphabetic
  4151.     
  4152.     
  4153.     DESCRIPTION:
  4154.     
  4155.           Returns  TRUE  (1)  if  the  passed  character  'c'  is  an  ASCII
  4156.        alphabetic letter of upper case, otherwise FALSE (0) is returned.
  4157.     
  4158.     
  4159.     EXAMPLES:
  4160.     
  4161.         flag = isupper(input_char);
  4162.     LONGJMP                                                         LONGJMP
  4163.     
  4164.     
  4165.     
  4166.     PROTOTYPE:
  4167.     
  4168.         longjmp(int savenv[3], int rvalue)
  4169.     
  4170.     
  4171.     ARGUMENTS:
  4172.     
  4173.         savenv  - Save area for program context
  4174.         rvalue  - Value to be returned by "setjmp"
  4175.     
  4176.     
  4177.     RETURN VALUE:
  4178.     
  4179.         N/A - Function never returns
  4180.     
  4181.     
  4182.     DESCRIPTION:
  4183.     
  4184.           The  "longjmp"  function  causes  execution  to  transfer  to  the
  4185.        "setjmp" call which  set  up  the  "savenv"  variable.  The  "setjmp"
  4186.        function will appear to return the value of "rvalue".
  4187.     
  4188.           NOTE-1: "longjmp" may  only  be  used  from  within  the  function
  4189.        calling "setjmp" or a function which has been called  "beneath"  that
  4190.        function. IT MUST NOT BE USED AFTER THE FUNCTION CALLING "SETJMP" HAS
  4191.        TERMINATED.
  4192.     
  4193.           NOTE-2: If "rvalue" is zero, the function  calling  "setjmp"  will
  4194.        assume that it is returning from initialization. Unless you want this
  4195.        unusual behavior, you should not pass  a  return  value  of  zero  to
  4196.        "longjmp".
  4197.     
  4198.           See also SETJMP.
  4199.     
  4200.     
  4201.     EXAMPLES:
  4202.     
  4203.         if(getc(stdin) == ('C'-'@'))    /* If Control-C entered... */
  4204.             longjmp(savearea, 1);       /* Return to main function */
  4205.     MALLOC                                                           MALLOC
  4206.     
  4207.     
  4208.     
  4209.     PROTOTYPE:
  4210.     
  4211.         char *malloc(int size)
  4212.     
  4213.     
  4214.     ARGUMENTS:
  4215.     
  4216.         size    - Size of memory block to allocate (in bytes).
  4217.     
  4218.     
  4219.     RETURN VALUE:
  4220.     
  4221.         0       - Memory allocation failed
  4222.         !0      - Pointer to allocated memory block
  4223.     
  4224.     
  4225.     DESCRIPTION:
  4226.     
  4227.           The "malloc" function allocates a block of memory of the specified
  4228.        size from the heap, and returns a pointer to  it.  This  memory  will
  4229.        remain allocated until it is  explicitly  releases  with  the  "free"
  4230.        function.
  4231.     
  4232.     
  4233.     EXAMPLES:
  4234.     
  4235.         if(!(ptr = malloc(BUFSIZ)))     /* Allocate a temporary buffer */
  4236.             abort("Not enough memory");
  4237.         do {                            /* Copy the file over */
  4238.             size = fget(ptr, BUFSIZ, in_fp);
  4239.             fput(ptr, size, out_fp); }
  4240.         while(size == BUFSIZ);
  4241.         free(ptr);                      /* Release temporary buffer */
  4242.     MAX                                                                 MAX
  4243.     
  4244.     
  4245.     
  4246.     PROTOTYPE:
  4247.     
  4248.         int max(int value1, int value2)
  4249.     
  4250.     
  4251.     ARGUMENTS:
  4252.     
  4253.         value1  - Any integer value
  4254.         value2  - Any integer value
  4255.     
  4256.     
  4257.     RETURN VALUE:
  4258.     
  4259.         The greater of "value1" or "value2"
  4260.     
  4261.     
  4262.     DESCRIPTION:
  4263.     
  4264.           The "max" function returns the higher of its two argument values.
  4265.     
  4266.     
  4267.     EXAMPLES:
  4268.     
  4269.         biggest = max(a, b);
  4270.     MEMCPY                                                           MEMCPY
  4271.     
  4272.     
  4273.     
  4274.     PROTOTYPE:
  4275.     
  4276.         memcpy(char *dest, char *source, unsigned size)
  4277.     
  4278.     
  4279.     ARGUMENTS:
  4280.     
  4281.         dest    - Pointer to the destination
  4282.         source  - Pointer to the souce
  4283.         size    - Number of bytes to copy
  4284.     
  4285.     
  4286.     RETURN VALUE:
  4287.     
  4288.         None
  4289.     
  4290.     
  4291.     DESCRIPTION:
  4292.     
  4293.           The "memcpy" function will copy the specified number of bytes from
  4294.        the source to the destination.
  4295.     
  4296.     
  4297.     EXAMPLES:
  4298.     
  4299.         memcpy(buffer1, buffer2, 256);
  4300.     MEMSET                                                           MEMSET
  4301.     
  4302.     
  4303.     
  4304.     PROTOTYPE:
  4305.     
  4306.         memset(char *block, char value, unsigned size)
  4307.     
  4308.     
  4309.     ARGUMENTS:
  4310.     
  4311.         block   - Pointer to a block of memory
  4312.         value   - Value to initialize memory with
  4313.         size    - Number of bytes to initialize
  4314.     
  4315.     
  4316.     RETURN VALUE:
  4317.     
  4318.         None
  4319.     
  4320.     
  4321.     DESCRIPTION:
  4322.     
  4323.           Sets a block of memory  beginning  at  the  pointer  "block",  for
  4324.        "size" bytes to the byte value "value".
  4325.     
  4326.     
  4327.     EXAMPLES:
  4328.     
  4329.         memset(buffer, 0, 100);
  4330.     MIN                                                                 MIN
  4331.     
  4332.     
  4333.     
  4334.     PROTOTYPE:
  4335.     
  4336.         int min(int value1, int value2)
  4337.     
  4338.     
  4339.     ARGUMENTS:
  4340.     
  4341.         value1  - Any integer value
  4342.         value2  - Any integer value
  4343.     
  4344.     
  4345.     RETURN VALUE:
  4346.     
  4347.         The smaller of "value1" or "value2"
  4348.     
  4349.     
  4350.     DESCRIPTION:
  4351.     
  4352.           The "min" function returns the lower of its two argument values.
  4353.     
  4354.     
  4355.     EXAMPLES:
  4356.     
  4357.         least = min(a, b);
  4358.     MKDIR                                                             MKDIR
  4359.     
  4360.     
  4361.     
  4362.     PROTOTYPE:
  4363.     
  4364.         int mkdir(char *pathname)
  4365.     
  4366.     
  4367.     ARGUMENTS:
  4368.     
  4369.         pathname- Name of directory to create
  4370.     
  4371.     
  4372.     RETURN VALUE:
  4373.     
  4374.         0 if successful, otherwise an operating system error code
  4375.     
  4376.     
  4377.     DESCRIPTION:
  4378.     
  4379.           The "mkdir" function create a new directory on the disk under  the
  4380.        specified path name.
  4381.     
  4382.     
  4383.     EXAMPLES:
  4384.     
  4385.         mkdir("subdir");
  4386.     NARGS                                                             NARGS
  4387.     
  4388.     
  4389.     
  4390.     PROTOTYPE:
  4391.     
  4392.         int nargs()
  4393.     
  4394.     
  4395.     ARGUMENTS:
  4396.     
  4397.         None
  4398.     
  4399.     
  4400.     RETURN VALUE:
  4401.     
  4402.         The number of arguments passed to the calling function
  4403.     
  4404.     
  4405.     DESCRIPTION:
  4406.     
  4407.           Returns the number of arguments passed to a "register" function.
  4408.     
  4409.           NOTE: When  calling  a  "register"  function,  MICRO-C  loads  the
  4410.        accumulator with the number of arguments just prior  to  calling  the
  4411.        function. This "nargs" routine is  simply  a  null  definition  which
  4412.        returns with the same value in the accumulator as was there  when  it
  4413.        was called. Therefore "nargs" MUST BE  THE  FIRST  ARITHMETIC  ENTITY
  4414.        EVALUATED WITHIN  THE  REGISTER  FUNCTION  or  the  contents  of  the
  4415.        accumulator will be lost. Some examples of "register" definitions and
  4416.        the use of "nargs" may be found in the library source code.
  4417.     
  4418.     
  4419.     EXAMPLES:
  4420.     
  4421.         first_arg = nargs() * 2 + &arguments;
  4422.     OUT                                                                 OUT
  4423.     
  4424.     
  4425.     
  4426.     PROTOTYPE:
  4427.     
  4428.         out(unsigned port, int value)
  4429.     
  4430.     
  4431.     ARGUMENTS:
  4432.     
  4433.         port    - I/O port address
  4434.         value   - Value to write to I/O port
  4435.     
  4436.     
  4437.     RETURN VALUE:
  4438.     
  4439.         None
  4440.     
  4441.     
  4442.     DESCRIPTION:
  4443.     
  4444.           The "out" function writes a byte (8 bit) value to an I/O port.
  4445.     
  4446.           The valid range of values for "port" depends on  the  I/O  address
  4447.        space of the processor.
  4448.     
  4449.           This function is not provided for processors which do not  support
  4450.        a separate I/O address space.
  4451.     
  4452.     
  4453.     EXAMPLES:
  4454.     
  4455.         out(0, 0);      /* Output 0 to I/O port 0 */
  4456.     OUTW                                                               OUTW
  4457.     
  4458.     
  4459.     
  4460.     PROTOTYPE:
  4461.     
  4462.         outw(unsigned port, int value)
  4463.     
  4464.     
  4465.     ARGUMENTS:
  4466.     
  4467.         port    - I/O port address
  4468.         value   - Value to write to I/O port
  4469.     
  4470.     
  4471.     RETURN VALUE:
  4472.     
  4473.         None
  4474.     
  4475.     
  4476.     DESCRIPTION:
  4477.     
  4478.           The "outw" function writes a word (16 bit) value to an I/O port.
  4479.     
  4480.           The valid range of values for "port" depends on  the  I/O  address
  4481.        space of the processor.
  4482.     
  4483.           This function is not provided for processors which do not  support
  4484.        a separate I/O address space.
  4485.     
  4486.     
  4487.     EXAMPLES:
  4488.     
  4489.         outw(0, 0);     /* Write 0 to I/O ports 0 and 1 */
  4490.     PEEK                                                               PEEK
  4491.     
  4492.     
  4493.     
  4494.     PROTOTYPE:
  4495.     
  4496.         (1) int peek(unsigned address)
  4497.         (2) int peek(unsigned h_addr, unsigned l_addr)
  4498.         (3) int peek(unsigned segment, unsigned offset)
  4499.     
  4500.     
  4501.     ARGUMENTS:
  4502.     
  4503.         segment - Memory segment
  4504.         offset  - Offset into segment
  4505.         h_addr  - High word of memory address
  4506.         l_addr  - Low word of memory address
  4507.         address - 16 bit memory address
  4508.     
  4509.     
  4510.     RETURN VALUE:
  4511.     
  4512.         The 8 bit value read from the given memory address
  4513.     
  4514.     
  4515.     DESCRIPTION:
  4516.     
  4517.           The "peek" function reads and returns a byte (8 bits) from  memory
  4518.        as an integer value between 0 and 255.
  4519.     
  4520.           Processors such as the 8080 or 6809 which address 64K of memory or
  4521.        less use form (1) of the function.
  4522.     
  4523.           Non-segmented processors addressing more  than  64K  such  as  the
  4524.        68000 use form (2) of the function.
  4525.     
  4526.           Processors employing a "segmented" architecture such as  the  8086
  4527.        use form (3) of the function.
  4528.     
  4529.     
  4530.     EXAMPLES:
  4531.     
  4532.         while(peek(0)); /* Wait for flag to clear */
  4533.     PEEKW                                                             PEEKW
  4534.     
  4535.     
  4536.     
  4537.     PROTOTYPE:
  4538.     
  4539.         (1) int peekw(unsigned address)
  4540.         (2) int peekw(unsigned h_addr, unsigned l_addr)
  4541.         (3) int peekw(unsigned segment, unsigned offset)
  4542.     
  4543.     
  4544.     ARGUMENTS:
  4545.     
  4546.         segment - Memory segment
  4547.         offset  - Offset into segment
  4548.         h_addr  - High word of memory address
  4549.         l_addr  - Low word of memory address
  4550.         address - 16 bit memory address
  4551.     
  4552.     
  4553.     RETURN VALUE:
  4554.     
  4555.         The 16 bit value read from the given memory address
  4556.     
  4557.     
  4558.     DESCRIPTION:
  4559.     
  4560.           The "peekw" function reads and  returns  a  word  (16  bits)  from
  4561.        memory as an integer value between 0 and 65535 (-1).
  4562.     
  4563.           Processors such as the 8080 or 6809 which address 64K of memory or
  4564.        less use form (1) of the function.
  4565.     
  4566.           Non-segmented processors addressing more  than  64K  such  as  the
  4567.        68000 use form (2) of the function.
  4568.     
  4569.           Processors employing a "segmented" architecture such as  the  8086
  4570.        use form (3) of the function.
  4571.     
  4572.     
  4573.     EXAMPLES:
  4574.     
  4575.         var = peekw(0));
  4576.     POKE                                                               POKE
  4577.     
  4578.     
  4579.     
  4580.     PROTOTYPE:
  4581.     
  4582.         (1) poke(unsigned address, int value)
  4583.         (2) poke(unsigned h_addr, unsigned l_addr, int value)
  4584.         (3) poke(unsigned segment, unsigned offset, int value)
  4585.     
  4586.     
  4587.     ARGUMENTS:
  4588.     
  4589.         segment - Memory segment
  4590.         offset  - Offset into segment
  4591.         h_addr  - High word of memory address
  4592.         l_addr  - Low word of memory address
  4593.         address - 16 bit memory address
  4594.         value   - Value to be written to memory
  4595.     
  4596.     
  4597.     RETURN VALUE:
  4598.     
  4599.         None
  4600.     
  4601.     
  4602.     DESCRIPTION:
  4603.     
  4604.           The "poke" function writes a byte (8 bit) value to memory.
  4605.     
  4606.           Processors such as the 8080 or 6809 which address 64K of memory or
  4607.        less use form (1) of the function.
  4608.     
  4609.           Non-segmented processors addressing more  than  64K  such  as  the
  4610.        68000 use form (2) of the function.
  4611.     
  4612.           Processors employing a "segmented" architecture such as  the  8086
  4613.        use form (3) of the function.
  4614.     
  4615.     
  4616.     EXAMPLES:
  4617.     
  4618.         poke(0, 0);     /* Write 0 to location 0 */
  4619.     POKEW                                                             POKEW
  4620.     
  4621.     
  4622.     
  4623.     PROTOTYPE:
  4624.     
  4625.         (1) pokew(unsigned address, int value)
  4626.         (2) pokew(unsigned h_addr, unsigned l_addr, int value)
  4627.         (3) pokew(unsigned segment, unsigned offset, int value)
  4628.     
  4629.     
  4630.     ARGUMENTS:
  4631.     
  4632.         segment - Memory segment
  4633.         offset  - Offset into segment
  4634.         h_addr  - High word of memory address
  4635.         l_addr  - Low word of memory address
  4636.         address - 16 bit memory address
  4637.         value   - Value to be written to memory
  4638.     
  4639.     
  4640.     RETURN VALUE:
  4641.     
  4642.         None
  4643.     
  4644.     
  4645.     DESCRIPTION:
  4646.     
  4647.           The "pokew" function writes a word (16 bit) value to memory.
  4648.     
  4649.           Processors such as the 8080 or 6809 which address 64K of memory or
  4650.        less use form (1) of the function.
  4651.     
  4652.           Non-segmented processors addressing more  than  64K  such  as  the
  4653.        68000 use form (2) of the function.
  4654.     
  4655.           Processors employing a "segmented" architecture such as  the  8086
  4656.        use form (3) of the function.
  4657.     
  4658.     
  4659.     EXAMPLES:
  4660.     
  4661.         pokew(0, 0);    /* Write 0 to locations 0 and 1 */
  4662.     PRINTF                                                           PRINTF
  4663.     
  4664.     
  4665.     
  4666.     PROTOTYPE:
  4667.     
  4668.         register printf(char *format, arg, ...)
  4669.     
  4670.     
  4671.     ARGUMENTS:
  4672.     
  4673.         format  - Pointer to format string
  4674.         arg     - Argument as determined by format string
  4675.         ...     - Additional arguments may be required
  4676.     
  4677.     
  4678.     RETURN VALUE:
  4679.     
  4680.         None
  4681.     
  4682.     
  4683.     DESCRIPTION:
  4684.     
  4685.           The "printf" routine performs a formatted print  to  the  standard
  4686.        output device  (usually  system  console).  The  "format"  string  is
  4687.        written  with  the  arguments  substituted  for  special  "conversion
  4688.        characters".
  4689.     
  4690.           See "fprintf" for more information on format strings.
  4691.     
  4692.           NOTE: This function uses a variable number of arguments, and  must
  4693.        be declared as "register" (See "stdio.h").
  4694.     
  4695.     
  4696.     EXAMPLES:
  4697.     
  4698.         printf("Hello world!!!\n");
  4699.         printf("File '%s', has %u lines\n", filename, num_lines);
  4700.     PUTC                                                               PUTC
  4701.     
  4702.     
  4703.     
  4704.     PROTOTYPE:
  4705.     
  4706.         putc(char c, FILE *fp)
  4707.     
  4708.     
  4709.     ARGUMENTS:
  4710.     
  4711.         c       - Any character value
  4712.         fp      - File pointer to an output file
  4713.     
  4714.     
  4715.     RETURN VALUE:
  4716.     
  4717.         0 if successful, otherwise an operating system error code
  4718.     
  4719.     
  4720.     DECRIPTION:
  4721.     
  4722.           This function writes the character 'c' to the  file  indicated  by
  4723.        "fp". The "newline" (\n) character will be translated  into  whatever
  4724.        character(s) are required by the operating system to separate records
  4725.        in the file.
  4726.     
  4727.     
  4728.     EXAMPLES:
  4729.     
  4730.         putc('*', fp);
  4731.         putc('\n', stderr);
  4732.     RAND                                                               RAND
  4733.     
  4734.     
  4735.     
  4736.     PROTOTYPE:
  4737.     
  4738.         unsigned rand(unsigned limit)
  4739.     
  4740.     
  4741.     ARGUMENTS:
  4742.     
  4743.         limit   - Maximum value to return
  4744.     
  4745.     
  4746.     RETURN VALUE:
  4747.     
  4748.         A pseudo-random number in the range of 0 to (limit-1)
  4749.     
  4750.     
  4751.     DESCRIPTION:
  4752.     
  4753.           The "rand" function calculates the next value of  a  pseudo-random
  4754.        sequence, based on a 16 bit unsigned "seed" value, which it maintains
  4755.        in the global variable "RAND_SEED". The new value is  stored  as  the
  4756.        new seed value, and is then divided  by  the  "limit"  parameter,  to
  4757.        obtain the remainder, which is returned. This  results  in  a  random
  4758.        number in the range of zero (0) to (limit - 1).
  4759.     
  4760.           Any  particular  sequence  may  be  repeated,  by   reseting   the
  4761.        "RAND_SEED" value.
  4762.     
  4763.     
  4764.     EXAMPLES:
  4765.     
  4766.         value = rand(52);
  4767.     RENAME                                                           RENAME
  4768.     
  4769.     
  4770.     
  4771.     PROTOTYPE:
  4772.     
  4773.         int rename(char *pathname, char *newname)
  4774.     
  4775.     
  4776.     ARGUMENTS:
  4777.     
  4778.         pathname- Name of file to rename
  4779.         newname - New name for file
  4780.     
  4781.     
  4782.     RETURN VALUE:
  4783.     
  4784.         0 if successful, otherwise an operating system error code
  4785.     
  4786.     
  4787.     DESCRIPTION:
  4788.     
  4789.           This function changes the name of an existing file  to  the  ASCII
  4790.        string specified by newname.
  4791.     
  4792.     
  4793.     EXAMPLES:
  4794.     
  4795.         rename("output.dat", "output.bak");
  4796.     REWIND                                                           REWIND
  4797.     
  4798.     
  4799.     
  4800.     PROTOTYPE:
  4801.     
  4802.         int rewind(FILE *fp)
  4803.     
  4804.     
  4805.     ARGUMENTS:
  4806.     
  4807.         fp      - File pointer to an open file
  4808.     
  4809.     
  4810.     RETURN VALUE:
  4811.     
  4812.         0 if successful, otherwise an operating system error code
  4813.     
  4814.     
  4815.     DESCRIPTION:
  4816.     
  4817.           This function resets the operating system internal file pointer so
  4818.        than any subsequent read or writes will be at the  beginning  of  the
  4819.        file.
  4820.     
  4821.     
  4822.     EXAMPLES:
  4823.     
  4824.         rewind(input_file);
  4825.     RMDIR                                                             RMDIR
  4826.     
  4827.     
  4828.     
  4829.     PROTOTYPE:
  4830.     
  4831.         int rmdir(char *pathname)
  4832.     
  4833.     
  4834.     ARGUMENTS:
  4835.     
  4836.         pathname- Name of directory to delete
  4837.     
  4838.     
  4839.     RETURN VALUE:
  4840.     
  4841.         0 if successful, otherwise an operating system error code
  4842.     
  4843.     
  4844.     DESCRIPTION:
  4845.     
  4846.           This function removes a directory from the disk. On most  systems,
  4847.        the directory  must  be  empty  (contains  no  files)  otherwise  the
  4848.        function will fail.
  4849.     
  4850.     
  4851.     EXAMPLES:
  4852.     
  4853.         rmdir("subdir");
  4854.     SCANF                                                             SCANF
  4855.     
  4856.     
  4857.     
  4858.     PROTOTYPE:
  4859.     
  4860.         register int scanf(char *format, arg1, arg2, ...)
  4861.     
  4862.     
  4863.     ARGUMENTS:
  4864.     
  4865.         format  - Pointer to format string
  4866.         arg     - Argument as determined by format string
  4867.         ...     - Additional arguments may be required
  4868.     
  4869.     
  4870.     RETURN VALUE:
  4871.     
  4872.         The number of successful matches
  4873.         EOF (-1) if end of file or an error condition occurs
  4874.     
  4875.     
  4876.     DESCRIPTION:
  4877.     
  4878.           The "scanf" function reads and scans  a  line  from  the  standard
  4879.        input device (usually system console) for specific values. Values are
  4880.        read and assigned to  the  passed  argument  addresses  according  to
  4881.        special "conversion characters" in the "format" string.
  4882.     
  4883.           See "fscanf" for more information on format strings.
  4884.     
  4885.           NOTE: This function uses a variable number of arguments, and  must
  4886.        be declared as "register".
  4887.     
  4888.     
  4889.     EXAMPLES:
  4890.     
  4891.         do
  4892.             printf("Please enter your First & Last names, and your age?");
  4893.         while(scanf("%s %s %u", first_name, last_name, &age) != 3);
  4894.     SETJMP                                                           SETJMP
  4895.     
  4896.     
  4897.     
  4898.     PROTOTYPE:
  4899.     
  4900.         int setjmp(int savenv[3])
  4901.     
  4902.     
  4903.     ARGUMENTS:
  4904.     
  4905.         savenv  - Save area for program context
  4906.     
  4907.     
  4908.     RETURN VALUE:
  4909.     
  4910.         0 is returned when actually called
  4911.         Value passed to "longjmp" is returned otherwise
  4912.     
  4913.     
  4914.     DESCRIPTION:
  4915.     
  4916.           When called, the "setjmp" function stores  the  current  execution
  4917.        state of the program into the passed integer array, and  returns  the
  4918.        value zero.
  4919.     
  4920.           The "longjmp" function may then be used to return the  program  to
  4921.        the "setjmp" call. In this case, the value returned by "setjmp"  will
  4922.        be the value which was passed to "longjmp". This allows the  function
  4923.        containing "setjmp" to determine which call to  "longjmp"  transfered
  4924.        execution to it.
  4925.     
  4926.           See also LONGJMP.
  4927.     
  4928.     
  4929.     EXAMPLES:
  4930.     
  4931.         switch(setjmp(savearea)) {
  4932.             case 0 : printf("Longjmp has been set up"); break;
  4933.             case 1 : printf("Control-C Interrupt");     break;
  4934.             case 2 : printf("Reset command executed");  break;
  4935.             default: printf("Software error trap");     break; }
  4936.     SPRINTF                                                         SPRINTF
  4937.     
  4938.     
  4939.     
  4940.     PROTOTYPE:
  4941.     
  4942.         register sprintf(char *dest, char *format, arg, ...)
  4943.     
  4944.     
  4945.     ARGUMENTS:
  4946.     
  4947.         dest    - Pointer to destination string
  4948.         format  - Pointer to format string
  4949.         arg     - Argument as determined by format string
  4950.         ...     - Additional arguments may be required
  4951.     
  4952.     
  4953.     RETURN VALUE:
  4954.     
  4955.         None
  4956.     
  4957.     
  4958.     DESCRIPTION:
  4959.     
  4960.           The "sprintf" routine performs a formatted print to  a  string  in
  4961.        memory. The "format" string is written to the destination string with
  4962.        the arguments substituted for special "conversion characters".
  4963.     
  4964.           See "fprintf" for more information on format strings.
  4965.     
  4966.           NOTE: This function uses a variable number of arguments, and  must
  4967.        be declared as "register" (See "stdio.h").
  4968.     
  4969.     
  4970.     EXAMPLES:
  4971.     
  4972.         sprintf(header_file, "/lib/%s.h", header_name);
  4973.     SQRT                                                               SQRT
  4974.     
  4975.     
  4976.     
  4977.     PROTOTYPE:
  4978.     
  4979.         int sqrt(unsigned value)
  4980.     
  4981.     
  4982.     ARGUMENTS:
  4983.     
  4984.         value   - Number for which to calculate square root
  4985.     
  4986.     
  4987.     RETURN VALUE:
  4988.     
  4989.         The integer square root (rounded up) of the argument value
  4990.     
  4991.     
  4992.     DESCRIPTION:
  4993.     
  4994.           The  SQRT  function  returns  the  smallest  number   which   when
  4995.        multiplied by itself will give a number equal to or larger  that  the
  4996.        argument value.
  4997.     
  4998.     
  4999.     EXAMPLES:
  5000.     
  5001.     /*
  5002.      * Draw a circle about point (x, y) of radus (r)
  5003.      */
  5004.     circle(x, y, r)
  5005.         int x, y, r;
  5006.     {
  5007.         int i, j, k, rs, lj;
  5008.     
  5009.         rs = (lj = r)*r;
  5010.         for(i=0; i <= r; ++i) {
  5011.             j = k = sqrt(rs - (i*i));
  5012.             do {
  5013.                 plot_xy(x+i, y+j);
  5014.                 plot_xy(x+i, y-j);
  5015.                 plot_xy(x-i, y+j);
  5016.                 plot_xy(x-i, y-j); }
  5017.             while(++j < lj);
  5018.             lj = k; }
  5019.     }
  5020.     SSCANF                                                           SSCANF
  5021.     
  5022.     
  5023.     
  5024.     PROTOTYPE:
  5025.     
  5026.         register int sscanf(char *input, char *format, arg1, arg2, ...)
  5027.     
  5028.     
  5029.     ARGUMENTS:
  5030.     
  5031.         input   - Pointer to input string
  5032.         format  - Pointer to format string
  5033.         arg     - Argument as determined by format string
  5034.         ...     - Additional arguments may be required
  5035.     
  5036.     
  5037.     RETURN VALUE:
  5038.     
  5039.         The number of successful matches
  5040.     
  5041.     
  5042.     DESCRIPTION:
  5043.     
  5044.           The "sscanf" function  scans  a  string  in  memory  for  specific
  5045.        values. Values are read and assigned to the passed argument addresses
  5046.        according to special "conversion characters" in the "format" string.
  5047.     
  5048.           See "fscanf" for more information on format strings.
  5049.     
  5050.           NOTE: This function uses a variable number of arguments, and  must
  5051.        be declared as "register".
  5052.     
  5053.     
  5054.     EXAMPLES:
  5055.     
  5056.         sscanf(pathname,"/%s/%s", directory, filename);
  5057.     STRBEG                                                           STRBEG
  5058.     
  5059.     
  5060.     
  5061.     PROTOTYPE:
  5062.     
  5063.         int strbeg(char *string1, char *string2)
  5064.     
  5065.     
  5066.     ARGUMENTS:
  5067.     
  5068.         string1 - Pointer to character string to test
  5069.         string2 - Pointer to character string to check for
  5070.     
  5071.     
  5072.     RETURN VALUE:
  5073.     
  5074.         0   - String1 does not begin with string2
  5075.         1   - String1 begins with string2
  5076.     
  5077.     
  5078.     DECRIPTION:
  5079.     
  5080.           Tests the passed "string1" to determine if it begins with the same
  5081.        data as is contained within "string2".
  5082.     
  5083.     
  5084.     EXAMPLES:
  5085.     
  5086.         if(strbeg(command, "delete"))
  5087.             delete_file(&command[6]);
  5088.     STRCAT                                                           STRCAT
  5089.     
  5090.     
  5091.     
  5092.     PROTOTYPE:
  5093.     
  5094.         char *strcat(char *dest, *source)
  5095.     
  5096.     
  5097.     ARGUMENTS:
  5098.     
  5099.         dest    - Pointer to destination string
  5100.         source  - Pointer to source string
  5101.     
  5102.     
  5103.     RETURN VALUE:
  5104.     
  5105.         Pointer to zero terminating destination string
  5106.     
  5107.     
  5108.     DESCRIPTION:
  5109.     
  5110.           This function concatinates the source string onto the tail of  the
  5111.        destination string. The destination string must be  large  enough  to
  5112.        hold the entire contents of both strings.
  5113.     
  5114.     
  5115.     EXAMPLES:
  5116.     
  5117.         strcat(program_name, ".c");
  5118.     STRCHR                                                           STRCHR
  5119.     
  5120.     
  5121.     
  5122.     PROTOTYPE:
  5123.     
  5124.         char *strchr(char *string, char chr)
  5125.     
  5126.     
  5127.     ARGUMENTS:
  5128.     
  5129.         string  - Pointer to a character string
  5130.         chr     - Character to look for
  5131.     
  5132.     
  5133.     RETURN VALUE:
  5134.     
  5135.         Pointer to the first occurance of 'chr' in 'string'
  5136.         Zero (0) if character was not found
  5137.     
  5138.     
  5139.     DECRIPTION:
  5140.     
  5141.           Searches  the  passed  string  got  the  first  occurance  of  the
  5142.        specified character. If the character is  found,  a  pointer  to  its
  5143.        position in the string is returned. If the character is not found,  a
  5144.        null pointer is returned.
  5145.     
  5146.           The null (0) character is treated as valid data by this  function,
  5147.        thus:
  5148.           strchr(string,  0);  would  return  the  position  of   the   null
  5149.        terminator of the string.
  5150.     
  5151.     
  5152.     EXAMPLES:
  5153.     
  5154.         comma = strchr(buffer, ',');
  5155.     STRCMP                                                           STRCMP
  5156.     
  5157.     
  5158.     
  5159.     PROTOTYPE:
  5160.     
  5161.         int strcmp(char *string1, char *string2)
  5162.     
  5163.     
  5164.     ARGUMENTS:
  5165.     
  5166.         string1 - Pointer to first string
  5167.         string2 - Pointer to second string
  5168.     
  5169.     
  5170.     RETURN VALUE:
  5171.     
  5172.         0   - Strings match exactly
  5173.         1   - String1 is greater than string2
  5174.         -1  - String2 is greater than string1
  5175.     
  5176.     
  5177.     DESCRIPTION:
  5178.     
  5179.           This function compares two strings character by character. If  the
  5180.        two strings are identical, a zero  (0)  is  returned.  If  the  first
  5181.        string is greater than the second (as far as ASCII is  concerned),  a
  5182.        one (1) is returned. If the second string is greater, a negative  one
  5183.        (-1) is returned.
  5184.     
  5185.     
  5186.     EXAMPLES:
  5187.     
  5188.         if(!strcmp(command, "quit"))
  5189.             exit(0);
  5190.     STRCPY                                                           STRCPY
  5191.     
  5192.     
  5193.     
  5194.     PROTOTYPE:
  5195.     
  5196.         char *strcpy(char *dest, char *source)
  5197.     
  5198.     
  5199.     ARGUMENTS:
  5200.     
  5201.         dest    - Pointer to destination string
  5202.         souce   - Pointer to source string
  5203.     
  5204.     
  5205.     RETURN VALUE:
  5206.     
  5207.         Pointer to zero terminating destination string
  5208.     
  5209.     
  5210.     DESCRIPTION:
  5211.     
  5212.           This function copies the source string to the destination  string.
  5213.        All data is copied up to and including the zero byte which terminates
  5214.        the string. The destination string must be large enough to  hold  the
  5215.        entire source.
  5216.     
  5217.     
  5218.     EXAMPLES:
  5219.     
  5220.         strcpy(filename, argv[1]);
  5221.     STRLEN                                                           STRLEN
  5222.     
  5223.     
  5224.     
  5225.     PROTOTYPE:
  5226.     
  5227.         int strlen(char *string)
  5228.     
  5229.     
  5230.     ARGUMENTS:
  5231.     
  5232.         string  - Pointer to a character string
  5233.     
  5234.     
  5235.     RETURN VALUE:
  5236.     
  5237.         The length of the string
  5238.     
  5239.     
  5240.     DECRIPTION:
  5241.     
  5242.           Returns the length in character of the passed string.  The  length
  5243.        does not include the zero byte which terminates the string.
  5244.     
  5245.     
  5246.     EXAMPLES:
  5247.     
  5248.         length = strlen(command);
  5249.     STRNCAT                                                         STRNCAT
  5250.     
  5251.     
  5252.     
  5253.     PROTOTYPE:
  5254.     
  5255.         char *strncat(char *dest, *source, unsigned length)
  5256.     
  5257.     
  5258.     ARGUMENTS:
  5259.     
  5260.         dest    - Pointer to destination string
  5261.         source  - Pointer to source string
  5262.         length  - Maximum number of characters to copy
  5263.     
  5264.     
  5265.     RETURN VALUE:
  5266.     
  5267.         Pointer to zero terminating destination string
  5268.     
  5269.     
  5270.     DESCRIPTION:
  5271.     
  5272.           This function concatinates the source string onto the tail of  the
  5273.        destination string. If the source string exceeds  "length"  bytes  in
  5274.        size, only that many characters are copied.
  5275.     
  5276.     
  5277.     EXAMPLES:
  5278.     
  5279.         strncat(path, filename, 64);
  5280.     STRNCMP                                                         STRNCMP
  5281.     
  5282.     
  5283.     
  5284.     PROTOTYPE:
  5285.     
  5286.         int strncmp(char *string1, char *string2, unsigned length)
  5287.     
  5288.     
  5289.     ARGUMENTS:
  5290.     
  5291.         string1 - Pointer to first string
  5292.         string2 - Pointer to second string
  5293.         length  - Number of bytes to compare
  5294.     
  5295.     
  5296.     RETURN VALUE:
  5297.     
  5298.         0   - Strings match exactly
  5299.         1   - String1 is greater than string2
  5300.         -1  - String2 is greater than string1
  5301.     
  5302.     
  5303.     DESCRIPTION:
  5304.     
  5305.           This function compares two strings character  by  character  until
  5306.        either a difference is detected, or  "length"  characters  have  been
  5307.        compared. If the two string portions are identical,  a  zero  (0)  is
  5308.        returned. If the first string is greater than the second (as  far  as
  5309.        ASCII is concerned), a one (1) is returned. If the second  string  is
  5310.        greater, a negative one (-1) is returned.
  5311.     
  5312.     
  5313.     EXAMPLES:
  5314.     
  5315.         len = strlen(buffer) - 3;
  5316.         for(i=1; i < len; ++i)
  5317.             if(strncmp(&buffer[i], "***", 3)
  5318.                 abort("Found three stars\n");
  5319.     STRNCPY                                                         STRNCPY
  5320.     
  5321.     
  5322.     
  5323.     PROTOTYPE:
  5324.     
  5325.         strncpy(char *dest, char *source, unsigned length)
  5326.     
  5327.     
  5328.     ARGUMENTS:
  5329.     
  5330.         dest    - Pointer to destination string
  5331.         souce   - Pointer to source string
  5332.         length  - Number of bytes to copy
  5333.     
  5334.     
  5335.     RETURN VALUE:
  5336.     
  5337.         None
  5338.     
  5339.     
  5340.     DESCRIPTION:
  5341.     
  5342.           This function copies "length" characters from the source string to
  5343.        the  destination  string.  If  the  source  string  is  shorter  than
  5344.        "length", the destination string is padded with nulls. If the  source
  5345.        string is longer than "length", only that many characters are copied,
  5346.        and the destination string is NOT zero terminated.
  5347.     
  5348.     
  5349.     EXAMPLES:
  5350.     
  5351.         strncpy(filename, argv[1], 64);
  5352.     STRSTR                                                           STRSTR
  5353.     
  5354.     
  5355.     
  5356.     PROTOTYPE:
  5357.     
  5358.         char *strstr(char *string1, char *string2)
  5359.     
  5360.     
  5361.     ARGUMENTS:
  5362.     
  5363.         string1 - Pointer to character string to test
  5364.         string2 - Pointer to substring to search for
  5365.     
  5366.     
  5367.     RETURN VALUE:
  5368.     
  5369.         Pointer to substring, or 0 if not found
  5370.     
  5371.     
  5372.     DECRIPTION:
  5373.     
  5374.           Searches the passed "string1"  for  the  first  occurance  of  the
  5375.        passed "string2". If found,  a  pointer  to  the  beginning  of  that
  5376.        substring within "string1" is returned.
  5377.     
  5378.     
  5379.     EXAMPLES:
  5380.     
  5381.         if(ptr = strstr(command, "delete"))
  5382.             delete_file(&ptr[6]);
  5383.     SYSTEM                                                           SYSTEM
  5384.     
  5385.     
  5386.     
  5387.     PROTOTYPE:
  5388.     
  5389.         int system(char *command)
  5390.     
  5391.     
  5392.     ARGUMENTS:
  5393.     
  5394.         command - A system command to be executed
  5395.     
  5396.     
  5397.     RETURN VALUE:
  5398.     
  5399.         0 if successful, otherwise an operating system error code
  5400.     
  5401.     
  5402.     DESCRIPTION:
  5403.     
  5404.           The SYSTEM function accepts any  operating  system  command  as  a
  5405.        string parameter, and passes that command to the operating system  to
  5406.        be executed.
  5407.     
  5408.           When the command has terminated,  execution  will  resume  in  the
  5409.        MICRO-C program, with the statement following the call to SYSTEM.
  5410.     
  5411.     
  5412.     EXAMPLES:
  5413.     
  5414.         system("DEL *.TMP");
  5415.     TOLOWER                                                         TOLOWER
  5416.     
  5417.     
  5418.     
  5419.     PROTOTYPE:
  5420.     
  5421.         char tolower(char c)
  5422.     
  5423.     
  5424.     ARGUMENTS:
  5425.     
  5426.         c   - Any character value
  5427.     
  5428.     
  5429.     RETURN VALUE:
  5430.     
  5431.         The value of 'c', converted to lower case
  5432.     
  5433.     
  5434.     DESCRIPTION:
  5435.     
  5436.           Returns the value of 'c' converted to lower case. If 'c' is not  a
  5437.        letter of upper case, no change is made, and the  original  value  of
  5438.        'c' is returned.
  5439.     
  5440.     
  5441.     EXAMPLES:
  5442.     
  5443.         input_char = tolower(getc(stdin));
  5444.     TOUPPER                                                         TOUPPER
  5445.     
  5446.     
  5447.     
  5448.     PROTOTYPE:
  5449.     
  5450.         char toupper(char c)
  5451.     
  5452.     
  5453.     ARGUMENTS:
  5454.     
  5455.         c   - Any character value
  5456.     
  5457.     
  5458.     RETURN VALUE:
  5459.     
  5460.         The value of 'c', converted to upper case
  5461.     
  5462.     
  5463.     DESCRIPTION:
  5464.     
  5465.           Returns the value of 'c' converted to upper case. If 'c' is not  a
  5466.        letter of lower case, no change is made, and the  original  value  of
  5467.        'c' is returned.
  5468.     
  5469.     
  5470.     EXAMPLES:
  5471.     
  5472.         putc(toupper(output_char), stdout);
  5473.     MICRO-C                                                          Page: 61
  5474.  
  5475.  
  5476.     10.2 IBM-PC/MS-DOS Library Functions
  5477.     
  5478.         The following functions are available only under the MS-DOS operating
  5479.     system, on IBM-PC or compatible systems.
  5480.     
  5481.         These routines perform operations which are closely tied to the 8086
  5482.     family of processors, the IBM-PC hardware, or the MS-DOS operating system,
  5483.     and are therefore impractical to implement on a "general" basis.
  5484.     ALLOC_SEG                                                     ALLOC_SEG
  5485.     
  5486.     
  5487.     
  5488.     PROTOTYPE:
  5489.     
  5490.         int alloc_seg(int size)
  5491.     
  5492.     
  5493.     ARGUMENTS:
  5494.     
  5495.         size    - Number of 16 byte paragraphs to allocate
  5496.     
  5497.     
  5498.     RETURN VALUE:
  5499.     
  5500.     
  5501.         0       - Not enough free memory available
  5502.         !0      - The segment address of the allocated memory
  5503.     
  5504.     
  5505.     DESCRIPTION:
  5506.     
  5507.              The "alloc_seg" function allocates a 'segment' of  memory  from
  5508.           DOS. The size is given in  16  byte  "paragraphs".  The  allocated
  5509.           memory will be outside of the data memory available to the MICRO-C
  5510.           program, and therefore must  be  accessed  via  assembly  lenguage
  5511.           functions, or with the "peek" and "poke" library functions.
  5512.     
  5513.     
  5514.     EXAMPLES:
  5515.     
  5516.         if(!(aseg = alloc(4096)))   /* Get a 64K data segment */
  5517.             abort("Not enough memory!!!");
  5518.         set_es(aseg);               /* Set up extra segment */
  5519.         asm_func();                 /* Invoke assembler function */
  5520.     CCLOSE                                                           CCLOSE
  5521.     
  5522.     
  5523.     
  5524.     PROTOTYPE:
  5525.     
  5526.         Cclose()
  5527.     
  5528.     
  5529.     ARGUMENTS:
  5530.     
  5531.         None
  5532.     
  5533.     
  5534.     RETURN VALUE:
  5535.     
  5536.         None
  5537.     
  5538.     
  5539.     DESCRIPTION:
  5540.     
  5541.              This function closes the communications port previously  opened
  5542.           using "Copen". The system interrupt vectors and all other hooks to
  5543.           the comm port are restored.
  5544.     
  5545.              This function must be called before any program  using  "Copen"
  5546.           terminates, otherwise the communications port will be left  in  an
  5547.           indeterminate state.  If  this  is  not  done,  there  will  be  a
  5548.           possibility of system crash if an interrupt is received  from  the
  5549.           port after the program has terminated.
  5550.     
  5551.     
  5552.     EXAMPLES:
  5553.     
  5554.         Cclose();       /* Close comm port */
  5555.         exit(0);        /* And terminate */
  5556.     CGETC                                                             CGETC
  5557.     
  5558.     
  5559.     
  5560.     PROTOTYPE:
  5561.     
  5562.         int Cgetc()
  5563.     
  5564.     
  5565.     ARGUMENTS:
  5566.     
  5567.         None
  5568.     
  5569.     
  5570.     RETURN VALUE:
  5571.     
  5572.         Character read from the communications port
  5573.     
  5574.     
  5575.     DESCRIPTION:
  5576.     
  5577.              This function reads a single character from the  communications
  5578.           port previously opened with "Copen". If no character is available,
  5579.           "Cgetc" will wait for one.
  5580.     
  5581.     
  5582.     EXAMPLES:
  5583.     
  5584.         /* Get a string from the comm port */
  5585.         while((c = cgetc()) != '\r')
  5586.             *ptr++ = c;
  5587.         *ptr = 0;
  5588.     COPEN                                                             COPEN
  5589.     
  5590.     
  5591.     
  5592.     PROTOTYPE:
  5593.     
  5594.         int Copen(int port, int speed, int mode, int modem)
  5595.     
  5596.     
  5597.     ARGUMENTS:
  5598.     
  5599.         port    - Comm port to use (1 or 2)
  5600.         speed   - Baudrate divisor to set
  5601.         mode    - Communications parameters to set
  5602.         modem   - Modem control lines to set
  5603.     
  5604.     RETURN VALUE:
  5605.     
  5606.         0       - Successful open
  5607.         !0      - Requested comm port is not available
  5608.     
  5609.     
  5610.     DESCRIPTION:
  5611.     
  5612.              The "Copen" function opens a serial communications port on  the
  5613.           IBM PC for  access.  An  independant  interrupt  handler  and  I/O
  5614.           drivers  are  installed,  which  allow  high  speed  full   duplex
  5615.           operation of the serial port with optional XON/XOFF  flow  control
  5616.           of both receive and transmit streams.
  5617.     
  5618.              Only one serial port may be accessed  at  a  time  using  these
  5619.           functions,  If  "Copen"  is  called  more  than  once,   it   will
  5620.           automatically close the last port before opening the new one.
  5621.     
  5622.              The meaning of the "speed", "mode", and "modem"  parameters  if
  5623.           documented in the "comm.h" header file.
  5624.     
  5625.              An external "char" variable "Cflags" may be accessed to  enable
  5626.           or disable transparency of the serial channel. When  "transparent"
  5627.           is selected, XON/XOFF flow control is disabled, and  all  data  is
  5628.           sent and received with no changes. When operating  in  this  mode,
  5629.           you must insure that "Cgetc" is called frequently enough that  the
  5630.           256 byte internal receive buffer will not overflow.
  5631.     
  5632.              Since "Cflags" is used by the  interrupt  handler,  you  should
  5633.           disable and enable interrupts around any accessed to it.
  5634.     
  5635.     
  5636.     
  5637.     EXAMPLES:
  5638.     
  5639.         #include comm.h     /* Get comm port defintions */
  5640.     
  5641.             extern char Cflags;
  5642.     
  5643.         /*
  5644.          * Program to read & echo characters on the serial port
  5645.          * in transparent mode. (Until ESCAPE char is received)
  5646.          */
  5647.         main()
  5648.         {
  5649.             char c;
  5650.     
  5651.             if(Copen(1, _2300, PAR_NO|DATA_8|STOP_1, SET_RTS|SET_DTR))
  5652.                 abort("Cannot access COM1");
  5653.     
  5654.             disable();                  /* Disable interrupts */
  5655.             Cflags |= TRANSPARENT;      /* Set transparency */
  5656.             enable();                   /* Re-enable interrupts */
  5657.     
  5658.             while((c = Cgetc()) != 0x1B)    /* Do until ESCAPE */
  5659.                 Cputc(c);
  5660.     
  5661.             Cclose();                   /* Close the serial port */
  5662.         }
  5663.     COPY_SEG                                                       COPY_SEG
  5664.     
  5665.     
  5666.     
  5667.     PROTOTYPE:
  5668.     
  5669.         copy_seg(int dseg, int doffset, int sseg, int soffset, int size)
  5670.     
  5671.     
  5672.     ARGUMENTS:
  5673.     
  5674.         dseg    - Destination segment
  5675.         doffset - Destination offset
  5676.         sseg    - Source segment
  5677.         soffset - Source offset
  5678.         size    - Number of bytes to copy
  5679.     
  5680.     
  5681.     RETURN VALUE:
  5682.     
  5683.         None
  5684.     
  5685.     
  5686.     DESCRIPTION:
  5687.     
  5688.              This function perform a copy  between  80X86  processor  memory
  5689.           segments. A number of bytes equal to "size"  is  copied  from  the
  5690.           source segment and offset to the destination segment and offset.
  5691.     
  5692.     
  5693.     EXAMPLES:
  5694.     
  5695.         /* Save the video display contents */
  5696.         copy_seg(get_ds(), buffer, _V_BASE, 0, (25*80)*2);
  5697.     CPU                                                                 CPU
  5698.     
  5699.     
  5700.     
  5701.     PROTOTYPE:
  5702.     
  5703.         int cpu()
  5704.     
  5705.     
  5706.     ARGUMENTS:
  5707.     
  5708.         None
  5709.     
  5710.     
  5711.     RETURN VALUE:
  5712.     
  5713.         0       - CPU is 8088 or 8086
  5714.         1       - CPU is 80188 or 80186
  5715.         2       - CPU is 80286
  5716.         3       - CPU is 80386 or 80486
  5717.     
  5718.     
  5719.     DESCRIPTION:
  5720.     
  5721.              This function returns a simple  integer  which  identifies  the
  5722.           processor type on which the program is currently executing.
  5723.     
  5724.     
  5725.     EXAMPLES:
  5726.     
  5727.         if(cpu() < 2)
  5728.             abort("This program requires at least an 80286");
  5729.     CPUTC                                                             CPUTC
  5730.     
  5731.     
  5732.     
  5733.     PROTOTYPE:
  5734.     
  5735.         Cputc(char c)
  5736.     
  5737.     
  5738.     ARGUMENTS:
  5739.     
  5740.         c       - Character to write to communciation port
  5741.     
  5742.     
  5743.     RETURN VALUE:
  5744.     
  5745.         None
  5746.     
  5747.     
  5748.     DESCRIPTION:
  5749.     
  5750.              The  "Cputc"  function  writes  the  given  character  to   the
  5751.           communcinations port previously opened by "Copen".
  5752.     
  5753.     
  5754.     EXAMPLES:
  5755.     
  5756.         while(*ptr)         /* Write a string to comm port */
  5757.             Cputc(*ptr++);
  5758.     CSIGNALS                                                       CSIGNALS
  5759.     
  5760.     
  5761.     
  5762.     PROTOTYPE:
  5763.     
  5764.         int Csignals()
  5765.     
  5766.     
  5767.     ARGUMENTS:
  5768.     
  5769.         None
  5770.     
  5771.     
  5772.     RETURN VALUE:
  5773.     
  5774.         The modem input signals read from the open comm port
  5775.     
  5776.     
  5777.     DESCRIPTION:
  5778.     
  5779.              This function reads the modem input signals (DSR, CD,  RI  etc)
  5780.           from the serial communication port previously opened  by  "Copen",
  5781.           and returns them as an integer value.
  5782.     
  5783.              The meaning of the individual bits in  the  value  returned  by
  5784.           "Csignals" is documented in the "comm.h" header file.
  5785.     
  5786.     
  5787.     EXAMPLES:
  5788.     
  5789.         if(!(Csignals() & DSR)) {
  5790.             Cclose();
  5791.             abort("Modem not ready"); }
  5792.     CTESTC                                                           CTESTC
  5793.     
  5794.     
  5795.     
  5796.     PROTOTYPE:
  5797.     
  5798.         int Ctestc()
  5799.     
  5800.     
  5801.     ARGUMENTS:
  5802.     
  5803.         None
  5804.     
  5805.     
  5806.     RETURN VALUE:
  5807.     
  5808.         0-255   - Character read from comm port
  5809.         -1      - No character available
  5810.     
  5811.     
  5812.     DESCRIPTION:
  5813.     
  5814.              This function tests for a  character  from  the  communications
  5815.           port previously opened with "Copen", and returns that character if
  5816.           one if found. If no character is available, "Ctestc" returns -1.
  5817.     
  5818.     
  5819.     EXAMPLES:
  5820.     
  5821.         if((c = Ctestc()) == -1) {
  5822.             Cclose();
  5823.             abort("No character available"); }
  5824.     DISABLE                                                         DISABLE
  5825.     
  5826.     
  5827.     
  5828.     PROTOTYPE:
  5829.     
  5830.         disable();
  5831.     
  5832.     
  5833.     ARGUMENTS:
  5834.     
  5835.         None
  5836.     
  5837.     
  5838.     RETURN VALUE:
  5839.     
  5840.         None
  5841.     
  5842.     
  5843.     DESCRIPTION:
  5844.     
  5845.              The "disable" function  disables  the  8086  interrupt  system,
  5846.           preventing the processor from servicing  interrupts.  It  is  used
  5847.           whenever the execution of an interrupt handler may interfere  with
  5848.           a particular operation.
  5849.     
  5850.              When this function is used, the  "enable"  function  should  be
  5851.           called as soon as possible after "disable". Failure to do this may
  5852.           result in loss of system  functions  performed  under  interrupts,
  5853.           such as timekeeping, and serial communications (Via MICRO-C serial
  5854.           drivers).
  5855.     
  5856.     
  5857.     EXAMPLES:
  5858.     
  5859.         disable();                  /* Disallow interrupts */
  5860.         Cflags &= ~TRANSPARENT;     /* Remove transparency */
  5861.         enable();                   /* Re-allow interrupts */
  5862.     ENABLE                                                           ENABLE
  5863.     
  5864.     
  5865.     
  5866.     PROTOTYPE:
  5867.     
  5868.         enable();
  5869.     
  5870.     
  5871.     ARGUMENTS:
  5872.     
  5873.         None
  5874.     
  5875.     
  5876.     RETURN VALUE:
  5877.     
  5878.         None
  5879.     
  5880.     
  5881.     DESCRIPTION:
  5882.     
  5883.              The  "enable"  function  enables  the  8086  interrupt  system,
  5884.           allowing the processor to service interrupts. It should be  called
  5885.           as soon as possible following the use of the "disable" function.
  5886.     
  5887.     
  5888.     EXAMPLES:
  5889.     
  5890.         disable();                  /* Disallow interrupts */
  5891.         Cflags |= TRANSPARENT;      /* Force  transparency */
  5892.         enable();                   /* Re-allow interrupts */
  5893.     EXEC                                                               EXEC
  5894.     
  5895.     
  5896.     
  5897.     PROTOTYPE:
  5898.     
  5899.         int exec(char *exefile, char *args)
  5900.     
  5901.     
  5902.     ARGUMENTS:
  5903.     
  5904.         exefile - Full pathname of a '.COM' or '.EXE' file
  5905.         args    - Command tail containing arguments
  5906.     
  5907.     
  5908.     RETURN VALUE:
  5909.     
  5910.         0 if successful, otherwise an MS-DOS error code
  5911.     
  5912.     
  5913.     DESCRIPTION:
  5914.     
  5915.              The "exec" function causes MS-DOS to suspend the  execution  of
  5916.           the MICRO-C program, and then to execute the indicated  '.EXE'  or
  5917.           '.COM' program file. When that program  terminates,  execution  of
  5918.           the MICRO-C program will resume.
  5919.     
  5920.              This is a low level interface to the  MS-DOS  'EXEC'  function,
  5921.           and as such, it does not search your PATH, does not process '.BAT'
  5922.           files, nor provide any I/O redirection facilities. If you want  to
  5923.           make use of these features (which are provided by  'COMMAND.COM'),
  5924.           use the higher level 'SYSTEM' function.
  5925.     
  5926.     
  5927.     EXAMPLES:
  5928.     
  5929.         printf("Type 'EXIT' to return to the MICRO-C program\n");
  5930.         exec("C:\\COMMAND.COM", "");    /* Start up a sub-shell */
  5931.     FREE_SEG                                                       FREE_SEG
  5932.     
  5933.     
  5934.     
  5935.     PROTOTYPE:
  5936.     
  5937.         int free_seg(int segment)
  5938.     
  5939.     
  5940.     ARGUMENTS:
  5941.     
  5942.         segment - A previously allocated segment of memory
  5943.     
  5944.     
  5945.     RETURN VALUE:
  5946.     
  5947.         0       - The segment was released
  5948.         !0      - DOS error code
  5949.     
  5950.     
  5951.     DESCRIPTION:
  5952.     
  5953.              The "free_seg" function releases a segment of memory previously
  5954.           allocated by "alloc_seg", and returns it to the operating  system.
  5955.           This should be used whenever your  program  has  finished  with  a
  5956.           segment of extra memory which it has allocated.
  5957.     
  5958.     
  5959.     EXAMPLES:
  5960.     
  5961.         aseg = alloc_seg(4096);         /* Allocate a 64K segment */
  5962.         set_es(aseg);                   /* Set up extra segment */
  5963.         asm_func();                     /* Call assembler function */
  5964.         free_seg(aseg);                 /* Releas the memory */
  5965.     GET_ATTR                                                       GET_ATTR
  5966.     
  5967.     
  5968.     
  5969.     PROTOTYPE:
  5970.     
  5971.         int get_attr(char *pathname, int &attrs)
  5972.     
  5973.     
  5974.     ARGUMENTS:
  5975.     
  5976.         pathname- Name of file to get attributes of
  5977.         attrs   - Integer to receive attributes
  5978.     
  5979.     
  5980.     RETURN VALUE:
  5981.     
  5982.         0 if successful, otherwise an operating system error code
  5983.     
  5984.     
  5985.     DESCRIPTION:
  5986.     
  5987.              This function retreives the attributes of the specified file.
  5988.     
  5989.              The meaning of the individual bits  in  the  "attrs"  value  is
  5990.           defined in the "file.h" header file.
  5991.     
  5992.     
  5993.     EXAMPLES:
  5994.     
  5995.         get_attr("tempfile", &attributes);
  5996.     GET_CS                                                           GET_CS
  5997.     
  5998.     
  5999.     
  6000.     PROTOTYPE:
  6001.     
  6002.         int get_cs()
  6003.     
  6004.     
  6005.     ARGUMENTS:
  6006.     
  6007.         None
  6008.     
  6009.     
  6010.     RETURN VALUE:
  6011.     
  6012.         The current processor CODE segment
  6013.     
  6014.     
  6015.     DESCRIPTION:
  6016.     
  6017.              This  function  is  available  only  on  the  8086  family   of
  6018.           processors, and returns the current processor CODE segment.
  6019.     
  6020.     
  6021.     EXAMPLES:
  6022.     
  6023.         code_seg = get_cs();
  6024.     GET_DATE                                                       GET_DATE
  6025.     
  6026.     
  6027.     
  6028.     PROTOTYPE:
  6029.     
  6030.         get_date(int &day, int &month, int &year)
  6031.     
  6032.     
  6033.     ARGUMENTS:
  6034.     
  6035.         &day    - Address of integer to receive day (1-31)
  6036.         &month  - Address of integer to receive month (1-12)
  6037.         &year   - Address of integer to receive year (1980-2099)
  6038.     
  6039.     
  6040.     RETURN VALUE:
  6041.     
  6042.         None
  6043.     
  6044.     
  6045.     DESCRIPTION:
  6046.     
  6047.              This function gets the current system date in day,  month,  and
  6048.           year.
  6049.     
  6050.     
  6051.     EXAMPLES:
  6052.     
  6053.         get_date(&day, &month, &year);
  6054.         printf("%s %u, %u", months[month], day, year);
  6055.     GET_DRIVE                                                     GET_DRIVE
  6056.     
  6057.     
  6058.     
  6059.     PROTOTYPE:
  6060.     
  6061.         int get_drive()
  6062.     
  6063.     
  6064.     ARGUMENTS:
  6065.     
  6066.         None
  6067.     
  6068.     
  6069.     RETURN VALUE:
  6070.     
  6071.         The currently active (default) disk drive (0=A, 1=B, 2=C, ...)
  6072.     
  6073.     
  6074.     DESCRIPTION:
  6075.     
  6076.              The "get_drive" function returns the drive index (0-n)  of  the
  6077.           currently active or "default" MS-DOS disk drive.
  6078.     
  6079.     
  6080.     EXAMPLES:
  6081.     
  6082.         old_drive = get_drive();
  6083.         set_drive(new_drive);
  6084.     GET_DS                                                           GET_DS
  6085.     
  6086.     
  6087.     
  6088.     PROTOTYPE:
  6089.     
  6090.         int get_ds()
  6091.     
  6092.     
  6093.     ARGUMENTS:
  6094.     
  6095.         None
  6096.     
  6097.     
  6098.     RETURN VALUE:
  6099.     
  6100.         The current processor DATA segment
  6101.     
  6102.     
  6103.     DESCRIPTION:
  6104.     
  6105.              This  function  is  available  only  on  the  8086  family   of
  6106.           processors, and returns the current processor DATA segment.
  6107.     
  6108.     
  6109.     EXAMPLES:
  6110.     
  6111.         data_seg = get_ds();
  6112.     GET_ES                                                           GET_ES
  6113.     
  6114.     
  6115.     
  6116.     PROTOTYPE:
  6117.     
  6118.         int get_es()
  6119.     
  6120.     
  6121.     ARGUMENTS:
  6122.     
  6123.         None
  6124.     
  6125.     
  6126.     RETURN VALUE:
  6127.     
  6128.         The current processor EXTRA segment
  6129.     
  6130.     
  6131.     DESCRIPTION:
  6132.     
  6133.              This  function  is  available  only  on  the  8086  family   of
  6134.           processors, and returns the current processor EXTRA segment.
  6135.     
  6136.     
  6137.     EXAMPLES:
  6138.     
  6139.         code_seg = get_es();
  6140.     GET_TIME                                                       GET_TIME
  6141.     
  6142.     
  6143.     
  6144.     PROTOTYPE:
  6145.     
  6146.         get_time(int &hour, int &minite, int &second)
  6147.     
  6148.     
  6149.     ARGUMENTS:
  6150.     
  6151.         &hour   - Address of integer to receive hour (0-23)
  6152.         &minite - Address of integer to receive minite (0-59)
  6153.         &second - Address of integer to receive second (0-59)
  6154.     
  6155.     
  6156.     RETURN VALUE:
  6157.     
  6158.         None
  6159.     
  6160.     
  6161.     DESCRIPTION:
  6162.     
  6163.              This function gets the current system time  in  hours,  minites
  6164.           and seconds.
  6165.     
  6166.     
  6167.     EXAMPLES:
  6168.     
  6169.         get_time(&hour, &minite, &second);
  6170.         printf("%02:%02:%02", hour, minite, second);
  6171.     RESIZE_SEG                                                   RESIZE_SEG
  6172.     
  6173.     
  6174.     
  6175.     PROTOTYPE:
  6176.     
  6177.         int resize_seg(int segment, int size)
  6178.     
  6179.     
  6180.     ARGUMENTS:
  6181.     
  6182.         segment - A previously allocated segment of memory
  6183.         size    - Desired size (in 16 byte paragraphs)
  6184.     
  6185.     
  6186.     RETURN VALUE:
  6187.     
  6188.         0       - The segments size has been adjusted
  6189.         !0      - DOS error code
  6190.     
  6191.     
  6192.     DESCRIPTION:
  6193.     
  6194.              The "resize_seg" function provides a  method  of  changing  the
  6195.           size of a segment of memory previously allocated via  "alloc_seg".
  6196.           If not enough memory is available, the function will fail  with  a
  6197.           ono-zero return value.
  6198.     
  6199.              This function may also be used to adjust the memoey  allocation
  6200.           of the programs image, by passing it the segment  address  of  the
  6201.           programs own PSP. This value is available in the external variable
  6202.           "PSP".
  6203.     
  6204.              MICRO-C normally allocates 64K for  programs  compiled  in  the
  6205.           TINY model, and (64K + (256 byte PSP) + (size of executable code))
  6206.           for programs compiled in the SMALL model. This  allocation  should
  6207.           NEVER be reduced, however you  may  enlarge  it  if  your  program
  6208.           wishes to access additional data  immediately  following  its  own
  6209.           DATA/STACK segment.
  6210.     
  6211.     
  6212.     EXAMPLES:
  6213.     
  6214.         extern int PSP;
  6215.     
  6216.         main()
  6217.         {
  6218.             if(resize_seg(PSP, 8192))   /* Append 64K buffer */
  6219.                 abort("Not enough memory!!!");
  6220.             ...     /* Remainder of program */
  6221.         }
  6222.     RESTORE_VIDEO                                             RESTORE_VIDEO
  6223.     
  6224.     
  6225.     
  6226.     PROTOTYPE:
  6227.     
  6228.         restore_video(char buffer[4006]);
  6229.     
  6230.     
  6231.     ARGUMENTS:
  6232.     
  6233.         buffer  - Video save area.
  6234.     
  6235.     
  6236.     RETURN VALUE:
  6237.     
  6238.         None
  6239.     
  6240.     
  6241.     DESCRIPTION:
  6242.     
  6243.              The RESTORE_VIDEO function restores the contents and  state  of
  6244.           the  IBM  P.C.  video  display  to  the  state  it  was  in   when
  6245.           "SAVE_VIDEO" was executed. At the present time,  the  function  is
  6246.           effective only for  text  modes.  Graphics  screens  will  not  be
  6247.           restored, due to the high memory requirements.
  6248.     
  6249.              Although this function is useful in ANY program (to restore the
  6250.           DOS screen before termination), it is most useful in "POP-UP"  ram
  6251.           resident programs (See "TSR" function), to save the screen of  any
  6252.           application which may be running when you pop up.
  6253.     
  6254.              The video state is restored from the passed "buffer"  argument,
  6255.           which is 4006 bytes in size, and  must  have  been  filled  in  by
  6256.           "SAVE_VIDEO". It has the following format:
  6257.     
  6258.                   buffer[0]         - Video mode
  6259.                     "   [1]         - Video page
  6260.                     "   [2]         - 'X' cursor position
  6261.                     "   [3]         - 'Y' cursor position
  6262.                     "   [4]         - Ending line for cursor
  6263.                     "   [5]         - Starting line for cursor
  6264.                     "   [6-4005]    - Saved video screen contents
  6265.     
  6266.     
  6267.     EXAMPLES:
  6268.     
  6269.         popup_func()
  6270.         {
  6271.             save_video();
  6272.             perform_function();
  6273.             restore_video();
  6274.         }
  6275.     SAVE_VIDEO                                                   SAVE_VIDEO
  6276.     
  6277.     
  6278.     
  6279.     PROTOTYPE:
  6280.     
  6281.         save_video(char buffer[4006]);
  6282.     
  6283.     
  6284.     ARGUMENTS:
  6285.     
  6286.         buffer  - Video save area.
  6287.     
  6288.     
  6289.     RETURN VALUE:
  6290.     
  6291.         None
  6292.     
  6293.     
  6294.     DESCRIPTION:
  6295.     
  6296.              The SAVE_VIDEO function saves the current contents and state of
  6297.           the IBM P.C. video display. The screen may be restored at any time
  6298.           using "RESTORE_VIDEO".  At  the  present  time,  the  function  is
  6299.           effective only for text modes. Graphics screens will not be saved,
  6300.           due to the high memory requirements.
  6301.     
  6302.              Although this function is useful in ANY program (to restore the
  6303.           DOS screen before termination), it is most useful in "POP-UP"  ram
  6304.           resident programs (See "TSR" function), to save the screen of  any
  6305.           application which may be running when you pop up.
  6306.     
  6307.              The video state is saved in the passed "buffer" argument, which
  6308.           is 4006 bytes in size, and has the following format:
  6309.     
  6310.                   buffer[0]         - Video mode
  6311.                     "   [1]         - Video page
  6312.                     "   [2]         - 'X' cursor position
  6313.                     "   [3]         - 'Y' cursor position
  6314.                     "   [4]         - Ending line for cursor
  6315.                     "   [5]         - Starting line for cursor
  6316.                     "   [6-4005]    - Saved video screen contents
  6317.     
  6318.     
  6319.     EXAMPLES:
  6320.     
  6321.         popup_func()
  6322.         {
  6323.             save_video();
  6324.             perform_function();
  6325.             restore_video();
  6326.         }
  6327.     SET_ATTR                                                       SET_ATTR
  6328.     
  6329.     
  6330.     
  6331.     PROTOTYPE:
  6332.     
  6333.         int set_attr(char *pathname, int attrs)
  6334.     
  6335.     
  6336.     ARGUMENTS:
  6337.     
  6338.         pathname- Name of file to get attributes of
  6339.         attrs   - New attributes
  6340.     
  6341.     
  6342.     RETURN VALUE:
  6343.     
  6344.         0 if successful, otherwise an operating system error code
  6345.     
  6346.     
  6347.     DESCRIPTION:
  6348.     
  6349.              This function sets the system attributes of the specified file.
  6350.     
  6351.              The meaning of the individual bits  in  the  "attrs"  value  is
  6352.           defined in the "file.h" header file.
  6353.     
  6354.     
  6355.     EXAMPLES:
  6356.     
  6357.         set_attr("tempfile", READONLY|HIDDEN);
  6358.     SET_DATE                                                       SET_DATE
  6359.     
  6360.     
  6361.     
  6362.     PROTOTYPE:
  6363.     
  6364.         set_date(int day, int month, int year)
  6365.     
  6366.     
  6367.     ARGUMENTS:
  6368.     
  6369.         day     - New day (1-31)
  6370.         month   - New month (1-12)
  6371.         year    - New year (1980-2099)
  6372.     
  6373.     
  6374.     RETURN VALUE:
  6375.     
  6376.         0       - Success
  6377.         -1      - Invalid date given
  6378.     
  6379.     
  6380.     DESCRIPTION:
  6381.     
  6382.              This function sets the current system date to day,  month,  and
  6383.           year.
  6384.     
  6385.     
  6386.     EXAMPLES:
  6387.     
  6388.         set_date(1, 1, 1980);   /* Set to Jan 1, 1980 */
  6389.     SET_DRIVE                                                     SET_DRIVE
  6390.     
  6391.     
  6392.     
  6393.     PROTOTYPE:
  6394.     
  6395.         int set_drive(int drive)
  6396.     
  6397.     
  6398.     ARGUMENTS:
  6399.     
  6400.         Drive   - New drive index (0=A, 1=B, 2=C ...)
  6401.     
  6402.     
  6403.     RETURN VALUE:
  6404.     
  6405.         The total number of "logical" disk drives in the system
  6406.     
  6407.     
  6408.     DESCRIPTION:
  6409.     
  6410.              The "set_drive" function sets the disk drive indicated  by  the
  6411.           "drive" index (0-x) to be the currently active or "default" MS-DOS
  6412.           disk drive.
  6413.     
  6414.     
  6415.     EXAMPLES:
  6416.     
  6417.         old_drive = get_drive();
  6418.         set_drive(new_drive);
  6419.     SET_ES                                                           SET_ES
  6420.     
  6421.     
  6422.     
  6423.     PROTOTYPE:
  6424.     
  6425.         int set_es(int segment)
  6426.     
  6427.     
  6428.     ARGUMENTS:
  6429.     
  6430.         segment - The 16 bit new segment value
  6431.     
  6432.     
  6433.     RETURN VALUE:
  6434.     
  6435.         None
  6436.     
  6437.     
  6438.     DESCRIPTION:
  6439.     
  6440.              This  function  is  available  only  on  the  8086  family   of
  6441.           processors, and sets the processors EXTRA segment to the indicated
  6442.           value.
  6443.     
  6444.     
  6445.     EXAMPLES:
  6446.     
  6447.         set_es(get_ds());       /* Copy DATA to EXTRA segments */
  6448.     SET_TIME                                                       SET_TIME
  6449.     
  6450.     
  6451.     
  6452.     PROTOTYPE:
  6453.     
  6454.         set_time(int hour, int minite, int second)
  6455.     
  6456.     
  6457.     ARGUMENTS:
  6458.     
  6459.         hour    - New hour (0-23)
  6460.         minite  - New minite (0-59)
  6461.         second  - New second (0-59)
  6462.     
  6463.     
  6464.     RETURN VALUE:
  6465.     
  6466.         0       - Success
  6467.         -1      - Invalid time given
  6468.     
  6469.     
  6470.     DESCRIPTION:
  6471.     
  6472.              This function sets the current system time to "hour",  "minite"
  6473.           and "second".
  6474.     
  6475.     
  6476.     EXAMPLES:
  6477.     
  6478.         set_time(0, 0, 0);  /* Set to 00:00:00 (midnight) */
  6479.     TSR                                                                 TSR
  6480.     
  6481.     
  6482.     
  6483.     PROTOTYPE:
  6484.     
  6485.         tsr(&func, int hotkey, int alloc)
  6486.     
  6487.     
  6488.     ARGUMENTS:
  6489.     
  6490.         func    - Address of function to execute
  6491.         hotkey  - POP-UP activation hotkeys
  6492.         alloc   - Memory allocation
  6493.     
  6494.     
  6495.     RETURN VALUE:
  6496.     
  6497.         Function normally never returns, but if it does, an
  6498.         operating system error code is passed back.
  6499.     
  6500.     
  6501.     DESCRIPTION:
  6502.     
  6503.              The TSR function terminates the MICRO-C program, but leaves  it
  6504.           resident in memory. When the specified "HOT KEYS" are detected  on
  6505.           the IBM PC keyboard, the context of whatever program is running is
  6506.           saved, and the specified MICRO-C function  is  called.  When  that
  6507.           function returns, the interrupted program is resumed.
  6508.     
  6509.              When activated this way, THE "func" FUNCTION MUST NOT TERMINATE
  6510.           WITH "exit" or one of its related functions (abort etc.). THE ONLY
  6511.           WAY IT MAY TERMINATE IS TO "return" NORMALLY.
  6512.     
  6513.              The meaning of "hotkey" is defined in the "tsr.h" header file.
  6514.     
  6515.              The "alloc" paremeter specifies how much extra memory is to  be
  6516.           retained in the TSR image for use by the MICRO-C  stack  and  heap
  6517.           memory allocation functions. The "func"  function(s)  must  insure
  6518.           that the total amount of memory used by the  stack  and  calls  to
  6519.           "malloc" does not exceed this value.
  6520.     
  6521.              NOTE: "malloc" will fail if the heap grows to within 1K of  the
  6522.           stack pointer.
  6523.     
  6524.              All memory used by code, global variables,  string  space,  and
  6525.           "malloc"  calls  prior  to  the  use  of  "tsr"  is  automatically
  6526.           retained, and should not be included in the "alloc" value.
  6527.     
  6528.              TSR programs which perform screen I/O should take care to  save
  6529.           and restore the screen contents when popping up and down.
  6530.     
  6531.     
  6532.     EXAMPLES:
  6533.     
  6534.         tsr(&popup_func, ALT+L_SHIFT, 1024);
  6535.     VCLEAR_BOX                                                   VCLEAR_BOX
  6536.     
  6537.     
  6538.     
  6539.     PROTOTYPE:
  6540.     
  6541.         vclear_box(int x, int y, int w, int h)
  6542.     
  6543.     
  6544.     ARGUMENTS:
  6545.     
  6546.         x       - COLUMN of top left corner of box
  6547.         y       - ROW of top left corner of box
  6548.         w       - Width of box (columns)
  6549.         h       - Height of box (rows)
  6550.     
  6551.     
  6552.     RETURN VALUE:
  6553.     
  6554.         None
  6555.     
  6556.     
  6557.     DESCRIPTION:
  6558.     
  6559.              This function clears a box of the specified height  and  width,
  6560.           at the indicated 'X' and 'Y'  coordinates,  on  the  IBM-PC  video
  6561.           screen using the block graphics  characters.  The  entire  box  is
  6562.           cleared to spaces.
  6563.     
  6564.              "VOPEN" MUST be called prior to using this function.
  6565.     
  6566.     
  6567.     EXAMPLES:
  6568.     
  6569.         vclear_box(21, 11, 8, 3);   /* Clear a BOX */
  6570.     VCLEOL                                                           VCLEOL
  6571.     
  6572.     
  6573.     
  6574.     PROTOTYPE:
  6575.     
  6576.         vcleol()
  6577.     
  6578.     
  6579.     ARGUMENTS:
  6580.     
  6581.         None
  6582.     
  6583.     
  6584.     RETURN VALUE:
  6585.     
  6586.         None
  6587.     
  6588.     
  6589.     DESCRIPTION:
  6590.     
  6591.              This function clears the IBM PC video screen from  the  current
  6592.           cursor position to the end of a line.
  6593.     
  6594.              You must "#include video.h", and execute "VOPEN" prior to using
  6595.           this function.
  6596.     
  6597.     
  6598.     EXAMPLES:
  6599.     
  6600.         vprintf("Input> ");     /* Display a prompt */
  6601.         vcleol();               /* Clear remainder of input line */
  6602.     VCLEOS                                                           VCLEOS
  6603.     
  6604.     
  6605.     
  6606.     PROTOTYPE:
  6607.     
  6608.         vcleos()
  6609.     
  6610.     
  6611.     ARGUMENTS:
  6612.     
  6613.         None
  6614.     
  6615.     
  6616.     RETURN VALUE:
  6617.     
  6618.         None
  6619.     
  6620.     
  6621.     DESCRIPTION:
  6622.     
  6623.              This function clears the IBM PC video screen from  the  current
  6624.           cursor position to the end of a screen.
  6625.     
  6626.              "VOPEN" MUST be called prior to using this function.
  6627.     
  6628.     
  6629.     EXAMPLES:
  6630.     
  6631.         vgotoxy(0, 10);         /* position at line 11 */
  6632.         vcleos();               /* Clear lower part of screen */
  6633.     VCLSCR                                                           VCLSCR
  6634.     
  6635.     
  6636.     
  6637.     PROTOTYPE:
  6638.     
  6639.         vclscr()
  6640.     
  6641.     
  6642.     ARGUMENTS:
  6643.     
  6644.         None
  6645.     
  6646.     
  6647.     RETURN VALUE:
  6648.     
  6649.         None
  6650.     
  6651.     
  6652.     DESCRIPTION:
  6653.     
  6654.              This function clears the entire IBM PC video screen and  resets
  6655.           the cursor position to the top left hand corner.
  6656.     
  6657.              "VOPEN" MUST be called prior to using this function.
  6658.     
  6659.     
  6660.     EXAMPLES:
  6661.     
  6662.         if(c = 0x1b) {          /* Escape command */
  6663.             vclscr();       /* Clear the screen */
  6664.             vprintf("%s has terminated\n", argv[0]);
  6665.             exit(-1); }
  6666.     VCURSOR_BLOCK                                             VCURSOR_BLOCK
  6667.     
  6668.     
  6669.     
  6670.     PROTOTYPE:
  6671.     
  6672.         vcursor_block()
  6673.     
  6674.     
  6675.     ARGUMENTS:
  6676.     
  6677.         None
  6678.     
  6679.     
  6680.     RETURN VALUE:
  6681.     
  6682.         None
  6683.     
  6684.     
  6685.     DESCRIPTION:
  6686.     
  6687.              This function enables (turns on) display of the cursor  on  the
  6688.           IBM PC video display. The  cursor  is  shown  as  flashing  block,
  6689.           occupying the entire character window.
  6690.     
  6691.              "VOPEN" MUST be called prior to using this function.
  6692.     
  6693.     
  6694.     EXAMPLES:
  6695.     
  6696.         if(insert)              /* Test insert mode flag */
  6697.             vcursor_block();    /* Indicate inserting with block cursor */
  6698.         else
  6699.             vcursor_line();     /* Indicate overwrite with line cursor */
  6700.     VCURSOR_LINE                                               VCURSOR_LINE
  6701.     
  6702.     
  6703.     
  6704.     PROTOTYPE:
  6705.     
  6706.         vcursor_line()
  6707.     
  6708.     
  6709.     ARGUMENTS:
  6710.     
  6711.         None
  6712.     
  6713.     
  6714.     RETURN VALUE:
  6715.     
  6716.         None
  6717.     
  6718.     
  6719.     DESCRIPTION:
  6720.     
  6721.              This function enables (turns on) display of the cursor  on  the
  6722.           IBM PC video display. The cursor is shown  as  a  single  flashing
  6723.           line, at the bottom of the character window.
  6724.     
  6725.              "VOPEN" MUST be called prior to using this function.
  6726.     
  6727.     
  6728.     EXAMPLES:
  6729.     
  6730.         vcursor_line();     /* Re-enable the cursor */
  6731.         exit(0);            /* And terminate */
  6732.     VCURSOR_OFF                                                 VCURSOR_OFF
  6733.     
  6734.     
  6735.     
  6736.     PROTOTYPE:
  6737.     
  6738.         vcursor_off()
  6739.     
  6740.     
  6741.     ARGUMENTS:
  6742.     
  6743.         None
  6744.     
  6745.     
  6746.     RETURN VALUE:
  6747.     
  6748.         None
  6749.     
  6750.     
  6751.     DESCRIPTION:
  6752.     
  6753.              This function inhibits (turns off) display of the cursor on the
  6754.           IBM PC video display. This affects the cursor display only, screen
  6755.           output will  continue  to  be  displayed  at  the  correct  cursor
  6756.           position.
  6757.     
  6758.              "VOPEN" MUST be called prior to using this function.
  6759.     
  6760.     
  6761.     EXAMPLES:
  6762.     
  6763.         vclscr();           /* Clear screen */
  6764.         vcursor_off();      /* Inhibit cursor */
  6765.         vmenu(10, 10, main_menu, 0, &index);    /* Present main menu */
  6766.     VDRAW_BOX                                                     VDRAW_BOX
  6767.     
  6768.     
  6769.     
  6770.     PROTOTYPE:
  6771.     
  6772.         vdraw_box(int x, int y, int w, int h)
  6773.     
  6774.     
  6775.     ARGUMENTS:
  6776.     
  6777.         x       - COLUMN of top left corner of box
  6778.         y       - ROW of top left corner of box
  6779.         w       - Width of box (columns)
  6780.         h       - Height of box (rows)
  6781.     
  6782.     
  6783.     RETURN VALUE:
  6784.     
  6785.         None
  6786.     
  6787.     
  6788.     DESCRIPTION:
  6789.     
  6790.              This function draws a box of the specified height and width, at
  6791.           the indicated 'X' and 'Y' coordinates, on the IBM-PC video  screen
  6792.           using the block graphics characters.
  6793.     
  6794.              "VOPEN" MUST be called prior to using this function.
  6795.     
  6796.     
  6797.     EXAMPLES:
  6798.     
  6799.         vdraw_box(20, 10, 10, 5);   /* Draw a BOX */
  6800.     VERSION                                                         VERSION
  6801.     
  6802.     
  6803.     
  6804.     PROTOTYPE:
  6805.     
  6806.         int version()
  6807.     
  6808.     
  6809.     ARGUMENTS:
  6810.     
  6811.         None
  6812.     
  6813.     
  6814.     RETURN VALUE:
  6815.     
  6816.         MS-DOS operating system version number
  6817.     
  6818.     
  6819.     DESCRIPTION:
  6820.     
  6821.              The "version" function is  available  only  under  MS-DOS,  and
  6822.           returns the version number of the operating system.
  6823.     
  6824.              The higher 8 bits of the returned  value  indicates  the  MAJOR
  6825.           version number ('3' in DOS 3.1)
  6826.     
  6827.              The lower 8 bits of the  returned  value  indicates  the  MINOR
  6828.           version nuber ('1' in DOS 3.1).
  6829.     
  6830.     
  6831.     EXAMPLES:
  6832.     
  6833.         if(version() < 0x031E)
  6834.             abort("Requires DOS 3.30 or higher\n");
  6835.     VGETC                                                             VGETC
  6836.     
  6837.     
  6838.     
  6839.     PROTOTYPE:
  6840.     
  6841.         int vgetc()
  6842.     
  6843.     
  6844.     ARGUMENTS:
  6845.     
  6846.         None
  6847.     
  6848.     
  6849.     RETURN VALUE:
  6850.     
  6851.         0-127   - ASCII value of key pressed
  6852.         < 0     - Special function key as defined in "video.h"
  6853.     
  6854.     
  6855.     DESCRIPTION:
  6856.     
  6857.              The "vgetc" function waits until a key is pressed on the system
  6858.           console, and returns its value.
  6859.     
  6860.              Note that due to the buffering of the  IBM-PC  keyboard,  every
  6861.           keypress will be reported, even if the VGETC  function  is  called
  6862.           after a key is pressed and released.
  6863.     
  6864.     
  6865.     EXAMPLES:
  6866.     
  6867.         switch(vgetc()) {       /* Handle input keys
  6868.                 . . .
  6869.         }
  6870.     VGETS                                                             VGETS
  6871.     
  6872.     
  6873.     
  6874.     PROTOTYPE:
  6875.     
  6876.         int vgets(int x, int y, char *prompt, char *field, int width)
  6877.     
  6878.     
  6879.     ARGUMENTS:
  6880.     
  6881.         x       - COLUMN of top left corner of input box
  6882.         y       - ROW of top left corner of input box
  6883.         prompt  - String to prompt with
  6884.         field   - String to receive the data
  6885.         width   - Width in characters of input field
  6886.     
  6887.     
  6888.     RETURN VALUE:
  6889.     
  6890.         0   - Selection was made and ENTER pressed.
  6891.         !0  - Input was aborted via ESCAPE key.
  6892.     
  6893.     
  6894.     DESCRIPTION:
  6895.     
  6896.              The "vgets" function draws a box on the  video  screen  at  the
  6897.           specified X and Y coordinates, then prompts for  and  receives  an
  6898.           input string in the box. The box is drawn large enough to  contain
  6899.           the prompt and the specified width of input field. The  prompt  is
  6900.           displayed at the left hand side of the  box,  and  the  cursor  is
  6901.           positioned immediatly following it, at  the  start  of  the  input
  6902.           field.
  6903.     
  6904.              The "field" parameter is the address of a  character  array  to
  6905.           receive the input string. The previous value of the "field"  array
  6906.           is inserted into the input box when VGETS is invoked.  If  you  do
  6907.           not want to display  an  old  value,  you  should  set  the  first
  6908.           character pointed to by field to zero, before calling VGETS.
  6909.     
  6910.              When entering the  string,  the  user  may  use  the  following
  6911.           special keys to edit the input field:
  6912.     
  6913.                 Right Arrow - Move forward one character
  6914.                 Left  Arrow - Move backward one character
  6915.                 Delete      - Delete the character under the cursor
  6916.                 Backspace   - Move backward one character and delete.
  6917.                 Home        - Move to beginning of string
  6918.                 End         - Move to end of string
  6919.                 PgUp        - Clear (erase) entire string
  6920.                 PgDn        - Clear from cursor to end of string
  6921.                 Enter       - Accept (enter) the string
  6922.                 ESC         - Abort the input request
  6923.     
  6924.              All data entered in the input box is  inserted  into  any  data
  6925.           which is already present.
  6926.     
  6927.     
  6928.     
  6929.     EXAMPLES:
  6930.     
  6931.         name[0] = 0;
  6932.         if(vgets(10, 10, "Your name?", name, 30))
  6933.             return;     /* Aborted, exit to higher level */
  6934.     VGOTOXY                                                         VGOTOXY
  6935.     
  6936.     
  6937.     
  6938.     PROTOTYPE:
  6939.     
  6940.         vgotoxy(int x, int y)
  6941.     
  6942.     
  6943.     ARGUMENTS:
  6944.     
  6945.         x       - New COLUMN (0-79)
  6946.         y       - New ROW    (0-24)
  6947.     
  6948.     
  6949.     RETURN VALUE:
  6950.     
  6951.         None
  6952.     
  6953.     
  6954.     DESCRIPTION:
  6955.     
  6956.              The "vgotoxy" function positions the cursor on the IBM-PC video
  6957.           screen. Any further display output will occur at the new  ROW  and
  6958.           COLUMN on the screen.
  6959.     
  6960.              The extern "int" variable "V_XY" may be referenced to  read  or
  6961.           set the current X/Y position. The higher 8 bits  contain  the  'Y'
  6962.           coordinate, and the lower 8 bits contain the  'X'  coordinate.  If
  6963.           this variable is  used  to  set  (restore)  the  cursor  position,
  6964.           "vupdatexy" must then be called to position the physical cursor.
  6965.     
  6966.              "VOPEN" MUST be called prior to using this function.
  6967.     
  6968.     
  6969.     EXAMPLES:
  6970.     
  6971.         for(i=0; i<24; ++i) {   /* Draw a diagonal line of 'X's */
  6972.             vgotoxy(i, i);
  6973.             vputc('X'); }
  6974.     VMENU                                                             VMENU
  6975.     
  6976.     
  6977.     
  6978.     PROTOTYPE:
  6979.     
  6980.         vmenu(int x, int y, char *names[], char erase, int &index)
  6981.     
  6982.     
  6983.     ARGUMENTS:
  6984.     
  6985.         x       - COLUMN of top left corner of menu box
  6986.         y       - ROW of top left corner of menu box
  6987.         names   - Array to menu selection text (last entry = 0)
  6988.         erase   - 1=Erase BOX after selection is made
  6989.         index   - Address of message selection index variable
  6990.     
  6991.     
  6992.     RETURN VALUE:
  6993.     
  6994.         0   - Selection was made and ENTER pressed.
  6995.         !0  - Menu was aborted via ESCAPE key.
  6996.     
  6997.     
  6998.     DESCRIPTION:
  6999.     
  7000.              The "vmenu" function displays a list of menu items enclosed  in
  7001.           a box on the IBM-PC video screen at the specified ROW  and  COLUMN
  7002.           address. The user may use the UP,  DOWN,  HOME  and  END  keys  to
  7003.           select an entry by moving the INVERSE VIDEO selection cursor.
  7004.     
  7005.              When the desired selection is under the cursor,  the  selection
  7006.           is made by pressing the ENTER key.
  7007.     
  7008.              At any time the menu selection may be canceled by pressing  the
  7009.           ESCAPE key.
  7010.     
  7011.              The "names" argument must be a pointer to an array of character
  7012.           strings which are the selections to display. This array  MUST  end
  7013.           with a zero (0) element to indicate the end of the list.
  7014.     
  7015.              The "erase" flag indicates that the menu box should be  cleared
  7016.           to blanks when the selection is made. If "erase=0", the  menu  box
  7017.           is left on the screen, WITHOUT  the  selection  cursor,  with  the
  7018.           selected entry marked by '>' and  '<'.  The  menu  box  is  always
  7019.           erased when the menu is aborted with the ESCAPE key.
  7020.     
  7021.              The "index" argument is the address of an "int" variable  which
  7022.           contains the position of the selection cursor. It  controls  where
  7023.           the selection cursor  will  appear  when  the  function  is  first
  7024.           invoked (0 = first entry), and also is assigned  the  position  of
  7025.           the selection cursor when the selection is made.
  7026.     
  7027.     
  7028.     
  7029.     EXAMPLES:
  7030.     
  7031.         char *names[] = { "One", "Two", "Three", "Four", "Five", 0 };
  7032.             . . .
  7033.         index = 0;
  7034.         if(vmenu(10, 10, names, 0, &index))
  7035.             return;         /* Aborted, exit to higher level */
  7036.         switch(index) {     /* Handle selection */
  7037.             . . .
  7038.         }
  7039.     VMESSAGE                                                       VMESSAGE
  7040.     
  7041.     
  7042.     
  7043.     PROTOTYPE:
  7044.     
  7045.         vmessage(int x, int y, char *string)
  7046.     
  7047.     
  7048.     ARGUMENTS:
  7049.     
  7050.         x       - COLUMN of top left corner of message box
  7051.         y       - ROW of top left corner of message box
  7052.         string  - Message to display
  7053.     
  7054.     
  7055.     RETURN VALUE:
  7056.     
  7057.         None
  7058.     
  7059.     
  7060.     DESCRIPTION:
  7061.     
  7062.              The "vmessage" function displays a text string surrounded by  a
  7063.           BOX, on the IBM-PC video screen, at the specified ROW  and  COLUMN
  7064.           address.
  7065.     
  7066.              "VOPEN" MUST be called prior to using this function.
  7067.     
  7068.     
  7069.     EXAMPLES:
  7070.     
  7071.         vmessage(20, 20, "Press any KEY to continue");
  7072.         get_key();
  7073.         vclear_box(20, 20, 26, 2);
  7074.     VOPEN                                                             VOPEN
  7075.     
  7076.     
  7077.     
  7078.     PROTOTYPE:
  7079.     
  7080.         vopen()
  7081.     
  7082.     
  7083.     ARGUMENTS:
  7084.     
  7085.         None
  7086.     
  7087.     
  7088.     RETURN VALUE:
  7089.     
  7090.         None
  7091.     
  7092.     
  7093.     DESCRIPTION:
  7094.     
  7095.              This function initializes the IBM-PC video display adapter  for
  7096.           use with the MICRO-C video library functions.  It  determines  the
  7097.           adapter type (COLOR ot MONOCHROME),  sets  up  internal  variables
  7098.           with information required by the other video functions, and clears
  7099.           the video screen.
  7100.     
  7101.              This function MUST be called before  any  of  the  other  video
  7102.           functions in the library are used.
  7103.     
  7104.              After "vopen" is called, the extern "int" variable "V_BASE" may
  7105.           be referenced to determine the memory segment of the video display
  7106.           (B000 for monochrome, B800 for color).
  7107.     
  7108.              Any program using the video library functions must include  the
  7109.           "video.h" header file.
  7110.     
  7111.     
  7112.     EXAMPLES:
  7113.     
  7114.         vopen();
  7115.     VPRINTF                                                         VPRINTF
  7116.     
  7117.     
  7118.     
  7119.     PROTOTYPE:
  7120.     
  7121.         register vprintf(char *format, arg, ...)
  7122.     
  7123.     
  7124.     ARGUMENTS:
  7125.     
  7126.         format  - Pointer to format string
  7127.         arg     - Argument as determined by format string
  7128.         ...     - Additional arguments may be required
  7129.     
  7130.     
  7131.     RETURN VALUE:
  7132.     
  7133.         None
  7134.     
  7135.     
  7136.     DESCRIPTION:
  7137.     
  7138.              This function performs exactly as the "PRINTF" function in  the
  7139.           standard function library, except that it outputs directly to  the
  7140.           video screen using the video interface library routines.
  7141.     
  7142.              This function should be used in  preference  to  "PRINTF"  when
  7143.           using the video function library since "PRINTF" will not move  the
  7144.           video librarys cursor.
  7145.     
  7146.              NOTE: This function uses a variable number  of  arguments,  and
  7147.           must be declared as "register" (See "video.h").
  7148.     
  7149.              "VOPEN" MUST be called prior to using this function.
  7150.     
  7151.     
  7152.     EXAMPLES:
  7153.     
  7154.         vgotoxy(0, 0);
  7155.         vprintf("Screen %u", screen);
  7156.     VPUTC                                                             VPUTC
  7157.     
  7158.     
  7159.     
  7160.     PROTOTYPE:
  7161.     
  7162.         vputc(char chr)
  7163.     
  7164.     
  7165.     ARGUMENTS:
  7166.     
  7167.         chr     - Character to display
  7168.     
  7169.     
  7170.     RETURN VALUE:
  7171.     
  7172.         None
  7173.     
  7174.     
  7175.     DESCRIPTION:
  7176.     
  7177.              This function displays a character on the video screen  at  the
  7178.           current cursor position.
  7179.     
  7180.              Characters are output in "tty" fashion, with proper handling of
  7181.           control codes such as CARRIAGE-RETURN,  LINE-FEED  and  BELL.  The
  7182.           screen will scroll upwards when a NEWLINE is printed on the bottom
  7183.           line of the screen, or when the bottom line wraps  around  to  the
  7184.           next.
  7185.     
  7186.              Although only the lower 8 bits of  a  passed  value  are  used,
  7187.           "vputc" will not perform ANY output translations  if  any  of  the
  7188.           upper 8 bits are set. This provides a  method  of  displaying  the
  7189.           video characters represented by control codes such as NEWLINE, and
  7190.           BACKSPACE.
  7191.     
  7192.              The external "char" variable "V_ATTR" may be used  to  set  the
  7193.           video attribute used by "VPUTC" to  display  the  character.  This
  7194.           value is written to the attribute  location  associated  with  the
  7195.           character on the video display hardware. Its effect  is  dependant
  7196.           on the video adapter in use. The "video.h"  header  file  contains
  7197.           definitions of the attribute bits for use on "standard" monochrome
  7198.           and color displays.
  7199.     
  7200.     
  7201.              "VOPEN" MUST be called prior to using this function.
  7202.     
  7203.     
  7204.     EXAMPLES:
  7205.     
  7206.         vputc(0x0A);            /* Line-feed, advance cursor */
  7207.         vputc(0x0A | 0xff00);   /* Display 0x0A character code */
  7208.     VPUTF                                                             VPUTF
  7209.     
  7210.     
  7211.     
  7212.     PROTOTYPE:
  7213.     
  7214.         vputf(char *string, int width)
  7215.     
  7216.     
  7217.     ARGUMENTS:
  7218.     
  7219.         string  - Pointer to character string
  7220.         width   - Width of output field
  7221.     
  7222.     
  7223.     RETURN VALUE:
  7224.     
  7225.         None
  7226.     
  7227.     
  7228.     DESCRIPTION:
  7229.     
  7230.              The "vputf" function outputs a character string to  the  IBM-PC
  7231.           video screen using the video library functions.
  7232.     
  7233.              The string is left justified in a field of the specified width.
  7234.           If the string is shorter than "width", the field  is  padded  with
  7235.           blanks. If the string  is  longer  than  "width",  the  output  is
  7236.           truncated.
  7237.     
  7238.              "VOPEN" MUST be called prior to using this function.
  7239.     
  7240.     
  7241.     EXAMPLES:
  7242.     
  7243.         vputf(message, 10); 
  7244.     VPUTS                                                             VPUTS
  7245.     
  7246.     
  7247.     
  7248.     PROTOTYPE:
  7249.     
  7250.         vputs(char *string)
  7251.     
  7252.     
  7253.     ARGUMENTS:
  7254.     
  7255.         string  - Pointer to character string
  7256.     
  7257.     
  7258.     RETURN VALUE:
  7259.     
  7260.         None
  7261.     
  7262.     
  7263.     DESCRIPTION:
  7264.     
  7265.              The "vputs" function outputs a character string to  the  IBM-PC
  7266.           video screen using the video library functions.
  7267.     
  7268.              "VOPEN" MUST be called prior to using this function.
  7269.     
  7270.     
  7271.     EXAMPLES:
  7272.     
  7273.         vputs(message);
  7274.     VTSTC                                                             VTSTC
  7275.     
  7276.     
  7277.     
  7278.     PROTOTYPE:
  7279.     
  7280.         int vtstc()
  7281.     
  7282.     
  7283.     ARGUMENTS:
  7284.     
  7285.         None
  7286.     
  7287.     
  7288.     RETURN VALUE:
  7289.     
  7290.         0       - No key pressed
  7291.         1-127   - ASCII value of key pressed
  7292.         < 0     - Special function key as defined in "video.h"
  7293.     
  7294.     
  7295.     DESCRIPTION:
  7296.     
  7297.              The "vtstc" function tests for a  key  pressed  on  the  system
  7298.           console, and returns its value.  A  returned  value  of  zero  (0)
  7299.           indicates that no key was found to be pressed.
  7300.     
  7301.              Note that due to the buffering of the  IBM-PC  keyboard,  every
  7302.           keypress will be reported, even if the VTSTC  function  is  called
  7303.           after a key is pressed and released.
  7304.     
  7305.     
  7306.     EXAMPLES:
  7307.     
  7308.         if(vtstc() == 0x1B) /* exit loop on ESCAPE key */
  7309.             break;
  7310.     VUPDATEXY                                                     VUPDATEXY
  7311.     
  7312.     
  7313.     
  7314.     PROTOTYPE:
  7315.     
  7316.         vupdatexy()
  7317.     
  7318.     
  7319.     ARGUMENTS:
  7320.     
  7321.         None
  7322.     
  7323.     
  7324.     RETURN VALUE:
  7325.     
  7326.         None
  7327.     
  7328.     
  7329.     DESCRIPTION:
  7330.     
  7331.              This function updates the real X/Y cursor position on the video
  7332.           screen to reflect the "logical" position where the next  character
  7333.           will be output.
  7334.     
  7335.              The MICRO-C video library uses a BIOS  interrupt  (INT  10)  to
  7336.           position the cursor, which is quite slow, compared to the speed of
  7337.           the library video routines. To prevent this from slowing down  the
  7338.           video output, the cursor is only physically re-positioned  when  a
  7339.           "vgotoxy" or a "vgetc" is executed.
  7340.     
  7341.              This allows the library routines to  run  at  full  speed,  and
  7342.           still put the cursor in the right place when output stops  and  an
  7343.           input request is made.
  7344.     
  7345.              A side effect of this is that the cursor on the screen will not
  7346.           appear to move unless you call "vgotoxy"  or  "vgetc".  This  only
  7347.           affects the physical cursor on the screen, MICRO-C  maintains  its
  7348.           own internal cursor location which it uses to determine  where  on
  7349.           the screen the next write will occur.
  7350.     
  7351.              Some applications which run in real time (Such  as  a  terminal
  7352.           emulator) do not  call  "vgetc",  but  use  "vtstc"  to  poll  the
  7353.           keyboard on a regular basis. In this case, the "vupdatexy" routine
  7354.           should be called any time that the visual position of  the  cursor
  7355.           is important.
  7356.     
  7357.              "VOPEN" MUST be called prior to using this function.
  7358.     
  7359.     
  7360.     EXAMPLES:
  7361.     
  7362.         vupdatexy();        /* position the cursor *
  7363.         c = vtstc();        /* Test for a character */
  7364.  
  7365.  
  7366.  
  7367.                                     MICRO-C
  7368.  
  7369.                                TABLE OF CONTENTS
  7370.  
  7371.  
  7372.                                                                          Page
  7373.  
  7374.      1. INTRODUCTION                                                        1
  7375.  
  7376.         1.1 Code Portability                                                2
  7377.         1.2 Compiler Portability                                            2
  7378.         1.3 The MCC command                                                 3
  7379.  
  7380.      2. THE MICRO-C PROGRAMMING LANGUAGE                                    4
  7381.  
  7382.         2.1 Constants                                                       4
  7383.         2.2 Symbols                                                         4
  7384.         2.3 Arrays & Pointers                                               7
  7385.         2.4 Functions                                                       7
  7386.         2.5 Control Statements                                              8
  7387.         2.6 Expression Operators                                           10
  7388.         2.7 Preprocessor Commands                                          12
  7389.         2.8 Error Messages                                                 13
  7390.         2.9 Quirks                                                         17
  7391.  
  7392.      3. ADVANCED TOPICS                                                    20
  7393.  
  7394.         3.1 Conversion Rules                                               20
  7395.         3.2 Assembly Language Interface                                    21
  7396.         3.3 Compiling for ROM                                              24
  7397.  
  7398.      4. PORTING THE COMPILER                                               25
  7399.  
  7400.         4.1 The "io" module                                                26
  7401.         4.2 The "code" module                                              28
  7402.         4.3 The "compile" module                                           33
  7403.         4.4 Porting without a compiler                                     34
  7404.         4.5 Porting without a linker                                       34
  7405.         4.6 Optimization Techniques                                        35
  7406.  
  7407.      5. THE MICRO-C PREPROCESSOR                                           38
  7408.  
  7409.         5.1 The MCP command                                                39
  7410.         5.2 Preprocesor Commands                                           40
  7411.         5.3 Error messages                                                 43
  7412.  
  7413.      6. THE MICRO-C OPTIMIZER                                              45
  7414.  
  7415.         6.1 The MCO command                                                45
  7416.         6.2 Porting to a new processor                                     46
  7417.  
  7418.      7. THE COMMAND CO-ORDINATOR                                           47
  7419.  
  7420.         7.1 The CC command                                                 47
  7421.     MICRO-C                                                Table of Contents
  7422.  
  7423.                                                                          Page
  7424.         7.2 Using multiple object modules                                  48
  7425.  
  7426.      8. THE MAKE UTILITY                                                   49
  7427.  
  7428.         8.1 MAKEfiles                                                      49
  7429.         8.2 Directives                                                     52
  7430.         8.3 The MAKE command                                               53
  7431.         8.4 The TOUCH command                                              54
  7432.  
  7433.      9. THE SOURCE LINKER                                                  55
  7434.  
  7435.         9.1 The SLINK Command                                              55
  7436.         9.2 The External Index File                                        56
  7437.         9.3 Multiple source files                                          57
  7438.         9.4 Source file information                                        57
  7439.         9.5 The SINDEX utility                                             59
  7440.  
  7441.      10. LIBRARY FUNCTIONS                                                 60
  7442.  
  7443.         10.1 Standard Library Functions                                    60
  7444.         10.2 IBM-PC/MS-DOS Library Functions                               61
  7445.