home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / STRLINK.ZIP / STRLINK.DOC < prev    next >
Encoding:
Text File  |  1989-08-28  |  15.0 KB  |  356 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                     STRLINK OBJECT
  7.                                      Version 1.00
  8.                                     28 August 1989
  9.  
  10.                                    Rob Rosenberger
  11.                                   Barn Owl Software
  12.                                      P.O. Box 74
  13.                                  O'Fallon, IL  66269
  14.                                     (618) 632-7345
  15.  
  16.  
  17.                This Turbo Pascal v5.5 OOP object implements a linked list
  18.           of strings.  You no longer have to read a text file more than one
  19.           time: you can now let an OOP variable of StrLinkList type read it
  20.           into memory.  You can sort text files based on varying criteria,
  21.           remove redundant strings, etc.
  22.  
  23.                This link list of strings offers an extra added bonus.  Each
  24.           string on the list takes up only as much space as it absolutely
  25.           requires.  This is true even if you change the size of the string
  26.           after putting it on the list.  (You can always inspect the code
  27.           if you want to see how it was accomplished.)
  28.  
  29.                And because it's OOP, you can create a descendent object if
  30.           you have special needs.  If any of the code is ever updated, you
  31.           can simply upgrade to the version ── you'll never have to change
  32.           a line of your descendent code.
  33.  
  34.  
  35.           UNIT NAME
  36.  
  37.  
  38.                The name of the main unit is "StrLink".  You should put this
  39.           in any program or unit of your own that needs access to variables
  40.           of type StrLinkList.
  41.  
  42.  
  43.           CONDITIONAL DIRECTIVES
  44.  
  45.  
  46.                {$IFDEF TPRO5}
  47.  
  48.                The StrLink and StrObj units can optionally use TurboPower
  49.           Software's TPRO5 toolkit.  TPRO5 offers some extra efficiency &
  50.           speed for string link lists.  If you do NOT have TPRO5, you must
  51.           change the '$' to a '.' so the proper code will compile.
  52.                I encourage you to write or call TurboPower for a brochure
  53.           about their products.  I actually pity you if you aren't using
  54.           their toolkits.  TPRO5 contains 50,000+ lines of source code in
  55.           over 30 units, and TurboPower is coming out soon with OPRO, the
  56.           Object Professional Toolkit.  You can contact TurboPower at P.O.
  57.           Box 66747, Scotts Valley, CA 95066, or call (408) 438-8608.  Be
  58.           sure to tell them I said hi.
  59.  
  60.           STRLINK OBJECT                                        Page 2 of 7
  61.  
  62.  
  63.  
  64.           USES
  65.  
  66.  
  67.                The StrLink unit USES the following units:
  68.  
  69.                     {$IFDEF TPRO5}
  70.                         TpString,
  71.                     {$ENDIF}
  72.                     Objects,
  73.                     ObjectA,
  74.                     StrObj;
  75.  
  76.                The TpString unit is supplied with the TurboPower Software
  77.           TPRO5 toolkit.  Please see the section on conditional compilation
  78.           directives for more information about this powerful toolkit.
  79.                The Objects unit is on Turbo Pascal v5.5 disk #3.  It imple-
  80.           ments the foundation of a singly linked list object.
  81.                The ObjectA unit is included in this file IF this was pulled
  82.           down from a BBS.  If it was pulled down from CompuServe, then you
  83.           must also download OBJA.ARC from BPROGA forum LIBrary 1.  ObjectA
  84.           builds on the Objects unit by offering a more powerful descendent
  85.           object for singly linked lists.
  86.                The StrObj unit is included with StrLink.  It implements the
  87.           foundation for a string object.
  88.  
  89.  
  90.           TYPES
  91.  
  92.  
  93.           SortedOrderType = (ForwardOrder,
  94.                              ReverseOrder,
  95.                              AscendingOrder,
  96.                              DescendingOrder);
  97.  
  98.           StrLinkList
  99.            = OBJECT(LinkList)
  100.              CurrentStrPtr     : StrObjectPtr;
  101.              UniqueStringsOnly : BOOLEAN;
  102.              SortedOrder       : SortedOrderType;
  103.              CaseMatters       : BOOLEAN;
  104.  
  105.              CONSTRUCTOR Init(UniqueStrings : BOOLEAN;
  106.                               SortSpecifier : SortedOrderType;
  107.                               IgnoreCase    : BOOLEAN);
  108.  
  109.              FUNCTION  GetSpecificString(NodePos : LONGINT) : STRING;
  110.              PROCEDURE DeleteSpecificString(NodePos : LONGINT);
  111.  
  112.              FUNCTION  ReadStrings(TheFilename : STRING) : BYTE;
  113.              FUNCTION  WriteStrings(TheFilename : STRING;
  114.                                     AppendFile  : BOOLEAN) : BYTE;
  115.  
  116.              PROCEDURE AddString(TheStr : STRING);
  117.              PROCEDURE DeleteString(TheStr : STRING);
  118.  
  119.           STRLINK OBJECT                                        Page 3 of 7
  120.  
  121.  
  122.  
  123.              FUNCTION  Exists(TheStr : STRING) : BOOLEAN;
  124.              FUNCTION  ExistsSubstring(TheSubStr : STRING) : BOOLEAN;
  125.              PROCEDURE DeleteStringsWithoutSubstring(TheSubStr  : STRING;
  126.                                                      IgnoreCase : BOOLEAN);
  127.              PROCEDURE DeleteStringsWithSubstring(TheSubStr  : STRING;
  128.                                                   IgnoreCase : BOOLEAN);
  129.              PROCEDURE DeleteDuplicates;
  130.              PROCEDURE DeleteLeadNullStrings;
  131.              PROCEDURE DeleteNullStrings;
  132.              PROCEDURE DeleteTrailNullStrings;
  133.  
  134.              PROCEDURE InitCurrent;
  135.              FUNCTION  CurrentString : STRING;
  136.              PROCEDURE ChangeCurrentString(NewStr : STRING);
  137.              FUNCTION  FirstString : STRING;
  138.              FUNCTION  LastString : STRING;
  139.              PROCEDURE Advance;
  140.              PROCEDURE Retreat;
  141.              FUNCTION  MoreStrings : BOOLEAN;
  142.              FUNCTION  NoMoreStrings : BOOLEAN
  143.              END;
  144.  
  145.  
  146.           PROCEDURES & FUNCTIONS
  147.  
  148.  
  149.           CONSTRUCTOR Init(UniqueStrings : BOOLEAN;
  150.                            SortSpecifier : SortedOrderType;
  151.                            IgnoreCase    : BOOLEAN);
  152.  
  153.                Initializes the StrLinkList instantiation.  UniqueStrings
  154.           dictates if the list should ignore duplicate strings.  IgnoreCase
  155.           dictates if the strings should be viewed as all uppercase, even
  156.           though they will be stored as upper/lowercase.
  157.                SortSpecifier dictates how the list is sorted.  ForwardOrder
  158.           means strings will be added to the END of the list.  This is the
  159.           same as reading a regular text file.  ReverseOrder means strings
  160.           will be added to the BEGINNING of the list.  This would be like
  161.           reading a text file backwards.  AscendingOrder dictates that the
  162.           list will be sorted in ascending order.  DescendingOrder dictates
  163.           that the list will be sorted in descending order.
  164.                The IgnoreCase boolean is important if you choose to sort
  165.           the list in ascending/descending order.  If IgnoreCase is FALSE,
  166.           "BBBB" will come before "aaaa".  When IgnoreCase is TRUE, all
  167.           strings are viewed as uppercase.  But don't worry, they're stored
  168.           exactly as they are.  IgnoreCase is important only during string
  169.           comparisons.
  170.  
  171.           STRLINK OBJECT                                        Page 4 of 7
  172.  
  173.  
  174.  
  175.           DESTRUCTOR  Done;
  176.  
  177.                This destructor is INHERITED from an ancestral object.  It
  178.           completely removes all strings from the list and frees up their
  179.           associated memory.  You must call this destructor/procedure when
  180.           you're finished with the list.  (You can "flush" the list for a
  181.           new purpose by calling Done, then calling Init once more.)
  182.  
  183.           FUNCTION  GetSpecificString(NodePos : LONGINT) : STRING;
  184.  
  185.              This function returns a string from the StrLinkList based on
  186.           the position of a particular string in the list.  This is useful
  187.           for people who use TurboPower Software's TPRO5 TpPick unit, for
  188.           example.  The position is represented by NodePos.  This function
  189.           returns a null string if NodePos is <= 0 or if it is > the last
  190.           node on the list.  The CurrentString function will return this
  191.           string after you use this function.
  192.  
  193.           PROCEDURE DeleteSpecificString(NodePos : LONGINT);
  194.  
  195.              This procedure deletes a string from the StrLinkList based on
  196.           the position of the string in the list, represented by NodePos.
  197.           It does nothing if NodePos is <= 0 or if it is > the last string
  198.           position on the list.  The CurrentString function points to NO
  199.           string after this call.
  200.  
  201.           FUNCTION  ReadStrings(TheFilename : STRING) : BYTE;
  202.  
  203.              Reads strings from TheFilename and adds them to the list.  The
  204.           IORESULT value is returned as the result of this function.
  205.  
  206.           FUNCTION  WriteStrings(TheFilename : STRING;
  207.                                  AppendFile  : BOOLEAN) : BYTE;
  208.  
  209.              Writes all strings on the list to TheFilename.  The IORESULT
  210.           value is returned as the result of this function.  AppendFile
  211.           dictates if the strings should be appended to the end of a file
  212.           if it already exists.  NOTE: the file must exist if AppendFile is
  213.           set to TRUE.
  214.  
  215.           PROCEDURE AddString(TheStr : STRING);
  216.  
  217.              Adds a string to the list.  It does nothing if the string is
  218.           redundant AND UniqueStrings was TRUE when you called Init.  The
  219.           CurrentString function is undefined after calling this routine.
  220.           (It may, or may not, point to the newly added string.)
  221.  
  222.           PROCEDURE DeleteString(TheStr : STRING);
  223.  
  224.              This procedure deletes the given string from the list.  It
  225.           does nothing if the string doesn't exist.  The CurrentString
  226.           function points to NO string after this call.
  227.  
  228.           STRLINK OBJECT                                        Page 5 of 7
  229.  
  230.  
  231.  
  232.           FUNCTION  Exists(TheStr : STRING) : BOOLEAN;
  233.  
  234.              Determines if the given string is on the list.
  235.  
  236.           FUNCTION  ExistsSubstring(TheSubStr : STRING) : BOOLEAN;
  237.  
  238.              Similar to the Exists function, this routine determines if a
  239.           given substring is on the StrLinkList.  It searches every string
  240.           on the list until it either finds the substring inside one of the
  241.           strings, or it runs out of strings to search.  This function is
  242.           TRUE if TheSubStr is a null string and at least one string exists
  243.           on the list.
  244.                If the result is TRUE, CurrentString will return the first
  245.           string on the list containing the given substring.
  246.  
  247.           PROCEDURE DeleteStringsWithoutSubstring(TheSubStr  : STRING;
  248.                                                   IgnoreCase : BOOLEAN);
  249.  
  250.              This procedure deletes any string from the list that doesn't
  251.           contain the given substring.  No strings will be deleted if the
  252.           substring is a null string.  The IgnoreCase variable dictates
  253.           whether upper/lower case is relevant during the search.  (This
  254.           overrides the string comparison check you specified when you
  255.           called Init.)
  256.  
  257.           PROCEDURE DeleteStringsWithSubstring(TheSubStr  : STRING;
  258.                                                IgnoreCase : BOOLEAN);
  259.  
  260.              This procedure deletes any string from the list that DOES
  261.           contain the given substring.  No strings will be deleted if the
  262.           substring is a null string.  The IgnoreCase variable dictates
  263.           whether upper/lower case is relevant during the search.  (This
  264.           overrides the string comparison check you specified when you
  265.           called Init.)
  266.  
  267.           PROCEDURE DeleteDuplicates;
  268.  
  269.                This procedure deletes duplicate strings from the list.  It
  270.           does nothing if you specified unique strings during the call to
  271.           the Init procedure.
  272.  
  273.           PROCEDURE DeleteLeadNullStrings;
  274.  
  275.                This procedure deletes leading null strings from the list.
  276.           It's an easy way to strip out any leading blank lines from a text
  277.           file.  Null strings that exist past the first non-null string in
  278.           the list are left alone.
  279.  
  280.           PROCEDURE DeleteNullStrings;
  281.  
  282.                This procedure deletes all null strings from the list.  It's
  283.           an easy way to delete all the blank lines from a text file you
  284.           just read from disk.
  285.  
  286.           STRLINK OBJECT                                        Page 6 of 7
  287.  
  288.  
  289.  
  290.           PROCEDURE DeleteTrailNullStrings;
  291.  
  292.                This procedure deletes trailing null strings from the list.
  293.           It's an easy way to delete blank lines from the end of a text
  294.           file you just read from disk.
  295.  
  296.           PROCEDURE InitCurrent;
  297.  
  298.                This function initializes the CurrentString so it returns
  299.           the first first string on the list (assuming there is at least
  300.           one string on the list).
  301.  
  302.           FUNCTION  CurrentString : STRING;
  303.  
  304.                This function returns the current string pointed to in the
  305.           list.  You must use the InitCurrent procedure to set the current
  306.           string to the first string in the list.  CurrentString returns a
  307.           null string if it points to no string.  (Use the MoreStrings and
  308.           NoMoreStrings functions to determine if CurrentString points to a
  309.           string.)
  310.  
  311.           PROCEDURE ChangeCurrentString(NewStr : STRING);
  312.  
  313.                Changes the current string to the new string.
  314.  
  315.           FUNCTION  FirstString : STRING;
  316.  
  317.                Returns the first String in the list.  It returns a null
  318.           string if there are no strings in the list.  The CurrentString
  319.           function will also return the first string after you call this
  320.           function.
  321.  
  322.           FUNCTION  LastString : STRING;
  323.  
  324.                Returns the last String in the list.  It returns a null
  325.           string if there are no strings in the list.  The CurrentString
  326.           function will also return the last string after you call this
  327.           function.
  328.  
  329.           PROCEDURE Advance;
  330.  
  331.                This procedure simply moves the current string pointer to
  332.           the next string in the list.  You should use the MoreStrings or
  333.           NoMoreStrings functions to see if there is another string on the
  334.           list after making this call.
  335.  
  336.           PROCEDURE Retreat;
  337.  
  338.                This procedure simply moves the current string pointer to
  339.           the previous string in the list.  You should use the MoreStrings
  340.           or NoMoreStrings functions to see if there is another string on
  341.           the list after making this call.
  342.  
  343.           STRLINK OBJECT                                        Page 7 of 7
  344.  
  345.  
  346.  
  347.           FUNCTION  MoreStrings : BOOLEAN;
  348.  
  349.                Returns TRUE or FALSE, explaining if CurrentString points to
  350.           a valid string in the list.  Should be used with the Advance and
  351.           Retreat procedures.
  352.  
  353.           FUNCTION  NoMoreStrings : BOOLEAN;
  354.  
  355.                The opposite of the MoreStrings function.  See above.
  356.