home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / xphy2201.arj / XPHYDRA.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-28  |  10.3 KB  |  447 lines

  1. { Version 2.201, letzte Änderung am 6.08.96 }
  2.  
  3. {$A+,B-,D-,E-,F-,G+,I+,L+,N-,O-,R-,S-,V-,X+}
  4. {$M 16384,0,0}
  5.  
  6. program xphydra;
  7.  
  8. uses
  9.   dos, crt, xphytool, utimestr, ulog, extract;
  10.  
  11. const
  12.   hauptversion = '2';
  13.   unterversion = '201';
  14.   alphastatus = ' BETA';
  15.   releasedate = '6.08.96';
  16.   version = hauptversion+'.'+unterversion+alphastatus;
  17. {  line    : word=14400;}
  18.   hydpath : pathstr='hydracom.exe';
  19.   ports   : array[1..4] of string[3]=('3F8','2F8','3E8','2E8');
  20.   mailext : array[1..7] of string[2]=('MO','TU','WE','TH','FR','SA','SU');
  21.   prgpath : pathstr='\';
  22.   logpath : pathstr='\';
  23.  
  24. var
  25.   lastioresult:integer;
  26.  
  27. type
  28.   tprogram = object
  29.  
  30.              screen    : array[1..25,1..80] of word;
  31.              vseg      : word;
  32.              sending   : boolean;
  33.              reqfile   : string[12];
  34.              hydraparams : string[128];
  35.              parpath   : string[12];
  36.              spoolpath : pathstr;
  37.              filespath : pathstr;
  38.              exitcode  : word;
  39.              hydraexitcode: word;
  40.  
  41.              procedure init;
  42.              procedure run;
  43.              procedure done;
  44.  
  45.              procedure savescreen;
  46.              procedure restorescreen;
  47.              procedure convertparameters;
  48.              procedure convertparfile;
  49.              procedure convertlogfile;
  50.              procedure endemeldung;
  51.  
  52.             end;
  53.  
  54.  
  55. procedure tprogram.init;
  56.  
  57. begin
  58.   if (paramcount=0) or (pos('?',paramstr(1))>0) then
  59.   begin
  60.     writeln;
  61.     writeln('XPHydra v'+version+', released '+releasedate+', Copyright '+#39+'95,96 by Jonas v. Poser');
  62.     writeln('XPHydra was designed by Jonas v. Poser, Matthias Eube and Andreas Mutter');
  63.     writeln;
  64.     halt;
  65.   end;
  66.   savescreen;
  67.   window(1,4,80,22);
  68.   clrscr;
  69.   if not exist(hydpath) then hydpath:=back(getenv('xphydra'))+'hydracom.exe';
  70.   prgpath:=getprgpath;
  71.   logpath:=getlogpath('LOGDIR','xpoint.cfg');
  72.   slogfile:=logpath+'xphydra.log';
  73.   sprompt:='[XPHydra] ';
  74.   log('Path to XPHydra version '+version+': '+prgpath);
  75.   writeln('Logfile:'+slogfile);
  76.   convertparameters;
  77.   convertparfile;
  78.   if sending then hydraparams:=hydraparams+' rec hydtemp\ sen '+reqfile
  79.              else hydraparams:=hydraparams+' rec hydtemp\ sen @xphydra.par';
  80.   if sending then log('Starting mailer session batch #1')
  81.              else log('Starting mailer session batch #2');
  82. end;
  83.  
  84.  
  85. procedure tprogram.run;
  86.  
  87. begin
  88.   {$I-}
  89.   if sending and (not exist('HYDTEMP')) then mkdir('HYDTEMP');
  90.   lastioresult:=ioresult; {Die möglich Iofehler zurückzusetzen}
  91.   {$I+}
  92.   if not exist(hydpath) then
  93.     begin
  94.       log('Error: '+hydpath+' not found.');
  95.       exitcode:=13;
  96.       endemeldung;
  97.       halt(exitcode);
  98.     end;
  99.   clrscr;
  100.   writeln;
  101.   log('Executing: '+hydpath+' '+hydraparams);
  102.   swapvectors;
  103.   exec(hydpath,hydraparams);
  104.   hydraexitcode:=dosexitcode;
  105.   swapvectors;
  106.   log('Errorlevel: '+ fstr(hydraexitcode));
  107. end;
  108.  
  109.  
  110. procedure tprogram.done;
  111.  
  112. var
  113.   i:BYTE;
  114.   f:FILE;
  115.  
  116.  
  117. procedure movefiles(mask,pathfro,pathto:string;attr:word);
  118.  
  119. const
  120.   recoveryname='BAD-XFER';
  121.  
  122. label
  123.   next;
  124.  
  125. var
  126.   s   : searchrec;
  127.   f   : file;
  128.   test: string;
  129.  
  130. begin
  131.   findfirst(pathfro+mask,attr,s);
  132.   while doserror=0 do
  133.   begin
  134.     if pos(recoveryname,s.name)<>0 then goto next;
  135.     if exist(pathto+s.name) then
  136.     begin
  137.       assign(f,pathto+s.name);
  138.       test:=s.name;
  139.       test[length(s.name)]:='1';
  140.       while exist(pathto+test) do
  141.       begin
  142.         test[length(s.name)]:=chr(ord(test[length(s.name)])+1);
  143.         if test[length(s.name)] = #58 then test[length(s.name)]:='A';
  144.         if test[length(s.name)] > #90 then halt(99);
  145.       end;
  146.       rename(f,pathto+test);
  147.     end;
  148.   assign(f,pathfro+s.name);
  149.   rename(f,pathto+s.name);
  150.   next:
  151.   findnext(s);
  152.   end;
  153. end;  { of movefiles}
  154.  
  155. begin
  156.   convertlogfile;
  157.   if not sending then
  158.   begin
  159.     for i:=1 to 7 do
  160.     movefiles('*.'+mailext[i]+'?','HYDTEMP\',spoolpath,anyfile);
  161.     movefiles('*.PKT','HYDTEMP\',spoolpath,anyFile);
  162.     movefiles('*.*','HYDTEMP\',filespath, anyfile and not (directory or volumeid) );
  163.     {$I-}
  164.     rmdir('HydTemp');
  165.     {$I+}
  166.     lastioresult:=ioresult; {Und weg mit eventuellen Fehlermelungen}
  167.     assign(f,'xphydra.par');
  168.     erase(f);
  169.   end;
  170.   case hydraexitcode of
  171.      0   : exitcode:=0;
  172.      1   : exitcode:=1;
  173.      255 : exitcode:=1;
  174.   end;
  175.   if exitcode <> 0 then
  176.   begin
  177.     endemeldung;
  178.     halt(exitcode);
  179.   end;
  180.   endemeldung;
  181. end; { of tprogram.done}
  182.  
  183.  
  184. procedure tprogram.savescreen;
  185.  
  186. var
  187.   bios:word absolute $0040:$0063;
  188.  
  189. begin
  190.   if bios=$3B4 then vseg:=$B000
  191.                else vseg:=$B800;
  192.   move(ptr(vseg,0)^,screen,25*80*2);
  193. end;
  194.  
  195.  
  196. procedure tprogram.restorescreen;
  197.  
  198. begin
  199.   move(screen,ptr(vseg,0)^,25*80*2);
  200. end;
  201.  
  202.  
  203. procedure tprogram.convertparameters;
  204.  
  205. var
  206.   i,o : byte;
  207.   pa,s: pathstr;
  208.  
  209. function token(s:string;x:byte):string;
  210.  
  211. var
  212.   i   : byte;
  213.   tmp : string;
  214.  
  215. begin
  216.   tmp:='';
  217.   i:=x;
  218.   while (s[i]<>' ') and (s[i]<>',') and (i<=Length(s)) do
  219.   begin
  220.     tmp:=tmp+s[i];
  221.     inc(i);
  222.   end;
  223.   token:=tmp;
  224. end; { of token }
  225.  
  226.  
  227. begin
  228.   hydraparams:='res xph~temp.log han hard';
  229.   for o:=1 to paramcount do
  230.   begin
  231.     pa:=paramstr(o);
  232.     if pa[1]='-' then
  233.       case pa[2] of
  234.         'c': begin
  235.                s:=token(pa,3);
  236.                i:=1;
  237.                if Length(s)>1
  238.                    then while (i<5) and (s<>ports[i]) do inc(i)
  239.                    else while (i<5) and (s<>fStr(i)) do inc(i);
  240.                if i=5 then i:=2;
  241.                hydraparams:=hydraparams+' por '+fstr(i);
  242.              end;
  243.         'k': begin
  244.                s:=token(pa,3);
  245.                hydraparams:=hydraparams+' lin '+s;
  246.              end;
  247.         'b': begin
  248.                s:=token(pa,3);
  249.                hydraparams:=hydraparams+' spe '+s;
  250.              end;
  251.         't': begin
  252.              if pa[3] ='l' then
  253.                begin
  254.                  s:=token(pa,4);
  255.                  hydraparams:=hydraparams+' fif '+s;
  256.                end;
  257.              end;
  258.       end else
  259.       case pa[1] of
  260.         'r': sending:=false;
  261.         's': sending:=true;
  262.         '@': parpath:=token(pa,2);
  263.       end; { of case }
  264.   end; { of for slope }
  265. end;
  266.  
  267.  
  268. procedure tprogram.convertparfile;
  269.  
  270. var
  271.   pt,ht : text;
  272.   s     : string;
  273.  
  274. begin
  275.   log('Converting parameter file: '+parpath);
  276.   assign(pt,parpath);
  277.   if not exist(parpath) then log('Error: '+parpath+' not found');
  278.   reset(pt);
  279.   if sending then
  280.   begin
  281.     assign(ht, 'xphydra.par');
  282.     rewrite(ht);
  283.     while not eof(pt) do
  284.     begin
  285.       readln(pt,s);
  286.       if (pos('.REQ', s)>0) and (s[1]<>';') and
  287.          (s[1]<>'-') and (pos('\',s)=0) then reqfile:=s
  288.                                         else reqfile:='';
  289.       if (s[1]<>';') and (s[1]<>'-') and ( (pos('.REQ',s)=0)) then
  290.       begin
  291.         if pos('\',s)=0 then s:=fexpand(s);
  292.         writeln(ht,s);
  293.       end else filespath:=s;
  294.     end;
  295.     close(ht);
  296.     close(pt);
  297.     end;
  298.  
  299.   if not sending then
  300.   begin
  301.     assign(pt,parpath);
  302.     reset(pt);
  303.     while not eof(pt) do
  304.     begin
  305.       readln(pt,s);
  306.       if (s[1]<>';') and (s[1]<>'-') and ( pos('.REQ',s)=0 ) and
  307.          (pos('\',s) > 0) then filespath:=s;
  308.       if (pos('-fm:',s)>0) then
  309.       spoolpath:=copy(s,5,length(s)-4);
  310.       if (pos('-fmx:',s)>0) then
  311.       spoolpath:=copy(s,6,length(s)-5);
  312.     end;
  313.     close(pt);
  314.   end;
  315. end;
  316.  
  317.  
  318. procedure tprogram.convertlogfile;
  319.  
  320. var
  321.   pLog,hLog,tLog:text;
  322.   filename,s,ps,temp:string;
  323.   bytes:longint;
  324.   cps, error, secs: integer;
  325.  
  326.  
  327. function part(s:string;x:byte):string;
  328. var
  329.   i,o,p: byte;
  330.   t    : string;
  331.  
  332. begin
  333.   i:=1;
  334.   while s[i]=' ' do inc(i);
  335.   for o:=1 to x-1 do
  336.   begin
  337.     while s[i]<>' ' do inc(i);
  338.     while s[i]=' ' do inc(i);
  339.   end;
  340.   p:=i+1;
  341.   if p>length(s) then
  342.     t:='' else begin
  343.                  while s[p]<>' ' do inc(p);
  344.                  t:=copy(s,i,p-i);
  345.                end;
  346.   part:=t;
  347. end;
  348.  
  349. begin
  350.   log('Converting log files');
  351.   assign(hlog,'xph~temp.log');
  352.   if not exist('xph~temp.log') then log('Error: xph~temp.log not found');
  353.   reset(hlog);
  354.   assign(plog,'zmtemp.log');
  355.   rewrite(plog);
  356.   assign(tlog,'xptemp.log');
  357.   if sending then
  358.   begin
  359.     rewrite(tlog);
  360.     filespath:='■'; spoolpath:='·';
  361.   end else reset(tLog);
  362.   while not eof(hlog) do
  363.   begin
  364.     readln(hlog,s);
  365.     ps:='';
  366.     if s[1]='H' then ps:='Z ' else
  367.     if s[1]='h' then ps:='z ' else
  368.     if sending then ps:='e ' else ps:='E ';
  369.     filename:=part(s,11);
  370.     if ps[1]='Z' then
  371.                     if copy(filename, Pos('.',filename)+1, 3)='PKT' then
  372.                     filename:=spoolpath+filename
  373.                  else begin
  374.                         cps:=1;
  375.                         while (cps<=7) and (copy(filename, pos('.', filename)+1, 2)<>mailext[cps]) do
  376.                         inc(cps);
  377.                         if cps>7 then filename:=filespath+filename
  378.                                  else filename:=spoolpath+filename;
  379.                       end;
  380.  
  381.     ps:=ps+Date+' '+Time+'  '+FileName+', ';
  382.  
  383.     temp:=Part(s,2);
  384.     ps:=ps+temp+' bytes, ';
  385.     Val(temp, bytes, error);
  386.  
  387.     temp:=Part(s,5);
  388.     Val(temp, cps, error);
  389.     IF (cps=9999) OR (cps=0) THEN
  390.     BEGIN
  391.         secs:=1;
  392.         temp:='0';
  393.     END ELSE secs:=bytes DIV cps;
  394.  
  395.     ps:=ps+FStr(secs)+' s, '+temp+' cps';
  396.     temp:=Part(s,7);
  397.     IF temp<>'0' THEN
  398.       ps:=ps+', '+temp+' errors';
  399.     IF (ps[1]='Z') AND sending THEN WriteLn(TLog,ps) ELSE WriteLn(PLog,ps);
  400.   END;
  401.  
  402.  
  403.   IF NOT sending THEN
  404.     WHILE NOT Eof(TLog) DO
  405.     BEGIN
  406.       ReadLn(TLog,s);
  407.       IF Pos('■',s)>0 THEN
  408.       BEGIN
  409.         Insert(FilesPath,s,Pos('■',s)+1);
  410.         Delete(s, Pos('■',s), 1);
  411.       END ELSE IF Pos('·',s)>0 THEN
  412.       BEGIN
  413.         Insert(SpoolPath,s,Pos('·',s)+1);
  414.         Delete(s, Pos('·',s), 1);
  415.       END;
  416.       WriteLn(PLog,s);
  417.     END;
  418.   Close(HLog);
  419.   Close(PLog);
  420.   Close(TLog);
  421.   Erase(Hlog);
  422.   IF NOT sending THEN Erase(TLog);
  423. END;
  424.  
  425.  
  426. procedure tprogram.endemeldung;
  427.  
  428. const
  429.   status: array[false..true] of string[1]=('2','1');
  430.  
  431. begin
  432.   restorescreen;
  433.   log('XPHydra '+version+' terminated. Errorlevel: '+fstr(exitcode));
  434.   log('Mailer session batch #'+status[sending]+' terminated.');
  435.   if not sending then log('');
  436. end;
  437.  
  438.  
  439. var
  440.   prog:tprogram;
  441.  
  442. begin
  443.   prog.init;
  444.   prog.run;
  445.   prog.done;
  446. end.
  447.