Subj : QWK .NDX-generating code To : All From : William McBrine Date : Fri Jan 12 2001 02:59 am Back when I was starting out in QWK, reading the de facto standard, QWKLAY, I noticed that the section which presented sample code for dealing with ..NDX files was a little short on the generating end -- there's only one, real-number-based generating routine, for Pascal, though there are three to go the other way (one real and one integer-based for Pascal, and one integer-based for C). As it happens, I just ran into a guy who was porting his BBS to Linux, and he was creating the .NDX files incorrectly -- he was using the sample Pascal code from QWKLAY, but of course, he couldn't use Borland Pascal on Linux, and the code wasn't quite compatible. So I took the opportunity to do something I'd meant to do a long time ago, and wrote a more portable, integer-based routine. My Pascal is rusty, so I wrote it in C first and ported it. :-) So then I thought, others might be interested in this code. Here it is; I'm putting it in the public domain: C version: /* ms is unsigned char ms[4] */ void longtoMSBIN(unsigned long index, unsigned char *ms) { unsigned char exp = '\0'; if (index) { while (!(index & 0x800000L)) { exp++; index <<= 1; } index &= 0x7fffffL; } else exp = 152; ms[0] = index & 0xff; ms[1] = (index >> 8) & 0xff; ms[2] = (index >> 16) & 0xff; ms[3] = 152 - exp; } Borland-like Pascal version (no reals, no absolutes): type bsingle = array[0..3] of byte; procedure longtoMSBIN(index: longint; var ms: bsingle); var exp: byte; begin if (index <> 0) then begin exp := 0; while (index and $800000) = 0 do begin inc(exp); index := index shl 1 end; index := index and $7FFFFF; end else exp := 152; ms[0] := index and $FF; ms[1] := (index shr 8) and $FF; ms[2] := (index shr 16) and $FF; ms[3] := 152 - exp; end; .... ///\oo/\\\ Bugs? What bugs? ///\oo/\\\ ///\oo/\\\ --- MultiMail/Linux v0.38 * Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000) .