home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUCP / RSNU106A.ZIP / src / rusnkill.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-27  |  15.8 KB  |  655 lines

  1. unit rusnkill;
  2.  
  3. {
  4.  
  5. rusn-kil.pas - rusnews killfile and antikillfile processing
  6.  
  7. }
  8.  
  9. {$I rusn-def.pas}
  10.  
  11. interface
  12.  
  13. uses rusnglob,rusnfunc,rusnio,rusnproc;
  14.  
  15. procedure addtokill(header,words: string; isglobal: boolean);
  16. procedure addtoantikill(header,words: string; isglobal: boolean);
  17. procedure readinkill(backup: boolean);
  18. procedure readinantikill(backup: boolean);
  19.  
  20. implementation
  21.  
  22. procedure addtosomekill(usekill: boolean; var somekillf: file;
  23.  header,words: string; isglobal: boolean);
  24.  
  25. var
  26.   spaceneeded: integer;
  27.   i,j: integer;
  28.   s: string;
  29.   tempf: text;
  30.   newsomekillwritten: boolean;
  31.   nonglobalsomekills: boolean;
  32.   numsomekills: integer;
  33.   somekillsubjsp,somekillfromsp,somekilltextp: killsarrp;
  34.  
  35. begin
  36.   if usekill then
  37.     begin
  38.       xwritelns('Updating kill file...');
  39.       nonglobalsomekills := nonglobalkills;
  40.       numsomekills := numkills;
  41.       somekillsubjsp := killsubjsp;
  42.       somekillfromsp := killfromsp;
  43.       somekilltextp := killtextp;
  44.     end
  45.   else
  46.     begin
  47.       xwritelns('Updating antikill file...');
  48.       nonglobalsomekills := nonglobalantikills;
  49.       numsomekills := numantikills;
  50.       somekillsubjsp := antikillsubjsp;
  51.       somekillfromsp := antikillfromsp;
  52.       somekilltextp := antikilltextp;
  53.     end;
  54.  
  55.   spaceneeded := 1;
  56.   if not isglobal then
  57.     if not nonglobalsomekills then
  58.       spaceneeded := 2;
  59.  
  60.   if numsomekills+spaceneeded<=maxkills then
  61.     begin
  62.       if isglobal then
  63.         begin
  64.           for i := numsomekills downto 1 do
  65.             somekilltextp^[i+1] := somekilltextp^[i];
  66.           somekilltextp^[1] := header+': '+words;
  67.         end
  68.       else if spaceneeded=2 then
  69.         begin
  70.           somekilltextp^[numsomekills+1] := 'Newsgroups'+': '+currgroup;
  71.           somekilltextp^[numsomekills+2] := header+': '+words;
  72.         end
  73.       else
  74.         begin
  75.           for i := 1 to numsomekills do
  76.             begin
  77.               s := somekilltextp^[i];
  78.               if (parseheadername(s)='Newsgroups') and
  79.                (parseheadervalue(s)=currgroup) then
  80.                 begin
  81.                   for j := numsomekills downto i+1 do
  82.                     somekilltextp^[j+1] := somekilltextp^[j];
  83.                   somekilltextp^[i+1] := header+': '+words;
  84.                 end;
  85.             end;
  86.         end;
  87.       if usekill then
  88.         inc(numkills,spaceneeded)
  89.       else
  90.         inc(numantikills,spaceneeded);
  91.       inc(numsomekills,spaceneeded);
  92.     end
  93.   else
  94.  
  95. {it definitely won't all fit in memory now}
  96.  
  97.     if usekill then
  98.       killfileinmem := false
  99.     else
  100.       antikillfileinmem := false;
  101.  
  102.   if header='Subject' then
  103.     begin
  104.       if numsubjks<maxkills then
  105.         begin
  106.           inc(numsubjks);
  107.           killsubjsp^[numsubjks] := words;
  108.         end
  109.       else
  110. {}{} {should delete the oldest one}
  111.         warn('kill file too large');
  112.     end
  113.   else
  114.     begin
  115.       if numfromks<maxkills then
  116.         begin
  117.           inc(numfromks);
  118.           killfromsp^[numfromks] := words;
  119.         end
  120.       else
  121. {}{} {should delete the oldest one}
  122.         warn('kill file too large');
  123.     end;
  124.  
  125.   if haskillfile then
  126.     begin
  127.       newsomekillwritten := false;
  128.       assign(tempf,temporarydir+'\'+userid);
  129.       reset(killf);
  130.       rewrite(tempf);
  131.       if isglobal then
  132.         begin
  133.           writeln(tempf,header,': ',words);
  134.           newsomekillwritten := true;
  135.         end;
  136.       while not eof(killf) do
  137.         begin
  138.           readln(killf,s);
  139.           if (parseheadername(s)='Newsgroups') and
  140.            (parseheadervalue(s)=currgroup) then
  141.             begin
  142.               writeln(tempf,s);
  143.               writeln(tempf,header,': ',words);
  144.               newsomekillwritten := true;
  145.             end
  146.           else
  147.             writeln(tempf,s);
  148.         end;
  149.       if not newsomekillwritten then {this group had no kill information}
  150.         begin
  151.           writeln(tempf,'Newsgroups',': ',currgroup);
  152.           writeln(tempf,header,': ',words);
  153.           newsomekillwritten := true;
  154.         end;
  155.       close(killf);
  156.       close(tempf);
  157.       reset(tempf);
  158.       rewrite(killf);
  159.       while not eof(tempf) do
  160.         begin
  161.           readln(tempf,s);
  162.           writeln(killf,s);
  163.         end;
  164.       close(tempf);
  165.       close(killf);
  166.  
  167.       erase(tempf);
  168.     end
  169.   else
  170.     begin
  171.       haskillfile := true;
  172.       assign(killf,killfn);
  173.       rewrite(killf);
  174.       if not isglobal then
  175.         writeln(killf,'Newsgroups',': ',currgroup);
  176.       writeln(killf,header,': ',words);
  177.     end;
  178.  
  179.   reset(killf);
  180. end;
  181.  
  182. procedure addtokill;
  183.  
  184. var
  185.   spaceneeded: integer;
  186.   i,j: integer;
  187.   s: string;
  188.   tempf: text;
  189.   newkillwritten: boolean;
  190.  
  191. begin
  192.   xwritelns('Updating kill file...');
  193.  
  194.   spaceneeded := 1;
  195.   if not isglobal then
  196.     if not nonglobalkills then
  197.       spaceneeded := 2;
  198.  
  199.   if numkills+spaceneeded<=maxkills then
  200.     begin
  201.       if isglobal then
  202.         begin
  203.           for i := numkills downto 1 do
  204.             killtextp^[i+1] := killtextp^[i];
  205.           killtextp^[1] := header+': '+words;
  206.         end
  207.       else if spaceneeded=2 then
  208.         begin
  209.           killtextp^[numkills+1] := 'Newsgroups'+': '+currgroup;
  210.           killtextp^[numkills+2] := header+': '+words;
  211.         end
  212.       else
  213.         begin
  214.           for i := 1 to numkills do
  215.             begin
  216.               s := killtextp^[i];
  217.               if (parseheadername(s)='Newsgroups') and
  218.                (parseheadervalue(s)=currgroup) then
  219.                 begin
  220.                   for j := numkills downto i+1 do
  221.                     killtextp^[j+1] := killtextp^[j];
  222.                   killtextp^[i+1] := header+': '+words;
  223.                 end;
  224.             end;
  225.         end;
  226.       inc(numkills,spaceneeded);
  227.     end
  228.   else
  229.     killfileinmem := false;  {it definitely won't all fit in memory now}
  230.  
  231.   if header='Subject' then
  232.     begin
  233.       if numsubjks<maxkills then
  234.         begin
  235.           inc(numsubjks);
  236.           killsubjsp^[numsubjks] := words;
  237.         end
  238.       else
  239. {}{} {should delete the oldest one}
  240.         warn('kill file too large');
  241.     end
  242.   else
  243.     begin
  244.       if numfromks<maxkills then
  245.         begin
  246.           inc(numfromks);
  247.           killfromsp^[numfromks] := words;
  248.         end
  249.       else
  250. {}{} {should delete the oldest one}
  251.         warn('kill file too large');
  252.     end;
  253.  
  254.   if haskillfile then
  255.     begin
  256.       newkillwritten := false;
  257.       assign(tempf,temporarydir+'\'+userid);
  258.       reset(killf);
  259.       rewrite(tempf);
  260.       if isglobal then
  261.         begin
  262.           writeln(tempf,header,': ',words);
  263.           newkillwritten := true;
  264.         end;
  265.       while not eof(killf) do
  266.         begin
  267.           readln(killf,s);
  268.           if (parseheadername(s)='Newsgroups') and
  269.            (parseheadervalue(s)=currgroup) then
  270.             begin
  271.               writeln(tempf,s);
  272.               writeln(tempf,header,': ',words);
  273.               newkillwritten := true;
  274.             end
  275.           else
  276.             writeln(tempf,s);
  277.         end;
  278.       if not newkillwritten then {this group had no kill information}
  279.         begin
  280.           writeln(tempf,'Newsgroups',': ',currgroup);
  281.           writeln(tempf,header,': ',words);
  282.           newkillwritten := true;
  283.         end;
  284.       close(killf);
  285.       close(tempf);
  286.       reset(tempf);
  287.       rewrite(killf);
  288.       while not eof(tempf) do
  289.         begin
  290.           readln(tempf,s);
  291.           writeln(killf,s);
  292.         end;
  293.       close(tempf);
  294.       close(killf);
  295.  
  296.       erase(tempf);
  297.     end
  298.   else
  299.     begin
  300.       haskillfile := true;
  301.       assign(killf,killfn);
  302.       rewrite(killf);
  303.       if not isglobal then
  304.         writeln(killf,'Newsgroups',': ',currgroup);
  305.       writeln(killf,header,': ',words);
  306.     end;
  307.  
  308.   reset(killf);
  309. end;
  310.  
  311. procedure addtoantikill;
  312.  
  313. var
  314.   spaceneeded: integer;
  315.   i,j: integer;
  316.   s: string;
  317.   tempf: text;
  318.   newantikillwritten: boolean;
  319.  
  320. begin
  321.   xwritelns('Updating antikill file...');
  322.  
  323.   spaceneeded := 1;
  324.   if not isglobal then
  325.     if not nonglobalantikills then
  326.       spaceneeded := 2;
  327.  
  328.   if numantikills+spaceneeded<=maxkills then
  329.     begin
  330.       if isglobal then
  331.         begin
  332.           for i := numantikills downto 1 do
  333.             antikilltextp^[i+1] := antikilltextp^[i];
  334.           antikilltextp^[1] := header+': '+words;
  335.         end
  336.       else if spaceneeded=2 then
  337.         begin
  338.           antikilltextp^[numantikills+1] := 'Newsgroups'+': '+currgroup;
  339.           antikilltextp^[numantikills+2] := header+': '+words;
  340.         end
  341.       else
  342.         begin
  343.           for i := 1 to numantikills do
  344.             begin
  345.               s := antikilltextp^[i];
  346.               if (parseheadername(s)='Newsgroups') and
  347.                (parseheadervalue(s)=currgroup) then
  348.                 begin
  349.                   for j := numantikills downto i+1 do
  350.                     antikilltextp^[j+1] := antikilltextp^[j];
  351.                   antikilltextp^[i+1] := header+': '+words;
  352.                 end;
  353.             end;
  354.         end;
  355.       inc(numantikills,spaceneeded);
  356.     end
  357.   else
  358.     antikillfileinmem := false;  {it definitely won't all fit in memory now}
  359.  
  360.   if header='Subject' then
  361.     begin
  362.       if numsubjaks<maxkills then
  363.         begin
  364.           inc(numsubjaks);
  365.           antikillsubjsp^[numsubjaks] := words;
  366.         end
  367.       else
  368. {}{} {should delete the oldest one}
  369.         warn('antikill file too large');
  370.     end
  371.   else
  372.     begin
  373.       if numfromaks<maxkills then
  374.         begin
  375.           inc(numfromaks);
  376.           antikillfromsp^[numfromaks] := words;
  377.         end
  378.       else
  379. {}{} {should delete the oldest one}
  380.         warn('antikill file too large');
  381.     end;
  382.  
  383.   if hasantikillfile then
  384.     begin
  385.       newantikillwritten := false;
  386.       assign(tempf,temporarydir+'\'+userid);
  387.       reset(antikillf);
  388.       rewrite(tempf);
  389.       if isglobal then
  390.         begin
  391.           writeln(tempf,header,': ',words);
  392.           newantikillwritten := true;
  393.         end;
  394.       while not eof(antikillf) do
  395.         begin
  396.           readln(antikillf,s);
  397.           if (parseheadername(s)='Newsgroups') and
  398.            (parseheadervalue(s)=currgroup) then
  399.             begin
  400.               writeln(tempf,s);
  401.               writeln(tempf,header,': ',words);
  402.               newantikillwritten := true;
  403.             end
  404.           else
  405.             writeln(tempf,s);
  406.         end;
  407.       if not newantikillwritten then {this group had no antikill information}
  408.         begin
  409.           writeln(tempf,'Newsgroups',': ',currgroup);
  410.           writeln(tempf,header,': ',words);
  411.           newantikillwritten := true;
  412.         end;
  413.       close(antikillf);
  414.       close(tempf);
  415.       reset(tempf);
  416.       rewrite(antikillf);
  417.       while not eof(tempf) do
  418.         begin
  419.           readln(tempf,s);
  420.           writeln(antikillf,s);
  421.         end;
  422.       close(tempf);
  423.       close(antikillf);
  424.  
  425.       erase(tempf);
  426.     end
  427.   else
  428.     begin
  429.       hasantikillfile := true;
  430.       assign(antikillf,antikillfn);
  431.       rewrite(antikillf);
  432.       if not isglobal then
  433.         writeln(antikillf,'Newsgroups',': ',currgroup);
  434.       writeln(antikillf,header,': ',words);
  435.     end;
  436.  
  437.   reset(antikillf);
  438. end;
  439.  
  440. {$ifdef oldaddtoantikill}
  441.  
  442. procedure addtoantikill(header,words: string; isglobal: boolean);
  443.  
  444. var
  445.   s: string;
  446.   tempf: text;
  447.   newantikillwritten: boolean;
  448.  
  449. begin
  450.   xwritelns('Updating antikill file...');
  451.  
  452.   if numantikills<maxkills then
  453.     begin
  454.       inc(numantikills);
  455.       antikilltextp^[numantikills] := header+': '+words;
  456.     end
  457.   else
  458.     antikillfileinmem := false;
  459.  
  460.   if header='Subject' then
  461.     begin
  462.       if numsubjaks<maxkills then
  463.         begin
  464.           inc(numsubjaks);
  465.           antikillsubjsp^[numsubjaks] := words;
  466.         end
  467.       else
  468. {}{} {should delete the oldest one?}
  469.         warn('antikill file too large');
  470.     end
  471.   else
  472.     begin
  473.       if numfromaks<maxkills then
  474.         begin
  475.           inc(numfromaks);
  476.           antikillfromsp^[numfromaks] := words;
  477.         end
  478.       else
  479. {}{} {should delete the oldest one?}
  480.         warn('antikill file too large');
  481.     end;
  482.  
  483.   if hasantikillfile then
  484.     begin
  485.       newantikillwritten := false;
  486.       assign(tempf,temporarydir+'\'+userid);
  487.       reset(antikillf);
  488.       rewrite(tempf);
  489.       if isglobal then
  490.         begin
  491.           writeln(tempf,header,': ',words);
  492.           newantikillwritten := true;
  493.         end;
  494.       while not eof(antikillf) do
  495.         begin
  496.           readln(antikillf,s);
  497.           if (parseheadername(s)='Newsgroups') and
  498.            (parseheadervalue(s)=currgroup) then
  499.             begin
  500.               writeln(tempf,s);
  501.               writeln(tempf,header,': ',words);
  502.               newantikillwritten := true;
  503.             end
  504.           else
  505.             writeln(tempf,s);
  506.         end;
  507.       if not newantikillwritten then {this group had no antikill information}
  508.         begin
  509.           writeln(tempf,'Newsgroups',': ',currgroup);
  510.           writeln(tempf,header,': ',words);
  511.           newantikillwritten := true;
  512.         end;
  513.       close(antikillf);
  514.       close(tempf);
  515.       reset(tempf);
  516.       rewrite(antikillf);
  517.       while not eof(tempf) do
  518.         begin
  519.           readln(tempf,s);
  520.           writeln(antikillf,s);
  521.         end;
  522.       close(tempf);
  523.       close(antikillf);
  524.  
  525.       erase(tempf);
  526.     end
  527.   else
  528.     begin
  529.       hasantikillfile := true;
  530.       assign(antikillf,antikillfn);
  531.       rewrite(antikillf);
  532.       if not isglobal then
  533.         writeln(antikillf,'Newsgroups',': ',currgroup);
  534.       writeln(antikillf,header,': ',words);
  535.     end;
  536.  
  537.   reset(antikillf);
  538. end;
  539.  
  540. {$endif}
  541.  
  542. procedure readinkill;
  543.  
  544. var
  545.   s: string;
  546.   tempf: text;
  547.  
  548. begin
  549.   killfileinmem := true;
  550.   numkills := 0;
  551.  
  552.   if haskillfile then
  553.     close(killf);
  554.  
  555.   haskillfile := true;
  556.  
  557.   killfn := home+'\kill';
  558.   assign(killf,killfn);
  559.   {$I-}
  560.   reset(killf);
  561.   {$I+}
  562.   if ioresult<>0 then
  563.     begin
  564.       haskillfile := false;
  565.       xwritelns('(no kill file found)');
  566.     end;
  567.  
  568.   if haskillfile then
  569.     begin
  570.       if backup then
  571.         begin
  572.           xwritelns('Backing up kill file...');
  573.           assign(tempf,home+'\kill.bak');
  574.           rewrite(tempf);
  575.         end
  576.       else
  577.         xwritelns('Reading in kill file...');
  578.       reset(killf);
  579.       while not eof(killf) do
  580.         begin
  581.           readln(killf,s);
  582.           if backup then
  583.             writeln(tempf,s);
  584.           if numkills<maxkills then
  585.             begin
  586.               inc(numkills);
  587.               killtextp^[numkills] := s;
  588.             end
  589.           else
  590.             killfileinmem := false;
  591.         end;
  592.       if backup then
  593.         close(tempf);
  594.       reset(killf);
  595.     end;
  596. end;
  597.  
  598. procedure readinantikill;
  599.  
  600. var
  601.   s: string;
  602.   tempf: text;
  603.  
  604. begin
  605.   if hasantikillfile then
  606.     close(antikillf);
  607.  
  608.   antikillfileinmem := true;
  609.   numantikills := 0;
  610.  
  611.   hasantikillfile := true;
  612.  
  613.   antikillfn := home+'\antikill';
  614.   assign(antikillf,antikillfn);
  615.   {$I-}
  616.   reset(antikillf);
  617.   {$I+}
  618.   if ioresult<>0 then
  619.     begin
  620.       hasantikillfile := false;
  621.       xwritelns('(no antikill file found)');
  622.     end;
  623.  
  624.   if hasantikillfile then
  625.     begin
  626.       if backup then
  627.         begin
  628.           xwritelns('Backing up antikill file...');
  629.           assign(tempf,home+'\antikill.bak');
  630.           rewrite(tempf);
  631.         end
  632.       else
  633.         xwritelns('Reading in antikill file...');
  634.       reset(antikillf);
  635.       while not eof(antikillf) do
  636.         begin
  637.           readln(antikillf,s);
  638.           if backup then
  639.             writeln(tempf,s);
  640.           if numantikills<maxkills then
  641.             begin
  642.               inc(numantikills);
  643.               antikilltextp^[numantikills] := s;
  644.             end
  645.           else
  646.             antikillfileinmem := false;
  647.         end;
  648.       if backup then
  649.         close(tempf);
  650.       reset(antikillf);
  651.     end;
  652. end;
  653.  
  654. end.
  655.