home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / trn-3.3 / part08 / common.h next >
C/C++ Source or Header  |  1993-11-27  |  26KB  |  927 lines

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