| 968 | ************************************************************************/ |
| 969 | |
| 970 | static int |
| 971 | xmlDetectEBCDIC(xmlParserInputPtr input, xmlCharEncodingHandlerPtr *hout) { |
| 972 | xmlChar out[200]; |
| 973 | xmlCharEncodingHandlerPtr handler; |
| 974 | int inlen, outlen, res, i; |
| 975 | |
| 976 | *hout = NULL; |
| 977 | |
| 978 | /* |
| 979 | * To detect the EBCDIC code page, we convert the first 200 bytes |
| 980 | * to EBCDIC-US and try to find the encoding declaration. |
| 981 | */ |
| 982 | res = xmlLookupCharEncodingHandler(XML_CHAR_ENCODING_EBCDIC, &handler); |
| 983 | if (res != 0) |
| 984 | return(res); |
| 985 | outlen = sizeof(out) - 1; |
| 986 | inlen = input->end - input->cur; |
| 987 | res = xmlEncInputChunk(handler, out, &outlen, input->cur, &inlen); |
| 988 | /* |
| 989 | * Return the EBCDIC handler if decoding failed. The error will |
| 990 | * be reported later. |
| 991 | */ |
| 992 | if (res < 0) |
| 993 | goto done; |
| 994 | out[outlen] = 0; |
| 995 | |
| 996 | for (i = 0; i < outlen; i++) { |
| 997 | if (out[i] == '>') |
| 998 | break; |
| 999 | if ((out[i] == 'e') && |
| 1000 | (xmlStrncmp(out + i, BAD_CAST "encoding", 8) == 0)) { |
| 1001 | int start, cur, quote; |
| 1002 | |
| 1003 | i += 8; |
| 1004 | while (IS_BLANK_CH(out[i])) |
| 1005 | i += 1; |
| 1006 | if (out[i++] != '=') |
| 1007 | break; |
| 1008 | while (IS_BLANK_CH(out[i])) |
| 1009 | i += 1; |
| 1010 | quote = out[i++]; |
| 1011 | if ((quote != '\'') && (quote != '"')) |
| 1012 | break; |
| 1013 | start = i; |
| 1014 | cur = out[i]; |
| 1015 | while (((cur >= 'a') && (cur <= 'z')) || |
| 1016 | ((cur >= 'A') && (cur <= 'Z')) || |
| 1017 | ((cur >= '0') && (cur <= '9')) || |
| 1018 | (cur == '.') || (cur == '_') || |
| 1019 | (cur == '-')) |
| 1020 | cur = out[++i]; |
| 1021 | if (cur != quote) |
| 1022 | break; |
| 1023 | out[i] = 0; |
| 1024 | xmlCharEncCloseFunc(handler); |
| 1025 | res = xmlOpenCharEncodingHandler((char *) out + start, |
| 1026 | /* output */ 0, &handler); |
| 1027 | if (res != 0) |
no test coverage detected