home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DPSX / TOOL-PAS.ZIP / IXTEST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-05-17  |  1.5 KB  |  78 lines

  1.  
  2. {$m 10000,0,0}
  3.  
  4. uses mdosio,bindex;
  5.  
  6. const
  7.    recs = 100;
  8.  
  9.  
  10. function generate_string: string;
  11. var
  12.    s: string;
  13.    i: integer;
  14.    l: integer;
  15. begin
  16.    l := 20 {random(10)+10};
  17.    s := '';
  18.    for i := 1 to l do
  19.       s := s + chr(random(10)+ord('0'));
  20.    generate_string := s;
  21. end;
  22.  
  23. var
  24.    ix:      bindex_handle;
  25.    fd:      dos_handle;
  26.    key:     string;
  27.    keylen:  byte;
  28.    fpos:    longint;
  29.    i,n:     integer;
  30.    crlf:    array[1..2] of char;
  31.  
  32. begin
  33.    crlf := ^M^J;
  34.    randomize;
  35.  
  36.    writeln('Create index');
  37.    ix.hdr.keysize := 23;
  38.    ix.hdr.keytype := StringKey;
  39.    CreateIndex(ix,'TEST.IX');
  40.  
  41.    OpenIndex(ix,'TEST.IX');
  42.    fd := dos_create('TEST.DAT');
  43.    for i := 1 to recs do
  44.    begin
  45.       key := generate_string;
  46.       writeln('   ',key);
  47.  
  48.       dos_lseek(fd,0,seek_cur);
  49.       fillchar(ix.rec,sizeof(ix.rec),0);
  50.       ix.rec.fpos := dos_tell;
  51.       ix.rec.fid := 0;
  52.       ix.rec.key := key;
  53.       AddKey(ix);
  54.  
  55.       dos_write(fd,key,length(key)+1);
  56.       dos_write(fd,crlf,sizeof(crlf));
  57.    end;
  58.    dos_close(fd);
  59.    CloseIndex(ix);
  60.  
  61.    writeln('Read index');
  62.    OpenIndex(ix,'TEST.IX');
  63.    fd := dos_open('TEST.DAT',open_read);
  64.    ix.match := '';
  65.    FindKey(ix);
  66.    while ix.ixpos <> indexNotFound do
  67.    begin
  68.       dos_lseek(fd,ix.rec.fpos,seek_start);
  69.       n := dos_read(fd,key[0],1);
  70.       n := dos_read(fd,key[1],length(key));
  71.       writeln('  found [',key,']');
  72.       FindNext(ix);
  73.    end;
  74.    dos_close(fd);
  75.    CloseIndex(ix);
  76. end.
  77.  
  78.