xref: /illumos-gate/usr/src/cmd/mailx/init.c (revision 6dde88b51419b99fe0aab8e56184c693945826b8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright (c) 1998 by Sun Microsystems, Inc.
28  * All rights reserved.
29  */
30 
31 /*
32  * University Copyright- Copyright (c) 1982, 1986, 1988
33  * The Regents of the University of California
34  * All Rights Reserved
35  *
36  * University Acknowledgment- Portions of this document are derived from
37  * software developed by the University of California, Berkeley, and its
38  * contributors.
39  */
40 
41 /*
42  * mailx -- a modified version of a University of California at Berkeley
43  *	mail program
44  *
45  * A bunch of global variable declarations lie herein.
46  *
47  * All global externs are declared in def.h. All variables are initialized
48  * here!
49  *
50  * !!!!!IF YOU CHANGE (OR ADD) IT HERE, DO IT THERE ALSO !!!!!!!!
51  *
52  */
53 
54 #include	"def.h"
55 #include	<grp.h>
56 #include	<pwd.h>
57 #include	<sys/utsname.h>
58 
59 int	Fflag = 0;			/* -F option (followup) */
60 int	Hflag = 0;			/* print headers and exit */
61 char	*Tflag;				/* -T temp file for netnews */
62 int	UnUUCP = 0;			/* -U flag */
63 char	**altnames;			/* List of alternate names for user */
64 int	askme;
65 int	baud;				/* Output baud rate */
66 char	*bflag;				/* Bcc given from non tty */
67 char	*binmsg = "*** Message content is not printable: pipe to command or save to a file ***";
68 char	*cflag;				/* Cc given from non tty */
69 int	cond;				/* Current state of conditional exc. */
70 NODE	*curptr = NOFP;
71 int	debug;				/* Debug flag set */
72 struct	message	*dot;			/* Pointer to current message */
73 int	edit;				/* Indicates editing a file */
74 char	*editfile;			/* Name of file being edited */
75 int	exitflg = 0;			/* -e for mail test */
76 NODE	*fplist = NOFP;
77 struct	grouphead	*groups[HSHSIZE];/* Pointer to active groups */
78 int	hflag;				/* Sequence number for network -h */
79 char	homedir[PATHSIZE];		/* Name of home directory */
80 struct	ignore		*ignore[HSHSIZE];/* Pointer to ignored fields */
81 int	image;				/* File descriptor for image of msg */
82 FILE	*input;				/* Current command input file */
83 int	intty;				/* True if standard input a tty */
84 int	issysmbox;			/* mailname is a system mailbox */
85 FILE	*itf;				/* Input temp file buffer */
86 int	lexnumber;			/* Number of TNUMBER from scan() */
87 char	lexstring[STRINGLEN];		/* String from TSTRING, scan() */
88 int	loading;			/* Loading user definitions */
89 char	*lockname;			/* named used for locking in /var/mail */
90 #ifdef	USR_SPOOL_MAIL
91 char	*maildir = "/usr/spool/mail/";	/* directory for mail files */
92 #else
93 # ifdef preSVr4
94 char	*maildir = "/usr/mail/";	/* directory for mail files */
95 # else
96 char	*maildir = "/var/mail/";	/* directory for mail files */
97 # endif
98 #endif
99 char	mailname[PATHSIZE];		/* Name of /var/mail system mailbox */
100 off_t	mailsize;			/* Size of system mailbox */
101 int	maxfiles;			/* Maximum number of open files */
102 struct	message	*message;		/* The actual message structure */
103 int	msgCount;			/* Count of messages read in */
104 gid_t	myegid;
105 uid_t	myeuid;
106 char	myname[PATHSIZE];		/* My login id */
107 pid_t	mypid;				/* Current process id */
108 gid_t	myrgid;
109 uid_t	myruid;
110 int	newsflg = 0;			/* -I option for netnews */
111 char	noheader;			/* Suprress initial header listing */
112 int	noreset;			/* String resets suspended */
113 char	nosrc;				/* Don't source /etc/mail/mailx.rc */
114 int	nretained;			/* Number of retained fields */
115 int	numberstack[REGDEP];		/* Stack of regretted numbers */
116 char	origname[PATHSIZE];		/* Name of mailfile before expansion */
117 FILE	*otf;				/* Output temp file buffer */
118 int	outtty;				/* True if standard output a tty */
119 FILE	*pipef;				/* Pipe file we have opened */
120 char	*progname;			/* program name (argv[0]) */
121 char	*prompt = NOSTR;		/* prompt string */
122 int	rcvmode;			/* True if receiving mail */
123 int	readonly;			/* Will be unable to rewrite file */
124 int	regretp;			/* Pointer to TOS of regret tokens */
125 int	regretstack[REGDEP];		/* Stack of regretted tokens */
126 struct	ignore		*retain[HSHSIZE];/* Pointer to retained fields */
127 char	*rflag;				/* -r address for network */
128 int	rmail;				/* Being called as rmail */
129 int	sawcom;				/* Set after first command */
130 int	selfsent;			/* User sent self something */
131 int	senderr;			/* An error while checking */
132 int	rpterr;				/* An error msg was sent to stderr */
133 char	*sflag;				/* Subject given from non tty */
134 int	sourcing;			/* Currently reading variant file */
135 int	space;				/* Current maximum number of messages */
136 jmp_buf	srbuf;
137 int	tflag;				/* Read headers from text */
138 /*
139  * The pointers for the string allocation routines,
140  * there are NSPACE independent areas.
141  * The first holds STRINGSIZE bytes, the next
142  * twice as much, and so on.
143  */
144 struct strings stringdope[NSPACE];
145 char	*stringstack[REGDEP];		/* Stack of regretted strings */
146 char	tempEdit[TMPSIZ];
147 char	tempMail[TMPSIZ];
148 char	tempMesg[TMPSIZ];
149 char	tempQuit[TMPSIZ];
150 char	tempResid[PATHSIZE];		/* temp file in :saved */
151 char	tempZedit[TMPSIZ];
152 uid_t	uid;				/* The invoker's user id */
153 static struct utimbuf	utimeb;
154 struct utimbuf	*utimep = &utimeb;
155 struct	var	*variables[HSHSIZE];	/* Pointer to active var list */
156 int	receipt_flg = 0;		/* Flag for return receipt */
157