annotate lib-src/fakemail.c @ 5457:4ed2dedf36a1

Copyright and license to etc/sample.Xresource.
author Mats Lidell <matsl@xemacs.org>
date Fri, 14 Jan 2011 23:32:08 +0100
parents b9167d522a9a
children a9094f28f9a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* sendmail-like interface to /bin/mail for system V,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 442
diff changeset
4 This file is part of XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
6 XEmacs is free software: you can redistribute it and/or modify it
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
7 under the terms of the GNU General Public License as published by the
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
8 Free Software Foundation, either version 3 of the License, or (at your
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
9 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
14 for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 4932
diff changeset
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 /* Synched up with: FSF 19.28. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 #define NO_SHORTNAMES
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 434
diff changeset
22 #include <config.h>
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #if defined (BSD) && !defined (BSD4_1) && !defined (USE_FAKEMAIL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* This program is not used in BSD, so just avoid loader complaints. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #elif defined (LINUX)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 int
2509
6a9afa282c8e [xemacs-hg @ 2005-01-26 09:53:28 by ben]
ben
parents: 2286
diff changeset
35 main (int argc, char *argv[])
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 /* Linux /bin/mail, if it exists, is NOT the Unix v7 mail that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 fakemail depends on! This causes garbled mail. Better to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 output an error message. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 fprintf (stderr, "Sorry, fakemail does not work on Linux.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 fprintf (stderr, "Make sure you have the sendmail program, and\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 fprintf (stderr, "set the Lisp variable `sendmail-program' to point\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 fprintf (stderr, "to the path of the sendmail binary.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #else /* not BSD 4.2 (or newer) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 /* These are defined in config in some versions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #ifdef static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #undef static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #ifdef read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #undef read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #undef write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #undef open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #undef close
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #if __STDC__ || defined(STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #include <ctype.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include <time.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #include <pwd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 /* Type definitions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #define boolean int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #define true 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #define false 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 /* Various lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 struct line_record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 char *string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 struct line_record *continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 typedef struct line_record *line_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 struct header_record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 line_list text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 struct header_record *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 struct header_record *previous;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 typedef struct header_record *header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 struct stream_record
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 FILE *handle;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 int (*action)(FILE *);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 struct stream_record *rest_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 typedef struct stream_record *stream_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* A `struct linebuffer' is a structure which holds a line of text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 * `readline' reads a line from a stream into a linebuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 * and works regardless of the length of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 struct linebuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
109 size_t size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 char *buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 struct linebuffer lb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #define new_list() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ((line_list) xmalloc (sizeof (struct line_record)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #define new_header() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ((header) xmalloc (sizeof (struct header_record)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 #define new_stream() \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ((stream_list) xmalloc (sizeof (struct stream_record)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 #define alloc_string(nchars) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ((char *) xmalloc ((nchars) + 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 /* Global declarations */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #define BUFLEN 1024
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 #define KEYWORD_SIZE 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #define FROM_PREFIX "From"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 #define MY_NAME "fakemail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 #define NIL ((line_list) NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #define INITIAL_LINE_SIZE 200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #define MAIL_PROGRAM_NAME "/bin/mail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
134 static const char *my_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 static char *the_date;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 static char *the_user;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 static line_list file_preface;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 static stream_list the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 static boolean no_problems = true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 #if !__STDC__ && !defined(STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 extern FILE *popen ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 extern int fclose (), pclose ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 extern char *malloc (), *realloc ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146
2687
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
147 #if defined(__FreeBSD_version) && __FreeBSD_version >= 400000
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
148 #define CURRENT_USER
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
149 #endif
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
150
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 #ifdef CURRENT_USER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 extern struct passwd *getpwuid ();
2687
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
153 #if defined(__FreeBSD_version) && __FreeBSD_version >= 400000
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
154 extern uid_t geteuid ();
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
155 #else
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
156 extern unsigned short geteuid ();
45609533aa75 [xemacs-hg @ 2005-03-25 16:34:53 by aidan]
aidan
parents: 2509
diff changeset
157 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 static struct passwd *my_entry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 #define cuserid(s) \
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
160 (my_entry = getpwuid ((int) geteuid ()), \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 my_entry->pw_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 /* Utilities */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
169 error (const char *s1, const char *s2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 printf ("%s: ", my_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 printf (s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 printf ("\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 no_problems = false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* Print error message and exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
180 fatal (const char *s1, const char *s2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 error (s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 /* Like malloc but get fatal error if memory is exhausted. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
188 static void *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 xmalloc (size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
191 void *result = malloc (size);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
192 if (result == NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 fatal ("virtual memory exhausted", (char *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
197 static void *
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
198 xrealloc (void *ptr, size_t size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
200 void *result = realloc (ptr, size);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
201 if (result == NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 fatal ("virtual memory exhausted", (char *) 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 /* Initialize a linebuffer for use */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 init_linebuffer (struct linebuffer *linebuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 linebuffer->size = INITIAL_LINE_SIZE;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
212 linebuffer->buffer = (char *) xmalloc (INITIAL_LINE_SIZE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 /* Read a line of text from `stream' into `linebuffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 * Return the length of the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 static long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 readline (struct linebuffer *linebuffer, FILE *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 char *buffer = linebuffer->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 char *p = linebuffer->buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 char *end = p + linebuffer->size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 while (true)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 int c = getc (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 if (p == end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 linebuffer->size *= 2;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
232 buffer = (char *) xrealloc (buffer, linebuffer->size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 p = buffer + (p - linebuffer->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 end = buffer + linebuffer->size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 linebuffer->buffer = buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 if (c < 0 || c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 *p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 *p++ = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 return p - buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 get_keyword (register char *field, char **rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 static char keyword[KEYWORD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 register char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 register char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ptr = &keyword[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 c = *field++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 if ((isspace ((int) (unsigned char) c)) || (c == ':'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 return (char *) NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 *ptr++ = ((islower ((int) (unsigned char) c)) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (toupper ((int) (unsigned char) c)) : c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 while (((c = *field++) != ':') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (!(isspace ((int) (unsigned char) c))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 *ptr++ = ((islower ((int) (unsigned char) c)) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (toupper ((int) (unsigned char) c)) : c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 *ptr++ = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 while (isspace ((int) (unsigned char) c)) c = *field++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 if (c != ':') return (char *) NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 *rest = field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 return &keyword[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 has_keyword (char *field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 char *ignored;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
276 return (get_keyword (field, &ignored) != (char *) NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 add_field (line_list the_list, register char *field, register char *where)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 register char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 while (true)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 *where++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 while ((c = *field++) != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 if (c == '(')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 while (*field && *field != ')') ++field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 if (! (*field++)) break; /* no closer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 if (! (*field)) break; /* closerNULL */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 c = *field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 *where++ = ((c == ','||c=='>'||c=='<') ? ' ' : c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 if (the_list == NIL) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 field = the_list->string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 the_list = the_list->continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 return where;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 static line_list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 make_file_preface (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 char *the_string, *temp;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
308 time_t idiotic_interface;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 long prefix_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 long user_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 long date_length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 line_list result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 prefix_length = strlen (FROM_PREFIX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 time (&idiotic_interface);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 the_date = ctime (&idiotic_interface);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 /* the_date has an unwanted newline at the end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 date_length = strlen (the_date) - 1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
319 if (the_date[date_length] == '\n')
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
320 the_date[date_length] = '\0';
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
321 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 temp = "(null)";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 temp = cuserid ((char *) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 user_length = strlen (temp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 the_user = alloc_string ((size_t) (user_length + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 strcpy (the_user, temp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 the_string = alloc_string ((size_t) (3 + prefix_length +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 user_length +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 date_length));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 temp = the_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 strcpy (temp, FROM_PREFIX);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 temp = &temp[prefix_length];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 *temp++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 strcpy (temp, the_user);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 temp = &temp[user_length];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 *temp++ = ' ';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 strcpy (temp, the_date);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 result = new_list ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 result->string = the_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 result->continuation = ((line_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 write_line_list (register line_list the_list, FILE *the_stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 for ( ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 the_list != ((line_list) NULL) ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 the_list = the_list->continuation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 fputs (the_list->string, the_stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 putc ('\n', the_stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 close_the_streams (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 register stream_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 for (rem = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 rem != ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 rem = rem->rest_streams)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 no_problems = (no_problems &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ((*rem->action) (rem->handle) == 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 the_streams = ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 return (no_problems ? 0 : 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 add_a_stream (FILE *the_stream, int (*closing_action)(FILE *))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 stream_list old = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 the_streams = new_stream ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 the_streams->handle = the_stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 the_streams->action = closing_action;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 the_streams->rest_streams = old;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 my_fclose (FILE *the_file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 putc ('\n', the_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 fflush (the_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 return fclose (the_file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 static boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 open_a_file (char *name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 FILE *the_stream = fopen (name, "a");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 if (the_stream != ((FILE *) NULL))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 add_a_stream (the_stream, my_fclose);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
398 if (the_user == (char *) NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 file_preface = make_file_preface ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 write_line_list (file_preface, the_stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 return true;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 return false;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 put_string (char *s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 register stream_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 for (rem = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 rem != ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 rem = rem->rest_streams)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 fputs (s, rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
418 put_line (const char *string)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 register stream_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 for (rem = the_streams;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 rem != ((stream_list) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 rem = rem->rest_streams)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
425 const char *s = string;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 int column = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 /* Divide STRING into lines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 while (*s != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
431 const char *breakpos;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 /* Find the last char that fits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 for (breakpos = s; *breakpos && column < 78; ++breakpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 if (*breakpos == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 column += 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 column++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 /* If we didn't reach end of line, break the line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 if (*breakpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 /* Back up to just after the last comma that fits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 while (breakpos != s && breakpos[-1] != ',') --breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 if (breakpos == s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 /* If no comma fits, move past the first address anyway. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 while (*breakpos != 0 && *breakpos != ',') ++breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 if (*breakpos != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 /* Include the comma after it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 ++breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 /* Output that much, then break the line. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 fwrite (s, 1, breakpos - s, rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 column = 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 /* Skip whitespace and prepare to print more addresses. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 s = breakpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 while (*s == ' ' || *s == '\t') ++s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 if (*s != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 fputs ("\n\t", rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 putc ('\n', rem->handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 #define mail_error error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 setup_files (register line_list the_list, register char *field)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 register char *start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 register char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 while (true)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 while (((c = *field) != '\0') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 ((c == ' ') ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (c == '\t') ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (c == ',')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 field += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 if (c != '\0')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 start = field;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 while (((c = *field) != '\0') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 (c != ' ') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (c != '\t') &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (c != ','))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 field += 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 *field = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 if (!open_a_file (start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 mail_error ("Could not open file %s", start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 *field = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 if (c != '\0') continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 if (the_list == ((line_list) NULL)) return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 field = the_list->string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 the_list = the_list->continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 args_size (header the_header)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 register line_list rem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 register int size = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 {
4932
8b63e21b0436 fix compile issues with gcc 4
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
513 char *field = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 register char *keyword = get_keyword (the_header->text->string, &field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 if ((strcmp (keyword, "TO") == 0) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (strcmp (keyword, "CC") == 0) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (strcmp (keyword, "BCC") == 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 size += 1 + strlen (field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 for (rem = the_header->text->continuation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 rem != NIL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 rem = rem->continuation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 size += 1 + strlen (rem->string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 the_header = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 } while (the_header != old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 return size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 parse_header (header the_header, register char *where)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 {
4932
8b63e21b0436 fix compile issues with gcc 4
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
536 char *field = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 register char *keyword = get_keyword (the_header->text->string, &field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 if (strcmp (keyword, "TO") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 where = add_field (the_header->text->continuation, field, where);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 else if (strcmp (keyword, "CC") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 where = add_field (the_header->text->continuation, field, where);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 else if (strcmp (keyword, "BCC") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 where = add_field (the_header->text->continuation, field, where);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 the_header->previous->next = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 the_header->next->previous = the_header->previous;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 else if (strcmp (keyword, "FCC") == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 setup_files (the_header->text->continuation, field);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 the_header = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 } while (the_header != old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 *where = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 static header
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 read_header (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 register header the_header = ((header) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 register line_list *next_line = ((line_list *) NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 init_linebuffer (&lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 long length;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 register char *line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 readline (&lb, stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 line = lb.buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 length = strlen (line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 if (length == 0) break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 if (has_keyword (line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 the_header = new_header ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 if (old == ((header) NULL))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 the_header->next = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 the_header->previous = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 the_header->previous = old;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 the_header->next = old->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 old->next = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 next_line = &(the_header->text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 if (next_line == ((line_list *) NULL))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 /* Not a valid header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 *next_line = new_list ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (*next_line)->string = alloc_string ((size_t) length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 strcpy (((*next_line)->string), line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 next_line = &((*next_line)->continuation);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 *next_line = NIL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 } while (true);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 return the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 write_header (header the_header)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 register header old = the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 register line_list the_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 for (the_list = the_header->text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 the_list != NIL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 the_list = the_list->continuation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 put_line (the_list->string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 the_header = the_header->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 } while (the_header != old);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 put_line ("");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 char *command_line;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 header the_header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 long name_length;
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 2687
diff changeset
631 const char *mail_program_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 char buf[BUFLEN + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 register int size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 FILE *the_pipe;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 mail_program_name = getenv ("FAKEMAILER");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 if (!(mail_program_name && *mail_program_name))
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 2687
diff changeset
638 mail_program_name = MAIL_PROGRAM_NAME;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 name_length = strlen (mail_program_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 my_name = MY_NAME;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 the_streams = ((stream_list) NULL);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
643 the_date = (char *) NULL;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
644 the_user = (char *) NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 the_header = read_header ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 command_line = alloc_string ((size_t) (name_length +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 args_size (the_header)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 strcpy (command_line, mail_program_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 parse_header (the_header, &command_line[name_length]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 the_pipe = popen (command_line, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 if (the_pipe == ((FILE *) NULL))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
654 fatal ("cannot open pipe to real mailer", (char *) NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 add_a_stream (the_pipe, pclose);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 write_header (the_header);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 /* Dump the message itself */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 while (!feof (stdin))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 size = fread (buf, 1, BUFLEN, stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 buf[size] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 put_string (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 return close_the_streams ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 #endif /* not BSD 4.2 (or newer) */