home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / UTILITY / QWKSPC12.ARJ / NDX.TXT < prev    next >
Text File  |  1992-01-01  |  4KB  |  127 lines

  1.  
  2.  
  3.  
  4.                            Format of Index files
  5.  
  6.       Index files are named XXX.NDX (where XXX is the conference
  7.       number padded with leading zeros to make it three characters
  8.       long.  There is one *.NDX file for each conference chosen that
  9.       contains messages in the MESSAGES.DAT file.
  10.  
  11.       The *.NDX file contain records five characters long that point
  12.       to each message in that conference.
  13.  
  14.  
  15.       NdxRecord = Record
  16.         MsgPointer: BasicReal
  17.         Conference: Byte;
  18.         End;
  19.  
  20.       The BasicReal is a four byte number in BASIC MKS$ format.
  21.  
  22.  
  23.       The following is a sample program unit for TurboPascal that
  24.       converts between BasicReal format and LongInt format.
  25.  
  26. ------------------------------------------------------------------------------
  27.  
  28. Unit BasicConvert;
  29.  
  30. Interface
  31.   Function BasicReal2Long(InValue: LongInt): LongInt;
  32.                 {Convert Basic Short Reals to LongInts}
  33.  
  34.   Function Long2BasicReal(InValue: LongInt): LongInt;
  35.                 {Convert LongInts to Basic Short Reals}
  36.  
  37. Implementation
  38.  
  39. Function BasicReal2Long(InValue: LongInt): LongInt;
  40.  
  41.   Var
  42.   Temp: LongInt;
  43.   Expon: Integer;
  44.  
  45.   Begin
  46.   Expon := ((InValue shr 24) and $ff) - 152;
  47.   Temp := (InValue and $007FFFFF) or $00800000;
  48.   If Expon < 0 Then
  49.     Temp := Temp shr Abs(Expon)
  50.   Else
  51.     Temp := Temp shl Expon;
  52.   If (InValue and $00800000) <> 0 Then
  53.     BasicReal2Long := -Temp
  54.   Else
  55.     BasicReal2Long := Temp;
  56.   If Expon = 0 Then
  57.     BasicReal2Long := 0;
  58.   End;
  59.  
  60.  
  61. Function Long2BasicReal(InValue: LongInt): LongInt;
  62.   Var
  63.   Negative: Boolean;
  64.   Expon: LongInt;
  65.  
  66.   Begin
  67.   If InValue = 0 Then
  68.     Long2BasicReal := 0
  69.   Else
  70.     Begin
  71.     If InValue < 0 Then
  72.       Begin
  73.       Negative := True;
  74.       InValue := Abs(InValue);
  75.       End
  76.     Else
  77.       Negative := False;
  78.     Expon := 152;
  79.     If InValue < $007FFFFF Then
  80.       While ((InValue and $00800000) = 0) Do
  81.         Begin
  82.         InValue := InValue shl 1;
  83.         Dec(Expon);
  84.         End
  85.     Else
  86.       While ((InValue And $FF000000) <> 0) Do
  87.         Begin
  88.         InValue := InValue shr 1;
  89.         Inc(Expon);
  90.         End;
  91.     InValue := InValue And $007FFFFF;
  92.     If Negative Then
  93.       InValue := InValue Or $00800000;
  94.     Long2BasicReal := InValue + (Expon shl 24);
  95.     End;
  96.   End;
  97.  
  98. End.
  99.  
  100. ------------------------------------------------------------------------------
  101.  
  102. A quick and dirty conversion (handles positive numbers only) is possible
  103. with the following expression:
  104.  
  105. MKSToNum := ((x AND NOT $ff000000) OR $00800000)
  106.              SHR (24 - ((x SHR 24) AND $7f));
  107.  
  108. ------------------------------------------------------------------------------
  109.  
  110.       The number contained in the MsgPointer is the record number
  111.       (128 byte records - starting numbering from record 1 not 0)
  112.       of the message header.  Note that since the 1st record contains
  113.       packet header, the lowest MsgPointer that can exist is 2.
  114.  
  115.       Some message readers will reformat the *.NDX files so that the
  116.       MsgPointer becomes a LongInt fileseek position (using a record
  117.       size of 1).  To determine which type of index you are reading
  118.       you should look at the size of the number.  Any BasicReal will
  119.       appear as a huge number that would unlikely ever be a byte
  120.       seek positon.
  121.  
  122.       An additional file PERSONAL.NDX is also optionally added to the
  123.       QWK archive.  This file has the same record format as the other
  124.       *.NDX files.  It contains index records pointing to messages to
  125.       the caller from all conferences (ie it is used by the mail reader
  126.       to do a quick search for personal mail in all areas).
  127.