Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libvcodex/Vcmisc/vcmap.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Phong Vo <[email protected]> *
18
* *
19
***********************************************************************/
20
#include <vclib.h>
21
22
/* Map bytes from one to another (e.g., the rot13 program).
23
** If no mapping is specified, the identity map is used.
24
** Various mappings between different types of EBCDIC and ASCII
25
** are provided.
26
**
27
** Written by Kiem-Phong Vo ([email protected])
28
*/
29
30
static Vcchar_t A2E[] =
31
{ /* CC_ASCII=>CC_EBCDIC_E */
32
0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017,
33
0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
34
0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
35
0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
36
0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
37
0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0232,0155,
38
0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
39
0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0137,0007,
40
0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
41
0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0341,
42
0101,0102,0103,0104,0105,0106,0107,0110, 0111,0121,0122,0123,0124,0125,0126,0127,
43
0130,0131,0142,0143,0144,0145,0146,0147, 0150,0151,0160,0161,0162,0163,0164,0165,
44
0166,0167,0170,0200,0212,0213,0214,0215, 0216,0217,0220,0152,0233,0234,0235,0236,
45
0237,0240,0252,0253,0254,0112,0256,0257, 0260,0261,0262,0263,0264,0265,0266,0267,
46
0270,0271,0272,0273,0274,0241,0276,0277, 0312,0313,0314,0315,0316,0317,0332,0333,
47
0334,0335,0336,0337,0352,0353,0354,0355, 0356,0357,0372,0373,0374,0375,0376,0377
48
};
49
50
static Vcchar_t E2A[] =
51
{ /* CC_EBCDIC_E=>CC_ASCII */
52
0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
53
0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
54
0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
55
0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
56
0040,0240,0241,0242,0243,0244,0245,0246, 0247,0250,0325,0056,0074,0050,0053,0174,
57
0046,0251,0252,0253,0254,0255,0256,0257, 0260,0261,0041,0044,0052,0051,0073,0176,
58
0055,0057,0262,0263,0264,0265,0266,0267, 0270,0271,0313,0054,0045,0137,0076,0077,
59
0272,0273,0274,0275,0276,0277,0300,0301, 0302,0140,0072,0043,0100,0047,0075,0042,
60
0303,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0304,0305,0306,0307,0310,0311,
61
0312,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0136,0314,0315,0316,0317,0320,
62
0321,0345,0163,0164,0165,0166,0167,0170, 0171,0172,0322,0323,0324,0133,0326,0327,
63
0330,0331,0332,0333,0334,0335,0336,0337, 0340,0341,0342,0343,0344,0135,0346,0347,
64
0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0350,0351,0352,0353,0354,0355,
65
0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0356,0357,0360,0361,0362,0363,
66
0134,0237,0123,0124,0125,0126,0127,0130, 0131,0132,0364,0365,0366,0367,0370,0371,
67
0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0372,0373,0374,0375,0376,0377
68
};
69
70
static Vcchar_t A2I[] =
71
{ /* CC_ASCII=>CC_EBCDIC_I */
72
0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017,
73
0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
74
0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
75
0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
76
0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
77
0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0137,0155,
78
0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
79
0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0241,0007,
80
0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
81
0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0341,
82
0101,0102,0103,0104,0105,0106,0107,0110, 0111,0121,0122,0123,0124,0125,0126,0127,
83
0130,0131,0142,0143,0144,0145,0146,0147, 0150,0151,0160,0161,0162,0163,0164,0165,
84
0166,0167,0170,0200,0212,0213,0214,0215, 0216,0217,0220,0232,0233,0234,0235,0236,
85
0237,0240,0252,0253,0254,0255,0256,0257, 0260,0261,0262,0263,0264,0265,0266,0267,
86
0270,0271,0272,0273,0274,0275,0276,0277, 0312,0313,0314,0315,0316,0317,0332,0333,
87
0334,0335,0336,0337,0352,0353,0354,0355, 0356,0357,0372,0373,0374,0375,0376,0377
88
};
89
90
static Vcchar_t I2A[] =
91
{ /* CC_EBCDIC_I=>CC_ASCII */
92
0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
93
0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
94
0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
95
0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
96
0040,0240,0241,0242,0243,0244,0245,0246, 0247,0250,0112,0056,0074,0050,0053,0174,
97
0046,0251,0252,0253,0254,0255,0256,0257, 0260,0261,0041,0044,0052,0051,0073,0136,
98
0055,0057,0262,0263,0264,0265,0266,0267, 0270,0271,0152,0054,0045,0137,0076,0077,
99
0272,0273,0274,0275,0276,0277,0300,0301, 0302,0140,0072,0043,0100,0047,0075,0042,
100
0303,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0304,0305,0306,0307,0310,0311,
101
0312,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0313,0314,0315,0316,0317,0320,
102
0321,0176,0163,0164,0165,0166,0167,0170, 0171,0172,0322,0323,0324,0133,0326,0327,
103
0330,0331,0332,0333,0334,0335,0336,0337, 0340,0341,0342,0343,0344,0135,0346,0347,
104
0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0350,0351,0352,0353,0354,0355,
105
0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0356,0357,0360,0361,0362,0363,
106
0134,0237,0123,0124,0125,0126,0127,0130, 0131,0132,0364,0365,0366,0367,0370,0371,
107
0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0372,0373,0374,0375,0376,0377
108
};
109
110
static Vcchar_t A2O[] =
111
{ /* CC_ASCII=>CC_EBDCID_O */
112
0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0025,0013,0014,0015,0016,0017,
113
0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
114
0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
115
0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
116
0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
117
0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0255,0340,0275,0137,0155,
118
0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
119
0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0241,0007,
120
0040,0041,0042,0043,0044,0045,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
121
0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0377,
122
0101,0252,0112,0261,0237,0262,0152,0265, 0273,0264,0232,0212,0260,0312,0257,0274,
123
0220,0217,0352,0372,0276,0240,0266,0263, 0235,0332,0233,0213,0267,0270,0271,0253,
124
0144,0145,0142,0146,0143,0147,0236,0150, 0164,0161,0162,0163,0170,0165,0166,0167,
125
0254,0151,0355,0356,0353,0357,0354,0277, 0200,0375,0376,0373,0374,0272,0256,0131,
126
0104,0105,0102,0106,0103,0107,0234,0110, 0124,0121,0122,0123,0130,0125,0126,0127,
127
0214,0111,0315,0316,0313,0317,0314,0341, 0160,0335,0336,0333,0334,0215,0216,0337
128
};
129
130
static Vcchar_t O2A[] =
131
{ /* CC_EBDCID_O=>CC_ASCII */
132
0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
133
0020,0021,0022,0023,0235,0012,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
134
0200,0201,0202,0203,0204,0205,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
135
0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
136
0040,0240,0342,0344,0340,0341,0343,0345, 0347,0361,0242,0056,0074,0050,0053,0174,
137
0046,0351,0352,0353,0350,0355,0356,0357, 0354,0337,0041,0044,0052,0051,0073,0136,
138
0055,0057,0302,0304,0300,0301,0303,0305, 0307,0321,0246,0054,0045,0137,0076,0077,
139
0370,0311,0312,0313,0310,0315,0316,0317, 0314,0140,0072,0043,0100,0047,0075,0042,
140
0330,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0253,0273,0360,0375,0376,0261,
141
0260,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0252,0272,0346,0270,0306,0244,
142
0265,0176,0163,0164,0165,0166,0167,0170, 0171,0172,0241,0277,0320,0133,0336,0256,
143
0254,0243,0245,0267,0251,0247,0266,0274, 0275,0276,0335,0250,0257,0135,0264,0327,
144
0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0255,0364,0366,0362,0363,0365,
145
0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0271,0373,0374,0371,0372,0377,
146
0134,0367,0123,0124,0125,0126,0127,0130, 0131,0132,0262,0324,0326,0322,0323,0325,
147
0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0263,0333,0334,0331,0332,0237
148
};
149
150
static Vcchar_t A2S[] =
151
{ /* CC_ASCII=>CC_EBCDIC_S */
152
0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0025,0013,0014,0015,0016,0017,
153
0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
154
0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
155
0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
156
0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
157
0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0273,0274,0275,0152,0155,
158
0112,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
159
0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0373,0117,0375,0377,0007,
160
0040,0041,0042,0043,0044,0045,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
161
0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0137,
162
0101,0252,0260,0261,0237,0262,0320,0265, 0171,0264,0232,0212,0272,0312,0257,0241,
163
0220,0217,0352,0372,0276,0240,0266,0263, 0235,0332,0233,0213,0267,0270,0271,0253,
164
0144,0145,0142,0146,0143,0147,0236,0150, 0164,0161,0162,0163,0170,0165,0166,0167,
165
0254,0151,0355,0356,0353,0357,0354,0277, 0200,0340,0376,0335,0374,0255,0256,0131,
166
0104,0105,0102,0106,0103,0107,0234,0110, 0124,0121,0122,0123,0130,0125,0126,0127,
167
0214,0111,0315,0316,0313,0317,0314,0341, 0160,0300,0336,0333,0334,0215,0216,0337
168
};
169
170
static Vcchar_t S2A[] =
171
{ /* CC_EBCDIC_S=>CC_ASCII */
172
0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
173
0020,0021,0022,0023,0235,0012,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
174
0200,0201,0202,0203,0204,0205,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
175
0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
176
0040,0240,0342,0344,0340,0341,0343,0345, 0347,0361,0140,0056,0074,0050,0053,0174,
177
0046,0351,0352,0353,0350,0355,0356,0357, 0354,0337,0041,0044,0052,0051,0073,0237,
178
0055,0057,0302,0304,0300,0301,0303,0305, 0307,0321,0136,0054,0045,0137,0076,0077,
179
0370,0311,0312,0313,0310,0315,0316,0317, 0314,0250,0072,0043,0100,0047,0075,0042,
180
0330,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0253,0273,0360,0375,0376,0261,
181
0260,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0252,0272,0346,0270,0306,0244,
182
0265,0257,0163,0164,0165,0166,0167,0170, 0171,0172,0241,0277,0320,0335,0336,0256,
183
0242,0243,0245,0267,0251,0247,0266,0274, 0275,0276,0254,0133,0134,0135,0264,0327,
184
0371,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0255,0364,0366,0362,0363,0365,
185
0246,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0271,0373,0374,0333,0372,0377,
186
0331,0367,0123,0124,0125,0126,0127,0130, 0131,0132,0262,0324,0326,0322,0323,0325,
187
0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0263,0173,0334,0175,0332,0176
188
};
189
190
static Vcchar_t A2H[] =
191
{ /* CC_ASCII=>CC_EBCDIC_H */
192
0000,0001,0002,0003,0067,0055,0056,0057, 0026,0005,0045,0013,0014,0015,0016,0017,
193
0020,0021,0022,0023,0074,0075,0062,0046, 0030,0031,0077,0047,0034,0035,0036,0037,
194
0100,0132,0177,0173,0133,0154,0120,0175, 0115,0135,0134,0116,0153,0140,0113,0141,
195
0360,0361,0362,0363,0364,0365,0366,0367, 0370,0371,0172,0136,0114,0176,0156,0157,
196
0174,0301,0302,0303,0304,0305,0306,0307, 0310,0311,0321,0322,0323,0324,0325,0326,
197
0327,0330,0331,0342,0343,0344,0345,0346, 0347,0350,0351,0272,0340,0273,0260,0155,
198
0171,0201,0202,0203,0204,0205,0206,0207, 0210,0211,0221,0222,0223,0224,0225,0226,
199
0227,0230,0231,0242,0243,0244,0245,0246, 0247,0250,0251,0300,0117,0320,0241,0007,
200
0040,0041,0042,0043,0044,0025,0006,0027, 0050,0051,0052,0053,0054,0011,0012,0033,
201
0060,0061,0032,0063,0064,0065,0066,0010, 0070,0071,0072,0073,0004,0024,0076,0377,
202
0101,0252,0112,0261,0237,0262,0152,0265, 0275,0264,0232,0212,0137,0312,0257,0274,
203
0220,0217,0352,0372,0276,0240,0266,0263, 0235,0332,0233,0213,0267,0270,0271,0253,
204
0144,0145,0142,0146,0143,0147,0236,0150, 0164,0161,0162,0163,0170,0165,0166,0167,
205
0254,0151,0355,0356,0353,0357,0354,0277, 0200,0375,0376,0373,0374,0255,0256,0131,
206
0104,0105,0102,0106,0103,0107,0234,0110, 0124,0121,0122,0123,0130,0125,0126,0127,
207
0214,0111,0315,0316,0313,0317,0314,0341, 0160,0335,0336,0333,0334,0215,0216,0337
208
};
209
210
static Vcchar_t H2A[] =
211
{ /* CC_EBCDIC_H=>CC_ASCII */
212
0000,0001,0002,0003,0234,0011,0206,0177, 0227,0215,0216,0013,0014,0015,0016,0017,
213
0020,0021,0022,0023,0235,0205,0010,0207, 0030,0031,0222,0217,0034,0035,0036,0037,
214
0200,0201,0202,0203,0204,0012,0027,0033, 0210,0211,0212,0213,0214,0005,0006,0007,
215
0220,0221,0026,0223,0224,0225,0226,0004, 0230,0231,0232,0233,0024,0025,0236,0032,
216
0040,0240,0342,0344,0340,0341,0343,0345, 0347,0361,0242,0056,0074,0050,0053,0174,
217
0046,0351,0352,0353,0350,0355,0356,0357, 0354,0337,0041,0044,0052,0051,0073,0254,
218
0055,0057,0302,0304,0300,0301,0303,0305, 0307,0321,0246,0054,0045,0137,0076,0077,
219
0370,0311,0312,0313,0310,0315,0316,0317, 0314,0140,0072,0043,0100,0047,0075,0042,
220
0330,0141,0142,0143,0144,0145,0146,0147, 0150,0151,0253,0273,0360,0375,0376,0261,
221
0260,0152,0153,0154,0155,0156,0157,0160, 0161,0162,0252,0272,0346,0270,0306,0244,
222
0265,0176,0163,0164,0165,0166,0167,0170, 0171,0172,0241,0277,0320,0335,0336,0256,
223
0136,0243,0245,0267,0251,0247,0266,0274, 0275,0276,0133,0135,0257,0250,0264,0327,
224
0173,0101,0102,0103,0104,0105,0106,0107, 0110,0111,0255,0364,0366,0362,0363,0365,
225
0175,0112,0113,0114,0115,0116,0117,0120, 0121,0122,0271,0373,0374,0371,0372,0377,
226
0134,0367,0123,0124,0125,0126,0127,0130, 0131,0132,0262,0324,0326,0322,0323,0325,
227
0060,0061,0062,0063,0064,0065,0066,0067, 0070,0071,0263,0333,0334,0331,0332,0237
228
};
229
230
static Vcmtarg_t _Mapargs[] =
231
{ { "a2e", "ASCII -> Xopen dd(1) EBCDIC.", A2E },
232
{ "e2a", "Xopen dd(1) EBCDIC -> ASCII.", E2A },
233
{ "a2i", "ASCII -> Xopen dd(1) IBM.", A2I },
234
{ "i2a", "Xopen dd(1) IBM -> ASCII.", I2A },
235
{ "a2o", "ASCII -> IBM OpenEdition.", A2O },
236
{ "o2a", "IBM OpenEdition -> ASCII.", O2A },
237
{ "a2s", "ASCII -> Siemens Posix-bc.", A2S },
238
{ "s2a", "Siemens Posix-bc -> ASCII.", S2A },
239
{ "a2h", "ASCII -> IBM-37 AS/400.", A2H },
240
{ "h2a", "IBM-37 AS/400 -> ASCII.", H2A },
241
{ 0 , "Identity mapping.", 0 }
242
};
243
244
typedef struct _vcmap_s
245
{ Vcchar_t* map;
246
} Vcmap_t;
247
248
#if __STD_C
249
static ssize_t vcmap(Vcodex_t* vc, const Void_t* data, size_t size, Void_t** out)
250
#else
251
static ssize_t vcmap(vc, data, size, out)
252
Vcodex_t* vc;
253
Void_t* data;
254
size_t size;
255
Void_t** out;
256
#endif
257
{
258
ssize_t sz;
259
Vcchar_t *dt, *enddt, *output, *o;
260
Vcchar_t *map;
261
Vcmap_t *vcm = vcgetmtdata(vc, Vcmap_t*);
262
Vcdisc_t *disc = vcgetdisc(vc);
263
264
if((sz = (ssize_t)size) == 0)
265
return 0;
266
if(!(dt = (Vcchar_t*)data) )
267
return -1;
268
269
if(!(map = vcm->map) )
270
if(disc && disc->data)
271
map = disc->data;
272
273
if(vc->flags&VC_DECODE)
274
if(vcrecode(vc, &dt, &sz, 0, 0) < 0)
275
return -1;
276
277
if(!(output = vcbuffer(vc, NIL(Vcchar_t*), sz, 0)) )
278
return -1;
279
280
if(!map)
281
memcpy(output, dt, sz);
282
else for(o = output, enddt = dt+sz; dt < enddt; )
283
*o++ = map[*dt++];
284
285
if((vc->flags&VC_DECODE) && vc->coder)
286
vcbuffer(vc, dt-sz, -1, -1);
287
288
if(vc->flags&VC_ENCODE)
289
{ dt = output;
290
if(vcrecode(vc, &output, &sz, 0, 0) < 0 )
291
return -1;
292
if(dt != output)
293
vcbuffer(vc, dt, -1, -1);
294
}
295
296
if(out)
297
*out = output;
298
return sz;
299
}
300
301
#if __STD_C
302
static int mapevent(Vcodex_t* vc, int type, Void_t* params)
303
#else
304
static int mapevent(vc, type, params)
305
Vcodex_t* vc;
306
int type;
307
Void_t* params;
308
#endif
309
{
310
Vcmap_t *vcm;
311
Vcmtarg_t *arg;
312
313
if(type == VC_OPENING)
314
{ if(!(vcm = (Vcmap_t*)calloc(1, sizeof(Vcmap_t))) )
315
return -1;
316
317
if(params) /* get the mapping type, if any */
318
{ vcgetmtarg((char*)params, 0, 0, _Mapargs, &arg);
319
if(arg)
320
vcm->map = arg->data;
321
}
322
323
vcsetmtdata(vc, vcm);
324
}
325
else if(type == VC_CLOSING)
326
{ if((vcm = vcgetmtdata(vc, Vcmap_t*)) )
327
free(vcm);
328
vcsetmtdata(vc, NIL(Vcmap_t*));
329
}
330
331
return 0;
332
}
333
334
Vcmethod_t _Vcmap =
335
{ vcmap,
336
vcmap,
337
mapevent,
338
"map", "Mapping bytes from codeset to codeset.",
339
"[-version?map (AT&T Research) 2003-01-01]" USAGE_LICENSE,
340
_Mapargs,
341
1024*1024,
342
0
343
};
344
345
VCLIB(Vcmap)
346
347