Professional Documents
Culture Documents
Lsortnt
Lsortnt
What is LSORT
You may make copies of this software and distribute to other users as
long as there is no charge or other consideration and this notice is not
removed or bypassed.
LSORTNT will sort MSDOS, Windows NT, OS2 files and dBase II and dBase III
databases. (dBase III memo files and FOXPRO memo files are not sorted
but .DBF files will be sorted.) Each file may be sorted using 1 to 32
sort fields. The file to be sorted may contain either fixed length
records, variable length records or comma delimited records. Variable
length records are records ending with cr/lf. Comma delimited records
are variable length records where the fields are also variable length
and separated by a comma. Character fields may be enclosed in either
single or double quotes. It will merge up to 5 files using 1 to 32
sort fields. dBase databases may not be merged. Any field may be
sorted in either ascending or descending sequence. LSORT allows for
three user defined field types to be used: X,Y and Z. You must write
your own comparison subroutine to compare user defined fields.
NOTE: zoned decimal numbers and comma delimitted files sort very slowly!
The only reasonable field types for comma delimited files are C or N.
LSORT will accept other field types, but the results are undefined.
Sorting Dates:
Until the Y2K issues became important, it was not necessary for LSORT to
specifically deal with date fields. Release 4.02 of LSORT has added a Y2K
compliant 2 character year field to handle dates that exceed the year 2000.
The maximum record length is 4096 bytes. Files will be sorted in memory
if possible.
Files larger than available memory are sorted in pieces and then merged
together.
SYNTAX:
Flags:
Sort Specifications:
You must specify either a SORT or MERGE operation.
If you ask for a SORT, you may tell LSORTNT to use either a QUICKSORT or
HEAPSORT for internal sorting. You will also be asked to specify two
devices to hold merge files if any are needed. Merge files may be placed on
floppy disk, hard disk or RAM disk. The specified drive must be large
enough to hold the entire input file.
If you specify SORT or MERGE you must enter your input file(s) and
output file as well as the definition of the key fields to be used in the
comparisons. Fields are specified by their starting position and length.
The types of fields have been listed above.
Type of Sort:
S -- for QUICKSORT
H -- for HEAPSORT
Merge Drive 1: You may reply with any drive letter, although it is best to
specify a fixed disk (if any).
Merge Drive 2: This should be different from drive 1 if you are using
floppy disks, but should be a fixed disk if you have one.
Name of input file: You may specify any name including drive letter and
path. Specify :X to use a user specified input routine.
Name of output file: See above. Specify :X to use a user specified output
routine.
You must then enter field definitions. Each field definition has
four parts:
starting position (from 1) or starting field (delimited files)
field length (in bytes) (no prompt for delimited files)
field type (See above list of valid types)
sort order (A--Ascending, D--Descending)
Enter a '0' for the starting position to end the prompt for field
definitions.
If you are sorting a dBase file, you may specify a field by name, in
which case you will only be need to enter the sort order {A|D}.
You may enter starting position, length, type and order as above.
example 1:
Merge Specification:
You will be asked to enter the number of files to be merged followed by 1-5
files to be merged. They are entered one at a time.
You will be asked to enter a file type, output file and a field list as
above.
example:
Merge files t1.dat t2.dat and t3.dat on positions 4-7 defined as a character
field, ascending.
You may define your own user exits to read and write data and you may define
your own compare routines for the standard field types or for user defined
field types. These routines must be written in Microsoft Visual C++ 5.0 or in
any other language that can be linked to Microsoft Visual C++.
User Exits are only available to registered users, who will recieve the
source and object files for LSORT.
Specify :X as the name of the input file. LSORTNT uses a routine named
USERIP to read the records to be sorted. You may write your own
version of USERIP and link it with LSORT to create a custom version
containing your own input routine.
int l,userip();
char buffer[...];
l = userip(buffer);
USERIP must return the length of the record read which must be <= 4096
or -1 for end of file. If you have specified V type files, USERIP must
return a string ending with a '\0'. The string length must include the
trailing '\0'.
User Output:
Specify :X as the name of the output file. LSORT uses a routine called
USEROP to write to the :X file. You may write your own user output
routine to be used to write the final sorted or merged output by
creating a custom version of USEROP and relinking LSORT to create a
custom LSORT. USEROP works as follows:
int buflen;
char buffer[...];
userop(s,l)
char *s;
int l;
{
/* s is string to write, l is length or 0 if 0 terminated or -1 for close */
static char firsttime = 1;
static int otchan;
if (firsttime) {
firsttime = 0;
otchan = fopen("usertest.srt","w");
}
if (l == -1 || s == NULL)
fclose(otchan);
else if (l) /* write an F type record */
while(l--) fputc(*s++,otchan);
else fputs(s,otchan); /* write a V type record */
}
The compare routines are called with three arguments, the address of the
first field, the address of the second field and the field length. The
routine must return 1 if field 1 < field 2, 0 if field1 == field2 and -1 if
field1 > field2.
sxcmp(a,b,l)
long int *a,*b;
int l;
{ /* this routine compares two long integers */
long int c;
c = *a - *b;
return c <0 ? -1 : c == 0 ? 0 : 1;
}
sycmp(a,b,l)
int *a,*b;
int l;
{ /* this routine compares two integers (2 bytes) */
int c;
c = *a - *b;
return c <0 ? -1 : c == 0 ? 0 : 1;
}
szcmp(a,b,l)
float *a,*b;
int l;
{ /* this routine compares two floating numbers */
float c;
c = *a - *b;
return c<0 ? -1 : c == 0 ? 0 : 1;
}