annotate src/README.integral-types @ 844:047d37eb70d7

[xemacs-hg @ 2002-05-16 13:30:23 by ben] ui fixes for things that were bothering me bytecode.c, editfns.c, lisp.h, lread.c: Fix save-restriction to use markers rather than pseudo-markers (integers representing the amount of text on either side of the region). That way, all inserts are handled correctly, not just those inside old restriction. Add buffer argument to save_restriction_save(). process.c: Clean up very dirty and kludgy code that outputs into a buffer -- use proper unwind protects, etc. font-lock.c: Do save-restriction/widen around the function -- otherwise, incorrect results will ensue when a buffer has been narrowed before a call to e.g. `buffer-syntactic-context' -- something that happens quite often. fileio.c: Look for a handler for make-temp-name. window.c, winslots.h: Try to solve this annoying problem: have two frames displaying the buffer, in different places; in one, temporarily switch away to another buffer and then back -- and you've lost your position; it's reset to the other one in the other frame. My current solution involves window-level caches of buffers and points (also a cache for window-start); when set-window-buffer is called, it looks to see if the buffer was previously visited in the window, and if so, uses the most recent point at that time. (It's a marker, so it handles changes.) #### Note: It could be argued that doing it on the frame level would be better -- e.g. if you visit a buffer temporarily through a grep, and then go back to that buffer, you presumably want the grep's position rather than some previous position provided everything was in the same frame, even though the grep was in another window in the frame. However, doing it on the frame level fails when you have two windows on the same frame. Perhaps we keep both a window and a frame cache, and use the frame cache if there are no other windows on the frame showing the buffer, else the window's cache? This is probably something to be configurable using a specifier. Suggestions please please please? window.c: Clean up a bit code that deals with the annoyance of window-point vs. point. dialog.el: Function to ask a multiple-choice question, automatically choosing a dialog box or minibuffer representation as necessary. Generalized version of yes-or-no-p, y-or-n-p. files.el: Use get-user-response to ask "yes/no/diff" question when recovering. "diff" means that a diff is displayed between the current file and the autosave. (Converts/deconverts escape-quoted as necessary. No more complaints from you, Mr. Turnbull!) One known problem: when a dialog is used, it's modal, so you can't scroll the diff. Will fix soon. lisp-mode.el: If we're filling a string, don't treat semicolon as a comment, which would give very unfriendly results. Uses `buffer-syntactic-context'. simple.el: all changes back to the beginning. (Useful if you've saved the file in the middle of the changes.) simple.el: Add option kill-word-into-kill-ring, which controls whether words deleted with kill-word, backward-kill-word, etc. are "cut" into the kill ring, or "cleared" into nothingness. (My preference is the latter, by far. I'd almost go so far as suggesting we make it the default, as you can always select a word and then cut it if you want it cut.) menubar-items.el: Add option corresponding to kill-word-into-kill-ring.
author ben
date Thu, 16 May 2002 13:30:58 +0000
parents 8bd30fae1bce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
734
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
1 README.integral-types
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
2
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
3 The great integral types renaming.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
4
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
5 #### The content of this file was originally posted as a ChangeLog and
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
6 should be moved to the Internals manual.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
7
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
8 The purpose of this is to rationalize the names used for various
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
9 integral types, so that they match their intended uses and follow
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
10 consist conventions, and eliminate types that were not semantically
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
11 different from each other.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
12
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
13 The conventions are:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
14
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
15 -- All integral types that measure quantities of anything are
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
16 signed. Some people disagree vociferously with this, but their
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
17 arguments are mostly theoretical, and are vastly outweighed by
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
18 the practical headaches of mixing signed and unsigned values,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
19 and more importantly by the far increased likelihood of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
20 inadvertent bugs: Because of the broken "viral" nature of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
21 unsigned quantities in C (operations involving mixed
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
22 signed/unsigned are done unsigned, when exactly the opposite is
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
23 nearly always wanted), even a single error in declaring a
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
24 quantity unsigned that should be signed, or even the even more
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
25 subtle error of comparing signed and unsigned values and
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
26 forgetting the necessary cast, can be catastrophic, as
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
27 comparisons will yield wrong results. -Wsign-compare is turned
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
28 on specifically to catch this, but this tends to result in a
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
29 great number of warnings when mixing signed and unsigned, and
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
30 the casts are annoying. More has been written on this
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
31 elsewhere.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
32
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
33 -- All such quantity types just mentioned boil down to EMACS_INT,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
34 which is 32 bits on 32-bit machines and 64 bits on 64-bit
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
35 machines. This is guaranteed to be the same size as Lisp
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
36 objects of type `int', and (as far as I can tell) of size_t
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
37 (unsigned!) and ssize_t. The only type below that is not an
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
38 EMACS_INT is Hashcode, which is an unsigned value of the same
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
39 size as EMACS_INT.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
40
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
41 -- Type names should be relatively short (no more than 10
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
42 characters or so), with the first letter capitalized and no
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
43 underscores if they can at all be avoided.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
44
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
45 -- "count" == a zero-based measurement of some quantity. Includes
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
46 sizes, offsets, and indexes.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
47
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
48 -- "bpos" == a one-based measurement of a position in a buffer.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
49 "Charbpos" and "Bytebpos" count text in the buffer, rather than
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
50 bytes in memory; thus Bytebpos does not directly correspond to
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
51 the memory representation. Use "Membpos" for this.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
52
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
53 -- "Char" refers to internal-format characters, not to the C type
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
54 "char", which is really a byte.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
55
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
56 -- For the actual name changes, see the script below.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
57
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
58 I ran the following script to do the conversion. (NOTE: This script
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
59 is idempotent. You can safely run it multiple times and it will
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
60 not screw up previous results -- in fact, it will do nothing if
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
61 nothing has changed. Thus, it can be run repeatedly as necessary
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
62 to handle patches coming in from old workspaces, or old branches.)
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
63 There are two tags, just before and just after the change:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
64 `pre-integral-type-rename' and `post-integral-type-rename'. When
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
65 merging code from the main trunk into a branch, the best thing to
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
66 do is first merge up to `pre-integral-type-rename', then apply the
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
67 script and associated changes, then merge from
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
68 `post-integral-type-change' to the present. (Alternatively, just do
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
69 the merging in one operation; but you may then have a lot of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
70 conflicts needing to be resolved by hand.)
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
71
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
72 Script `fixtypes.sh' follows:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
73
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
74
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
75 ----------------------------------- cut ------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
76 files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]"
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
77 gr Memory_Count Bytecount $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
78 gr Lstream_Data_Count Bytecount $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
79 gr Element_Count Elemcount $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
80 gr Hash_Code Hashcode $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
81 gr extcount bytecount $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
82 gr bufpos charbpos $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
83 gr bytind bytebpos $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
84 gr memind membpos $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
85 gr bufbyte intbyte $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
86 gr Extcount Bytecount $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
87 gr Bufpos Charbpos $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
88 gr Bytind Bytebpos $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
89 gr Memind Membpos $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
90 gr Bufbyte Intbyte $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
91 gr EXTCOUNT BYTECOUNT $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
92 gr BUFPOS CHARBPOS $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
93 gr BYTIND BYTEBPOS $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
94 gr MEMIND MEMBPOS $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
95 gr BUFBYTE INTBYTE $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
96 gr MEMORY_COUNT BYTECOUNT $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
97 gr LSTREAM_DATA_COUNT BYTECOUNT $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
98 gr ELEMENT_COUNT ELEMCOUNT $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
99 gr HASH_CODE HASHCODE $files
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
100 ----------------------------------- cut ------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
101
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
102
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
103 `fixtypes.sh' is a Bourne-shell script; it uses 'gr':
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
104
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
105
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
106 ----------------------------------- cut ------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
107 #!/bin/sh
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
108
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
109 # Usage is like this:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
110
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
111 # gr FROM TO FILES ...
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
112
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
113 # globally replace FROM with TO in FILES. FROM and TO are regular expressions.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
114 # backup files are stored in the `backup' directory.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
115 from="$1"
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
116 to="$2"
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
117 shift 2
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
118 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g"
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
119 ----------------------------------- cut ------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
120
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
121
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
122 `gr' in turn uses a Perl script to do its real work,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
123 `global-replace', which follows:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
124
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
125
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
126 ----------------------------------- cut ------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
127 : #-*- Perl -*-
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
128
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
129 ### global-modify --- modify the contents of a file by a Perl expression
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
130
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
131 ## Copyright (C) 1999 Martin Buchholz.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
132 ## Copyright (C) 2001 Ben Wing.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
133
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
134 ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org>
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
135 ## Maintainer: Ben Wing <ben@xemacs.org>
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
136 ## Current Version: 1.0, May 5, 2001
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
137
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
138 # This program is free software; you can redistribute it and/or modify
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
139 # it under the terms of the GNU General Public License as published by
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
140 # the Free Software Foundation; either version 2, or (at your option)
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
141 # any later version.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
142 #
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
143 # This program is distributed in the hope that it will be useful, but
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
144 # WITHOUT ANY WARRANTY; without even the implied warranty of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
145 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
146 # General Public License for more details.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
147 #
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
148 # You should have received a copy of the GNU General Public License
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
149 # along with XEmacs; see the file COPYING. If not, write to the Free
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
150 # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
151 # 02111-1307, USA.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
152
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
153 eval 'exec perl -w -S $0 ${1+"$@"}'
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
154 if 0;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
155
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
156 use strict;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
157 use FileHandle;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
158 use Carp;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
159 use Getopt::Long;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
160 use File::Basename;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
161
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
162 (my $myName = $0) =~ s@.*/@@; my $usage="
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
163 Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode]
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
164 PERLEXPR FILE ...
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
165
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
166 Globally modify a file, either line by line or in one big hunk.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
167
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
168 Typical usage is like this:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
169
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
170 [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
171 in file names]
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
172
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
173 find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
174
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
175 [with non-GNU print, xargs]
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
176
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
177 find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
178
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
179
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
180 The file is read in, either line by line (with --line-mode specified)
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
181 or in one big hunk (with --hunk-mode specified; it's the default), and
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
182 the Perl expression is then evalled with \$_ set to the line or hunk of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
183 text, including the terminating newline if there is one. It should
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
184 destructively modify the value there, storing the changed result in \$_.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
185
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
186 Files in which any modifications are made are backed up to the directory
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
187 specified using --backup-dir, or to `backup' by default. To disable this,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
188 use --backup-dir= with no argument.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
189
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
190 Hunk mode is the default because it is MUCH MUCH faster than line-by-line.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
191 Use line-by-line only when it matters, e.g. you want to do a replacement
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
192 only once per line (the default without the `g' argument). Conversely,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
193 when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
194 replacement in the entire file!
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
195 ";
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
196
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
197 my %options = ();
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
198 $Getopt::Long::ignorecase = 0;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
199 &GetOptions (
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
200 \%options,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
201 'help', 'backup-dir=s', 'line-mode', 'hunk-mode',
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
202 );
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
203
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
204
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
205 die $usage if $options{"help"} or @ARGV <= 1;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
206 my $code = shift;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
207
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
208 die $usage if grep (-d || ! -w, @ARGV);
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
209
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
210 sub SafeOpen {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
211 open ((my $fh = new FileHandle), $_[0]);
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
212 confess "Can't open $_[0]: $!" if ! defined $fh;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
213 return $fh;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
214 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
215
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
216 sub SafeClose {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
217 close $_[0] or confess "Can't close $_[0]: $!";
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
218 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
219
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
220 sub FileContents {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
221 my $fh = SafeOpen ("< $_[0]");
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
222 my $olddollarslash = $/;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
223 local $/ = undef;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
224 my $contents = <$fh>;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
225 $/ = $olddollarslash;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
226 return $contents;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
227 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
228
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
229 sub WriteStringToFile {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
230 my $fh = SafeOpen ("> $_[0]");
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
231 binmode $fh;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
232 print $fh $_[1] or confess "$_[0]: $!\n";
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
233 SafeClose $fh;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
234 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
235
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
236 foreach my $file (@ARGV) {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
237 my $changed_p = 0;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
238 my $new_contents = "";
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
239 if ($options{"line-mode"}) {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
240 my $fh = SafeOpen $file;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
241 while (<$fh>) {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
242 my $save_line = $_;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
243 eval $code;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
244 $changed_p = 1 if $save_line ne $_;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
245 $new_contents .= $_;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
246 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
247 } else {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
248 my $orig_contents = $_ = FileContents $file;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
249 eval $code;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
250 if ($_ ne $orig_contents) {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
251 $changed_p = 1;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
252 $new_contents = $_;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
253 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
254 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
255
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
256 if ($changed_p) {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
257 my $backdir = $options{"backup-dir"};
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
258 $backdir = "backup" if !defined ($backdir);
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
259 if ($backdir) {
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
260 my ($name, $path, $suffix) = fileparse ($file, "");
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
261 my $backfulldir = $path . $backdir;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
262 my $backfile = "$backfulldir/$name";
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
263 mkdir $backfulldir, 0755 unless -d $backfulldir;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
264 print "modifying $file (original saved in $backfile)\n";
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
265 rename $file, $backfile;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
266 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
267 WriteStringToFile ($file, $new_contents);
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
268 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
269 }
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
270 ----------------------------------- cut ------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
271
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
272
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
273 In addition to those programs, I needed to fix up a few other
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
274 things, particularly relating to the duplicate definitions of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
275 types, now that some types merged with others. Specifically:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
276
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
277 1. in lisp.h, removed duplicate declarations of Bytecount. The
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
278 changed code should now look like this: (In each code snippet
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
279 below, the first and last lines are the same as the original, as
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
280 are all lines outside of those lines. That allows you to locate
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
281 the section to be replaced, and replace the stuff in that
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
282 section, verifying that there isn't anything new added that
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
283 would need to be kept.)
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
284
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
285 --------------------------------- snip -------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
286 /* Counts of bytes or chars */
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
287 typedef EMACS_INT Bytecount;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
288 typedef EMACS_INT Charcount;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
289
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
290 /* Counts of elements */
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
291 typedef EMACS_INT Elemcount;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
292
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
293 /* Hash codes */
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
294 typedef unsigned long Hashcode;
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
295
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
296 /* ------------------------ dynamic arrays ------------------- */
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
297 --------------------------------- snip -------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
298
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
299 2. in lstream.h, removed duplicate declaration of Bytecount.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
300 Rewrote the comment about this type. The changed code should
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
301 now look like this:
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
302
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
303
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
304 --------------------------------- snip -------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
305 #endif
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
306
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
307 /* The have been some arguments over the what the type should be that
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
308 specifies a count of bytes in a data block to be written out or read in,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
309 using Lstream_read(), Lstream_write(), and related functions.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
310 Originally it was long, which worked fine; Martin "corrected" these to
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
311 size_t and ssize_t on the grounds that this is theoretically cleaner and
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
312 is in keeping with the C standards. Unfortunately, this practice is
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
313 horribly error-prone due to design flaws in the way that mixed
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
314 signed/unsigned arithmetic happens. In fact, by doing this change,
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
315 Martin introduced a subtle but fatal error that caused the operation of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
316 sending large mail messages to the SMTP server under Windows to fail.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
317 By putting all values back to be signed, avoiding any signed/unsigned
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
318 mixing, the bug immediately went away. The type then in use was
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
319 Lstream_Data_Count, so that it be reverted cleanly if a vote came to
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
320 that. Now it is Bytecount.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
321
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
322 Some earlier comments about why the type must be signed: This MUST BE
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
323 SIGNED, since it also is used in functions that return the number of
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
324 bytes actually read to or written from in an operation, and these
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
325 functions can return -1 to signal error.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
326
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
327 Note that the standard Unix read() and write() functions define the
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
328 count going in as a size_t, which is UNSIGNED, and the count going
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
329 out as an ssize_t, which is SIGNED. This is a horrible design
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
330 flaw. Not only is it highly likely to lead to logic errors when a
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
331 -1 gets interpreted as a large positive number, but operations are
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
332 bound to fail in all sorts of horrible ways when a number in the
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
333 upper-half of the size_t range is passed in -- this number is
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
334 unrepresentable as an ssize_t, so code that checks to see how many
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
335 bytes are actually written (which is mandatory if you are dealing
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
336 with certain types of devices) will get completely screwed up.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
337
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
338 --ben
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
339 */
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
340
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
341 typedef enum lstream_buffering
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
342 --------------------------------- snip -------------------------------------
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
343
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
344
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
345 3. in dumper.c, there are four places, all inside of switch()
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
346 statements, where XD_BYTECOUNT appears twice as a case tag. In
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
347 each case, the two case blocks contain identical code, and you
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
348 should *REMOVE THE SECOND* and leave the first.
8bd30fae1bce [xemacs-hg @ 2002-01-25 16:46:24 by stephent]
stephent
parents:
diff changeset
349