home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / pci040vk.zip / chkpci.pas < prev    next >
Pascal/Delphi Source File  |  2000-07-28  |  7KB  |  323 lines

  1. (*&Use32+*)
  2. (*&Delphi-*)
  3. (*&AlignCode+*)
  4. (*&AlignData+*)
  5. (*&AlignRec-*)
  6. (*&Optimize+*)
  7. program chkpci;
  8.  
  9.  
  10. uses
  11.   (*$IFDEF VirtualPascal*)
  12.   VPutils,
  13.   (*$ELSE*)
  14.   newdelay,
  15.   (*$ENDIF*)
  16.   crt;
  17.  
  18.  
  19.  
  20. {
  21.  
  22. Totals up and displays statistics on all data
  23.  
  24. Checks PCIDEVS.TXT for the following errors:
  25.  
  26. Unrecognised lines
  27.  
  28. Bad formatting of V, D, O, S, R, X entries;
  29.  - formatting tab character(s) missing
  30.  - ID digits wrong case or out of range
  31.  - description at least 2 characters long
  32.  
  33. Wrong numeric ordering of V, D, O, S, R entries
  34.  
  35. Duplicates of V, D, O, S, R entries
  36.  
  37.  
  38. }
  39.  
  40.  
  41.  
  42.  
  43. var
  44.   fi    : text;
  45.   fs    : file of byte;
  46.  
  47.   s     : string;
  48.  
  49.  
  50.  
  51.   size,
  52.  
  53.   cvt,
  54.   cven,
  55.   cdev,
  56.   coem,
  57.   csub,
  58.   crev,
  59.  
  60.   comment,
  61.   blank,
  62.   ven,
  63.   dev,
  64.   OEM,
  65.   Sub,
  66.   rev   : longint;
  67.  
  68.  
  69.   junk,
  70.   x,
  71.   p,
  72.   i     : integer;
  73.  
  74.   t,
  75.   f     : boolean;
  76.  
  77.  
  78.  
  79.  
  80. function valdigits(d:string) : boolean;
  81. begin
  82.   p:=0;
  83.  
  84.   for i:=1 to length(d) do
  85.   begin
  86.     if (ord(d[i])>=ord('0')) and ((ord(d[i])<=ord('9'))) then inc(p);
  87.     if (ord(d[i])>=ord('A')) and ((ord(d[i])<=ord('F'))) then inc(p);
  88.   end;
  89.  
  90.  
  91.   if p=length(d) then valdigits:=false else valdigits:=true;
  92.  
  93. end;
  94.  
  95.  
  96. function cvtb(b:byte) : byte;
  97. begin
  98.   if b>9 then cvtb:=b+ord('A')-10 else cvtb:=b+ord('0');
  99. end;
  100.  
  101. function wrhexw(wor:word): string;
  102. begin
  103.   wrhexw:=chr(cvtb(wor shr 12))+chr(cvtb((wor shr 8) and $f))+chr(cvtb((wor shr 4) and $f))+chr(cvtb(wor and $f));
  104. end;
  105.  
  106.  
  107. (*$IFDEF VirtualPascal*)
  108. function IORedirected : boolean ;
  109.   begin
  110.     IORedirected:=not VPUtils.IsFileHandleConsole(SysFileStdOut);
  111.   end;
  112. (*$ELSE*)
  113. function IORedirected : boolean ; Assembler;
  114. asm
  115.   push ds
  116.   mov ax,prefixseg
  117.   mov ds,ax
  118.   xor bx,bx
  119.   les bx,[bx + $34]
  120.   mov al,es:[bx]
  121.   mov ah,es:[bx +1]
  122.   pop ds
  123.   cmp al,ah
  124.   mov al,true
  125.   jne @exit
  126.  
  127.   mov al,false
  128.  
  129.  @exit:
  130. end;
  131. (*$ENDIF*)
  132.  
  133.  
  134.  
  135. begin
  136.   if ioredirected then
  137.   begin
  138.     assign(output,'');
  139.     rewrite(output);
  140.   end else clrscr;
  141.  
  142.   writeln('CHKPCI Version 0.02ß');
  143.   writeln;
  144.  
  145.   assign(fi,'PCIDEVS.TXT');
  146.   reset(fi);
  147.   assign(fs,'PCIDEVS.TXT');
  148.   reset(fs);
  149.   size:=filesize(fs);
  150.   close(fs);
  151.  
  152.   writeln('PCIDEVS.TXT   : ',size/1024:5:1,'Kb');
  153.   writeln;
  154.  
  155.  
  156.   comment:=0;
  157.   blank:=0;
  158.   ven:=0;
  159.   dev:=0;
  160.   oem:=0;
  161.   sub:=0;
  162.   rev:=0;
  163.   x:=0;
  164.  
  165.  
  166.   cven:=-1;
  167.   cdev:=-1;
  168.   coem:=-1;
  169.   csub:=-1;
  170.   crev:=-1;
  171.  
  172.  
  173.   while not eof(fi) do
  174.   begin
  175.     readln(fi,s);
  176.     t:=false;
  177.  
  178.     if length(s)=0 then
  179.     begin
  180.       inc(blank);
  181.       t:=true;
  182.     end;
  183.  
  184.     if not t then if s[1]=';' then
  185.     begin
  186.       inc(comment);
  187.       t:=true;
  188.     end;
  189.  
  190.     if not t then if s[1]='V' then
  191.     begin
  192.       f:=false;
  193.       if s[2]<>#9 then f:=true;
  194.       if s[7]<>#9 then f:=true;
  195.       if valdigits(copy(s,3,4)) then f:=true;
  196.       if f then writeln('Vendor Entry Error : ',copy(s,1,52));
  197.       t:=true;
  198.       inc(ven);
  199.  
  200.       val(('$'+copy(s,3,4)),cvt,junk);
  201.       if cvt<cven then writeln('VENDOR ',copy(s,3,4),' out of order');
  202.       if cvt=cven then writeln('VENDOR ',copy(s,3,4),' duplicated');
  203.  
  204.       cven:=cvt;
  205.       cdev:=-1;
  206.  
  207.     end;
  208.  
  209.     if not t then if s[1]='D' then
  210.     begin
  211.       f:=false;
  212.       if length(s)<8 then f:=true;
  213.       if s[2]<>#9 then f:=true;
  214.       if s[7]<>#9 then f:=true;
  215.       if valdigits(copy(s,3,4)) then f:=true;
  216.       if f then writeln('Device Entry Error : ',copy(s,1,52));
  217.       t:=true;
  218.       inc(dev);
  219.  
  220.       val(('$'+copy(s,3,4)),cvt,junk);
  221.       if cvt<cdev then writeln('DEVICE ',copy(s,3,4),', (Vendor ',wrhexw(cven),') out of order');
  222.       if cvt=cdev then writeln('DEVICE ',copy(s,3,4),', (Vendor ',wrhexw(cven),') duplicated');
  223.       cdev:=cvt;
  224.       coem:=-1;
  225.       crev:=-1;
  226.     end;
  227.  
  228.  
  229.     if not t then if s[1]='O' then
  230.     begin
  231.       f:=false;
  232.       if length(s)<8 then f:=true;
  233.       if s[2]<>#9 then f:=true;
  234.       if s[7]<>#9 then f:=true;
  235.       if valdigits(copy(s,3,4)) then f:=true;
  236.       if f then writeln('OEM Entry Error    : ',copy(s,1,52));
  237.       t:=true;
  238.       inc(oem);
  239.  
  240.       val(('$'+copy(s,3,4)),cvt,junk);
  241.       if cvt<coem then writeln('OEM ',copy(s,3,4),' (Device ',wrhexw(cdev),', Vendor ',wrhexw(cven),') out of order');
  242.       if cvt=coem then writeln('OEM ',copy(s,3,4),' (Device ',wrhexw(cdev),', Vendor ',wrhexw(cven),') duplicated');
  243.       coem:=cvt;
  244.       csub:=-1;
  245.     end;
  246.  
  247.     if not t then if s[1]='S' then
  248.     begin
  249.       f:=false;
  250.       if length(s)<8 then f:=true;
  251.       if s[2]<>#9 then f:=true;
  252.       if s[7]<>#9 then f:=true;
  253.       if valdigits(copy(s,3,4)) then f:=true;
  254.       if f then writeln('Subsys Entry Error : ',copy(s,1,52));
  255.       t:=true;
  256.       inc(sub);
  257.  
  258.       val(('$'+copy(s,3,4)),cvt,junk);
  259.       if cvt<csub then writeln('SUBSYS ',copy(s,3,4)
  260.         ,' (OEM ',wrhexw(coem),' Device ',wrhexw(cdev),', Vendor ',wrhexw(cven),') out of order');
  261.       if cvt=csub then writeln('SUBSYS ',copy(s,3,4)
  262.         ,' (OEM ',wrhexw(coem),' Device ',wrhexw(cdev),', Vendor ',wrhexw(cven),') duplicated');
  263.       csub:=cvt;
  264.     end;
  265.  
  266.     if not t then if s[1]='R' then
  267.     begin
  268.       f:=false;
  269.       if length(s)<6 then f:=true;
  270.       if s[2]<>#9 then f:=true;
  271.       if s[5]<>#9 then f:=true;
  272.       if valdigits(copy(s,3,2)) then f:=true;
  273.       if f then writeln('Rev Entry Error    : ',copy(s,1,52));
  274.       t:=true;
  275.       inc(rev);
  276.  
  277.       val(('$'+copy(s,3,2)),cvt,junk);
  278.       if cvt<crev then writeln('REV ',copy(s,3,2),' (SUBSYS ',wrhexw(csub),' OEM ',wrhexw(coem)
  279.         ,' Device ',wrhexw(cdev),', Vendor ',wrhexw(cven),') out of order');
  280.       if cvt=crev then writeln('REV ',copy(s,3,2),' (SUBSYS ',wrhexw(csub),' OEM ',wrhexw(coem)
  281.         ,' Device ',wrhexw(cdev),', Vendor ',wrhexw(cven),') duplicated');
  282.       crev:=cvt;
  283.  
  284.     end;
  285.  
  286.     if not t then if s[1]='X' then
  287.     begin
  288.       f:=false;
  289.       if length(s)<12 then f:=true;
  290.       if s[2]<>#9 then f:=true;
  291.       if s[11]<>#9 then f:=true;
  292.       if valdigits(copy(s,3,8)) then f:=true;
  293.       if f then writeln('X Entry Error      : ',copy(s,1,52));
  294.       t:=true;
  295.       inc(x);
  296.  
  297.     end;
  298.  
  299.  
  300.  
  301.  
  302.     if t=false then writeln('Unknown line   : ',copy(s,1,52));
  303.  
  304.   end;
  305.   close(fi);
  306.  
  307.  
  308.   writeln;
  309.   writeln('Found and checked ',ven+dev+oem+sub+rev+x,' entries');
  310.   writeln;
  311.   writeln('Vendors       : ',ven);
  312.   writeln('Devices       : ',dev);
  313.   writeln('OEM IDs       : ',oem);
  314.   writeln('Subsystem IDs : ',sub);
  315.   writeln('Revision IDs  : ',rev);
  316.   writeln('X Codes       : ',x);
  317.   writeln;
  318.   writeln('Comment Lines : ',comment);
  319.   writeln('Blank Lines   : ',blank);
  320.  
  321. end.
  322.  
  323.