home *** CD-ROM | disk | FTP | other *** search
- EXTENSION SORT FOR OPDIR.TPU
- or
- THE SORT METHOD TURBOPOWER SORT OF FORGOT
-
- Copyright 1990
- by Gil Yoder [73237,3103]
- Portions Copyright 1989 by TurboPower Software
- Permission granted to copy and distribute
- if such is done without profit
-
-
- Thank you TurboPower for a great new product! Object
- Professional is great. Although at first glance the packaged
- seemed unwieldy (my wife had to get a neighbor to help her carry
- it into the house ;->), after reading about a third of the
- printed documentation I am coming to the realization that
- implementing the features of this tool box will be much easier
- than its predecessor, Turbo Professional.
-
- There are, however, just a few things one could wish for; not
- much, but a few. For example OPDIR needs at least one new sort
- procedure for directory lists. You include sorts based on name
- and extension; directory, name and extension; size, name and
- extension; and date, name and extension; but where are the
- procedures for sorting by directory, extension and name? For
- picking filenames out of large directories this extra method of
- sorting is essential.
-
- Really, I am not complaining! In fact you said, "If you need to
- write a sort procedure that isn't already covered, study the
- sort routines in OPDIR.IN1" (volume 1, page 4-246). That is
- what I did. The code that you have written is so well
- documented and easy to understand, I was able to prepare two new
- sort methods within a matter of about 30 minutes. Below are the
- changes I have made to OPDIR.IN1 and OPDIR.PAS to implement
- sorting by extension and name, and sorting by directory,
- extension and name.
-
- These four lines were added to OPDIR.PAS in the INTERFACE
- section to make the procedures accessible to the outside. Add
- them along with the other Sort procedures (search for
- "SortName").
-
- procedure SortExt(DirPtr : DirListPtr);
- {-Sort alphabetically by extension, then by name}
- procedure SortDirExt(DirPtr : DirListPtr);
- {-Sort directories first, then alphabetically by extension and name}
-
- These two procedures are added along with two local functions to
- OPDIR.IN1. If you keep the order given here, you can put them
- just about anywhere in the file, but it would be wise to search
- for the sort routines and place these routines with those.
- (Again search for "SortName.")
-
- function LessExt(var X, Y : DirRec) : Boolean;
- {-Sort ordering -- alphabetically by extension then name}
- var
- Xdrive : Boolean;
- Ydrive : Boolean;
- begin
- Xdrive := (X.Attr = diDriveAttr);
- Ydrive := (Y.Attr = diDriveAttr);
- if Xdrive = Ydrive then
- if ByteFlagIsSet(X.Attr, Directory) then
- LessExt := (X.Name < Y.Name)
- else
- LessExt := (JustExtension(X.Name)+X.Name <
- JustExtension(Y.Name)+Y.Name)
- else
- LessExt := Xdrive;
- end;
-
- procedure SortExt(DirPtr : DirListPtr);
- {-Sort alphabetically by name, then by extension}
- begin
- with DirPtr^ do begin
- diLess := LessExt;
- diQuickSort(1, pkItems);
- end;
- end;
-
- function LessDirExt(var X, Y : DirRec) : Boolean;
- {-Sort directories first, then alphabetically by extension and name}
- var
- Xdir : Boolean;
- Ydir : Boolean;
- Xdrive : Boolean;
- Ydrive : Boolean;
- begin
- Xdrive := (X.Attr = diDriveAttr);
- Ydrive := (Y.Attr = diDriveAttr);
- if Xdrive = Ydrive then begin
- Xdir := ByteFlagIsSet(X.Attr, Directory);
- Ydir := ByteFlagIsSet(Y.Attr, Directory);
- if Xdir = YDir then
- LessDirExt := LessExt(X, Y)
- else
- LessDirExt := Xdir;
- end else
- LessDirExt := Xdrive;
- end;
-
- procedure SortDirExt(DirPtr : DirListPtr);
- {-Sort directories first, then alphabetically by extension and name}
- begin
- with DirPtr^ do begin
- diLess := LessDirExt;
- diQuickSort(1, pkItems);
- end;
- end;
-
- [I can't take credit for these routines, because they are only
- slight variations of the routines already supplied with OPRO.]
-
- After adding these routines to OPDIR, I modified DESKPOP to take
- advantage of the new sort methods. Two of DESKPOP's source
- files need changing. DESKPOP.ICD must be changed on one line.
- Change line 11 from this...
-
- DirSortType = (dstName, dstDate, dstSize, dstDos);
-
- ... to this...
-
- DirSortType = (dstName, dstExt, dstDate, dstSize, dstDos);
-
- If you want to make Extension sorting the default, change line
- 57 from this...
-
- CurDirSortType : DirSortType = dstName; {sort method}
-
- ... to this...
-
- CurDirSortType : DirSortType = dstExt; {sort method}
-
- DESKMAIN.IN1 needs to be changed in a couple of places. Change
- line 353 from this...
-
- 'Name ', 'Date ', 'Size ', 'MS-DOS');
-
- ... to this...
-
- 'Name ', 'Ext ', 'Date ', 'Size ', 'MS-DOS');
-
- ... and then add this at line 568
-
- dstExt : SetSortOrder(SortDirExt);
-
- Make these few changes to the files mentioned and compile with
- TPC. You will need about 520k memory, and should specify /L to
- link to disk. Otherwise all your changes will be for nought.
-
- What else could a programmer want? Well so far this is my wish
- list:
-
- 1. A multiple choice pick list that returns choices in a linked
- list or array rather than a BitSet. BitSets are efficient
- for small lists, but the larger the pick list the less
- efficient BitSets become. I have an application requiring
- multiple choices from a list of over 12,000 items! That
- would require a structure containing over 1,500 bytes. That's
- a lot of data to reference 1 to 20 items.
- 2. A quick incremental search for large pick lists (same
- project). This will probably be easy to program, given
- objects and the excellent design of OPRO. If you can assume
- (or determine) that a list is in alphabetical order, for a normal
- incremental search there is way too much overhead in
- comparing every item with the search string. A much faster
- approach is to compare a mid point with the search string.
- If there is no match there, the list can be divided in half
- and the half that could contain the string could be searched
- in the same way. Eventually the string would be found, or
- else no other portion of the list could be divided. If the
- string is found, then each string one less than that could be
- compared with the string, until no match was found. The new
- item would be the last string found that matched the search
- string. I implemented this method with TurboPower, and
- found that I could do an incremental search in an
- alphabetical list of 12,500 words and update the bar cursor
- as fast as anyone could type.
- 3. A larger index. Six pages for three volumes of material as
- rich as you have is just a little conservative.
-
- All the same Object Professional is a great package; it's hard
- to imagine how you produced it in the short time that you did
- (documentation problems notwithstanding). Thank you, and keep
- up the good work.
-
- NOTE: Except for small changes the code listed in this article
- is taken from code found in the Object Professional package.
- The copyright (c) 1989 to the code found here belongs to TurboPower
- Software, P.O. Box 66747, Scotts Valley, CA 95066. CompuServe
- 76004,2611. The people at TurboPower have graciously granted
- permission to place this file at the disposal of their customers
- by means of CompuServe or any other avenue.
-
-
- POST SCRIPT
-
- Because of the similarity between the procedures found here and
- those found in OPDIR, before uploading this file I sent it to
- TurboPower to ask for their permission to make it available to
- others. Kim Kokkonen replied...
-
- >> Gil - nice job on your "article." I don't have any problem
- >> with your posting it on PCVENB or elsewhere. One
- >> suggestion: your new sorts for OPDIR can just as easily be
- >> implemented without changing any of our source files. I'd
- >> suggest that you just write a standalone unit that
- >> includes your new functions for sorting. The DESKPOP
- >> changes, of course, would be slightly modified.
- >>
- >> Regarding your suggestions: 1) it would be easy to
- >> post-process the OPPICK selected bitset to turn it into a
- >> linked list and then dispose of the bitset. For
- >> performance reasons, OPPICK must have indexed access to
- >> the elements of the bitset while it is processing, so a
- >> linked list is not a good choice internally. 2) the
- >> searching functions for the pick list were designed to be
- >> extensible. I think that you could write a separate unit
- >> using the same kind of methodology you did for OPDIR
- >> sorting that would provide the kind of incremental search
- >> you want. 3) I agree that the index could be expanded.
- >> Someday when we have time we'll go through and beef it up
- >> and create a text file that people can use.
-
- Comments: The suggestion to place the procedures and functions
- in a standalone unit is a good one. As far as possible it is
- best not to modify TurboPower's routines unless official changes
- are released. OpDirX.pas implements both of the preceeding
- sorts without changing OpDir. The changes detailed above for
- DESKPOP.ICD and DESKMAIN.IN1 are still necessary. In addition
- DESKMAIN.PAS needs to add OPDIRX in its "uses" statement.
-
- Enjoy.