home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUCP / RSNU106A.ZIP / src / rusnproc.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-10-16  |  9.5 KB  |  468 lines

  1. unit rusnproc;
  2.  
  3. {
  4.  
  5. rusnproc.pas - rusnews procedures
  6.  
  7. }
  8.  
  9. {$I rusn-def.pas}
  10.  
  11. interface
  12.  
  13. uses dos,rusnglob,rusnfunc,rusnio,rusngenf,rusnmous;
  14.  
  15. procedure warn(warning: string);
  16. procedure warn3(w1,w2,w3: string);
  17. procedure warnerr(prg: string; doserr: integer);
  18. procedure execp(cmd,cmdline: string);
  19. procedure shellout;
  20. procedure unfoldergroup(var group: string);
  21. procedure pickagroup(var possgroup: string);
  22. procedure updatejoin(highestnum: word);
  23. procedure updatejoinunsubscribe;
  24. procedure addnewmailgroup(newgroup: string);
  25. procedure mkhier(hier: string);
  26. procedure copyfile(oldfn,newfn: string);
  27. procedure movefile(oldfn,newfn: string);
  28.  
  29. implementation
  30.  
  31. procedure warn;
  32.  
  33. var
  34.   wastec: char;
  35.  
  36. begin
  37.   xclreolxy(1,lpp);
  38.   xwritess(warning,' - press any key ');
  39.   wastec := xreadkey;
  40.   xclreolxy(1,lpp);
  41. end;
  42.  
  43. procedure warn3;
  44.  
  45. begin
  46.   xwriteln;
  47.   xwriteln;
  48.   xclreolxy(1,lpp-2);
  49.   xwrites(w1);
  50.   xclreolxy(1,lpp-1);
  51.   xwrites(w2);
  52.   warn(w3);
  53.   xclreolxy(1,lpp-2);
  54.   xclreolxy(1,lpp-1);
  55. end;
  56.  
  57. procedure warnerr;
  58.  
  59. var
  60.   errstr: string;
  61.  
  62. begin
  63.   errstr := itoa(doserr); 
  64.   if doserr=2 then errstr := '2 (file not found)'
  65.   else if doserr=3 then errstr := '3 (path not found)'
  66.   else if doserr=5 then errstr := '5 (access denied)'
  67.   else if doserr=6 then errstr := '6 (invalid handle)'
  68.   else if doserr=8 then errstr := '8 (not enough memory)'
  69.   else if doserr=10 then errstr := '10 (invalid environment)'
  70.   else if doserr=11 then errstr := '11 (invalid format)'
  71.   else if doserr=18 then errstr := '18 (no more files)';
  72.  
  73.   warn('warning: '+prg+' failed (error '+errstr+')');
  74. end;
  75.  
  76. procedure execp;
  77.  
  78. var
  79.   path: string;
  80.   success: boolean;
  81.   el: string;
  82.   at: integer;
  83.  
  84. begin
  85.   if (pos(':',cmd)<>0) or (pos('\',cmd)<>0) then
  86.     exec(cmd,cmdline)
  87.   else if indir(cmd,'.') then
  88.     exec(cmd,cmdline)
  89.   else
  90.     begin
  91.       path := getenv('PATH');
  92.       success := false;
  93.       while not success and (path<>'') do
  94.         begin
  95.           if copy(path,length(path),255)<>';' then
  96.             path := path+';';
  97.           at := pos(';',path);
  98.           el := copy(path,1,at-1);
  99.           path := copy(path,at+1,255);
  100.           if indir(cmd,el) then
  101.             begin
  102.               success := true;
  103.               exec(el+'\'+cmd,cmdline);
  104.             end;
  105.         end;
  106.     end;
  107. end;
  108.  
  109. procedure shellout;
  110.  
  111. var
  112.   comspec: string;
  113.   doserr: integer;
  114.   wastec: char;
  115.  
  116. begin
  117.   if console and trusted then
  118.     begin
  119.       xgotoxy(1,lpp);
  120.       xwriteln;
  121.       xwriteln;
  122.       xwriteln;
  123.       xwritelns('use `EXIT'' to return to rusnews');
  124.       xwritelns('be careful - you probably don''t have a lot of memory left');
  125.       xwriteln;
  126.       comspec := getenv('COMSPEC');
  127.       if comspec='' then
  128.         if indir('c:\.','command.com') then
  129.           comspec := 'c:\command.com';
  130.       if comspec='' then
  131.         begin
  132.           warn('could not find what shell to run - no COMSPEC variable');
  133.         end
  134.       else
  135.         begin
  136.           mousehide;
  137.           execp(comspec,'');
  138.           mouseshow;
  139.           doserr := doserror;
  140.           xgotoxy(1,lpp);
  141.           xwriteln;
  142.           xwriteln;
  143.           xwriteln;
  144.           if doserr<>0 then
  145.             xwrites('(error) press any key to return to rusnews ')
  146.           else
  147.             xwrites('press any key to return to rusnews ');
  148.           wastec := xreadkey;
  149.           xwrites(^M);
  150.           xclreol;
  151.           if doserr<>0 then
  152.             warnerr('shell',doserr);
  153.         end
  154.     end;
  155. end;
  156.  
  157. procedure unfoldergroup;
  158.  
  159. begin
  160.   if length(group)>0 then
  161.     if group[1]='=' then
  162.       begin
  163.         if length(group)=1 then
  164.           group := mailprefix
  165.         else
  166.           group := mailprefix+'.'+copy(group,2,255);
  167.  
  168. { prevent possible security hole }
  169.  
  170.         if (numoccur('\',unslash(group))<>0) or
  171.          (numoccur(':',group)<>0) or (pos('..',group)<>0) then
  172.           group := mailprefix;
  173.       end;
  174. end;
  175.  
  176. procedure pickagroup;
  177.  
  178. var
  179.   howto: char;
  180.  
  181. begin
  182.   xclreolxy(1,lpp);
  183.   if possgroup='' then
  184.     begin
  185.       xwrites('Goto group (or initials): ');
  186.       possgroup := currgroup;
  187.  
  188. { changed true to false - it was a pain having to hit ^U to cancel this }
  189.  
  190. {
  191.       xreadlnsp(possgroup,cols-30,true);
  192. }
  193.  
  194.       xreadlnsp(possgroup,cols-30,false);
  195.  
  196. {mail folder support}
  197.  
  198.       unfoldergroup(possgroup);
  199.  
  200.     end;
  201.  
  202.   if (possgroup='') then
  203.     xclreolxy(1,lpp)
  204.   else
  205.     if joinedtogroup(possgroup) then
  206.       begin
  207.         xclreolxy(1,lpp-1);
  208.         xwritelnss('found group: ',possgroup);
  209.         howto := 
  210.          onekey('<j>ump normally, <a>ll, last <1>-<9> pages (default=j) ',
  211.          'ja123456789 '+#13);
  212.         if (howto=' ') or (howto=#13) then
  213.           howto := 'j';
  214.         if howto='a' then
  215.           readallarts := true;
  216.         if (howto>='1') and (howto<='9') then
  217.           readpagesback := ord(howto)-ord('0');
  218.         xclreolxy(1,lpp);
  219.       end
  220.     else
  221.       begin
  222.         warn('could not find a group to match');
  223.         possgroup := '';
  224.       end;
  225. end;
  226.  
  227. procedure updatejoin;
  228.  
  229. var
  230.   s: string;
  231.   tempf: text;
  232.  
  233. begin
  234.   if highestnum>alreadyread then
  235.     begin
  236.       xwritelns('Updating join file...');
  237.       assign(tempf,temporarydir+'\'+userid);
  238.       reset(joinf);
  239.       rewrite(tempf);
  240.       while not eof(joinf) do
  241.         begin
  242.           readln(joinf,s);
  243.           if getfirstw(s)=currgroup then
  244.             writeln(tempf,currgroup,' ',highestnum)
  245.           else
  246.             writeln(tempf,s);
  247.         end;
  248.       close(joinf);
  249.       close(tempf);
  250.  
  251.       reset(tempf);
  252.       rewrite(joinf);
  253.       while not eof(tempf) do
  254.         begin
  255.           readln(tempf,s);
  256.           writeln(joinf,s);
  257.         end;
  258.       close(tempf);
  259.       close(joinf);
  260.  
  261.       erase(tempf);
  262.  
  263.       reset(joinf);
  264.     end;
  265. end;
  266.  
  267. procedure updatejoinunsubscribe;
  268.  
  269. var
  270.   s: string;
  271.   firstw: string;
  272.   tempf: text;
  273.  
  274. begin
  275.   xwritelns('Updating join file...');
  276.   assign(tempf,temporarydir+'\'+userid);
  277.   reset(joinf);
  278.   rewrite(tempf);
  279.   numjoined := 0;
  280.   while not eof(joinf) do
  281.     begin
  282.       readln(joinf,s);
  283.       firstw := getfirstw(s);
  284.       if firstw<>currgroup then
  285.         begin
  286.           if numjoined<maxjoined then
  287.             begin
  288.               inc(numjoined);
  289.               joinedgroups[numjoined] := firstw;
  290.             end;
  291.           writeln(tempf,s);
  292.         end;
  293.     end;
  294.   close(joinf);
  295.   close(tempf);
  296.  
  297.   reset(tempf);
  298.   rewrite(joinf);
  299.   while not eof(tempf) do
  300.     begin
  301.       readln(tempf,s);
  302.       writeln(joinf,s);
  303.     end;
  304.   close(tempf);
  305.   close(joinf);
  306.  
  307.   erase(tempf);
  308.  
  309.   reset(joinf);
  310. end;
  311.  
  312. procedure addnewmailgroup;
  313.  
  314. var
  315.   seenmailbutnotnew: boolean;
  316.   s: string;
  317.   firstw: string;
  318.   tempf: text;
  319.  
  320. begin
  321.   seenmailbutnotnew := false;
  322.   xwritelns('Updating join file...');
  323.   assign(tempf,temporarydir+'\'+userid);
  324.   reset(joinf);
  325.   rewrite(tempf);
  326.   numjoined := 0;
  327.   while not eof(joinf) do
  328.     begin
  329.       readln(joinf,s);
  330.       firstw := getfirstw(s);
  331.  
  332.       if firstw=mailprefix then
  333.         seenmailbutnotnew := true;
  334.  
  335. {insert the new group alphabetically in the mail groups, or after}
  336. {the last one if it's the biggest alphabetically of them all}
  337.  
  338.       if (seenmailbutnotnew and not ismailgroup(firstw)) or
  339.        (ismailgroup(firstw) and (firstw>newgroup)) then
  340.         begin
  341.           if numjoined<maxjoined then
  342.             begin
  343.               inc(numjoined);
  344.               joinedgroups[numjoined] := newgroup;
  345.             end;
  346.           writeln(tempf,newgroup,' 0');
  347.           seenmailbutnotnew := false;
  348.         end;
  349.  
  350.       if numjoined<maxjoined then
  351.         begin
  352.           inc(numjoined);
  353.           joinedgroups[numjoined] := firstw;
  354.         end;
  355.       writeln(tempf,s);
  356.     end;
  357.  
  358.   if seenmailbutnotnew then
  359.     begin
  360.       if numjoined<maxjoined then
  361.         begin
  362.           inc(numjoined);
  363.           joinedgroups[numjoined] := newgroup;
  364.         end;
  365.       writeln(tempf,newgroup,' 0');
  366.     end;
  367.  
  368.   close(joinf);
  369.   close(tempf);
  370.  
  371.   reset(tempf);
  372.   rewrite(joinf);
  373.   while not eof(tempf) do
  374.     begin
  375.       readln(tempf,s);
  376.       writeln(joinf,s);
  377.     end;
  378.   close(tempf);
  379.   close(joinf);
  380.  
  381.   erase(tempf);
  382.  
  383.   reset(joinf);
  384. end;
  385.  
  386. procedure mkhier;
  387.  
  388. var
  389.   s: string;
  390.   i: integer;
  391.   fileinfo: searchrec;
  392.   dir: string;
  393.  
  394. begin
  395.  
  396. {$I-}
  397.  
  398. {if the directory already exists, don't worry about an error}
  399.  
  400. {WHY DOESN'T THIS WORK WITH TP6 ?!?!?!}
  401.  
  402.   s := hier;
  403.  
  404.   for i := 1 to length(s) do
  405.     if s[i]='/' then
  406.       s[i] := '\';
  407.  
  408.   if length(s)>0 then
  409.     if s[length(s)]='\' then
  410.       s := copy(s,1,length(s)-1);
  411.  
  412.   for i := 2 to length(s) do
  413.     if (s[i]='\') and (s[i-1]<>':') then
  414.       begin
  415.         dir := copy(s,1,i-1);
  416.         findfirst(dir,directory,fileinfo);
  417.         if doserror<>0 then
  418.           mkdir(dir);
  419.       end;
  420.  
  421.   findfirst(s,directory,fileinfo);
  422.   if doserror<>0 then
  423.     mkdir(s);
  424.  
  425. {$I+}
  426.  
  427. end;
  428.  
  429. procedure copyfile;
  430.  
  431. const
  432.   bufsize=1024;
  433.  
  434. var
  435.   infile, outfile: file;
  436.   done: boolean;
  437.   numread: word;
  438.   buffer: array[1..bufsize] of char;
  439.  
  440. begin
  441.   assign(infile,oldfn);
  442.   reset(infile,1);
  443.   assign(outfile,newfn);
  444.   rewrite(outfile,1);
  445.   done := false;
  446.   while not done do
  447.     begin
  448.       blockread(infile,buffer,bufsize,numread);
  449.       blockwrite(outfile,buffer,numread);
  450.       done := (numread<bufsize);
  451.     end;
  452.   close(infile);
  453.   close(outfile);
  454. end;
  455.  
  456. procedure movefile;
  457.  
  458. var
  459.   f: file;
  460.  
  461. begin
  462.   copyfile(oldfn,newfn);
  463.   assign(f,oldfn);
  464.   erase(f);
  465. end;
  466.  
  467. end.
  468.