LSORT 4.06 for Windows NT, Windows 2000 and Windows 95/Windows 98 Copyright (c) LONDON Computing 1988-2000. All rights reserved. LSORTNT 4.06 (C) Copyright London Computing, 1983-1999. All rights reserved. What is LSORT? LSORT for Windows is a sort program for Microsoft Windows 95 or Windows NT Release 3.51 and above. It will sort text files, xBase files, comma delimited files and fixed files on 1 - 15 sort fields. The LSRTNT sort filter is included with LSORT. LSRTNT is a sort filter, like the built in SORT command but with more flexibility. It reads from standard input and writes to standard output so that it can be used in conjunction with command line Pipes. See LSRTNT.TXT for more information. User Supported Software: LSORT is User Supported Software, if this program proves useful, please make a contribution ($35 suggested) to: London Computing, P.O. Box 696 Cherry Hill, NJ 08003 Support is available at www.londoncomputing.com as are the latest versions of LSORT. You can email support questions to: londoncomputing@abac.com Anyone sending a contribution will receive a disk containing the source code to LSORTNT as well as a copy of the LSRTNT sort filter. LSRTNT is similar to the SORT filter but works much faster and will sort on multiple fields. Once you have registered, you will be able to create write user exits to LSORT using Visual C++ 5.0 or later. 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. What's New: LSORT 4.06 -- Fixed a bug that prevented use of UNC names for input / output files. LSORT 4.05 -- Added the ability to specify escape characters: \n -- linefeed, \r -- Carriage Return, \a -- alarm, \t -- tab \xxx character with decimal value xxx in the -d="..." flag. This allows these special characters to be used as delimiters when doing a Delim sort. LSORT 4.04 -- Added -B flag for Batch Mode (non interactive). No Prompting is done. In Batch Mode, messages are written to STDERR. If Logfile in use (the default), and Quiet Mode (-Q) is specified, nothing is written to STDERR. In this case, the log file contains all of the information. This release also fixes a Y2K problem with date fields when the year ends in 00. LSORT 4.03 -- Modifications to the installer only to resolve problems with the Windows front end on systems running Microsoft Windows 95 and Microsoft Windows 98. LSORT 4.02 -- Addition of Y2K compliant Year field, plus various Y2K compliant date fields. Interface tweaks. LSORT 4.00 -- Modifications to the interfact to run seamlessly from the Windows front end. Field Types: Any sort field can be sorted into ascending or descending sequence. Sort fields may be: o Case independant character strings, o Case dependant character strings, o Numbers stored as character strings, o 2 byte binary integers (Intel Format) o 4 byte binary integers (Intel Format) o 4 byte IEEE floating point numbers, o 8 byte IEEE floating point numbers, o xBase Logical fields (True/False fields), o IBM Mainframe style binary integers, o IBM Mainframe style packed decimal numbers. o Y2K Compliant 2 position year field. o Y2K Compliant mm/dd/yy date field. o Y2K Compliant dd/mm/yy date field. o Y2K Compliant yy/mm/dd date field. o mm/dd/yyyy date field. o dd/mm/yyyy date field. o yyyy/mm/dd date field. Implementation: LSORT runs as a Windows application. The front end was written with Visual Basic 5.0 and the Sorting Engine is the LSORTNT sort/merge utility compiled using Visual C++ 6.0. You may also run LSORTNT from a command line. When run from the command line, you can sort up to 32 fields. Instructions for running from the command line can be found in the section labelled: Command Line Interface. Installation: LSORT is packaged into a self extracting installation program, LSORT404.EXE. It will install to a subdirectory of your choice and create an icon for LSORT 4.05, the windows executable, as well as LSORT404.TXT, these instructions. LSORT404.EXE is also packaged as a set of 2 diskettes. To install, run SETUP.EXE from diskette #1. Upgrade: If you are upgrading LSORT, please uninstall the old version of LSORT first. If you are running Windows 95 or Windows 98, please manually delete the file: C:\WINDOWS\SYSTEM\COMDLG32.OCX before upgrading. Known Problems: LSORT402 did not install properly on some systems running Windows 95/98. The Command Line Program, LSORTNT.EXE, would work properly, but the LSORT32.EXE front end would not load. LSORT403 is a fix for that install problem. If you are upgrading to resolve the LSORT402 install problem, follow the Upgrade instructions above. Be sure the remove COMDLG32.OCX. Using the Windows Interface The LSORT for Windows menus has seven options on the menu bar: File, Record, SortField, Options, Go, Help and Exit. File Menu: Use the File menu to specify: o The type of Sort to run (Heap Sort, Quick Sort or Merge), o The name(s) of the input file(s) o The name of the output file Once a file has been selected, LSORT will display the file name with a View button next to it. Clicking the View button will allow you to view first 16KB of the file. File Menu Options: New sort Specification -- Used to Clear the current settings and start over. Load Sort Specifications -- Used to restore previously saved sort specifications. Save Sort Specifications -- Use to save the current setting in a specifications file (.LSR) Save Redirection File -- Create a redirection file that can be used with LSORTNT.EXE to rerun the current sort without needing to rerun the GUI interface. This option is initially disabled and will not be enabled until there is enough information to run the sort. This option is enabled whenever the Go options (below) is enabled. See Go for more information. Heap Sort -- Sort a file using the heap sort algorithm. Heap sort is generally slower than Quick Sort. It should be used only when Quick Sort has been tried and has run very slowly. Quick Sort -- Sort a file using the quick sort algorithm. Quick sort is usually faster than Heap Sort, but occassionally runs into strange data that makes it run very slowly. Merge -- Merge from 2-5 files into a single sorted file. Input -- Specify the input file for the sort or the set of input files to merge depending on the selection of Heap Sort, Quick Sort or Merge. All files to be merged must be in the same directory. Output -- Specify the name of the output file. Go -- Run the Sort/merge. Go is initially disabled. When SORTING, You must specify an input file, an output file and at least one Field Definition before Go is activated. When MERGING, you must specify between 2 and 5 Input Files, an output file and at least one sort field before Go is activated. Exit -- Shut down LSORT32. Record Menu: Use the Record menu to define the type of file to sort: o Variable (File contains Text Records ending with CR-LF) o Fixed Length Record (May be Text or Binary. You will be prompted to enter the Record Length to use. When sorting Fixed Length Records, CR-LF combinations do NOT end the record. o Delimitted Records. The file contains variable length records as above, but each field is seperated from the next using the delimitter character. The system defaults to using a comma, but other delimitter characters can be used instead. o xBase File. The file being sorted is an xBase file. The file header will be used to determine field positions and field lengths. SortFields Menu: Use the SortFields menu to define the fields to be sorted. Selecting Sortfield allows you to specify from 1 to 15 sort fields. A sort field definition consists of four pieces of information: o The starting position of the field, from 1. o The length of the field (1 ... 127). The field length is not needed and may not be entered for Comma Delimited Files. o The Field Type (Character, Case Independant Character, 2 Byte Binary, 4 Byte Binary, 4 Byte IEEE Floating point, 8 Byte IEEE Floating Point and xBase Logical, IBM mainframe style binary integers and IBM mainframe style packed decimal numbers.) o Ascending or Descending Sort. When SortFields is selected, a list of defined sort fields are displayed along with Add, Edit, Delete, Cancel and Ok buttons. You can insert a new sort field before an existing field by highlighting a field definition and clicking Add. You can modify a definition or fill in a blank definition by highlighting an item (possibly empty) in the list of defined fields and pressing Edit or by double clicking a field definition. The Delete button will remove the current field definition. The Cancel button will return you to the main menu. Any changes made before Cancel will be ignored. The Ok button applies changes to field definitions before returning you to the main menu. When you select a sort field to Edit, a field definition form is displayed. You may set or change the starting position, field length, field type and sort sequence. A sample record is also displayed. You can define a field by selecting clicking on the first character of the field and dragging the mouse to the last character of the field. The starting position and field length will be filled in. LSORT will also set an initial field type. These values can be changed later. When a sort field is defined, it will be displayed on the main menu. Sort fields are displayed top to bottom, left to right. A displayed sort field and be modified by clicking the text. The field definition window will open allowing you to modify the entries. All fields is Comma Delimited files are shown with their field length set to 0. Options Menu: The Options Button is used to specify one or more of the following options: o Check Field Start -- When selected, LSORT will check that sort fields in Variable Files do not start past the end of the current record. If the field does start past then end of the record, it is treated as a blank field. This option is only enabled when sorting Variable length files. o Delimiters -- Click to specify the delimiter to be used in parsing delimited files. The default is a comma (,). This option is only enabled when sorting delimited files. o Memory -- Click this option to specify how much memory LSORT should use during the sort/merge operation. You can specify memory usage 1 of 4 different ways: o Percentage of total memory (Default 36%) o Abslute amount of total memory o Percentage of total memory to leave free for other tasks. o Absolule amount of memory to leave free. o Work Drives -- The drives to be used for temporary sort work files. These files are created whenever a file is too large to sort in memory and must be sorted in pieces then merged together. The first set of work files go to the Work1 drive. If there are too many work files to merge in one pass, the second set of files are created on the Work2 drive. Work1 and Work2 default to the "C" drive, but should be set to different drive letters if possible. Go Menu: The Go option on the main menu is initially disabled. You must specify an input file, an output file and at least one sort field before Go is activated. Click the Go option to actually sort the file. When Go is selected, the front end invokes the command line utility, LSORTNT.EXE to actually sort the data. Log Files: LSORT produces a log file each time it is run. Log files are stored in the directory from which LSORT is run. The current version of the log file is always named: LSORTNT.LOG. You should refer to this file if the results of your sort are not what was expected. If any prior versions of the log file exist, they are renamed as LSORTNT.LOG.-xx where xx is a number from 01-99. The oldest log file is always replaced. Command Line Interface (LSORTNT.EXE) All actual sorting and merging is done by the sort engine, LSORTNT.EXE. LSORTNT is a general purpose sort/merge utility written in Visual C++ for Microsoft Windows 95 and Microsoft Windows NT 3.51 or later. It runs on IBM PCs and compatibles. Once you have registered, you will be able to create user exits for LSORT using Visual C++ 5.0 or later. LSORTNT is User Supported Software, if this program proves useful, please make a contribution ($35 suggested) to: London Computing, P.O. Box 696 Cherry Hill, NJ 08003 Anyone sending a contribution will receive a disk containing the source code to LSORTNT as well as a copy of the LSRT sort filter. LSRT is similar to the DOS SORT filter but works much faster and will sort on multiple fields. 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 Windows NT, MSDOS, 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. LSORTNT 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. The sort knows about: field type binary fields (to 127 bytes) B Binary Fields are sorted from left to right one byte at a time based on the code in each position (0-255). Useful for comparing IBM Mainframe style binary numbers. packed decimal fields (1-8 bytes) Stored as on P IBM Mainframe computers. Each digit position is stored in 4 bits as a binary value between 0 and 10. The digits are stored left to right with the rightmost position containing a sign, 0x0D for negative, 0x0C or 0x0F for positive. A packed decimal field can store between 1 and 15 digits depending on the length of the field. If an invalid sign field is specified, the sort won't produce what you would expect. Packed decimal values are only meaningful in fixed length record. character fields (to 127 bytes) C Character fields compare up to the first binary zero in the field, following the C language conventions for character strings. upper case character fields (sort fields are U translated to upper case before compare) 2 byte integers in internal format I 4 byte integers in internal format L floating point numbers (ieee) F double precision floating point (ieee) D zoned decimal numbers N (Text format numbers, Decimals are allowed) (LSORTNT now supports scientific notation as) (well, using E notation, eg. .98 == 9.8E-1) (xBase N and F fields are sorted as type Z) 1 byte logical fields (dBase II or III) T 2 position year field used as part of a date 2 to be sorted, i.e. as the yy part of a yymmdd date. If the value of yy is > 30, it is assumed to be a year in 1900. If the value of yy is <= 30, it is assumed to be a year in 2000. 6-8 position mm/dd/yy date. The delimiter can be 3 any punctuation character, e.g. period, comma slash, ... This date field is considered Y2K compliant using the rule of 30 as above. If the value of yy is > 30, it is assumed to be a year in 1900. If the value of yy is <= 30, it is assumed to be a year in 2000. yy,mm and dd may be either 1 or 2 positions long. Leading and trailing spaces are ignored. 6-8 position dd/mm/yy date. The delimiter can be 4 any punctuation character, e.g. period, comma slash, ... This date field is considered Y2K compliant using the rule of 30 as above. If the value of yy is > 30, it is assumed to be a year in 1900. If the value of yy is <= 30, it is assumed to be a year in 2000. yy,mm and dd may be either 1 or 2 positions long. Leading and trailing spaces are ignored. 6-8 position yy/mm/dd date. The delimiter can be 5 any punctuation character, e.g. period, comma slash, ... This date field is considered Y2K compliant using the rule of 30 as above. If the value of yy is > 30, it is assumed to be a year in 1900. If the value of yy is <= 30, it is assumed to be a year in 2000. yy,mm and dd may be either 1 or 2 positions long. Leading and trailing spaces are ignored. 6-10 position dd/mm/yyyy date. The delimiter can 6 be any punctuation character, e.g. period, comma slash, ... dd and mm may be either 1 or 2 positions long. Leading and trailing spaces are ignored. yyyy may be from 1-4 positions long. Leading and trailing spaces are ignored. 6-10 position mm/dd/yyyy date. The delimiter can 7 be any punctuation character as above. dd and mm may be either 1 or 2 positions long. Leading and trailing spaces are ignored. yyyy may be from 1-4 positions long. Leading and trailing spaces are ignored. 6-10 position yyyy/mm/dd date. The delimiter can 8 be any punctuation character as above. dd and mm may be either 1 or 2 positions long. Leading and trailing spaces are ignored. yyyy may be from 1-4 positions long. Leading and trailing spaces are ignored. User defined field type X X User defined field type Y Y User defined field type Z Z A zoned decimal number is stored as a character string and may contain leading and trailing spaces, minus sign, decimal point and digits. 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. LSORTNT will prompt you for all parameters and file names or you may specify some or all of the parameters on the command line when you invoke the sort. 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. If you have a floppy only system, you should have LSORTNT on the A drive and the file to be sorted on the B drive. Place a copy of LSORTNT on an otherwise empty disk and use as your A drive. You may need a formatted empty disk for work files on the B drive. You may specify the sub-directories to be used for merge files by setting environment variables: LSORTWORK1 and LSORTWORK2 to specific drives and directories. If a file is too large to sort in memory, then it will be sorted in pieces over several passes. All odd numbered passes merge files will be stored in LSORTWORK1. Even numbered merge files will be stored in LSORTWORK2. It is a good idea to place these files on seperate physical drives (if possible.) You may now run multiple copies of LSORT at the same time. You must run each copy from a different directory in order to not destroy the restart files. If you need to run multiple copies of LSORT, you should add your LSORT installation directory to your PATH. EG. C: C: cd \DIR1 cd \DIR2 LSORTNT ... LSORTNT ... SYNTAX: LSORTNT [-d="x"] [-unn|-fnn] [-V] [-Q] [-W] [-Llogfile] sort specifications -- will take the specification entered and prompt you for any others. Specify -unn to use nn% of available memory for the sort. -fnn to leave nn% of available memory free. Specify -V to check each field in a V type file to ensure that the field starts before the end of the record. If the field starts past the end of the record, set to empty. Specify -Q for QUIET mode. LSORT will run silently unless an error occurs. Specify -W to display SORT statistics at end of the sort. Specify -d="x" to use x as the delimitter for delimitted files. Defaults to a comma (,). You may use \t for tab, \n for newline, \r for return, \a for alarm, \xxx for decimal character xxx. or LSORTNT -R -- will restart a sort. It uses information stored in a file SORTPARM.DAT that is created when a sort begins. If the sort finishes properly, SORTPARM.DAT will be deleted. If it doesn't, you can use the -R flag to restart it. Restarting: If a sort stops in the middle due to lack of space or is stopped by you by pressing ^BREAK, it may be restarted by issuing the LSORTNT -R command providing the dataset(s), SORTPARM.DAT and (DB3PARM.DAT for dBase III files only) are still available and further providing all files LSMERGE?.DAT are still available. The sort will be restarted at the beginning of the LSSORT phase (where the input file is read and sorted) or at the beginning of an LSMERGE pass, where several partially sorted files are combined. Sort Operations: 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 drives must be large enough to hold the entire input file. For a SORT operation, you must specify your input file, output file, type of file, plus field definitions. Fields are specified by their starting position and length. The types of fields have been listed above. The sort specifications must be entered on the command line in the order shown below. Each parameter should be separated from the others with one or more spaces. The sort will ask for the following information in the order shown: Type of Sort: You may enter: 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. File Type (Unless you are sorting a dBase file): You may reply F for a fixed length file (all records are the same length), V for a varying length file (records must end with CR LF.) or D for comma delimited files. If you entered 'F' for a fixed file, you must then enter the record length. Field definitions. Each field definition has four parts: o starting position (from 1) or starting field (delimited files) o field length (in bytes) (no prompt for delimited files) o field type B -- for a binary field. (Also Mainframe style integer) C -- for a character field. D -- for a double precision IEEE format floating number. F -- for a single precision IEEE format floating number. I -- for a two byte binary integer. L -- for a four byte binary integer. N -- for an ASCII format numeric field (decimals allowed). P -- for an IBM Mainframe style Packed Decimal field. T -- for a dBase Logical (True or False) field. U -- for a character compare where case is ignored. 2 -- for Y2K compliant 2 character year field. 3 -- for Y2K compliant mm/dd/yy date field. 4 -- for Y2K compliant dd/mm/yy date field. 5 -- for Y2K compliant yy/mm/dd date field. 6 -- for Y2K compliant mm/dd/yyyy date field. 7 -- for Y2K compliant dd/mm/yyyy date field. 8 -- for Y2K compliant yyyy/mm/dd date field. X -- for user defined field type X. Y -- for user defined field type Y. Z -- for user defined field type Z. User defined fields are available to registered users who have received the source code. o sort order (A--Ascending, D--Descending) In order to work as efficiently as possible, LSORTNT does not check the starting position of a field against the actual length of a record. If some field starts past the end of a record (e.g. sort field 1 starts in column 10 but the record is only 8 bytes long), the results will be undefined and most certainly not what you want. Please be careful. Enter a '0' for the starting position to end the list of field definitions. If you are sorting a dBase file, you may specify a field by name, in which case you need only enter the sort order or you may enter starting position, length, type and order as above. example 1: Sort file test.dat on positions 1-5,char,ascending and 6-7, binary integer, descending. Use drive C for the work files and put the sorted file in test.srt. Issue the following command: LSORTNT S C C test.dat test.srt V 1 5 C A 6 2 H D 0 | | | | | | |_____| |_____| | | | | input output F | | | | | | file file i sort sort | | | | name name l field 1 field 2 | | | | e starts starts | | | merge drive 2 at byte at byte | | | T 1, is 5 6, is 2 | | merge drive 1 y byte byte | | p char- long | sort using e acter integer | quicksort string sorted ends list of sort fields. ascend- descend- ing ing Merge Specification: Enter 'M' to indicate the merge operation. You must then enter the number of files to be merged followed by 1-5 filenames to be merged. You must then 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. LSORTNT M 3 t1.dat t2.dat t3.dat test.mrg V 4 4 c a 0 | | | | | | | |_____| | | | input input input output | | | | | file 1 file 2 file 3 file | merge | | | | field | | merge 3 files | 1 | | | end of list of merge do a merge file fields type Sort or Merge specifications may be stored in a file for reuse. In that case, you can use the following syntax: LSORTNT [flags] @sortfile where flags are defined above and sortfile contains the sort specifications. Flags may also be entered in redirected, but you may only place one flag on a line. If a new line begins with a -, it is assumed to be a flag until the 1st non flag is read. this means that flags must be set before any other parameters. The -d="x" parameter must be entered as -d=x when in a redirected file. You may enter all other parameters one or more to a line. Redirected files are especially useful when merging, since it is possible to exceed the size of a Windows 95 command line if multiple file names must be entered. Example 3: Sort file test.dat on positions 1-5,char,ascending and 6-7, binary integer, descending. Use drive C for the work files and put the sorted file in test.srt. Save the sort specifications is sort.inp. Issue the following command: LSORTNT @sort.inp sort.inp can consist of one line containing: S C C test.dat test.srt V 1 5 C A 6 2 H D 0 The information can also be broken up with one or more specifications to a line as below: S C C test.dat test.srt V 1 5 C A 6 2 H D 0 Example 4: Merge files t1.dat t2.dat and t3.dat on positions 4-7 defined as a character field, ascending. LSORTNT @merge.inp where merge.inp looks like: M 3 t1.dat t2.dat t3.dat test.mrg V 4 4 c a 0 User Exits: 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. User input: (Available for Sorting Only) 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. USERIP is used as follows: 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(buffer,buflen); /* userop must write buflen bytes from buffer */ /* buflen == 0 means that you want to write a 0 terminated string */ userop(NULL,-1); /* userop must perform end of file processing */ Sample versions of userip and userop appear below: /* Userip to return a varying length string */ #define CPMEOF 26 #include "stdio.h" userip(s) char *s; { static char firsttime = 1; static int inchan; char *fgets(); int l; /* input is string buffer, max length 4k, 4k always available */ /* this routine must return length of string or EOF if end of file */ /* example follows: (Note length of string includes 0 byte at end */ if (firsttime) { firsttime=0; inchan=fopen("usertest.dat","r"); } if (fgets(s,4096,inchan)) return strlen(s)+1; else return EOF; } /* Userip to return a fixed length string */ #define CPMEOF 26 #define STRLEN 128 #include "stdio.h" userip(s) char *s; { static char firsttime = 1; static int inchan; char *fgets(); int c,l; /* input is string buffer, max length 4k, 4k always available */ /* this routine must return length of string or EOF if end of file */ /* example follows: (Note length of string includes 0 byte at end */ if (firsttime) { firsttime=0; inchan=fopen("usertest.dat","r"); } if ((l=read(inchan,buffer,STRLEN)) == STRLEN) return STRLEN; else return EOF; } 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 */ } User Compare Routines: You may define up three user defined fields: X,Y,Z. You must write a compare routine for each field type used. The routine names are: sxcmp -- for field type X. sycmp -- for field type Y. szcmp -- for field type Z. 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. Sample routines are shown below: 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; } Installing the LSORT Source Files: If you have registered LSORT, you will also receive LS404SRC.EXE. If you have chosen to receive floppy disks, LS404SRC.EXE will be stored on disk#2. It contains the source and object files for LSORTNT.EXE, the sorting engine as well as the VB5 code for the Windows Interface and the C code for a .DLL used by the Windows interface. To install, run LS405SRC. You will be prompted for a subdirectory to install to. The default is LSORTSRC. Running LS405SRC creates the following directory structure (assuming that the default LSORT directory was chosen): \LSORT This contains the source code for LSORTNT and LSRTNT. It also contains the project files needed to rebuild the application as well as a .MAK file if you are not using Microsoft Visual C++. \LSORT\WINREL This contains the object files for LSORTNT. You can use these files if you are creating your own user exits. \LSORT\LSORTW32 This contains the Microsoft Visual Basic 5 source files for the windows front end to LSORTNT. It generates LSORT32.EXE. \LSORT\STRHEX32 This contains the C source for STRHEX32.DLL which is used by LSORT32.EXE.