home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / answcode / newpoint.pas < prev    next >
Pascal/Delphi Source File  |  1988-10-27  |  5KB  |  224 lines

  1.  
  2. Unit NewPoint;
  3. {$R-,S-,I-,N-,D-,T-,F+,B+}
  4.  
  5. INTERFACE
  6.  
  7. Uses Crt,Library,Wndw,Wndwvars,Qwik,TAccess,TAHigh;
  8.  
  9. Procedure MakePointers;
  10. IMPLEMENTATION
  11.  
  12. Procedure MakePointers;
  13. Type
  14.    IndexType = String[6];
  15.    CommonType = Array[1..1000] of string[6];
  16.    ParseType = String[12];
  17.    Sorted = Record
  18.     KeyWord : String[12];
  19.     end;
  20.  
  21.    Pointers = Record
  22.         IndexWord : IndexType;
  23.           PtrArray : Array[1..200] of Integer;
  24.          end;
  25.  
  26.    String6 = String[6];
  27.  
  28. MaxDataType = Pointers;
  29. MaxKeyWordType = IndexType;
  30.  
  31. Var
  32.     SortFile : File of Sorted;
  33.     PointerFile : DataSet;
  34.    FileName : String[8];
  35.     A,J,K,M,Per : Integer;
  36.     I : LongInt;
  37.     PointerRec : Pointers;
  38.     SortRec : Sorted;
  39.     CommonWords : CommonType;
  40.    SearchKey : String[6];
  41.     KeyLine : ParseType;
  42.    CommonFile : Text;
  43.     IntValue,LineCount,Position,Result : Integer;
  44.    Line : String[6];
  45.     Empty,Exact,Found : Boolean;
  46.  
  47.  
  48. Procedure AddPointer;
  49.  
  50. Var
  51.     X : Integer;
  52.  
  53. Procedure SchStBin(var TextArray : CommonType;LineCount,Position : Integer;
  54.           TextKey : ParseType;var Result : Integer);
  55.  
  56.  
  57. var
  58.    Low,High,J,Width : Integer;
  59.  
  60. begin
  61.    Result := -1;
  62.    Width := Length(TextKey);
  63.    if width <1 then exit;
  64.    low := 1;
  65.    high := LineCount;
  66.    while high>=low do
  67.    begin
  68.         J := (low + high) div 2;
  69.         if textkey<copy(textarray[J],Position,width) then
  70.         high := j-1
  71.         else
  72.         if textkey>copy(textarray[J],position,width) then
  73.         low := j+1
  74.         else
  75.         begin
  76.         result :=j;
  77.         exit
  78.         end
  79.         end
  80.         end;
  81.  
  82. Procedure ParseIn(SourceStr:ParseType;var Position:Integer;var Found:Boolean;var IntValue:Integer);
  83.  
  84. var
  85.    SourceLen,TrialLen,Code : Integer;
  86.  
  87. begin
  88.      SourceLen := length(SourceStr);
  89.      IntValue := 0;
  90.      Found := False;
  91.      If not (Position in [1..SourceLen]) then
  92.      exit;
  93.      TrialLen := SourceLen-Position+1;
  94.      repeat
  95.            val(copy(SourceStr,Position,TrialLen),IntValue,Code);
  96.            if Code>TrialLen then
  97.               Code := TrialLen;
  98.  
  99.            if Code>0 then
  100.               TrialLen := Code-1
  101.  
  102.      until
  103.           (TrialLen=0) or (Code=0);
  104.           if (Code=0) then
  105.           begin
  106.           Found := True;
  107.           Position := Position+TrialLen;
  108.           If Position>SourceLen then
  109.           Position := 0
  110.           end
  111.  
  112. end;
  113.  
  114.  
  115.  
  116. begin
  117.     with SortRec do
  118.     begin
  119.     KeyLine := KeyWord;
  120.     A := Pos(',',KeyLine);
  121.     SearchKey := PadR(Copy(KeyLine,1,A-1),6);
  122.     Position := 1;
  123.     SchStBin(CommonWords,LineCount,Position,SearchKey,Result);
  124.     If Result>=0 then Exit;
  125.     Position := A+1;
  126.     ParseIn(KeyLine,Position,Found,IntValue);
  127.     end;
  128.     TARead(PointerFile,PointerRec,SearchKey,Exact);
  129.     If OK then
  130.         begin
  131.         K := 1;
  132.         Empty := True;
  133.         with PointerRec do
  134.         begin
  135.       while Empty do
  136.         begin
  137.         If PtrArray[K] = 0 then
  138.         begin
  139.         If PtrArray[Pred(K)]<>IntValue then PtrArray[K] := IntValue
  140.       else Exit;
  141.         Empty := False;
  142.         end
  143.         else K := K + 1;
  144.         If K = 200 then exit;
  145.         end;
  146.         end;
  147.         TAUpdate(PointerFile,PointerRec,SearchKey);
  148.         Exit;
  149.       end
  150.         else
  151.         begin
  152.         with PointerRec do
  153.         begin
  154.         For X:= 1 to 200 do
  155.         PtrArray[X] := 0;
  156.       IndexWord := SearchKey;
  157.         PtrArray[1] := IntValue;
  158.         end;
  159.         TAInsert(PointerFile,PointerRec,PointerRec.IndexWord);
  160.         end;
  161. end;
  162.  
  163.  
  164. Var
  165.     Loop : Integer;
  166.  
  167. begin
  168. ClrScr;
  169. InitWindow(0,True);
  170. MakeWindow(17,1,8,80,White+RedBG,White+RedBG,DoubleBrdr,Window30);
  171. gotoxy(2,3);
  172. write('                             ANSWERS ! Version 4.0');
  173. gotoxy(2,4);
  174. write('                           Copyright 1988 Brian Corll');
  175. gotoxy(2,5);
  176. write('                               All Rights Reserved');
  177. MakeWindow(10,11,5,62,White+BlueBG,White+BlueBG,DoubleBrdr,Window3);
  178. QWrite(12,26,White+BlueBG,'Loading Vocabulary of Common Words');
  179. Per := Pos('.',ParamStr(1));
  180. If Per>0 then
  181.     FileName := Copy(ParamStr(1),1,Per-1)
  182. else
  183.     FileName := ParamStr(1);
  184.     Assign(SortFile,FileName+'.srt');
  185.     Reset(SortFile);
  186.    Assign(CommonFile,'common.wds');
  187.     Reset(CommonFile);
  188.     I := 1;
  189.     while not eof(CommonFile) do
  190.     begin
  191.    Readln(CommonFile,Line);
  192.     CommonWords[I] := PadR(Line,6);
  193.     I := I + 1;
  194.     end;
  195.     Close(CommonFile);
  196.     Delay(2000);
  197.     LineCount := I;
  198.     I := 1;
  199.     RemoveWindow;
  200.     SetWindowModes(ZoomMode);
  201.    MakeWindow(10,11,5,62,Black+LightGrayBG,Black+LightGrayBG,DoubleBrdr,Window3);
  202.     gotoxy(2,1);
  203.     write('               Creating Index and Pointer Files.');
  204.     gotoxy(2,2);
  205.     write('               Processing Word Number ');
  206.     TACreate(PointerFile,FileName+'.ptr',SizeOf(PointerRec),FileName+'.ndx',SizeOf(IndexType)-1);
  207.     while not eof(SortFile) do
  208.     begin
  209.       gotoxy(41,2);
  210.         write(I);
  211.         Seek(SortFile,I-1);
  212.         Read(SortFile,SortRec);
  213.       AddPointer;
  214.         I := I + 1;
  215.    end;
  216.     TAClose(PointerFile);
  217.     Close(SortFile);
  218. end;
  219.  
  220.  
  221. END.
  222.  
  223.  
  224.