aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c223
1 files changed, 104 insertions, 119 deletions
diff --git a/src/editfns.c b/src/editfns.c
index d266ca9951d..8f7b2aee76c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -59,10 +59,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
59#include "window.h" 59#include "window.h"
60#include "blockinput.h" 60#include "blockinput.h"
61 61
62#ifndef NULL
63#define NULL 0
64#endif
65
66#ifndef USER_FULL_NAME 62#ifndef USER_FULL_NAME
67#define USER_FULL_NAME pw->pw_gecos 63#define USER_FULL_NAME pw->pw_gecos
68#endif 64#endif
@@ -81,7 +77,7 @@ static void time_overflow (void) NO_RETURN;
81static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object, 77static Lisp_Object format_time_string (char const *, ptrdiff_t, Lisp_Object,
82 int, time_t *, struct tm *); 78 int, time_t *, struct tm *);
83static int tm_diff (struct tm *, struct tm *); 79static int tm_diff (struct tm *, struct tm *);
84static void update_buffer_properties (EMACS_INT, EMACS_INT); 80static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
85 81
86static Lisp_Object Qbuffer_access_fontify_functions; 82static Lisp_Object Qbuffer_access_fontify_functions;
87static Lisp_Object Fuser_full_name (Lisp_Object); 83static Lisp_Object Fuser_full_name (Lisp_Object);
@@ -141,8 +137,14 @@ init_editfns (void)
141 /* If the user name claimed in the environment vars differs from 137 /* If the user name claimed in the environment vars differs from
142 the real uid, use the claimed name to find the full name. */ 138 the real uid, use the claimed name to find the full name. */
143 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name); 139 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
144 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid ()) 140 if (! NILP (tem))
145 : Vuser_login_name); 141 tem = Vuser_login_name;
142 else
143 {
144 uid_t euid = geteuid ();
145 tem = make_fixnum_or_float (euid);
146 }
147 Vuser_full_name = Fuser_full_name (tem);
146 148
147 p = getenv ("NAME"); 149 p = getenv ("NAME");
148 if (p) 150 if (p)
@@ -207,7 +209,7 @@ DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
207} 209}
208 210
209static Lisp_Object 211static Lisp_Object
210buildmark (EMACS_INT charpos, EMACS_INT bytepos) 212buildmark (ptrdiff_t charpos, ptrdiff_t bytepos)
211{ 213{
212 register Lisp_Object mark; 214 register Lisp_Object mark;
213 mark = Fmake_marker (); 215 mark = Fmake_marker ();
@@ -232,17 +234,6 @@ DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
232 return buildmark (PT, PT_BYTE); 234 return buildmark (PT, PT_BYTE);
233} 235}
234 236
235EMACS_INT
236clip_to_bounds (EMACS_INT lower, EMACS_INT num, EMACS_INT upper)
237{
238 if (num < lower)
239 return lower;
240 else if (num > upper)
241 return upper;
242 else
243 return num;
244}
245
246DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ", 237DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
247 doc: /* Set point to POSITION, a number or marker. 238 doc: /* Set point to POSITION, a number or marker.
248Beginning of buffer is position (point-min), end is (point-max). 239Beginning of buffer is position (point-min), end is (point-max).
@@ -250,7 +241,7 @@ Beginning of buffer is position (point-min), end is (point-max).
250The return value is POSITION. */) 241The return value is POSITION. */)
251 (register Lisp_Object position) 242 (register Lisp_Object position)
252{ 243{
253 EMACS_INT pos; 244 ptrdiff_t pos;
254 245
255 if (MARKERP (position) 246 if (MARKERP (position)
256 && current_buffer == XMARKER (position)->buffer) 247 && current_buffer == XMARKER (position)->buffer)
@@ -330,7 +321,7 @@ overlays_around (EMACS_INT pos, Lisp_Object *vec, ptrdiff_t len)
330{ 321{
331 Lisp_Object overlay, start, end; 322 Lisp_Object overlay, start, end;
332 struct Lisp_Overlay *tail; 323 struct Lisp_Overlay *tail;
333 EMACS_INT startpos, endpos; 324 ptrdiff_t startpos, endpos;
334 ptrdiff_t idx = 0; 325 ptrdiff_t idx = 0;
335 326
336 for (tail = current_buffer->overlays_before; tail; tail = tail->next) 327 for (tail = current_buffer->overlays_before; tail; tail = tail->next)
@@ -479,7 +470,7 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
479static void 470static void
480find_field (Lisp_Object pos, Lisp_Object merge_at_boundary, 471find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
481 Lisp_Object beg_limit, 472 Lisp_Object beg_limit,
482 EMACS_INT *beg, Lisp_Object end_limit, EMACS_INT *end) 473 ptrdiff_t *beg, Lisp_Object end_limit, ptrdiff_t *end)
483{ 474{
484 /* Fields right before and after the point. */ 475 /* Fields right before and after the point. */
485 Lisp_Object before_field, after_field; 476 Lisp_Object before_field, after_field;
@@ -595,7 +586,7 @@ A field is a region of text with the same `field' property.
595If POS is nil, the value of point is used for POS. */) 586If POS is nil, the value of point is used for POS. */)
596 (Lisp_Object pos) 587 (Lisp_Object pos)
597{ 588{
598 EMACS_INT beg, end; 589 ptrdiff_t beg, end;
599 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 590 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
600 if (beg != end) 591 if (beg != end)
601 del_range (beg, end); 592 del_range (beg, end);
@@ -608,7 +599,7 @@ A field is a region of text with the same `field' property.
608If POS is nil, the value of point is used for POS. */) 599If POS is nil, the value of point is used for POS. */)
609 (Lisp_Object pos) 600 (Lisp_Object pos)
610{ 601{
611 EMACS_INT beg, end; 602 ptrdiff_t beg, end;
612 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 603 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
613 return make_buffer_string (beg, end, 1); 604 return make_buffer_string (beg, end, 1);
614} 605}
@@ -619,7 +610,7 @@ A field is a region of text with the same `field' property.
619If POS is nil, the value of point is used for POS. */) 610If POS is nil, the value of point is used for POS. */)
620 (Lisp_Object pos) 611 (Lisp_Object pos)
621{ 612{
622 EMACS_INT beg, end; 613 ptrdiff_t beg, end;
623 find_field (pos, Qnil, Qnil, &beg, Qnil, &end); 614 find_field (pos, Qnil, Qnil, &beg, Qnil, &end);
624 return make_buffer_string (beg, end, 0); 615 return make_buffer_string (beg, end, 0);
625} 616}
@@ -634,7 +625,7 @@ If LIMIT is non-nil, it is a buffer position; if the beginning of the field
634is before LIMIT, then LIMIT will be returned instead. */) 625is before LIMIT, then LIMIT will be returned instead. */)
635 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit) 626 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit)
636{ 627{
637 EMACS_INT beg; 628 ptrdiff_t beg;
638 find_field (pos, escape_from_edge, limit, &beg, Qnil, 0); 629 find_field (pos, escape_from_edge, limit, &beg, Qnil, 0);
639 return make_number (beg); 630 return make_number (beg);
640} 631}
@@ -649,7 +640,7 @@ If LIMIT is non-nil, it is a buffer position; if the end of the field
649is after LIMIT, then LIMIT will be returned instead. */) 640is after LIMIT, then LIMIT will be returned instead. */)
650 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit) 641 (Lisp_Object pos, Lisp_Object escape_from_edge, Lisp_Object limit)
651{ 642{
652 EMACS_INT end; 643 ptrdiff_t end;
653 find_field (pos, escape_from_edge, Qnil, 0, limit, &end); 644 find_field (pos, escape_from_edge, Qnil, 0, limit, &end);
654 return make_number (end); 645 return make_number (end);
655} 646}
@@ -685,7 +676,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
685 (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge, Lisp_Object only_in_line, Lisp_Object inhibit_capture_property) 676 (Lisp_Object new_pos, Lisp_Object old_pos, Lisp_Object escape_from_edge, Lisp_Object only_in_line, Lisp_Object inhibit_capture_property)
686{ 677{
687 /* If non-zero, then the original point, before re-positioning. */ 678 /* If non-zero, then the original point, before re-positioning. */
688 EMACS_INT orig_point = 0; 679 ptrdiff_t orig_point = 0;
689 int fwd; 680 int fwd;
690 Lisp_Object prev_old, prev_new; 681 Lisp_Object prev_old, prev_new;
691 682
@@ -699,10 +690,10 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
699 CHECK_NUMBER_COERCE_MARKER (new_pos); 690 CHECK_NUMBER_COERCE_MARKER (new_pos);
700 CHECK_NUMBER_COERCE_MARKER (old_pos); 691 CHECK_NUMBER_COERCE_MARKER (old_pos);
701 692
702 fwd = (XFASTINT (new_pos) > XFASTINT (old_pos)); 693 fwd = (XINT (new_pos) > XINT (old_pos));
703 694
704 prev_old = make_number (XFASTINT (old_pos) - 1); 695 prev_old = make_number (XINT (old_pos) - 1);
705 prev_new = make_number (XFASTINT (new_pos) - 1); 696 prev_new = make_number (XINT (new_pos) - 1);
706 697
707 if (NILP (Vinhibit_field_text_motion) 698 if (NILP (Vinhibit_field_text_motion)
708 && !EQ (new_pos, old_pos) 699 && !EQ (new_pos, old_pos)
@@ -727,7 +718,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
727 /* It is possible that NEW_POS is not within the same field as 718 /* It is possible that NEW_POS is not within the same field as
728 OLD_POS; try to move NEW_POS so that it is. */ 719 OLD_POS; try to move NEW_POS so that it is. */
729 { 720 {
730 EMACS_INT shortage; 721 ptrdiff_t shortage;
731 Lisp_Object field_bound; 722 Lisp_Object field_bound;
732 723
733 if (fwd) 724 if (fwd)
@@ -782,8 +773,8 @@ boundaries bind `inhibit-field-text-motion' to t.
782This function does not move point. */) 773This function does not move point. */)
783 (Lisp_Object n) 774 (Lisp_Object n)
784{ 775{
785 EMACS_INT orig, orig_byte, end; 776 ptrdiff_t orig, orig_byte, end;
786 int count = SPECPDL_INDEX (); 777 ptrdiff_t count = SPECPDL_INDEX ();
787 specbind (Qinhibit_point_motion_hooks, Qt); 778 specbind (Qinhibit_point_motion_hooks, Qt);
788 779
789 if (NILP (n)) 780 if (NILP (n))
@@ -823,15 +814,17 @@ boundaries bind `inhibit-field-text-motion' to t.
823This function does not move point. */) 814This function does not move point. */)
824 (Lisp_Object n) 815 (Lisp_Object n)
825{ 816{
826 EMACS_INT end_pos; 817 ptrdiff_t clipped_n;
827 EMACS_INT orig = PT; 818 ptrdiff_t end_pos;
819 ptrdiff_t orig = PT;
828 820
829 if (NILP (n)) 821 if (NILP (n))
830 XSETFASTINT (n, 1); 822 XSETFASTINT (n, 1);
831 else 823 else
832 CHECK_NUMBER (n); 824 CHECK_NUMBER (n);
833 825
834 end_pos = find_before_next_newline (orig, 0, XINT (n) - (XINT (n) <= 0)); 826 clipped_n = clip_to_bounds (PTRDIFF_MIN + 1, XINT (n), PTRDIFF_MAX);
827 end_pos = find_before_next_newline (orig, 0, clipped_n - (clipped_n <= 0));
835 828
836 /* Return END_POS constrained to the current input field. */ 829 /* Return END_POS constrained to the current input field. */
837 return Fconstrain_to_field (make_number (end_pos), make_number (orig), 830 return Fconstrain_to_field (make_number (end_pos), make_number (orig),
@@ -958,7 +951,7 @@ usage: (save-excursion &rest BODY) */)
958 (Lisp_Object args) 951 (Lisp_Object args)
959{ 952{
960 register Lisp_Object val; 953 register Lisp_Object val;
961 int count = SPECPDL_INDEX (); 954 ptrdiff_t count = SPECPDL_INDEX ();
962 955
963 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 956 record_unwind_protect (save_excursion_restore, save_excursion_save ());
964 957
@@ -973,7 +966,7 @@ usage: (save-current-buffer &rest BODY) */)
973 (Lisp_Object args) 966 (Lisp_Object args)
974{ 967{
975 Lisp_Object val; 968 Lisp_Object val;
976 int count = SPECPDL_INDEX (); 969 ptrdiff_t count = SPECPDL_INDEX ();
977 970
978 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); 971 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
979 972
@@ -1099,7 +1092,7 @@ At the beginning of the buffer or accessible region, return 0. */)
1099 XSETFASTINT (temp, 0); 1092 XSETFASTINT (temp, 0);
1100 else if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 1093 else if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
1101 { 1094 {
1102 EMACS_INT pos = PT_BYTE; 1095 ptrdiff_t pos = PT_BYTE;
1103 DEC_POS (pos); 1096 DEC_POS (pos);
1104 XSETFASTINT (temp, FETCH_CHAR (pos)); 1097 XSETFASTINT (temp, FETCH_CHAR (pos));
1105 } 1098 }
@@ -1153,7 +1146,7 @@ POS is an integer or a marker and defaults to point.
1153If POS is out of range, the value is nil. */) 1146If POS is out of range, the value is nil. */)
1154 (Lisp_Object pos) 1147 (Lisp_Object pos)
1155{ 1148{
1156 register EMACS_INT pos_byte; 1149 register ptrdiff_t pos_byte;
1157 1150
1158 if (NILP (pos)) 1151 if (NILP (pos))
1159 { 1152 {
@@ -1186,7 +1179,7 @@ If POS is out of range, the value is nil. */)
1186 (Lisp_Object pos) 1179 (Lisp_Object pos)
1187{ 1180{
1188 register Lisp_Object val; 1181 register Lisp_Object val;
1189 register EMACS_INT pos_byte; 1182 register ptrdiff_t pos_byte;
1190 1183
1191 if (NILP (pos)) 1184 if (NILP (pos))
1192 { 1185 {
@@ -1246,7 +1239,7 @@ of the user with that uid, or nil if there is no such user. */)
1246 if (NILP (uid)) 1239 if (NILP (uid))
1247 return Vuser_login_name; 1240 return Vuser_login_name;
1248 1241
1249 id = XFLOATINT (uid); 1242 CONS_TO_INTEGER (uid, uid_t, id);
1250 BLOCK_INPUT; 1243 BLOCK_INPUT;
1251 pw = getpwuid (id); 1244 pw = getpwuid (id);
1252 UNBLOCK_INPUT; 1245 UNBLOCK_INPUT;
@@ -1273,14 +1266,7 @@ DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0,
1273Value is an integer or a float, depending on the value. */) 1266Value is an integer or a float, depending on the value. */)
1274 (void) 1267 (void)
1275{ 1268{
1276 /* Assignment to EMACS_INT stops GCC whining about limited range of 1269 uid_t euid = geteuid ();
1277 data type. */
1278 EMACS_INT euid = geteuid ();
1279
1280 /* Make sure we don't produce a negative UID due to signed integer
1281 overflow. */
1282 if (euid < 0)
1283 return make_float (geteuid ());
1284 return make_fixnum_or_float (euid); 1270 return make_fixnum_or_float (euid);
1285} 1271}
1286 1272
@@ -1289,14 +1275,7 @@ DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
1289Value is an integer or a float, depending on the value. */) 1275Value is an integer or a float, depending on the value. */)
1290 (void) 1276 (void)
1291{ 1277{
1292 /* Assignment to EMACS_INT stops GCC whining about limited range of 1278 uid_t uid = getuid ();
1293 data type. */
1294 EMACS_INT uid = getuid ();
1295
1296 /* Make sure we don't produce a negative UID due to signed integer
1297 overflow. */
1298 if (uid < 0)
1299 return make_float (getuid ());
1300 return make_fixnum_or_float (uid); 1279 return make_fixnum_or_float (uid);
1301} 1280}
1302 1281
@@ -1319,7 +1298,8 @@ name, or nil if there is no such user. */)
1319 return Vuser_full_name; 1298 return Vuser_full_name;
1320 else if (NUMBERP (uid)) 1299 else if (NUMBERP (uid))
1321 { 1300 {
1322 uid_t u = XFLOATINT (uid); 1301 uid_t u;
1302 CONS_TO_INTEGER (uid, uid_t, u);
1323 BLOCK_INPUT; 1303 BLOCK_INPUT;
1324 pw = getpwuid (u); 1304 pw = getpwuid (u);
1325 UNBLOCK_INPUT; 1305 UNBLOCK_INPUT;
@@ -1381,10 +1361,11 @@ get_system_name (void)
1381} 1361}
1382 1362
1383DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0, 1363DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
1384 doc: /* Return the process ID of Emacs, as an integer. */) 1364 doc: /* Return the process ID of Emacs, as a number. */)
1385 (void) 1365 (void)
1386{ 1366{
1387 return make_number (getpid ()); 1367 pid_t pid = getpid ();
1368 return make_fixnum_or_float (pid);
1388} 1369}
1389 1370
1390 1371
@@ -1424,7 +1405,7 @@ hi_time (time_t t)
1424} 1405}
1425 1406
1426/* Return the bottom 16 bits of the time T. */ 1407/* Return the bottom 16 bits of the time T. */
1427static EMACS_INT 1408static int
1428lo_time (time_t t) 1409lo_time (time_t t)
1429{ 1410{
1430 return t & ((1 << 16) - 1); 1411 return t & ((1 << 16) - 1);
@@ -1542,6 +1523,8 @@ lisp_time_argument (Lisp_Object specified_time, time_t *result, int *usec)
1542 else 1523 else
1543 { 1524 {
1544 CHECK_NUMBER (usec_l); 1525 CHECK_NUMBER (usec_l);
1526 if (! (0 <= XINT (usec_l) && XINT (usec_l) < 1000000))
1527 return 0;
1545 *usec = XINT (usec_l); 1528 *usec = XINT (usec_l);
1546 } 1529 }
1547 } 1530 }
@@ -1712,7 +1695,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1712{ 1695{
1713 char buffer[4000]; 1696 char buffer[4000];
1714 char *buf = buffer; 1697 char *buf = buffer;
1715 size_t size = sizeof buffer; 1698 ptrdiff_t size = sizeof buffer;
1716 size_t len; 1699 size_t len;
1717 Lisp_Object bufstring; 1700 Lisp_Object bufstring;
1718 int usec; 1701 int usec;
@@ -1720,8 +1703,7 @@ format_time_string (char const *format, ptrdiff_t formatlen,
1720 struct tm *tm; 1703 struct tm *tm;
1721 USE_SAFE_ALLOCA; 1704 USE_SAFE_ALLOCA;
1722 1705
1723 if (! (lisp_time_argument (timeval, tval, &usec) 1706 if (! lisp_time_argument (timeval, tval, &usec))
1724 && 0 <= usec && usec < 1000000))
1725 error ("Invalid time specification"); 1707 error ("Invalid time specification");
1726 ns = usec * 1000; 1708 ns = usec * 1000;
1727 1709
@@ -1885,9 +1867,12 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1885 tzstring = SSDATA (zone); 1867 tzstring = SSDATA (zone);
1886 else if (INTEGERP (zone)) 1868 else if (INTEGERP (zone))
1887 { 1869 {
1888 int abszone = eabs (XINT (zone)); 1870 EMACS_INT abszone = eabs (XINT (zone));
1889 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0), 1871 EMACS_INT zone_hr = abszone / (60*60);
1890 abszone / (60*60), (abszone/60) % 60, abszone % 60); 1872 int zone_min = (abszone/60) % 60;
1873 int zone_sec = abszone % 60;
1874 sprintf (tzbuf, "XXX%s%"pI"d:%02d:%02d", "-" + (XINT (zone) < 0),
1875 zone_hr, zone_min, zone_sec);
1891 tzstring = tzbuf; 1876 tzstring = tzbuf;
1892 } 1877 }
1893 else 1878 else
@@ -2193,10 +2178,10 @@ set_time_zone_rule (const char *tzstring)
2193 2178
2194static void 2179static void
2195general_insert_function (void (*insert_func) 2180general_insert_function (void (*insert_func)
2196 (const char *, EMACS_INT), 2181 (const char *, ptrdiff_t),
2197 void (*insert_from_string_func) 2182 void (*insert_from_string_func)
2198 (Lisp_Object, EMACS_INT, EMACS_INT, 2183 (Lisp_Object, ptrdiff_t, ptrdiff_t,
2199 EMACS_INT, EMACS_INT, int), 2184 ptrdiff_t, ptrdiff_t, int),
2200 int inherit, ptrdiff_t nargs, Lisp_Object *args) 2185 int inherit, ptrdiff_t nargs, Lisp_Object *args)
2201{ 2186{
2202 ptrdiff_t argnum; 2187 ptrdiff_t argnum;
@@ -2332,7 +2317,7 @@ from adjoining text, if those properties are sticky. */)
2332 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit) 2317 (Lisp_Object character, Lisp_Object count, Lisp_Object inherit)
2333{ 2318{
2334 int i, stringlen; 2319 int i, stringlen;
2335 register EMACS_INT n; 2320 register ptrdiff_t n;
2336 int c, len; 2321 int c, len;
2337 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2322 unsigned char str[MAX_MULTIBYTE_LENGTH];
2338 char string[4000]; 2323 char string[4000];
@@ -2408,10 +2393,10 @@ from adjoining text, if those properties are sticky. */)
2408 buffer substrings. */ 2393 buffer substrings. */
2409 2394
2410Lisp_Object 2395Lisp_Object
2411make_buffer_string (EMACS_INT start, EMACS_INT end, int props) 2396make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
2412{ 2397{
2413 EMACS_INT start_byte = CHAR_TO_BYTE (start); 2398 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
2414 EMACS_INT end_byte = CHAR_TO_BYTE (end); 2399 ptrdiff_t end_byte = CHAR_TO_BYTE (end);
2415 2400
2416 return make_buffer_string_both (start, start_byte, end, end_byte, props); 2401 return make_buffer_string_both (start, start_byte, end, end_byte, props);
2417} 2402}
@@ -2432,8 +2417,8 @@ make_buffer_string (EMACS_INT start, EMACS_INT end, int props)
2432 buffer substrings. */ 2417 buffer substrings. */
2433 2418
2434Lisp_Object 2419Lisp_Object
2435make_buffer_string_both (EMACS_INT start, EMACS_INT start_byte, 2420make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte,
2436 EMACS_INT end, EMACS_INT end_byte, int props) 2421 ptrdiff_t end, ptrdiff_t end_byte, int props)
2437{ 2422{
2438 Lisp_Object result, tem, tem1; 2423 Lisp_Object result, tem, tem1;
2439 2424
@@ -2466,7 +2451,7 @@ make_buffer_string_both (EMACS_INT start, EMACS_INT start_byte,
2466 in the current buffer, if necessary. */ 2451 in the current buffer, if necessary. */
2467 2452
2468static void 2453static void
2469update_buffer_properties (EMACS_INT start, EMACS_INT end) 2454update_buffer_properties (ptrdiff_t start, ptrdiff_t end)
2470{ 2455{
2471 /* If this buffer has some access functions, 2456 /* If this buffer has some access functions,
2472 call them, specifying the range of the buffer being accessed. */ 2457 call them, specifying the range of the buffer being accessed. */
@@ -2505,7 +2490,7 @@ into the result string; if you don't want the text properties,
2505use `buffer-substring-no-properties' instead. */) 2490use `buffer-substring-no-properties' instead. */)
2506 (Lisp_Object start, Lisp_Object end) 2491 (Lisp_Object start, Lisp_Object end)
2507{ 2492{
2508 register EMACS_INT b, e; 2493 register ptrdiff_t b, e;
2509 2494
2510 validate_region (&start, &end); 2495 validate_region (&start, &end);
2511 b = XINT (start); 2496 b = XINT (start);
@@ -2521,7 +2506,7 @@ The two arguments START and END are character positions;
2521they can be in either order. */) 2506they can be in either order. */)
2522 (Lisp_Object start, Lisp_Object end) 2507 (Lisp_Object start, Lisp_Object end)
2523{ 2508{
2524 register EMACS_INT b, e; 2509 register ptrdiff_t b, e;
2525 2510
2526 validate_region (&start, &end); 2511 validate_region (&start, &end);
2527 b = XINT (start); 2512 b = XINT (start);
@@ -2605,8 +2590,8 @@ determines whether case is significant or ignored. */)
2605 register Lisp_Object trt 2590 register Lisp_Object trt
2606 = (!NILP (BVAR (current_buffer, case_fold_search)) 2591 = (!NILP (BVAR (current_buffer, case_fold_search))
2607 ? BVAR (current_buffer, case_canon_table) : Qnil); 2592 ? BVAR (current_buffer, case_canon_table) : Qnil);
2608 EMACS_INT chars = 0; 2593 ptrdiff_t chars = 0;
2609 EMACS_INT i1, i2, i1_byte, i2_byte; 2594 ptrdiff_t i1, i2, i1_byte, i2_byte;
2610 2595
2611 /* Find the first buffer and its substring. */ 2596 /* Find the first buffer and its substring. */
2612 2597
@@ -2767,21 +2752,21 @@ and don't mark the buffer as really changed.
2767Both characters must have the same length of multi-byte form. */) 2752Both characters must have the same length of multi-byte form. */)
2768 (Lisp_Object start, Lisp_Object end, Lisp_Object fromchar, Lisp_Object tochar, Lisp_Object noundo) 2753 (Lisp_Object start, Lisp_Object end, Lisp_Object fromchar, Lisp_Object tochar, Lisp_Object noundo)
2769{ 2754{
2770 register EMACS_INT pos, pos_byte, stop, i, len, end_byte; 2755 register ptrdiff_t pos, pos_byte, stop, i, len, end_byte;
2771 /* Keep track of the first change in the buffer: 2756 /* Keep track of the first change in the buffer:
2772 if 0 we haven't found it yet. 2757 if 0 we haven't found it yet.
2773 if < 0 we've found it and we've run the before-change-function. 2758 if < 0 we've found it and we've run the before-change-function.
2774 if > 0 we've actually performed it and the value is its position. */ 2759 if > 0 we've actually performed it and the value is its position. */
2775 EMACS_INT changed = 0; 2760 ptrdiff_t changed = 0;
2776 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH]; 2761 unsigned char fromstr[MAX_MULTIBYTE_LENGTH], tostr[MAX_MULTIBYTE_LENGTH];
2777 unsigned char *p; 2762 unsigned char *p;
2778 int count = SPECPDL_INDEX (); 2763 ptrdiff_t count = SPECPDL_INDEX ();
2779#define COMBINING_NO 0 2764#define COMBINING_NO 0
2780#define COMBINING_BEFORE 1 2765#define COMBINING_BEFORE 1
2781#define COMBINING_AFTER 2 2766#define COMBINING_AFTER 2
2782#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER) 2767#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
2783 int maybe_byte_combining = COMBINING_NO; 2768 int maybe_byte_combining = COMBINING_NO;
2784 EMACS_INT last_changed = 0; 2769 ptrdiff_t last_changed = 0;
2785 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2770 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2786 int fromc, toc; 2771 int fromc, toc;
2787 2772
@@ -2841,7 +2826,7 @@ Both characters must have the same length of multi-byte form. */)
2841 stop = min (stop, GPT_BYTE); 2826 stop = min (stop, GPT_BYTE);
2842 while (1) 2827 while (1)
2843 { 2828 {
2844 EMACS_INT pos_byte_next = pos_byte; 2829 ptrdiff_t pos_byte_next = pos_byte;
2845 2830
2846 if (pos_byte >= stop) 2831 if (pos_byte >= stop)
2847 { 2832 {
@@ -2944,7 +2929,7 @@ Both characters must have the same length of multi-byte form. */)
2944} 2929}
2945 2930
2946 2931
2947static Lisp_Object check_translation (EMACS_INT, EMACS_INT, EMACS_INT, 2932static Lisp_Object check_translation (ptrdiff_t, ptrdiff_t, ptrdiff_t,
2948 Lisp_Object); 2933 Lisp_Object);
2949 2934
2950/* Helper function for Ftranslate_region_internal. 2935/* Helper function for Ftranslate_region_internal.
@@ -2954,7 +2939,7 @@ static Lisp_Object check_translation (EMACS_INT, EMACS_INT, EMACS_INT,
2954 element is found, return it. Otherwise return Qnil. */ 2939 element is found, return it. Otherwise return Qnil. */
2955 2940
2956static Lisp_Object 2941static Lisp_Object
2957check_translation (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT end, 2942check_translation (ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t end,
2958 Lisp_Object val) 2943 Lisp_Object val)
2959{ 2944{
2960 int buf_size = 16, buf_used = 0; 2945 int buf_size = 16, buf_used = 0;
@@ -2963,7 +2948,7 @@ check_translation (EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT end,
2963 for (; CONSP (val); val = XCDR (val)) 2948 for (; CONSP (val); val = XCDR (val))
2964 { 2949 {
2965 Lisp_Object elt; 2950 Lisp_Object elt;
2966 EMACS_INT len, i; 2951 ptrdiff_t len, i;
2967 2952
2968 elt = XCAR (val); 2953 elt = XCAR (val);
2969 if (! CONSP (elt)) 2954 if (! CONSP (elt))
@@ -3016,8 +3001,8 @@ It returns the number of characters changed. */)
3016 register unsigned char *tt; /* Trans table. */ 3001 register unsigned char *tt; /* Trans table. */
3017 register int nc; /* New character. */ 3002 register int nc; /* New character. */
3018 int cnt; /* Number of changes made. */ 3003 int cnt; /* Number of changes made. */
3019 EMACS_INT size; /* Size of translate table. */ 3004 ptrdiff_t size; /* Size of translate table. */
3020 EMACS_INT pos, pos_byte, end_pos; 3005 ptrdiff_t pos, pos_byte, end_pos;
3021 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 3006 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
3022 int string_multibyte IF_LINT (= 0); 3007 int string_multibyte IF_LINT (= 0);
3023 3008
@@ -3295,7 +3280,7 @@ save_restriction_restore (Lisp_Object data)
3295 /* The restriction has changed from the saved one, so restore 3280 /* The restriction has changed from the saved one, so restore
3296 the saved restriction. */ 3281 the saved restriction. */
3297 { 3282 {
3298 EMACS_INT pt = BUF_PT (buf); 3283 ptrdiff_t pt = BUF_PT (buf);
3299 3284
3300 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos); 3285 SET_BUF_BEGV_BOTH (buf, beg->charpos, beg->bytepos);
3301 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos); 3286 SET_BUF_ZV_BOTH (buf, end->charpos, end->bytepos);
@@ -3353,7 +3338,7 @@ usage: (save-restriction &rest BODY) */)
3353 (Lisp_Object body) 3338 (Lisp_Object body)
3354{ 3339{
3355 register Lisp_Object val; 3340 register Lisp_Object val;
3356 int count = SPECPDL_INDEX (); 3341 ptrdiff_t count = SPECPDL_INDEX ();
3357 3342
3358 record_unwind_protect (save_restriction_restore, save_restriction_save ()); 3343 record_unwind_protect (save_restriction_restore, save_restriction_save ());
3359 val = Fprogn (body); 3344 val = Fprogn (body);
@@ -3571,12 +3556,12 @@ usage: (format STRING &rest OBJECTS) */)
3571 ptrdiff_t n; /* The number of the next arg to substitute */ 3556 ptrdiff_t n; /* The number of the next arg to substitute */
3572 char initial_buffer[4000]; 3557 char initial_buffer[4000];
3573 char *buf = initial_buffer; 3558 char *buf = initial_buffer;
3574 EMACS_INT bufsize = sizeof initial_buffer; 3559 ptrdiff_t bufsize = sizeof initial_buffer;
3575 EMACS_INT max_bufsize = STRING_BYTES_BOUND + 1; 3560 ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1;
3576 char *p; 3561 char *p;
3577 Lisp_Object buf_save_value IF_LINT (= {0}); 3562 Lisp_Object buf_save_value IF_LINT (= {0});
3578 register char *format, *end, *format_start; 3563 register char *format, *end, *format_start;
3579 EMACS_INT formatlen, nchars; 3564 ptrdiff_t formatlen, nchars;
3580 /* Nonzero if the format is multibyte. */ 3565 /* Nonzero if the format is multibyte. */
3581 int multibyte_format = 0; 3566 int multibyte_format = 0;
3582 /* Nonzero if the output should be a multibyte string, 3567 /* Nonzero if the output should be a multibyte string,
@@ -3603,7 +3588,7 @@ usage: (format STRING &rest OBJECTS) */)
3603 info[0] is unused. Unused elements have -1 for start. */ 3588 info[0] is unused. Unused elements have -1 for start. */
3604 struct info 3589 struct info
3605 { 3590 {
3606 EMACS_INT start, end; 3591 ptrdiff_t start, end;
3607 int converted_to_string; 3592 int converted_to_string;
3608 int intervals; 3593 int intervals;
3609 } *info = 0; 3594 } *info = 0;
@@ -3660,7 +3645,7 @@ usage: (format STRING &rest OBJECTS) */)
3660 char *format0 = format; 3645 char *format0 = format;
3661 3646
3662 /* Bytes needed to represent the output of this conversion. */ 3647 /* Bytes needed to represent the output of this conversion. */
3663 EMACS_INT convbytes; 3648 ptrdiff_t convbytes;
3664 3649
3665 if (*format == '%') 3650 if (*format == '%')
3666 { 3651 {
@@ -3687,7 +3672,7 @@ usage: (format STRING &rest OBJECTS) */)
3687 int space_flag = 0; 3672 int space_flag = 0;
3688 int sharp_flag = 0; 3673 int sharp_flag = 0;
3689 int zero_flag = 0; 3674 int zero_flag = 0;
3690 EMACS_INT field_width; 3675 ptrdiff_t field_width;
3691 int precision_given; 3676 int precision_given;
3692 uintmax_t precision = UINTMAX_MAX; 3677 uintmax_t precision = UINTMAX_MAX;
3693 char *num_end; 3678 char *num_end;
@@ -3794,11 +3779,11 @@ usage: (format STRING &rest OBJECTS) */)
3794 { 3779 {
3795 /* handle case (precision[n] >= 0) */ 3780 /* handle case (precision[n] >= 0) */
3796 3781
3797 EMACS_INT width, padding, nbytes; 3782 ptrdiff_t width, padding, nbytes;
3798 EMACS_INT nchars_string; 3783 ptrdiff_t nchars_string;
3799 3784
3800 EMACS_INT prec = -1; 3785 ptrdiff_t prec = -1;
3801 if (precision_given && precision <= TYPE_MAXIMUM (EMACS_INT)) 3786 if (precision_given && precision <= TYPE_MAXIMUM (ptrdiff_t))
3802 prec = precision; 3787 prec = precision;
3803 3788
3804 /* lisp_string_width ignores a precision of 0, but GNU 3789 /* lisp_string_width ignores a precision of 0, but GNU
@@ -3811,7 +3796,7 @@ usage: (format STRING &rest OBJECTS) */)
3811 width = nchars_string = nbytes = 0; 3796 width = nchars_string = nbytes = 0;
3812 else 3797 else
3813 { 3798 {
3814 EMACS_INT nch, nby; 3799 ptrdiff_t nch, nby;
3815 width = lisp_string_width (args[n], prec, &nch, &nby); 3800 width = lisp_string_width (args[n], prec, &nch, &nby);
3816 if (prec < 0) 3801 if (prec < 0)
3817 { 3802 {
@@ -3908,7 +3893,7 @@ usage: (format STRING &rest OBJECTS) */)
3908 verify (0 < USEFUL_PRECISION_MAX); 3893 verify (0 < USEFUL_PRECISION_MAX);
3909 3894
3910 int prec; 3895 int prec;
3911 EMACS_INT padding, sprintf_bytes; 3896 ptrdiff_t padding, sprintf_bytes;
3912 uintmax_t excess_precision, numwidth; 3897 uintmax_t excess_precision, numwidth;
3913 uintmax_t leading_zeros = 0, trailing_zeros = 0; 3898 uintmax_t leading_zeros = 0, trailing_zeros = 0;
3914 3899
@@ -4223,8 +4208,8 @@ usage: (format STRING &rest OBJECTS) */)
4223 4208
4224 if (CONSP (props)) 4209 if (CONSP (props))
4225 { 4210 {
4226 EMACS_INT bytepos = 0, position = 0, translated = 0; 4211 ptrdiff_t bytepos = 0, position = 0, translated = 0;
4227 EMACS_INT argn = 1; 4212 ptrdiff_t argn = 1;
4228 Lisp_Object list; 4213 Lisp_Object list;
4229 4214
4230 /* Adjust the bounds of each text property 4215 /* Adjust the bounds of each text property
@@ -4242,7 +4227,7 @@ usage: (format STRING &rest OBJECTS) */)
4242 for (list = props; CONSP (list); list = XCDR (list)) 4227 for (list = props; CONSP (list); list = XCDR (list))
4243 { 4228 {
4244 Lisp_Object item; 4229 Lisp_Object item;
4245 EMACS_INT pos; 4230 ptrdiff_t pos;
4246 4231
4247 item = XCAR (list); 4232 item = XCAR (list);
4248 4233
@@ -4373,12 +4358,12 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer. */)
4373 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */ 4358 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
4374 4359
4375static void 4360static void
4376transpose_markers (EMACS_INT start1, EMACS_INT end1, 4361transpose_markers (ptrdiff_t start1, ptrdiff_t end1,
4377 EMACS_INT start2, EMACS_INT end2, 4362 ptrdiff_t start2, ptrdiff_t end2,
4378 EMACS_INT start1_byte, EMACS_INT end1_byte, 4363 ptrdiff_t start1_byte, ptrdiff_t end1_byte,
4379 EMACS_INT start2_byte, EMACS_INT end2_byte) 4364 ptrdiff_t start2_byte, ptrdiff_t end2_byte)
4380{ 4365{
4381 register EMACS_INT amt1, amt1_byte, amt2, amt2_byte, diff, diff_byte, mpos; 4366 register ptrdiff_t amt1, amt1_byte, amt2, amt2_byte, diff, diff_byte, mpos;
4382 register struct Lisp_Marker *marker; 4367 register struct Lisp_Marker *marker;
4383 4368
4384 /* Update point as if it were a marker. */ 4369 /* Update point as if it were a marker. */
@@ -4452,9 +4437,9 @@ any markers that happen to be located in the regions.
4452Transposing beyond buffer boundaries is an error. */) 4437Transposing beyond buffer boundaries is an error. */)
4453 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers) 4438 (Lisp_Object startr1, Lisp_Object endr1, Lisp_Object startr2, Lisp_Object endr2, Lisp_Object leave_markers)
4454{ 4439{
4455 register EMACS_INT start1, end1, start2, end2; 4440 register ptrdiff_t start1, end1, start2, end2;
4456 EMACS_INT start1_byte, start2_byte, len1_byte, len2_byte; 4441 ptrdiff_t start1_byte, start2_byte, len1_byte, len2_byte;
4457 EMACS_INT gap, len1, len_mid, len2; 4442 ptrdiff_t gap, len1, len_mid, len2;
4458 unsigned char *start1_addr, *start2_addr, *temp; 4443 unsigned char *start1_addr, *start2_addr, *temp;
4459 4444
4460 INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2, tmp_interval3; 4445 INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2, tmp_interval3;
@@ -4475,7 +4460,7 @@ Transposing beyond buffer boundaries is an error. */)
4475 /* Swap the regions if they're reversed. */ 4460 /* Swap the regions if they're reversed. */
4476 if (start2 < end1) 4461 if (start2 < end1)
4477 { 4462 {
4478 register EMACS_INT glumph = start1; 4463 register ptrdiff_t glumph = start1;
4479 start1 = start2; 4464 start1 = start2;
4480 start2 = glumph; 4465 start2 = glumph;
4481 glumph = end1; 4466 glumph = end1;