home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / wCNews_1.0.30.lha / contrib / joel / text0000.txt < prev   
Encoding:
Text File  |  1992-10-22  |  9.0 KB  |  421 lines

  1. Hello Kai, in <m0mdBhx-0000hzF@hactar.hanse.de> on Oct 9 you wrote:
  2.  
  3. >      Ok, hope  to hear from you soon =:-> (Gee, never though that there was
  4. > such a interest in CNews ...)
  5. >             kai
  6.  
  7. Enclosed is a couple of scripts/programs I use locally under WB 2.0 (2.1).
  8. Feel free to include any of them in a cnews distribution.  I would like
  9. to see CNews take a different face..  The underlying mechanism for CNews
  10. (active file and article history) works very well, but the external one
  11. needs quite a bit of work..  We're not working on a bland no-graphics
  12. unix station here..this is an amiga, and I want to see amiga-tized programs
  13. to do my news handling.  It could be cleaned up quite a bit..hope to see
  14. that for the next amiga release..
  15.  
  16. ---------------
  17.  
  18. ---   OLD/batchnews  { Everything in the OLD directory is stuff that used to work,
  19.                        but not well.  Feel free to look it over/use it if you wish.
  20.                      }
  21.  
  22. .key none
  23. .bra {
  24. .ket }
  25. ;
  26. ; Primary script to batch out going news to other sites 
  27. ;
  28. cd >Env:Dir{$$}
  29. list >T:batch{$$}.tmp uunews:out.going/#? lformat "BatchNewsSys %s" 
  30. sort T:batch{$$}.tmp T:batch{$$}.sh
  31. execute T:batch{$$}.sh
  32. cd $Dir{$$}
  33. delete Env:Dir{$$} T:batch{$$}.#? quiet
  34.  
  35. ---   OLD/batchnewssys
  36.  
  37. .key sys
  38. .bra {
  39. .ket }
  40. cd uunews:out.going/{sys}
  41. if exists togo
  42.   rename togo togo.tmp
  43.   c:replace <togo.tmp >togo.{sys} "UUNews:" ""
  44.   failat 11
  45.   batcher -S {sys} -f togo.{sys}
  46.   list >T:batch{$$}.tmp1 batch_???? lformat "compress %s%s"
  47.   list >T:batch{$$}.tmp2 batch_???? lformat "delete %s"
  48.   sort T:batch{$$}.tmp1 T:batch{$$}.cmp
  49.   execute T:batch{$$}.cmp
  50.   sort T:batch{$$}.tmp2 T:batch{$$}.cmp2
  51.   execute T:batch{$$}.cmp2
  52. delete T:batch{$$}.cmp T:batch{$$}.cmp2 T:batch{$$}.tmp1 T:batch{$$}.tmp2 togo.tmp quiet
  53.   endif 
  54.  
  55. ---    OLD/BatchTo  { This script was replaced by the following program. }
  56.  
  57. .key sys
  58. .bra {
  59. .ket }
  60.  
  61. if exists uunews:in.coming
  62.   cd uunews:in.coming
  63.   List ~(#?.#?) FILES QUICK TO t:incoming.a LFORMAT "unbatchnewsfile %s"
  64.   failat 10
  65.   execute >nil: t:incoming.a
  66. endif
  67.  
  68. if exists uunews:out.going/{sys}
  69.   cd uunews:out.going/{sys}
  70.   if exists togo
  71.     batchnewssys {sys}
  72.   endif
  73. endif
  74.  
  75. copy togo.{sys} /togo.{sys}.old
  76. List FILES QUICK TO t:incoming.b LFORMAT "uux %s {sys}!rnews"
  77. execute >nil: t:incoming.b
  78. if not WARN
  79.   delete uunews:out.going/{sys}/#?.Z
  80.   delete uunews:out.going/{sys}/togo.{sys}
  81. endif
  82.  
  83. delete t:incoming.a t:incoming.b quiet
  84.  
  85. ---   batch.c
  86.  
  87. #include <stdio.h>
  88. #include <string.h>
  89. #include <exec/memory.h>
  90. #include <exec/io.h>
  91.  
  92. #define BATCHSIZE 50000
  93. #define BUFF_SIZE 20000
  94.  
  95. main(argc,argv)
  96. int argc;
  97. char *argv[];
  98.  
  99. {
  100.   FILE *togo, *batch, *art;
  101.   
  102.   char artname[256];
  103.   char batchname[60];
  104.   char command[100];
  105.   char togofile[50];
  106.   char temp[50];
  107.   char sysid[20];
  108.   char *buffer;
  109.   int currartsize=0;
  110.   int currbatsize=0;
  111.   int batchcount=0;
  112.   int wrotesize;
  113.   int readsize;
  114.   int remainsize;
  115.  
  116.   batch = NULL;
  117.  
  118.   if (argc != 2) {
  119.       printf("Usage: %s SYSTEM\n",argv[0]);
  120.       exit(0);
  121.     }
  122.   strcpy(sysid,argv[1]);
  123.   sprintf(togofile,"UUNews:out.going/%s/togo",sysid);
  124.  
  125.   if ((togo = fopen(togofile, "r")) == NULL) {
  126.       printf("Unable to open togo file!\n");
  127.       exit(0);
  128.     }
  129.   else /* togo got opened */ {
  130.     if ((buffer=(char *)malloc(BUFF_SIZE))==NULL)  {
  131.         printf("Not enough memory for buffer\n");
  132.         exit(10);
  133.       }
  134.     while (fscanf(togo, "%s %d\n", artname, &currartsize) == 2) {
  135.       if (currbatsize > BATCHSIZE) {
  136.     fclose(batch);
  137.     procbatch(batchname,sysid);
  138.     currbatsize = 0;
  139.     batch = NULL;
  140.       }
  141.       if (!batch) {
  142.     sprintf(batchname, "t:batch_%04d", ++batchcount);
  143.     if ((batch = fopen(batchname, "w")) == NULL) {
  144.       fclose(togo);
  145.       printf("Unable to open batch!\n");
  146.           free(buffer);
  147.       exit(10);
  148.     }
  149.       }
  150.       if ((art = fopen(artname, "r")) == NULL)
  151.     printf("Unable to open article: %s\n", artname);
  152.       else {
  153.     fprintf(batch, "#! rnews %ld\n", currartsize);
  154.     remainsize = currartsize;
  155.     while (remainsize) {
  156.       if (remainsize > BUFF_SIZE)
  157.         readsize = BUFF_SIZE;
  158.       else
  159.         readsize = remainsize;
  160.       remainsize = remainsize - readsize;
  161.       if (fread(buffer, 1, readsize, art) != readsize)
  162.         printf("Read from article failure!\n");
  163.       else if (fwrite(buffer, 1, readsize, batch) != readsize)
  164.         printf("Write to batch failure!\n");
  165.     }
  166.       }
  167.       fclose(art);
  168.       currbatsize += currartsize;
  169.     }
  170.   }
  171.   fclose(batch);
  172.   free(buffer);
  173.   procbatch(batchname, sysid);
  174.   fclose(togo);
  175.   sprintf(command,"copy UUNews:out.going/%s/togo UUNews:out.going/togo.%s.old", sysid, sysid);
  176.   system(command);
  177.   sprintf(command,"delete uunews:out.going/%s/togo QUIET", sysid);
  178.   system(command);
  179. }
  180.  
  181. int
  182. procbatch(char *batchname, char *sysid)
  183. {
  184. char command[100];
  185.  
  186. sprintf(command, "compress %s",batchname);
  187. system(command);
  188. sprintf(command, "uux %s.z %s!rnews", batchname, sysid);
  189. system(command);
  190. sprintf(command, "delete %s.z QUIET", batchname); 
  191. system(command);
  192. }
  193.  
  194. ---  OLD/CNewsLock
  195.  
  196. LAB Check_Again
  197. If EXISTS T:Cnews.lock
  198.     Wait 65
  199.     Skip Back Check_Again
  200. EndIf
  201. Echo >T:Cnews.lock "locked"
  202.  
  203. ---  DoExpire
  204.  
  205. .key VAR
  206. .bra {
  207. .ket }
  208.  
  209. cnewslock
  210. changetaskpri PRIORITY=-1
  211. expire >NIL: -v -l UULib:News/Expire.{VAR}
  212.  
  213. Delete Quiet T:Cnews.lock uulib:News/(log|errlog)
  214. Copy UULib:News/active uulib:news/active.old
  215.  
  216. ;arnmaster >NIL:
  217. changetaskpri PRIORITY=0
  218.  
  219. ---  UULib:News/Expire.d  { Daily expire of news }
  220.  
  221. # :ts=8
  222. # hold onto history lines 14 days
  223. /bounds/            x    14-14-14        -
  224.  
  225. # no article gets more than 6 days
  226. /expired/            x    0-14-14        -
  227.  
  228. # real noise gets thrown away fast
  229. # (handled by "all" below)
  230. junk,control            x    0-0-0        -
  231.  
  232. # unmoderated groups get 7 days, moderated ones 7 also
  233. # comp                x    7        -
  234. misc.forsale.computers          x      2-2-2            -
  235. comp.sys.amiga.marketplace      x      2-2-2            -
  236. news.groups                     x      2-2-2            -
  237. all                x      14-14-14            -
  238.  
  239.  
  240. ---  OLD/Poll   {  Could never get this to work correctly.  Needs work. }
  241.  
  242. .key hostname/A,tries/A,delay
  243. .bra {
  244. .ket }
  245. ;
  246. ; Batch news to coplex
  247. Failat 11
  248. Batch coplex >NIL:
  249. ;
  250. ;  Keep track of how many times we've tried
  251. ;
  252. SetEnv Poll{hostname} 1
  253. ;
  254. ; Will be deleted if the connection was successful
  255. ;
  256. Echo >uuspool:C.{hostname}DUMMY
  257. ;
  258. ; Call every two minutes until we connect or get tired
  259. ;
  260. Lab Loop
  261. Echo "Call #" NOLINE
  262. Echo $Poll{hostname} NOLINE
  263. Echo " of " NOLINE
  264. Echo {tries} NOLINE
  265. Echo " started at " NOLINE
  266. Date
  267. ;
  268. ; Make the call
  269. ;
  270. uucico -s{hostname}
  271. ;
  272. ; Increment our attempt counter
  273. ;
  274. Eval <Env:Poll{hostname} >NIL: TO T:PollTemp{$$} value2=1 op=+ ?
  275. Copy T:PollTemp{$$} Env:Poll{hostname} quiet
  276. Delete T:PollTemp{$$} quiet
  277. ;
  278. ; Are we done trying?
  279. ;
  280. If $Poll{hostname} NOT GT {tries}
  281. ; Did we connect?
  282.   If exists uuspool:C.{hostname}DUMMY
  283. ;   If not, try again later
  284.     Wait {delay} min
  285.     Skip back Loop
  286.   Else
  287.     Skip Connected
  288.   Endif
  289. Endif
  290. ;
  291. ; Cleanup
  292. ;
  293. Delete Env:Poll{hostname} quiet
  294. Quit
  295. ;
  296. ; Here's where we go once we've connected
  297. ;
  298. Lab Connected
  299. ;
  300. ; Check to see if uuxqt is still running
  301. ;
  302. If exists t:UUXQT.lock
  303.   Wait 1 min
  304.   Skip back Connected
  305. Endif
  306. ;
  307. ; Unbatch any news we may have recieved
  308. ;
  309. UnBatchNews >NIL:
  310. Quit
  311.  
  312.  
  313. ---  UUIO  { What I currently use to call out. }
  314.  
  315. ; $Ver UUIO 1.0 5-23-92
  316. ;
  317. Batch coplex >NIL:
  318. ;
  319. Poll.mine coplex
  320. ; check for connection complete
  321. lab connected
  322. if exists env:retrycoplex
  323.   wait 2 min
  324.   Skip connected BACK
  325. endif
  326. ; check for uuxqt still running
  327. lab unbatching
  328. if exists t:UUXQT.LOCK
  329.   wait 2 min
  330.   Skip unbatching BACK
  331. endif
  332. ;
  333. changetaskpri PRIORITY=-1
  334. unbatchnews <NIL: >NIL:
  335. wait 15 mins
  336. arnmaster <NIL: >NIL:
  337. changetaskpri PRIORITY=0
  338.  
  339. ---  Poll.mine
  340.  
  341. .KEY hostname/A
  342. .BRA {
  343. .KET }
  344.  
  345. setenv retry{hostname} x
  346.  
  347. echo >uuspool:C.{hostname}DUMMY
  348.  
  349. lab loop
  350. ;echo "Call started at "
  351. ;date
  352. uucico -A -7 -U1 -n7 -pri -p1 -s{hostname}
  353. echo >>env:retry{hostname} x NOLINE
  354. if $retry{hostname} NOT EQ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  355.  if EXISTS uuspool:C.{hostname}DUMMY
  356.   wait 2 min
  357.   skip loop BACK
  358.  endif
  359. endif
  360. delete env:retry{hostname} QUIET
  361.  
  362.  
  363. ---  UnBatchNews
  364.  
  365. .key type
  366. .bra {
  367. .ket }
  368. ;
  369. ; Primary script to process in coming news
  370. ;
  371. ; Set the CNews lock and save our directory
  372. ;
  373. CNewsLock
  374. cd >Env:Dir{$$}
  375. cd uunews:in.coming
  376. failat 11
  377. ;
  378. ; List all file in uunews:in.coming and unbatch them in order
  379. ;
  380. List >T:unbatch{$$}.tmp #?.z LFORMAT "UnBatchNewsFile %s"
  381. Sort T:unbatch{$$}.tmp T:unbatch{$$}.sh >nil:
  382. If warn
  383.   Skip Exit
  384. EndIf
  385. Execute T:unbatch{$$}.sh
  386. ;
  387. ; Run ArnMaster to update the .newsdb's
  388. ;
  389. ArnMaster >NIL:
  390. ;
  391. ; Return us to out starting directory and clean up
  392. ;
  393. Lab Exit
  394. Cd $Dir{$$}
  395. Delete T:unbatch{$$}.#? QUIET
  396. Delete Env:Dir{$$} T:CNews.lock QUIET
  397. Quit
  398.  
  399.  
  400. ---  UnBatchNewsFile
  401.  
  402. .key file/a,type
  403. .bra {
  404. .ket }
  405. ;echo "Processing ... {file}" NOLINE
  406. uncompress <{file} >t:tempfile
  407. failat 20
  408. relaynews <t:tempfile -r
  409. cd uunews:in.coming
  410. delete {file} QUIET
  411. ;echo " ... Done" 
  412.  
  413.  
  414.  
  415. ------------------------------------------------------------------------------
  416.      /// Joel C. Justen                |    UUNET:  uunet!coplex.com!crpi!joel
  417. \\\ ///  System Administrator          |    BITNET: jcjust01@ulkyvx.BITNET
  418.  \XXX/   Crazyrat Software Productions |    UUCP:   joel@crpi.UUCP
  419. ------------------------------------------------------------------------------
  420. flames <NIL: >NIL: | "This is *MY* damn amiga and I'll say what I want to say!"
  421.