FastSort Manual

Sorting Programmatically
FastSort Manual429834-003
4-9
Sorting From C Programs
You can also set flags.<5> to 1 to direct FastSort to not purge an existing output file
that seems too small.
Sorting From C Programs
Example 4-1 shows a C program that calls FastSort procedures to perform a serial sort
run.
Example 4-1. C Example of a Serial Sort Run (page1of5)
#pragma sql wheneverlist
#pragma symbols
#pragma inspect
#pragma runnable
#pragma nolist
/*-------------------------------------------------------------*/
/* FastSort Serial Sort Run */
/*-------------------------------------------------------------*/
/* This program sends input records to a SORTPROG process */
/* using SORTMERGESEND and then receives the sorted output */
/* records using SORTMERGERECEIVE. To reduce interprocess */
/* messages, this program uses a blocked interface and */
/* declares two buffers for nowait I/O for writes to SORTPROG. */
/* Error handling and displaying of statistics are stubbed out.*/
/*-------------------------------------------------------------*/
/* External declarations */
/*-------------------------------------------------------------*/
#include <stdioh>
#include <stdlibh>
#include <stringh>
#include <sqlh>
#include <talh>
#include <cextdecs>
#pragma list
#define BLOCKLEN 4096
#define MAXCOUNT 20 /* maximum record count */
#define BUFSIZE 35 /* size of input buff array */
char home_term_name[48]; /* terminal name */
short home_term_filenum; /* file number */
short home_term_len; /* actual len of hometerm name */
short home_term_maxlen = 48; /* max len of hometerm name */
short error_detail; /* output from process_getinfo_*/
/*-------------------------------------------------------------*/
/* FastSort control and flags information. */
/*-------------------------------------------------------------*/
_lowmem short ctlblk[200]; /* control block for sort interface */
short smflags = 0; /* SORTMERGESTART flags */
short smflags2 = 1; /* SORTMERGESTART flags2 for nowait I/0 */
short sflag1 = 1; /* use SORTMERGESTATISTICS 22-word array */
_lowmem short key_array[4]; /* SORTMERGESTART key field defns */
/*-------------------------------------------------------------*/
/* FastSort block buffers */
/*-------------------------------------------------------------*/
long block_buffer[BLOCKLEN - 1];
long block_buffer2[BLOCKLEN - 1];
/*-------------------------------------------------------------*/
/* FastSort record information and buffer. */
/*-------------------------------------------------------------*/
long dcount = 20; /* actual record count */
long *pdcount = &dcount;
short inbuf[BUFSIZE]; /* record buffer */
_lowmem char outbuf[MAXCOUNT]; /* output buffer */