1/* 2Copyright (c) 2001 by Juliusz Chroboczek 3 4Permission is hereby granted, free of charge, to any person obtaining a copy 5of this software and associated documentation files (the "Software"), to deal 6in the Software without restriction, including without limitation the rights 7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8copies of the Software, and to permit persons to whom the Software is 9furnished to do so, subject to the following conditions: 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20THE SOFTWARE. 21*/ 22 23#ifndef LUIT_ISO2022_H 24#define LUIT_ISO2022_H 1 25 26#include "charset.h" 27 28#define ESC 0x1B 29#define CSI 0x9B 30#define CSI_7 '[' 31#define SS2 0x8E 32#define SS2_7 0x4E 33#define SS3 0x8F 34#define SS3_7 0x4F 35#define LS0 0x0F 36#define LS1 0x0E 37#define LS2_7 0x6E 38#define LS3_7 0x6F 39#define LS1R_7 0x7E 40#define LS2R_7 0x7D 41#define LS3R_7 0x7C 42 43#define IS_FINAL_ESC(x) (((x) & 0xF0 ) != 0x20) 44#define IS_FINAL_CSI(x) (((x) & 0xF0 ) != 0x20 && (((x) & 0xF0 ) != 0x30)) 45 46#define P_NORMAL 0 47#define P_ESC 1 48#define P_CSI 2 49 50#define S_NORMAL 0 51#define S_SS2 1 52#define S_SS3 2 53 54#define IF_SS 1 55#define IF_LS 2 56#define IF_EIGHTBIT 4 57#define IF_SSGR 8 58 59#define OF_SS 1 60#define OF_LS 2 61#define OF_SELECT 4 62#define OF_PASSTHRU 8 63 64typedef struct _Iso2022 { 65 const CharsetRec **glp; 66 const CharsetRec **grp; 67 const CharsetRec *g[4]; 68 const CharsetRec *other; 69 int parserState; 70 int shiftState; 71 int inputFlags; 72 int outputFlags; 73 unsigned char *buffered; 74 size_t buffered_len; 75 size_t buffered_count; 76 int buffered_ku; 77 unsigned char *outbuf; 78 size_t outbuf_count; 79} Iso2022Rec, *Iso2022Ptr; 80 81#define GL(i) (*(i)->glp) 82#define GR(i) (*(i)->grp) 83#define G0(i) ((i)->g[0]) 84#define G1(i) ((i)->g[1]) 85#define G2(i) ((i)->g[2]) 86#define G3(i) ((i)->g[3]) 87#define OTHER(i) ((i)->other) 88 89#define BUFFER_SIZE 512 90 91Iso2022Ptr allocIso2022(void); 92void destroyIso2022(Iso2022Ptr); 93int initIso2022(const char *, const char *, Iso2022Ptr); 94int mergeIso2022(Iso2022Ptr, Iso2022Ptr); 95void reportIso2022(Iso2022Ptr); 96void terminate(Iso2022Ptr, int); 97void terminateEsc(Iso2022Ptr, int, unsigned char *, unsigned); 98void copyIn(Iso2022Ptr, int, unsigned char *, int); 99void copyOut(Iso2022Ptr, int, unsigned char *, unsigned); 100 101#endif /* LUIT_ISO2022_H */ 102