home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ECO30603.ZIP / ECO30603.LZH / ECOLIBBS / eco_node.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-09  |  8.5 KB  |  287 lines

  1. (*
  2.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  3.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  6.     ▓▓▓▓▓▓▓▓·──                                              ──·▓▓▓▓▓▓▓▓▓▓▓
  7.     ▓▓▓▓▓▓▓▓│                                                  │░░▓▓▓▓▓▓▓▓▓
  8.     ▓▓▓▓▓▓▓▓   EFTPNODE was Conceived, Designed and Written     ░░▓▓▓▓▓▓▓▓▓
  9.     ▓▓▓▓▓▓▓▓   by Floor A.C. Naaijkens for                      ░░▓▓▓▓▓▓▓▓▓
  10.     ▓▓▓▓▓▓▓▓   UltiHouse Software / The ECO Group.              ░░▓▓▓▓▓▓▓▓▓
  11.     ▓▓▓▓▓▓▓▓                                                    ░░▓▓▓▓▓▓▓▓▓
  12.     ▓▓▓▓▓▓▓▓   (C) MCMXCII by EUROCON PANATIONAL CORPORATION.   ░░▓▓▓▓▓▓▓▓▓
  13.     ▓▓▓▓▓▓▓▓   All Rights Reserved for The ECO Group.           ░░▓▓▓▓▓▓▓▓▓
  14.     ▓▓▓▓▓▓▓▓                                                    ░░▓▓▓▓▓▓▓▓▓
  15.     ▓▓▓▓▓▓▓▓   Accesses the 1Mb+ nodelist quickly, without      ░░▓▓▓▓▓▓▓▓▓
  16.     ▓▓▓▓▓▓▓▓   building large indexes.                          ░░▓▓▓▓▓▓▓▓▓
  17.     ▓▓▓▓▓▓▓▓   (Optionally builds a small index, not needed)    ░░▓▓▓▓▓▓▓▓▓
  18.     ▓▓▓▓▓▓▓▓│                                                  │░░▓▓▓▓▓▓▓▓▓
  19.     ▓▓▓▓▓▓▓▓·──                                              ──·░░▓▓▓▓▓▓▓▓▓
  20.     ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓
  21.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  22.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  23.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  24. *)
  25. {$A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}
  26. {$M 65520, 0, 655360}
  27.  
  28. unit eco_node;
  29.  
  30. interface
  31. uses
  32.   crt, dos, eco_lib
  33.  
  34.   ;
  35.  
  36.  
  37.  
  38. const
  39.   maxnets = 500;
  40.  
  41.  
  42. type
  43.   tbuf = array[1..49152] of char;
  44.   indextype = array[1..6, 1..maxnets] of record net: word; line: word end;
  45.  
  46.   nodelistobj = object { data must not be altered directly }
  47.     idx       :    boolean;
  48.     oindex,
  49.     onodel    :     string;
  50.     bin       :      ^tbuf;
  51.     path      :     string;
  52.     tin       :       text;
  53.     this,
  54.     thissize  :    longint;
  55.   
  56.     indexes   :  indextype;
  57.     curzone   :       word;
  58.     indexfile : file of indextype;
  59.     curzones  : array[1..6] of word;
  60.   
  61.     { ========== externals =========== }
  62.     function  init(nodelist: string; compile: boolean): boolean;
  63.     function  getnode(st: string): string;
  64.     procedure done(removeindex: boolean);
  65.     { ========== internals =========== }
  66.     function  cvtnode(s: string): string;
  67.     function  getline(l: integer): string; { nice for overrides }
  68.     procedure compilenodes;
  69.     function  seektextpos(z, n: word): boolean;
  70.   end;
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. implementation
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.   procedure __expandnum(
  91.     node : string; var tozone, tonet, tonode, topoint: word
  92.   );
  93.   var                      { zzzzz:nnnnn/nnnnn.ppppp }
  94.     i, j : byte;           { eg.  '12:5003/1222.000' }
  95.  
  96.   begin
  97.     i := pos(':', node);
  98.     tozone := __str(copy(node, 1, i - 1));
  99.     j := pos('/', node); if j=0 then j := pos('\', node);
  100.     tonet  := __str(copy(node, i + 1, j - i - 1));
  101.     i := pos('.', node);
  102.     if i > 0 then tonode := __str(copy(node, j+1, i-j-1)) else
  103.       tonode := __str(copy(node, j+1, length(node)-j));
  104.     topoint := __str(copy(node, i + 1, length(node) - i));
  105.   end; { __expandnum }
  106.  
  107.  
  108.  
  109.   function __extractpath(s : string): string; { eindigt op \ }
  110.   var i : byte;
  111.   begin
  112.     i := length(s); while (s[i] <> '\') and (i > 1) do dec(i);
  113.     __extractpath := copy(s, 1, i);
  114.   end;
  115.  
  116.  
  117.  
  118.  
  119. const
  120.   dontcare  = -1;
  121.   untouched =  0;
  122.  
  123.  
  124.   function nodelistobj.getline(l: integer): string;
  125.   var stt: string;
  126.   begin
  127.     readln(tin, stt);
  128.     inc(this); inc(thissize, length(stt)+2);
  129.     if l = untouched then getline := stt else
  130.       if l > untouched then getline := __up(copy(stt, 1, l)) else
  131.         getline := '';
  132.   end;
  133.  
  134.  
  135.  
  136.   procedure nodelistobj.compilenodes;
  137.   var
  138.     seconds,
  139.     nodes, i :   word;
  140.     stt      : string;
  141.  
  142.   begin
  143.     nodes := 0;
  144.     if wherey > 20 then begin for i := 1 to 4 do writeln; gotoxy(1, 20) end;
  145.     writeln('  AMERICA  EUROPA   OCEANIA   LATINA   AFRICA    ASIA');
  146.     gotoxy(1, wherey+2); write('  Nodes/sec: '); gotoxy(1, wherey-2);
  147.     starttimer(1);
  148.     while not(eof(tin)) do begin
  149.       readln(tin, stt); inc(this); stt := __up(stt);
  150.       if (copy(stt, 1, 5) = 'ZONE,') then begin
  151.         curzone := __str(copy(stt, 6, 1)); inc(nodes);
  152.       end else if (copy(stt, 1, 5) = 'HOST,') then begin
  153.         inc(curzones[curzone]); inc(nodes);
  154.         stt := copy(stt, 6, 6);
  155.         with indexes[curzone, curzones[curzone]] do begin
  156.           net := __str(copy(stt, 1, pos(',', stt)-1));
  157.           line := this;
  158.         end;
  159.         if nodes mod 7 = 0 then begin
  160.           gotoxy(1, wherey);
  161.           write(
  162.             curzones[1]:7, '  ', curzones[2]:7, '  ', curzones[3]:7, '  ',
  163.             curzones[4]:7, '  ', curzones[5]:7, '  ', curzones[6]:7 
  164.           );
  165.           gotoxy(14, wherey+2);
  166.           stt := getlaptime(1);
  167.           seconds := __str(copy(stt, 7, 2));
  168.           seconds := seconds + 60 * __str(copy(stt, 4, 2));
  169.           if seconds > 0 then write(trunc(nodes/seconds), '  ');
  170.           gotoxy(14, wherey-2);
  171.         end;
  172.       end else if not(
  173.         (stt[1] = ';') or (copy(stt, 1, 5) = 'HOLD,') or 
  174.         (copy(stt, 1, 5) = 'DOWN,') or (copy(stt, 1, 7) = 'REGION,')
  175.       ) then inc(nodes);
  176.     end;
  177.     stt := stoptimer(1);
  178.     assign(indexfile, oindex); rewrite(indexfile);
  179.     write(indexfile, indexes); close(indexfile);
  180.     gotoxy(1, wherey);
  181.     write(
  182.       curzones[1]:7, '  ', curzones[2]:7, '  ', curzones[3]:7, '  ',
  183.       curzones[4]:7, '  ', curzones[5]:7, '  ', curzones[6]:7 
  184.     );
  185.     writeln; writeln;
  186.     seconds := __str(copy(stt, 7, 2));
  187.     seconds := seconds + 60 * __str(copy(stt, 4, 2));
  188.     writeln(
  189.       'Compiled ', stt, '  ',
  190.       trunc(nodes/seconds), ' nodes/second.', '  ',
  191.       nodes, ' nodes, ',
  192.       curzones[1]+curzones[2]+curzones[3]+curzones[4]+curzones[5]+curzones[6],
  193.       ' nets total.'
  194.     );
  195.   end;
  196.  
  197.  
  198.  
  199.   function nodelistobj.seektextpos(z, n: word): boolean;
  200.   var i, j, lin : word;
  201.   begin
  202.     if idx then begin
  203.       i := 1; lin := 0;
  204.       while (i < maxnets+1) and (indexes[z, i].net <> n) do inc(i);
  205.       if i < maxnets+1 then begin
  206.         lin := indexes[z, i].line;
  207.         for j := 1 to lin do getline(dontcare);
  208.         seektextpos := true;
  209.       end else seektextpos := false;
  210.     end else seektextpos := false;
  211.   end;
  212.  
  213.  
  214.  
  215.  
  216.   function nodelistobj.cvtnode(s: string): string;
  217.   var i : byte;
  218.   begin
  219.     for i := 1 to length(s) do if s[i] = '_' then s[i] := ' ';
  220.     cvtnode := s;
  221.   end;
  222.  
  223.  
  224.  
  225.   function nodelistobj.getnode(st: string): string;
  226.   var zone, net, node, topoint: word;
  227.   begin
  228.     this := 0; thissize := 0; curzone := 2; reset(tin);
  229.     __expandnum(st, zone, net, node, topoint);
  230.     if not(seektextpos(zone, net)) then begin
  231.       st := '';
  232.       while (
  233.         not(eof(tin)) and
  234.         (pos('ZONE,' + __num(zone) + ',', st) = 0)
  235.       ) do st := getline(10);
  236.       st := '';
  237.       while (
  238.         not(eof(tin)) and
  239.         (pos('HOST,'+__num(net), st) = 0)
  240.       ) do st := getline(10);
  241.     end;
  242.     st := '';
  243.     while (
  244.       not(
  245.         eof(tin) or (copy(st, 1, 5) = 'ZONE,') or (copy(st, 1, 5) = 'HOST,')
  246.       ) and
  247.       (pos(',' + __num(node) + ',', st) = 0)
  248.     ) do st := getline(untouched);
  249.     if not(
  250.       eof(tin) or (copy(st, 1, 5) = 'ZONE,') or (copy(st, 1, 5) = 'HOST,')
  251.     ) then getnode := cvtnode(st) else getnode := '';
  252.   end;
  253.  
  254.  
  255.  
  256.   function nodelistobj.init(nodelist: string; compile: boolean): boolean;
  257.   var i : word;
  258.   begin
  259.     onodel := nodelist;
  260.     init := __existfil(nodelist);
  261.     new(bin);
  262.     assign(tin, onodel); reset(tin); settextbuf(tin, bin^);
  263.     this := 0; thissize := 0; curzone := 2;
  264.     fillchar(indexes, sizeof(indexes), 0);
  265.     for i := 1 to 6 do curzones[i] := 0;
  266.     oindex := __normfil(__backapp(__extractpath(paramstr(0))) + 'EFTPNODE.IDX');
  267.     if compile then writeln('Index: ', __slashfil(oindex));
  268.     idx := false;
  269.     if compile then compilenodes;
  270.     if __existfil(oindex) then begin
  271.       assign(indexfile, oindex); reset(indexfile);
  272.       read(indexfile, indexes); close(indexfile); idx := true;
  273.     end;
  274.   end;
  275.  
  276.  
  277.  
  278.   procedure nodelistobj.done(removeindex: boolean);
  279.   begin
  280.     dispose(bin); if removeindex then erase(indexfile)
  281.   end;
  282.  
  283.  
  284.  
  285.  
  286. {happy}end.{unit}
  287.