1a8fdb4bcSmrg/*
2a8fdb4bcSmrgCopyright (c) 2001 by Juliusz Chroboczek
3a8fdb4bcSmrg
4a8fdb4bcSmrgPermission is hereby granted, free of charge, to any person obtaining a copy
5a8fdb4bcSmrgof this software and associated documentation files (the "Software"), to deal
6a8fdb4bcSmrgin the Software without restriction, including without limitation the rights
7a8fdb4bcSmrgto use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8a8fdb4bcSmrgcopies of the Software, and to permit persons to whom the Software is
9a8fdb4bcSmrgfurnished to do so, subject to the following conditions:
10a8fdb4bcSmrg
11a8fdb4bcSmrgThe above copyright notice and this permission notice shall be included in
12a8fdb4bcSmrgall copies or substantial portions of the Software.
13a8fdb4bcSmrg
14a8fdb4bcSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15a8fdb4bcSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16a8fdb4bcSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17a8fdb4bcSmrgAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18a8fdb4bcSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19a8fdb4bcSmrgOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20a8fdb4bcSmrgTHE SOFTWARE.
21a8fdb4bcSmrg*/
2277683534Smrg
2377683534Smrg#ifndef LUIT_ISO2022_H
2477683534Smrg#define LUIT_ISO2022_H 1
2577683534Smrg
2677683534Smrg#include "charset.h"
2777683534Smrg
2877683534Smrg#define ESC    0x1B
2977683534Smrg#define CSI    0x9B
3077683534Smrg#define CSI_7  '['
3177683534Smrg#define SS2    0x8E
3277683534Smrg#define SS2_7  0x4E
3377683534Smrg#define SS3    0x8F
3477683534Smrg#define SS3_7  0x4F
3577683534Smrg#define LS0    0x0F
3677683534Smrg#define LS1    0x0E
3777683534Smrg#define LS2_7  0x6E
3877683534Smrg#define LS3_7  0x6F
39a8fdb4bcSmrg#define LS1R_7 0x7E
40a8fdb4bcSmrg#define LS2R_7 0x7D
41a8fdb4bcSmrg#define LS3R_7 0x7C
42a8fdb4bcSmrg
43a8fdb4bcSmrg#define IS_FINAL_ESC(x) (((x) & 0xF0 ) != 0x20)
4477683534Smrg#define IS_FINAL_CSI(x) (((x) & 0xF0 ) != 0x20 && (((x) & 0xF0 ) != 0x30))
45a8fdb4bcSmrg
4677683534Smrg#define P_NORMAL    0
4777683534Smrg#define P_ESC       1
4877683534Smrg#define P_CSI       2
49a8fdb4bcSmrg
5077683534Smrg#define S_NORMAL    0
5177683534Smrg#define S_SS2       1
5277683534Smrg#define S_SS3       2
53a8fdb4bcSmrg
5477683534Smrg#define IF_SS       1
5577683534Smrg#define IF_LS       2
56a8fdb4bcSmrg#define IF_EIGHTBIT 4
5777683534Smrg#define IF_SSGR     8
58a8fdb4bcSmrg
5977683534Smrg#define OF_SS       1
6077683534Smrg#define OF_LS       2
6177683534Smrg#define OF_SELECT   4
62a8fdb4bcSmrg#define OF_PASSTHRU 8
63a8fdb4bcSmrg
64a8fdb4bcSmrgtypedef struct _Iso2022 {
6577683534Smrg    const CharsetRec **glp;
6677683534Smrg    const CharsetRec **grp;
6777683534Smrg    const CharsetRec *g[4];
6877683534Smrg    const CharsetRec *other;
69a8fdb4bcSmrg    int parserState;
70a8fdb4bcSmrg    int shiftState;
71a8fdb4bcSmrg    int inputFlags;
72a8fdb4bcSmrg    int outputFlags;
73a8fdb4bcSmrg    unsigned char *buffered;
7477683534Smrg    size_t buffered_len;
7577683534Smrg    size_t buffered_count;
76a8fdb4bcSmrg    int buffered_ku;
77a8fdb4bcSmrg    unsigned char *outbuf;
7877683534Smrg    size_t outbuf_count;
79a8fdb4bcSmrg} Iso2022Rec, *Iso2022Ptr;
80a8fdb4bcSmrg
81a8fdb4bcSmrg#define GL(i) (*(i)->glp)
82a8fdb4bcSmrg#define GR(i) (*(i)->grp)
83a8fdb4bcSmrg#define G0(i) ((i)->g[0])
84a8fdb4bcSmrg#define G1(i) ((i)->g[1])
85a8fdb4bcSmrg#define G2(i) ((i)->g[2])
86a8fdb4bcSmrg#define G3(i) ((i)->g[3])
87a8fdb4bcSmrg#define OTHER(i) ((i)->other)
88a8fdb4bcSmrg
89a8fdb4bcSmrg#define BUFFER_SIZE 512
90a8fdb4bcSmrg
91a8fdb4bcSmrgIso2022Ptr allocIso2022(void);
92a8fdb4bcSmrgvoid destroyIso2022(Iso2022Ptr);
9377683534Smrgint initIso2022(const char *, const char *, Iso2022Ptr);
94a8fdb4bcSmrgint mergeIso2022(Iso2022Ptr, Iso2022Ptr);
95a8fdb4bcSmrgvoid reportIso2022(Iso2022Ptr);
96a8fdb4bcSmrgvoid terminate(Iso2022Ptr, int);
9777683534Smrgvoid terminateEsc(Iso2022Ptr, int, unsigned char *, unsigned);
9877683534Smrgvoid copyIn(Iso2022Ptr, int, unsigned char *, int);
9977683534Smrgvoid copyOut(Iso2022Ptr, int, unsigned char *, unsigned);
10077683534Smrg
10177683534Smrg#endif /* LUIT_ISO2022_H */
102