CHKIND.MOD 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. IMPLEMENTATION MODULE ChkInd;
  2. (*
  3. * ModBase
  4. * Release 3.0
  5. * By Don Fletcher & John McMonagle
  6. * (c) Copyright 1986 - 1991 PMI
  7. * P.O. Box 8402
  8. * Green Bay Wi 53308
  9. * All Rights Reserved
  10. *
  11. *)
  12. FROM DBIndxes IMPORT
  13. FindPositionCh, OpenIndex, BuildIndex, DBIndex, NextRecord, PrevRecord,
  14. CurrentRec,CurrentKeyCh,GoTop;
  15. FROM StrConv IMPORT
  16. CardinalToStr;
  17. FROM StringIO IMPORT
  18. ReadStr, WriteStr, WriteEol;
  19. FROM M2Strings IMPORT
  20. Assign, CompareStr,Concat;
  21. FROM BigSets IMPORT InitSet,InSet,InclSet;
  22. FROM Storage IMPORT ALLOCATE, DEALLOCATE;
  23. CONST
  24. inp = 0;
  25. outp = 1;
  26. prn = 4;
  27. stderror = 2;
  28. PROCEDURE NDXChk(VAR ndx:DBIndex);
  29. VAR
  30. LastKey,KeyStr : ARRAY[ 0 .. 127 ] OF CHAR;
  31. str,string :ARRAY[0..79] OF CHAR;
  32. cardrec, Keys :CARDINAL;
  33. CurRec : LONGINT;
  34. ok,
  35. error,
  36. dumbool : BOOLEAN;
  37. set : POINTER TO ARRAY[0..4095] OF BITSET;
  38. BEGIN
  39. NEW( set);
  40. error:=FALSE;
  41. Keys:=1;
  42. InitSet(set^);
  43. GoTop( ndx );
  44. InclSet(set^,VAL(CARDINAL,CurrentRec(ndx)));
  45. CurrentKeyCh( ndx, LastKey );
  46. WHILE NextRecord( ndx, CurRec ) DO
  47. cardrec:=VAL(CARDINAL,CurRec);
  48. CurrentKeyCh(ndx,KeyStr);
  49. IF InSet(set^,cardrec)
  50. THEN
  51. error:=TRUE;
  52. Concat('duplicate entry for ',KeyStr,str);
  53. Concat(str,' record number ',str);
  54. CardinalToStr(cardrec,1,string);
  55. Concat(str,string,str);
  56. WriteEol(prn,str);
  57. HALT;
  58. ELSE
  59. InclSet(set^,cardrec);
  60. END;
  61. INC(Keys);
  62. IF CompareStr( LastKey, KeyStr ) > 0
  63. THEN
  64. WriteEol(prn,'sort error in index');
  65. error:=TRUE;
  66. HALT;
  67. END (* if *);
  68. Assign( KeyStr, LastKey );
  69. END (* while *);
  70. FOR cardrec:=1 TO Keys DO
  71. IF NOT InSet(set^,cardrec)
  72. THEN
  73. CardinalToStr(cardrec,1,string);
  74. Concat('record number not in index ',string,str);
  75. WriteEol(prn,str);
  76. HALT;
  77. END;
  78. END (* for *);
  79. IF error
  80. THEN
  81. CardinalToStr(Keys,8,LastKey);
  82. WriteStr( prn, LastKey );
  83. WriteEol( prn ,' keys found.');
  84. WriteEol( prn, 'SORTING ERRORS FOUND');
  85. END;
  86. DISPOSE(set);
  87. END NDXChk;
  88. END ChkInd.