home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / de / comp / sources / os9 / 10 next >
Encoding:
Internet Message Format  |  1992-12-23  |  44.5 KB

  1. Xref: sparky de.comp.sources.os9:10 comp.os.os9:1552
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!seven-up.East.Sun.COM!sungy!stasys!stasys!not-for-mail
  3. From: frank.kaefer@stasys.sta.sub.org (Frank Kaefer)
  4. Newsgroups: de.comp.sources.os9,comp.os.os9
  5. Subject: MNews Prerelease Part05/09
  6. Message-ID: <1hafdfINNpt6@stasys.sta.sub.org>
  7. Date: 23 Dec 92 19:41:35 GMT
  8. Sender: news@stasys.sta.sub.org
  9. Followup-To: de.comp.sources.d
  10. Organization: Stasys News Server, Starnberg, Germany
  11. Lines: 2007
  12. Approved: frank.kaefer@stasys.sta.sub.org (Frank Kaefer)
  13. NNTP-Posting-Host: stasys.sta.sub.org
  14.  
  15. Submitted-by: Ulrich Dessauer <ud@Nightmare.ddt.sub.org>
  16. Archive-name: mnews/part05
  17.  
  18. : ----- Cut here ----- Cut here ----- Cut here ----- Cut here -----
  19. : Use  sh filename  to extract shell archive
  20. : This shell archive contains following files:
  21. :     'INEWS/psys.c                                  882 bytes'
  22. :     'INEWS/ract.c                                 2810 bytes'
  23. :     'INEWS/retr.c                                  981 bytes'
  24. :     'INEWS/rhead.c                                4336 bytes'
  25. :     'INEWS/rsat.c                                 1309 bytes'
  26. :     'INEWS/rsys.c                                 5149 bytes'
  27. :     'INEWS/sect.c                                 4541 bytes'
  28. :     'INEWS/shead.c                                1409 bytes'
  29. :     'INEWS/sinfo.c                                4889 bytes'
  30. :     'INEWS/sit.c                                  1351 bytes'
  31. :     'INEWS/spch.c                                 4632 bytes'
  32. :     'INEWS/store.c                                3458 bytes'
  33. :     'INEWS/tsys.c                                 3084 bytes'
  34. if test -f 'INEWS/psys.c' ; then
  35.   echo 'File INEWS/psys.c already exists, overwriting it'
  36.   del 'INEWS/psys.c'
  37. fi
  38. echo Extracting \"'INEWS/psys.c'\"
  39. sed "s/^X//" >'INEWS/psys.c' <<'__END__OF__THIS__FILE__'
  40. X/*
  41. X * $Log:    psys.c_v $
  42. X * Revision 1.1  90/08/31  15:35:09  cs
  43. X * Initial revision
  44. X * 
  45. X */
  46. X# ifndef    LINT
  47. Xstatic char rcsid[] = "$Id: psys.c_v 1.1 90/08/31 15:35:09 cs Exp $";
  48. X# endif        LINT
  49. X# include    "inews.h"
  50. X
  51. Xint
  52. Xprocess_sys ()
  53. X{
  54. X    register sys    *stmp, *la;
  55. X
  56. X    if (block_forward)
  57. X        do_log ("Article blocked to be forwarded\n");
  58. X    stmp = hsys;
  59. X    while (stmp) {
  60. X        if (stmp->fwd) {
  61. X            switch (stmp->cmd ? stmp->cmd[0] : '\0') {
  62. X                case '-':
  63. X                case '\0':
  64. X                    if (! block_forward)
  65. X                        write_it (stmp);
  66. X                    break;
  67. X                case '+':
  68. X                    save_it (stmp);
  69. X                    break;
  70. X                default:
  71. X                    pipe_it (stmp->cmd);
  72. X                    break;
  73. X            }
  74. X            for (la = stmp->next; la; la = la->next)
  75. X                if (la->fwd && (! strcmp (stmp->site, la->site)))
  76. X                    if (((! stmp->cmd) && (! stmp->cmd)) || (stmp->cmd && la->cmd && (! strcmp (stmp->cmd, la->cmd))))
  77. X                        la->fwd = FALSE;
  78. X        }
  79. X        stmp = stmp->next;
  80. X    }
  81. X    return (0);
  82. X}
  83. __END__OF__THIS__FILE__
  84. if test -f 'INEWS/ract.c' ; then
  85.   echo 'File INEWS/ract.c already exists, overwriting it'
  86.   del 'INEWS/ract.c'
  87. fi
  88. echo Extracting \"'INEWS/ract.c'\"
  89. sed "s/^X//" >'INEWS/ract.c' <<'__END__OF__THIS__FILE__'
  90. X/*
  91. X * $Log:    ract.c_v $
  92. X * Revision 1.2  91/12/06  14:46:55  ud
  93. X * Changed format of active file to be compatible to BNews/CNews
  94. X * 
  95. X * Revision 1.1  90/08/31  15:35:12  cs
  96. X * Initial revision
  97. X * 
  98. X */
  99. X# ifndef    LINT
  100. Xstatic char rcsid[] = "$Id: ract.c_v 1.2 91/12/06 14:46:55 ud Exp $";
  101. X# endif        LINT
  102. X# include    <c8type.h>
  103. X# include    <modes.h>
  104. X# include    "inews.h"
  105. X
  106. Xextern char    *malloc ();
  107. Xextern char    *strdup ();
  108. X
  109. Xint
  110. Xread_active ()
  111. X{
  112. X    register char    *ptr;
  113. X    register int    t;
  114. X    register active    *act, *tmp;
  115. X    register int    fd;
  116. X    int        n;
  117. X    char        *buf, *sav;
  118. X    char        **arg;
  119. X    int        pos;
  120. X
  121. X    hact = NULL;
  122. X# ifdef        HASH_SEARCH
  123. X    if (! (hashact = (active **) malloc ((HASH_ACTIVE + 2) * sizeof (active *)))) {
  124. X        do_log ("Can't alloc for active hashtable\n");
  125. X        return (-1);
  126. X    }
  127. X    memset (hashact, '\0', HASH_ACTIVE * sizeof (active *));
  128. X# endif        /* HASH_SEARCH */
  129. X    act = NULL;
  130. X    if ((fd = open (ACTIVE_FILE, S_IREAD)) < 0) {
  131. X        do_log ("Can't open %s\n", ACTIVE_FILE);
  132. X        return (-1);
  133. X    }
  134. X    pos = 0;
  135. X    catlines = TRUE;
  136. X    while (buf = readbuf (fd, & n)) {
  137. X        buf[n-1] = '\0';
  138. X        if ((n == 1) || (buf[0] == '#')) {
  139. X            pos += n;
  140. X            continue;
  141. X        }
  142. X        if (!(tmp = (active *) malloc (sizeof (active)))) {
  143. X            close (fd);
  144. X            do_log ("Can't alloc memory in read_active()\n");
  145. X            return (-1);
  146. X        }
  147. X        sav = buf;
  148. X        ptr = skipc (sav, '\0');
  149. X        tmp->changed = FALSE;
  150. X        tmp->pos = pos + strlen (sav) + 1;
  151. X        pos += n;
  152. X        if (!(tmp->grp = strdup (sav))) {
  153. X            close (fd);
  154. X            do_log ("Can't alloc memory in read_active()\n");
  155. X            return (-1);
  156. X        }
  157. X        sav = ptr;
  158. X        ptr = skipc (sav, '\0');
  159. X        tmp->high = atoi (sav);
  160. X        sav = ptr;
  161. X        ptr = skipc (sav, '\0');
  162. X        tmp->low = atoi (sav);
  163. X        sav = ptr;
  164. X        ptr = skipc (sav, '\0');
  165. X        tmp->aflag[0] = sav[0];
  166. X        tmp->aflag[1] = (sav[0] && sav[1]) ? sav[1] : M_USE;
  167. X
  168. X        if (is8digit (*ptr)) {
  169. X            sav = ptr;
  170. X            ptr = skipc (sav, '\0');
  171. X            tmp -> kblimit = atoi (sav);
  172. X        } else
  173. X            tmp -> kblimit = -1;
  174. X
  175. X        if (tmp->aflag[0] == M_MOD) {
  176. X            if ((n = getargs (ptr, &arg)) >= 0) {
  177. X                if (tmp->moderator = (char **) malloc (sizeof (char *) * (n + 2))) {
  178. X                    for (t=0;t<n;++t)
  179. X                        if (!(tmp->moderator[t] = strdup (arg[t]))) {
  180. X                            close (fd);
  181. X                            do_log ("Can't alloc memory in read_active()\n");
  182. X                            return (-1);
  183. X                        }
  184. X                    tmp->moderator[t] = NULL;
  185. X                } else {
  186. X                    close (fd);
  187. X                    do_log ("Can't alloc memory in read_active()\n");
  188. X                    return (-1);
  189. X                }
  190. X                free ((char *) arg);
  191. X            } else {
  192. X                close (fd);
  193. X                do_log ("Can't alloc memory in read_active()\n");
  194. X                return (-1);
  195. X            }
  196. X        } else
  197. X            tmp->moderator = NULL;
  198. X# ifdef        HASH_SEARCH
  199. X        tmp -> id = calc_hash (tmp -> grp, TRUE);
  200. X        t = tmp -> id % HASH_ACTIVE;
  201. X        tmp -> hnext = hashact[t];
  202. X        hashact[t] = tmp;
  203. X# endif        /* HASH_SEARCH */
  204. X        tmp->next = NULL;
  205. X        if (!act)
  206. X            hact = tmp;
  207. X        else
  208. X            act->next = tmp;
  209. X        act = tmp;
  210. X    }
  211. X    catlines = FALSE;
  212. X    close (fd);
  213. X    return (0);
  214. X}
  215. __END__OF__THIS__FILE__
  216. if test -f 'INEWS/retr.c' ; then
  217.   echo 'File INEWS/retr.c already exists, overwriting it'
  218.   del 'INEWS/retr.c'
  219. fi
  220. echo Extracting \"'INEWS/retr.c'\"
  221. sed "s/^X//" >'INEWS/retr.c' <<'__END__OF__THIS__FILE__'
  222. X/*
  223. X * $Log:    retr.c_v $
  224. X * Revision 1.1  91/02/03  15:34:13  ud
  225. X * Initial revision
  226. X * 
  227. X */
  228. X# ifndef    LINT
  229. Xstatic char rcsid[] = "$Id: retr.c_v 1.1 91/02/03 15:34:13 ud Exp $";
  230. X# endif        LINT
  231. X# include    <time.h>
  232. X# include    "inews.h"
  233. X
  234. Xextern char    *index ();
  235. X
  236. Xvoid
  237. Xretreive_message_id (msgid)
  238. Xcharc *msgid;
  239. X{
  240. X    charc        *cur, *tmp;
  241. X    char        *fn, *ptr;
  242. X    time_t        tim;
  243. X    struct tm    *tt;
  244. X
  245. X    if (do_init (FALSE) < 0)
  246. X        exit (_errmsg (1, "Can't setup system.\n"));
  247. X    tmp = msgid;
  248. X    while (tmp) {
  249. X        if (fn = exists_message_id (tmp->text, &tim)) {
  250. X            if (ptr = index (fn, ' '))
  251. X                *ptr = '\0';
  252. X            printf ("+%s\t%s/%s\t%ld", tmp->text, newsdir, fn, tim);
  253. X            if (tt = gmtime (&tim))
  254. X                printf ("\t%04d/%02d/%02d %02d:%02d\n",
  255. X                    tt->tm_year + 1900,
  256. X                    tt->tm_mon + 1,
  257. X                    tt->tm_mday,
  258. X                    tt->tm_hour,
  259. X                    tt->tm_min);
  260. X            else
  261. X                printf ("\t0000/00/00 00:00\n");
  262. X            free (fn);
  263. X        } else
  264. X            printf ("-%s\n", tmp->text);
  265. X        cur = tmp->next;
  266. X        free (tmp->text);
  267. X        free ((char *) tmp);
  268. X        tmp = cur;
  269. X    }
  270. X}
  271. __END__OF__THIS__FILE__
  272. if test -f 'INEWS/rhead.c' ; then
  273.   echo 'File INEWS/rhead.c already exists, overwriting it'
  274.   del 'INEWS/rhead.c'
  275. fi
  276. echo Extracting \"'INEWS/rhead.c'\"
  277. sed "s/^X//" >'INEWS/rhead.c' <<'__END__OF__THIS__FILE__'
  278. X/*
  279. X * $Log:    rhead.c_v $
  280. X * Revision 1.3  91/09/11  18:13:43  ud
  281. X * Moved del_obsolete_header to wgrp.c
  282. X * 
  283. X * Revision 1.2  91/05/22  13:05:15  ud
  284. X * - Added 8 bit support
  285. X * - Added in memory features
  286. X * - Added Supersedes: header
  287. X * 
  288. X * Revision 1.1  90/08/31  15:35:17  cs
  289. X * Initial revision
  290. X * 
  291. X */
  292. X# ifndef    LINT
  293. Xstatic char rcsid[] = "$Id: rhead.c_v 1.3 91/09/11 18:13:43 ud Exp $";
  294. X# endif        LINT
  295. X# include    <c8type.h>
  296. X# include    <time.h>
  297. X# include    <modes.h>
  298. X# include    "inews.h"
  299. X
  300. Xextern char    *index ();
  301. Xextern char    *malloc ();
  302. Xextern char    *rindex ();
  303. Xextern char    *strdup ();
  304. X
  305. Xint
  306. Xread_in_body (fd, fill, firstline, readon)
  307. Xregister int fd;
  308. Xregister char *fill;
  309. Xchar *firstline;
  310. Xint readon;
  311. X{
  312. X    int        fillen;
  313. X    register char    *buf;
  314. X    int        n;
  315. X    register int    fdo;
  316. X
  317. X    if (fill)
  318. X        fillen = strlen (fill);
  319. X    lines = 0;
  320. X
  321. X# ifndef    IN_MEMORY
  322. X    if ((fdo = create (newstmp, S_IWRITE, 03)) < 0) {
  323. X        do_log ("Can't create %s\n", newstmp);
  324. X        return (-1);
  325. X    }
  326. X# endif        /* IN_MEMORY */
  327. X
  328. X    if (readon) {
  329. X        if (firstline && *firstline) {
  330. X# ifndef    IN_MEMORY
  331. X            write (fdo, firstline, strlen (firstline));
  332. X# else        /* IN_MEMORY */
  333. X            add_list (&newstmp, firstline, strlen (firstline));
  334. X# endif        /* IN_MEMORY */
  335. X            ++lines;
  336. X            artsize += strlen (firstline);
  337. X        }
  338. X        conv_it = TRUE;
  339. X        while (buf = readbuf (fd, & n)) {
  340. X            ++lines;
  341. X            artsize += n + 1;
  342. X# ifndef    IN_MEMORY
  343. X            if (fill)
  344. X                write (fdo, fill, fillen);
  345. X            write (fdo, buf, n);
  346. X# else        /* IN_MEMORY */
  347. X            if (fill)
  348. X                add_list (&newstmp, fill, fillen);
  349. X            add_list (&newstmp, buf, n);
  350. X# endif        /* IN_MEMORY */
  351. X        }
  352. X        conv_it = FALSE;
  353. X    }
  354. X# ifndef    IN_MEMORY
  355. X    close (fdo);
  356. X# endif        /* IN_MEMORY */
  357. X    return (0);
  358. X}
  359. X
  360. Xint
  361. Xread_in_header (fd, fill, read_body)
  362. Xint fd;
  363. Xchar *fill;
  364. Xint read_body;
  365. X{
  366. X    register int    t;
  367. X    charc        *act;
  368. X    register charc    *tmp;
  369. X    register char    *buf;
  370. X    register char    *ptr;
  371. X    int        n;
  372. X    
  373. X    head = NULL;
  374. X    act = NULL;
  375. X    conv_it = TRUE;
  376. X    while (buf = readbuf (fd, & n)) {
  377. X        if (n == 1)
  378. X            break;
  379. X        buf[n - 1] = '\0';
  380. X        if (is8space (buf[0]) && act) {
  381. X            if (ptr = malloc (strlen (act->text) + strlen (buf) + 6)) {
  382. X                strcpy (ptr, act->text);
  383. X# ifdef        CAT_LINES
  384. X                strcat (ptr, " ");
  385. X                p = buf;
  386. X                while (is8space (*p))
  387. X                    ++p;
  388. X                strcat (ptr, p);
  389. X# else        CAT_LINES
  390. X                strcat (ptr, "\n");
  391. X                strcat (ptr, buf);
  392. X# endif        CAT_LINES
  393. X                free (act->text);
  394. X                act->text = ptr;
  395. X            }
  396. X            continue;
  397. X        }
  398. X        if (!fill) {
  399. X            for (t=0;hlines[t];++t)
  400. X                if (Strnieql (buf, hlines[t] + 2, strlen (hlines[t] + 2)))
  401. X                    break;
  402. X            ptr= skip_field (buf);
  403. X            if ((!ptr) || (!*ptr))
  404. X                continue;
  405. X        }
  406. X        if (!(tmp = (charc *) malloc (sizeof (charc)))) {
  407. X            do_log ("Can't alloc in read_header\n");
  408. X            return (-1);
  409. X        }
  410. X        if (!(tmp->text = strdup (buf))) {
  411. X            do_log ("Can't alloc in read_header\n");
  412. X            return (-1);
  413. X        }
  414. X        tmp->next = NULL;
  415. X        if (!head)
  416. X            head = tmp;
  417. X        else
  418. X            act->next = tmp;
  419. X        act = tmp;
  420. X    }
  421. X    conv_it = FALSE;
  422. X    if (fill) {
  423. X        handle_special (S_SUBJECT);
  424. X        handle_special (S_REFERENCES);
  425. X        handle_special (S_FOLLOWUP_TO);
  426. X        handle_special (S_TO);
  427. X        if (buf = malloc (512)) {
  428. X            if (tmp = get_header_line (H_MESSAGE_ID)) {
  429. X                ptr = skip_field (tmp->text);
  430. X                strcpy (buf, "In ");
  431. X                strcat (buf, ptr);
  432. X                strcat (buf, ", ");
  433. X            } else
  434. X                strcpy (buf, "");
  435. X            if (ptr = find_from (FALSE))
  436. X                strcat (buf, ptr);
  437. X            else
  438. X                strcat (buf, "Someone");
  439. X            strcat (buf, " wrote:\n");
  440. X        }
  441. X        delete_header (H_MESSAGE_ID);
  442. X        clear_msgid ();
  443. X    } else
  444. X        buf = NULL;
  445. X
  446. X    for (tmp = head; tmp; tmp = tmp -> next)
  447. X        artsize += strlen (tmp -> text);
  448. X
  449. X    if (read_body)
  450. X        if (read_in_body (fd, fill, buf, n > 0) < 0) {
  451. X            close (fd);
  452. X            return (-1);
  453. X        }
  454. X    if (buf)
  455. X        free (buf);
  456. X    close (fd);
  457. X    return (0);
  458. X}
  459. X
  460. Xint
  461. Xread_header (fd)
  462. Xint fd;
  463. X{
  464. X    char    *tmp;
  465. X
  466. X    if (read_in_header (fd, NULL, TRUE) < 0)
  467. X        return (-1);
  468. X    if (crthd) {
  469. X        delete_header (H_PATH);
  470. X        delete_header (H_SENDER);
  471. X        delete_header (H_APPROVED);
  472. X        create_header (TRUE, FALSE);
  473. X    }
  474. X    handle_special (S_NEWSGROUPS);
  475. X    handle_special (S_DISTRIBUTION);
  476. X    handle_special (S_SUPERSEDES);
  477. X    if (crthd && ngs && (!get_header_line (H_FOLLOWUP_TO)))
  478. X        if (tmp = find_followup_to (ngs)) {
  479. X            insert_header (H_FOLLOWUP_TO, tmp, FALSE);
  480. X            free (tmp);
  481. X        }
  482. X    test_systems ();
  483. X    handle_special (S_PATH);
  484. X    handle_special (S_MESSAGE_ID);
  485. X    if (sort_header (TRUE) < 0) {
  486. X        do_log ("Failed in sort_header()\n");
  487. X        return (-1);
  488. X    }
  489. X    check_approved ();
  490. X    check_control ();
  491. X    return (0);
  492. X}
  493. __END__OF__THIS__FILE__
  494. if test -f 'INEWS/rsat.c' ; then
  495.   echo 'File INEWS/rsat.c already exists, overwriting it'
  496.   del 'INEWS/rsat.c'
  497. fi
  498. echo Extracting \"'INEWS/rsat.c'\"
  499. sed "s/^X//" >'INEWS/rsat.c' <<'__END__OF__THIS__FILE__'
  500. X/*
  501. X * $Log:    rsat.c_v $
  502. X * Revision 1.1  90/08/31  15:36:00  cs
  503. X * Initial revision
  504. X * 
  505. X */
  506. X# ifndef    LINT
  507. Xstatic char rcsid[] = "$Id: rsat.c_v 1.1 90/08/31 15:36:00 cs Exp $";
  508. X# endif        LINT
  509. X# include    <modes.h>
  510. X# include    "inews.h"
  511. X
  512. Xextern int    os9forkc ();
  513. X
  514. Xextern char    **environ;
  515. X
  516. Xvoid
  517. Xdo_send_article (fdi, is_ctrl)
  518. Xint fdi;
  519. Xint is_ctrl;
  520. X{
  521. X    char    buf[256];
  522. X    char    fn[64 + sizeof (TEMPDIR)];
  523. X    char    *arg[6];
  524. X    int    old0;
  525. X    int    pid, st;
  526. X    int    n;
  527. X    charc    *tmp;
  528. X    int    fd;
  529. X
  530. X    sprintf (fn, "%s/inewscXXXXXX", TEMPDIR);
  531. X    mktemp (fn);
  532. X    if ((fd = create (fn, S_IREAD | S_IWRITE, 03)) < 0) {
  533. X        do_log ("Can't create tempfile, aborted\n");
  534. X        return;
  535. X    }
  536. X    tmp = head;
  537. X    while (tmp) {
  538. X        write (fd, tmp->text, strlen (tmp->text));
  539. X        write (fd, "\n", 1);
  540. X        tmp = tmp->next;
  541. X    }
  542. X    write (fd, "\n", 1);
  543. X    while ((n = readln (fdi, buf, 250)) > 0)
  544. X        write (fd, buf, n);
  545. X    old0 = dup (0);
  546. X    close (0);
  547. X    lseek (fd, 0 ,0);
  548. X    dup (fd);
  549. X    close (fd);
  550. X    n = 0;
  551. X    arg[n++] = "inews";
  552. X    if (is_ctrl)
  553. X        arg[n++] = "-a";
  554. X    if (verbose)
  555. X        arg[n++] = "-v";
  556. X    arg[n] = NULL;
  557. X    pid = os9exec (os9forkc, arg[0], arg, environ, 0, 0, 3);
  558. X    close (0);
  559. X    dup (old0);
  560. X    close (old0);
  561. X    if (pid < 0) {
  562. X        do_log ("Can't fork inews\n");
  563. X        unlink (fn);
  564. X        return;
  565. X    }
  566. X    while (((n = wait (&st)) != pid) && (n != -1))
  567. X        ;
  568. X    unlink (fn);
  569. X    if (st)
  570. X        do_log ("`inews' returns %d\n", st);
  571. X}
  572. __END__OF__THIS__FILE__
  573. if test -f 'INEWS/rsys.c' ; then
  574.   echo 'File INEWS/rsys.c already exists, overwriting it'
  575.   del 'INEWS/rsys.c'
  576. fi
  577. echo Extracting \"'INEWS/rsys.c'\"
  578. sed "s/^X//" >'INEWS/rsys.c' <<'__END__OF__THIS__FILE__'
  579. X/*
  580. X * $Log:    rsys.c_v $
  581. X * Revision 1.3  91/12/26  13:40:07  ud
  582. X * Added sizelimit in activefile
  583. X * 
  584. X * Revision 1.2  91/05/22  13:19:11  ud
  585. X * Allows now to include other sys file style files; so you can keep
  586. X * a seperate sys file for each site
  587. X * 
  588. X * Revision 1.1  90/08/31  15:36:03  cs
  589. X * Initial revision
  590. X * 
  591. X */
  592. X# ifndef    LINT
  593. Xstatic char rcsid[] = "$Id: rsys.c_v 1.3 91/12/26 13:40:07 ud Exp $";
  594. X# endif        LINT
  595. X# include    <c8type.h>
  596. X# include    <modes.h>
  597. X# include    "inews.h"
  598. X
  599. X/*
  600. X *    Maximum of indent levels for Sys-File
  601. X */
  602. X# define    MAX_FDS        10
  603. X
  604. Xextern char    *index ();
  605. Xextern char    *malloc ();
  606. Xextern char    *strdup ();
  607. X
  608. Xint
  609. Xread_sys ()
  610. X{
  611. X    register char    *ptr;
  612. X    register char    *p;
  613. X    register int    t;
  614. X    sys        *act, *tmp;
  615. X    int        fds[MAX_FDS + 2];
  616. X    int        fdp;
  617. X    int        n;
  618. X    int        siz;
  619. X    char        *fflags;
  620. X    char        *buf, *sav;
  621. X    char        *store;
  622. X    char        *rbuf;
  623. X    char        **arg;
  624. X
  625. X    hsys = NULL;
  626. X    act = NULL;
  627. X    if (! (rbuf = malloc (512))) {
  628. X        do_log ("Failed alloc memory in read_sys\n");
  629. X        return (-1);
  630. X    }
  631. X    if ((fds[0] = open (SYS_FILE, S_IREAD)) < 0) {
  632. X        do_log ("Can't open %s\n", SYS_FILE);
  633. X        return (-1);
  634. X    }
  635. X    fdp = 0;
  636. X    catlines = TRUE;
  637. X    while (fdp >= 0) {
  638. X        while (buf = readbuf (fds[fdp], & n)) {
  639. X            buf[n-1] = '\0';
  640. X            if ((n == 1) || (buf[0] == '#'))
  641. X                continue;
  642. X            if (buf[0] == ':') {
  643. X                if (fdp < MAX_FDS)
  644. X                    if ((fds[fdp + 1] = open (buf + 1, S_IREAD)) != -1)
  645. X                        ++fdp;
  646. X                continue;
  647. X            }
  648. X            if (!(tmp = (sys *) malloc (sizeof (sys)))) {
  649. X                while (fdp >= 0)
  650. X                    close (fds[fdp--]);
  651. X                do_log ("Failed alloc memory in read_sys\n");
  652. X                return (-1);
  653. X            }
  654. X            tmp->fwd = FALSE;
  655. X            sav = buf;
  656. X            ptr = skipc (sav, ':');
  657. X            if (fflags = index (sav, '>')) {
  658. X                *fflags++ = '\0';
  659. X                while (is8space (*fflags))
  660. X                    ++fflags;
  661. X                tmp -> fflags = strdup (fflags);
  662. X            } else
  663. X                tmp -> fflags = NULL;
  664. X            if (p = index (sav, '/')) {
  665. X                *p++ = '\0';
  666. X                store = p;
  667. X                siz = 4;
  668. X                while (p = index (p, ',')) {
  669. X                    ++p;
  670. X                    ++siz;
  671. X                }
  672. X                if (tmp->wsites = (char **) malloc (siz * (sizeof (char *)))) {
  673. X                    p = store;
  674. X                    n = 0;
  675. X                    while (p) {
  676. X                        store = p;
  677. X                        if (p = index (p, ','))
  678. X                            *p++ = '\0';
  679. X                        if (!(tmp->wsites[n++] = strdup (store)))
  680. X                            break;
  681. X                    }
  682. X                    tmp->wsites[n] = NULL;
  683. X                }
  684. X            } else
  685. X                tmp->wsites = NULL;
  686. X            if (!(tmp->site = strdup (sav))) {
  687. X                while (fdp >= 0)
  688. X                    close (fds[fdp--]);
  689. X                do_log ("Failed alloc memory in read_sys\n");
  690. X                return (-1);
  691. X            }
  692. X            sav = ptr;
  693. X            ptr = skipc (sav, ':');
  694. X            if ((n = getargs (sav, &arg)) < 0) {
  695. X                while (fdp >= 0)
  696. X                    close (fds[fdp--]);
  697. X                do_log ("Failed alloc memory in read_sys\n");
  698. X                return (-1);
  699. X            }
  700. X            if (!(tmp->grps = (regexp **) malloc (sizeof (regexp *) * (n + 3)))) {
  701. X                while (fdp >= 0)
  702. X                    close (fds[fdp--]);
  703. X                do_log ("Failed alloc memory in read_sys\n");
  704. X                return (-1);
  705. X            }
  706. X            if (!(tmp->inv = (int *) malloc (sizeof (int) * (n + 3)))) {
  707. X                while (fdp >= 0)
  708. X                    close (fds[fdp--]);
  709. X                do_log ("Failed alloc memory in read_sys\n");
  710. X                return (-1);
  711. X            }
  712. X            if (n > 0) {
  713. X                for (t=0;t<n;++t) {
  714. X                    p = arg[t];
  715. X                    while (*p) {
  716. X                        *p = to8lower (*p);
  717. X                        ++p;
  718. X                    }
  719. X                    p = arg[t];
  720. X                    if (*p == '!') {
  721. X                        ++p;
  722. X                        tmp->inv[t] = TRUE;
  723. X                    } else
  724. X                        tmp->inv[t] = FALSE;
  725. X                    if (p[0] == '^')
  726. X                        strcpy (rbuf, p);
  727. X                    else {
  728. X                        strcpy (rbuf + 1, p);
  729. X                        rbuf[0] = '^';
  730. X                    }
  731. X                    if (rbuf[strlen (rbuf) - 1] != '$')
  732. X                        strcat (rbuf, "$");
  733. X                    if (!(tmp->grps[t] = regcomp (rbuf))) {
  734. X                        while (fdp >= 0)
  735. X                            close (fds[fdp--]);
  736. X                        do_log ("Failed alloc memory in read_sys\n");
  737. X                        return (-1);
  738. X                    }
  739. X                }
  740. X                tmp->grps[t] = NULL;
  741. X                free ((char *) arg);
  742. X            } else
  743. X                n = 0;
  744. X# ifdef        DEFAULT_CTRL
  745. X            tmp->grps[n] = regcomp (NG_CONTROL);
  746. X            tmp->inv[n] = FALSE;
  747. X            tmp->grps[n+1] = NULL;
  748. X# else        DEFAULT_CTRL
  749. X            tmp->grps[n] = NULL;
  750. X# endif        DEFAULT_CTRL
  751. X            sav = ptr;
  752. X            ptr = skipc (sav, ':');
  753. X            if (!*sav)
  754. X                tmp->dist = NULL;
  755. X            if (*sav) {
  756. X                if ((n = getargs (sav, &arg)) < 0) {
  757. X                    while (fdp >= 0)
  758. X                        close (fds[fdp--]);
  759. X                    do_log ("Failed alloc memory in read_sys\n");
  760. X                    return (-1);
  761. X                }
  762. X            } else
  763. X                n = 0;
  764. X            if (!(tmp->dist = (char **) malloc (sizeof (char *) * (n + 3)))) {
  765. X                while (fdp >= 0)
  766. X                    close (fds[fdp--]);
  767. X                do_log ("Failed alloc memory in read_sys\n");
  768. X                return (-1);
  769. X            }
  770. X            if (n > 0) {
  771. X                for (t=0;t<n;++t) {
  772. X                    p = arg[t];
  773. X                    while (*p) {
  774. X                        *p = to8lower (*p);
  775. X                        ++p;
  776. X                    }
  777. X                    if (!(tmp->dist[t] = strdup (arg[t]))) {
  778. X                        while (fdp >= 0)
  779. X                            close (fds[fdp--]);
  780. X                        do_log ("Failed alloc memory in read_sys\n");
  781. X                        return (-1);
  782. X                    }
  783. X                }
  784. X                tmp->dist[t] = NULL;
  785. X                free ((char *) arg);
  786. X            }
  787. X# ifdef        ADD_SITENAME_AS_DISTRIBUTION
  788. X            tmp->dist[n++] = strdup (tmp->site);
  789. X# endif        /* ADD_SITENAME_AS_DISTRIBUTION */
  790. X            tmp->dist[n] = NULL;
  791. X            if (*ptr) {
  792. X                if (!(tmp->cmd = strdup (ptr))) {
  793. X                    while (fdp >= 0)
  794. X                        close (fds[fdp--]);
  795. X                    do_log ("Failed alloc memory in read_sys\n");
  796. X                    return (-1);
  797. X                }
  798. X            } else
  799. X                tmp->cmd = NULL;
  800. X            tmp->next = NULL;
  801. X            if (!act)
  802. X                hsys = tmp;
  803. X            else
  804. X                act->next = tmp;
  805. X            act = tmp;
  806. X        }
  807. X        close (fds[fdp--]);
  808. X    }
  809. X    catlines = FALSE;
  810. X    free (rbuf);
  811. X    return (0);
  812. X}
  813. __END__OF__THIS__FILE__
  814. if test -f 'INEWS/sect.c' ; then
  815.   echo 'File INEWS/sect.c already exists, overwriting it'
  816.   del 'INEWS/sect.c'
  817. fi
  818. echo Extracting \"'INEWS/sect.c'\"
  819. sed "s/^X//" >'INEWS/sect.c' <<'__END__OF__THIS__FILE__'
  820. X/*
  821. X * $Log:    sect.c_v $
  822. X * Revision 1.2  91/05/22  13:06:16  ud
  823. X * Abstracted news owner (from static to variable)
  824. X * 
  825. X * Revision 1.1  90/08/31  15:36:08  cs
  826. X * Initial revision
  827. X * 
  828. X */
  829. X# ifndef    LINT
  830. Xstatic char rcsid[] = "$Id: sect.c_v 1.2 91/05/22 13:06:16 ud Exp $";
  831. X# endif        LINT
  832. X# include    <time.h>
  833. X# include    <pwd.h>
  834. X# include    "inews.h"
  835. X
  836. Xextern char    *getenv ();
  837. Xextern char    *malloc ();
  838. Xextern char    *strdup ();
  839. X
  840. Xvoid
  841. Xsend_control (msg, opts, pars)
  842. Xchar *msg;
  843. Xchar *opts;
  844. Xchar *pars;
  845. X{
  846. X    register int    t;
  847. X    time_t        tim;
  848. X    char        *line;
  849. X    char        *cont;
  850. X    charc        *act;
  851. X    charc        *tmp;
  852. X    charc        *htmp, *t2;
  853. X    int        siz;
  854. X    char        *ptr;
  855. X    char        *sender, *fullname;
  856. X    char        *ffname;
  857. X    struct passwd    *pwd;
  858. X    struct gecos    *gc;
  859. X
  860. X    sender = news_owner;
  861. X    fullname = NULL;
  862. X    setpwent ();
  863. X    if (pwd = getpwuid (getuid () & 0xffff))
  864. X        if ((gc = getgecos (pwd->pw_gecos)) && gc->fullname && *gc->fullname)
  865. X            fullname = strdup (gc->fullname);
  866. X    ffname = NULL;
  867. X    setpwent ();
  868. X    if (pwd = getpwnam (user))
  869. X        if ((gc = getgecos (pwd->pw_gecos)) && gc->fullname && *gc->fullname)
  870. X            ffname = strdup (gc->fullname);
  871. X    endpwent ();
  872. X    act = NULL;
  873. X    cont = NULL;
  874. X    for (t=0;hlines[t];++t) {
  875. X        line = hlines[t] + 2;
  876. X        switch (t) {
  877. X            case H_PATH:
  878. X                cont = strdup (news_owner);
  879. X                break;
  880. X            case H_FROM:
  881. X                if (cont = malloc (strlen (fhost) + strlen (user) + (ffname ? strlen (ffname) + 6 : 0) + 10)) {
  882. X                    sprintf (cont, "%s@%s", user, fhost);
  883. X                    if (ffname) {
  884. X                        strcat (cont, " (");
  885. X                        strcat (cont, ffname);
  886. X                        strcat (cont, ")");
  887. X                    }
  888. X                }
  889. X                break;
  890. X            case H_SENDER:
  891. X            case H_APPROVED:
  892. X                if ((!isadm) && (t == H_SENDER)) {
  893. X                    if (cont = malloc (strlen (fhost) + strlen (user) + 6))
  894. X                        sprintf (cont, "%s@%s", user, fhost);
  895. X                    break;
  896. X                }
  897. X                if (cont = malloc (strlen (fhost) + strlen (sender) + (fullname ? strlen (fullname) + 6 : 0) + 10)) {
  898. X                    sprintf (cont, "%s@%s", sender, fhost);
  899. X                    if (fullname) {
  900. X                        strcat (cont, " (");
  901. X                        strcat (cont, fullname);
  902. X                        strcat (cont, ")");
  903. X                    }
  904. X                }
  905. X                break;
  906. X            case H_NEWSGROUPS:
  907. X            case H_DISTRIBUTION:
  908. X                if (t == H_NEWSGROUPS) {
  909. X# ifdef        ALWAYS_CONTROL
  910. X                    cont = strdup (NG_CONTROL);
  911. X# endif        /* ALWAYS_CONTROL */
  912. X                    if (! (htmp = ngs)) {
  913. X# ifndef    ALWAYS_CONTROL
  914. X                        cont = strdup (NG_CONTROL);
  915. X# endif        /* ALWAYS_CONTROL */
  916. X                        break;
  917. X                    }
  918. X                } else if (dists)
  919. X                    htmp = dists;
  920. X                else
  921. X                    break;
  922. X                siz = 0;
  923. X                t2 = htmp;
  924. X                while (t2) {
  925. X                    siz += strlen (t2->text) + 4;
  926. X                    if (cont && Streql (t2->text, cont)) {
  927. X                        siz = 0;
  928. X                        break;
  929. X                    }
  930. X                    t2 = t2->next;
  931. X                }
  932. X                if ((t == H_NEWSGROUPS) && (siz > 0) && cont)
  933. X                    if (tmp = (charc *) malloc (sizeof (charc)))
  934. X                        if (tmp->text = strdup (cont)) {
  935. X                            tmp->next = ngs;
  936. X                            ngs = tmp;
  937. X                            htmp = ngs;
  938. X                            siz += strlen (cont) + 4;
  939. X                        } else
  940. X                            free ((char *) tmp);
  941. X                if (cont) {
  942. X                    free (cont);
  943. X                    cont = NULL;
  944. X                }
  945. X                if ((siz > 0) && (cont = malloc (siz + 10))) {
  946. X                    t2 = htmp;
  947. X                    strcpy (cont, "");
  948. X                    while (t2) {
  949. X                        if (t2 != htmp)
  950. X                            strcat (cont, ",");
  951. X                        strcat (cont, t2->text);
  952. X                        t2 = t2->next;
  953. X                    }
  954. X                }
  955. X                break;
  956. X            case H_SUBJECT:
  957. X            case H_CONTROL:
  958. X                if (cont = malloc (strlen (msg) + strlen (opts) + 4 + ((pars && *pars) ? strlen (pars) + 4 : 0))) {
  959. X                    strcpy (cont, msg);
  960. X                    if (*opts) {
  961. X                        strcat (cont, " ");
  962. X                        strcat (cont, opts);
  963. X                        if (pars && *pars) {
  964. X                            strcat (cont, " ");
  965. X                            strcat (cont, pars);
  966. X                        }
  967. X                    }
  968. X                }
  969. X                break;
  970. X            case H_MESSAGE_ID:
  971. X                cont = strdup (get_msgid ());
  972. X                break;
  973. X            case H_DATE:
  974. X                time (&tim);
  975. X                cont = strdup (ntime (&tim));
  976. X                break;
  977. X            case H_ORGANIZATION:
  978. X                if (ptr = getenv ("ORGANIZATION"))
  979. X                    cont = strdup (ptr);
  980. X                else
  981. X                    cont = NULL;
  982. X                break;
  983. X            case H_REFERENCES:
  984. X                if ((!isadm) && opts && *opts)
  985. X                    cont = strdup (opts);
  986. X                break;
  987. X            case H_FOLLOWUP_TO:
  988. X            case H_KEYWORDS:
  989. X            case H_SUMMARY:
  990. X            case H_EXPIRES:
  991. X            case H_LINES:
  992. X            case H_XREF:
  993. X            default:
  994. X                cont = NULL;
  995. X        }
  996. X        if (cont) {
  997. X            if (!(tmp = (charc *) malloc (sizeof (charc))))
  998. X                do_exit (_errmsg (1, "Can't alloc in send_control\n"));
  999. X            if (!(tmp->text = malloc (strlen (cont) + strlen (line) + 6)))
  1000. X                do_exit (_errmsg (1, "Can't alloc in send_control\n"));
  1001. X            strcpy (tmp->text, line);
  1002. X            strcat (tmp->text, " ");
  1003. X            strcat (tmp->text, cont);
  1004. X            free (cont);
  1005. X            cont = NULL;
  1006. X            tmp->next = NULL;
  1007. X            if (act)
  1008. X                act->next = tmp;
  1009. X            else
  1010. X                head = tmp;
  1011. X            act = tmp;
  1012. X        }
  1013. X    }
  1014. X    do_send_article (0, TRUE);
  1015. X    if (fullname)
  1016. X        free (fullname);
  1017. X    if (ffname)
  1018. X        free (ffname);
  1019. X}
  1020. __END__OF__THIS__FILE__
  1021. if test -f 'INEWS/shead.c' ; then
  1022.   echo 'File INEWS/shead.c already exists, overwriting it'
  1023.   del 'INEWS/shead.c'
  1024. fi
  1025. echo Extracting \"'INEWS/shead.c'\"
  1026. sed "s/^X//" >'INEWS/shead.c' <<'__END__OF__THIS__FILE__'
  1027. X/*
  1028. X * $Log:    shead.c_v $
  1029. X * Revision 1.1  90/08/31  15:36:13  cs
  1030. X * Initial revision
  1031. X * 
  1032. X */
  1033. X# ifndef    LINT
  1034. Xstatic char rcsid[] = "$Id: shead.c_v 1.1 90/08/31 15:36:13 cs Exp $";
  1035. X# endif        LINT
  1036. X# include    "inews.h"
  1037. X
  1038. Xint
  1039. Xsort_header (make_missing)
  1040. Xregister int make_missing;
  1041. X{
  1042. X    register int    t;
  1043. X    register charc    *act, *tmp, *t2;
  1044. X
  1045. X    act = head;
  1046. X    for (t=0;hlines[t];++t) {
  1047. X        tmp = act;
  1048. X        while (tmp)
  1049. X            if (Strnieql (tmp->text, hlines[t] + 2, strlen (hlines[t] + 2))) {
  1050. X                if (tmp != act) {
  1051. X                    t2 = act;
  1052. X                    while (t2->next)
  1053. X                        if (t2->next == tmp)
  1054. X                            break;
  1055. X                        else
  1056. X                            t2 = t2->next;
  1057. X                    if (t2->next == tmp) {
  1058. X                        t2->next = tmp->next;
  1059. X                        tmp->next = act;
  1060. X                        if (head == act)
  1061. X                            head = tmp;
  1062. X                        else {
  1063. X                            t2 = head;
  1064. X                            while (t2->next)
  1065. X                                if (t2->next == act)
  1066. X                                    break;
  1067. X                                else
  1068. X                                    t2 = t2->next;
  1069. X                            if (t2->next == act) {
  1070. X                                t2->next = tmp;
  1071. X                                tmp->next = act;
  1072. X                            }
  1073. X                        }
  1074. X                    }
  1075. X                } else
  1076. X                    act = act->next;
  1077. X                break;
  1078. X            } else
  1079. X                tmp = tmp->next;
  1080. X        if ((!tmp) && (hlines[t][0] == '0') && make_missing) {
  1081. X            if (tmp = make_head (t))
  1082. X                if (act == head) {
  1083. X                    head = tmp;
  1084. X                    tmp->next = act;
  1085. X                } else {
  1086. X                    t2 = head;
  1087. X                    while (t2->next)
  1088. X                        if (t2->next == act)
  1089. X                            break;
  1090. X                        else
  1091. X                            t2 = t2->next;
  1092. X                    if (t2->next == act) {
  1093. X                        tmp->next = act;
  1094. X                        t2->next = tmp;
  1095. X                    }
  1096. X                }
  1097. X        }
  1098. X    }
  1099. X    return (0);
  1100. X}
  1101. __END__OF__THIS__FILE__
  1102. if test -f 'INEWS/sinfo.c' ; then
  1103.   echo 'File INEWS/sinfo.c already exists, overwriting it'
  1104.   del 'INEWS/sinfo.c'
  1105. fi
  1106. echo Extracting \"'INEWS/sinfo.c'\"
  1107. sed "s/^X//" >'INEWS/sinfo.c' <<'__END__OF__THIS__FILE__'
  1108. X/*
  1109. X * $Log:    sinfo.c_v $
  1110. X * Revision 1.2  91/05/22  13:25:33  ud
  1111. X * Get news owner from password file
  1112. X * Determinate full host name from an own sysinfo entry (if available)
  1113. X * Do better locking/unlocking for lck.inews
  1114. X * 
  1115. X * Revision 1.1  90/08/31  15:36:17  cs
  1116. X * Initial revision
  1117. X * 
  1118. X */
  1119. X# ifndef    LINT
  1120. Xstatic char rcsid[] = "$Id: sinfo.c_v 1.2 91/05/22 13:25:33 ud Exp $";
  1121. X# endif        LINT
  1122. X# include    <stdio.h>
  1123. X# include    <pwd.h>
  1124. X# include    <time.h>
  1125. X# include    "inews.h"
  1126. X
  1127. Xextern char    *cuserid ();
  1128. Xextern char    *getenv ();
  1129. Xextern char    *getlogin ();
  1130. Xextern char    *malloc ();
  1131. Xextern char    *strdup ();
  1132. X
  1133. Xstatic int    islocked = FALSE;
  1134. Xstatic FILE    *logp = NULL;
  1135. Xstatic time_t    starttim, endtim;
  1136. X
  1137. Xvoid
  1138. Xzero_out ()
  1139. X{
  1140. X    struct passwd    *pw;
  1141. X
  1142. X    ngs = NULL;
  1143. X    dists = NULL;
  1144. X    head = NULL;
  1145. X    hsys = NULL;
  1146. X    hact = NULL;
  1147. X# ifdef        HASH_SEARCH
  1148. X    hashact = NULL;
  1149. X# endif        /* HASH_SEARCH */
  1150. X    artsize = 0;
  1151. X    act_rewrite = FALSE;
  1152. X
  1153. X    block_forward = FALSE;
  1154. X
  1155. X    recv = NULL;
  1156. X
  1157. X    batchdir = NULL;
  1158. X    newsdir = NULL;
  1159. X    newslib = NULL;
  1160. X    newstspool = NULL;
  1161. X
  1162. X    hostname = NULL;
  1163. X    fhost = NULL;
  1164. X
  1165. X    isctrl = NULL;
  1166. X
  1167. X    catlines = FALSE;
  1168. X    verbose = FALSE;
  1169. X    logp = NULL;
  1170. X    if (!(user = getlogin ()))
  1171. X        if (!(user = getenv ("USER")))
  1172. X            if (!(user = cuserid ()))
  1173. X                user = "*unknown*";
  1174. X    user = strdup (user);
  1175. X    setpwent ();
  1176. X    if (!(home = getenv ("HOME"))) {
  1177. X        if (!(pw = getpwnam (user)))
  1178. X            home = TEMPDIR;
  1179. X        else
  1180. X            home = pw->pw_dir;
  1181. X    }
  1182. X    if (pw = getpwuid (getmuid () & 0xffff))
  1183. X        news_owner = strdup (pw->pw_name);
  1184. X    else
  1185. X        news_owner = strdup (NEWS_OWNER);
  1186. X    if (! news_owner)
  1187. X        news_owner = NEWS_OWNER;
  1188. X    endpwent ();
  1189. X    home = strdup (home);
  1190. X    local_term = NULL;
  1191. X}
  1192. X
  1193. Xstatic void
  1194. Xopen_log ()
  1195. X{
  1196. X    if (access (LOG_FILE, 0) != -1)
  1197. X        logp = fopen (LOG_FILE, "a");
  1198. X}
  1199. X
  1200. Xstatic void
  1201. Xclose_log ()
  1202. X{
  1203. X    if (logp) {
  1204. X        fclose (logp);
  1205. X        logp = NULL;
  1206. X    }
  1207. X}
  1208. X
  1209. Xint
  1210. Xdo_init (lockit)
  1211. Xint lockit;
  1212. X{
  1213. X    char    *buf;
  1214. X    int    t;
  1215. X    int    slp;
  1216. X
  1217. X    if (!(buf = malloc (512)))
  1218. X        return (-1);
  1219. X    if (!info_str (BATCHDIR, buf, 500))
  1220. X        batchdir = strdup (NEWS_BATCH);
  1221. X    else
  1222. X        batchdir = strdup (buf);
  1223. X    if (!info_str (NEWSDIR, buf, 500))
  1224. X        newsdir = strdup (NEWS_DIR);
  1225. X    else
  1226. X        newsdir = strdup (buf);
  1227. X    if (!info_str (LIBDIR, buf, 500))
  1228. X        newslib = strdup (NEWS_LIB);
  1229. X    else
  1230. X        newslib = strdup (buf);
  1231. X
  1232. X    if (! info_str (TSPOOLDIR, buf, 500))
  1233. X        newstspool = strdup (MNEWS_TSPOOLDIR);
  1234. X    else
  1235. X        newstspool = strdup (buf);
  1236. X
  1237. X    if (!gethostname (buf, 500))
  1238. X        return (-1);
  1239. X    else
  1240. X        if (!(hostname = strdup (buf)))
  1241. X            return (-1);
  1242. X
  1243. X    if (! getfullhostname (buf, 500)) {
  1244. X        if (info_str ("hostdomain", buf, 500)) {
  1245. X            if (fhost = malloc (strlen (hostname) + strlen (buf) + 3))
  1246. X                sprintf (fhost, "%s.%s", hostname, buf);
  1247. X        } else
  1248. X            fhost = strdup (hostname);
  1249. X    } else
  1250. X        fhost = strdup (buf);
  1251. X
  1252. X    /*
  1253. X     *    Test, if an allocation failed
  1254. X     */
  1255. X    if (!(batchdir && newsdir && newslib && fhost))
  1256. X        return (-1);
  1257. X
  1258. X# ifndef    IN_MEMORY
  1259. X    /*
  1260. X     *    Make Filename for news body
  1261. X     */
  1262. X    sprintf (newstmp, "%s/inewsXXXXXX", TEMPDIR);
  1263. X    mktemp (newstmp);
  1264. X# else        /* IN_MEMORY */
  1265. X    newstmp = NULL;
  1266. X# endif        /* IN_MEMORY */
  1267. X
  1268. X    if (chdir (newslib) < 0)
  1269. X        return (-1);
  1270. X
  1271. X    /*
  1272. X     *    Try to lock
  1273. X     */
  1274. X    if (lockit) {
  1275. X# ifndef    EVENT_LOCK
  1276. X        if (LOCK_TIMEOUT > 0) {
  1277. X            t = LOCK_TIMEOUT;
  1278. X            while (t-- > 0)
  1279. X                if (info_is_locked (NEWS_LOCK))
  1280. X                    sleep (1);
  1281. X                else
  1282. X                    break;
  1283. X        } else
  1284. X            t = info_is_locked (NEWS_LOCK) ? -1 : 1;
  1285. X        if ((t <= 0) || (info_lock (NEWS_LOCK, -1) < 0))
  1286. X            return (-2);
  1287. X# else        /* EVENT_LOCK */
  1288. X        if (do_lock (NEWS_LOCK, LOCK_TIMEOUT) < 0)
  1289. X            return (-2);
  1290. X# endif        /* EVENT_LOCK */
  1291. X        islocked = TRUE;
  1292. X        open_log ();
  1293. X    }
  1294. X    time (&starttim);
  1295. X    return (0);
  1296. X}
  1297. X
  1298. Xint
  1299. Xnlock ()
  1300. X{
  1301. X    int    err;
  1302. X
  1303. X    if (! islocked) {
  1304. X# ifndef    EVENT_LOCK
  1305. X        err = info_lock (NEWS_LOCK, -1);
  1306. X# else        /* EVENT_LOCK */
  1307. X        err = do_lock (NEWS_LOCK, LOCK_TIMEOUT);
  1308. X# endif        /* EVENT_LOCK */
  1309. X        if (err != -1) {
  1310. X            islocked = TRUE;
  1311. X            open_log ();
  1312. X        }
  1313. X    }
  1314. X    return (islocked ? 0 : -1);
  1315. X}
  1316. X
  1317. Xvoid
  1318. Xnunlock ()
  1319. X{
  1320. X    if (islocked) {
  1321. X# ifndef    EVENT_LOCK
  1322. X        info_unlock (NEWS_LOCK);
  1323. X# else        /* EVENT_LOCK */
  1324. X        do_unlock (NEWS_LOCK);
  1325. X# endif        /* EVENT_LOCK */
  1326. X        islocked = FALSE;
  1327. X        close_log ();
  1328. X        respool (TRUE);
  1329. X    }
  1330. X}
  1331. X
  1332. Xvoid
  1333. Xdo_term ()
  1334. X{
  1335. X    charc        *tmp;
  1336. X    struct tm    *tt;
  1337. X
  1338. X    if (local_term)
  1339. X        (*local_term) ();
  1340. X# ifndef    IN_MEMORY
  1341. X    unlink (newstmp);
  1342. X# else        /* IN_MEMORY */
  1343. X    free_list (newstmp);
  1344. X    newstmp = NULL;
  1345. X# endif        /* IN_MEMORY */
  1346. X    time (&endtim);
  1347. X    if (tt = localtime (&starttim))
  1348. X        do_log ("%02d.%02d %02d:%02d ",
  1349. X            tt->tm_mday,
  1350. X            tt->tm_mon + 1,
  1351. X            tt->tm_hour,
  1352. X            tt->tm_min);
  1353. X    do_log ("[%d]", endtim - starttim);
  1354. X    for (tmp = ngs; tmp; tmp = tmp->next)
  1355. X        do_log (" %s", tmp->text);
  1356. X    do_log ("\n");
  1357. X    close_log ();
  1358. X    if (islocked)
  1359. X        nunlock ();
  1360. X    else
  1361. X        close_log ();
  1362. X# ifdef        EVENT_LOCK
  1363. X    /* Sure is sure ... */
  1364. X    do_unlock ("*");
  1365. X# endif        /* EVENT_LOCK */
  1366. X}
  1367. X
  1368. Xvoid
  1369. Xdo_exit (n)
  1370. Xint n;
  1371. X{
  1372. X    do_term ();
  1373. X    exit (n);
  1374. X}
  1375. X
  1376. Xvoid
  1377. Xdo_log (fmt, a, b, c, d, e, f)
  1378. Xchar *fmt, *a, *b, *c, *d, *e, *f;
  1379. X{
  1380. X    if (logp)
  1381. X        fprintf (logp, fmt, a, b, c, d, e, f);
  1382. X    if (verbose)
  1383. X        fprintf (stderr, fmt, a, b, c, d, e, f);
  1384. X}
  1385. __END__OF__THIS__FILE__
  1386. if test -f 'INEWS/sit.c' ; then
  1387.   echo 'File INEWS/sit.c already exists, overwriting it'
  1388.   del 'INEWS/sit.c'
  1389. fi
  1390. echo Extracting \"'INEWS/sit.c'\"
  1391. sed "s/^X//" >'INEWS/sit.c' <<'__END__OF__THIS__FILE__'
  1392. X/*
  1393. X * $Log:    sit.c_v $
  1394. X * Revision 1.1  90/08/31  15:36:22  cs
  1395. X * Initial revision
  1396. X * 
  1397. X */
  1398. X# ifndef    LINT
  1399. Xstatic char rcsid[] = "$Id: sit.c_v 1.1 90/08/31 15:36:22 cs Exp $";
  1400. X# endif        LINT
  1401. X# include    <stdio.h>
  1402. X# include    <modes.h>
  1403. X# include    "inews.h"
  1404. X
  1405. Xextern char    *malloc ();
  1406. X
  1407. Xvoid
  1408. Xsave_it (st)
  1409. Xsys *st;
  1410. X{
  1411. X    char        *dir;
  1412. X    char        *buf;
  1413. X    char        *fn;
  1414. X    FILE        *fp, *fpi;
  1415. X    int        fd;
  1416. X    int        id;
  1417. X
  1418. X    dir = st->cmd + 1;
  1419. X    if (access (dir, S_IFDIR) < 0) {
  1420. X        do_log ("FATAL: %s is no directory in save_it().\n", dir);
  1421. X        return;
  1422. X    }
  1423. X    if (!(fn = malloc (strlen (dir) + 64))) {
  1424. X        do_log ("FATAL: can't alloc in save_it()\n");
  1425. X        return;
  1426. X    }
  1427. X    sprintf (fn, "%s/.seq", dir);
  1428. X    if ((fd = open (fn, S_IREAD | S_IWRITE)) < 0) {
  1429. X        fd = create (fn, S_IWRITE, 03);
  1430. X        id = 1;
  1431. X    } else {
  1432. X        if (read (fd, &id, sizeof (int)) == sizeof (int))
  1433. X            ++id;
  1434. X        lseek (fd, 0, 0);
  1435. X    }
  1436. X    if (fd != -1) {
  1437. X        write (fd, &id, sizeof (int));
  1438. X        close (fd);
  1439. X    }
  1440. X    sprintf (fn, "%s/%06d", dir, id);
  1441. X    if (fp = fopen (fn, "w")) {
  1442. X        if (buf = malloc (520)) {
  1443. X            sprintf (buf, "%s/%s", newsdir, realfile);
  1444. X            if (fpi = fopen (buf, "r")) {
  1445. X                while (fgets (buf, 512, fpi))
  1446. X                    fputs (buf, fp);
  1447. X                fclose (fpi);
  1448. X            } else
  1449. X                do_log ("Can't open %s for reading.\n", buf);
  1450. X            free (buf);
  1451. X        } else
  1452. X            do_log ("Can't alloc copy-buffer.\n");
  1453. X        fclose (fp);
  1454. X    } else
  1455. X        do_log ("Can't open output-file %s.\n", fn);
  1456. X    free (fn);
  1457. X}
  1458. __END__OF__THIS__FILE__
  1459. if test -f 'INEWS/spch.c' ; then
  1460.   echo 'File INEWS/spch.c already exists, overwriting it'
  1461.   del 'INEWS/spch.c'
  1462. fi
  1463. echo Extracting \"'INEWS/spch.c'\"
  1464. sed "s/^X//" >'INEWS/spch.c' <<'__END__OF__THIS__FILE__'
  1465. X/*
  1466. X * $Log:    spch.c_v $
  1467. X * Revision 1.2  91/05/22  13:24:52  ud
  1468. X * Added Supersedes: support
  1469. X * 
  1470. X * Revision 1.1  90/08/31  15:36:25  cs
  1471. X * Initial revision
  1472. X * 
  1473. X */
  1474. X# ifndef    LINT
  1475. Xstatic char rcsid[] = "$Id: spch.c_v 1.2 91/05/22 13:24:52 ud Exp $";
  1476. X# endif        LINT
  1477. X# include    <c8type.h>
  1478. X# include    "inews.h"
  1479. X
  1480. Xextern char    *index ();
  1481. Xextern char    *malloc ();
  1482. X
  1483. Xvoid
  1484. Xspecial_header (hd, ind)
  1485. Xcharc *hd;
  1486. Xint ind;
  1487. X{
  1488. X    register char    *p1, *p2;
  1489. X    char        *tp;
  1490. X    char        *buf;
  1491. X    charc        *tmp;
  1492. X    int        n;
  1493. X
  1494. X    switch (ind) {
  1495. X        case S_PATH:
  1496. X            p1 = skip_field (hd->text);
  1497. X# ifdef        USE_FULLHOST
  1498. X            n = strlen (fhost);
  1499. X            if ((n <= strlen (p1)) && Strneql (p1, fhost, n) && (! isalnum (p1[n])) && (p1[n] != '.'))
  1500. X                break;
  1501. X# endif        /* USE_FULLHOST */
  1502. X# ifndef    USE_ONLY_FULLHOST
  1503. X            n = strlen (hostname);
  1504. X            if ((n <= strlen (p1)) && Strneql (p1, hostname, n) && (! isalnum (p1[n])) && (p1[n] != '.'))
  1505. X                break;
  1506. X# endif        /* USE_ONLY_FULLHOST */
  1507. X            if (!(buf = malloc (strlen (hd->text) + strlen (hostname) + strlen (fhost) + 32)))
  1508. X                do_exit (_errmsg (1, "Can't alloc memory when expanding Path: field.\n"));
  1509. X            p2 = buf;
  1510. X            p1 = hd->text;
  1511. X            while (*p1 && (*p1 != ':'))
  1512. X                *p2++ = *p1++;
  1513. X            if (*p1) {
  1514. X                *p2++ = *p1++;
  1515. X                *p2++ = ' ';
  1516. X                while (is8space (*p1))
  1517. X                    ++p1;
  1518. X# ifndef    USE_ONLY_FULLHOST
  1519. X                tp = hostname;
  1520. X                while (*tp)
  1521. X                    *p2++ = *tp++;
  1522. X                *p2++ = '!';
  1523. X# endif        USE_ONLY_FULLHOST
  1524. X# ifdef        USE_FULLHOST
  1525. X                tp = fhost;
  1526. X                while (*tp)
  1527. X                    *p2++ = *tp++;
  1528. X                *p2++ = '!';
  1529. X# endif        USE_FULLHOST
  1530. X                while (*p1)
  1531. X                    *p2++ = *p1++;
  1532. X                *p2 = '\0';
  1533. X                free (hd->text);
  1534. X                hd->text = buf;
  1535. X            } else {
  1536. X                do_log ("Internal error when expanding Path: field\n");
  1537. X                do_exit (1);
  1538. X            }
  1539. X            break;
  1540. X        case S_NEWSGROUPS:
  1541. X            p1 = skip_field (hd->text);
  1542. X            ngs = split_fields (p1, TRUE);
  1543. X            if (alias_newsgroups ()) {
  1544. X                if (!ngs) {
  1545. X                    do_log ("No more Newsgroups: after alias, aborted.\n");
  1546. X                    do_exit (0);
  1547. X                }
  1548. X                if (p1 = catcharc (ngs, ",")) {
  1549. X                    insert_header (H_NEWSGROUPS, p1, TRUE);
  1550. X                    free (p1);
  1551. X                }
  1552. X            }
  1553. X            break;
  1554. X        case S_SUBJECT:
  1555. X            p1 = skip_field (hd->text);
  1556. X            if (Strnicmp (p1, "re: ", 4))
  1557. X                if (p2 = malloc (strlen (hd->text) + 10)) {
  1558. X                    sprintf (p2, "%s Re: %s", hlines[H_SUBJECT] + 2, p1);
  1559. X                    free (hd->text);
  1560. X                    hd->text = p2;
  1561. X                }
  1562. X            break;
  1563. X        case S_FOLLOWUP_TO:
  1564. X            p1 = skip_field (hd->text);
  1565. X            if (*p1) {
  1566. X                free_field (ngs);
  1567. X                ngs = NULL;
  1568. X                ngs = split_fields (p1, TRUE);
  1569. X                insert_header (H_NEWSGROUPS, p1, TRUE);
  1570. X                delete_header (H_FOLLOWUP_TO);
  1571. X            }
  1572. X            break;
  1573. X        case S_MESSAGE_ID:
  1574. X            p1 = skip_field (hd->text);
  1575. X            set_msgid (p1);
  1576. X            check_message_id (p1);
  1577. X            break;
  1578. X        case S_DISTRIBUTION:
  1579. X            p1 = skip_field (hd->text);
  1580. X            dists = split_fields (p1, TRUE);
  1581. X# ifdef        NO_DOT_IN_DIST
  1582. X            tmp = dists;
  1583. X            while (tmp) {
  1584. X                if (p1 = index (tmp->text, '.'))
  1585. X                    *p1 = '\0';
  1586. X                tmp = tmp->next;
  1587. X            }
  1588. X# endif        NO_DOT_IN_DIST
  1589. X            break;
  1590. X        case S_REFERENCES:
  1591. X            if (tmp = get_header_line (H_MESSAGE_ID)) {
  1592. X                p1 = skip_field (tmp->text);
  1593. X                if (p2 = malloc (strlen (p1) + strlen (hd->text) + 6)) {
  1594. X                    sprintf (p2, "%s %s", hd->text, p1);
  1595. X                    free (hd->text);
  1596. X                    hd->text = p2;
  1597. X                }
  1598. X            }
  1599. X            break;
  1600. X        case S_SUPERSEDES:
  1601. X            if (tmp = get_header_line (H_SUPERSEDES)) {
  1602. X                p1 = skip_field (tmp->text);
  1603. X                delete_msg (p1);
  1604. X            }
  1605. X            break;
  1606. X    }
  1607. X}
  1608. X
  1609. Xvoid
  1610. Xhandle_special (id)
  1611. Xregister int id;
  1612. X{
  1613. X    register charc    *tmp;
  1614. X    register int    found;
  1615. X    register charc    *htmp;
  1616. X    register char    *ptr;
  1617. X
  1618. X    if ((id < 0) || (id > SPECIAL_MAX))
  1619. X        return;
  1620. X    tmp = head;
  1621. X    found = FALSE;
  1622. X    while (tmp) {
  1623. X        if (Strnieql (tmp->text, slines[id], strlen (slines[id]))) {
  1624. X            special_header (tmp, id);
  1625. X            found = TRUE;
  1626. X        }
  1627. X        tmp = tmp->next;
  1628. X    }
  1629. X    if (!found)
  1630. X        switch (id) {
  1631. X            case S_TO:
  1632. X                if (!recv) {
  1633. X                    if (!(ptr = find_address ()))
  1634. X                        break;
  1635. X                    if (recv = (charc *) malloc (sizeof (charc)))
  1636. X                        if (recv->text = malloc (strlen (ptr) + strlen (hlines[H_TO] + 2) + 6)) {
  1637. X                            sprintf (recv->text, "%s %s", hlines[H_TO] + 2, ptr);
  1638. X                            recv->next = NULL;
  1639. X                        } else {
  1640. X                            free ((char *) recv);
  1641. X                            recv = NULL;
  1642. X                        }
  1643. X                    free (ptr);
  1644. X                }
  1645. X                break;
  1646. X            case S_REFERENCES:
  1647. X                if (!(tmp = (charc *) malloc (sizeof (charc))))
  1648. X                    break;
  1649. X                if (!(htmp = get_header_line (H_MESSAGE_ID))) {
  1650. X                    free ((char *) tmp);
  1651. X                    break;
  1652. X                }
  1653. X                ptr = skip_field (htmp->text);
  1654. X                insert_header (H_REFERENCES, ptr, TRUE);
  1655. X                break;
  1656. X            case S_DISTRIBUTION:
  1657. X                if ((! dists) && (crthd || ins_dist))
  1658. X                    make_default_dists ();
  1659. X                if (dists && (dists->next || Stricmp (dists->text, DST_WORLD)))
  1660. X                    if (ptr = catcharc (dists, ",")) {
  1661. X                        insert_header (H_DISTRIBUTION, ptr, TRUE);
  1662. X                        free (ptr);
  1663. X                    }
  1664. X                break;
  1665. X        }
  1666. X}
  1667. __END__OF__THIS__FILE__
  1668. if test -f 'INEWS/store.c' ; then
  1669.   echo 'File INEWS/store.c already exists, overwriting it'
  1670.   del 'INEWS/store.c'
  1671. fi
  1672. echo Extracting \"'INEWS/store.c'\"
  1673. sed "s/^X//" >'INEWS/store.c' <<'__END__OF__THIS__FILE__'
  1674. X/*
  1675. X * $Log:    store.c_v $
  1676. X * Revision 1.1  91/05/22  13:36:49  ud
  1677. X * Initial revision
  1678. X * 
  1679. X * 
  1680. X */
  1681. X# ifndef    LINT
  1682. Xstatic char rcsid[] = "$Id: store.c_v 1.1 91/05/22 13:36:49 ud Exp $";
  1683. X# endif        LINT
  1684. X# include    <stdio.h>
  1685. X# include    <ctype.h>
  1686. X# include    <errno.h>
  1687. X# include    <modes.h>
  1688. X# include    <dir.h>
  1689. X# include    "inews.h"
  1690. X
  1691. X# define    SEQ        ".seq"
  1692. X# define    TNEWS_AVAIL    "/dd/SYS/.TNews_Available"
  1693. X
  1694. Xextern char    *_prgname ();
  1695. Xextern char    *malloc ();
  1696. Xextern char    *strdup ();
  1697. Xextern FILE    *xpopen ();
  1698. X
  1699. Xstatic int
  1700. Xenter_tspool ()
  1701. X{
  1702. X    if (! newstspool) {
  1703. X        do_log ("No TSPOOL found.\n");
  1704. X        return (-1);
  1705. X    }
  1706. X    if (chdir (newstspool) < 0) {
  1707. X        do_log ("Can't chdir to %s.\n", newstspool);
  1708. X        return (-1);
  1709. X    }
  1710. X    return (0);
  1711. X}
  1712. X
  1713. Xint
  1714. Xdo_store ()
  1715. X{
  1716. X    char    *buf;
  1717. X    int    n;
  1718. X    int    fd;
  1719. X    int    tout;
  1720. X
  1721. X    if (enter_tspool () < 0)
  1722. X        return (-1);
  1723. X    if (! (buf = malloc (256))) {
  1724. X        do_log ("Can't alloc in do_store()\n");
  1725. X        return (-1);
  1726. X    }
  1727. X    tout = 10;
  1728. X    do {
  1729. X        if (((fd = open (SEQ, S_IREAD | S_IWRITE | S_ISHARE)) < 0) && (errno == E_PNNF)) {
  1730. X            if ((fd = create (SEQ, S_IWRITE | S_ISHARE, 03 | S_ISHARE)) != -1)
  1731. X                n = 0;
  1732. X        } else {
  1733. X            read (fd, &n, sizeof (int));
  1734. X            lseek (fd, 0, 0);
  1735. X        }
  1736. X        if (fd == -1)
  1737. X            sleep (1);
  1738. X    } while ((fd == -1) && (tout-- > 0));
  1739. X    if (fd == -1) {
  1740. X        do_log ("Can't open/create %s\n", SEQ);
  1741. X        free (buf);
  1742. X        return (-1);
  1743. X    }
  1744. X    if (++n < 0)
  1745. X        n = 0;
  1746. X    write (fd, &n, sizeof (int));
  1747. X    close (fd);
  1748. X    sprintf (buf, "%06d", n);
  1749. X    if ((fd = create (buf, S_IWRITE | S_ISIZE, 03, 4096)) != -1) {
  1750. X        if (crthd)
  1751. X            writeln (fd, " -h\n", 4);
  1752. X        else
  1753. X            writeln (fd, "\n", 1);
  1754. X        while ((n = read (0, buf, 256)) > 0)
  1755. X            if (write (fd, buf, n) != n) {
  1756. X                do_log ("Can't write to temp.file\n");
  1757. X                break;
  1758. X            }
  1759. X        close (fd);
  1760. X        if (n > 0)
  1761. X            fd = -1;
  1762. X    }
  1763. X    if (fd != -1) {
  1764. X        if ((fd = create (TNEWS_AVAIL, S_IWRITE, 03)) != -1)
  1765. X            close (fd);
  1766. X        return (0);
  1767. X    } else
  1768. X        return (-1);
  1769. X}
  1770. X
  1771. Xint
  1772. Xrespool (check)
  1773. Xint check;
  1774. X{
  1775. X    FILE        *pp;
  1776. X    DIR        *dp;
  1777. X    struct direct    *ent;
  1778. X    charc        *root, *cur, *prev, *tmp;
  1779. X    register char    *ptr;
  1780. X    char        *pgm;
  1781. X    char        *cmd;
  1782. X    char        *buf;
  1783. X    int        n;
  1784. X    int        fd;
  1785. X
  1786. X    if (check) {
  1787. X        if (access (TNEWS_AVAIL, 0) == -1)
  1788. X            return (0);
  1789. X        unlink (TNEWS_AVAIL);
  1790. X    }
  1791. X    if (enter_tspool () < 0)
  1792. X        return (-1);
  1793. X    if (! (dp = opendir ("."))) {
  1794. X        do_log ("Can't open %s\n", newstspool);
  1795. X        return (-1);
  1796. X    }
  1797. X    root = NULL;
  1798. X    prev = NULL;
  1799. X    while (ent = readdir (dp)) {
  1800. X        ptr = ent->d_name;
  1801. X        while (isdigit (*ptr))
  1802. X            ++ptr;
  1803. X        if (*ptr)
  1804. X            continue;
  1805. X        if (cur = (charc *) malloc (sizeof (charc)))
  1806. X            if (cur->text = strdup (ent->d_name)) {
  1807. X                cur->nr = 0;
  1808. X                cur->next = NULL;
  1809. X                if (! prev)
  1810. X                    root = cur;
  1811. X                else
  1812. X                    prev->next = cur;
  1813. X                prev = cur;
  1814. X            } else
  1815. X                free ((char *) cur);
  1816. X    }
  1817. X    closedir (dp);
  1818. X    if (! root)
  1819. X        return (-1);
  1820. X    if (! (buf = malloc (256))) {
  1821. X        do_log ("Can't alloc in respool()\n");
  1822. X        return (-1);
  1823. X    }
  1824. X    if (! (pgm = _prgname ()))
  1825. X        pgm = "inews";
  1826. X    if (! (cmd = malloc (256 + strlen (pgm) + 8)))
  1827. X        return (-1);
  1828. X    for (cur = root; cur;) {
  1829. X        if ((fd = open (cur->text, S_IREAD)) < 0)
  1830. X            continue;
  1831. X        if ((n = readln (fd, buf, 256)) <= 0) {
  1832. X            close (fd);
  1833. X            continue;
  1834. X        }
  1835. X        buf[n - 1] = '\0';
  1836. X        sprintf (cmd, "%s%s", pgm, buf);
  1837. X        if (! (pp = xpopen (cmd, "w"))) {
  1838. X            close (fd);
  1839. X            continue;
  1840. X        }
  1841. X        while ((n = read (fd, buf, 256)) > 0)
  1842. X            if (fwrite (buf, sizeof (char), n, pp) != n)
  1843. X                break;
  1844. X        close (fd);
  1845. X        if (pclose (pp))
  1846. X            n = 1;
  1847. X        if (! n)
  1848. X            unlink (cur->text);
  1849. X        tmp = cur;
  1850. X         cur = cur->next;
  1851. X         free (tmp -> text);
  1852. X        free ((char *) tmp);
  1853. X    }
  1854. X    free (buf);
  1855. X    free (cmd);
  1856. X    return (0);
  1857. X}
  1858. __END__OF__THIS__FILE__
  1859. if test -f 'INEWS/tsys.c' ; then
  1860.   echo 'File INEWS/tsys.c already exists, overwriting it'
  1861.   del 'INEWS/tsys.c'
  1862. fi
  1863. echo Extracting \"'INEWS/tsys.c'\"
  1864. sed "s/^X//" >'INEWS/tsys.c' <<'__END__OF__THIS__FILE__'
  1865. X/*
  1866. X * $Log:    tsys.c_v $
  1867. X * Revision 1.2  91/09/11  18:16:52  ud
  1868. X * Moved macro is_part_of_hostname to inews.h
  1869. X * 
  1870. X * Revision 1.1  90/08/31  15:36:30  cs
  1871. X * Initial revision
  1872. X * 
  1873. X */
  1874. X# ifndef    LINT
  1875. Xstatic char rcsid[] = "$Id: tsys.c_v 1.2 91/09/11 18:16:52 ud Exp $";
  1876. X# endif        LINT
  1877. X# include    <c8type.h>
  1878. X# include    <string.h>
  1879. X# include    "inews.h"
  1880. X
  1881. Xextern char    *malloc ();
  1882. Xextern char    *rindex ();
  1883. X
  1884. Xint
  1885. Xis_system_in_path (path, system)
  1886. Xregister char *path;
  1887. Xregister char *system;
  1888. X{
  1889. X    register char    *ptr;
  1890. X    register int    is_in;
  1891. X
  1892. X    is_in = FALSE;
  1893. X    if ((ptr = strstr (path, system)) && (strlen (ptr) >= strlen (system)))
  1894. X        if ((ptr == path) || ((ptr > path) && (!is_part_of_hostname (*(ptr-1))))) {
  1895. X            ptr += strlen (system);
  1896. X            if (!is_part_of_hostname (*ptr))
  1897. X                is_in = TRUE;
  1898. X        }
  1899. X    return (is_in);
  1900. X}
  1901. X
  1902. Xvoid
  1903. Xtest_systems ()
  1904. X{
  1905. X    register sys    *stmp;
  1906. X    register int    t;
  1907. X    int        found, isok;
  1908. X    charc        *ntmp;
  1909. X    charc        *htmp;
  1910. X    char        *path;
  1911. X    int        inv;
  1912. X    charc        *dtmp;
  1913. X    char        *buf, *ptr;
  1914. X    int        size;
  1915. X    
  1916. X    if (!(htmp = get_header_line (H_PATH))) {
  1917. X        do_log ("FATAL: Can't get Path: field!\n");
  1918. X        return;
  1919. X    }
  1920. X    path = skip_field (htmp->text);
  1921. X    for (ntmp = ngs, size = 0; ntmp; ntmp = ntmp->next)
  1922. X        if ((t = strlen (ntmp->text)) > size)
  1923. X            size = t;
  1924. X    if (!(buf = malloc (size + 10))) {
  1925. X        do_log ("FATAL: Can't alloc for control-check\n");
  1926. X        return;
  1927. X    }
  1928. X    stmp = hsys;
  1929. X    while (stmp) {
  1930. X        /*
  1931. X         *    Test if System is in Path:
  1932. X         */
  1933. X        isok = TRUE;
  1934. X        if (is_system_in_path (path, stmp->site))
  1935. X            isok = FALSE;
  1936. X        else if (stmp->wsites)
  1937. X            for (t=0;stmp->wsites[t];++t)
  1938. X                if (is_system_in_path (path, stmp->wsites[t])) {
  1939. X                    isok = FALSE;
  1940. X                    break;
  1941. X                }
  1942. X        if (!isok) {
  1943. X            stmp = stmp->next;
  1944. X            continue;
  1945. X        }
  1946. X
  1947. X        /*
  1948. X         *    Test newsgroups-part
  1949. X         */
  1950. X        found = FALSE;
  1951. X        ntmp = ngs;
  1952. X        while (ntmp) {
  1953. X            if (buf) {
  1954. X                strcpy (buf, ntmp->text);
  1955. X                if ((ptr = rindex (buf, '.')) && (Strieql (ptr, CTRL_POSTFIX)))
  1956. X                    *ptr = '\0';
  1957. X            }
  1958. X            for (t=0;stmp->grps[t];++t)
  1959. X                if (regexec (stmp->grps[t], ntmp->text) ||
  1960. X                    (buf && regexec (stmp->grps[t], buf))) {
  1961. X                    found = TRUE;
  1962. X                    inv = stmp->inv[t];
  1963. X                    break;
  1964. X                }
  1965. X            if (found)
  1966. X                break;
  1967. X            ntmp = ntmp->next;
  1968. X        }
  1969. X        if ((!found) || inv) {
  1970. X            stmp = stmp->next;
  1971. X            continue;
  1972. X        }
  1973. X
  1974. X        /*
  1975. X         *    Now check distribution at least
  1976. X         */
  1977. X        inv = FALSE;
  1978. X        if (stmp->dist && dists) {
  1979. X            found = FALSE;
  1980. X            dtmp = dists;
  1981. X            while (dtmp) {
  1982. X                for (t=0;stmp->dist[t];++t)
  1983. X                    if (stmp->dist[t][0] == '!') {
  1984. X                        if (_cmpnam (dtmp->text, stmp->dist[t] + 1, strlen (stmp->dist[t] + 1)) == 0) {
  1985. X                            found = TRUE;
  1986. X                            inv = TRUE;
  1987. X                        }
  1988. X                    } else if (_cmpnam (dtmp->text, stmp->dist[t], strlen (stmp->dist[t])) == 0) {
  1989. X                        found = TRUE;
  1990. X                        break;
  1991. X                    }
  1992. X                if (found)
  1993. X                    break;
  1994. X                dtmp = dtmp->next;
  1995. X            }
  1996. X# ifndef    ALWAYS_DIST_WORLD
  1997. X        } else if (stmp->dist) {
  1998. X            found = FALSE;
  1999. X            for (t=0;stmp->dist[t];++t)
  2000. X                if (_cmpnam (DST_WORLD, stmp->dist[t], strlen (stmp->dist[t])) == 0) {
  2001. X                    found = TRUE;
  2002. X                    break;
  2003. X                }
  2004. X# endif        /* ALWAYS_DIST_WORLD */
  2005. X        } else
  2006. X            found = TRUE;
  2007. X        if (found && (!inv))
  2008. X            stmp->fwd = TRUE;
  2009. X        stmp = stmp->next;
  2010. X    }
  2011. X    if (buf)
  2012. X        free (buf);
  2013. X}
  2014. X
  2015. __END__OF__THIS__FILE__
  2016. exit 0
  2017. : end of shell archive
  2018.  
  2019. -- 
  2020. Frank Kaefer # fkk@stasys.sta.sub.org # Starnberg, Germany
  2021.