Category : Files from Magazines
Archive   : CSORT.ZIP
Filename : FILESORT.C

 
Output of file : FILESORT.C contained in archive : CSORT.ZIP
/* --------------------- filesort.c ------------------------ */

#include
#include
#include
#include "csort.h"

/* sort a file:
* command line: filesort filename length {f1, l1, az1, ...}
* filename is the name of the input file
* length is the length of a record
* for each field:
* f1 is the field position relative to 1
* l1 is the field lengths
* az1 = A = ascending, D = descending
*/

static struct s_prm sp;
static void usage(void);

void main(int argc, char *argv[])
{
int i, fct = 0;
FILE *fpin, *fpout;
char *buf;
char filename[64];

/* ------- get the file name from the command line ------ */
if (argc-- > 1)
strcpy(filename, argv++[1]);
else
usage();
/* ----- get the record length from the command line ---- */
if (argc-- > 1)
sp.rc_len = atoi(argv++[1]);
else
usage();
/* ----- get field definitions from the command line ---- */
do {
if (argc < 4)
usage();
sp.s_fld[fct].f_pos = atoi(argv++[1]);
sp.s_fld[fct].f_len = atoi(argv++[1]);
sp.s_fld[fct].ad = *argv++[1];
argc -= 3;
fct++;
} while (argc > 1);

printf("\nFile: %s, length", filename, sp.rc_len);
for (i = 0; i < fct; i++)
printf("\nField %d: position %d, length %d, %s",
i+1,
sp.s_fld[i].f_pos,
sp.s_fld[i].f_len,
sp.s_fld[i].ad == 'd' ?
"descending" : "ascending");

if ((fpin = fopen(filename, "rb")) == NULL) {
printf("\nInput file not found");
exit(1);
}
if ((buf = malloc(sp.rc_len)) == NULL ||
init_sort(&sp) == -1) {
printf("\nInsufficient memory to sort");
exit(1);
}
/* ------ sort the input records ------- */
while (fread(buf, sp.rc_len, 1, fpin) == 1)
sort(buf);
sort(NULL);
fclose(fpin);
/* ----- retrieve the sorted output records ------ */
fpout = fopen("SORTED.DAT", "wb");
while ((buf = sort_op()) != NULL)
fwrite(buf, sp.rc_len, 1, fpout);
fclose(fpout);
sort_stats();
free(buf);
}

static void usage(void)
{
printf("\nusage: filesort fname len {pos length ad...}");
exit(1);
}


  3 Responses to “Category : Files from Magazines
Archive   : CSORT.ZIP
Filename : FILESORT.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/