static void find_field P_ ((Lisp_Object, Lisp_Object, Lisp_Object, int *, Lisp_Object, int *));
static void update_buffer_properties P_ ((int, int));
static Lisp_Object region_limit P_ ((int));
-static int lisp_time_argument P_ ((Lisp_Object, time_t *, int *));
+int lisp_time_argument P_ ((Lisp_Object, time_t *, int *));
static size_t emacs_memftimeu P_ ((char *, size_t, const char *,
size_t, const struct tm *, int));
static void general_insert_function P_ ((void (*) (const unsigned char *, int),
DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0,
doc: /* Return the name under which the user logged in, as a string.
This is based on the effective uid, not the real uid.
-Also, if the environment variable LOGNAME or USER is set,
+Also, if the environment variables LOGNAME or USER are set,
that determines the value of this function.
If optional argument UID is an integer, return the login name of the user
}
\f
-static int
+int
lisp_time_argument (specified_time, result, usec)
Lisp_Object specified_time;
time_t *result;
DEFUN ("float-time", Ffloat_time, Sfloat_time, 0, 1, 0,
doc: /* Return the current time, as a float number of seconds since the epoch.
-If an argument is given, it specifies a time to convert to float
-instead of the current time. The argument should have the forms:
- (HIGH . LOW) or (HIGH LOW USEC) or (HIGH LOW . USEC).
-Thus, you can use times obtained from `current-time'
-and from `file-attributes'.
+If SPECIFIED-TIME is given, it is the time to convert to float
+instead of the current time. The argument should have the form
+(HIGH LOW . IGNORED). Thus, you can use times obtained from
+`current-time' and from `file-attributes'. SPECIFIED-TIME can also
+have the form (HIGH . LOW), but this is considered obsolete.
WARNING: Since the result is floating point, it may not be exact.
Do not use this function if precise time stamps are required. */)
DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
doc: /* Use FORMAT-STRING to format the time TIME, or now if omitted.
-TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by
-`current-time' or `file-attributes'.
+TIME is specified as (HIGH LOW . IGNORED), as returned by
+`current-time' or `file-attributes'. The obsolete form (HIGH . LOW)
+is also still accepted.
The third, optional, argument UNIVERSAL, if non-nil, means describe TIME
as Universal Time; nil means describe TIME in the local time zone.
The value is a copy of FORMAT-STRING, but with certain constructs replaced
DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0,
doc: /* Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).
-The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)
-or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'
-to use the current time. The list has the following nine members:
-SEC is an integer between 0 and 60; SEC is 60 for a leap second, which
-only some operating systems support. MINUTE is an integer between 0 and 59.
-HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.
-MONTH is an integer between 1 and 12. YEAR is an integer indicating the
-four-digit year. DOW is the day of week, an integer between 0 and 6, where
-0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.
-ZONE is an integer indicating the number of seconds east of Greenwich.
-(Note that Common Lisp has different meanings for DOW and ZONE.) */)
+The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED),
+as from `current-time' and `file-attributes', or `nil' to use the
+current time. The obsolete form (HIGH . LOW) is also still accepted.
+The list has the following nine members: SEC is an integer between 0
+and 60; SEC is 60 for a leap second, which only some operating systems
+support. MINUTE is an integer between 0 and 59. HOUR is an integer
+between 0 and 23. DAY is an integer between 1 and 31. MONTH is an
+integer between 1 and 12. YEAR is an integer indicating the
+four-digit year. DOW is the day of week, an integer between 0 and 6,
+where 0 is Sunday. DST is t if daylight savings time is effect,
+otherwise nil. ZONE is an integer indicating the number of seconds
+east of Greenwich. (Note that Common Lisp has different meanings for
+DOW and ZONE.) */)
(specified_time)
Lisp_Object specified_time;
{
The intervening arguments are ignored.
This feature lets (apply 'encode-time (decode-time ...)) work.
-Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;
+Out-of-range values for SECOND, MINUTE, HOUR, DAY, or MONTH are allowed;
for example, a DAY of 0 means the day preceding the given month.
Year numbers less than 100 are treated just like other year numbers.
If you want them to stand for years in this century, you must do that yourself.
However, see also the functions `decode-time' and `format-time-string'
which provide a much more powerful and general facility.
-If an argument is given, it specifies a time to format
-instead of the current time. The argument should have the form:
- (HIGH . LOW)
-or the form:
- (HIGH LOW . IGNORED).
-Thus, you can use times obtained from `current-time'
-and from `file-attributes'. */)
+If SPECIFIED-TIME is given, it is a time to format instead of the
+current time. The argument should have the form (HIGH LOW . IGNORED).
+Thus, you can use times obtained from `current-time' and from
+`file-attributes'. SPECIFIED-TIME can also have the form (HIGH . LOW),
+but this is considered obsolete. */)
(specified_time)
Lisp_Object specified_time;
{
OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
A negative value means west of Greenwich.
NAME is a string giving the name of the time zone.
-If an argument is given, it specifies when the time zone offset is determined
-instead of using the current time. The argument should have the form:
- (HIGH . LOW)
-or the form:
- (HIGH LOW . IGNORED).
-Thus, you can use times obtained from `current-time'
-and from `file-attributes'.
+If SPECIFIED-TIME is given, the time zone offset is determined from it
+instead of using the current time. The argument should have the form
+(HIGH LOW . IGNORED). Thus, you can use times obtained from
+`current-time' and from `file-attributes'. SPECIFIED-TIME can also
+have the form (HIGH . LOW), but this is considered obsolete.
Some operating systems cannot provide all this information to Emacs;
in this case, `current-time-zone' returns a list containing nil for
DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
1, 3, 0,
- doc: /* Insert before point a substring of the contents of buffer BUFFER.
+ doc: /* Insert before point a substring of the contents of BUFFER.
BUFFER may be a buffer or a buffer name.
-Arguments START and END are character numbers specifying the substring.
-They default to the beginning and the end of BUFFER. */)
- (buf, start, end)
- Lisp_Object buf, start, end;
+Arguments START and END are character positions specifying the substring.
+They default to the values of (point-min) and (point-max) in BUFFER. */)
+ (buffer, start, end)
+ Lisp_Object buffer, start, end;
{
register int b, e, temp;
register struct buffer *bp, *obuf;
- Lisp_Object buffer;
+ Lisp_Object buf;
- buffer = Fget_buffer (buf);
- if (NILP (buffer))
- nsberror (buf);
- bp = XBUFFER (buffer);
+ buf = Fget_buffer (buffer);
+ if (NILP (buf))
+ nsberror (buffer);
+ bp = XBUFFER (buf);
if (NILP (bp->name))
error ("Selecting deleted buffer");
DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",
doc: /* Delete the text between point and mark.
+
When called from a program, expects two arguments,
positions (integers or markers) specifying the stretch to be deleted. */)
(start, end)
string itself, will not be used. Element NARGS, corresponding to
no argument, *will* be assigned to in the case that a `%' and `.'
occur after the final format specifier. */
- int *precision = (int *) (alloca(nargs * sizeof (int)));
+ int *precision = (int *) (alloca((nargs + 1) * sizeof (int)));
int longest_format;
Lisp_Object val;
int arg_intervals = 0;
+ USE_SAFE_ALLOCA;
/* discarded[I] is 1 if byte I of the format
string was not copied into the output.
/* Piggyback on this loop to initialize precision[N]. */
precision[n] = -1;
}
+ precision[nargs] = -1;
CHECK_STRING (args[0]);
/* We may have to change "%S" to "%s". */
longest_format = 0;
/* Make room in result for all the non-%-codes in the control string. */
- total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]);
+ total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]) + 1;
- /* Allocate the info and discarded tables. */
+ /* Allocate the info and discarded tables. */
{
- int nbytes = nargs * sizeof *info;
+ int nbytes = (nargs+1) * sizeof *info;
int i;
info = (struct info *) alloca (nbytes);
bzero (info, nbytes);
/* Allocate the space for the result.
Note that TOTAL is an overestimate. */
- if (total < 1000)
- buf = (char *) alloca (total + 1);
- else
- buf = (char *) xmalloc (total + 1);
+ SAFE_ALLOCA (buf, char *, total);
p = buf;
nchars = 0;
maybe_combine_byte = 1;
this_nchars = strlen (p);
if (multibyte)
- p += str_to_multibyte (p, buf + total - p, this_nchars);
+ p += str_to_multibyte (p, buf + total - 1 - p, this_nchars);
else
p += this_nchars;
nchars += this_nchars;
*p++ = *format++, nchars++;
}
- if (p > buf + total + 1)
+ if (p > buf + total)
abort ();
if (maybe_combine_byte)
val = make_specified_string (buf, nchars, p - buf, multibyte);
/* If we allocated BUF with malloc, free it too. */
- if (total >= 1000)
- xfree (buf);
+ SAFE_FREE (total);
/* If the format string has text properties, or any of the string
arguments has text properties, set up text properties of the
}
DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0,
- doc: /* Transpose region START1 to END1 with START2 to END2.
+ doc: /* Transpose region STARTR1 to ENDR1 with STARTR2 to ENDR2.
The regions may not be overlapping, because the size of the buffer is
never changed in a transposition.
-Optional fifth arg LEAVE_MARKERS, if non-nil, means don't update
+Optional fifth arg LEAVE-MARKERS, if non-nil, means don't update
any markers that happen to be located in the regions.
Transposing beyond buffer boundaries is an error. */)
/* First region smaller than second. */
if (len1_byte < len2_byte)
{
- /* We use alloca only if it is small,
- because we want to avoid stack overflow. */
- if (len2_byte > 20000)
- temp = (unsigned char *) xmalloc (len2_byte);
- else
- temp = (unsigned char *) alloca (len2_byte);
+ USE_SAFE_ALLOCA;
+
+ SAFE_ALLOCA (temp, unsigned char *, len2_byte);
/* Don't precompute these addresses. We have to compute them
at the last minute, because the relocating allocator might
bcopy (start2_addr, temp, len2_byte);
bcopy (start1_addr, start1_addr + len2_byte, len1_byte);
bcopy (temp, start1_addr, len2_byte);
- if (len2_byte > 20000)
- xfree (temp);
+ SAFE_FREE (len2_byte);
}
else
/* First region not smaller than second. */
{
- if (len1_byte > 20000)
- temp = (unsigned char *) xmalloc (len1_byte);
- else
- temp = (unsigned char *) alloca (len1_byte);
+ USE_SAFE_ALLOCA;
+
+ SAFE_ALLOCA (temp, unsigned char *, len1_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
bcopy (start1_addr, temp, len1_byte);
bcopy (start2_addr, start1_addr, len2_byte);
bcopy (temp, start1_addr + len2_byte, len1_byte);
- if (len1_byte > 20000)
- xfree (temp);
+ SAFE_FREE (len1_byte);
}
graft_intervals_into_buffer (tmp_interval1, start1 + len2,
len1, current_buffer, 0);
if (len1_byte == len2_byte)
/* Regions are same size, though, how nice. */
{
+ USE_SAFE_ALLOCA;
+
modify_region (current_buffer, start1, end1);
modify_region (current_buffer, start2, end2);
record_change (start1, len1);
Fset_text_properties (make_number (start2), make_number (end2),
Qnil, Qnil);
- if (len1_byte > 20000)
- temp = (unsigned char *) xmalloc (len1_byte);
- else
- temp = (unsigned char *) alloca (len1_byte);
+ SAFE_ALLOCA (temp, unsigned char *, len1_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
bcopy (start1_addr, temp, len1_byte);
bcopy (start2_addr, start1_addr, len2_byte);
bcopy (temp, start2_addr, len1_byte);
- if (len1_byte > 20000)
- xfree (temp);
+ SAFE_FREE (len1_byte);
+
graft_intervals_into_buffer (tmp_interval1, start2,
len1, current_buffer, 0);
graft_intervals_into_buffer (tmp_interval2, start1,
else if (len1_byte < len2_byte) /* Second region larger than first */
/* Non-adjacent & unequal size, area between must also be shifted. */
{
+ USE_SAFE_ALLOCA;
+
modify_region (current_buffer, start1, end2);
record_change (start1, (end2 - start1));
tmp_interval1 = copy_intervals (cur_intv, start1, len1);
Qnil, Qnil);
/* holds region 2 */
- if (len2_byte > 20000)
- temp = (unsigned char *) xmalloc (len2_byte);
- else
- temp = (unsigned char *) alloca (len2_byte);
+ SAFE_ALLOCA (temp, unsigned char *, len2_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
bcopy (start2_addr, temp, len2_byte);
bcopy (start1_addr, start1_addr + len_mid + len2_byte, len1_byte);
safe_bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
bcopy (temp, start1_addr, len2_byte);
- if (len2_byte > 20000)
- xfree (temp);
+ SAFE_FREE (len2_byte);
+
graft_intervals_into_buffer (tmp_interval1, end2 - len1,
len1, current_buffer, 0);
graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
else
/* Second region smaller than first. */
{
+ USE_SAFE_ALLOCA;
+
record_change (start1, (end2 - start1));
modify_region (current_buffer, start1, end2);
Qnil, Qnil);
/* holds region 1 */
- if (len1_byte > 20000)
- temp = (unsigned char *) xmalloc (len1_byte);
- else
- temp = (unsigned char *) alloca (len1_byte);
+ SAFE_ALLOCA (temp, unsigned char *, len1_byte);
start1_addr = BYTE_POS_ADDR (start1_byte);
start2_addr = BYTE_POS_ADDR (start2_byte);
bcopy (start1_addr, temp, len1_byte);
bcopy (start2_addr, start1_addr, len2_byte);
bcopy (start1_addr + len1_byte, start1_addr + len2_byte, len_mid);
bcopy (temp, start1_addr + len2_byte + len_mid, len1_byte);
- if (len1_byte > 20000)
- xfree (temp);
+ SAFE_FREE (len1_byte);
+
graft_intervals_into_buffer (tmp_interval1, end2 - len1,
len1, current_buffer, 0);
graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
transpose_markers (start1, end1, start2, end2,
start1_byte, start1_byte + len1_byte,
start2_byte, start2_byte + len2_byte);
- fix_overlays_in_range (start1, end2);
+ fix_start_end_in_overlays (start1, end2);
}
return Qnil;