home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part08 / common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  26.4 KB  |  957 lines

  1. /* $Id: common.h,v 4.4.2.1 1991/12/01 18:05:42 sob PATCH_2 sob $
  2.  * 
  3.  * $Log: common.h,v $
  4.  * Revision 4.4.2.1  1991/12/01  18:05:42  sob
  5.  * Patchlevel 2 changes
  6.  *
  7.  * Revision 4.4  1991/09/09  20:18:23  sob
  8.  * release 4.4
  9.  *
  10.  *
  11.  *
  12.  */
  13. /* This software is Copyright 1991 by Stan Barber. 
  14.  *
  15.  * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  16.  * use this software as long as: there is no monetary profit gained
  17.  * specifically from the use or reproduction of this software, it is not
  18.  * sold, rented, traded or otherwise marketed, and this copyright notice is
  19.  * included prominently in any copy made. 
  20.  *
  21.  * The author make no claims as to the fitness or correctness of this software
  22.  * for any use whatsoever, and it is provided as is. Any use of this software
  23.  * is at the user's own risk. 
  24.  */
  25. #include <stdio.h>
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <ctype.h>
  29. #include "config.h"    /* generated by installation script */
  30. #ifdef WHOAMI
  31. #    include <whoami.h>
  32. #endif
  33. #ifndef isalnum
  34. #   define isalnum(c) (isalpha(c) || isdigit(c))
  35. #endif
  36.  
  37. #include <errno.h>
  38. #include <signal.h>
  39. #ifdef IOCTL
  40. #include <sys/ioctl.h>
  41. #endif
  42. #ifdef SUNOS4
  43. # ifdef sparc        /* needed to support vfork call on sparc machines */
  44. #  include <vfork.h>
  45. # endif
  46. #endif
  47.  
  48. #ifdef FCNTL
  49. #   include <fcntl.h>
  50. #endif
  51.  
  52. #ifdef TERMIO
  53. #   include <termio.h>
  54. #else
  55. # ifdef TERMIOS
  56. #   include <termios.h>
  57. # else
  58. #   include <sgtty.h>
  59. # endif
  60. #endif
  61.  
  62. #ifdef GETPWENT
  63. #   include <pwd.h>
  64. #endif
  65.  
  66. #ifdef PTEM
  67. #include <sys/stream.h>
  68. #include <sys/ptem.h>
  69. #endif
  70.  
  71. #define BITSPERBYTE 8
  72. #ifdef pdp11
  73. #define LBUFLEN 512    /* line buffer length */
  74. #else
  75. #define LBUFLEN 1024    /* line buffer length */
  76. #endif
  77.             /* (don't worry, .newsrc lines can exceed this) */
  78. #ifdef pdp11
  79. #   define CBUFLEN 256    /* command buffer length */
  80. #   define PUSHSIZE 128
  81. #else
  82. #   define CBUFLEN 512    /* command buffer length */
  83. #   define PUSHSIZE 256
  84. #endif
  85. #ifdef pdp11
  86. #   define MAXFILENAME 128
  87. #else
  88. #   define MAXFILENAME 512
  89. #endif
  90. #define LONGKEY 15    /* longest keyword: currently "posting-version" */
  91. #define FINISHCMD 0177
  92.  
  93. /* some handy defs */
  94.  
  95. #define bool char
  96. #define bool_int int
  97. #define char_int int
  98. #ifndef TRUE
  99. #define TRUE (1)
  100. #endif
  101. #ifndef FALSE
  102. #define FALSE (0)
  103. #endif
  104. #define Null(t) ((t)0)
  105. #define Nullch Null(char *)
  106. #define Nullfp Null(FILE *)
  107.  
  108. #define Ctl(ch) (ch & 037)
  109.  
  110. #define strNE(s1,s2) (strcmp(s1,s2))
  111. #define strEQ(s1,s2) (!strcmp(s1,s2))
  112. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  113. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  114.  
  115. /* Things we can figure out ourselves */
  116.  
  117. #ifdef SIGTSTP
  118. #   define BERKELEY     /* include job control signals? */
  119. #endif
  120.  
  121. #ifdef FIONREAD
  122. #   define PENDING
  123. #else
  124. #   ifdef O_NDELAY
  125. #    define PENDING
  126. #   endif
  127. #endif
  128.  
  129. #ifdef EUNICE
  130. #   define LINKART        /* add 1 level of possible indirection */
  131. #   define UNLINK(victim) while (!unlink(victim))
  132. #else
  133. #   define UNLINK(victim) unlink(victim)
  134. #endif
  135.  
  136. /* Valid substitutions for strings marked with % comment are:
  137.  *    %a    Current article number
  138.  *    %A    Full name of current article (%P/%c/%a)
  139.  *        (if LINKART defined, is the name of the real article)
  140.  *    %b    Destination of a save command, a mailbox or command
  141.  *    %B    The byte offset to the beginning of the article for saves
  142.  *        with or without the header
  143.  *    %c    Current newsgroup, directory form
  144.  *    %C    Current newsgroup, dot form
  145.  *    %d    %P/%c
  146.  *    %D    Old Distribution: line
  147.  *    %e    Extract program
  148.  *    %E    Extract destination directory
  149.  *    %f    Old From: line or Reply-To: line
  150.  *    %F    Newsgroups to followup to from Newsgroups: and Followup-To:
  151.  *    %h    Name of header file to pass to mail or news poster
  152.  *    %H    Host name (yours)
  153.  *    %i    Old Message-I.D.: line, with <>
  154.  *    %I    Inclusion indicator
  155.  *    %l    News administrator login name
  156.  *    %L    Login name (yours)
  157.  *    %M    Number of articles marked with M
  158.  *    %n    Newsgroups from source article
  159.  *    %N    Full name (yours)
  160.  *    %o    Organization (yours)
  161.  *    %O    Original working directory (where you ran rn from)
  162.  *    %p    Your private news directory (-d switch)
  163.  *    %P    Public news spool directory (SPOOLDIR)
  164.  *    %r    Last reference (parent article id)
  165.  *    %R    New references list
  166.  *    %s    Subject, with all Re's and (nf)'s stripped off
  167.  *    %S    Subject, with one Re stripped off
  168.  *    %t    New To: line derived from From: and Reply-To (Internet always)
  169.  *    %T    New To: line derived from Path:
  170.  *    %u    Number of unread articles
  171.  *    %U    Number of unread articles disregarding current article
  172.  *    %v    Number of unselected articles disregarding current article
  173.  *    %w    Mthreads' tmp directory
  174.  *    %W    The thread directory root
  175.  *    %x    News library directory, usually /usr/lib/news
  176.  *    %X    Rn library directory, usually %x/rn
  177.  *    %z    Size of current article in bytes.
  178.  *    %Z    Number of selected threads.
  179.  *    %~    Home directory
  180.  *    %.    Directory containing . files
  181.  *    %#    count of articles saved in current command (from 1 to n)
  182.  *    %$    current process number
  183.  *    %{name} Environment variable "name".  %{name-default} form allowed.
  184.  *    %[name]    Header line beginning with "Name: ", without "Name: " 
  185.  *    %"prompt"
  186.  *        Print prompt and insert what is typed.
  187.  *    %`command`
  188.  *        Insert output of command.
  189.  *    %(test_text=pattern?if_text:else_text)
  190.  *        Substitute if_text if test_text matches pattern, otherwise
  191.  *        substitute else_text.  Use != for negated match.
  192.  *        % substitutions are done on test_text, if_text, and else_text.
  193.  *        (Note: %() only works if CONDSUB defined.)
  194.  *    %digit    Substitute the text matched by the nth bracket in the last
  195.  *        pattern that had brackets.  %0 matches the last bracket
  196.  *        matched, in case you had alternatives.
  197.  *
  198.  *    Put ^ in the middle to capitalize the first letter: %^C = Net.jokes
  199.  *    Put _ in the middle to capitalize last component: %_c = net/Jokes
  200.  *
  201.  *    ~ interpretation in filename expansion happens after % expansion, so
  202.  *    you could put ~%{NEWSLOGNAME-news} and it will expand correctly.
  203.  */
  204.  
  205. /* *** System Dependent Stuff *** */
  206.  
  207. /* NOTE: many of these are defined in the config.h file */
  208.  
  209. /* name of organization */
  210. #ifndef ORGNAME
  211. #   define ORGNAME "ACME Widget Company, Widget Falls, Southern North Dakota"
  212. #endif
  213.  
  214. #ifndef MBOXCHAR
  215. #   define MBOXCHAR 'F'    /* how to recognize a mailbox by 1st char */
  216. #endif
  217.  
  218. #ifndef ROOTID
  219. #   define ROOTID 0        /* uid of superuser */
  220. #endif
  221.  
  222. #ifdef NORMSIG
  223. #   define sigset signal
  224. #   define sigignore(sig) signal(sig,SIG_IGN)
  225. #endif
  226.  
  227. #ifndef LOGDIRFIELD
  228. #   define LOGDIRFIELD 6        /* Which field (origin 1) is the */
  229.                     /* login directory in /etc/passwd? */
  230.                     /* (If it is not kept in passwd, */
  231.                     /* but getpwnam() returns it, */
  232.                     /* define the symbol GETPWENT) */
  233. #endif
  234. #ifndef GCOSFIELD
  235. #   define GCOSFIELD 5
  236. #endif
  237.  
  238. #ifndef NEGCHAR
  239. #   define NEGCHAR '!'
  240. #endif
  241.  
  242. /* Space conservation section */
  243.  
  244. /* To save D space, cut down size of NGMAX and  VARYSIZE. */
  245. #define NGMAX 100    /* number of newsgroups allowed on command line */
  246.             /* undefine ONLY symbol to disable "only" feature */
  247. #define VARYSIZE 256    /* this makes a block 1024 bytes long in DECville */
  248.             /* (used by virtual array routines) */
  249.  
  250. /* Undefine any of the following features to save both I and D space */
  251. /* In general, earlier ones are easier to get along without */
  252. /* Pdp11's without split I and D may have to undefine them all */
  253. #define DEBUGGING    /* include debugging code */
  254. #define USETHREADS    /* Add article-thread following */
  255. #define CUSTOMLINES    /* include code for HIDELINE and PAGESTOP */
  256. #define PUSHBACK    /* macros and keymaps using pushback buffer */
  257. #define SPEEDOVERMEM    /* use more memory to run faster */
  258. #define WORDERASE    /* enable ^W to erase a word */
  259. #define MAILCALL    /* check periodically for mail */
  260. #define CLEAREOL    /* use clear to end-of-line instead of clear screen */
  261. #define NOFIREWORKS    /* keep whole screen from flashing on certain */
  262.             /* terminals such as older Televideos */
  263. #define VERIFY        /* echo the command they just typed */
  264. #define HASHNG        /* hash newsgroup lines for fast lookup-- */
  265.             /* linear search used if not defined */
  266. #define CONDSUB        /* allow %(cond?text:text) */
  267. #define BACKTICK    /* allow %`command` */
  268. #define PROMPTTTY    /* allow %"prompt" */
  269. #define ULSMARTS    /* catch _^H in text and do underlining */
  270. #define TERMMOD        /* allow terminal type modifier on switches */
  271. #define BAUDMOD        /* allow baudrate modifier on switches */
  272. #define GETLOGIN    /* use getlogin() routine as backup to environment */
  273.             /* variables USER or LOGNAME */
  274. #define ORGFILE        /* if organization begins with /, look up in file */
  275. #define TILDENAME    /* allow ~logname expansion */
  276. #define SETENV        /* allow command line environment variable setting */
  277. #define MAKEDIR        /* use our makedir() instead of shell script */
  278. #define MEMHELP        /* keep help messages in memory */
  279. #define VERBOSE        /* compile in more informative messages */
  280. #define TERSE        /* compile in shorter messages */
  281.             /* (Note: both VERBOSE and TERSE can be defined; -t
  282.              * sets terse mode.  One or the other MUST be defined.
  283.              */
  284. #ifndef pdp11
  285. #   define CACHESUBJ    /* cache subject lines in memory */
  286.             /* without this ^N still works but runs really slow */
  287.             /* but you save lots and lots of D space */
  288. #   define CACHEFIRST    /* keep absolute first article numbers in memory */
  289.             /* cost: about 2k */
  290. #endif
  291. #define ROTATION    /* enable x, X and ^X commands to work */
  292. #define DELBOGUS    /* ask if bogus newsgroups should be deleted */
  293. #define RELOCATE    /* allow newsgroup rearranging */
  294. #define ESCSUBS        /* escape substitutions in multi-character commands */
  295. #define DELAYMARK    /* allow articles to be temporarily marked as read */
  296.             /* until exit from current newsgroup or Y command */
  297. #undef MCHASE        /* unmark xrefed articles on m or M */
  298. #define MUNGHEADER    /* allow alternate header formatting via */
  299.             /* environment variable ALTHEADER (not impl) */
  300. #define ASYNC_PARSE    /* allow parsing headers asyncronously to reading */
  301.             /* used by MCHASE and MUNGHEADER */
  302. #define FINDNEWNG    /* check for new newsgroups on startup */
  303. #define FASTNEW        /* do optimizations on FINDNEWNG for faster startup */
  304.             /* (this optimization can make occasional mistakes */
  305.             /* if a group is removed and another group of the */
  306.             /* same length is added, and if no softpointers are */
  307.             /* affected by said change.) */
  308. #define INNERSEARCH    /* search command 'g' with article */
  309. #define CATCHUP        /* catchup command at newsgroup level */
  310. #define NGSEARCH    /* newsgroup pattern matching */
  311. #define ONLY        /* newsgroup restrictions by pattern */
  312. #define KILLFILES    /* automatic article killer files */
  313. #define ARTSEARCH    /* pattern searches among articles */
  314.             /* /, ?, ^N, ^P, k, K */
  315.  
  316. /* some dependencies among options */
  317.  
  318. #ifndef ARTSEARCH
  319. #   undef KILLFILES
  320. #   undef INNERSEARCH
  321. #   undef CACHESUBJ
  322. #endif
  323.  
  324. #ifndef DELAYMARK
  325. #   ifndef MCHASE
  326. #    ifndef MUNGHEADER
  327. #        undef ASYNC_PARSE
  328. #    endif
  329. #   endif
  330. #endif
  331.  
  332. #ifndef SETUIDGID
  333. #   define eaccess access
  334. #endif
  335.  
  336. #ifdef ONLY                /* idiot lint doesn't grok #if */
  337. #   define NGSORONLY
  338. #else
  339. #   ifdef NGSEARCH
  340. #    define NGSORONLY
  341. #   endif
  342. #endif
  343.  
  344. #ifdef VERBOSE
  345. #   ifdef TERSE
  346. #    define IF(c) if (c)
  347. #    define ELSE else
  348. #   else
  349. #    define IF(c)
  350. #    define ELSE
  351. #   endif
  352. #else /* !VERBOSE */
  353. #   ifndef TERSE
  354. #    define TERSE
  355. #   endif
  356. #   define IF(c) "IF" outside of VERBOSE???
  357. #   define ELSE "ELSE" outside of VERBOSE???
  358. #endif
  359.  
  360. #ifdef DEBUGGING
  361. #   define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);sig_catcher(0);}}
  362. #else
  363. #   define assert(ex) ;
  364. #endif
  365.  
  366. #ifdef SPEEDOVERMEM
  367. #   define OFFSET(x) (x)
  368. #else
  369. #   define OFFSET(x) ((x)-absfirst)
  370. #endif
  371.  
  372. /* If you're strapped for space use the help messages in shell scripts */
  373. /* if {NG,ART,PAGER,SUBS}HELP is undefined, help messages are in memory */
  374. #ifdef MEMHELP  /* undef MEMHELP above to get them all as sh scripts */
  375. #   undef NGHELP
  376. #   undef ARTHELP
  377. #   undef PAGERHELP
  378. #   undef SUBSHELP
  379. #else
  380. #   ifndef NGHELP            /* % and ~ */
  381. #    define NGHELP "%X/ng.help"
  382. #   endif
  383. #   ifndef ARTHELP            /* % and ~ */
  384. #    define ARTHELP "%X/art.help"
  385. #   endif
  386. #   ifndef PAGERHELP        /* % and ~ */
  387. #    define PAGERHELP "%X/pager.help"
  388. #   endif
  389. #   ifndef SUBSHELP        /* % and ~ */
  390. #    define SUBSHELP "%X/subs.help"
  391. #   endif
  392. #endif
  393.  
  394. #ifdef CLEAREOL
  395. #   define TCSIZE 512    /* capacity for termcap strings */
  396. #else
  397. #   ifdef pdp11
  398. #    define TCSIZE 256    /* capacity for termcap strings */
  399. #   else
  400. #    define TCSIZE 512    /* capacity for termcap srings */
  401. #   endif
  402. #endif
  403.  
  404. /* Additional ideas:
  405.  *    Make the do_newsgroup() routine a separate process.
  406.  *    Keep .newsrc on disk instead of in memory.
  407.  *    Overlays, if you have them.
  408.  *    Get a bigger machine.
  409.  */
  410.  
  411. /* End of Space Conservation Section */
  412.  
  413. /* More System Dependencies */
  414.  
  415. /* news library */
  416. #ifndef LIB        /* ~ and %l only ("~%l" is permissable) */
  417. #   define LIB "/usr/lib/news"
  418. #endif
  419.  
  420. /* path to private executables */
  421. #ifndef RNLIB        /* ~, %x and %l only */
  422. #   define RNLIB "%x/trn"
  423. #endif
  424.  
  425. /* system-wide RNINIT switches */
  426. #ifndef GLOBINIT
  427. #   define GLOBINIT "%X/INIT"
  428. #endif
  429.  
  430. /* where to find news files */
  431. #ifndef SPOOL            /* % and ~ */
  432. #   define SPOOL "/usr/spool/news"
  433. #endif
  434.  
  435. #ifdef USETHREADS
  436. # ifdef THREAD_DIR
  437. #   ifdef LONG_THREAD_NAMES
  438. #    undef SUFFIX
  439. #   else
  440. #     ifndef SUFFIX
  441. #    define SUFFIX ".th"
  442. #     endif
  443. #   endif
  444. # else
  445. #   define THREAD_DIR    SPOOL
  446. #   ifndef SUFFIX
  447. #     define SUFFIX    "/.thread"
  448. #   endif
  449. #   undef LONG_THREAD_NAMES
  450. # endif
  451. # ifndef NEW_THREAD
  452. #   define NEW_THREAD ".new"
  453. # endif
  454. #endif
  455.  
  456. /* default characters to use in the selection menu */
  457. #ifndef SELECTCHARS
  458. #   define SELECTCHARS "abcdefgijlorstuvwxz1234567890"
  459. #endif
  460.  
  461. /* file containing list of active newsgroups and max article numbers */
  462. #ifndef ACTIVE            /* % and ~ */
  463. #   define ACTIVE "%x/active"
  464. #endif
  465. #ifdef SERVER
  466. #   ifndef ACTIVE1
  467. #    define ACTIVE1 "%w/active1"
  468. #   endif
  469. #endif
  470. #ifndef ACTIVE2
  471. #   define ACTIVE2 "%w/active2"
  472. #endif
  473. #ifndef DBINIT
  474. #   define DBINIT "%W/db.init"
  475. #endif
  476. #ifndef MTPRELOCK
  477. #   define MTPRELOCK "%w/LOCK"
  478. #endif
  479. #ifndef MTLOCK
  480. #   define MTLOCK "%w/LOCKmthreads"
  481. #endif
  482. #ifndef MTDLOCK
  483. #   define MTDLOCK "%w/LOCKmtdaemon"
  484. #endif
  485. #ifndef MTLOG
  486. #   define MTLOG "%w/mt.log"
  487. #endif
  488.  
  489. #if !defined(SERVER) && defined(XTHREAD)
  490. #   undef XTHREAD
  491. #endif
  492.  
  493. /* location of history file */
  494. #ifndef ARTFILE            /* % and ~ */
  495. #    define ARTFILE "%x/history"
  496. #endif
  497.  
  498. /* command to setup a new .newsrc */
  499. #ifndef NEWSETUP        /* % and ~ */
  500. #   define NEWSETUP "newsetup"
  501. #endif
  502.  
  503. /* command to display a list of un-subscribed-to newsgroups */
  504. #ifndef NEWSGROUPS        /* % and ~ */
  505. #   define NEWSGROUPS "newsgroups"
  506. #endif
  507.  
  508. /* preferred shell for use in doshell routine */
  509. /*  ksh or sh would be okay here */
  510. #ifndef PREFSHELL
  511. #   define PREFSHELL "/bin/csh"
  512. #endif
  513.  
  514. /* path to fastest starting shell */
  515. #ifndef SH
  516. #   define SH "/bin/sh"
  517. #endif
  518.  
  519. /* default unshar'ing program */
  520. #ifndef UNSHAR
  521. #   define UNSHAR "/bin/sh"
  522. #endif
  523.  
  524. /* path to default editor */
  525. #ifndef DEFEDITOR
  526. #   define DEFEDITOR "/usr/ucb/vi"
  527. #endif
  528.  
  529. /* location of macro file */
  530. #ifndef RNMACRO
  531. #   ifdef PUSHBACK
  532. #    define RNMACRO "%./.rnmac"
  533. #   endif
  534. #endif
  535.  
  536. /* location of full name */
  537. #ifndef FULLNAMEFILE
  538. #   ifndef PASSNAMES
  539. #    define FULLNAMEFILE "%./.fullname"
  540. #   endif
  541. #endif
  542.  
  543. /* virtual array file name template */
  544. #ifndef VARYNAME        /* % and ~ */
  545. #   define VARYNAME "/tmp/rnvary.%$"
  546. #endif
  547.  
  548. /* where to compile a new newsgroup list */
  549. #ifndef RNEWNAME
  550. #   define RNEWNAME "/tmp/rnew.%$"
  551. #endif
  552.  
  553. /* file to pass header to followup article poster */
  554. #ifndef HEADNAME        /* % and ~ */
  555. #   define HEADNAME "%./.rnhead"
  556. /* or alternately #define HEADNAME "/tmp/rnhead.%$" */
  557. #endif
  558.  
  559. #ifndef MAKEDIR
  560. /* shell script to make n-deep subdirectories */
  561. #   ifndef DIRMAKER        /* % and ~ */
  562. #    define DIRMAKER "%X/makedir"
  563. #   endif
  564. #endif
  565.  
  566. /* location of newsrc file */
  567. #ifndef RCNAME        /* % and ~ */
  568. #   define RCNAME "%./.newsrc"
  569. #endif
  570.  
  571. /* temporary newsrc file in case we crash while writing out */
  572. #ifndef RCTNAME        /* % and ~ */
  573. #   define RCTNAME "%./.newnewsrc"
  574. #endif
  575.  
  576. /* newsrc file at the beginning of this session */
  577. #ifndef RCBNAME        /* % and ~ */
  578. #   define RCBNAME "%./.oldnewsrc"
  579. #endif
  580.  
  581. /* if existent, contains process number of current or crashed rn */
  582. #ifndef LOCKNAME        /* % and ~ */
  583. #   define LOCKNAME "%./.rnlock"
  584. #endif
  585.  
  586. /* information from last invocation of rn */
  587. #ifndef LASTNAME        /* % and ~ */
  588. #   define LASTNAME "%./.rnlast"
  589. #endif
  590.  
  591. /* file with soft pointers into the active file */
  592. #ifndef SOFTNAME        /* % and ~ */
  593. #   define SOFTNAME "%./.rnsoft"
  594. #endif
  595.  
  596. /* list of article numbers to mark as unread later (see M and Y cmmands) */
  597. #ifndef RNDELNAME        /* % and ~ */
  598. #   define RNDELNAME "%./.rndelay"
  599. #endif
  600.  
  601. /* a motd-like file for rn */
  602. #ifndef NEWSNEWSNAME        /* % and ~ */
  603. #   define NEWSNEWSNAME "%X/newsnews"
  604. #endif
  605.  
  606. /* command to send a reply */
  607. #ifndef MAILPOSTER        /* % and ~ */
  608. #   define MAILPOSTER "Rnmail -h %h"
  609. #endif
  610.  
  611. #ifdef INTERNET
  612. #   ifndef MAILHEADER        /* % */
  613. #    ifdef CONDSUB
  614. #        define MAILHEADER "To: %t\nSubject: Re: %S\nNewsgroups: %n\nIn-Reply-To: %i\n%(%[references]!=^$?References\\: %[references]\n)Organization: %o\nCc: \nBcc: \n\n"
  615. #    else
  616. #        define MAILHEADER "To: %t\nSubject: Re: %S\nNewsgroups: %n\nIn-Reply-To: %i\nReferences: %[references]\nCc: \nBcc: \n\n"
  617. #    endif
  618. #   endif
  619. #else
  620. #   ifndef MAILHEADER        /* % */
  621. #    ifdef CONDSUB
  622. #        define MAILHEADER "To: %T\nSubject: %(%i=^$?:Re: %S\nNewsgroups: %n\nIn-Reply-To: %i)\n%(%[references]!=^$?References\\: %[references]\n)Organization: %o\nCc: \nBcc: \n\n"
  623. #    else
  624. #        define MAILHEADER "To: %T\nSubject: Re: %S\nNewsgroups: %n\nIn-Reply-To: %i\nReferences: %[references]\nCc: \nBcc: \n\n"
  625. #    endif
  626. #   endif
  627. #endif
  628.  
  629. #ifndef YOUSAID            /* % */
  630. #   define YOUSAID "In article %i you write:"
  631. #endif
  632.  
  633. /* command to submit a followup article */
  634. #ifndef NEWSPOSTER        /* % and ~ */
  635. #   define NEWSPOSTER "Pnews -h %h"
  636. #endif
  637.  
  638. #ifndef NEWSHEADER        /* % */
  639. #   ifdef CONDSUB
  640. #ifdef INTERNET
  641. #    define NEWSHEADER "Newsgroups: %(%F=^$?%C:%F)\nSubject: %(%S=^$?%\"\n\nSubject: \":Re: %S)\nSummary: \nExpires: \n%(%R=^$?:References: %R\n)Sender: \nFollowup-To: \nDistribution: %(%i=^$?%\"Distribution: \":%D)\nOrganization: %o\nKeywords: %[keywords]\n\n"
  642. #else
  643. #    define NEWSHEADER "Newsgroups: %(%F=^$?%C:%F)\nSubject: %(%S=^$?%\"\n\nSubject: \":Re: %S)\nSummary: \nExpires: \n%(%R=^$?:References: %R\n)Sender: \nFollowup-To: \nDistribution: %(%i=^$?%\"Distribution: \":%D)\nOrganization: %o\nKeywords: %[keywords]\n\n"
  644. #endif
  645. #   else
  646. #    ifdef INTERNET
  647. #        define NEWSHEADER "Newsgroups: %F\nSubject: Re: %S\nSummary: \nExpires: \nReferences: %R\nSender: \nFollowup-To: \nDistribution: %D\nOrganization: %o\nKeywords: %[keywords]\n\n"
  648. #    else
  649. #        define NEWSHEADER "Newsgroups: %F\nSubject: Re: %S\nSummary: \nExpires: \nReferences: %R\nSender: \nFollowup-To: \nDistribution: %D\nOrganization: %o\nKeywords: %[keywords]\n\n"
  650. #    endif
  651. #   endif
  652. #endif
  653.  
  654. #ifndef ATTRIBUTION        /* % */
  655. #   define ATTRIBUTION "In article %i %f writes:"
  656. #endif
  657.  
  658. #ifndef PIPESAVER        /* % */
  659. #   ifdef CONDSUB
  660. #       ifdef SERVER
  661. #               define PIPESAVER "%(%B=^0$?<%P/rrn%a.%$:tail +%Bc %P/rrn%a.%$ |) %b"
  662. #       else
  663. #        define PIPESAVER "%(%B=^0$?<%A:tail +%Bc %A |) %b"
  664. #    endif
  665. #   else
  666. #       ifdef SERVER
  667. #               define PIPESAVER "tail +%Bc %P/rrn%a.%$ | %b"
  668. #       else
  669. #        define PIPESAVER "tail +%Bc %A | %b"
  670. #    endif
  671. #   endif
  672. #endif
  673.  
  674. #ifndef EXSAVER
  675. #    ifdef SERVER
  676. #    define EXSAVER "tail +%Bc %P/rrn%a.%$ | %e"
  677. #    else
  678. #    define EXSAVER "tail +%Bc %A | %e"
  679. #    endif
  680. #endif
  681.  
  682. #ifndef NORMSAVER        /* % and ~ */
  683. #    ifdef SERVER
  684. #    define NORMSAVER "%X/norm.saver %P/rrn%a.%$ %P %c %a %B %C \"%b\""
  685. #    else
  686. #       define NORMSAVER "%X/norm.saver %A %P %c %a %B %C \"%b\""
  687. #    endif
  688. #endif
  689.  
  690. #ifndef MBOXSAVER        /* % and ~ */
  691. #   ifdef MININACT        /* 2.10.2 site? */
  692. #       ifdef SERVER
  693. #           define MBOXSAVER "%X/mbox.saver %P/rrn%a.%$ %P %c %a %B %C \"%b\" \"From %T %`date`\""
  694. #       else
  695. #        define MBOXSAVER "%X/mbox.saver %A %P %c %a %B %C \"%b\" \"From %T %`date`\""
  696. #    endif
  697. #   else
  698. #    ifdef CONDSUB
  699. #           ifdef SERVER
  700. #               define MBOXSAVER "%X/mbox.saver %P/rrn%a.%$ %P %c %a %B %C \"%b\" \"From %T %(%[date]=^\\(\\w*\\), \\(\\w*\\)-\\(\\w*\\)-\\(\\w*\\) \\([^ ]*\\)?%1 %3 %(%2=..?%2: %2) %5 19%4)\""
  701. #           else
  702. #            define MBOXSAVER "%X/mbox.saver %A %P %c %a %B %C \"%b\" \"From %T %(%[date]=^\\(\\w*\\), \\(\\w*\\)-\\(\\w*\\)-\\(\\w*\\) \\([^ ]*\\)?%1 %3 %(%2=..?%2: %2) %5 19%4)\""
  703. #        endif
  704.                     /* header munging with a vengeance */
  705. #    else
  706. #           ifdef SERVER
  707. #               define MBOXSAVER "%X/mbox.saver %P/rrn%a.%$ %P %c %a %B %C \"%b\" \"From %T %[posted]\""
  708. #           else
  709. #            define MBOXSAVER "%X/mbox.saver %A %P %c %a %B %C \"%b\" \"From %T %[posted]\""
  710. #        endif
  711. #    endif
  712. #   endif
  713. #endif
  714.  
  715. #ifdef MKDIRS
  716.  
  717. #   ifndef SAVEDIR            /* % and ~ */
  718. #    define SAVEDIR "%p/%c"
  719. #   endif
  720. #   ifndef SAVENAME        /* % */
  721. #    define SAVENAME "%a"
  722. #   endif
  723.  
  724. #else
  725.  
  726. #   ifndef SAVEDIR            /* % and ~ */
  727. #    define SAVEDIR "%p"
  728. #   endif
  729. #   ifndef SAVENAME        /* % */
  730. #    define SAVENAME "%^C"
  731. #   endif
  732.  
  733. #endif
  734.  
  735. #ifndef KILLGLOBAL        /* % and ~ */
  736. #   define KILLGLOBAL "%p/KILL"
  737. #endif
  738.  
  739. #ifndef KILLLOCAL        /* % and ~ */
  740. #   define KILLLOCAL "%p/%c/KILL"
  741. #endif
  742.  
  743. /* how to cancel an article */
  744. #ifndef CANCEL
  745. #   ifdef MININACT            /* 2.10.2 ? */
  746. #    define CANCEL "%x/inews -h < %h"
  747. #   else
  748. #    define CANCEL "inews -h < %h"
  749. #   endif
  750. #endif
  751.  
  752. /* how to cancel an article, continued */
  753. #ifndef CANCELHEADER
  754. #ifdef INTERNET
  755. #   define CANCELHEADER "From: %L@%H (%N)\nNewsgroups: %n\nSubject: cmsg cancel %i\nReferences: %R\nDistribution: %D\nOrganization: %o\n\n%i was cancelled from within trn.\n"
  756. #else
  757. #   define CANCELHEADER "From:%L@%H.UUCP (%N)\nNewsgroups: %n\nSubject: cmsg cancel %i\nReferences: %R\nDistribution: %D\nOrganization: %o\n\n%i was cancelled from within trn.\n"
  758. #endif
  759. #endif
  760.  
  761. /* how to supersede an article */
  762. #ifndef SUPERSEDEHEADER
  763. #ifdef INTERNET
  764. #   define SUPERSEDEHEADER "From: %L@%H (%N)\nNewsgroups: %n\nSupersedes: %i\nSubject: %S\nDistribution: %D\nOrganization: %o\n"
  765. #else
  766. #   define SUPERSEDEHEADER "From:%L@%H.UUCP (%N)\nNewsgroups: %n\nSupersedes: %i\nSubject: %S\nDistribution: %D\nOrganization: %o\n"
  767. #endif
  768. #endif
  769.  
  770. #ifndef LOCALTIMEFMT
  771. #   define LOCALTIMEFMT "%a %b %d %X %Z %Y"
  772. #endif
  773.  
  774. /* where to find the mail file */
  775. #ifndef MAILFILE
  776. #   define MAILFILE "/usr/spool/mail/%L"
  777. #endif
  778.  
  779. /* how to open binary format files */
  780. #ifndef FOPEN_RB
  781. #   define FOPEN_RB "r"
  782. #endif
  783. #ifndef FOPEN_WB
  784. #   define FOPEN_WB "w"
  785. #endif
  786.  
  787. /* what to do with ansi prototypes -- '()' == ignore, 'x' == use */
  788. #ifndef ANSI
  789. #   ifdef __STDC__
  790. #    define ANSI(x) x
  791. #   else
  792. #    define ANSI(x) ()
  793. #   endif
  794. #endif
  795.  
  796. /* how many characters is a newline in a text file? */
  797. #ifndef NL_SIZE
  798. #   define NL_SIZE 1
  799. #endif
  800.  
  801. /* some important types */
  802.  
  803. typedef int        NG_NUM;        /* newsgroup number */
  804. typedef long        ART_NUM;    /* article number */
  805. #ifdef pdp11
  806.     typedef short    ART_UNREAD;    /* ordinarily this should be long */
  807.                     /* like ART_NUM, but assuming that */
  808.                     /* we stay less than 32767 articles */
  809.                     /* behind saves a lot of space. */
  810.                     /* NOTE: do not make unsigned. */
  811. #else
  812.     typedef long    ART_UNREAD;
  813. #endif
  814. #ifdef SERVER
  815. typedef int        ART_PART;    /* for passing to nntpopen() */
  816. #endif
  817. typedef long        ART_POS;    /* char position in article file */
  818. typedef int        ART_LINE;    /* line position in article file */
  819. typedef long        ACT_POS;    /* char position in active file */
  820. typedef unsigned int    MEM_SIZE;    /* for passing to malloc */
  821.  
  822.  
  823. /* *** end of the machine dependent stuff *** */
  824.  
  825. /* GLOBAL THINGS */
  826.  
  827. /* file statistics area */
  828.  
  829. EXT struct stat filestat;
  830.  
  831. /* various things of type char */
  832.  
  833. char    *index();
  834. char    *rindex();
  835. char    *getenv();
  836. char    *strcat();
  837. char    *strcpy();
  838.  
  839. EXT char buf[LBUFLEN+1];    /* general purpose line buffer */
  840. EXT char cmd_buf[CBUFLEN];    /* buffer for formatting system commands */
  841. EXT char *indstr INIT(">");    /* indent for old article embedded in followup */
  842.  
  843. EXT char *cwd INIT(Nullch);        /* current working directory */
  844. EXT char *dfltcmd INIT(Nullch);    /* 1st char is default command */
  845.  
  846. /* switches */
  847.  
  848. #ifdef DEBUGGING
  849.     EXT int debug INIT(0);                /* -D */
  850. #   define DEB_NNTP 16 
  851. #   define DEB_INNERSRCH 32 
  852. #   define DEB_FILEXP 64 
  853. #   define DEB_HASH 128
  854. #   define DEB_XREF_MARKER 256
  855. #   define DEB_CTLAREA_BITMAP 512
  856. #   define DEB_SOFT_POINTERS 1024
  857. #   define DEB_NEWSRC_LINE 2048
  858. #   define DEB_SEARCH_AHEAD 4096
  859. #   define DEB_CHECKPOINTING 8192
  860. #   define DEB_FEED_XREF 16384
  861. #endif
  862.  
  863. #ifdef ARTSEARCH
  864.     EXT int scanon INIT(0);                /* -S */
  865. #endif
  866.  
  867. #ifdef USETHREADS
  868.     EXT bool use_threads INIT(THREAD_INIT);        /* -x */
  869.     EXT int max_tree_lines INIT(6);
  870.     EXT char select_order[4] INIT("lsm");
  871.     EXT int select_on INIT(SELECT_INIT);        /* -X */
  872.     EXT char end_select INIT('Z');
  873.     EXT char page_select INIT('>');
  874. #endif
  875.  
  876. EXT bool mbox_always INIT(FALSE);            /* -M */
  877. EXT bool norm_always INIT(FALSE);            /* -N */
  878. EXT bool thread_always INIT(FALSE);            /* -a */
  879. EXT bool olden_days INIT(FALSE);            /* -o */
  880. EXT bool checkflag INIT(FALSE);            /* -c */
  881. EXT bool suppress_cn INIT(FALSE);            /* -s */
  882. EXT int countdown INIT(5);    /* how many lines to list before invoking -s */
  883. EXT bool muck_up_clear INIT(FALSE);            /* -loco */
  884. EXT bool erase_screen INIT(FALSE);            /* -e */
  885. #if defined(CLEAREOL) || defined(USETHREADS)
  886. EXT bool can_home INIT(FALSE);
  887. #endif
  888. #ifdef CLEAREOL
  889. EXT bool can_home_clear INIT(FALSE);        /* fancy -e */
  890. #endif
  891. EXT bool findlast INIT(FALSE);            /* -r */
  892. EXT bool typeahead INIT(FALSE);            /* -T */
  893. #ifdef VERBOSE
  894. #   ifdef TERSE
  895.     EXT bool verbose INIT(TRUE);            /* +t */
  896. #   endif
  897. #endif
  898. #ifdef VERIFY
  899.     EXT bool verify INIT(FALSE);            /* -v */
  900. #endif
  901.     EXT bool quickstart INIT(FALSE);            /* -q */
  902.  
  903. #define NOMARKING 0
  904. #define STANDOUT 1
  905. #define UNDERLINE 2
  906. EXT int marking INIT(NOMARKING);            /* -m */
  907.  
  908. EXT ART_LINE initlines INIT(0);        /* -i */
  909. EXT bool initlines_specified INIT(FALSE);
  910.  
  911. /* miscellania */
  912.  
  913. int fseek();
  914. long atol(), ftell();
  915. EXT bool in_ng INIT(FALSE);        /* current state of rn */
  916. EXT char mode INIT('i');        /* current state of rn */
  917.  
  918. EXT FILE *tmpfp INIT(Nullfp);    /* scratch fp used for .rnlock, .rnlast, etc. */
  919.  
  920. EXT NG_NUM nextrcline INIT(0);    /* 1st unused slot in rcline array */
  921.             /* startup to avoid checking twice in a row */
  922.  
  923. extern errno;
  924. /* Factored strings */
  925.  
  926. EXT char nullstr[1] INIT("");
  927. EXT char sh[] INIT(SH);
  928. EXT char defeditor[] INIT(DEFEDITOR);
  929. EXT char hforhelp[] INIT("Type h for help.\n");
  930. #ifdef STRICTCR
  931. EXT char badcr[] INIT("\nUnnecessary CR ignored.\n");
  932. #endif
  933. EXT char readerr[] INIT("rn read error");
  934. EXT char unsubto[] INIT("\n\nUnsubscribed to newsgroup %s\n");
  935. EXT char cantopen[] INIT("Can't open %s\n");
  936. EXT char cantcreate[] INIT("Can't create %s\n");
  937. EXT char cantrecreate[] INIT("Can't recreate %s -- restoring older version.\n");
  938.  
  939. #ifdef VERBOSE
  940.     EXT char nocd[] INIT("Can't chdir to directory %s\n");
  941. #else
  942.     EXT char nocd[] INIT("Can't find %s\n");
  943. #endif
  944.  
  945. #ifdef NOLINEBUF
  946. #define FLUSH ,fflush(stdout)
  947. #else
  948. #define FLUSH
  949. #endif
  950.  
  951. #ifdef lint
  952. #undef FLUSH
  953. #define FLUSH
  954. #undef putchar
  955. #define putchar(c)
  956. #endif
  957.