annotate lib-src/b2m.c @ 107984:bef5d1738c0b

Make variable forwarding explicit rather the using special values. Basically, this makes the structure of buffer-local values and object forwarding explicit in the type of Lisp_Symbols rather than use special Lisp_Objects for that. This tends to lead to slightly more verbose code, but is more C-like, simpler, and makes it easier to make sure we handled all cases, among other things by letting the compiler help us check it. * lisp.h (enum Lisp_Misc_Type, union Lisp_Misc): Removing forwarding objects. (enum Lisp_Fwd_Type, enum symbol_redirect, union Lisp_Fwd): New types. (struct Lisp_Symbol): Make the various forms of variable-forwarding explicit rather than hiding them inside Lisp_Object "values". (XFWDTYPE): New macro. (XINTFWD, XBOOLFWD, XOBJFWD, XKBOARD_OBJFWD): Redefine. (XBUFFER_LOCAL_VALUE): Remove. (SYMBOL_VAL, SYMBOL_ALIAS, SYMBOL_BLV, SYMBOL_FWD, SET_SYMBOL_VAL) (SET_SYMBOL_ALIAS, SET_SYMBOL_BLV, SET_SYMBOL_FWD): New macros. (SYMBOL_VALUE, SET_SYMBOL_VALUE): Remove. (struct Lisp_Intfwd, struct Lisp_Boolfwd, struct Lisp_Objfwd) (struct Lisp_Buffer_Objfwd, struct Lisp_Kboard_Objfwd): Remove the Lisp_Misc_* header. (struct Lisp_Buffer_Local_Value): Redefine. (BLV_FOUND, SET_BLV_FOUND, BLV_VALUE, SET_BLV_VALUE): New macros. (struct Lisp_Misc_Any): Add filler to get the right size. (struct Lisp_Free): Use struct Lisp_Misc_Any rather than struct Lisp_Intfwd. (DEFVAR_LISP, DEFVAR_LISP_NOPRO, DEFVAR_BOOL, DEFVAR_INT) (DEFVAR_KBOARD): Allocate a forwarding object. * data.c (do_blv_forwarding, store_blv_forwarding): New macros. (let_shadows_global_binding_p): New function. (union Lisp_Val_Fwd): New type. (make_blv): New function. (swap_in_symval_forwarding, indirect_variable, do_symval_forwarding) (store_symval_forwarding, swap_in_global_binding, Fboundp) (swap_in_symval_forwarding, find_symbol_value, Fset) (let_shadows_buffer_binding_p, set_internal, default_value) (Fset_default, Fmake_variable_buffer_local, Fmake_local_variable) (Fkill_local_variable, Fmake_variable_frame_local) (Flocal_variable_p, Flocal_variable_if_set_p) (Fvariable_binding_locus): * xdisp.c (select_frame_for_redisplay): * lread.c (Fintern, Funintern, init_obarray, defvar_int) (defvar_bool, defvar_lisp_nopro, defvar_lisp, defvar_kboard): * frame.c (store_frame_param): * eval.c (Fdefvaralias, Fuser_variable_p, specbind, unbind_to): * bytecode.c (Fbyte_code) <varref, varset>: Adapt to the new symbol value structure. * buffer.c (PER_BUFFER_SYMBOL): Move from buffer.h. (clone_per_buffer_values): Only adjust markers into the current buffer. (reset_buffer_local_variables): PER_BUFFER_IDX is never -2. (Fbuffer_local_value, set_buffer_internal_1) (swap_out_buffer_local_variables): Adapt to the new symbol value structure. (DEFVAR_PER_BUFFER): Allocate a Lisp_Buffer_Objfwd object. (defvar_per_buffer): Take a new arg for the fwd object. (buffer_lisp_local_variables): Return a proper alist (different fix for bug#4138). * alloc.c (Fmake_symbol): Use SET_SYMBOL_VAL. (Fgarbage_collect): Don't handle buffer_defaults specially. (mark_object): Handle new symbol value structure rather than the old special Lisp_Misc_* objects. (gc_sweep) <symbols>: Free also the buffer-local-value objects. * term.c (set_tty_color_mode): * bidi.c (bidi_initialize): Don't access the ->value field directly. * buffer.h (PER_BUFFER_VAR_OFFSET): Don't bother with a buffer_local_flags. * print.c (print_object): Get rid of impossible forwarding objects.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 19 Apr 2010 21:50:52 -0400
parents 5048b64c7cf0
children 5842e8fabe06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /*
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 * b2m - a filter for Babyl -> Unix mail files
42260
661375cd8c4c Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 40067
diff changeset
3 * The copyright on this file has been disclaimed.
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 * usage: b2m < babyl > mailbox
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 * I find this useful whenever I have to use a
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 * system which - shock horror! - doesn't run
40067
5c3937ee7017 Properly spell the name of Emacs.
Pavel Janík <Pavel@Janik.cz>
parents: 37163
diff changeset
9 * GNU Emacs. At least now I can read all my
5c3937ee7017 Properly spell the name of Emacs.
Pavel Janík <Pavel@Janik.cz>
parents: 37163
diff changeset
10 * GNU Emacs Babyl format mail files!
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 * it's not much but it's free!
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 *
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 * Ed Wilkinson
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 * E.Wilkinson@massey.ac.nz
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 * Mon Nov 7 15:54:06 PDT 1988
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 */
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
19 /* Made conformant to the GNU coding standards January, 1995
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
20 by Francesco Potorti` <pot@cnuce.cnr.it>. */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
21
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
22 #ifdef HAVE_CONFIG_H
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
23 #include <config.h>
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
24 /* On some systems, Emacs defines static as nothing for the sake
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
25 of unexec. We don't want that here since we don't use unexec. */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
26 #undef static
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
27 #endif
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
26083
134b57acef68 Add support for large files. Merge glibc 2.1.2.
Paul Eggert <eggert@twinsun.com>
parents: 21386
diff changeset
29 #include <stdio.h>
134b57acef68 Add support for large files. Merge glibc 2.1.2.
Paul Eggert <eggert@twinsun.com>
parents: 21386
diff changeset
30 #include <time.h>
134b57acef68 Add support for large files. Merge glibc 2.1.2.
Paul Eggert <eggert@twinsun.com>
parents: 21386
diff changeset
31 #include <sys/types.h>
134b57acef68 Add support for large files. Merge glibc 2.1.2.
Paul Eggert <eggert@twinsun.com>
parents: 21386
diff changeset
32 #include <getopt.h>
134b57acef68 Add support for large files. Merge glibc 2.1.2.
Paul Eggert <eggert@twinsun.com>
parents: 21386
diff changeset
33 #ifdef MSDOS
134b57acef68 Add support for large files. Merge glibc 2.1.2.
Paul Eggert <eggert@twinsun.com>
parents: 21386
diff changeset
34 #include <fcntl.h>
21386
49b24e54a5fa Include <stdlib.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 21354
diff changeset
35 #endif
49b24e54a5fa Include <stdlib.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 21354
diff changeset
36
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
37 #undef TRUE
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
38 #define TRUE 1
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
39 #undef FALSE
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
40 #define FALSE 0
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
41
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
42 #define streq(s,t) (strcmp (s, t) == 0)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
43 #define strneq(s,t,n) (strncmp (s, t, n) == 0)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
44
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
45 typedef int logical;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
46
69790
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
47 #define TM_YEAR_BASE 1900
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
48
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
49 /* Nonzero if TM_YEAR is a struct tm's tm_year value that causes
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
50 asctime to have well-defined behavior. */
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
51 #ifndef TM_YEAR_IN_ASCTIME_RANGE
69697
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
52 # define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \
69790
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
53 (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE)
69697
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
54 #endif
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
55
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
56 /*
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
57 * A `struct linebuffer' is a structure which holds a line of text.
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
58 * `readline' reads a line from a stream into a linebuffer and works
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
59 * regardless of the length of the line.
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
60 */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
61 struct linebuffer
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
62 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
63 long size;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
64 char *buffer;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
65 };
8957
4dffbc5d5dc7 (from, labels, data): Use MAX_DATA_LEN as length.
Richard M. Stallman <rms@gnu.org>
parents: 7528
diff changeset
66
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
67 extern char *strtok();
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
68
11674
754722efad75 (xmalloc, xrealloc): Declare them long *.
Richard M. Stallman <rms@gnu.org>
parents: 11423
diff changeset
69 long *xmalloc (), *xrealloc ();
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
70 char *concat ();
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
71 long readline ();
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
72 void fatal ();
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
74 /*
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
75 * xnew -- allocate storage. SYNOPSIS: Type *xnew (int n, Type);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
76 */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
77 #define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type)))
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
78
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
79
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
80
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
81 char *progname;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
82
20328
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
83 struct option longopts[] =
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
84 {
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
85 { "help", no_argument, NULL, 'h' },
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
86 { "version", no_argument, NULL, 'V' },
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
87 { 0 }
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
88 };
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
89
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
90 extern int optind;
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
91
21386
49b24e54a5fa Include <stdlib.h> if available.
Andreas Schwab <schwab@suse.de>
parents: 21354
diff changeset
92 int
2101
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
93 main (argc, argv)
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
94 int argc;
df8249aa4901 * b2m.c (main): Don't exit upon reading a blank line.
Jim Blandy <jimb@redhat.com>
parents: 998
diff changeset
95 char **argv;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 {
103774
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
97 logical labels_saved, printing, header, first, last_was_blank_line;
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
98 time_t ltoday;
69697
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
99 struct tm *tm;
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
100 char *labels, *p, *today;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
101 struct linebuffer data;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
102
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
103 #ifdef MSDOS
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
104 _fmode = O_BINARY; /* all of files are treated as binary files */
14968
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
105 #if __DJGPP__ > 1
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
106 if (!isatty (fileno (stdout)))
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
107 setmode (fileno (stdout), O_BINARY);
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
108 if (!isatty (fileno (stdin)))
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
109 setmode (fileno (stdin), O_BINARY);
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
110 #else /* not __DJGPP__ > 1 */
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
111 (stdout)->_flag &= ~_IOTEXT;
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
112 (stdin)->_flag &= ~_IOTEXT;
14968
1351c75bc3d6 (main) [MSDOS]: Handle DJGPP version 2.
Richard M. Stallman <rms@gnu.org>
parents: 14850
diff changeset
113 #endif /* not __DJGPP__ > 1 */
5448
18de002e47dd (main) [MSDOS]: Open all files as binary.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
114 #endif
14850
13d38dfedb51 (main): Initialize progname variable before using it.
Richard M. Stallman <rms@gnu.org>
parents: 11674
diff changeset
115 progname = argv[0];
13d38dfedb51 (main): Initialize progname variable before using it.
Richard M. Stallman <rms@gnu.org>
parents: 11674
diff changeset
116
20328
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
117 while (1)
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
118 {
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
119 int opt = getopt_long (argc, argv, "hV", longopts, 0);
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
120 if (opt == EOF)
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
121 break;
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
122
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
123 switch (opt)
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
124 {
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
125 case 'V':
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
126 printf ("%s (GNU Emacs %s)\n", "b2m", VERSION);
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
127 puts ("b2m is in the public domain.");
55408
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
128 exit (EXIT_SUCCESS);
20328
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
129
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
130 case 'h':
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
131 fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", progname);
55408
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
132 exit (EXIT_SUCCESS);
20328
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
133 }
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
134 }
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
135
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
136 if (optind != argc)
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
137 {
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
138 fprintf (stderr, "Usage: %s <babylmailbox >unixmailbox\n", progname);
55408
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
139 exit (EXIT_SUCCESS);
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
140 }
20328
000f4d300712 Include getopt.h.
Karl Heuer <kwzh@gnu.org>
parents: 18238
diff changeset
141
103774
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
142 labels_saved = printing = header = last_was_blank_line = FALSE;
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
143 first = TRUE;
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
144 ltoday = time (0);
69697
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
145 /* Convert to a string, checking for out-of-range time stamps.
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
146 Don't use 'ctime', as that might dump core if the hardware clock
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
147 is set to a bizarre value. */
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
148 tm = localtime (&ltoday);
69790
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
149 if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year)
1e68e7f3b824 * lib-src/b2m.c (main): Don't include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 69697
diff changeset
150 && (today = asctime (tm))))
69697
e112ec9aa49b * b2m.c: Include <limits.h>.
Paul Eggert <eggert@twinsun.com>
parents: 55408
diff changeset
151 fatal ("current time is out of range");
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
152 data.size = 200;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
153 data.buffer = xnew (200, char);
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
155 if (readline (&data, stdin) == 0
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
156 || !strneq (data.buffer, "BABYL OPTIONS:", 14))
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
157 fatal ("standard input is not a Babyl mailfile.");
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
158
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
159 while (readline (&data, stdin) > 0)
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
160 {
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
161 if (streq (data.buffer, "*** EOOH ***") && !printing)
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
162 {
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
163 printing = header = TRUE;
14850
13d38dfedb51 (main): Initialize progname variable before using it.
Richard M. Stallman <rms@gnu.org>
parents: 11674
diff changeset
164 printf ("From \"Babyl to mail by %s\" %s", progname, today);
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
165 continue;
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
166 }
6173
cbf3383981cb (main): Change delimiter from "^L" to "^_^L".
Karl Heuer <kwzh@gnu.org>
parents: 5448
diff changeset
167
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
168 if (data.buffer[0] == '\037')
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
169 {
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
170 if (data.buffer[1] == '\0')
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
171 continue;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
172 else if (data.buffer[1] == '\f')
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
173 {
103774
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
174 if (first)
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
175 first = FALSE;
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
176 else if (! last_was_blank_line)
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
177 puts("");
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
178 /* Save labels. */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
179 readline (&data, stdin);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
180 p = strtok (data.buffer, " ,\r\n\t");
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
181 labels = "X-Babyl-Labels: ";
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
42471
4234f54994ef (main): Parenthesize assignment when used as truth value to prevent gcc
Pavel Janík <Pavel@Janik.cz>
parents: 42260
diff changeset
183 while ((p = strtok (NULL, " ,\r\n\t")))
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
184 labels = concat (labels, p, ", ");
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
185
11423
a096f82d87d9 (main): Check for trailing ", " before trying to delete it.
Karl Heuer <kwzh@gnu.org>
parents: 10370
diff changeset
186 p = &labels[strlen (labels) - 2];
a096f82d87d9 (main): Check for trailing ", " before trying to delete it.
Karl Heuer <kwzh@gnu.org>
parents: 10370
diff changeset
187 if (*p == ',')
a096f82d87d9 (main): Check for trailing ", " before trying to delete it.
Karl Heuer <kwzh@gnu.org>
parents: 10370
diff changeset
188 *p = '\0';
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
189 printing = header = FALSE;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
190 labels_saved = TRUE;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
191 continue;
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
192 }
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
193 }
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
195 if ((data.buffer[0] == '\0') && header)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
196 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
197 header = FALSE;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
198 if (labels_saved)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
199 puts (labels);
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
200 }
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
202 if (printing)
103774
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
203 {
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
204 puts (data.buffer);
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
205 if (data.buffer[0] == '\0')
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
206 last_was_blank_line = TRUE;
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
207 else
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
208 last_was_blank_line = FALSE;
5048b64c7cf0 * b2m.c (main): Ensure that each message ends in two newlines.
Chong Yidong <cyd@stupidchicken.com>
parents: 69790
diff changeset
209 }
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
210 }
37163
e563147d81e5 (main): Always return a value.
Gerd Moellmann <gerd@gnu.org>
parents: 26083
diff changeset
211
55408
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
212 return EXIT_SUCCESS;
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
213 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
214
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
215
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
216
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
217 /*
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
218 * Return a newly-allocated string whose contents
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
219 * concatenate those of s1, s2, s3.
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
220 */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
221 char *
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
222 concat (s1, s2, s3)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
223 char *s1, *s2, *s3;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
224 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
225 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
226 char *result = xnew (len1 + len2 + len3 + 1, char);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
227
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
228 strcpy (result, s1);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
229 strcpy (result + len1, s2);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
230 strcpy (result + len1 + len2, s3);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
231 result[len1 + len2 + len3] = '\0';
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
232
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
233 return result;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
234 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
235
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
236 /*
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
237 * Read a line of text from `stream' into `linebuffer'.
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
238 * Return the number of characters read from `stream',
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
239 * which is the length of the line including the newline, if any.
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
240 */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
241 long
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
242 readline (linebuffer, stream)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
243 struct linebuffer *linebuffer;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
244 register FILE *stream;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
245 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
246 char *buffer = linebuffer->buffer;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
247 register char *p = linebuffer->buffer;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
248 register char *pend;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
249 int chars_deleted;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
250
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
251 pend = p + linebuffer->size; /* Separate to avoid 386/IX compiler bug. */
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
252
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
253 while (1)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
254 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
255 register int c = getc (stream);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
256 if (p == pend)
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
257 {
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
258 linebuffer->size *= 2;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
259 buffer = (char *) xrealloc (buffer, linebuffer->size);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
260 p += buffer - linebuffer->buffer;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
261 pend = buffer + linebuffer->size;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
262 linebuffer->buffer = buffer;
6215
226d490216f7 Clean up indentation and whitespace.
Richard M. Stallman <rms@gnu.org>
parents: 6214
diff changeset
263 }
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
264 if (c == EOF)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
265 {
18238
1f3d8941aba2 (readline): Terminate buffer properly when EOF seen.
Karl Heuer <kwzh@gnu.org>
parents: 14968
diff changeset
266 *p = '\0';
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
267 chars_deleted = 0;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
268 break;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
269 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
270 if (c == '\n')
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
271 {
18238
1f3d8941aba2 (readline): Terminate buffer properly when EOF seen.
Karl Heuer <kwzh@gnu.org>
parents: 14968
diff changeset
272 if (p > buffer && p[-1] == '\r')
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
273 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
274 *--p = '\0';
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
275 chars_deleted = 2;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
276 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
277 else
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
278 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
279 *p = '\0';
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
280 chars_deleted = 1;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
281 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
282 break;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
283 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
284 *p++ = c;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 }
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
286
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
287 return (p - buffer + chars_deleted);
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
288 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
289
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
290 /*
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
291 * Like malloc but get fatal error if memory is exhausted.
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
292 */
11674
754722efad75 (xmalloc, xrealloc): Declare them long *.
Richard M. Stallman <rms@gnu.org>
parents: 11423
diff changeset
293 long *
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
294 xmalloc (size)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
295 unsigned int size;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
296 {
11674
754722efad75 (xmalloc, xrealloc): Declare them long *.
Richard M. Stallman <rms@gnu.org>
parents: 11423
diff changeset
297 long *result = (long *) malloc (size);
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
298 if (result == NULL)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
299 fatal ("virtual memory exhausted");
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
300 return result;
440
c1abcb55a546 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 }
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
302
11674
754722efad75 (xmalloc, xrealloc): Declare them long *.
Richard M. Stallman <rms@gnu.org>
parents: 11423
diff changeset
303 long *
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
304 xrealloc (ptr, size)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
305 char *ptr;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
306 unsigned int size;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
307 {
11674
754722efad75 (xmalloc, xrealloc): Declare them long *.
Richard M. Stallman <rms@gnu.org>
parents: 11423
diff changeset
308 long *result = (long *) realloc (ptr, size);
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
309 if (result == NULL)
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
310 fatal ("virtual memory exhausted");
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
311 return result;
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
312 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
313
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
314 void
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
315 fatal (message)
21354
f998f239f77b (fatal): Declare the arg.
Richard M. Stallman <rms@gnu.org>
parents: 20328
diff changeset
316 char *message;
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
317 {
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
318 fprintf (stderr, "%s: %s\n", progname, message);
55408
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
319 exit (EXIT_FAILURE);
10370
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
320 }
4b1c8dc724e6 (concat, xmalloc, xrealloc, readline, xnew): Four new
Richard M. Stallman <rms@gnu.org>
parents: 9491
diff changeset
321
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 42471
diff changeset
322 /* arch-tag: 5a3ad2af-a802-408f-83cc-e7cf5e98653e
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 42471
diff changeset
323 (do not change this comment) */
55408
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
324
1c425ce93ce9 (GOOD, BAD): Delete macros. Throughout,
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
325 /* b2m.c ends here */