Mercurial > emacs
comparison src/coding.c @ 19285:af3d00fde172
(Fset_terminal_coding_system_internal): Set
CODING_FLAG_ISO_SAFE in terminal_coding.flags.
(ENCODE_ISO_CHARACTER_DIMENSION1): Check
CODING_SPEC_ISO_EXPECTED_CHARSETS.
(ENCODE_ISO_CHARACTER_DIMENSION2): Likewise.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Sun, 10 Aug 1997 05:54:48 +0000 |
| parents | e755044718ee |
| children | d9374f5ebd3a |
comparison
equal
deleted
inserted
replaced
| 19284:dd1d7096f59d | 19285:af3d00fde172 |
|---|---|
| 1180 /* Produce codes for a DIMENSION1 character whose character set is | 1180 /* Produce codes for a DIMENSION1 character whose character set is |
| 1181 CHARSET and whose position-code is C1. Designation and invocation | 1181 CHARSET and whose position-code is C1. Designation and invocation |
| 1182 sequences are also produced in advance if necessary. */ | 1182 sequences are also produced in advance if necessary. */ |
| 1183 | 1183 |
| 1184 | 1184 |
| 1185 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ | 1185 #define ENCODE_ISO_CHARACTER_DIMENSION1(charset, c1) \ |
| 1186 do { \ | 1186 do { \ |
| 1187 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \ | 1187 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \ |
| 1188 { \ | 1188 { \ |
| 1189 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ | 1189 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ |
| 1190 *dst++ = c1 & 0x7F; \ | 1190 *dst++ = c1 & 0x7F; \ |
| 1191 else \ | 1191 else \ |
| 1192 *dst++ = c1 | 0x80; \ | 1192 *dst++ = c1 | 0x80; \ |
| 1193 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \ | 1193 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \ |
| 1194 break; \ | 1194 break; \ |
| 1195 } \ | 1195 } \ |
| 1196 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \ | 1196 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \ |
| 1197 { \ | 1197 { \ |
| 1198 *dst++ = c1 & 0x7F; \ | 1198 *dst++ = c1 & 0x7F; \ |
| 1199 break; \ | 1199 break; \ |
| 1200 } \ | 1200 } \ |
| 1201 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \ | 1201 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \ |
| 1202 { \ | 1202 { \ |
| 1203 *dst++ = c1 | 0x80; \ | 1203 *dst++ = c1 | 0x80; \ |
| 1204 break; \ | 1204 break; \ |
| 1205 } \ | 1205 } \ |
| 1206 else if (coding->flags & CODING_FLAG_ISO_SAFE \ | 1206 else if (coding->flags & CODING_FLAG_ISO_SAFE \ |
| 1207 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) \ | 1207 && !CODING_SPEC_ISO_EXPECTED_CHARSETS (coding)[charset]) \ |
| 1208 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)) \ | 1208 { \ |
| 1209 { \ | 1209 /* We should not encode this character, instead produce one or \ |
| 1210 /* We should not encode this character, instead produce one or \ | 1210 two `?'s. */ \ |
| 1211 two `?'s. */ \ | 1211 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ |
| 1212 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ | 1212 if (CHARSET_WIDTH (charset) == 2) \ |
| 1213 if (CHARSET_WIDTH (charset) == 2) \ | 1213 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ |
| 1214 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ | 1214 break; \ |
| 1215 break; \ | 1215 } \ |
| 1216 } \ | 1216 else \ |
| 1217 else \ | 1217 /* Since CHARSET is not yet invoked to any graphic planes, we \ |
| 1218 /* Since CHARSET is not yet invoked to any graphic planes, we \ | 1218 must invoke it, or, at first, designate it to some graphic \ |
| 1219 must invoke it, or, at first, designate it to some graphic \ | 1219 register. Then repeat the loop to actually produce the \ |
| 1220 register. Then repeat the loop to actually produce the \ | 1220 character. */ \ |
| 1221 character. */ \ | 1221 dst = encode_invocation_designation (charset, coding, dst); \ |
| 1222 dst = encode_invocation_designation (charset, coding, dst); \ | |
| 1223 } while (1) | 1222 } while (1) |
| 1224 | 1223 |
| 1225 /* Produce codes for a DIMENSION2 character whose character set is | 1224 /* Produce codes for a DIMENSION2 character whose character set is |
| 1226 CHARSET and whose position-codes are C1 and C2. Designation and | 1225 CHARSET and whose position-codes are C1 and C2. Designation and |
| 1227 invocation codes are also produced in advance if necessary. */ | 1226 invocation codes are also produced in advance if necessary. */ |
| 1228 | 1227 |
| 1229 #define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2) \ | 1228 #define ENCODE_ISO_CHARACTER_DIMENSION2(charset, c1, c2) \ |
| 1230 do { \ | 1229 do { \ |
| 1231 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \ | 1230 if (CODING_SPEC_ISO_SINGLE_SHIFTING (coding)) \ |
| 1232 { \ | 1231 { \ |
| 1233 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ | 1232 if (coding->flags & CODING_FLAG_ISO_SEVEN_BITS) \ |
| 1234 *dst++ = c1 & 0x7F, *dst++ = c2 & 0x7F; \ | 1233 *dst++ = c1 & 0x7F, *dst++ = c2 & 0x7F; \ |
| 1235 else \ | 1234 else \ |
| 1236 *dst++ = c1 | 0x80, *dst++ = c2 | 0x80; \ | 1235 *dst++ = c1 | 0x80, *dst++ = c2 | 0x80; \ |
| 1237 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \ | 1236 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; \ |
| 1238 break; \ | 1237 break; \ |
| 1239 } \ | 1238 } \ |
| 1240 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \ | 1239 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 0)) \ |
| 1241 { \ | 1240 { \ |
| 1242 *dst++ = c1 & 0x7F, *dst++= c2 & 0x7F; \ | 1241 *dst++ = c1 & 0x7F, *dst++= c2 & 0x7F; \ |
| 1243 break; \ | 1242 break; \ |
| 1244 } \ | 1243 } \ |
| 1245 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \ | 1244 else if (charset == CODING_SPEC_ISO_PLANE_CHARSET (coding, 1)) \ |
| 1246 { \ | 1245 { \ |
| 1247 *dst++ = c1 | 0x80, *dst++= c2 | 0x80; \ | 1246 *dst++ = c1 | 0x80, *dst++= c2 | 0x80; \ |
| 1248 break; \ | 1247 break; \ |
| 1249 } \ | 1248 } \ |
| 1250 else if (coding->flags & CODING_FLAG_ISO_SAFE \ | 1249 else if (coding->flags & CODING_FLAG_ISO_SAFE \ |
| 1251 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) \ | 1250 && !CODING_SPEC_ISO_EXPECTED_CHARSETS (coding)[charset]) \ |
| 1252 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)) \ | 1251 { \ |
| 1253 { \ | 1252 /* We should not encode this character, instead produce one or \ |
| 1254 /* We should not encode this character, instead produce one or \ | 1253 two `?'s. */ \ |
| 1255 two `?'s. */ \ | 1254 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ |
| 1256 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ | 1255 if (CHARSET_WIDTH (charset) == 2) \ |
| 1257 if (CHARSET_WIDTH (charset) == 2) \ | 1256 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ |
| 1258 *dst++ = CODING_INHIBIT_CHARACTER_SUBSTITUTION; \ | 1257 break; \ |
| 1259 break; \ | 1258 } \ |
| 1260 } \ | 1259 else \ |
| 1261 else \ | 1260 /* Since CHARSET is not yet invoked to any graphic planes, we \ |
| 1262 /* Since CHARSET is not yet invoked to any graphic planes, we \ | 1261 must invoke it, or, at first, designate it to some graphic \ |
| 1263 must invoke it, or, at first, designate it to some graphic \ | 1262 register. Then repeat the loop to actually produce the \ |
| 1264 register. Then repeat the loop to actually produce the \ | 1263 character. */ \ |
| 1265 character. */ \ | 1264 dst = encode_invocation_designation (charset, coding, dst); \ |
| 1266 dst = encode_invocation_designation (charset, coding, dst); \ | |
| 1267 } while (1) | 1265 } while (1) |
| 1268 | 1266 |
| 1269 #define ENCODE_ISO_CHARACTER(charset, c1, c2) \ | 1267 #define ENCODE_ISO_CHARACTER(charset, c1, c2) \ |
| 1270 do { \ | 1268 do { \ |
| 1271 int c_alt, charset_alt; \ | 1269 int c_alt, charset_alt; \ |
| 2378 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0; | 2376 CODING_SPEC_ISO_INVOCATION (coding, 0) = 0; |
| 2379 /* Invoke graphic register 1 to plane 1 if we can use full 8-bit. */ | 2377 /* Invoke graphic register 1 to plane 1 if we can use full 8-bit. */ |
| 2380 CODING_SPEC_ISO_INVOCATION (coding, 1) | 2378 CODING_SPEC_ISO_INVOCATION (coding, 1) |
| 2381 = (coding->flags & CODING_FLAG_ISO_SEVEN_BITS ? -1 : 1); | 2379 = (coding->flags & CODING_FLAG_ISO_SEVEN_BITS ? -1 : 1); |
| 2382 /* Not single shifting at first. */ | 2380 /* Not single shifting at first. */ |
| 2383 CODING_SPEC_ISO_SINGLE_SHIFTING(coding) = 0; | 2381 CODING_SPEC_ISO_SINGLE_SHIFTING (coding) = 0; |
| 2384 /* Beginning of buffer should also be regarded as bol. */ | 2382 /* Beginning of buffer should also be regarded as bol. */ |
| 2385 CODING_SPEC_ISO_BOL(coding) = 1; | 2383 CODING_SPEC_ISO_BOL (coding) = 1; |
| 2386 | 2384 |
| 2387 /* Checks FLAGS[REG] (REG = 0, 1, 2 3) and decide designations. | 2385 /* Checks FLAGS[REG] (REG = 0, 1, 2 3) and decide designations. |
| 2388 FLAGS[REG] can be one of below: | 2386 FLAGS[REG] can be one of below: |
| 2389 integer CHARSET: CHARSET occupies register I, | 2387 integer CHARSET: CHARSET occupies register I, |
| 2390 t: designate nothing to REG initially, but can be used | 2388 t: designate nothing to REG initially, but can be used |
| 2395 if an element is t, REG can be used by any charset, | 2393 if an element is t, REG can be used by any charset, |
| 2396 nil: REG is never used. */ | 2394 nil: REG is never used. */ |
| 2397 for (charset = 0; charset <= MAX_CHARSET; charset++) | 2395 for (charset = 0; charset <= MAX_CHARSET; charset++) |
| 2398 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | 2396 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
| 2399 = CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION; | 2397 = CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION; |
| 2398 bzero (CODING_SPEC_ISO_EXPECTED_CHARSETS (coding), MAX_CHARSET + 1); | |
| 2400 for (i = 0; i < 4; i++) | 2399 for (i = 0; i < 4; i++) |
| 2401 { | 2400 { |
| 2402 if (INTEGERP (flags[i]) | 2401 if (INTEGERP (flags[i]) |
| 2403 && (charset = XINT (flags[i]), CHARSET_VALID_P (charset)) | 2402 && (charset = XINT (flags[i]), CHARSET_VALID_P (charset)) |
| 2404 || (charset = get_charset_id (flags[i])) >= 0) | 2403 || (charset = get_charset_id (flags[i])) >= 0) |
| 2405 { | 2404 { |
| 2406 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset; | 2405 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset; |
| 2407 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) = i; | 2406 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) = i; |
| 2407 CODING_SPEC_ISO_EXPECTED_CHARSETS (coding)[charset] = 1; | |
| 2408 } | 2408 } |
| 2409 else if (EQ (flags[i], Qt)) | 2409 else if (EQ (flags[i], Qt)) |
| 2410 { | 2410 { |
| 2411 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; | 2411 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; |
| 2412 default_reg_bits |= 1 << i; | 2412 default_reg_bits |= 1 << i; |
| 2420 CHARSET_VALID_P (charset)) | 2420 CHARSET_VALID_P (charset)) |
| 2421 || (charset = get_charset_id (XCONS (tail)->car)) >= 0) | 2421 || (charset = get_charset_id (XCONS (tail)->car)) >= 0) |
| 2422 { | 2422 { |
| 2423 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset; | 2423 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = charset; |
| 2424 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) =i; | 2424 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) =i; |
| 2425 CODING_SPEC_ISO_EXPECTED_CHARSETS (coding)[charset] = 1; | |
| 2425 } | 2426 } |
| 2426 else | 2427 else |
| 2427 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; | 2428 CODING_SPEC_ISO_INITIAL_DESIGNATION (coding, i) = -1; |
| 2428 tail = XCONS (tail)->cdr; | 2429 tail = XCONS (tail)->cdr; |
| 2429 while (CONSP (tail)) | 2430 while (CONSP (tail)) |
| 2430 { | 2431 { |
| 2431 if (INTEGERP (XCONS (tail)->car) | 2432 if (INTEGERP (XCONS (tail)->car) |
| 2432 && (charset = XINT (XCONS (tail)->car), | 2433 && (charset = XINT (XCONS (tail)->car), |
| 2433 CHARSET_VALID_P (charset)) | 2434 CHARSET_VALID_P (charset)) |
| 2434 || (charset = get_charset_id (XCONS (tail)->car)) >= 0) | 2435 || (charset = get_charset_id (XCONS (tail)->car)) >= 0) |
| 2435 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | 2436 { |
| 2436 = i; | 2437 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
| 2438 = i; | |
| 2439 CODING_SPEC_ISO_EXPECTED_CHARSETS (coding)[charset] | |
| 2440 = 1; | |
| 2441 } | |
| 2437 else if (EQ (XCONS (tail)->car, Qt)) | 2442 else if (EQ (XCONS (tail)->car, Qt)) |
| 2438 default_reg_bits |= 1 << i; | 2443 default_reg_bits |= 1 << i; |
| 2439 tail = XCONS (tail)->cdr; | 2444 tail = XCONS (tail)->cdr; |
| 2440 } | 2445 } |
| 2441 } | 2446 } |
| 2454 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)) | 2459 if (! (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT)) |
| 2455 /* Without any shifting, only REG 0 and 1 can be used. */ | 2460 /* Without any shifting, only REG 0 and 1 can be used. */ |
| 2456 default_reg_bits &= 3; | 2461 default_reg_bits &= 3; |
| 2457 } | 2462 } |
| 2458 | 2463 |
| 2459 if (! (coding->flags & CODING_FLAG_ISO_SAFE)) | 2464 for (charset = 0; charset <= MAX_CHARSET; charset++) |
| 2460 for (charset = 0; charset <= MAX_CHARSET; charset++) | 2465 if (CHARSET_VALID_P (charset) |
| 2461 if (CHARSET_VALID_P (charset) | 2466 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
| 2462 && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | 2467 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)) |
| 2463 == CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)) | 2468 { |
| 2464 { | 2469 /* We have not yet decided where to designate CHARSET. */ |
| 2465 /* We have not yet decided where to designate CHARSET. */ | 2470 int reg_bits = default_reg_bits; |
| 2466 int reg_bits = default_reg_bits; | 2471 |
| 2467 | 2472 if (CHARSET_CHARS (charset) == 96) |
| 2468 if (CHARSET_CHARS (charset) == 96) | 2473 /* A charset of CHARS96 can't be designated to REG 0. */ |
| 2469 /* A charset of CHARS96 can't be designated to REG 0. */ | 2474 reg_bits &= ~1; |
| 2470 reg_bits &= ~1; | 2475 |
| 2471 | 2476 if (reg_bits) |
| 2472 if (reg_bits) | 2477 /* There exist some default graphic register. */ |
| 2473 /* There exist some default graphic register. */ | 2478 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
| 2474 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | 2479 = (reg_bits & 1 |
| 2475 = (reg_bits & 1 | 2480 ? 0 : (reg_bits & 2 ? 1 : (reg_bits & 4 ? 2 : 3))); |
| 2476 ? 0 : (reg_bits & 2 ? 1 : (reg_bits & 4 ? 2 : 3))); | 2481 else |
| 2477 else | 2482 /* We anyway have to designate CHARSET to somewhere. */ |
| 2478 /* We anyway have to designate CHARSET to somewhere. */ | 2483 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) |
| 2479 CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) | 2484 = (CHARSET_CHARS (charset) == 94 |
| 2480 = (CHARSET_CHARS (charset) == 94 | 2485 ? 0 |
| 2481 ? 0 | 2486 : ((coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT |
| 2482 : ((coding->flags & CODING_FLAG_ISO_LOCKING_SHIFT | 2487 || ! coding->flags & CODING_FLAG_ISO_SEVEN_BITS) |
| 2483 || ! coding->flags & CODING_FLAG_ISO_SEVEN_BITS) | 2488 ? 1 |
| 2484 ? 1 | 2489 : (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT |
| 2485 : (coding->flags & CODING_FLAG_ISO_SINGLE_SHIFT | 2490 ? 2 : 0))); |
| 2486 ? 2 : 0))); | 2491 } |
| 2487 } | |
| 2488 } | 2492 } |
| 2489 coding->require_flushing = 1; | 2493 coding->require_flushing = 1; |
| 2490 break; | 2494 break; |
| 2491 | 2495 |
| 2492 case 3: | 2496 case 3: |
| 3583 (coding_system) | 3587 (coding_system) |
| 3584 Lisp_Object coding_system; | 3588 Lisp_Object coding_system; |
| 3585 { | 3589 { |
| 3586 CHECK_SYMBOL (coding_system, 0); | 3590 CHECK_SYMBOL (coding_system, 0); |
| 3587 setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding); | 3591 setup_coding_system (Fcheck_coding_system (coding_system), &terminal_coding); |
| 3592 /* We had better not send unexpected characters to terminal. */ | |
| 3593 terminal_coding.flags |= CODING_FLAG_ISO_SAFE; | |
| 3594 | |
| 3588 return Qnil; | 3595 return Qnil; |
| 3589 } | 3596 } |
| 3590 | 3597 |
| 3591 DEFUN ("set-safe-terminal-coding-system-internal", | 3598 DEFUN ("set-safe-terminal-coding-system-internal", |
| 3592 Fset_safe_terminal_coding_system_internal, | 3599 Fset_safe_terminal_coding_system_internal, |
