home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUCP / UUPOST10.ZIP / uupcpost.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1994-04-24  |  6.0 KB  |  259 lines

  1. {$M 8192, 0, 0}
  2. program uupc_post_news;
  3.  
  4.   Posting module for UUPC/Extended. This program implements posting of
  5.   newsgroups using UUPC/Extended's UUCP- and RNEWS-programs.
  6.  
  7.   All articles are posted to the Mailserv host using UUCP, as RNEWS
  8.   (at least up till version 1.12i) does not handle outgoing news.
  9.  
  10.   A local copy of the article is created in the news database, using
  11.   RNEWS to process the article file and store it in the local database.
  12.  
  13.   Note: This program assumes that you are running UUPC in its default
  14.   news-batching mode. If you have the 'snews' option set in UUPC.RC,
  15.   this program will not be able to store a local copy of the article,
  16.   although posting of the article to your newsfeed will work.
  17.  
  18.   Written by Henrik Storner (storner@osiris.ping.dk).
  19.  
  20. Credits:
  21.  
  22.   Russell Schulz, for his Rusnews program which made me hack this to-
  23.   gether, so that I could use his Rusnews newsreader instead of the
  24.   very simplistic Snews program. Also, credit goes to Russ for getting
  25.   me to implement this as a standalone program. The 'indir' and 'execp'
  26.   routines herein were taken from the Rusnews sources.
  27.  
  28.   The authors of SNews, who came up with the scheme for posting using
  29.   only UUCP, which is used in this program.
  30. }
  31.  
  32. uses dos;
  33.  
  34. var
  35.   { These vars are read from the UUPC config files }
  36.   userdir, temporarydir, newsname, smarthost: string;
  37.  
  38.   { These are local vars }
  39.   seqfile, tmp: text;
  40.   seq: integer; seqstr: string;
  41.   i: integer;
  42.   d_name, x_name, short_x_name: string;
  43.   uucp_args: string;
  44.  
  45.  
  46. procedure loadconfig;
  47.  
  48.   Load the UUPC configuration. We need the following entries from 
  49.   the file referenced by UUPCSYSRC:
  50.   - Tempdir   -> temporarydir
  51.   - Nodename  -> newsname
  52.   - Mailserv  -> smarthost
  53.  
  54.   Userdir is set to the UUPC main directory, i.e. the directory for
  55.   the UUPCSYSRC file.
  56. }
  57.  
  58. var
  59.     uupcsysrcfn : string;
  60.     t1, t2: string;
  61.     sysf: text;
  62.  
  63. begin
  64. uupcsysrcfn:= GetEnv('UUPCSYSRC');
  65. if (uupcsysrcfn = '') then
  66.    begin
  67.    writeln('UUPCSYSRC not set - aborting.');
  68.    halt(2);
  69.    end;
  70.  
  71. FSplit(uupcsysrcfn, userdir, t1, t2);
  72. if (userdir[length(userdir)] = '\') then
  73.    delete(userdir, length(userdir), 1);
  74.  
  75. assign(sysf, uupcsysrcfn);
  76. {$I-}
  77. reset(sysf);
  78. {$I+}
  79. if (ioresult <> 0) then
  80.    begin
  81.    writeln('Cannot open UUPCSYSRC file (', uupcsysrcfn, ')');
  82.    halt(2);
  83.    end;
  84.  
  85. temporarydir:= '';
  86. newsname:= '';
  87. smarthost:= '';
  88.  
  89. while not eof(sysf) do
  90.    begin
  91.    readln(sysf, t1);
  92.    if (t1 <> '') then
  93.       begin
  94.       while (t1[1] in [' ', #9]) do
  95.          delete(t1, 1, 1);
  96.  
  97.       t2:= t1;
  98.       for i:= 1 to length(t1) do
  99.           t1[i]:= UpCase(t1[i]);
  100.  
  101.       if (t1[1] <> '#') then
  102.          begin
  103.          if (pos('TEMPDIR', t1) = 1) then
  104.         temporarydir:= copy(t2, pos('=', t2)+1, 255);
  105.          if (pos('NODENAME', t1) = 1) then
  106.         newsname:= copy(t2, pos('=', t2)+1, 255);
  107.      if (pos('MAILSERV', t1) = 1) then
  108.         smarthost:= copy(t2, pos('=', t2)+1, 255);
  109.          end;
  110.       end;
  111.    end;
  112.  
  113. close(sysf);
  114.  
  115. if (temporarydir = '') or (newsname = '') or (smarthost = '') then
  116.    begin
  117.    writeln('Cannot read config from UUPCSYSRC file');
  118.    writeln('tempdir = ', temporarydir);
  119.    writeln('nodename = ', newsname);
  120.    writeln('mailserv = ', smarthost);
  121.    halt(2);
  122.    end;
  123. end;
  124.  
  125.  
  126.  
  127. function indir(filespec,dir: string): boolean;
  128. var
  129.   fileinfo: searchrec;
  130.  
  131. begin
  132.   findfirst(dir+'\'+filespec,archive,fileinfo);
  133.   indir := (doserror=0);
  134. end;
  135.  
  136.  
  137. procedure execp(cmd, cmdline: string);
  138. var
  139.   path: string;
  140.   success: boolean;
  141.   el: string;
  142.   at: integer;
  143.  
  144. begin
  145.   if (pos(':',cmd)<>0) or (pos('\',cmd)<>0) then
  146.     exec(cmd,cmdline)
  147.   else if indir(cmd,'.') then
  148.     exec(cmd,cmdline)
  149.   else
  150.     begin
  151.       path := getenv('PATH');
  152.       success := false;
  153.       while not success and (path<>'') do
  154.         begin
  155.           if copy(path,length(path),255)<>';' then
  156.             path := path+';';
  157.           at := pos(';',path);
  158.           el := copy(path,1,at-1);
  159.           path := copy(path,at+1,255);
  160.           if indir(cmd,el) then
  161.             begin
  162.               success := true;
  163.               exec(el+'\'+cmd,cmdline);
  164.             end;
  165.         end;
  166.     end;
  167. end;
  168.  
  169.  
  170. procedure uupc_post(articlefn: string);
  171. const
  172.   hexchars : string[16] = '0123456789abcdef';
  173.  
  174. begin
  175.  
  176. { Get a sequence number for the D. and X. files }
  177. assign(seqfile, userdir+'\nseq');
  178. {$I-} 
  179. reset(seqfile);
  180. if ioresult<>0 then
  181.    begin
  182.    { Sequence file not found }
  183.    seq:= 0;
  184.    end
  185. else
  186.    begin
  187.    readln(seqfile, seq);
  188.    if ioresult<>0 then seq:= 0;
  189.    close(seqfile);
  190.    end;
  191. seq:= seq+1;
  192. rewrite(seqfile);
  193. if ioresult=0 then
  194.    writeln(seqfile, seq)
  195. else
  196.    { Do some error handling }
  197.    ;
  198. close(seqfile);
  199. {$I+}
  200.  
  201. { Get it in 4-digit hex }
  202. seqstr:= '';
  203. for i:= 1 to 4 do
  204.    begin
  205.    seqstr:= hexchars[1+(seq mod 16)] + seqstr;
  206.    seq:= seq div 16;
  207.    end;
  208.  
  209. d_name:= 'D.' + newsname + seqstr;
  210. x_name:= 'X.' + newsname + seqstr;
  211. short_x_name:= temporarydir + '\X_' + seqstr + '.' + copy(newsname, 1, 3);
  212.  
  213. assign(tmp, short_x_name); rewrite(tmp);
  214. writeln(tmp, 'U news ', newsname);
  215. writeln(tmp, 'Z');
  216. writeln(tmp, 'F ', d_name);
  217. writeln(tmp, 'I ', d_name);
  218. writeln(tmp, 'C rnews');
  219. close(tmp);
  220.  
  221. uucp_args:= '-C ' + articlefn + ' ' + smarthost + '!' + d_name;
  222. execp('uucp.exe', uucp_args);
  223. uucp_args:= '-C ' + short_x_name + ' ' + smarthost + '!' + x_name;
  224. execp('uucp.exe', uucp_args);
  225.  
  226. assign(tmp, short_x_name); erase(tmp);
  227.  
  228. { Post the article locally. For this, rnews works! }
  229. uucp_args:= '-f ' + articlefn;
  230. execp('rnews.exe', uucp_args);
  231.  
  232. end;
  233.  
  234.  
  235. begin
  236. writeln('UUPCpost 1.0');
  237. if (paramcount <> 1) then
  238.    begin
  239.    writeln('Usage: uupcpost infile');
  240.    halt(1)
  241.    end;
  242.  
  243. { Check that the file exists }
  244. assign(tmp, paramstr(1));
  245. {$I-} reset(tmp); {$I+}
  246. if (ioresult <> 0) then
  247.    begin
  248.    writeln('Cannot read file ', paramstr(1));
  249.    halt(1);
  250.    end;
  251.  
  252. loadconfig;
  253. uupc_post(paramstr(1));
  254. halt(0);
  255. end.
  256.  
  257.