Binary Data Sort (BSort) for Windows 95/NT

PURPOSE:
The "Binary Sort Utility (BSort)" offers:
- sorting capabilities for text and binary files containing
  fixed length records
- unlimited file sizes
- sorting by several columns each ascending or descending
- up to 1000 columns per table/record
- 13 different basic data types:
	Signed integers		(1,2,3 or 4 bytes)
	Unsigned integers	(1,2,3 or 4 bytes)
	Floating point		(4 or 8 bytes)
	Text sort			(case sensitive/insensitive)
	Binary sort		(based on byte values)
- up to 100 different customizable data types
	dynamically loaded via BSort.DLL
- easy record structure definition via configuration files
- even viewing capability of binary files
- sorted output can be a separate file or replacing the input file
  (in place sort!)

INSTALLATION:
c:
cd \temp
pkunzip \download\BSort.zip       (or where you stored the download file)
SETUP.exe
edit c:\autoexec.bat                 (Add PATH=...;C:\BSORT)
CbMgmt                               To view demo time left and install

PROGRAM STATUS:
BSort is a shareware program with a 30day trial period.

DISTRIBUTION:
BSort in demo mode may be freely distributed without limitations.

CONTACT:
For questions and inquiries contact us at:
To contact "Professional Software Solutions":

Write to:
"Professional Software Solutions"
c/o BSORT
1626 N. Wilcox Suite #252
Los Angeles, California 90028
U.S.A.

or e-mail to:
bsort@pobox.com

visit out WWW site at:
http://www.ProfSoftware.com


