aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Steingold2000-07-26 18:41:15 +0000
committerSam Steingold2000-07-26 18:41:15 +0000
commit34a7a2672ad6bbb5751db3e13e99a16f5adde9d3 (patch)
tree191d4b8b7c87c2e4a6bf6c7b2c44543dde31d2e6 /src
parente092928efc27381ad55227b8fc590d792a893f21 (diff)
downloademacs-34a7a2672ad6bbb5751db3e13e99a16f5adde9d3.tar.gz
emacs-34a7a2672ad6bbb5751db3e13e99a16f5adde9d3.zip
new function: float-time
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/editfns.c115
2 files changed, 91 insertions, 35 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 142e84d4dfb..cf9cbcc3158 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12000-07-26 Sam Steingold <sds@gnu.org>
2
3 * editfns.c (lisp_time_argument): Added third argument `usec'.
4 (Ffloat_time): new built-in Lisp function.
5
12000-07-26 Gerd Moellmann <gerd@gnu.org> 62000-07-26 Gerd Moellmann <gerd@gnu.org>
2 7
3 * dispextern.h (GLYPH_FROM_CHAR_GLYPH): Use CHARACTERBITS bits 8 * dispextern.h (GLYPH_FROM_CHAR_GLYPH): Use CHARACTERBITS bits
@@ -118,7 +123,7 @@
118 123
119 * xterm.c (note_mouse_highlight): Process overlays in the right 124 * xterm.c (note_mouse_highlight): Process overlays in the right
120 order of priority. 125 order of priority.
121 126
122 * keyboard.c (show_help_echo, gen_help_event): Extend comments. 127 * keyboard.c (show_help_echo, gen_help_event): Extend comments.
123 128
124 * xterm.c (note_mouse_highlight): If help-echo was found in an 129 * xterm.c (note_mouse_highlight): If help-echo was found in an
@@ -126,7 +131,7 @@
126 found. 131 found.
127 132
128 * window.c (foreach_window_1): Fix typo reversing an if-condition. 133 * window.c (foreach_window_1): Fix typo reversing an if-condition.
129 134
130 * window.c (foreach_window): Instead of a fake variable argument 135 * window.c (foreach_window): Instead of a fake variable argument
131 list, take one USER_DATA argument. 136 list, take one USER_DATA argument.
132 (foreach_window_1): Likewise, and call callback functions with two 137 (foreach_window_1): Likewise, and call callback functions with two
@@ -224,7 +229,7 @@
224 * xfaces.c (face-alternative-font-family-alist): Remove 229 * xfaces.c (face-alternative-font-family-alist): Remove
225 DEFVAR_LISP; staticpro instead. 230 DEFVAR_LISP; staticpro instead.
226 231
227 * xmenu.c (menu_help_callback): Call show_help_echo with 232 * xmenu.c (menu_help_callback): Call show_help_echo with
228 new arguments. 233 new arguments.
229 234
230 * keyboard.c (show_help_echo): Add parameter WINDOW. 235 * keyboard.c (show_help_echo): Add parameter WINDOW.
diff --git a/src/editfns.c b/src/editfns.c
index 218c5f0ef94..a8e5b5594ed 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -122,7 +122,7 @@ init_editfns ()
122 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name); 122 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
123 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid()) 123 Vuser_full_name = Fuser_full_name (NILP (tem)? make_number (geteuid())
124 : Vuser_login_name); 124 : Vuser_login_name);
125 125
126 p = (unsigned char *) getenv ("NAME"); 126 p = (unsigned char *) getenv ("NAME");
127 if (p) 127 if (p)
128 Vuser_full_name = build_string (p); 128 Vuser_full_name = build_string (p);
@@ -685,7 +685,7 @@ save_excursion_save ()
685 return Fcons (Fpoint_marker (), 685 return Fcons (Fpoint_marker (),
686 Fcons (Fcopy_marker (current_buffer->mark, Qnil), 686 Fcons (Fcopy_marker (current_buffer->mark, Qnil),
687 Fcons (visible ? Qt : Qnil, 687 Fcons (visible ? Qt : Qnil,
688 current_buffer->mark_active))); 688 current_buffer->mark_active)));
689} 689}
690 690
691Lisp_Object 691Lisp_Object
@@ -978,7 +978,7 @@ If POS is out of range, the value is nil.")
978 CHECK_NUMBER_COERCE_MARKER (pos, 0); 978 CHECK_NUMBER_COERCE_MARKER (pos, 0);
979 if (XINT (pos) < BEGV || XINT (pos) >= ZV) 979 if (XINT (pos) < BEGV || XINT (pos) >= ZV)
980 return Qnil; 980 return Qnil;
981 981
982 pos_byte = CHAR_TO_BYTE (XINT (pos)); 982 pos_byte = CHAR_TO_BYTE (XINT (pos));
983 } 983 }
984 984
@@ -1104,22 +1104,22 @@ name, or nil if there is no such user.")
1104 Lisp_Object full; 1104 Lisp_Object full;
1105 1105
1106 if (NILP (uid)) 1106 if (NILP (uid))
1107 return Vuser_full_name; 1107 return Vuser_full_name;
1108 else if (NUMBERP (uid)) 1108 else if (NUMBERP (uid))
1109 pw = (struct passwd *) getpwuid (XINT (uid)); 1109 pw = (struct passwd *) getpwuid (XINT (uid));
1110 else if (STRINGP (uid)) 1110 else if (STRINGP (uid))
1111 pw = (struct passwd *) getpwnam (XSTRING (uid)->data); 1111 pw = (struct passwd *) getpwnam (XSTRING (uid)->data);
1112 else 1112 else
1113 error ("Invalid UID specification"); 1113 error ("Invalid UID specification");
1114 1114
1115 if (!pw) 1115 if (!pw)
1116 return Qnil; 1116 return Qnil;
1117 1117
1118 p = (unsigned char *) USER_FULL_NAME; 1118 p = (unsigned char *) USER_FULL_NAME;
1119 /* Chop off everything after the first comma. */ 1119 /* Chop off everything after the first comma. */
1120 q = (unsigned char *) index (p, ','); 1120 q = (unsigned char *) index (p, ',');
1121 full = make_string (p, q ? q - p : strlen (p)); 1121 full = make_string (p, q ? q - p : strlen (p));
1122 1122
1123#ifdef AMPERSAND_FULL_NAME 1123#ifdef AMPERSAND_FULL_NAME
1124 p = XSTRING (full)->data; 1124 p = XSTRING (full)->data;
1125 q = (unsigned char *) index (p, '&'); 1125 q = (unsigned char *) index (p, '&');
@@ -1191,12 +1191,26 @@ resolution finer than a second.")
1191 1191
1192 1192
1193static int 1193static int
1194lisp_time_argument (specified_time, result) 1194lisp_time_argument (specified_time, result, usec)
1195 Lisp_Object specified_time; 1195 Lisp_Object specified_time;
1196 time_t *result; 1196 time_t *result;
1197 int *usec;
1197{ 1198{
1198 if (NILP (specified_time)) 1199 if (NILP (specified_time))
1199 return time (result) != -1; 1200 {
1201 if (usec)
1202 {
1203 EMACS_TIME t;
1204
1205 if (-1 == EMACS_GET_TIME (t))
1206 return 0;
1207 *usec = EMACS_USECS (t);
1208 *result = EMACS_SECS (t);
1209 return 1;
1210 }
1211 else
1212 return time (result) != -1;
1213 }
1200 else 1214 else
1201 { 1215 {
1202 Lisp_Object high, low; 1216 Lisp_Object high, low;
@@ -1204,13 +1218,49 @@ lisp_time_argument (specified_time, result)
1204 CHECK_NUMBER (high, 0); 1218 CHECK_NUMBER (high, 0);
1205 low = Fcdr (specified_time); 1219 low = Fcdr (specified_time);
1206 if (CONSP (low)) 1220 if (CONSP (low))
1207 low = Fcar (low); 1221 {
1222 if (usec)
1223 {
1224 Lisp_Object usec_l = Fcdr (low);
1225 if (CONSP (usec_l))
1226 usec_l = Fcar (usec_l);
1227 if (NILP (usec_l))
1228 *usec = 0;
1229 else
1230 {
1231 CHECK_NUMBER (usec_l, 0);
1232 *usec = XINT (usec_l);
1233 }
1234 }
1235 low = Fcar (low);
1236 }
1237 else if (usec)
1238 *usec = 0;
1208 CHECK_NUMBER (low, 0); 1239 CHECK_NUMBER (low, 0);
1209 *result = (XINT (high) << 16) + (XINT (low) & 0xffff); 1240 *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
1210 return *result >> 16 == XINT (high); 1241 return *result >> 16 == XINT (high);
1211 } 1242 }
1212} 1243}
1213 1244
1245DEFUN ("float-time", Ffloat_time, Sfloat_time, 0, 1, 0,
1246 "Return the current time, as a float number of seconds since the epoch.\n\
1247If an argument is given, it specifies a time to convert to float\n\
1248instead of the current time. The argument should have the forms:\n\
1249 (HIGH . LOW) or (HIGH LOW USEC) or (HIGH LOW . USEC).\n\
1250Thus, you can use times obtained from `current-time'\n\
1251and from `file-attributes'.")
1252 (specified_time)
1253 Lisp_Object specified_time;
1254{
1255 time_t sec;
1256 int usec;
1257
1258 if (! lisp_time_argument (specified_time, &sec, &usec))
1259 error ("Invalid time specification");
1260
1261 return make_float (sec + usec * 0.0000001);
1262}
1263
1214/* Write information into buffer S of size MAXSIZE, according to the 1264/* Write information into buffer S of size MAXSIZE, according to the
1215 FORMAT of length FORMAT_LEN, using time information taken from *TP. 1265 FORMAT of length FORMAT_LEN, using time information taken from *TP.
1216 Default to Universal Time if UT is nonzero, local time otherwise. 1266 Default to Universal Time if UT is nonzero, local time otherwise.
@@ -1328,7 +1378,7 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
1328 1378
1329 CHECK_STRING (format_string, 1); 1379 CHECK_STRING (format_string, 1);
1330 1380
1331 if (! lisp_time_argument (time, &value)) 1381 if (! lisp_time_argument (time, &value, NULL))
1332 error ("Invalid time specification"); 1382 error ("Invalid time specification");
1333 1383
1334 format_string = code_convert_string_norecord (format_string, 1384 format_string = code_convert_string_norecord (format_string,
@@ -1385,8 +1435,8 @@ ZONE is an integer indicating the number of seconds east of Greenwich.\n\
1385 struct tm save_tm; 1435 struct tm save_tm;
1386 struct tm *decoded_time; 1436 struct tm *decoded_time;
1387 Lisp_Object list_args[9]; 1437 Lisp_Object list_args[9];
1388 1438
1389 if (! lisp_time_argument (specified_time, &time_spec)) 1439 if (! lisp_time_argument (specified_time, &time_spec, NULL))
1390 error ("Invalid time specification"); 1440 error ("Invalid time specification");
1391 1441
1392 decoded_time = localtime (&time_spec); 1442 decoded_time = localtime (&time_spec);
@@ -1460,7 +1510,7 @@ If you want them to stand for years in this century, you must do that yourself."
1460 char tzbuf[100]; 1510 char tzbuf[100];
1461 char *tzstring; 1511 char *tzstring;
1462 char **oldenv = environ, **newenv; 1512 char **oldenv = environ, **newenv;
1463 1513
1464 if (EQ (zone, Qt)) 1514 if (EQ (zone, Qt))
1465 tzstring = "UTC0"; 1515 tzstring = "UTC0";
1466 else if (STRINGP (zone)) 1516 else if (STRINGP (zone))
@@ -1475,7 +1525,7 @@ If you want them to stand for years in this century, you must do that yourself."
1475 else 1525 else
1476 error ("Invalid time zone specification"); 1526 error ("Invalid time zone specification");
1477 1527
1478 /* Set TZ before calling mktime; merely adjusting mktime's returned 1528 /* Set TZ before calling mktime; merely adjusting mktime's returned
1479 value doesn't suffice, since that would mishandle leap seconds. */ 1529 value doesn't suffice, since that would mishandle leap seconds. */
1480 set_time_zone_rule (tzstring); 1530 set_time_zone_rule (tzstring);
1481 1531
@@ -1518,7 +1568,7 @@ and from `file-attributes'.")
1518 char buf[30]; 1568 char buf[30];
1519 register char *tem; 1569 register char *tem;
1520 1570
1521 if (! lisp_time_argument (specified_time, &value)) 1571 if (! lisp_time_argument (specified_time, &value, NULL))
1522 value = -1; 1572 value = -1;
1523 tem = (char *) ctime (&value); 1573 tem = (char *) ctime (&value);
1524 1574
@@ -1578,7 +1628,7 @@ the data it can't find.")
1578 struct tm *t; 1628 struct tm *t;
1579 struct tm gmt; 1629 struct tm gmt;
1580 1630
1581 if (lisp_time_argument (specified_time, &value) 1631 if (lisp_time_argument (specified_time, &value, NULL)
1582 && (t = gmtime (&value)) != 0 1632 && (t = gmtime (&value)) != 0
1583 && (gmt = *t, t = localtime (&value)) != 0) 1633 && (gmt = *t, t = localtime (&value)) != 0)
1584 { 1634 {
@@ -1644,7 +1694,7 @@ If TZ is t, use Universal Time.")
1644/* These two values are known to load tz files in buggy implementations, 1694/* These two values are known to load tz files in buggy implementations,
1645 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2. 1695 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
1646 Their values shouldn't matter in non-buggy implementations. 1696 Their values shouldn't matter in non-buggy implementations.
1647 We don't use string literals for these strings, 1697 We don't use string literals for these strings,
1648 since if a string in the environment is in readonly 1698 since if a string in the environment is in readonly
1649 storage, it runs afoul of bugs in SVR4 and Solaris 2.3. 1699 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
1650 See Sun bugs 1113095 and 1114114, ``Timezone routines 1700 See Sun bugs 1113095 and 1114114, ``Timezone routines
@@ -2402,7 +2452,7 @@ Both characters must have the same length of multi-byte form.")
2402 } 2452 }
2403 2453
2404 /* Take care of the case where the new character 2454 /* Take care of the case where the new character
2405 combines with neighboring bytes. */ 2455 combines with neighboring bytes. */
2406 if (maybe_byte_combining 2456 if (maybe_byte_combining
2407 && (maybe_byte_combining == COMBINING_AFTER 2457 && (maybe_byte_combining == COMBINING_AFTER
2408 ? (pos_byte_next < Z_BYTE 2458 ? (pos_byte_next < Z_BYTE
@@ -2433,7 +2483,7 @@ Both characters must have the same length of multi-byte form.")
2433 pos--; 2483 pos--;
2434 else 2484 else
2435 INC_POS (pos_byte_next); 2485 INC_POS (pos_byte_next);
2436 2486
2437 if (! NILP (noundo)) 2487 if (! NILP (noundo))
2438 current_buffer->undo_list = tem; 2488 current_buffer->undo_list = tem;
2439 2489
@@ -2511,7 +2561,7 @@ It returns the number of characters changed.")
2511 if (nc != oc) 2561 if (nc != oc)
2512 { 2562 {
2513 /* Take care of the case where the new character 2563 /* Take care of the case where the new character
2514 combines with neighboring bytes. */ 2564 combines with neighboring bytes. */
2515 if (!ASCII_BYTE_P (nc) 2565 if (!ASCII_BYTE_P (nc)
2516 && (CHAR_HEAD_P (nc) 2566 && (CHAR_HEAD_P (nc)
2517 ? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1)) 2567 ? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte + 1))
@@ -2848,7 +2898,7 @@ properties to add to the result ")
2848 2898
2849 properties = string = Qnil; 2899 properties = string = Qnil;
2850 GCPRO2 (properties, string); 2900 GCPRO2 (properties, string);
2851 2901
2852 /* First argument must be a string. */ 2902 /* First argument must be a string. */
2853 CHECK_STRING (args[0], 0); 2903 CHECK_STRING (args[0], 0);
2854 string = Fcopy_sequence (args[0]); 2904 string = Fcopy_sequence (args[0]);
@@ -3015,7 +3065,7 @@ Use %% to put a single % into the output.")
3015 && *format != 'i' && *format != 'X' && *format != 'c') 3065 && *format != 'i' && *format != 'X' && *format != 'c')
3016 error ("Invalid format operation %%%c", *format); 3066 error ("Invalid format operation %%%c", *format);
3017 3067
3018 thissize = 30; 3068 thissize = 30;
3019 if (*format == 'c' 3069 if (*format == 'c'
3020 && (! SINGLE_BYTE_CHAR_P (XINT (args[n])) 3070 && (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
3021 || XINT (args[n]) == 0)) 3071 || XINT (args[n]) == 0))
@@ -3048,7 +3098,7 @@ Use %% to put a single % into the output.")
3048 args[n] = tem; 3098 args[n] = tem;
3049 goto string; 3099 goto string;
3050 } 3100 }
3051 3101
3052 if (thissize < minlen) 3102 if (thissize < minlen)
3053 thissize = minlen; 3103 thissize = minlen;
3054 3104
@@ -3147,7 +3197,7 @@ Use %% to put a single % into the output.")
3147 info = (struct info *) alloca (nbytes); 3197 info = (struct info *) alloca (nbytes);
3148 bzero (info, nbytes); 3198 bzero (info, nbytes);
3149 } 3199 }
3150 3200
3151 info[n].start = start; 3201 info[n].start = start;
3152 info[n].end = nchars; 3202 info[n].end = nchars;
3153 } 3203 }
@@ -3214,17 +3264,17 @@ Use %% to put a single % into the output.")
3214 /* If the format string has text properties, or any of the string 3264 /* If the format string has text properties, or any of the string
3215 arguments has text properties, set up text properties of the 3265 arguments has text properties, set up text properties of the
3216 result string. */ 3266 result string. */
3217 3267
3218 if (XSTRING (args[0])->intervals || info) 3268 if (XSTRING (args[0])->intervals || info)
3219 { 3269 {
3220 Lisp_Object len, new_len, props; 3270 Lisp_Object len, new_len, props;
3221 struct gcpro gcpro1; 3271 struct gcpro gcpro1;
3222 3272
3223 /* Add text properties from the format string. */ 3273 /* Add text properties from the format string. */
3224 len = make_number (XSTRING (args[0])->size); 3274 len = make_number (XSTRING (args[0])->size);
3225 props = text_property_list (args[0], make_number (0), len, Qnil); 3275 props = text_property_list (args[0], make_number (0), len, Qnil);
3226 GCPRO1 (props); 3276 GCPRO1 (props);
3227 3277
3228 if (CONSP (props)) 3278 if (CONSP (props))
3229 { 3279 {
3230 new_len = make_number (XSTRING (val)->size); 3280 new_len = make_number (XSTRING (val)->size);
@@ -3317,7 +3367,7 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.")
3317 Traverses the entire marker list of the buffer to do so, adding an 3367 Traverses the entire marker list of the buffer to do so, adding an
3318 appropriate amount to some, subtracting from some, and leaving the 3368 appropriate amount to some, subtracting from some, and leaving the
3319 rest untouched. Most of this is copied from adjust_markers in insdel.c. 3369 rest untouched. Most of this is copied from adjust_markers in insdel.c.
3320 3370
3321 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */ 3371 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
3322 3372
3323void 3373void
@@ -3354,7 +3404,7 @@ transpose_markers (start1, end1, start2, end2,
3354 /* The difference between the region's lengths */ 3404 /* The difference between the region's lengths */
3355 diff = (end2 - start2) - (end1 - start1); 3405 diff = (end2 - start2) - (end1 - start1);
3356 diff_byte = (end2_byte - start2_byte) - (end1_byte - start1_byte); 3406 diff_byte = (end2_byte - start2_byte) - (end1_byte - start1_byte);
3357 3407
3358 /* For shifting each marker in a region by the length of the other 3408 /* For shifting each marker in a region by the length of the other
3359 region plus the distance between the regions. */ 3409 region plus the distance between the regions. */
3360 amt1 = (end2 - start2) + (start2 - end1); 3410 amt1 = (end2 - start2) + (start2 - end1);
@@ -3443,7 +3493,7 @@ Transposing beyond buffer boundaries is an error.")
3443 1. Adjacent (contiguous) regions, or separate but equal regions 3493 1. Adjacent (contiguous) regions, or separate but equal regions
3444 (no, really equal, in this case!), or 3494 (no, really equal, in this case!), or
3445 2. Separate regions of unequal size. 3495 2. Separate regions of unequal size.
3446 3496
3447 The worst case is usually No. 2. It means that (aside from 3497 The worst case is usually No. 2. It means that (aside from
3448 potential need for getting the gap out of the way), there also 3498 potential need for getting the gap out of the way), there also
3449 needs to be a shifting of the text between the two regions. So 3499 needs to be a shifting of the text between the two regions. So
@@ -3722,7 +3772,7 @@ functions if all the text being accessed has this property.");
3722 3772
3723 DEFVAR_LISP ("system-name", &Vsystem_name, 3773 DEFVAR_LISP ("system-name", &Vsystem_name,
3724 "The name of the machine Emacs is running on."); 3774 "The name of the machine Emacs is running on.");
3725 3775
3726 DEFVAR_LISP ("user-full-name", &Vuser_full_name, 3776 DEFVAR_LISP ("user-full-name", &Vuser_full_name,
3727 "The full name of the user logged in."); 3777 "The full name of the user logged in.");
3728 3778
@@ -3798,6 +3848,7 @@ functions if all the text being accessed has this property.");
3798 defsubr (&Semacs_pid); 3848 defsubr (&Semacs_pid);
3799 defsubr (&Scurrent_time); 3849 defsubr (&Scurrent_time);
3800 defsubr (&Sformat_time_string); 3850 defsubr (&Sformat_time_string);
3851 defsubr (&Sfloat_time);
3801 defsubr (&Sdecode_time); 3852 defsubr (&Sdecode_time);
3802 defsubr (&Sencode_time); 3853 defsubr (&Sencode_time);
3803 defsubr (&Scurrent_time_string); 3854 defsubr (&Scurrent_time_string);