home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume31 / tin / part12 / tin.h < prev   
C/C++ Source or Header  |  1992-07-08  |  14KB  |  671 lines

  1. /*
  2.  *  Project   : tin - a threaded Netnews reader
  3.  *  Module    : tin.h
  4.  *  Author    : I.Lea & R.Skrenta
  5.  *  Created   : 01-04-91
  6.  *  Updated   : 22-06-92
  7.  *  Notes     : #include files, #defines & struct's
  8.  *  Copyright : (c) Copyright 1991-92 by Iain Lea & Rich Skrenta
  9.  *              You may  freely  copy or  redistribute  this software,
  10.  *              so  long as there is no profit made from its use, sale
  11.  *              trade or  reproduction.  You may not change this copy-
  12.  *              right notice, and it must be included in any copy made
  13.  */
  14.  
  15. #include    <stdio.h>
  16. #include    <signal.h>
  17. #include    <errno.h>
  18. #ifdef apollo
  19. #    include </bsd4.3/usr/include/sys/types.h>
  20. #else
  21. #    include <sys/types.h>
  22. #endif
  23. #include    <sys/stat.h>
  24. #include    <pwd.h>
  25. #include    <ctype.h>
  26. #include    <time.h>
  27. #if !defined(apollo) && !defined(__NeXT__)
  28. #    include    <unistd.h>
  29. #endif
  30.  
  31. #ifdef BSD
  32. #    include    <strings.h>
  33. #    include    <fcntl.h>
  34. #else
  35. #    ifndef apollo
  36. #        include    <stdlib.h>
  37. #    endif
  38. #    include    <string.h>
  39. #endif
  40.  
  41. #ifndef MINIX
  42. #    include <sys/ioctl.h>
  43. #endif
  44.  
  45. #ifdef M_XENIX
  46. #    include    <prototypes.h>
  47. #endif
  48.  
  49. #ifdef SVR4
  50. #    include <locale.h>
  51. #endif
  52.  
  53. #if !defined(BSD) && !defined(sinix) && !defined(RS6000)
  54. #    include    <sys/utsname.h>
  55. #endif
  56.  
  57. /*
  58.  * Needed for catching child processes
  59.  */
  60.  
  61. #ifdef SIGCHLD
  62. #    include    <sys/wait.h>
  63. #endif
  64.  
  65. /*
  66.  * Needed for resizing under an xterm
  67.  */
  68.  
  69. #if defined(SIGWINCH)
  70. #    ifndef SCO_UNIX
  71. #        include <termios.h>
  72. #    endif
  73. #    if !defined(TIOCGWINSZ) && !defined(TIOCGSIZE)
  74. #        if !defined(sinix) && !defined(nsc)
  75. #            include <sys/stream.h>
  76. #            ifdef PTX
  77. #                include <termio.h>
  78. #            else
  79. #                ifndef apollo
  80. #                    include <sys/ptem.h>
  81. #                    include <sys/tty.h>
  82. #                endif
  83. #                if !defined(SCO_UNIX) && !defined(SVR4) && !defined(apollo)
  84. #                    ifndef _h_BSDTYPES
  85. #                        include <sys/bsdtypes.h>
  86. #                    endif
  87. #                    include <sys/pty.h>
  88. #                endif
  89. #            endif
  90. #        endif
  91. #    endif
  92. #endif
  93.  
  94. /*
  95.  * Setup support for reading from CD-ROM
  96.  */
  97.  
  98. #ifdef CDROM_ONLY
  99. #    define CDROM_ABLE
  100. #endif
  101.  
  102. #ifdef CDROM_ABLE
  103. #    define XSPOOLDIR
  104. #    define NNTP_ABLE
  105. #    undef NNTP_ONLY
  106. #    undef NNTP_INEWS
  107. #endif
  108.  
  109. /*
  110.  * Setup support for reading from NNTP
  111.  */
  112.  
  113. #if defined(NNTP_ABLE) || defined(NNTP_ONLY)
  114. #    ifndef NNTP_ABLE
  115. #        define    NNTP_ABLE
  116. #    endif
  117. #    ifndef NNTP_INEWS
  118. #        define    NNTP_INEWS
  119. #    endif
  120. #endif
  121.  
  122. /*
  123.  * Index file daemon version of tin. Will create/update index files from cron
  124.  * on NNTP server machine so clients can retreive index file with NNTP XINDEX
  125.  * command from server. Also can be used on machines that just want one copy
  126.  * of all the index files in one place. In this case the normal tin must have
  127.  * access to the index directory (-I dir option) or be setuid news.
  128.  */
  129.  
  130. #ifdef INDEX_DAEMON
  131. #    define    LOCK_FILE "/tmp/tind.LCK"
  132. #    undef    NNTP_ABLE
  133. #    undef    NNTP_ONLY
  134. #    undef    NNTP_INEWS
  135. #endif
  136.  
  137. /*
  138.  * Determine signal return type
  139.  */
  140.  
  141. #if defined(__GNUC__) || defined(POSIX_JOB_CONTROL)
  142. typedef void sigtype_t;
  143. #else    
  144. #    if defined(sony)
  145. typedef int sigtype_t;
  146. #    else
  147. #        if __STDC__ || defined(SVR4) || defined(sinix) || defined(sun) || \
  148.            defined(ultrix) || defined(atthcx) || defined(PTX) || defined(sgi)
  149. typedef void sigtype_t;
  150. #        else
  151. typedef int sigtype_t;
  152. #        endif
  153. #    endif
  154. #endif
  155.  
  156. /*
  157.  * Specify News spool & control directories
  158.  */
  159.  
  160. #ifndef SPOOLDIR
  161. #    define        SPOOLDIR    "/usr/spool/news"
  162. #endif
  163. #ifndef LIBDIR
  164. #    define        LIBDIR        "/usr/lib/news"
  165. #endif
  166. #ifndef INEWSDIR
  167. #    define        INEWSDIR    LIBDIR
  168. #endif
  169.  
  170. /*
  171.  * Determine machine configuration for external programs & directories
  172.  */
  173.  
  174. #ifdef BSD
  175. #    if defined(_SEQUENT_) || defined(pyr)
  176. #        define        memcmp(s1, s2, n)    bcmp(s2, s1, n)
  177. #    endif
  178. #    define        strchr(str, ch)    index(str, ch)
  179. #    define        DEFAULT_SHELL    "/bin/csh"
  180. #    define        DEFAULT_EDITOR    "/usr/ucb/vi"
  181. #    define        DEFAULT_PRINTER    "/usr/ucb/lpr"
  182. #    define        DEFAULT_SUM    "sum"
  183. #    ifdef DGUX
  184. #        define        DEFAULT_MAILER    "/bin/mail"
  185. #        define        DEFAULT_MAILBOX    "/usr/mail"
  186. #        define        POSIX_JOB_CONTROL
  187. #        define        USE_INVERSE_HACK
  188. #    endif
  189. #    ifdef pyr
  190. #        define        DEFAULT_MAILER    "/usr/.attbin/mailx"
  191. #    endif
  192. #    ifndef DEFAULT_MAILER
  193. #        define        DEFAULT_MAILER    "/usr/ucb/Mail"
  194. #    endif
  195. #    ifndef DEFAULT_MAILBOX
  196. #        define        DEFAULT_MAILBOX    "/usr/spool/mail"
  197. #    endif
  198. #    ifndef USE_LONG_FILENAMES
  199. #        define USE_LONG_FILENAMES
  200. #    endif
  201. #else
  202. #    ifdef M_XENIX
  203. #        define        DEFAULT_EDITOR    "/bin/vi"
  204. #        define        DEFAULT_MAILER    "/usr/bin/mail"
  205. #        define        DEFAULT_MAILBOX    "/usr/spool/mail"
  206. #    endif
  207. #    if defined(NCR) || defined(atthcx) || defined(HPUX)
  208. #        define        DEFAULT_MAILER    "/usr/bin/mailx"
  209. #    endif
  210. #    ifdef PTX
  211. #        define        DEFAULT_MAILER    "/usr/bin/mailx"
  212. #        ifndef USE_LONG_FILENAMES
  213. #            define    USE_LONG_FILENAMES
  214. #        endif
  215. #    endif
  216. #    ifdef RS6000
  217. #        define        DEFAULT_MAILER    "/usr/bin/mail"
  218. #        define        DEFAULT_PRINTER    "/bin/lp"
  219. #    endif
  220. #    ifdef sinix
  221. #        define        DEFAULT_MAILER    "/bin/rmail"
  222. #        define        DEFAULT_PRINTER    "/bin/lpr"
  223. #        ifndef USE_LONG_FILENAMES
  224. #            define USE_LONG_FILENAMES
  225. #        endif
  226. #    endif
  227. #    ifdef SVR4
  228. #        define        POSIX_JOB_CONTROL
  229. #        ifndef USE_LONG_FILENAMES
  230. #            define    USE_LONG_FILENAMES
  231. #        endif
  232. #    endif
  233. #    ifdef UNIXPC
  234. #        define        DEFAULT_MAILER    "/bin/rmail"
  235. #    endif
  236. #    ifndef DEFAULT_SHELL
  237. #        define        DEFAULT_SHELL    "/bin/sh"
  238. #    endif
  239. #    ifndef DEFAULT_EDITOR
  240. #        define        DEFAULT_EDITOR    "/usr/bin/vi"
  241. #    endif
  242. #    ifndef DEFAULT_MAILBOX
  243. #        define        DEFAULT_MAILBOX    "/usr/mail"
  244. #    endif
  245. #    ifndef DEFAULT_MAILER
  246. #        define        DEFAULT_MAILER    "/bin/mail"
  247. #    endif
  248. #    ifndef DEFAULT_PRINTER
  249. #        define        DEFAULT_PRINTER    "/usr/bin/lp"
  250. #    endif
  251. #    define        DEFAULT_SUM        "sum -r"
  252. #endif
  253.  
  254. #ifdef USE_LONG_FILENAMES
  255. #    define        LONG_PATH_PART    "part"
  256. #    define        LONG_PATH_PATCH    "patch"
  257. #else
  258. #    define        LONG_PATH_PART    ""
  259. #    define        LONG_PATH_PATCH    "p"
  260. #endif
  261.  
  262. /*
  263.  * Useful for logging user usage
  264.  */
  265.  
  266. #ifdef LOG_USER
  267. #    define        LOG_USER_FILE    "/tmp/.tin_log" 
  268. #endif
  269.  
  270. /*
  271.  * Should active file be rereaf for new news & if so how often
  272.  */
  273.  
  274. #ifndef NO_RESYNC_ACTIVE_FILE
  275. #    ifndef RESYNC_ACTIVE_SECS
  276. #        define    RESYNC_ACTIVE_SECS    300    /* reread active every n secs */
  277. #    endif
  278. #endif
  279.  
  280. /*
  281.  * Initial sizes of internal arrays for small (<4MB) & large memory machines
  282.  */
  283.  
  284. #ifdef SMALL_MEMORY_MACHINE
  285. #    define        DEFAULT_ACTIVE_NUM    1800    
  286. #    define        DEFAULT_ARTICLE_NUM    400    
  287. #    define        DEFAULT_KILL_NUM    10    
  288. #    define        DEFAULT_SAVE_NUM    10    
  289. #else
  290. #    define        DEFAULT_ACTIVE_NUM    1800    
  291. #    define        DEFAULT_ARTICLE_NUM    1200    
  292. #    define        DEFAULT_KILL_NUM    30    
  293. #    define        DEFAULT_SAVE_NUM    30    
  294. #endif
  295.  
  296. #define        RCDIR            ".tin"
  297. #define        RCFILE            "tinrc"
  298. #define        INDEXDIR        ".index"
  299. #define        KILLFILE        "kill"
  300. #define        POSTFILE        "posted"
  301. #define        UNTHREADFILE    "unthread"
  302. #define        DEFAULT_MAILDIR    "Mail"
  303.  
  304. #define BUG_REPORT_ADDRESS    "iain%anl433.uucp@Germany.EU.net"
  305.  
  306. #ifdef TRUE
  307. #    undef TRUE
  308. #endif
  309. #define        TRUE        1
  310.  
  311. #ifdef FALSE
  312. #    undef FALSE
  313. #endif
  314. #define        FALSE        0
  315.  
  316. #define        LEN                1024
  317. #define        PATH_LEN            256
  318. #define        HEADER_LEN            1024
  319. #define        MODULO_COUNT_NUM        5
  320. #define        TABLE_SIZE            1409
  321. #define        MAX_PAGES            1000
  322. #define        ctrl(c)                ((c) & 0x1F)
  323.  
  324. #ifndef DEFAULT_COMMENT
  325. #    define        DEFAULT_COMMENT    ": "    /* used when by follow-ups & replys */
  326. #endif
  327. #ifndef UNREAD_ART_MARK
  328. #    define        UNREAD_ART_MARK    '+'    /* used to show that an art is unread */
  329. #endif
  330. #ifndef RETURN_ART_MARK
  331. #    define        RETURN_ART_MARK    '-'    /* used to show that an art will return */
  332. #endif
  333. #ifndef HOT_ART_MARK
  334. #    define        HOT_ART_MARK    '*'    /* used to show that an art was auto selected */
  335. #endif
  336. #ifndef READ_ART_MARK
  337. #    define        READ_ART_MARK    ' '    /* used to show that an art was not read or seen  */
  338. #endif
  339.  
  340. #ifdef USE_INVERSE_HACK
  341. #    define        SELECT_MISC_COLS    21
  342. #    define        BLANK_GROUP_COLS    2
  343. #    define        BLANK_PAGE_COLS        2
  344. #else
  345. #    define        SELECT_MISC_COLS    21
  346. #    define        BLANK_GROUP_COLS    0
  347. #    define        BLANK_PAGE_COLS        0
  348. #endif
  349.  
  350. #define        SCREEN_READ_UNREAD        6        /* position for "  +" / "   " */
  351. #define        INDEX_TOP                2
  352.  
  353. #ifdef NO_REGEX 
  354. #    define STR_MATCH(s1,s2)    (str_str (s1, s2, strlen (s2)) != 0)
  355. #else        
  356. #    define STR_MATCH(s1,pat)    (wildmat (s1, pat))
  357. #endif
  358.  
  359. #define IGNORE_ART(i)    ((arts[i].thread == ART_EXPIRED) || \
  360.              (arts[i].killed && kill_level > 0))
  361.  
  362. /*
  363.  *  used by get_arrow_key()
  364.  */
  365.  
  366. #define        KEYMAP_UNKNOWN            0
  367. #define        KEYMAP_UP                1
  368. #define        KEYMAP_DOWN                2
  369. #define        KEYMAP_PAGE_UP            3
  370. #define        KEYMAP_PAGE_DOWN        4
  371. #define        KEYMAP_HOME                5
  372. #define        KEYMAP_END                6
  373.  
  374. /*
  375.  *  used by feed.c - feed_articles()
  376.  */
  377.  
  378. #define        SELECT_LEVEL                1
  379. #define        GROUP_LEVEL                2
  380. #define        PAGE_LEVEL                3
  381.  
  382. #define        FEED_MAIL                1
  383. #define        FEED_PIPE                2
  384. #define        FEED_PRINT                3
  385. #define        FEED_SAVE                4
  386. #define        FEED_XPOST                5
  387.  
  388. /*
  389.  *  used in art.c & rcfile.c
  390.  */
  391.  
  392. #define        SORT_BY_NOTHING            0        /* sort types on arts[] array */
  393. #define        SORT_BY_SUBJ_DESCEND    1
  394. #define        SORT_BY_SUBJ_ASCEND        2
  395. #define        SORT_BY_FROM_DESCEND    3
  396. #define        SORT_BY_FROM_ASCEND        4
  397. #define        SORT_BY_DATE_DESCEND    5
  398. #define        SORT_BY_DATE_ASCEND        6
  399.  
  400. #define        SHOW_FROM_NONE            0
  401. #define        SHOW_FROM_ADDR            1
  402. #define        SHOW_FROM_NAME            2
  403. #define        SHOW_FROM_BOTH            3
  404.  
  405. /*
  406.  *  used in help.c
  407.  */
  408.  
  409. #define        HELP_INFO                0
  410. #define        POST_INFO                1
  411.  
  412. /*
  413.  *  used in save.c
  414.  */
  415.  
  416. #define        CHECK_ANY_NEWS            0
  417. #define        START_ANY_NEWS            1
  418. #define        MAIL_ANY_NEWS            2
  419. #define        SAVE_ANY_NEWS            3
  420.  
  421. /*
  422.  *  used in help.c
  423.  */
  424.  
  425. #define        HEADER_TO                0
  426. #define        HEADER_SUBJECT            1
  427.  
  428. /*
  429.  *  used in page.c & post.c
  430.  */
  431.  
  432. #define        POSTED_NONE                0
  433. #define        POSTED_REDRAW            1
  434. #define        POSTED_OK                2
  435.  
  436. /*
  437.  *  Assertion verifier
  438.  */
  439.  
  440. #if __STDC__ && !defined(apollo)
  441. #    define    assert(p)    if(! (p)) asfail(__FILE__, __LINE__, #p); else
  442. #else
  443. #    define    assert(p)    if(! (p)) asfail(__FILE__, __LINE__, "p"); else
  444. #endif
  445.  
  446. #define        ESC        27
  447. #if defined(BSD) || defined(MINIX) || defined(apollo)
  448. #    define        CR        '\r'
  449. #else
  450. #    define        CR        10
  451. #endif
  452.  
  453. /*
  454.  * return codes for change_rcfile ()
  455.  */
  456.  
  457. #define        NO_KILLING        0
  458. #define        KILLING            1
  459.  
  460. /*
  461.  *  art.thread
  462.  */
  463.  
  464. #define        ART_NORMAL        -1
  465. #define        ART_EXPIRED        -2
  466.  
  467. /*
  468.  *  art.unread
  469.  */
  470.  
  471. #define        ART_READ        0
  472. #define        ART_UNREAD        1
  473. #define        ART_WILL_RETURN    2
  474.  
  475. /*
  476.  * used by group_t & my_group[]
  477.  */
  478.  
  479. #define        UNSUBSCRIBED    0x01    /* haven't put in my_group[] yet */
  480. #define        SUBSCRIBED        0x02    /* subscribed to */
  481.  
  482. /*
  483.  * kill_type used in struct kill_t
  484.  */
  485.  
  486. #define KILL_SUBJ    1
  487. #define KILL_FROM    2
  488. #define KILL_BOTH    3
  489.  
  490. /*
  491.  * usedin group.c & page.c
  492.  */
  493.  
  494. #define    ART_UNAVAILABLE    -1
  495.  
  496.  
  497. /*
  498.  * used in feed.c & save.c
  499.  */
  500.  
  501. #define POST_PROC_NONE            0
  502. #define POST_PROC_SHAR            1
  503. #define POST_PROC_UUDECODE        2
  504. #define POST_PROC_UUD_LST_ZOO    3
  505. #define POST_PROC_UUD_EXT_ZOO    4
  506.  
  507. /*
  508.  *  struct article_t - article header
  509.  *
  510.  *  article.artnum:
  511.  *    article number in spool directory for group
  512.  *
  513.  *  article.thread:
  514.  *    -1 initial default
  515.  *    -2 means article has expired (wasn't found in file search
  516.  *    of spool directory for the group)
  517.  *    >=0 points to another arts[] (struct article_t)
  518.  *
  519.  *  article.inthread:
  520.  *    FALSE for the first article in a thread, TRUE for all
  521.  *    following articles in thread
  522.  *
  523.  *  article.unread:
  524.  *    boolean, has this article been read or not
  525.  *
  526.  *  article.killed:
  527.  *    boolean, has this article been killed
  528.  *
  529.  *  article.hot:
  530.  *    boolean, has this article been auto-selected
  531.  *
  532.  *  article.tagged:
  533.  *    count, has this article been tagged for saving (>0) or not (=0)
  534.  *
  535.  *  article.date
  536.  *    date: line used for sorting articles by date order
  537.  *
  538.  *  article.archive:
  539.  *    archive name used in *source* groups
  540.  *
  541.  *  article.part:
  542.  *    part no. of archive
  543.  *
  544.  *  article.patch:
  545.  *    patch no. of archive
  546.  *
  547.  */
  548.  
  549. struct article_t {
  550.     long artnum;
  551.     char *subject;        /* Subject: line from mail header */
  552.     char *from;        /* From: line from mail header (address) */
  553.     char *name;        /* From: line from mail header (full name) */
  554.     int thread;
  555.     unsigned int inthread:1;/* 0 = thread head, 1 = thread follower */
  556.     unsigned int unread:2;    /* 0 = read, 1 = unread, 2 = will return */
  557.     unsigned int killed:1;    /* 0 = not killed, 1 = killed */
  558.     unsigned int hot:1;    /* 0 = not hot, 1 = hot */
  559.     unsigned int zombie:1;    /* 1 = was alive (unread) before 'X' command */
  560.     unsigned int o_unread:2;/* original value of unread - used in xref */
  561.     int tagged;        /* 0 = not tagged, >0 = tagged */
  562.     char date[16];        /* Date: line from mail header */
  563.     char *archive;        /* Archive-name: line from mail header */
  564.     char *part;        /* part no. of archive */
  565.     char *patch;        /* patch no. of archive */
  566.     char *xref;        /* cross reference line */
  567. };
  568.  
  569. /*
  570.  *  struct attribute_t - configurable attributes on a per group basis
  571.  */
  572.  
  573. struct attribute_t {
  574.     char *server;            /* read group locally/via nntp server */
  575.     char *maildir;            /* mail dir if other than ~/Mail */
  576.     char *savedir;            /* save dir if other than ~/News */
  577.     char *sigfile;            /* sig file if other than ~/.Sig */
  578.     unsigned int read:1;        /* marked TRUE if group was entered during session */
  579.     unsigned int showall:1;        /* 0 = only unread, 1 = all */
  580.     unsigned int thread:1;        /* 0 = unthread, 1 = thread */
  581.     unsigned int sortby:4;        /* 0 = none, 1 = , 2 = , 3 = , 4 = , */
  582.     unsigned int author:4;        /* 0 = none, 1 = name, 2 = addr, 3 = both */
  583.     unsigned int autosave:1;    /* 0 = none, 1 = save */
  584.     unsigned int process:4;        /* 0 = none, 1 = shar, 2 = uudecode, 
  585.                          3 = uud & list zoo, 4 = uud & ext zoo*/
  586. };
  587.  
  588. /*
  589.  *  struct group_t - newsgroup info from active file
  590.  */
  591.  
  592. struct group_t {
  593.     char *name;
  594.     char *description;        /* text from LIBDIR/newsgroups file */
  595.     long max;
  596.     long min;
  597.     char moderated;
  598.     int next;            /* next active entry in hash chain */
  599.     int flag;
  600.     struct attribute_t attribute;    /* per group attributes */ 
  601. };
  602.  
  603. /*
  604.  *  used in hashstr.c
  605.  */
  606.  
  607. struct hashnode {
  608.     char *s;                        /* the string we're saving */
  609.     struct hashnode *next;            /* chain for spillover */
  610. };
  611.  
  612. /*
  613.  *  used in kill.c
  614.  */
  615.  
  616. struct kill_t {
  617.     unsigned int kill_type:8;
  618.     unsigned int kill_how:8;    /* kill/auto select */
  619.     long kill_group;
  620.     char *kill_subj;
  621.     char *kill_from;
  622. };
  623.  
  624. struct save_t {
  625.     char *subject;
  626.     char *dir;
  627.     char *file;
  628.     char *archive;
  629.     char *part;
  630.     char *patch;
  631.     int index;    
  632.     int saved;    
  633.     int is_mailbox;    
  634. };
  635.  
  636. struct screen_t {
  637.     char *col;
  638. };
  639.  
  640. struct posted_t {
  641.     char date[10];
  642.     char group[80];
  643.     char action;
  644.     char subj[120];
  645. };
  646.  
  647. struct art_stat_t {
  648.     int total;    /* total article count */
  649.     int unread;    /* number of unread articles (does not include seen) arts */
  650.     int seen;    /* number of seen articles (ART_WILL_RETURN) */
  651.     int hot_total;    /* total hot count */
  652.     int hot_unread; /* hot and unread */
  653.     int hot_seen;    /* hot and seen */
  654.     char art_mark;    /* mark to use for this thread - not used for groups */
  655. };
  656.  
  657. struct spooldir_t {
  658.     int state;
  659.     char *name;
  660.     char *comment;
  661. };
  662.  
  663. /*
  664.  *  function prototypes    & extern definitions    
  665.  */ 
  666.  
  667. #include    "patchlev.h"
  668. #include    "extern.h"
  669. #include    "nntplib.h"
  670. #include    "proto.h"
  671.