BSort Command Line syntax
=========================
usage: bsort -i{input} [-o{output}] [-c{cfg}] [-v]
input   = data input file
output  = data output file (can be same as input)
cfg     = sort configuration file (defining the record structure):
          NAME={n} TYPE={t}  [LEN=l[.p]] [# comment]
          Available types {t}
          INT1/2/3/4     = signed integer of 1-4 bytes length
          UINT1/2/3/4    = unsigned integer of 1-4 bytes length
          FLT4/8         = floating point 4/8 bytes length
          STR{b}         = text string of <b> bytes length
          USTR{b}        = case insensitive text string of <b> bytes length
          BYTES{b}       = binary bytes string of <b> bytes length
          (If no cfg specified BSORT will use BSort.cfg in the home directory)
-v      = View data only based on the current CFG file (-o is ignored)

The input filename is the only required command line argument.
All other options are optional.

BSort Configuration File (xxx.cfg)
==================================
In order to sort Bsort needs the information about the record structure to sort on.
This information in contained in the "BSORT Configuration file (xxx.cfg)".
You can have many different configuration for the same data file.
You can either specify the configuration to be used on the command line or 
let BSORT use the default configuration "Bsort.cfg" in the same directory were BSORT is.
The CFG file is also used to communicate the details when BSORT is used to view the data.

Column Definition
Each column is defined in one line:
[NAME={name}]  TYPE={t}   [LEN={w[.p]] # comment

NAME
The NAME attribute is optional, but can be helpful for your orientation

TYPE
The TYPE attribute defines the data type of the column.
Currently the following basic types are available:
INT1		= Signed integer of one byte length (char)
INT2		= Signed integer of two bytes length (short)
INT3		= Signed integer of three bytes length (---)
INT4		= Signed integer of four bytes length (long)

UINT1		= Unsigned integer of one byte length (BYTE/unsigned char)
UINT2		= Unsigned integer of two bytes length (WORD/unsigned short)
UINT3		= Unsigned integer of three bytes length (---)
UINT4		= Unsigned integer of four bytes length (DWORD/unsigned long)

FLT4		= floating point 4 bytes length (float)
FLT8		= floating point 8 bytes length (double)

STR{n}	= text string of <n> bytes length (char [n])
USTR{n}	= case insensitive text string of <n> bytes length (char [n])

BYTES{n}	= binary bytes string of <n> bytes length (BYTE [n])

LEN=w[.p]
The LEN attribute defines the display width `w' of numeric columns.
If LEN is not specified BSORT will use only the width needed.
The floating point data type also uses the precision `p' if specified.

COMMENT
Any text after the `#' comment sign is ignored

Example CFG file:
# Example5: Sort based on the following two columns
#           1. ascending  column5 and
#           2. descending column4
NAME=col1  TYPE=USTR6                       # Text Key
NAME=col2  TYPE=UINT2  LEN=3                # unsigned 2 byte short
NAME=col3  TYPE=UINT4  LEN=6                # unsigned 4 byte long
NAME=col4  TYPE=INT4   LEN=8    SORT2=DESC  # signed 4 byte long
NAME=col5  TYPE=INT2   LEN=6    SORT1=ASC   # signed 2 byte short
NAME=col6  TYPE=FLT4   LEN=10.2             # floating point 4 byte
NAME=col7  TYPE=FLT8   LEN=20.4             # floating point 8 byte

BSort Custom Data Type Interface (BSort.DLL)
============================================
In many cases your data will contain custom data which cannot be sorted by the
13 basic data types already provided with BSORT.

For these cases we provided a custom interface were you can define any of these special sorts.

You can define and use up to 100 different custom data types per sort run.
The custom sort function is embedded in the BSort.DLL library.
You can easily create many different versions of BSort.DLL and get an unlimited
potential of custom sorts.

The following files are part of the BSort.DLL package:
CustSort.c		C Source file interface file
BSort.DLL		Release version of the custom sort interface DLL
BSort.lib		Release version of the custom sort interface library
BSortD.DLL		Debug version of the custom sort interface DLL
BSort.D.lib	 	Debug version of the custom sort interface library
BSortDLL.mak	Microsoft Visual C/C++ makefile (32 bit)
makeDLL.bat		Batch file to recreate BSort.DLL after changes to CustSort.c

Below is the initial version of "CustSort.c" as a starting point for you to customize.
We implemented as an example a sort using the absolute numeric value of signed
integers if 1/2 or 4 bytes length. Since the column length is supllied as an argument
you can use the same custom data type for all 3 different length:

#define _MAX_PATH 256

extern char szFnIn[_MAX_PATH+1];        /* sort input filename */
extern char szFnOut[_MAX_PATH+1];       /* sort output file */
extern char szFnCfg[_MAX_PATH+1];       /* sort configuration file */
extern char szHome[_MAX_PATH+1];        /* Home directory */

/*****************************************************************************/
/* CUSTOM SORT ENTRY POINT FOR BSORT                                         */
/* Input:                                                                    */
/* cTyle     = Custom sort type (1 ... 100) defined in *.cfg CUST{l}/cType   */
/* nBy       = length of this column in bytes                                */
/* el1       = pointer to element1 in the sort array                         */
/* el2       = pointer to element2 in the sort array                         */
/*                                                                           */
/* Output:                                                                   */
/* 0         = both elements are equal                                       */
/* 1         = element1 is smaller than element2                             */
/* -1        = element1 is greater than element2                             */
/*****************************************************************************/
int CustSort(int cType,int nBy,unsigned char *el1,unsigned char *el2)
{
long nVal1, nVal2;

    switch (cType)
    {
    /****** EXAMPLE OF A CUSTOM SORT (TYPE 1) ********************************/
    /****** IGNORE SIGN: SORT BY ABSOLUTE VALUE ******************************/
    case 1:
        /****** GET THE SIGNED VALUE *****************************************/
        switch (nBy)
        {
        case 1: nVal1 = *(char *)el1; nVal2 = *(char *)el2; break;
        case 2: nVal1 = *(short*)el1; nVal2 = *(short*)el2; break;
        case 4: nVal1 = *(long *)el1; nVal2 = *(long *)el2; break;
        default:
            return(0);
        }

        /****** MAKE UNSIGNED ************************************************/
        if (nVal1 < 0)
            nVal1 = -nVal1;
        if (nVal2 < 0)
            nVal2 = -nVal2;

        /****** CHECK FOR EQUAL **********************************************/
        if (nVal1 == nVal2)
            return(0);

        /****** COPMARE NOT EQUAL ********************************************/
        return((nVal2 > nVal1) ? -1 : 1);

        break;

    /****** DEFAULT SORT JUST BY BYTE VALUES *********************************/
    default:
        while(*el1 == *el2++)
            {
            *el1++;
            if (--nBy <= 0)
                return(0);                  /* equal */
            }
        return((*(--el2) > *el1) ? -1 : 1); /* not equal */
        break;
    }
}




DISCLAIMER - AGREEMENT
Users of BSORT must accept this disclaimer of warranty:
BSORT is supplied as is.  The author disclaims all
warranties, expressed or implied, including, without limitation,
the warranties of merchantability and of fitness for any purpose.
The author assumes no liability for damages, direct or consequential,
which may result from the use of BSORT."

BSORT is a "shareware program" and is provided at no charge
to the user for evaluation.  Feel free to share it with your
friends, but please do not give it away altered or as part of
another system.  The essence of "user-supported" software is to
provide personal computer users with quality software without
high prices, and yet to provide incentive for programmers to
continue to develop new products.  If you find this program
useful and find that you are using BSORT and continue to use
BSORT after a reasonable trial period, you must make a registration
payment of $54.50(WIndwos95/NT) or $49.50(Windows3.11/MSDOS)
to "Professional Software Solutions".

The registration fee will license one copy for use on any one
computer at any one time.  You must treat this software just like
a book.  An example is that this software may be used by any
number of people and may be freely moved from one computer
location to another, so long as there is no possibility of it
being used at one location while it's being used at another.
Just as a book cannot be read by two different persons at the
same time.

Commercial users of BSORT must register and pay for their
copies of BSORT within 30 days of first use or their license
is withdrawn.  Site-License arrangements may be made by con-
tacting "Professional Software Solutions".

Anyone distributing BSORT for any kind of remuneration must
first contact "Professional Software Solutions" at the address
below for authorization.
This authorization will be automatically granted to distributors
recognized by the (ASP) as adhering to its guidelines for
shareware distributors, and such distributors may begin offering
BSORT immediately
(However "Professional Software Solutions" must still be advised so
that the distributor can be kept up-to-date with the latest
version of BSORT.).

You are encouraged to pass a copy of BSORT along to your
friends for evaluation.  Please encourage them to register their
copy if they find that they can use it.  All registered users
will receive a copy of the latest version of the BSORT
system.

DEFINITION OF SHAREWARE

Shareware distribution gives users a chance to try software
before buying it. If you try a Shareware program and continue
using it, you are expected to register. Individual programs
differ on details -- some request registration while others
require it, some specify a maximum trial period. With
registration, you get anything from the simple right to continue
using the software to an updated program with printed manual.

Copyright laws apply to both Shareware and commercial software,
and the copyright holder retains all rights, with a few specific
exceptions as stated below. Shareware authors are accomplished
programmers, just like commercial authors, and the programs are
of comparable quality. (In both cases, there are good programs
and bad ones!) The main difference is in the method of
distribution. The author specifically grants the right to copy
and distribute the software, either to all and sundry or to a
specific group. For example, some authors require written
permission before a commercial disk vendor may copy their
Shareware.

Shareware is a distribution method, not a type of software. You
should find software that suits your needs and pocketbook,
whether it's commercial or Shareware. The Shareware system makes
fitting your needs easier, because you can try before you buy.
And because the overhead is low, prices are low also. Shareware
has the ultimate money-back guarantee -- if you don't use the
product, you don't pay for it.

To contact "Professional Software Solutions":

Write to:
"Professional Software Solutions"
c/o BSORT
1626 N. Wilcox Suite #252
Los Angeles, California 90028
U.S.A.

or e-mail to:
bsort@pobox.com

visit out WWW site at:
http://www.ProfSoftware.com

/pub/simtelnet/win95/util:
bsort_11.zip Binary Data Sort with custom sort interface          
