summaryrefslogtreecommitdiffstats
path: root/Modules/cjkcodecs/_codecs_iso2022.c
diff options
context:
space:
mode:
authorHye-Shik Chang <hyeshik@gmail.com>2006-03-04 16:08:19 (GMT)
committerHye-Shik Chang <hyeshik@gmail.com>2006-03-04 16:08:19 (GMT)
commit4b96c1384e008218bdfeb9e271a094b1ab8484d3 (patch)
tree8ca29d17d54e6c671408e427279a7acc3082a4bf /Modules/cjkcodecs/_codecs_iso2022.c
parentad9afcf213f5a69d1a43616cbd445126e8a7d6cb (diff)
downloadcpython-4b96c1384e008218bdfeb9e271a094b1ab8484d3.zip
cpython-4b96c1384e008218bdfeb9e271a094b1ab8484d3.tar.gz
cpython-4b96c1384e008218bdfeb9e271a094b1ab8484d3.tar.bz2
- Modernize code to use Py_ssize_t more intensively.
- Do some minor code clean-ups.
Diffstat (limited to 'Modules/cjkcodecs/_codecs_iso2022.c')
-rw-r--r--Modules/cjkcodecs/_codecs_iso2022.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/Modules/cjkcodecs/_codecs_iso2022.c b/Modules/cjkcodecs/_codecs_iso2022.c
index 5cee8ce..1e52c34 100644
--- a/Modules/cjkcodecs/_codecs_iso2022.c
+++ b/Modules/cjkcodecs/_codecs_iso2022.c
@@ -2,7 +2,6 @@
* _codecs_iso2022.c: Codecs collection for ISO-2022 encodings.
*
* Written by Hye-Shik Chang <perky@FreeBSD.org>
- * $CJKCodecs: _codecs_iso2022.c,v 1.22 2004/08/19 17:08:13 perky Exp $
*/
#define USING_IMPORTED_MAPS
@@ -104,7 +103,7 @@
typedef int (*iso2022_init_func)(void);
typedef ucs4_t (*iso2022_decode_func)(const unsigned char *data);
-typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, int *length);
+typedef DBCHAR (*iso2022_encode_func)(const ucs4_t *data, Py_ssize_t *length);
struct iso2022_designation {
unsigned char mark;
@@ -160,7 +159,7 @@ ENCODER(iso2022)
const struct iso2022_designation *dsg;
DBCHAR encoded;
ucs4_t c = **inbuf;
- int insize;
+ Py_ssize_t insize;
if (c < 0x80) {
if (STATE_G0 != CHARSET_ASCII) {
@@ -183,7 +182,7 @@ ENCODER(iso2022)
encoded = MAP_UNMAPPABLE;
for (dsg = CONFIG_DESIGNATIONS; dsg->mark; dsg++) {
- int length = 1;
+ Py_ssize_t length = 1;
encoded = dsg->encoder(&c, &length);
if (encoded == MAP_MULTIPLE_AVAIL) {
/* this implementation won't work for pair
@@ -300,12 +299,12 @@ DECODER_RESET(iso2022)
return 0;
}
-static int
+static Py_ssize_t
iso2022processesc(const void *config, MultibyteCodec_State *state,
- const unsigned char **inbuf, size_t *inleft)
+ const unsigned char **inbuf, Py_ssize_t *inleft)
{
unsigned char charset, designation;
- size_t i, esclen;
+ Py_ssize_t i, esclen;
for (i = 1;i < MAX_ESCSEQLEN;i++) {
if (i >= *inleft)
@@ -388,10 +387,10 @@ iso2022processesc(const void *config, MultibyteCodec_State *state,
else if ((c) == 0xa2) (assi) = 0x2019; \
else if ((c) == 0xaf) (assi) = 0x2015;
-static int
+static Py_ssize_t
iso2022processg2(const void *config, MultibyteCodec_State *state,
- const unsigned char **inbuf, size_t *inleft,
- Py_UNICODE **outbuf, size_t *outleft)
+ const unsigned char **inbuf, Py_ssize_t *inleft,
+ Py_UNICODE **outbuf, Py_ssize_t *outleft)
{
/* not written to use encoder, decoder functions because only few
* encodings use G2 designations in CJKCodecs */
@@ -425,7 +424,7 @@ DECODER(iso2022)
while (inleft > 0) {
unsigned char c = IN1;
- int err;
+ Py_ssize_t err;
if (STATE_GETFLAG(F_ESCTHROUGHOUT)) {
/* ESC throughout mode:
@@ -589,7 +588,7 @@ ksx1001_decoder(const unsigned char *data)
}
static DBCHAR
-ksx1001_encoder(const ucs4_t *data, int *length)
+ksx1001_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
assert(*length == 1);
@@ -625,7 +624,7 @@ jisx0208_decoder(const unsigned char *data)
}
static DBCHAR
-jisx0208_encoder(const ucs4_t *data, int *length)
+jisx0208_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
assert(*length == 1);
@@ -662,7 +661,7 @@ jisx0212_decoder(const unsigned char *data)
}
static DBCHAR
-jisx0212_encoder(const ucs4_t *data, int *length)
+jisx0212_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
assert(*length == 1);
@@ -760,7 +759,7 @@ jisx0213_2004_2_decoder(const unsigned char *data)
}
static DBCHAR
-jisx0213_encoder(const ucs4_t *data, int *length, void *config)
+jisx0213_encoder(const ucs4_t *data, Py_ssize_t *length, void *config)
{
DBCHAR coded;
@@ -814,7 +813,7 @@ jisx0213_encoder(const ucs4_t *data, int *length, void *config)
}
static DBCHAR
-jisx0213_2000_1_encoder(const ucs4_t *data, int *length)
+jisx0213_2000_1_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded = jisx0213_encoder(data, length, (void *)2000);
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -826,10 +825,10 @@ jisx0213_2000_1_encoder(const ucs4_t *data, int *length)
}
static DBCHAR
-jisx0213_2000_1_encoder_paironly(const ucs4_t *data, int *length)
+jisx0213_2000_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
- int ilength = *length;
+ Py_ssize_t ilength = *length;
coded = jisx0213_encoder(data, length, (void *)2000);
switch (ilength) {
@@ -849,7 +848,7 @@ jisx0213_2000_1_encoder_paironly(const ucs4_t *data, int *length)
}
static DBCHAR
-jisx0213_2000_2_encoder(const ucs4_t *data, int *length)
+jisx0213_2000_2_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded = jisx0213_encoder(data, length, (void *)2000);
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -861,7 +860,7 @@ jisx0213_2000_2_encoder(const ucs4_t *data, int *length)
}
static DBCHAR
-jisx0213_2004_1_encoder(const ucs4_t *data, int *length)
+jisx0213_2004_1_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded = jisx0213_encoder(data, length, NULL);
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -873,10 +872,10 @@ jisx0213_2004_1_encoder(const ucs4_t *data, int *length)
}
static DBCHAR
-jisx0213_2004_1_encoder_paironly(const ucs4_t *data, int *length)
+jisx0213_2004_1_encoder_paironly(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
- int ilength = *length;
+ Py_ssize_t ilength = *length;
coded = jisx0213_encoder(data, length, NULL);
switch (ilength) {
@@ -896,7 +895,7 @@ jisx0213_2004_1_encoder_paironly(const ucs4_t *data, int *length)
}
static DBCHAR
-jisx0213_2004_2_encoder(const ucs4_t *data, int *length)
+jisx0213_2004_2_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded = jisx0213_encoder(data, length, NULL);
if (coded == MAP_UNMAPPABLE || coded == MAP_MULTIPLE_AVAIL)
@@ -917,7 +916,7 @@ jisx0201_r_decoder(const unsigned char *data)
}
static DBCHAR
-jisx0201_r_encoder(const ucs4_t *data, int *length)
+jisx0201_r_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
JISX0201_R_ENCODE(*data, coded)
@@ -935,7 +934,7 @@ jisx0201_k_decoder(const unsigned char *data)
}
static DBCHAR
-jisx0201_k_encoder(const ucs4_t *data, int *length)
+jisx0201_k_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
JISX0201_K_ENCODE(*data, coded)
@@ -967,7 +966,7 @@ gb2312_decoder(const unsigned char *data)
}
static DBCHAR
-gb2312_encoder(const ucs4_t *data, int *length)
+gb2312_encoder(const ucs4_t *data, Py_ssize_t *length)
{
DBCHAR coded;
assert(*length == 1);
@@ -986,7 +985,7 @@ dummy_decoder(const unsigned char *data)
}
static DBCHAR
-dummy_encoder(const ucs4_t *data, int *length)
+dummy_encoder(const ucs4_t *data, Py_ssize_t *length)
{
return MAP_UNMAPPABLE;
}