9762 Split the custr functions into their own library
[unleashed.git] / usr / src / cmd / mailx / hdr / def.h
bloba343afab38748f585a36b042262d8073543062c1
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2018 Joyent, Inc.
27 * Copyright (c) 1985, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Copyright (c) 2016 by Delphix. All rights reserved.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
35 * University Copyright- Copyright (c) 1982, 1986, 1988
36 * The Regents of the University of California
37 * All Rights Reserved
39 * University Acknowledgment- Portions of this document are derived from
40 * software developed by the University of California, Berkeley, and its
41 * contributors.
44 #ifndef _MAILX_DEF_H
45 #define _MAILX_DEF_H
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 #include <sys/types.h>
52 #include <signal.h>
53 #include <stdio.h>
54 #include <fcntl.h>
55 #include <string.h>
56 #include <termio.h>
57 #include <setjmp.h>
58 #include <time.h>
59 #include <sys/stat.h>
60 #include <maillock.h>
61 #include <ctype.h>
62 #include <errno.h>
63 #ifndef preSVr4
64 #include <unistd.h>
65 #include <stdlib.h>
66 #include <ulimit.h>
67 #include <wait.h>
68 #include <libcustr.h>
69 #endif
70 #ifdef VMUNIX
71 #include <sys/wait.h>
72 #endif
73 #include "local.h"
74 #include "uparm.h"
77 * mailx -- a modified version of a University of California at Berkeley
78 * mail program
81 #define SENDESC '~' /* Default escape for sending */
82 #define NMLSIZE 1024 /* max names in a message list */
83 #define PATHSIZE 1024 /* Size of pathnames throughout */
84 #define HSHSIZE 59 /* Hash size for aliases and vars */
85 #define HDRFIELDS 3 /* Number of header fields */
86 #define LINESIZE 5120 /* max readable line width */
87 #define STRINGSIZE ((unsigned)128) /* Dynamic allocation units */
88 #define MAXARGC 1024 /* Maximum list of raw strings */
89 #define NOSTR ((char *)0) /* Nill string pointer */
90 #define NOSTRPTR ((char **)0) /* Nill pointer to string pointer */
91 #define NOINTPTR ((int *)0) /* Nill pointer */
92 #define MAXEXP 25 /* Maximum expansion of aliases */
94 /* A nice function to string compare */
95 #define equal(a, b) (strcmp(a, b) == 0)
97 /* Keep a list of all opened files */
98 #define fopen(s, t) my_fopen(s, t)
100 /* Delete closed file from the list */
101 #define fclose(s) my_fclose(s)
103 struct message {
104 off_t m_offset; /* offset in block of message */
105 long m_size; /* Bytes in the message */
106 long m_lines; /* Lines in the message */
107 long m_clen; /* Content-Length of the mesg */
108 short m_flag; /* flags, see below */
109 char m_text; /* TRUE if the contents is text */
110 /* False otherwise */
113 typedef struct fplst {
114 FILE *fp;
115 struct fplst *next;
116 } NODE;
119 * flag bits.
122 #define MUSED (1<<0) /* entry is used, but this bit isn't */
123 #define MDELETED (1<<1) /* entry has been deleted */
124 #define MSAVED (1<<2) /* entry has been saved */
125 #define MTOUCH (1<<3) /* entry has been noticed */
126 #define MPRESERVE (1<<4) /* keep entry in sys mailbox */
127 #define MMARK (1<<5) /* message is marked! */
128 #define MODIFY (1<<6) /* message has been modified */
129 #define MNEW (1<<7) /* message has never been seen */
130 #define MREAD (1<<8) /* message has been read sometime. */
131 #define MSTATUS (1<<9) /* message status has changed */
132 #define MBOX (1<<10) /* Send this to mbox, regardless */
133 #define MBOXED (1<<11) /* message has been sent to mbox */
135 #define H_AFWDCNT 1 /* "Auto-Forward-Count:" */
136 #define H_AFWDFROM 2 /* "Auto-Forwarded-From:" */
137 #define H_CLEN 3 /* "Content-Length:" */
138 #define H_CTYPE 4 /* "Content-Type:" */
139 #define H_DATE 5 /* "Date:" */
140 #define H_DEFOPTS 6 /* "Default-Options:" */
141 #define H_EOH 7 /* "End-of-Header:" */
142 #define H_FROM 8 /* "From " */
143 #define H_FROM1 9 /* ">From " */
144 #define H_FROM2 10 /* "From: " */
145 #define H_MTSID 11 /* "MTS-Message-ID:" */
146 #define H_MTYPE 12 /* "Message-Type:" */
147 #define H_MVERS 13 /* "Message-Version:" */
148 #define H_MSVC 14 /* "Message-Service:" */
149 #define H_RECEIVED 15 /* "Received:" */
150 #define H_RVERS 16 /* "Report-Version:" */
151 #define H_STATUS 17 /* "Status:" */
152 #define H_SUBJ 18 /* "Subject:" */
153 #define H_TO 19 /* "To:" */
154 #define H_TCOPY 20 /* ">To:" */
155 #define H_TROPTS 21 /* "Transport-Options:" */
156 #define H_UAID 22 /* "UA-Content-ID:" */
158 #define H_DAFWDFROM 23 /* Hold A-F-F when sending Del. Notf. */
159 #define H_DTCOPY 24 /* Hold ">To:" when sending Del. Notf. */
160 #define H_DRECEIVED 25 /* Hold Rcvd: when sending Del. Notf. */
161 #define H_CONT 26 /* Continuation of previous line */
162 #define H_NAMEVALUE 27 /* unrecognized "name: value" hdr line */
165 * Format of the command description table.
166 * The actual table is declared and initialized
167 * in lex.c
170 struct cmd {
171 char *c_name; /* Name of command */
172 int (*c_func)(void *); /* Implementor of the command */
173 short c_argtype; /* Type of arglist (see below) */
174 short c_msgflag; /* Required flags of messages */
175 short c_msgmask; /* Relevant flags of messages */
178 /* can't initialize unions */
180 #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
181 #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
184 * Argument types.
187 #define MSGLIST 0 /* Message list type */
188 #define STRLIST 1 /* A pure string */
189 #define RAWLIST 2 /* Shell string list */
190 #define NOLIST 3 /* Just plain 0 */
191 #define NDMLIST 4 /* Message list, no defaults */
193 #define P 040 /* Autoprint dot after command */
194 #define I 0100 /* Interactive command bit */
195 #define M 0200 /* Legal from send mode bit */
196 #define W 0400 /* Illegal when read only bit */
197 #define F 01000 /* Is a conditional command */
198 #define T 02000 /* Is a transparent command */
199 #define R 04000 /* Cannot be called from collect */
202 * Oft-used mask values
205 #define MMNORM (MDELETED|MSAVED) /* Look at both save and delete bits */
206 #define MMNDEL MDELETED /* Look only at deleted bit */
209 * Structure used to return a break down of a head
210 * line
213 typedef struct headline {
214 custr_t *hl_from; /* The name of the sender */
215 custr_t *hl_tty; /* Its tty string (if any) */
216 custr_t *hl_date; /* The entire date string */
217 } headline_t;
219 #define GTO 1 /* Grab To: line */
220 #define GSUBJECT 2 /* Likewise, Subject: line */
221 #define GCC 4 /* And the Cc: line */
222 #define GBCC 8 /* And also the Bcc: line */
223 #define GDEFOPT 16 /* And the Default-Options: lines */
224 #define GNL 32 /* Print blank line after */
225 #define GOTHER 64 /* Other header lines */
226 #define GMASK (GTO|GSUBJECT|GCC|GBCC|GDEFOPT|GNL|GOTHER)
227 /* Mask of all header lines */
228 #define GDEL 128 /* Entity removed from list */
229 #define GCLEN 256 /* Include Content-Length header */
232 * Structure used to pass about the current
233 * state of the user-typed message header.
236 struct header {
237 char *h_to; /* Dynamic "To:" string */
238 char *h_subject; /* Subject string */
239 char *h_cc; /* Carbon copies string */
240 char *h_bcc; /* Blind carbon copies */
241 char *h_defopt; /* Default options */
242 char **h_others; /* Other header lines */
243 int h_seq; /* Sequence for optimization */
247 * Structure of namelist nodes used in processing
248 * the recipients of mail and aliases and all that
249 * kind of stuff.
252 struct name {
253 struct name *n_flink; /* Forward link in list. */
254 struct name *n_blink; /* Backward list link */
255 short n_type; /* From which list it came */
256 char *n_name; /* This fella's name */
257 char *n_full; /* Full name */
261 * Structure of a variable node. All variables are
262 * kept on a singly-linked list of these, rooted by
263 * "variables"
266 struct var {
267 struct var *v_link; /* Forward link to next variable */
268 char *v_name; /* The variable's name */
269 char *v_value; /* And it's current value */
272 struct mgroup {
273 struct mgroup *ge_link; /* Next person in this group */
274 char *ge_name; /* This person's user name */
277 struct grouphead {
278 struct grouphead *g_link; /* Next grouphead in list */
279 char *g_name; /* Name of this group */
280 struct mgroup *g_list; /* Users in group. */
283 #define NIL ((struct name *)0) /* The nil pointer for namelists */
284 #define NONE ((struct cmd *)0) /* The nil pointer to command tab */
285 #define NOVAR ((struct var *)0) /* The nil pointer to variables */
286 #define NOGRP ((struct grouphead *)0) /* The nil grouphead pointer */
287 #define NOGE ((struct mgroup *)0) /* The nil group pointer */
288 #define NOFP ((struct fplst *)0) /* The nil file pointer */
290 #define TRUE 1
291 #define FALSE 0
293 #define DEADPERM 0600 /* permissions of dead.letter */
294 #define TEMPPERM 0600 /* permissions of temp files */
295 #define MBOXPERM 0600 /* permissions of ~/mbox */
297 #ifndef MFMODE
298 #define MFMODE 0600 /* create mode for `/var/mail' files */
299 #endif
302 * Structure of the hash table of ignored header fields
304 struct ignore {
305 struct ignore *i_link; /* Next ignored field in bucket */
306 char *i_field; /* This ignored field */
309 #ifdef preSVr4
310 struct utimbuf {
311 time_t actime;
312 time_t modtime;
314 #else
315 #include <utime.h>
316 #endif
319 * Token values returned by the scanner used for argument lists.
320 * Also, sizes of scanner-related things.
323 #define TEOL 0 /* End of the command line */
324 #define TNUMBER 1 /* A message number */
325 #define TDASH 2 /* A simple dash */
326 #define TSTRING 3 /* A string (possibly containing -) */
327 #define TDOT 4 /* A "." */
328 #define TUP 5 /* An "^" */
329 #define TDOLLAR 6 /* A "$" */
330 #define TSTAR 7 /* A "*" */
331 #define TOPEN 8 /* An '(' */
332 #define TCLOSE 9 /* A ')' */
333 #define TPLUS 10 /* A '+' */
335 #define REGDEP 2 /* Maximum regret depth. */
336 #define STRINGLEN 1024 /* Maximum length of string token */
339 * Constants for conditional commands. These describe whether
340 * we should be executing stuff or not.
343 #define CANY 0 /* Execute in send or receive mode */
344 #define CRCV 1 /* Execute in receive mode only */
345 #define CSEND 2 /* Execute in send mode only */
346 #define CTTY 3 /* Execute if attached to a tty only */
347 #define CNOTTY 4 /* Execute if not attached to a tty */
350 * Flags for msend().
353 #define M_IGNORE 1 /* Do "ignore/retain" processing */
354 #define M_SAVING 2 /* Saving to a file/folder */
357 * VM/UNIX has a vfork system call which is faster than forking. If we
358 * don't have it, fork(2) will do . . .
361 #if !defined(VMUNIX) && defined(preSVr4)
362 #define vfork() fork()
363 #endif
364 #ifndef SIGRETRO
365 #define sigchild()
366 #endif
370 * 4.2bsd signal interface help...
372 #ifdef VMUNIX
373 #define sigset(s, a) signal(s, a)
374 #define sigsys(s, a) signal(s, a)
375 #else
376 #ifndef preSVr4
377 /* SVr4 version of sigset() in fio.c */
378 #define sigsys(s, a) signal(s, a)
379 #define setjmp(x) sigsetjmp((x), 1)
380 #define longjmp siglongjmp
381 #define jmp_buf sigjmp_buf
382 #else
383 #define OLD_BSD_SIGS
384 #endif
385 #endif
388 * Truncate a file to the last character written. This is
389 * useful just before closing an old file that was opened
390 * for read/write.
392 #define trunc(stream) ftruncate(fileno(stream), (long)ftell(stream))
395 * The pointers for the string allocation routines,
396 * there are NSPACE independent areas.
397 * The first holds STRINGSIZE bytes, the next
398 * twice as much, and so on.
401 #define NSPACE 25 /* Total number of string spaces */
402 struct strings {
403 char *s_topFree; /* Beginning of this area */
404 char *s_nextFree; /* Next alloctable place here */
405 unsigned s_nleft; /* Number of bytes left here */
408 /* The following typedefs must be used in SVR4 */
409 #ifdef preSVr4
410 #ifndef sun
411 typedef int gid_t;
412 typedef int uid_t;
413 typedef int mode_t;
414 typedef int pid_t;
415 #endif
416 #endif
418 #define STSIZ 40
419 #define TMPSIZ 14
421 * Forward declarations of routine types to keep lint and cc happy.
424 extern int Copy(int *msgvec);
425 extern FILE *Fdopen(int fildes, char *mode);
426 extern int Followup(int *msgvec);
427 extern char *Getf(register char *s);
428 extern int More(int *msgvec);
429 extern int Respond(int *msgvec);
430 extern int Save(int *msgvec);
431 extern int Sendm(char *str);
432 extern int Sput(char str[]);
433 extern int Type(int *msgvec);
434 extern void Verhogen(void);
435 extern char *addone(char hf[], char news[]);
436 extern char *addto(char hf[], char news[]);
437 extern void alter(char name[]);
438 extern int alternates(char **namelist);
439 extern void announce(void);
440 extern int any(int ch, char *str);
441 extern int anyof(register char *s1, register char *s2);
442 extern int argcount(char **argv);
443 extern void assign(char name[], char value[]);
444 extern int blankline(const char linebuf[]);
445 extern struct name *cat(struct name *n1, struct name *n2);
446 extern FILE *collect(struct header *hp);
447 extern void commands(void);
448 extern char *copy(char *str1, char *str2);
449 extern int copycmd(char str[]);
450 extern int deassign(register char *s);
451 extern int delm(int *msgvec);
452 extern struct name *delname(register struct name *np, char name[]);
453 extern int deltype(int msgvec[]);
454 extern char *detract(register struct name *np, int ntype);
455 extern int docomma(char *s);
456 extern int dopipe(char str[]);
457 extern int dosh(char *str);
458 extern int echo(register char **argv);
459 extern int editor(int *msgvec);
460 extern int edstop(int noremove);
461 extern struct name *elide(struct name *names);
462 extern int elsecmd(void);
463 extern int endifcmd(void);
464 extern int execute(char linebuf[], int contxt);
465 extern char *expand(char *name);
466 extern struct name *extract(char line[], int arg_ntype);
467 extern int fferror(FILE *iob);
468 extern int field(char str[]);
469 extern int file(char **argv);
470 extern struct grouphead *findgroup(char name[]);
471 extern void findmail(char *name);
472 extern int first(int f, int m);
473 extern void flush(void);
474 extern int folders(char **arglist);
475 extern int followup(int *msgvec);
476 extern int from(int *msgvec);
477 extern off_t fsize(FILE *iob);
478 extern int getfold(char *name);
479 extern int gethfield(register FILE *f, char linebuf[], register long rem);
480 extern int getaline(char *line, int size, FILE *f, int *hasnulls);
481 extern int getmessage(char *buf, int *vector, int flags);
482 extern int getmsglist(char *buf, int *vector, int flags);
483 extern int getname(uid_t uid, char namebuf[]);
484 extern int getrawlist(char line[], char **argv, int argc);
485 extern void getrecf(char *buf, char *recfile,
486 int useauthor, int sz_recfile);
487 extern uid_t getuserid(char name[]);
488 extern int grabh(register struct header *hp, int gflags, int subjtop);
489 extern int group(char **argv);
490 extern void hangup(int);
491 extern int hash(char name[]);
492 extern char *hcontents(char hfield[]);
493 extern int headerp(register char *line);
494 extern int headers(int *msgvec);
495 extern int headline_alloc(headline_t **);
496 extern void headline_free(headline_t *);
497 extern void headline_reset(headline_t *);
498 extern int help(void);
499 extern char *helppath(char *file);
500 extern char *hfield(char field[], struct message *mp,
501 char *(*add)(char *, char *));
502 extern void holdsigs(void);
503 extern int icequal(register char *s1, register char *s2);
504 extern int ifcmd(char **argv);
505 extern int igfield(char *list[]);
506 extern int inc(void);
507 extern void inithost(void);
508 extern int isdir(char name[]);
509 extern boolean_t is_headline(const char *);
510 extern int ishfield(char linebuf[], char field[]);
511 extern int ishost(char *sys, char *rest);
512 extern int isign(char *field, int saving);
513 extern void istrcpy(char *dest, int dstsize, char *src);
514 extern void lcwrite(char *fn, FILE *fi, FILE *fo, int addnl);
515 extern void load(char *name);
516 extern int loadmsg(char str[]);
517 extern int lock(FILE *fp, char *mode, int blk);
518 extern void lockmail(void);
519 extern int mail(char **people);
520 extern void mail1(struct header *hp, int use_to, char *orig_to);
521 extern void mapf(register struct name *np, char *from);
522 extern int mboxit(int msgvec[]);
523 extern void mechk(struct name *names);
524 extern int member(register char *realfield,
525 register struct ignore **table);
526 extern int messize(int *msgvec);
527 extern void minit(void);
528 extern int more(int *msgvec);
529 extern long msend(struct message *mailp, FILE *obuf,
530 int flag, int (*fp)(const char *, FILE *));
531 extern int my_fclose(register FILE *iop);
532 extern FILE *my_fopen(char *file, char *mode);
533 extern char *nameof(register struct message *mp);
534 extern char *netmap(char name[], char from[]);
535 extern int newfileinfo(int start);
536 extern int next(int *msgvec);
537 extern int npclose(FILE *ptr);
538 extern FILE *npopen(char *cmd, char *mode);
539 extern char *nstrcpy(char *dst, int dstsize, char *src);
540 extern char *nstrcat(char *dst, int dstsize, char *src);
541 extern int null(char *e);
542 extern int outof(struct name *names, FILE *fo);
543 extern struct name *outpre(struct name *to);
544 extern void panic(char *str);
545 extern int parse_headline(const char *, headline_t *);
546 extern int pcmdlist(void);
547 extern int pdot(void);
548 extern int preserve(int *msgvec);
549 extern void printgroup(char name[]);
550 extern void printhead(int mesg);
551 extern int puthead(struct header *hp, FILE *fo, int w, long clen);
552 extern int pversion(char *e);
553 extern void quit(int noremove);
554 extern int readline(FILE *ibuf, char *linebuf);
555 extern void receipt(struct message *mp);
556 extern void relsesigs(void);
557 extern int removefile(char name[]);
558 extern int replyall(int *msgvec);
559 extern int replysender(int *msgvec);
560 extern int respond(int *msgvec);
561 extern int retfield(char *list[]);
562 extern int rexit(int e);
563 extern char *safeexpand(char name[]);
564 extern void *salloc(unsigned size);
565 extern void *srealloc(void *optr, unsigned size);
566 extern int samebody(register char *user, register char *addr,
567 int fuzzy);
568 extern int save(char str[]);
569 extern void savedead(int s);
570 extern char *savestr(char *str);
571 extern int schdir(char *str);
572 extern int screensize(void);
573 extern int scroll(char arg[]);
574 extern int sendm(char *str);
575 extern int set(char **arglist);
576 extern void setclen(register struct message *mp);
577 extern int setfile(char *name, int isedit);
578 extern FILE *setinput(register struct message *mp);
579 extern void setptr(register FILE *ibuf);
580 extern int shell(char *str);
581 #ifndef sigchild
582 extern void sigchild(void);
583 #endif
584 #ifndef sigset
585 extern void (*sigset())();
586 #endif
587 extern char *skin(char *name);
588 extern char *snarf(char linebuf[], int *flag, int erf);
589 extern int source(char name[]);
590 extern char *splice(char *addr, char *hdr);
591 extern int sput(char str[]);
592 extern void sreset(void);
593 extern void stop(int s);
594 extern int stouch(int msgvec[]);
595 extern int substr(char *string1, char *string2);
596 extern int swrite(char str[]);
597 extern struct name *tailof(struct name *name);
598 extern void tinit(void);
599 extern int tmail(void);
600 extern int top(int *msgvec);
601 extern void touch(int mesg);
602 extern struct name *translate(struct name *np);
603 extern int type(int *msgvec);
604 extern int undelete(int *msgvec);
605 extern int ungroup(char **argv);
606 extern int unigfield(char *list[]);
607 extern void unlockmail(void);
608 extern char **unpack(struct name *np);
609 extern int unread(int msgvec[]);
610 extern int unretfield(char *list[]);
611 extern int unset(char **arglist);
612 extern int unstack(void);
613 extern char *unuucp(char *name);
614 extern struct name *usermap(struct name *names);
615 extern char *value(char name[]);
616 extern char *vcopy(char str[]);
617 extern void vfree(register char *cp);
618 extern int visual(int *msgvec);
619 extern char *yankword(char *name, char *word, int sz, int comma);
622 * These functions are defined in libmail.a
624 #ifdef __cplusplus
625 extern "C" {
626 #endif
627 extern int delempty(mode_t, char *);
628 extern char *maildomain(void);
629 extern void touchlock(void);
630 extern char *xgetenv(char *);
631 extern int xsetenv(char *);
632 #ifdef __cplusplus
634 #endif
637 * Standard functions from the C library.
638 * These are all defined in <stdlib.h> and <wait.h> in SVr4.
640 #ifdef preSVr4
641 extern long atol();
642 extern char *getcwd();
643 extern char *calloc();
644 extern char *getenv();
645 extern void exit();
646 extern void free();
647 extern char *malloc();
648 extern time_t time();
649 extern long ulimit();
650 extern int utime();
651 extern int wait();
652 extern int fputs();
653 #endif
655 #ifdef __cplusplus
657 #endif
659 #endif /* _MAILX_DEF_H */