Mercurial > emacs
annotate lib-src/b2m.pl @ 51208:86d74f5ea803
(struct window): Rename members left to left_col,
top to top_line, height to total_lines, width to total_cols,
left_margin_width to left_margin_cols, right_margin_width to
right_margin_cols, orig_height to orig_total_lines, orig_top to
orig_top_line. All uses changed.
(struct window): New members left_fringe_width, right_fringe_width,
fringes_outside_margins, scroll_bar_width, vertical_scroll_bar_type.
(WINDOW_XFRAME, WINDOW_FRAME_COLUMN_WIDTH, WINDOW_FRAME_LINE_HEIGHT):
New macros primarily used to simplify other macros.
(WINDOW_TOTAL_COLS): New macro. Change relevant code that
referred to XINT (w->width).
(WINDOW_TOTAL_LINES): New macro. Change relevant code that
referred to XINT (w->height).
(WINDOW_TOTAL_WIDTH): New macro. Change relevant code that
referred to XINT (w->width) * canon_x_unit.
(WINDOW_TOTAL_HEIGHT): New macro. Change relevant code that
referred to XINT (w->height) * canon_y_unit.
(WINDOW_LEFT_EDGE_COL): New macro. Change relevant code that
referred to XINT (w->left).
(WINDOW_RIGHT_EDGE_COL): Renamed from WINDOW_RIGHT_EDGE. Change
all uses and code that referred to XINT (w->left) + XINT (w->width).
(WINDOW_TOP_EDGE_LINE): New macro. Change relevant code that
referred to XINT (w->top).
(WINDOW_BOTTOM_EDGE_LINE): New macro. Change relevant code that
referred to XINT (w->top) + XINT (w->height).
(WINDOW_LEFT_EDGE_X): New macro. Change relevant code that
referred to XINT (w->left) * canon_x_unit.
(WINDOW_RIGHT_EDGE_X): New macro. Change relevant code that
referred to (XINT (w->left) + XINT (w->width)) * canon_x_unit.
(WINDOW_TOP_EDGE_Y): New macro. Change relevant code that
referred to XINT (w->top) * canon_y_unit.
(WINDOW_BOTTOM_EDGE_Y): New macro. Change relevant code that
referred to (XINT (w->top) + XINT (w->height)) * canon_y_unit.
(WINDOW_LEFTMOST_P): New macro.
(WINDOW_BOX_LEFT_EDGE_COL): Renamed from WINDOW_LEFT_MARGIN.
All uses changed.
(WINDOW_BOX_RIGHT_EDGE_COL): Renamed from WINDOW_RIGHT_MARGIN.
All uses changed.
(WINDOW_BOX_LEFT_EDGE_X): Renamed from
WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X, moved from dispextern.h.
Do not exclude left fringe width.
(WINDOW_BOX_RIGHT_EDGE_X): Renamed from
WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X, moved from dispextern.h.
Do not exclude fringe widths.
(WINDOW_LEFT_FRINGE_WIDTH, WINDOW_RIGHT_FRINGE_WIDTH)
(WINDOW_FRINGE_COLS, WINDOW_TOTAL_FRINGE_WIDTH): New macros.
Change relevant code that referred to FRAME_LEFT_FRINGE_WIDTH,
FRAME_RIGHT_FRINGE_WIDTH, FRAME_FRINGE_COLS, and
FRAME_TOTAL_FRINGE_WIDTH to allow per-window fringe settings.
(WINDOW_HAS_FRINGES_OUTSIDE_MARGINS): New macro.
(WINDOW_VERTICAL_SCROLL_BAR_TYPE, WINDOW_HAS_VERTICAL_SCROLL_BAR)
(WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT)
(WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT)
(WINDOW_CONFIG_SCROLL_BAR_WIDTH, WINDOW_CONFIG_SCROLL_BAR_COLS):
New macros. Change code which referenced corresponding
FRAME_VERTICAL_SCROLL_BAR_TYPE, FRAME_HAS_VERTICAL_SCROLL_BARS,
FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT,
FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT,
FRAME_SCROLL_BAR_PIXEL_WIDTH, and FRAME_SCROLL_BAR_COLS macros to
allow per-window scroll-bar settings.
(WINDOW_LEFT_SCROLL_BAR_COLS, WINDOW_RIGHT_SCROLL_BAR_COLS): New macros.
(WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH): New macro. Change code that
referred to FRAME_LEFT_SCROLL_BAR_WIDTH.
(WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH): New macro. Change code
that referred to FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT and
FRAME_SCROLL_BAR_WIDTH.
(WINDOW_SCROLL_BAR_COLS, WINDOW_SCROLL_BAR_AREA_WIDTH)
(WINDOW_SCROLL_BAR_AREA_X): New macros.
(WINDOW_HEADER_LINE_HEIGHT): Renamed from
WINDOW_DISPLAY_HEADER_LINE_HEIGHT, moved from dispextern.h.
(WINDOW_BOX_HEIGHT_NO_MODE_LINE): Renamed from
WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE, moved from dispextern.h.
(WINDOW_BOX_TEXT_HEIGHT): Renamed from
WINDOW_DISPLAY_PIXEL_WIDTH, moved from dispextern.h.
(WINDOW_TO_FRAME_PIXEL_X, WINDOW_TO_FRAME_PIXEL_Y)
(FRAME_TO_WINDOW_PIXEL_X, FRAME_TO_WINDOW_PIXEL_Y)
(WINDOW_TEXT_TO_FRAME_PIXEL_X): Moved here from dispextern.h.
(WINDOW_LEFT_MARGIN_WIDTH): Renamed from
WINDOW_DISPLAY_LEFT_AREA_PIXEL_WIDTH, moved from dispextern.h.
(WINDOW_RIGHT_MARGIN_WIDTH): Renamed from
WINDOW_DISPLAY_RIGHT_AREA_PIXEL_WIDTH, moved from dispextern.h.
(window_from_coordinates): Update prototype.
(Fset_window_buffer): Update EXFUN.
(set_window_buffer): Update prototype.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Sat, 24 May 2003 22:08:20 +0000 |
parents | 23a1cea22d13 |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
46032 | 1 #!/usr/bin/perl |
2 | |
3 # b2m.pl - Script to convert a Babyl file to an mbox file | |
4 | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 | |
10 # This program is distributed in the hope that it will be useful, but | |
11 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 # General Public License for more details. | |
14 | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
18 # USA. | |
19 | |
20 # Maintained by Jonathan Kamens <jik@kamens.brookline.ma.us>. | |
21 | |
22 # Requires CPAN modules: MailTools (for Mail::Address), TimeDate (for | |
23 # Date::Parse). | |
24 | |
25 use warnings; | |
26 use strict; | |
27 use File::Basename; | |
28 use Getopt::Long; | |
29 use Mail::Address; | |
30 use Date::Parse; | |
31 | |
32 my($whoami) = basename $0; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48810
diff
changeset
|
33 my($version) = '$Revision: 1.4 $'; |
46032 | 34 my($usage) = "Usage: $whoami [--help] [--version] [--[no]full-headers] [Babyl-file] |
35 \tBy default, full headers are printed.\n"; | |
36 | |
37 my($opt_help, $opt_version); | |
38 my($opt_full_headers) = 1; | |
39 | |
40 die $usage if (! GetOptions( | |
41 'help' => \$opt_help, | |
42 'version' => \$opt_version, | |
43 'full-headers!' => \$opt_full_headers, | |
44 )); | |
45 | |
46 if ($opt_help) { | |
47 print $usage; | |
48 exit; | |
49 } | |
50 elsif ($opt_version) { | |
51 print "$whoami version: $version\n"; | |
52 exit; | |
53 } | |
54 | |
55 die $usage if (@ARGV > 1); | |
56 | |
57 $/ = "\n\037"; | |
58 | |
59 if (<> !~ /^BABYL OPTIONS:/) { | |
60 die "$whoami: $ARGV is not a Babyl file\n$usage"; | |
61 } | |
62 | |
63 while (<>) { | |
64 my($msg_num) = $. - 1; | |
46184
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
65 my($labels, $pruned, $full_header, $header); |
46032 | 66 my($from_line, $from_addr); |
67 my($time); | |
68 | |
69 # This will strip the initial form feed, any whitespace that may | |
70 # be following it, and then a newline | |
71 s/^\s+//; | |
72 # This will strip the ^_ off of the end of the message | |
73 s/\037$//; | |
74 | |
75 if (! s/(.*)\n//) { | |
76 malformatted: | |
77 warn "$whoami: message $msg_num in $ARGV is malformatted\n"; | |
78 next; | |
79 } | |
80 $labels = $1; | |
81 | |
46184
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
82 # Strip the integer indicating whether the header is pruned |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48810
diff
changeset
|
83 $labels =~ s/^(\d+)[,\s]*//; |
46184
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
84 $pruned = $1; |
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
85 |
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
86 s/(?:((?:.+\n)+)\n*)?\*\*\* EOOH \*\*\*\n+// || goto malformatted; |
46032 | 87 $full_header = $1; |
88 | |
89 if (s/((?:.+\n)+)\n+//) { | |
90 $header = $1; | |
91 } | |
92 else { | |
93 # Message has no body | |
94 $header = $_; | |
95 $_ = ''; | |
96 } | |
97 | |
46184
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
98 # "$pruned eq '0'" is different from "! $pruned". We want to make |
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
99 # sure that we found a valid label line which explicitly indicated |
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
100 # that the header was not pruned. |
81235cad75cb
Obey the rmail file and use the unpruned header properly.
Pavel Janík <Pavel@Janik.cz>
parents:
46032
diff
changeset
|
101 if ((! $full_header) || ($pruned eq '0')) { |
46032 | 102 $full_header = $header; |
103 } | |
104 | |
48810
1626973bdb2b
Make sure every message ends with a blank line, because some mbox parsers
Pavel Janík <Pavel@Janik.cz>
parents:
46737
diff
changeset
|
105 # End message with two newlines (some mbox parsers require a blank |
1626973bdb2b
Make sure every message ends with a blank line, because some mbox parsers
Pavel Janík <Pavel@Janik.cz>
parents:
46737
diff
changeset
|
106 # line before the next "From " line). |
1626973bdb2b
Make sure every message ends with a blank line, because some mbox parsers
Pavel Janík <Pavel@Janik.cz>
parents:
46737
diff
changeset
|
107 s/\s+$/\n\n/; |
46032 | 108 |
109 # Quote "^From " | |
110 s/(^|\n)From /$1>From /g; | |
111 | |
112 # Strip extra commas and whitespace from the end | |
113 $labels =~ s/[,\s]+$//; | |
114 # Now collapse extra commas and whitespace in the remaining label string | |
115 $labels =~ s/[,\s]+/, /g; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48810
diff
changeset
|
116 |
46032 | 117 foreach my $rmail_header qw(summary-line x-coding-system) { |
118 $full_header =~ s/(^|\n)$rmail_header:.*\n/$1/i; | |
119 } | |
120 | |
121 if ($full_header =~ s/(^|\n)mail-from:\s*(From .*)\n/$1/i) { | |
122 ($from_line = $2) =~ s/\s*$/\n/; | |
123 } | |
124 else { | |
125 foreach my $addr_header qw(return-path from really-from sender) { | |
46737
7c794ace9e1a
Fix regexp for finding return address fields.
Pavel Janík <Pavel@Janik.cz>
parents:
46184
diff
changeset
|
126 if ($full_header =~ /(?:^|\n)$addr_header:\s*(.*\n(?:\B.*\n)*)/i) { |
46032 | 127 my($addr) = Mail::Address->parse($1); |
128 $from_addr = $addr->address($addr); | |
129 last; | |
130 } | |
131 } | |
132 | |
133 if (! $from_addr) { | |
134 $from_addr = "Babyl_to_mail_by_$whoami\@localhost"; | |
135 } | |
136 | |
137 if ($full_header =~ /(?:^|\n)date:\s*(\S.*\S)/i) { | |
138 $time = str2time($1); | |
139 } | |
140 | |
141 if (! $time) { | |
142 # No Date header or we failed to parse it | |
143 $time = time; | |
144 } | |
145 | |
146 $from_line = "From " . $from_addr . " " . localtime($time) . "\n"; | |
147 } | |
148 | |
149 print($from_line, ($opt_full_headers ? $full_header : $header), | |
150 ($labels ? "X-Babyl-Labels: $labels\n" : ""), "\n", | |
151 $_) || die "$whoami: error writing to stdout: $!\n"; | |
152 } | |
153 | |
154 close(STDOUT) || die "$whoami: Error closing stdout: $!\n"; |