home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / nicol / sti_stak / sti_stak.txt < prev   
Encoding:
Text File  |  1990-08-22  |  13.0 KB  |  529 lines

  1.  
  2.  
  3.  
  4.         
  5.         
  6.         
  7.         
  8.         
  9.         
  10.         
  11.         
  12.         
  13.         
  14.         
  15.         
  16.                                  GENERIC STACK SYSTEM 1.0
  17.         
  18.                                For Turbo Pascal Version 5.0
  19.         
  20.         
  21.         
  22.         
  23.         
  24.         
  25.         
  26.         
  27.         
  28.         
  29.         
  30.         
  31.                                   Copyright 1990, 1991 By
  32.         
  33.                              Software Technology International
  34.         
  35.                                     All Rights Reserved
  36.         
  37.         
  38.         
  39.         
  40.         
  41.         
  42.         
  43.         
  44.         
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.                                             -1-
  67.                                           NOTICE
  68.                                           ------
  69.                   
  70.         
  71.         
  72.                      All parts of this manual and the accompanying  soft-
  73.                   ware  are  copyrighted material. You, as  a  registered 
  74.                   user, are granted permission to make as many copies  of 
  75.                   the  software, or manual, as you wish, as long as  they 
  76.                   are for your personal use. You may not copy this  soft-
  77.                   ware,  or  manual,  in any form  whatsoever  for  usage 
  78.                   outside of your personal use. This includes, but is not 
  79.                   limited  to, duplication of the disk, the files on  the 
  80.                   disk or the manual, by manual or electronic means.
  81.         
  82.         
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.                                             -2-
  133.                                      TABLE OF CONTENTS
  134.                                      -----------------
  135.         
  136.                   
  137.                    Subject                                     Page
  138.                    -----------------------------------------------------
  139.         
  140.                    GENERAL DESCRIPTION ......................   4  
  141.                      Introduction ...........................   4  
  142.                      The software ...........................   4  
  143.                                                              
  144.                    THE SOFTWARE IN DETAIL ...................   4  
  145.                      Functions and Procedures ...............   4  
  146.                      Usage Pointers .........................   7  
  147.                                                              
  148.                    INDEX ....................................   8  
  149.         
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.                                             -3-
  199.                                 GENERAL DESCRIPTION
  200.                                     -------------------
  201.                   Introduction
  202.                   ------------
  203.                   
  204.                      Welcome to Version 1.0 of Software Technology Inter-
  205.                   nationals'  Generic Stack System. This group  of  func-
  206.                   tions  will  enable your Turbo Pascal  Version  5.0  to 
  207.                   create stacks containing any data, and to have multiple 
  208.                   stacks  per program. The functions were written  to  be 
  209.                   flexible,  as fast as possible, and as easy to  use  as 
  210.                   possible.  We hope they live up to  your  expectations. 
  211.                   Please  feel free to write to us anytime with  bug  re-
  212.                   ports or suggestions for future versions. If you are  a 
  213.                   registered  user, this will entitle you to a  free  up-
  214.                   grade.
  215.                      Remember  that  this  software  is  copyrighted,  so 
  216.                   please don't copy and distribute it, this is a  federal 
  217.                   offense. 
  218.         
  219.                   The Software
  220.                   ------------
  221.                   
  222.                      These are a group of 4 procedures that allow you  to 
  223.                   create new stacks, destroy stacks, push data items, and 
  224.                   pop  data items. The kind of data you may stack can  be 
  225.                   any kind of valid Turbo Pascal data item.
  226.                      The  procedures return error codes through a  single 
  227.                   variable to make error checking easy. They are  robust, 
  228.                   in that stack overflow or underflow will not crash  the 
  229.                   system (though HEAP overflow may).
  230.                      The system can stack up to (65535 /  sizeof(Pointer) 
  231.                   = 16383) items per stack, though if the data items  are 
  232.                   large, you will surely run out of memory before then.
  233.         
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.                                             -4-
  265.                                   THE SOFTWARE IN DETAIL
  266.                                   ----------------------
  267.         
  268.                   
  269.                   The Functions And Procedures
  270.                   ----------------------------
  271.         
  272.                   Constants
  273.                   ---------
  274.                   
  275.                   MAXSTACK  = 16383;
  276.         
  277.                      This  is  the maximum number of items  that  may  be 
  278.                   stacked per stack. 
  279.         
  280.                   
  281.                   STACK_ALL_OK    = 0;  
  282.                   STACK_OVERFLOW  = 1;  
  283.                   STACK_UNDERFLOW = 2;  
  284.                   STACK_NO_MEMORY = 3;  
  285.         
  286.                      These are the error codes return through  STI_Stack-
  287.                   Error. They are self explanatory. 
  288.         
  289.                   Types
  290.                   -----
  291.                   
  292.                   STI_StackRec = array[1..MAXSTACK] of pointer;
  293.                   
  294.                      This is an array type that enable easy access to the 
  295.                   stack itself.
  296.                   
  297.                   STI_StackPtr = ^STI_Stack;
  298.         
  299.                      This is a pointer to a stack record. The  procedures 
  300.                   all expect a pointer like this to operate on.
  301.                   
  302.                   STI_Stack    = record                   
  303.                                    Stack  : ^STI_StackRec;
  304.                                    Size   : word;         
  305.                                    StackP : word;         
  306.                                  end;
  307.         
  308.                      This is the actual declaration for the stack record. 
  309.                   Besides  the stack there are 2 variables. SIZE  is  the 
  310.                   size of the stack, and StackP is the stack pointer.  By 
  311.                   not actually using stack records, but rather a  pointer 
  312.                   to it, it makes it very easy to have multiple stacks.
  313.         
  314.         
  315.         
  316.         
  317.         
  318.         
  319.         
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.                                             -5-
  331.                   Variables
  332.                   ---------
  333.                   
  334.                   STI_StackError : byte;
  335.         
  336.                      This  is the variable where all the error codes  are 
  337.                   passed. Having a single error variable makes it easy to 
  338.                   check for errors.
  339.         
  340.         
  341.                   Procedures
  342.                   ----------
  343.                   
  344.                   procedure STI_Create_Stack(Var NewStack : STI_StackPtr; 
  345.                                                      Size : word);
  346.         
  347.                      This procedure creates a new stack from the  pointer 
  348.                   NEWSTACK. The SIZE parameter determines the actual size 
  349.                   of the stack. After creation the stack will occupy only 
  350.                   (Size x 4) + 4 bytes.
  351.                   
  352.                   procedure STI_Destroy_Stack(
  353.                                             Var OldStack : STI_StackPtr);
  354.                   
  355.                      This  procedure is the opposite of  STI_Create_Stack 
  356.                   in  that it destroys the stack. It will use the  previ-
  357.                   ously  assigned to the stack to free the  memory  used. 
  358.                   There is one point that needs to be watched for; if all 
  359.                   elements have not been popped, then the memory used  by 
  360.                   those will NOT be released. 
  361.         
  362.                   procedure STI_Push(Var Stack : STI_StackPtr; 
  363.                                      Var Data; 
  364.                                          Size  : word);
  365.                   
  366.                      This  procedure  pushes the DATA variable  onto  the 
  367.                   stack.  STACK must be a previously created  stack,  and 
  368.                   SIZE  must  be  the EXACT size of  the  DATA  variable, 
  369.                   otherwise  data  will be lost. If the  stack  is  over-
  370.                   flowed, the data will not be stored.
  371.                   
  372.                   procedure STI_Pop(Var Stack : STI_StackPtr; 
  373.                                     Var Data; 
  374.                                         Size  : word);
  375.         
  376.                      This procedure pops the stack into DATA. Again, SIZE 
  377.                   must  be the exact size of the DATA variable  otherwise 
  378.                   data  will  be lost AND memory will be wasted.  If  the 
  379.                   stack is underflowed, DATA will contain junk.
  380.         
  381.         
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.                                       
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.                                             -6-
  397.                                       USAGE POINTERS
  398.                                       --------------
  399.         
  400.                      Basically,  these procedures are very easy  to  use. 
  401.                   With these procedures you may also push different sized 
  402.                   DATA  variables onto the stack AS LONG AS YOU POP  THEM 
  403.                   OFF  CORRECTLY. This is because, if the  SIZE  variable 
  404.                   passed to the STI_Pop procedure is wrong, you will lose 
  405.                   memory.
  406.                   
  407.                      Another point to remember is that before  destroying 
  408.                   the stack, make sure all elements have been popped off, 
  409.                   otherwise, again, you will lose memory.
  410.         
  411.                      Other  than that, they are very simple, and  because 
  412.                   they  use a pointer, rather than a data record,  it  is 
  413.                   very easy to have multiple stacks per program.
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.                                             -7-
  463.                                            INDEX
  464.                                            -----
  465.         
  466.                     Topic                                     Page Number
  467.                   -------------------------------------------------------
  468.         
  469.                  Constants.................................      5
  470.                  Contents..................................      3
  471.                  Copying...................................      2
  472.                  Copyright.................................      2
  473.         
  474.                  Descriptions..............................      5
  475.         
  476.                  Error Codes...............................      6
  477.         
  478.                  Functions.................................      5
  479.         
  480.                  General Description.......................      4
  481.         
  482.                  Introduction..............................      4
  483.         
  484.                  Memory Usage..............................      6,7
  485.         
  486.                  Overflow..................................      4
  487.         
  488.                  Procedures................................      5,6
  489.         
  490.                  Return Codes..............................      5
  491.         
  492.                  Stack Overflow............................      6
  493.                  Stack Size................................      4,5
  494.                  STI_Create_Stack..........................      6
  495.                  STI_Destroy_Stack.........................      6
  496.                  STI_Pop...................................      6
  497.                  STI_Push..................................      6
  498.                  STI_Stack.................................      5
  499.                  STI_StackError............................      6
  500.                  STI_StackPtr..............................      5
  501.                  STI_StackRec..............................      5
  502.         
  503.                  Types.....................................      5
  504.         
  505.                  Underflow.................................      4
  506.                  Usage.....................................      7
  507.                  Users.....................................      2
  508.         
  509.                  Variables.................................      6
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.                                             -8-                                            
  529.