📄 common.h
字号:
/* $Id: common.h,v 3.0 1992/02/23 21:25:39 davison Trn $ *//* This software is Copyright 1991 by Stan Barber. * * Permission is hereby granted to copy, reproduce, redistribute or otherwise * use this software as long as: there is no monetary profit gained * specifically from the use or reproduction of this software, it is not * sold, rented, traded or otherwise marketed, and this copyright notice is * included prominently in any copy made. * * The author make no claims as to the fitness or correctness of this software * for any use whatsoever, and it is provided as is. Any use of this software * is at the user's own risk. */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <ctype.h>#include "config.h" /* generated by installation script */#ifndef isalnum# define isalnum(c) (isalpha(c) || isdigit(c))#endif#include <errno.h>#include <signal.h>#ifdef I_SYS_IOCTL#include <sys/ioctl.h>#endif#ifdef I_VFORK# include <vfork.h>#endif#include <fcntl.h>#ifdef I_TERMIO# include <termio.h>#else# ifdef I_TERMIOS# include <termios.h># else# include <sgtty.h># endif#endif#ifdef HAS_GETPWENT# include <pwd.h>#endif#ifdef I_PTEM#include <sys/stream.h>#include <sys/ptem.h>#endif#include <time.h>#define BITSPERBYTE 8#define LBUFLEN 1024 /* line buffer length */ /* (don't worry, .newsrc lines can exceed this) */#define CBUFLEN 512 /* command buffer length */#define PUSHSIZE 256#define MAXFILENAME 512#define LONGKEY 15 /* longest keyword: currently "posting-version" */#define FINISHCMD 0177/* some handy defs */#define bool char#define bool_int int#define char_int int#ifndef TRUE#define TRUE (1)#endif#ifndef FALSE#define FALSE (0)#endif#define Null(t) ((t)0)#define Nullch Null(char*)#define Nullfp Null(FILE*)#define Ctl(ch) (ch & 037)#define strNE(s1,s2) (strcmp(s1,s2))#define strEQ(s1,s2) (!strcmp(s1,s2))#define strnNE(s1,s2,l) (strncmp(s1,s2,l))#define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))/* Things we can figure out ourselves */#ifdef SIGTSTP# define BERKELEY /* include job control signals? */#endif#if defined(FIONREAD) || defined(HAS_RDCHK) || defined(O_NDELAY)# define PENDING#endif#ifdef EUNICE# define LINKART /* add 1 level of possible indirection */# define UNLINK(victim) while (!unlink(victim))#else# define UNLINK(victim) unlink(victim)#endif/* Valid substitutions for strings marked with % comment are: * %a Current article number * %A Full name of current article (%P/%c/%a) * (if LINKART defined, is the name of the real article) * %b Destination of a save command, a mailbox or command * %B The byte offset to the beginning of the article for saves * with or without the header * %c Current newsgroup, directory form * %C Current newsgroup, dot form * %d %P/%c * %D Old Distribution: line * %e Extract program * %E Extract destination directory * %f Old From: line or Reply-To: line * %F Newsgroups to followup to from Newsgroups: and Followup-To: * %h Name of header file to pass to mail or news poster * %H Host name (yours) * %i Old Message-I.D.: line, with <> * %I Inclusion indicator * %l News administrator login name * %L Login name (yours) * %m The current mode of trn. * %M Number of articles marked with M * %n Newsgroups from source article * %N Full name (yours) * %o Organization (yours) * %O Original working directory (where you ran trn from) * %p Your private news directory (-d switch) * %P Public news spool directory (NEWSSPOOL) * %r Last reference (parent article id) * %R New references list * %s Subject, with all Re's and (nf)'s stripped off * %S Subject, with one Re stripped off * %t New To: line derived from From: and Reply-To (Internet always) * %T New To: line derived from Path: * %u Number of unread articles * %U Number of unread articles disregarding current article * %v Number of unselected articles disregarding current article * %W The thread directory root * %x News library directory, usually /usr/lib/news * %X Rn library directory, usually %x/rn * %z Size of current article in bytes. * %Z Number of selected threads. * %~ Home directory * %. Directory containing . files * %# count of articles saved in current command (from 1 to n) * %$ current process number * %{name} Environment variable "name". %{name-default} form allowed. * %[name] Header line beginning with "Name: ", without "Name: " * %"prompt" * Print prompt and insert what is typed. * %`command` * Insert output of command. * %(test_text=pattern?if_text:else_text) * Substitute if_text if test_text matches pattern, otherwise * substitute else_text. Use != for negated match. * % substitutions are done on test_text, if_text, and else_text. * (Note: %() only works if CONDSUB defined.) * %digit Substitute the text matched by the nth bracket in the last * pattern that had brackets. %0 matches the last bracket * matched, in case you had alternatives. * * Put ^ in the middle to capitalize the first letter: %^C = Rec.humor * Put _ in the middle to capitalize last component: %_c = net/Jokes * Put \ in the middle to quote regexp and % characters in the result * Put :FMT in the middle to format the result: %:-30.30t * * ~ interpretation in filename expansion happens after % expansion, so * you could put ~%{NEWSLOGNAME-news} and it will expand correctly. *//* *** System Dependent Stuff *** *//* NOTE: many of these are defined in the config.h file *//* name of organization */#ifndef ORGNAME# define ORGNAME "ACME Widget Company, Widget Falls, Southern North Dakota"#endif#ifndef MBOXCHAR# define MBOXCHAR 'F' /* how to recognize a mailbox by 1st char */#endif#ifndef ROOTID# define ROOTID 0 /* uid of superuser */#endif#ifdef NORMSIG# define sigset signal# define sigignore(sig) signal(sig,SIG_IGN)#endif#ifndef LOGDIRFIELD# define LOGDIRFIELD 6 /* Which field (origin 1) is the */ /* login directory in /etc/passwd? */ /* (If it is not kept in passwd, */ /* but getpwnam() returns it, */ /* define the symbol HAS_GETPWENT) */#endif#ifndef GCOSFIELD# define GCOSFIELD 5#endif#ifndef NEGCHAR# define NEGCHAR '!'#endif/* Space conservation section *//* To save D space, cut down size of NGMAX and VARYSIZE. */#define NGMAX 100 /* number of newsgroups allowed on command line */ /* undefine ONLY symbol to disable "only" feature */#define VARYSIZE 256 /* this makes a block 1024 bytes long in DECville */ /* (used by virtual array routines) *//* Undefine any of the following features to save both I and D space *//* In general, earlier ones are easier to get along without */#define CUSTOMLINES /* include code for HIDELINE and PAGESTOP */#define WORDERASE /* enable ^W to erase a word */#define MAILCALL /* check periodically for mail */#define CLEAREOL /* use clear to end-of-line instead of clear screen */#define NOFIREWORKS /* keep whole screen from flashing on certain */ /* terminals such as older Televideos */#define VERIFY /* echo the command they just typed */#define HASHNG /* hash newsgroup lines for fast lookup-- */ /* linear search used if not defined */#define CONDSUB /* allow %(cond?text:text) */#define BACKTICK /* allow %`command` */#define PROMPTTTY /* allow %"prompt" */#define ULSMARTS /* catch _^H in text and do underlining */#define TERMMOD /* allow terminal type modifier on switches */#define BAUDMOD /* allow baudrate modifier on switches */#define GETLOGIN /* use getlogin() routine as backup to environment */ /* variables USER or LOGNAME */#define ORGFILE /* if organization begins with /, look up in file */#define TILDENAME /* allow ~logname expansion */#define SETENV /* allow command line environment variable setting */#define MAKEDIR /* use our makedir() instead of shell script */#define MEMHELP /* keep help messages in memory */#define VERBOSE /* compile in more informative messages */#define TERSE /* compile in shorter messages */ /* (Note: both VERBOSE and TERSE can be defined; -t * sets terse mode. One or the other MUST be defined. */#define ROTATION /* enable x, X and ^X commands to work */#define DELBOGUS /* ask if bogus newsgroups should be deleted */#define RELOCATE /* allow newsgroup rearranging */#define ESCSUBS /* escape substitutions in multi-character commands */#undef MCHASE /* unmark xrefed articles on m or M */#define MUNGHEADER /* allow alternate header formatting via */ /* environment variable ALTHEADER (not impl) */#define ASYNC_PARSE /* allow parsing headers asyncronously to reading */ /* used by MCHASE and MUNGHEADER */#define FINDNEWNG /* check for new newsgroups on startup */#define FASTNEW /* do optimizations on FINDNEWNG for faster startup */ /* (this optimization can make occasional mistakes */ /* if a group is removed and another group of the */ /* same length is added, and if no softpointers are */ /* affected by said change.) */#define INNERSEARCH /* search command 'g' with article */#define CATCHUP /* catchup command at newsgroup level */#define NGSEARCH /* newsgroup pattern matching */#define ONLY /* newsgroup restrictions by pattern */#define KILLFILES /* automatic article killer files */#define ARTSEARCH /* pattern searches among articles */ /* /, ?, ^N, ^P, k, K */#define EDIT_DISTANCE /* Allow -G to specify a fuzzy 'go' command */#undef METAMAIL /* use metamail to process mime articles *//* some dependencies among options */#ifndef ARTSEARCH# undef KILLFILES# undef INNERSEARCH#endif#ifndef SETUIDGID# define eaccess access#endif#ifdef ONLY /* idiot lint doesn't grok #if */# define NGSORONLY#else# ifdef NGSEARCH# define NGSORONLY# endif#endif#ifdef VERBOSE# ifdef TERSE# define IF(c) if (c)# define ELSE else# else# define IF(c)# define ELSE# endif#else /* !VERBOSE */# ifndef TERSE# define TERSE# endif# define IF(c) "IF" outside of VERBOSE???# define ELSE "ELSE" outside of VERBOSE???#endif#ifdef DEBUG# define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);sig_catcher(0);}}#else# define assert(ex) ;#endif/* If you're strapped for space use the help messages in shell scripts *//* if {NG,ART,PAGER,SUBS}HELP is undefined, help messages are in memory */#ifdef MEMHELP /* undef MEMHELP above to get them all as sh scripts */# undef NGHELP# undef ARTHELP# undef PAGERHELP# undef SUBSHELP#else# ifndef NGHELP /* % and ~ */# define NGHELP "%X/ng.help"# endif# ifndef ARTHELP /* % and ~ */# define ARTHELP "%X/art.help"# endif# ifndef PAGERHELP /* % and ~ */# define PAGERHELP "%X/pager.help"# endif# ifndef SUBSHELP /* % and ~ */# define SUBSHELP "%X/subs.help"# endif#endif#define TCSIZE 512 /* capacity for termcap strings */#ifdef EDIT_DISTANCE# define MIN_DIST 7 /* Maximum error count for acceptable match */#endif/* Additional ideas: * Make the do_newsgroup() routine a separate process. * Keep .newsrc on disk instead of in memory. * Overlays, if you have them. * Get a bigger machine. *//* End of Space Conservation Section *//* More System Dependencies *//* news library */#ifndef NEWSLIB /* ~ and %l only ("~%l" is permissable) */# define NEWSLIB "/usr/lib/news"#endif/* path to private executables */#ifndef PRIVLIB /* ~, %x and %l only */# define PRIVLIB "%x/trn"#endif/* system-wide RNINIT switches */#ifndef GLOBINIT# define GLOBINIT "%X/INIT"#endif/* where to find news files */#ifndef NEWSSPOOL /* % and ~ */# define NEWSSPOOL "/usr/spool/news"#endif#ifndef THREAD_DIR# undef LONG_THREAD_NAMES#endif/* default characters to use in the selection menu */#ifndef SELECTCHARS# define SELECTCHARS "abdefgijlorstuvwxyz1234567890BCFGHIKVW"#endif/* file containing list of active newsgroups and max article numbers */#ifndef ACTIVE /* % and ~ */# define ACTIVE "%x/active"#endif#ifndef DBINIT# define DBINIT "%W/db.init"#endif#ifdef USE_NNTP# ifndef ACTIVE_TIMES# define APPEND_UNSUB# endif#else# ifdef USE_XTHREAD# undef USE_XTHREAD# endif# ifdef USE_XOVER# undef USE_XOVER# endif#endif/* location of history file */#ifndef ARTFILE /* % and ~ */# define ARTFILE "%x/history"#endif/* command to setup a new .newsrc */#ifndef NEWSETUP /* % and ~ */# define NEWSETUP "newsetup"#endif/* command to display a list of un-subscribed-to newsgroups */#ifndef NEWSGROUPS /* % and ~ */# define NEWSGROUPS "newsgroups"#endif/* preferred shell for use in doshell routine *//* ksh or sh would be okay here */#ifndef PREFSHELL# define PREFSHELL "/bin/csh"#endif/* path to fastest starting shell */#ifndef SH# define SH "/bin/sh"#endif/* default unshar'ing program */#ifndef UNSHAR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -