struct cp_list_item *cpi;
const struct cp_list_item *cpi;
int decode_codepage(char *cp_name){    char *s, *d;    struct cp_list_item *cpi;    int codepage = -1;    CPINFO cpinfo;    if (!*cp_name) {	/*	 * Here we select a plausible default code page based on	 * the locale the user is in. We wish to select an ISO code	 * page or appropriate local default _rather_ than go with	 * the Win125* series, because it's more important to have	 * CSI and friends enabled by default than the ghastly	 * Windows extra quote characters, and because it's more	 * likely the user is connecting to a remote server that	 * does something Unixy or VMSy and hence standards-	 * compliant than that they're connecting back to a Windows	 * box using horrible nonstandard charsets.	 * 	 * Accordingly, Robert de Bath suggests a method for	 * picking a default character set that runs as follows:	 * first call GetACP to get the system's ANSI code page	 * identifier, and translate as follows:	 * 	 * 1250 -> ISO 8859-2	 * 1251 -> KOI8-U	 * 1252 -> ISO 8859-1	 * 1253 -> ISO 8859-7	 * 1254 -> ISO 8859-9	 * 1255 -> ISO 8859-8	 * 1256 -> ISO 8859-6	 * 1257 -> ISO 8859-4	 * 	 * and for anything else, choose direct-to-font.	 */	int cp = GetACP();	switch (cp) {	  case 1250: cp_name = "ISO-8859-2"; break;	  case 1251: cp_name = "KOI8-U"; break;	  case 1252: cp_name = "ISO-8859-1"; break;	  case 1253: cp_name = "ISO-8859-7"; break;	  case 1254: cp_name = "ISO-8859-9"; break;	  case 1255: cp_name = "ISO-8859-8"; break;	  case 1256: cp_name = "ISO-8859-6"; break;	  case 1257: cp_name = "ISO-8859-4"; break;	    /* default: leave it blank, which will select -1, direct->font */	}    }    if (cp_name && *cp_name)	for (cpi = cp_list; cpi->name; cpi++) {	    s = cp_name;	    d = cpi->name;	    for (;;) {		while (*s && !isalnum(*s) && *s != ':')		    s++;		while (*d && !isalnum(*d) && *d != ':')		    d++;		if (*s == 0) {		    codepage = cpi->codepage;		    if (codepage == CP_UTF8)			goto break_break;		    if (codepage == -1)			return codepage;		    if (codepage == 0) {			codepage = 65536 + (cpi - cp_list);			goto break_break;		    }		    if (GetCPInfo(codepage, &cpinfo) != 0)			goto break_break;		}		if (tolower(*s++) != tolower(*d++))		    break;	    }	}    if (cp_name && *cp_name) {	d = cp_name;	if (tolower(d[0]) == 'c' && tolower(d[1]) == 'p')	    d += 2;	if (tolower(d[0]) == 'i' && tolower(d[1]) == 'b'	    && tolower(d[1]) == 'm')	    d += 3;	for (s = d; *s >= '0' && *s <= '9'; s++);	if (*s == 0 && s != d)	    codepage = atoi(d);	       /* CP999 or IBM999 */	if (codepage == CP_ACP)	    codepage = GetACP();	if (codepage == CP_OEMCP)	    codepage = GetOEMCP();	if (codepage > 65535)	    codepage = -2;    }  break_break:;    if (codepage != -1) {	if (codepage != CP_UTF8 && codepage < 65536) {	    if (GetCPInfo(codepage, &cpinfo) == 0) {		codepage = -2;	    } else if (cpinfo.MaxCharSize > 1)		codepage = -3;	}    }    if (codepage == -1 && *cp_name)	codepage = -2;    return codepage;}