Mercurial > emacs
comparison src/editfns.c @ 46370:40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
SCHARS, SBYTES, STRING_INTERVALS, SREF, SDATA; explicit size_byte references
left unchanged for now.
author | Ken Raeburn <raeburn@raeburn.org> |
---|---|
date | Mon, 15 Jul 2002 00:00:41 +0000 |
parents | 1fb8f75062c6 |
children | b612fecce4cc |
comparison
equal
deleted
inserted
replaced
46369:dd1d3b1d0053 | 46370:40db0673e6f0 |
---|---|
1200 if (NILP (uid)) | 1200 if (NILP (uid)) |
1201 return Vuser_full_name; | 1201 return Vuser_full_name; |
1202 else if (NUMBERP (uid)) | 1202 else if (NUMBERP (uid)) |
1203 pw = (struct passwd *) getpwuid ((uid_t) XFLOATINT (uid)); | 1203 pw = (struct passwd *) getpwuid ((uid_t) XFLOATINT (uid)); |
1204 else if (STRINGP (uid)) | 1204 else if (STRINGP (uid)) |
1205 pw = (struct passwd *) getpwnam (XSTRING (uid)->data); | 1205 pw = (struct passwd *) getpwnam (SDATA (uid)); |
1206 else | 1206 else |
1207 error ("Invalid UID specification"); | 1207 error ("Invalid UID specification"); |
1208 | 1208 |
1209 if (!pw) | 1209 if (!pw) |
1210 return Qnil; | 1210 return Qnil; |
1213 /* Chop off everything after the first comma. */ | 1213 /* Chop off everything after the first comma. */ |
1214 q = (unsigned char *) index (p, ','); | 1214 q = (unsigned char *) index (p, ','); |
1215 full = make_string (p, q ? q - p : strlen (p)); | 1215 full = make_string (p, q ? q - p : strlen (p)); |
1216 | 1216 |
1217 #ifdef AMPERSAND_FULL_NAME | 1217 #ifdef AMPERSAND_FULL_NAME |
1218 p = XSTRING (full)->data; | 1218 p = SDATA (full); |
1219 q = (unsigned char *) index (p, '&'); | 1219 q = (unsigned char *) index (p, '&'); |
1220 /* Substitute the login name for the &, upcasing the first character. */ | 1220 /* Substitute the login name for the &, upcasing the first character. */ |
1221 if (q) | 1221 if (q) |
1222 { | 1222 { |
1223 register unsigned char *r; | 1223 register unsigned char *r; |
1224 Lisp_Object login; | 1224 Lisp_Object login; |
1225 | 1225 |
1226 login = Fuser_login_name (make_number (pw->pw_uid)); | 1226 login = Fuser_login_name (make_number (pw->pw_uid)); |
1227 r = (unsigned char *) alloca (strlen (p) + XSTRING (login)->size + 1); | 1227 r = (unsigned char *) alloca (strlen (p) + SCHARS (login) + 1); |
1228 bcopy (p, r, q - p); | 1228 bcopy (p, r, q - p); |
1229 r[q - p] = 0; | 1229 r[q - p] = 0; |
1230 strcat (r, XSTRING (login)->data); | 1230 strcat (r, SDATA (login)); |
1231 r[q - p] = UPCASE (r[q - p]); | 1231 r[q - p] = UPCASE (r[q - p]); |
1232 strcat (r, q + 1); | 1232 strcat (r, q + 1); |
1233 full = build_string (r); | 1233 full = build_string (r); |
1234 } | 1234 } |
1235 #endif /* AMPERSAND_FULL_NAME */ | 1235 #endif /* AMPERSAND_FULL_NAME */ |
1248 | 1248 |
1249 char * | 1249 char * |
1250 get_system_name () | 1250 get_system_name () |
1251 { | 1251 { |
1252 if (STRINGP (Vsystem_name)) | 1252 if (STRINGP (Vsystem_name)) |
1253 return (char *) XSTRING (Vsystem_name)->data; | 1253 return (char *) SDATA (Vsystem_name); |
1254 else | 1254 else |
1255 return ""; | 1255 return ""; |
1256 } | 1256 } |
1257 | 1257 |
1258 DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0, | 1258 DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0, |
1477 | 1477 |
1478 format_string = code_convert_string_norecord (format_string, | 1478 format_string = code_convert_string_norecord (format_string, |
1479 Vlocale_coding_system, 1); | 1479 Vlocale_coding_system, 1); |
1480 | 1480 |
1481 /* This is probably enough. */ | 1481 /* This is probably enough. */ |
1482 size = STRING_BYTES (XSTRING (format_string)) * 6 + 50; | 1482 size = SBYTES (format_string) * 6 + 50; |
1483 | 1483 |
1484 tm = ut ? gmtime (&value) : localtime (&value); | 1484 tm = ut ? gmtime (&value) : localtime (&value); |
1485 if (! tm) | 1485 if (! tm) |
1486 error ("Specified time is not representable"); | 1486 error ("Specified time is not representable"); |
1487 | 1487 |
1491 { | 1491 { |
1492 char *buf = (char *) alloca (size + 1); | 1492 char *buf = (char *) alloca (size + 1); |
1493 int result; | 1493 int result; |
1494 | 1494 |
1495 buf[0] = '\1'; | 1495 buf[0] = '\1'; |
1496 result = emacs_memftimeu (buf, size, XSTRING (format_string)->data, | 1496 result = emacs_memftimeu (buf, size, SDATA (format_string), |
1497 STRING_BYTES (XSTRING (format_string)), | 1497 SBYTES (format_string), |
1498 tm, ut); | 1498 tm, ut); |
1499 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0')) | 1499 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0')) |
1500 return code_convert_string_norecord (make_string (buf, result), | 1500 return code_convert_string_norecord (make_string (buf, result), |
1501 Vlocale_coding_system, 0); | 1501 Vlocale_coding_system, 0); |
1502 | 1502 |
1503 /* If buffer was too small, make it bigger and try again. */ | 1503 /* If buffer was too small, make it bigger and try again. */ |
1504 result = emacs_memftimeu (NULL, (size_t) -1, | 1504 result = emacs_memftimeu (NULL, (size_t) -1, |
1505 XSTRING (format_string)->data, | 1505 SDATA (format_string), |
1506 STRING_BYTES (XSTRING (format_string)), | 1506 SBYTES (format_string), |
1507 tm, ut); | 1507 tm, ut); |
1508 size = result + 1; | 1508 size = result + 1; |
1509 } | 1509 } |
1510 } | 1510 } |
1511 | 1511 |
1608 char **oldenv = environ, **newenv; | 1608 char **oldenv = environ, **newenv; |
1609 | 1609 |
1610 if (EQ (zone, Qt)) | 1610 if (EQ (zone, Qt)) |
1611 tzstring = "UTC0"; | 1611 tzstring = "UTC0"; |
1612 else if (STRINGP (zone)) | 1612 else if (STRINGP (zone)) |
1613 tzstring = (char *) XSTRING (zone)->data; | 1613 tzstring = (char *) SDATA (zone); |
1614 else if (INTEGERP (zone)) | 1614 else if (INTEGERP (zone)) |
1615 { | 1615 { |
1616 int abszone = abs (XINT (zone)); | 1616 int abszone = abs (XINT (zone)); |
1617 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0), | 1617 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0), |
1618 abszone / (60*60), (abszone/60) % 60, abszone % 60); | 1618 abszone / (60*60), (abszone/60) % 60, abszone % 60); |
1786 else if (EQ (tz, Qt)) | 1786 else if (EQ (tz, Qt)) |
1787 tzstring = "UTC0"; | 1787 tzstring = "UTC0"; |
1788 else | 1788 else |
1789 { | 1789 { |
1790 CHECK_STRING (tz); | 1790 CHECK_STRING (tz); |
1791 tzstring = (char *) XSTRING (tz)->data; | 1791 tzstring = (char *) SDATA (tz); |
1792 } | 1792 } |
1793 | 1793 |
1794 set_time_zone_rule (tzstring); | 1794 set_time_zone_rule (tzstring); |
1795 if (environbuf) | 1795 if (environbuf) |
1796 free (environbuf); | 1796 free (environbuf); |
1932 (*insert_func) (str, len); | 1932 (*insert_func) (str, len); |
1933 } | 1933 } |
1934 else if (STRINGP (val)) | 1934 else if (STRINGP (val)) |
1935 { | 1935 { |
1936 (*insert_from_string_func) (val, 0, 0, | 1936 (*insert_from_string_func) (val, 0, 0, |
1937 XSTRING (val)->size, | 1937 SCHARS (val), |
1938 STRING_BYTES (XSTRING (val)), | 1938 SBYTES (val), |
1939 inherit); | 1939 inherit); |
1940 } | 1940 } |
1941 else | 1941 else |
1942 { | 1942 { |
1943 val = wrong_type_argument (Qchar_or_string_p, val); | 1943 val = wrong_type_argument (Qchar_or_string_p, val); |
2144 | 2144 |
2145 if (! NILP (current_buffer->enable_multibyte_characters)) | 2145 if (! NILP (current_buffer->enable_multibyte_characters)) |
2146 result = make_uninit_multibyte_string (end - start, end_byte - start_byte); | 2146 result = make_uninit_multibyte_string (end - start, end_byte - start_byte); |
2147 else | 2147 else |
2148 result = make_uninit_string (end - start); | 2148 result = make_uninit_string (end - start); |
2149 bcopy (BYTE_POS_ADDR (start_byte), XSTRING (result)->data, | 2149 bcopy (BYTE_POS_ADDR (start_byte), SDATA (result), |
2150 end_byte - start_byte); | 2150 end_byte - start_byte); |
2151 | 2151 |
2152 /* If desired, update and copy the text properties. */ | 2152 /* If desired, update and copy the text properties. */ |
2153 if (props) | 2153 if (props) |
2154 { | 2154 { |
2657 int multibyte = !NILP (current_buffer->enable_multibyte_characters); | 2657 int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
2658 | 2658 |
2659 validate_region (&start, &end); | 2659 validate_region (&start, &end); |
2660 CHECK_STRING (table); | 2660 CHECK_STRING (table); |
2661 | 2661 |
2662 size = STRING_BYTES (XSTRING (table)); | 2662 size = SBYTES (table); |
2663 tt = XSTRING (table)->data; | 2663 tt = SDATA (table); |
2664 | 2664 |
2665 pos_byte = CHAR_TO_BYTE (XINT (start)); | 2665 pos_byte = CHAR_TO_BYTE (XINT (start)); |
2666 stop = CHAR_TO_BYTE (XINT (end)); | 2666 stop = CHAR_TO_BYTE (XINT (end)); |
2667 modify_region (current_buffer, XINT (start), XINT (end)); | 2667 modify_region (current_buffer, XINT (start), XINT (end)); |
2668 pos = XINT (start); | 2668 pos = XINT (start); |
2927 } | 2927 } |
2928 else | 2928 else |
2929 { | 2929 { |
2930 register Lisp_Object val; | 2930 register Lisp_Object val; |
2931 val = Fformat (nargs, args); | 2931 val = Fformat (nargs, args); |
2932 message3 (val, STRING_BYTES (XSTRING (val)), STRING_MULTIBYTE (val)); | 2932 message3 (val, SBYTES (val), STRING_MULTIBYTE (val)); |
2933 return val; | 2933 return val; |
2934 } | 2934 } |
2935 } | 2935 } |
2936 | 2936 |
2937 DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0, | 2937 DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0, |
2977 if (! message_text) | 2977 if (! message_text) |
2978 { | 2978 { |
2979 message_text = (char *)xmalloc (80); | 2979 message_text = (char *)xmalloc (80); |
2980 message_length = 80; | 2980 message_length = 80; |
2981 } | 2981 } |
2982 if (STRING_BYTES (XSTRING (val)) > message_length) | 2982 if (SBYTES (val) > message_length) |
2983 { | 2983 { |
2984 message_length = STRING_BYTES (XSTRING (val)); | 2984 message_length = SBYTES (val); |
2985 message_text = (char *)xrealloc (message_text, message_length); | 2985 message_text = (char *)xrealloc (message_text, message_length); |
2986 } | 2986 } |
2987 bcopy (XSTRING (val)->data, message_text, STRING_BYTES (XSTRING (val))); | 2987 bcopy (SDATA (val), message_text, SBYTES (val)); |
2988 message2 (message_text, STRING_BYTES (XSTRING (val)), | 2988 message2 (message_text, SBYTES (val), |
2989 STRING_MULTIBYTE (val)); | 2989 STRING_MULTIBYTE (val)); |
2990 return val; | 2990 return val; |
2991 } | 2991 } |
2992 } | 2992 } |
2993 #ifdef HAVE_MENUS | 2993 #ifdef HAVE_MENUS |
3056 CHECK_SYMBOL (args[i]); | 3056 CHECK_SYMBOL (args[i]); |
3057 properties = Fcons (args[i], Fcons (args[i + 1], properties)); | 3057 properties = Fcons (args[i], Fcons (args[i + 1], properties)); |
3058 } | 3058 } |
3059 | 3059 |
3060 Fadd_text_properties (make_number (0), | 3060 Fadd_text_properties (make_number (0), |
3061 make_number (XSTRING (string)->size), | 3061 make_number (SCHARS (string)), |
3062 properties, string); | 3062 properties, string); |
3063 RETURN_UNGCPRO (string); | 3063 RETURN_UNGCPRO (string); |
3064 } | 3064 } |
3065 | 3065 |
3066 | 3066 |
3067 /* Number of bytes that STRING will occupy when put into the result. | 3067 /* Number of bytes that STRING will occupy when put into the result. |
3068 MULTIBYTE is nonzero if the result should be multibyte. */ | 3068 MULTIBYTE is nonzero if the result should be multibyte. */ |
3069 | 3069 |
3070 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \ | 3070 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \ |
3071 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \ | 3071 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \ |
3072 ? count_size_as_multibyte (XSTRING (STRING)->data, \ | 3072 ? count_size_as_multibyte (SDATA (STRING), SBYTES (STRING)) \ |
3073 STRING_BYTES (XSTRING (STRING))) \ | 3073 : SBYTES (STRING)) |
3074 : STRING_BYTES (XSTRING (STRING))) | |
3075 | 3074 |
3076 DEFUN ("format", Fformat, Sformat, 1, MANY, 0, | 3075 DEFUN ("format", Fformat, Sformat, 1, MANY, 0, |
3077 doc: /* Format a string out of a control-string and arguments. | 3076 doc: /* Format a string out of a control-string and arguments. |
3078 The first argument is a control string. | 3077 The first argument is a control string. |
3079 The other arguments are substituted into it to make the result, a string. | 3078 The other arguments are substituted into it to make the result, a string. |
3131 | 3130 |
3132 /* If we start out planning a unibyte result, | 3131 /* If we start out planning a unibyte result, |
3133 and later find it has to be multibyte, we jump back to retry. */ | 3132 and later find it has to be multibyte, we jump back to retry. */ |
3134 retry: | 3133 retry: |
3135 | 3134 |
3136 format = XSTRING (args[0])->data; | 3135 format = SDATA (args[0]); |
3137 end = format + STRING_BYTES (XSTRING (args[0])); | 3136 end = format + SBYTES (args[0]); |
3138 longest_format = 0; | 3137 longest_format = 0; |
3139 | 3138 |
3140 /* Make room in result for all the non-%-codes in the control string. */ | 3139 /* Make room in result for all the non-%-codes in the control string. */ |
3141 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]); | 3140 total = 5 + CONVERTED_BYTE_SIZE (multibyte, args[0]); |
3142 | 3141 |
3253 { | 3252 { |
3254 multibyte = 1; | 3253 multibyte = 1; |
3255 goto retry; | 3254 goto retry; |
3256 } | 3255 } |
3257 args[n] = Fchar_to_string (args[n]); | 3256 args[n] = Fchar_to_string (args[n]); |
3258 thissize = STRING_BYTES (XSTRING (args[n])); | 3257 thissize = SBYTES (args[n]); |
3259 } | 3258 } |
3260 } | 3259 } |
3261 else if (FLOATP (args[n]) && *format != 's') | 3260 else if (FLOATP (args[n]) && *format != 's') |
3262 { | 3261 { |
3263 if (! (*format == 'e' || *format == 'f' || *format == 'g')) | 3262 if (! (*format == 'e' || *format == 'f' || *format == 'g')) |
3301 p = buf; | 3300 p = buf; |
3302 nchars = 0; | 3301 nchars = 0; |
3303 n = 0; | 3302 n = 0; |
3304 | 3303 |
3305 /* Scan the format and store result in BUF. */ | 3304 /* Scan the format and store result in BUF. */ |
3306 format = XSTRING (args[0])->data; | 3305 format = SDATA (args[0]); |
3307 maybe_combine_byte = 0; | 3306 maybe_combine_byte = 0; |
3308 while (format != end) | 3307 while (format != end) |
3309 { | 3308 { |
3310 if (*format == '%') | 3309 if (*format == '%') |
3311 { | 3310 { |
3351 | 3350 |
3352 if (p > buf | 3351 if (p > buf |
3353 && multibyte | 3352 && multibyte |
3354 && !ASCII_BYTE_P (*((unsigned char *) p - 1)) | 3353 && !ASCII_BYTE_P (*((unsigned char *) p - 1)) |
3355 && STRING_MULTIBYTE (args[n]) | 3354 && STRING_MULTIBYTE (args[n]) |
3356 && !CHAR_HEAD_P (XSTRING (args[n])->data[0])) | 3355 && !CHAR_HEAD_P (SREF (args[n], 0))) |
3357 maybe_combine_byte = 1; | 3356 maybe_combine_byte = 1; |
3358 nbytes = copy_text (XSTRING (args[n])->data, p, | 3357 nbytes = copy_text (SDATA (args[n]), p, |
3359 STRING_BYTES (XSTRING (args[n])), | 3358 SBYTES (args[n]), |
3360 STRING_MULTIBYTE (args[n]), multibyte); | 3359 STRING_MULTIBYTE (args[n]), multibyte); |
3361 p += nbytes; | 3360 p += nbytes; |
3362 nchars += XSTRING (args[n])->size; | 3361 nchars += SCHARS (args[n]); |
3363 end = nchars; | 3362 end = nchars; |
3364 | 3363 |
3365 if (negative) | 3364 if (negative) |
3366 while (padding-- > 0) | 3365 while (padding-- > 0) |
3367 { | 3366 { |
3369 nchars++; | 3368 nchars++; |
3370 } | 3369 } |
3371 | 3370 |
3372 /* If this argument has text properties, record where | 3371 /* If this argument has text properties, record where |
3373 in the result string it appears. */ | 3372 in the result string it appears. */ |
3374 if (XSTRING (args[n])->intervals) | 3373 if (STRING_INTERVALS (args[n])) |
3375 { | 3374 { |
3376 if (!info) | 3375 if (!info) |
3377 { | 3376 { |
3378 int nbytes = nargs * sizeof *info; | 3377 int nbytes = nargs * sizeof *info; |
3379 info = (struct info *) alloca (nbytes); | 3378 info = (struct info *) alloca (nbytes); |
3448 | 3447 |
3449 /* If the format string has text properties, or any of the string | 3448 /* If the format string has text properties, or any of the string |
3450 arguments has text properties, set up text properties of the | 3449 arguments has text properties, set up text properties of the |
3451 result string. */ | 3450 result string. */ |
3452 | 3451 |
3453 if (XSTRING (args[0])->intervals || info) | 3452 if (STRING_INTERVALS (args[0]) || info) |
3454 { | 3453 { |
3455 Lisp_Object len, new_len, props; | 3454 Lisp_Object len, new_len, props; |
3456 struct gcpro gcpro1; | 3455 struct gcpro gcpro1; |
3457 | 3456 |
3458 /* Add text properties from the format string. */ | 3457 /* Add text properties from the format string. */ |
3459 len = make_number (XSTRING (args[0])->size); | 3458 len = make_number (SCHARS (args[0])); |
3460 props = text_property_list (args[0], make_number (0), len, Qnil); | 3459 props = text_property_list (args[0], make_number (0), len, Qnil); |
3461 GCPRO1 (props); | 3460 GCPRO1 (props); |
3462 | 3461 |
3463 if (CONSP (props)) | 3462 if (CONSP (props)) |
3464 { | 3463 { |
3465 new_len = make_number (XSTRING (val)->size); | 3464 new_len = make_number (SCHARS (val)); |
3466 extend_property_ranges (props, len, new_len); | 3465 extend_property_ranges (props, len, new_len); |
3467 add_text_properties_from_list (val, props, make_number (0)); | 3466 add_text_properties_from_list (val, props, make_number (0)); |
3468 } | 3467 } |
3469 | 3468 |
3470 /* Add text properties from arguments. */ | 3469 /* Add text properties from arguments. */ |
3471 if (info) | 3470 if (info) |
3472 for (n = 1; n < nargs; ++n) | 3471 for (n = 1; n < nargs; ++n) |
3473 if (info[n].end) | 3472 if (info[n].end) |
3474 { | 3473 { |
3475 len = make_number (XSTRING (args[n])->size); | 3474 len = make_number (SCHARS (args[n])); |
3476 new_len = make_number (info[n].end - info[n].start); | 3475 new_len = make_number (info[n].end - info[n].start); |
3477 props = text_property_list (args[n], make_number (0), len, Qnil); | 3476 props = text_property_list (args[n], make_number (0), len, Qnil); |
3478 extend_property_ranges (props, len, new_len); | 3477 extend_property_ranges (props, len, new_len); |
3479 /* If successive arguments have properites, be sure that | 3478 /* If successive arguments have properites, be sure that |
3480 the value of `composition' property be the copy. */ | 3479 the value of `composition' property be the copy. */ |