DataMuseum.dk

Presents historical artifacts from the history of:

Christian Rovsing CR7, CR8 & CR16 CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Christian Rovsing CR7, CR8 & CR16 CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦29102cf7b⟧ TextFile

    Length: 1280 (0x500)
    Types: TextFile
    Names: »ALPH.C«

Derivation

└─⟦23f778bf6⟧ Bits:30005378 BDS C v1.46 & Pascal/MT+ v5.5 (Callan format)
    └─ ⟦this⟧ »ALPH.C« 
└─⟦4ada80662⟧ Bits:30005446 Pascal/MT+ v5.5 & XREF & BDS C v1.46
    └─ ⟦this⟧ »ALPH.C« 

TextFile

/*
	Alphabetize a file by lines.
	Usage:
		alph <inputfile> <outputfile>
*/

#include "bdscio.h"


#define MAXLINES   300		/* max number of lines */

int strcmp();
char iobufÆBUFSIZÅ;
char *ltabÆMAXLINESÅ;
int lcount;

char *allocp;

main(argc,argv)
char **argv;
æ
	int i;
	char linbufÆ300Å;

	if (argc != 3) exit(puts("Usage: alph <infile> <outfile>Øn"));
	if (fopen(argvÆ1Å,iobuf)== ERROR)
		exit(puts("Can't open input fileØn"));

	lcount = 0;

	for (i = 0; i < MAXLINES; i++)
	æ
		if (!fgets(linbuf,iobuf)) break;
		if ((allocp = sbrk(strlen(linbuf) + 1))	== ERROR)
			exit(puts("Out of allocation spaceØn"));
		ltabÆlcount++Å = allocp;
		strcpy(allocp,linbuf);
	å

	fclose(iobuf);

	if (i == MAXLINES) exit(puts("Too many lines. Change MAXLINESØn"));

	qsort(ltab,lcount,2,&strcmp);

	if (fcreat(argvÆ2Å,iobuf) == ERROR)
		exit(puts("Can't creat output fileØn"));
	for (i = 0; i < lcount; i++)
		fputs(ltabÆiÅ,iobuf);
	putc(CPMEOF,iobuf);
	fflush(iobuf);	
	fclose(iobuf);
	puts("All done.Øn");
å

int strcmp(s,t)
char **s, **t;
æ
	char *s1, *t1;
	s1 = *s;
	t1 = *t;
	int i;
	i = 0;
	while (s1ÆiÅ == t1ÆiÅ)
		if (s1Æi++Å == 'Ø0')
			return 0;
	return s1ÆiÅ - t1ÆiÅ;
å
«eof»