Download Order email More Products

Binary data Sort (BSort) for Windows
BSort offers the  following features:

BSORT Command Line Options

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.

Example1
Sort ascending by column1
distinguish between upper and lower case

Col1|Col2| Col3| Col4| Col5| Col6|    Col7|
REC01 | 1|   10|    2|    2| 1.01| 10.0100|
REC02 | 2|    9|   -4|    2| 2.01|  9.0100|
REC03 | 3|    8|    6|    2| 3.01|  8.0100|
REC05 | 5|    6|   10|    3| 5.01|  6.0100|
REC07 | 7|    4|   -3|    3| 7.01|  4.0100|
REC09 | 9|    2|   -7|    1| 9.01|  2.0100|
REC10 |10|    1|    9|    1|10.01|  1.0100|
rec04 | 4|    7|   -8|    2| 4.01|  7.0100|
rec06 | 6|    5|    1|    3| 6.01|  5.0100|
rec08 | 8|    3|    5|    3| 8.01|  3.0100|

Example3

Sort ascending by column1
don't distinguish between upper and lower case

Col1|Col2| Col3| Col4| Col5| Col6|   Col7|
REC01 | 1|   10|    2|    2| 1.01|10.0100|
REC02 | 2|    9|   -4|    2| 2.01| 9.0100|
REC03 | 3|    8|    6|    2| 3.01| 8.0100|
rec04 | 4|    7|   -8|    2| 4.01| 7.0100|
REC05 | 5|    6|   10|    3| 5.01| 6.0100|
rec06 | 6|    5|    1|    3| 6.01| 5.0100|
REC07 | 7|    4|   -3|    3| 7.01| 4.0100|
rec08 | 8|    3|    5|    3| 8.01| 3.0100|
REC09 | 9|    2|   -7|    1| 9.01| 2.0100|
REC10 |10|    1|    9|    1|10.01| 1.0100|
 

Example6
Sort based on the following two columns
1. ascending column5 and
2. descending column4

Col1|Col2| Col3| Col4| Col5| Col6|   Col7|
REC10 |10|    1|    9|    1|10.01| 1.0100|
REC09 | 9|    2|   -7|    1| 9.01| 2.0100|
REC03 | 3|    8|    6|    2| 3.01| 8.0100|
REC01 | 1|   10|    2|    2| 1.01|10.0100|
REC02 | 2|    9|   -4|    2| 2.01| 9.0100|
rec04 | 4|    7|   -8|    2| 4.01| 7.0100|
REC05 | 5|    6|   10|    3| 5.01| 6.0100|
rec08 | 8|    3|    5|    3| 8.01| 3.0100|
rec06 | 6|    5|    1|    3| 6.01| 5.0100|
REC07 | 7|    4|   -3|    3| 7.01| 4.0100|
 

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])

ISTR{n}    = text string of <n> bytes length converted to an integer value
FSTR{n}    = text string of <n> bytes length converted to a floating point value

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 supplied 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;
}
}


Send comments and questions to: pss@pobox.com

© Copyright 1992-2017, Burkhard Eichberger, Professional Software Solutions
All Rights Reserved Worldwide.

Unix® is the Trademark of X/Open Company
UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,sharewareWindows® is the Trademark of Micosoft Corp.

UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,shareware