[sword-devel] Re: Fw: building indexers.

Troy A. Griffitts sword-devel@crosswire.org
Mon, 20 Dec 1999 15:03:08 -0700


OK, all you need to do is right a small C / C++ function that receive 2
character arrays and returns -1 if the first one is less than the second
one; 1 if the first one is greater than the second one, and 0 if they
are equal.  for ascii comparisons of standard english letters, I would
write something like this:

int compare(char *value1, char *value2) {
	int offset;

	while (true) {	infinite loop that we will 'return' out of
		if ((value1[offset] == 0) && (value2[offset] == 0))  // end of both
			return 0;	// strings are equal
		if (value1[offset] == 0) // we've hit the end of the first string
			return -1;
		if (value2[offset] == 0)  // end of second string
			return 1;
		if (value1[offset] > value2[offset])
			return 1;
		if (value1[offset] < value2[offset])
			return -1;
		offset++;	// characters at this pos must be ==
				// goto next pos and continue checking

	}
}

__________________________________________--

you may need to create an array of ascii values and their 'weight' for
comparison.
char hebrewCharacters[255];
	hebrewCharacters[<ascii value of Aleph>]  = 0;
	hebrewCharacters[<ascii value of Bet>]    = 1;
	hebrewCharacters[<ascii value of Gimmel>] = 2;
	and so one...

And then use this array in your comparison like:
Change the 2 checks above from:

		if (value1[offset] > value2[offset])
			return 1;
		if (value1[offset] < value2[offset])
			return -1;

to:
	if (hebrewCharacters[value1[offset]] >
hebrewCharacters[value2[offset]])
		return 1;
	if (hebrewCharacters[value1[offset]] <
hebrewCharacters[value2[offset]])
		return -1;


______________________________________________________

Hope this helps.....
Hope this code actually compiles :)



Yeshiah Zalman wrote:
> 
> I feel bad, you lost me!
> please be patient.
> Considering 2 months ago I knew NOTHING of
> Sword OR Cbuilder.
> 
> Please explain step by step WHAT and where?
> Heh I develkoped a neat VB dictionary which sits as a BAR on the top of your screen. But C is harder.
> 
> thank you for your patience.
> 
> ----- Original Message -----
> From: Troy A. Griffitts <scribe@crosswire.org>
> To: Yeshiah Zalman <shayah@gatecom.com>; <sword-devel@crosswire.org>
> Sent: Monday, December 20, 1999 3:40 PM
> Subject: Re: Fw: building indexers.
> 
> > Yeshiah,
> > I've been giving your delema some thought and believe that I have a
> > proper solution in mind instead of a hack.  I will allow you to
> > 'register' a 'compare' method for a lexdict module that will be used
> > when doing the lookup.  The compare method will take 2 char * (Strings)
> > and should return same as strcmp (<0 for 1 < 2; >0 for 1 > 2; and 0 for
> > 1 == 2).  The sig should be something like:
> >
> > int compare(char *value1, char *value2);
> >
> > This means that the file should be sorted in such a way that:
> > for (module == TOP; !module.Error(); module++) {
> > if (compare(module.KeyText(), (module + 1).KeyText()) > 0)
> > fprintf(stderr, "ERROR: %s is greater than %s", module.KeyText(),
> > (module + 1).KeyText());
> > }
> >
> > Does this make sense?  All I need from you is a proper implementation of
> > the compare method and a properly sorted module.
> >
> > Any feedback from you or anyone else on this implementation is greatly
> > appreciated....
> >
> > -Troy