void wtf_push_ucs(Str os, wc_uint32 ucs, wc_status *st) { wc_ccs ccs; if (ucs >= WC_C_LANGUAGE_TAG0 && ucs <= WC_C_CANCEL_TAG) { if (! WcOption.use_language_tag) return; if (ucs == WC_C_LANGUAGE_TAG) st->tag = Strnew_size(4); else if (ucs == WC_C_CANCEL_TAG) { st->tag = NULL; st->ntag = 0; } else if (st->tag && ucs >= WC_C_TAG_SPACE) Strcat_char(st->tag, (char)(ucs & 0x7f)); return; } if (st->tag) { st->ntag = wc_ucs_put_tag(st->tag->ptr); st->tag = NULL; } if (ucs < 0x80) { if (st->ntag) wtf_push(os, WC_CCS_UCS_TAG, wc_ucs_to_ucs_tag(ucs, st->ntag)); else Strcat_char(os, (char)ucs); } else { ccs = wc_ucs_to_ccs(ucs); if (st->ntag && ucs <= WC_C_UNICODE_END) { ccs = wc_ccs_ucs_to_ccs_ucs_tag(ccs); ucs = wc_ucs_to_ucs_tag(ucs, st->ntag); } wtf_push(os, ccs, ucs); } }
struct parsed_tagarg * cgistr2tagarg(char *cgistr) { Str tag; Str value; struct parsed_tagarg *t0, *t; t = t0 = NULL; do { t = New(struct parsed_tagarg); t->next = t0; t0 = t; tag = Strnew(); while (*cgistr && *cgistr != '=' && *cgistr != '&') Strcat_char(tag, *cgistr++); t->arg = Str_form_unquote(tag)->ptr; t->value = NULL; if (*cgistr == '\0') return t; else if (*cgistr == '=') { cgistr++; value = Strnew(); while (*cgistr && *cgistr != '&') Strcat_char(value, *cgistr++); t->value = Str_form_unquote(value)->ptr; } else if (*cgistr == '&') cgistr++; } while (*cgistr); return t; }
void wc_push_to_gb18030(Str os, wc_wchar_t cc, wc_status *st) { while (1) { switch (WC_CCS_SET(cc.ccs)) { case WC_CCS_US_ASCII: Strcat_char(os, (char)cc.code); return; case WC_CCS_GB_2312: Strcat_char(os, (char)((cc.code >> 8) | 0x80)); Strcat_char(os, (char)((cc.code & 0xff) | 0x80)); return; case WC_CCS_GBK_1: case WC_CCS_GBK_2: cc = wc_cs128w_to_gbk(cc); case WC_CCS_GBK: Strcat_char(os, (char)(cc.code >> 8)); Strcat_char(os, (char)(cc.code & 0xff)); return; case WC_CCS_GBK_EXT_1: case WC_CCS_GBK_EXT_2: cc = wc_cs128w_to_gbk(cc); case WC_CCS_GBK_EXT: Strcat_char(os, (char)(cc.code >> 8)); Strcat_char(os, (char)(cc.code & 0xff)); return; case WC_CCS_GB18030: Strcat_char(os, (char)((cc.code >> 24) & 0xff)); Strcat_char(os, (char)((cc.code >> 16) & 0xff)); Strcat_char(os, (char)((cc.code >> 8) & 0xff)); Strcat_char(os, (char)(cc.code & 0xff)); return; case WC_CCS_UNKNOWN_W: if (!WcOption.no_replace) Strcat_charp(os, WC_REPLACE_W); return; case WC_CCS_UNKNOWN: if (!WcOption.no_replace) Strcat_charp(os, WC_REPLACE); return; default: #ifdef USE_UNICODE if (WcOption.ucs_conv) cc = wc_any_to_any_ces(cc, st); else #endif cc.ccs = WC_CCS_IS_WIDE(cc.ccs) ? WC_CCS_UNKNOWN_W : WC_CCS_UNKNOWN; continue; } } }
static char * html_quote_s(char *str) { Str tmp = NULL; char *p, *q; bool space = true; for (p = str; *p; p++) { if (IS_SPACE(*p)) { if (space) continue; q = " "; space = true; } else { q = html_quote_char(*p); space = false; } if (q) { if (tmp == NULL) tmp = Strnew_charp_n(str, (int)(p - str)); Strcat_charp(tmp, q); } else { if (tmp) Strcat_char(tmp, *p); } } if (tmp) return tmp->ptr; return str; }
static void interpret_rc(FILE * f) { Str line; Str tmp; char *p; for (;;) { line = Strfgets(f); Strchop(line); if (line->length == 0) break; Strremovefirstspaces(line); if (line->ptr[0] == '#') /* comment */ continue; tmp = Strnew(); p = line->ptr; while (*p && !IS_SPACE(*p)) Strcat_char(tmp, *p++); while (*p && IS_SPACE(*p)) p++; Strlower(tmp); set_param(tmp->ptr, p); } }
int set_param_option(char *option) { Str tmp = Strnew(); char *p = option, *q; while (*p && !IS_SPACE(*p) && *p != '=') Strcat_char(tmp, *p++); while (*p && IS_SPACE(*p)) p++; if (*p == '=') { p++; while (*p && IS_SPACE(*p)) p++; } Strlower(tmp); if (set_param(tmp->ptr, p)) goto option_assigned; q = tmp->ptr; if (!strncmp(q, "no", 2)) { /* -o noxxx, -o no-xxx, -o no_xxx */ q += 2; if (*q == '-' || *q == '_') q++; } else if (tmp->ptr[0] == '-') /* -o -xxx */ q++; else return 0; if (set_param(q, "0")) goto option_assigned; return 0; option_assigned: return 1; }
char * getAnchorText(Buffer *buf, AnchorList *al, Anchor *a) { int hseq, i; Line *l; Str tmp = NULL; char *p, *ep; if (!a || a->hseq < 0) return NULL; hseq = a->hseq; l = buf->firstLine; for (i = 0; i < al->nanchor; i++) { a = &al->anchors[i]; if (a->hseq != hseq) continue; for (; l; l = l->next) { if (l->linenumber == a->start.line) break; } if (!l) break; p = l->lineBuf + a->start.pos; ep = l->lineBuf + a->end.pos; for (; p < ep && IS_SPACE(*p); p++) ; if (p == ep) continue; if (!tmp) tmp = Strnew_size(ep - p); else Strcat_char(tmp, ' '); Strcat_charp_n(tmp, p, ep - p); } return tmp ? tmp->ptr : NULL; }
static Str make_cookie(struct cookie *cookie) { Str tmp = Strdup(cookie->name); Strcat_char(tmp, '='); Strcat(tmp, cookie->value); return tmp; }
Str Stralign_center(Str s, int width) { Str n; int i, w; STR_LENGTH_CHECK(s); if (s->length >= width) return Strdup(s); n = Strnew_size(width); w = (width - s->length) / 2; for (i = 0; i < w; i++) Strcat_char(n, ' '); Strcat(n, s); for (i = w + s->length; i < width; i++) Strcat_char(n, ' '); return n; }
Str quote_mailcap(char *s, int flag) { Str d; d = Strnew(); for (;; ++s) switch (*s) { case '\0': goto end; case '$': case '`': case '"': case '\\': if (!(flag & MCF_SQUOTED)) Strcat_char(d, '\\'); Strcat_char(d, *s); break; case '\'': if (flag & MCF_SQUOTED) { Strcat_charp(d, "'\\''"); break; } default: if (!flag && !IS_ALNUM(*s)) Strcat_char(d, '\\'); case '_': case '.': case ':': case '/': Strcat_char(d, *s); break; } end: return d; }
Str Strsubstr(Str s, int beg, int len) { Str new_s; int i; STR_LENGTH_CHECK(s); new_s = Strnew(); if (beg >= s->length) return new_s; for (i = 0; i < len && beg + i < s->length; i++) Strcat_char(new_s, s->ptr[beg + i]); return new_s; }
Str StrmyISgets(InputStream stream) { BaseStream base; StreamBuffer sb; Str s = NULL; int i, len; if (stream == NULL) return '\0'; base = &stream->base; sb = &base->stream; while (!base->iseos) { if (MUST_BE_UPDATED(base)) { do_update(base); } else { if (s && Strlastchar(s) == '\r') { if (sb->buf[sb->cur] == '\n') Strcat_char(s, (char)sb->buf[sb->cur++]); return s; } for (i = sb->cur; i < sb->next && sb->buf[i] != '\n' && sb->buf[i] != '\r'; i++) ; if (i < sb->next) { len = i - sb->cur + 1; if (s == NULL) s = Strnew_size(len + MARGIN_STR_SIZE); Strcat_charp_n(s, (char *)&sb->buf[sb->cur], len); sb->cur = i + 1; if (sb->buf[i] == '\n') return s; } else { if (s == NULL) s = Strnew_size(sb->next - sb->cur + MARGIN_STR_SIZE); Strcat_charp_n(s, (char *)&sb->buf[sb->cur], sb->next - sb->cur); sb->cur = sb->next; } } } if (s == NULL) return Strnew(); return s; }
Str Stralign_right(Str s, int width) { Str n; int i; STR_LENGTH_CHECK(s); if (s->length >= width) return Strdup(s); n = Strnew_size(width); for (i = s->length; i < width; i++) Strcat_char(n, ' '); Strcat(n, s); return n; }
Str loadLocalDir(char *dname) { Str tmp; DIR *d; Directory *dir; struct stat st; char **flist; char *p, *qdir; Str fbuf = Strnew(); #ifdef HAVE_LSTAT struct stat lst; #ifdef HAVE_READLINK char lbuf[1024]; #endif /* HAVE_READLINK */ #endif /* HAVE_LSTAT */ int i, l, nrow = 0, n = 0, maxlen = 0; int nfile, nfile_max = 100; Str dirname; d = opendir(dname); if (d == NULL) return NULL; dirname = Strnew_charp(dname); if (Strlastchar(dirname) != '/') Strcat_char(dirname, '/'); qdir = html_quote(Str_conv_from_system(dirname)->ptr); /* FIXME: gettextize? */ tmp = Strnew_m_charp("<HTML>\n<HEAD>\n<BASE HREF=\"file://", html_quote(file_quote(dirname->ptr)), "\">\n<TITLE>Directory list of ", qdir, "</TITLE>\n</HEAD>\n<BODY>\n<H1>Directory list of ", qdir, "</H1>\n", NULL); flist = New_N(char *, nfile_max); nfile = 0; while ((dir = readdir(d)) != NULL) { flist[nfile++] = allocStr(dir->d_name, -1); if (nfile == nfile_max) { nfile_max *= 2; flist = New_Reuse(char *, flist, nfile_max); } if (multicolList) { l = strlen(dir->d_name); if (l > maxlen) maxlen = l; n++; } }
Str wc_conv_from_viet(Str is, wc_ces ces) { Str os; wc_uchar *sp = (wc_uchar *)is->ptr; wc_uchar *ep = sp + is->length; wc_uchar *p; wc_ccs ccs1 = WcCesInfo[WC_CCS_INDEX(ces)].gset[1].ccs; wc_ccs ccs2 = WcCesInfo[WC_CCS_INDEX(ces)].gset[2].ccs; wc_uint8 *map = NULL; switch (ces) { case WC_CES_TCVN_5712: map = wc_c0_tcvn57122_map; break; case WC_CES_VISCII_11: map = wc_c0_viscii112_map; break; case WC_CES_VPS: map = wc_c0_vps2_map; break; } wc_create_detect_map(ces, WC_FALSE); for (p = sp; p < ep && ! WC_DETECT_MAP[*p]; p++) ; if (p == ep) return is; os = Strnew_size(is->length); if (p > sp) Strcat_charp_n(os, is->ptr, (int)(p - sp)); for (; p < ep; p++) { if (*p & 0x80) wtf_push(os, ccs1, (wc_uint32)*p); else if (*p < 0x20 && map[*p]) wtf_push(os, ccs2, (wc_uint32)*p); else Strcat_char(os, (char)*p); } return os; }
static struct portlist * make_portlist(Str port) { struct portlist *first = NULL, *pl; char *p; Str tmp = Strnew(); p = port->ptr; while (*p) { while (*p && !IS_DIGIT(*p)) p++; Strclear(tmp); while (*p && IS_DIGIT(*p)) Strcat_char(tmp, *(p++)); if (tmp->length == 0) break; pl = New(struct portlist); pl->port = atoi(tmp->ptr); pl->next = first; first = pl; } return first; }
static bool matchMailcapAttr(char *p, char *attr, size_t len, Str *value) { bool quoted = false; char *q = NULL; if (strncasecmp(p, attr, len) == 0) { p += len; SKIP_BLANKS(p); if (value) { *value = Strnew(); if (*p == '=') { p++; SKIP_BLANKS(p); while (*p && (quoted || *p != ';')) { if (quoted || !IS_SPACE(*p)) q = p; if (quoted) quoted = false; else if (*p == '\\') quoted = true; Strcat_char(*value, *p); p++; } if (q) Strshrink(*value, p - q - 1); } return true; } else { if (*p == '\0' || *p == ';') { return true; } } } return false; }
Str wc_conv_from_gb18030(Str is, wc_ces ces) { Str os; wc_uchar *sp = (wc_uchar *)is->ptr; wc_uchar *ep = sp + is->length; wc_uchar *p; int state = WC_GB18030_NOSTATE; wc_uint32 gbk; wc_wchar_t cc; #ifdef USE_UNICODE wc_uint32 ucs; #endif for (p = sp; p < ep && *p < 0x80; p++) ; if (p == ep) return is; os = Strnew_size(is->length); if (p > sp) Strcat_charp_n(os, (char *)is->ptr, (int)(p - sp)); for (; p < ep; p++) { switch (state) { case WC_GB18030_NOSTATE: switch (WC_GB18030_MAP[*p]) { case UB: state = WC_GB18030_MBYTE1; break; case C1: wtf_push_unknown(os, p, 1); break; default: Strcat_char(os, (char)*p); break; } break; case WC_GB18030_MBYTE1: if (WC_GB18030_MAP[*p] & LB) { gbk = ((wc_uint32)*(p-1) << 8) | *p; if (wc_gbk_or_gbk_ext(gbk) == WC_CCS_GBK_EXT) wtf_push(os, WC_CCS_GBK_EXT, gbk); else if (*(p-1) >= 0xA1 && *p >= 0xA1) wtf_push(os, wc_gb2312_or_gbk(gbk), gbk); else wtf_push(os, WC_CCS_GBK, gbk); } else if (WC_GB18030_MAP[*p] == L4) { state = WC_GB18030_MBYTE2; break; } else wtf_push_unknown(os, p-1, 2); state = WC_GB18030_NOSTATE; break; case WC_GB18030_MBYTE2: if (WC_GB18030_MAP[*p] == UB) { state = WC_GB18030_MBYTE3; break; } else wtf_push_unknown(os, p-2, 3); state = WC_GB18030_NOSTATE; break; case WC_GB18030_MBYTE3: if (WC_GB18030_MAP[*p] == L4) { cc.ccs = WC_CCS_GB18030_W; cc.code = ((wc_uint32)*(p-3) << 24) | ((wc_uint32)*(p-2) << 16) | ((wc_uint32)*(p-1) << 8) | *p; #ifdef USE_UNICODE if (WcOption.gb18030_as_ucs && (ucs = wc_gb18030_to_ucs(cc)) != WC_C_UCS4_ERROR) wtf_push(os, WC_CCS_GB18030 | (wc_ucs_to_ccs(ucs) & ~WC_CCS_A_SET), cc.code); else #endif wtf_push(os, cc.ccs, cc.code); } else wtf_push_unknown(os, p-3, 4); state = WC_GB18030_NOSTATE; break; } } switch (state) { case WC_GB18030_MBYTE1: wtf_push_unknown(os, p-1, 1); break; case WC_GB18030_MBYTE2: wtf_push_unknown(os, p-2, 2); break; case WC_GB18030_MBYTE3: wtf_push_unknown(os, p-3, 3); break; } return os; }
InputStream openFTPStream(ParsedURL *pu, URLFile *uf) { Str tmp; int status; char *user = NULL; char *pass = NULL; Str uname = NULL; Str pwd = NULL; int add_auth_cookie_flag = FALSE; char *realpathname = NULL; if (!pu->host) return NULL; if (pu->user == NULL && pu->pass == NULL) { if (find_auth_user_passwd(pu, NULL, &uname, &pwd, 0)) { if (uname) user = uname->ptr; if (pwd) pass = pwd->ptr; } } if (user) /* do nothing */ ; else if (pu->user) user = pu->user; else user = "******"; if (current_ftp.host) { if (!strcmp(current_ftp.host, pu->host) && current_ftp.port == pu->port && !strcmp(current_ftp.user, user)) { ftp_command(¤t_ftp, "NOOP", NULL, &status); if (status != 200) ftp_close(¤t_ftp); else goto ftp_read; } else ftp_quit(¤t_ftp); } if (pass) /* do nothing */ ; else if (pu->pass) pass = pu->pass; else if (pu->user) { pwd = NULL; find_auth_user_passwd(pu, NULL, &uname, &pwd, 0); if (pwd == NULL) { if (fmInitialized) { term_raw(); pwd = Strnew_charp(inputLine("Password: "******"Password: "******"Password: "******"anonymous"); #else tmp = Strnew_charp("anonymous"); #endif /* __MINGW32_VERSION */ Strcat_char(tmp, '@'); pass = tmp->ptr; } if (!current_ftp.host) { current_ftp.host = allocStr(pu->host, -1); current_ftp.port = pu->port; current_ftp.user = allocStr(user, -1); current_ftp.pass = allocStr(pass, -1); if (!ftp_login(¤t_ftp)) return NULL; } if (add_auth_cookie_flag) add_auth_user_passwd(pu, NULL, uname, pwd, 0); ftp_read: ftp_command(¤t_ftp, "TYPE", "I", &status); if (ftp_pasv(¤t_ftp) < 0) { ftp_quit(¤t_ftp); return NULL; } if (pu->file == NULL || *pu->file == '\0' || pu->file[strlen(pu->file) - 1] == '/') goto ftp_dir; realpathname = file_unquote(pu->file); if (*realpathname == '/' && *(realpathname + 1) == '~') realpathname++; /* Get file */ uf->modtime = ftp_modtime(¤t_ftp, realpathname); ftp_command(¤t_ftp, "RETR", realpathname, &status); if (status == 125 || status == 150) return newFileStream(current_ftp.data, (void (*)())closeFTPdata); ftp_dir: pu->scheme = SCM_FTPDIR; return NULL; }
Str checkType(Str s, Lineprop **oprop, Linecolor **ocolor) { Lineprop mode; Lineprop effect = PE_NORMAL; Lineprop *prop; static Lineprop *prop_buffer = NULL; static int prop_size = 0; char *str = s->ptr, *endp = &s->ptr[s->length], *bs = NULL; #ifdef USE_ANSI_COLOR Lineprop ceffect = PE_NORMAL; Linecolor cmode = 0; int check_color = FALSE; Linecolor *color = NULL; static Linecolor *color_buffer = NULL; static int color_size = 0; char *es = NULL; #endif int do_copy = FALSE; int i; int plen = 0, clen; if (prop_size < s->length) { prop_size = (s->length > LINELEN) ? s->length : LINELEN; prop_buffer = New_Reuse(Lineprop, prop_buffer, prop_size); } prop = prop_buffer; if (ShowEffect) { bs = memchr(str, '\b', s->length); #ifdef USE_ANSI_COLOR if (ocolor) { es = memchr(str, ESC_CODE, s->length); if (es) { if (color_size < s->length) { color_size = (s->length > LINELEN) ? s->length : LINELEN; color_buffer = New_Reuse(Linecolor, color_buffer, color_size); } color = color_buffer; } } #endif if ((bs != NULL) #ifdef USE_ANSI_COLOR || (es != NULL) #endif ) { char *sp = str, *ep; s = Strnew_size(s->length); do_copy = TRUE; ep = bs ? (bs - 2) : endp; #ifdef USE_ANSI_COLOR if (es && ep > es - 2) ep = es - 2; #endif for (; str < ep && IS_ASCII(*str); str++) { *(prop++) = PE_NORMAL | (IS_CNTRL(*str) ? PC_CTRL : PC_ASCII); #ifdef USE_ANSI_COLOR if (color) *(color++) = 0; #endif } Strcat_charp_n(s, sp, (int)(str - sp)); } } if (!do_copy) { for (; str < endp && IS_ASCII(*str); str++) *(prop++) = PE_NORMAL | (IS_CNTRL(*str) ? PC_CTRL : PC_ASCII); } while (str < endp) { if (prop - prop_buffer >= prop_size) break; if (bs != NULL) { #ifdef USE_M17N if (str == bs - 2 && !strncmp(str, "__\b\b", 4)) { str += 4; effect = PE_UNDER; if (str < endp) bs = memchr(str, '\b', endp - str); continue; } else #endif if (str == bs - 1 && *str == '_') { str += 2; effect = PE_UNDER; if (str < endp) bs = memchr(str, '\b', endp - str); continue; } else if (str == bs) { if (*(str + 1) == '_') { if (s->length) { str += 2; #ifdef USE_M17N for (i = 1; i <= plen; i++) *(prop - i) |= PE_UNDER; #else *(prop - 1) |= PE_UNDER; #endif } else { str++; } } #ifdef USE_M17N else if (!strncmp(str + 1, "\b__", 3)) { if (s->length) { str += (plen == 1) ? 3 : 4; for (i = 1; i <= plen; i++) *(prop - i) |= PE_UNDER; } else { str += 2; } } else if (*(str + 1) == '\b') { if (s->length) { clen = get_mclen(str + 2); if (plen == clen && !strncmp(str - plen, str + 2, plen)) { for (i = 1; i <= plen; i++) *(prop - i) |= PE_BOLD; str += 2 + clen; } else { Strshrink(s, plen); prop -= plen; str += 2; } } else { str += 2; } } #endif else { if (s->length) { #ifdef USE_M17N clen = get_mclen(str + 1); if (plen == clen && !strncmp(str - plen, str + 1, plen)) { for (i = 1; i <= plen; i++) *(prop - i) |= PE_BOLD; str += 1 + clen; } else { Strshrink(s, plen); prop -= plen; str++; } #else if (*(str - 1) == *(str + 1)) { *(prop - 1) |= PE_BOLD; str += 2; } else { Strshrink(s, 1); prop--; str++; } #endif } else { str++; } } if (str < endp) bs = memchr(str, '\b', endp - str); continue; } #ifdef USE_ANSI_COLOR else if (str > bs) bs = memchr(str, '\b', endp - str); #endif } #ifdef USE_ANSI_COLOR if (es != NULL) { if (str == es) { int ok = parse_ansi_color(&str, &ceffect, &cmode); if (str < endp) es = memchr(str, ESC_CODE, endp - str); if (ok) { if (cmode) check_color = TRUE; continue; } } else if (str > es) es = memchr(str, ESC_CODE, endp - str); } #endif plen = get_mclen(str); mode = get_mctype(str) | effect; #ifdef USE_ANSI_COLOR if (color) { *(color++) = cmode; mode |= ceffect; } #endif *(prop++) = mode; #ifdef USE_M17N if (plen > 1) { mode = (mode & ~PC_WCHAR1) | PC_WCHAR2; for (i = 1; i < plen; i++) { *(prop++) = mode; #ifdef USE_ANSI_COLOR if (color) *(color++) = cmode; #endif } if (do_copy) Strcat_charp_n(s, (char *)str, plen); str += plen; } else #endif { if (do_copy) Strcat_char(s, (char)*str); str++; } effect = PE_NORMAL; } *oprop = prop_buffer; #ifdef USE_ANSI_COLOR if (ocolor) *ocolor = check_color ? color_buffer : NULL; #endif return s; }
Str loadFTPDir0(ParsedURL *pu) #endif { Str FTPDIRtmp; Str tmp; int status; volatile int sv_type; char *realpathname, *fn, *q; char **flist; int i, nfile, nfile_max; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset; *charset = WC_CES_US_ASCII; #endif if (current_ftp.data == NULL) return NULL; tmp = ftp_command(¤t_ftp, "SYST", NULL, &status); if (strstr(tmp->ptr, "UNIX") != NULL || !strncmp(tmp->ptr + 4, "Windows_NT", 10)) /* :-) */ sv_type = UNIXLIKE_SERVER; else sv_type = SERVER_NONE; if (pu->file == NULL || *pu->file == '\0') { if (sv_type == UNIXLIKE_SERVER) ftp_command(¤t_ftp, "LIST", NULL, &status); else ftp_command(¤t_ftp, "NLST", NULL, &status); pu->file = "/"; } else { realpathname = file_unquote(pu->file); if (*realpathname == '/' && *(realpathname + 1) == '~') realpathname++; if (sv_type == UNIXLIKE_SERVER) { ftp_command(¤t_ftp, "CWD", realpathname, &status); if (status == 250) ftp_command(¤t_ftp, "LIST", NULL, &status); } else ftp_command(¤t_ftp, "NLST", realpathname, &status); } if (status != 125 && status != 150) { fclose(current_ftp.data); current_ftp.data = NULL; return NULL; } tmp = parsedURL2Str(pu); if (Strlastchar(tmp) != '/') Strcat_char(tmp, '/'); fn = html_quote(tmp->ptr); tmp = convertLine(NULL, Strnew_charp(file_unquote(tmp->ptr)), RAW_MODE, charset, doc_charset); q = html_quote(tmp->ptr); FTPDIRtmp = Strnew_m_charp("<html>\n<head>\n<base href=\"", fn, "\">\n<title>", q, "</title>\n</head>\n<body>\n<h1>Index of ", q, "</h1>\n", NULL); if (SETJMP(AbortLoading) != 0) { if (sv_type == UNIXLIKE_SERVER) Strcat_charp(FTPDIRtmp, "</a></pre>\n"); else Strcat_charp(FTPDIRtmp, "</a></ul>\n"); Strcat_charp(FTPDIRtmp, "<p>Transfer Interrupted!\n"); goto ftp_end; } TRAP_ON; if (sv_type == UNIXLIKE_SERVER) Strcat_charp(FTPDIRtmp, "<pre>\n"); else Strcat_charp(FTPDIRtmp, "<ul>\n<li>"); Strcat_charp(FTPDIRtmp, "<a href=\"..\">[Upper Directory]</a>\n"); nfile_max = 100; flist = New_N(char *, nfile_max); nfile = 0; if (sv_type == UNIXLIKE_SERVER) { char *name, *link, *date, *size, *type_str; int ftype, max_len, len, j; max_len = 20; while (tmp = Strfgets(current_ftp.data), tmp->length > 0) { Strchop(tmp); if ((ftype = ex_ftpdir_name_size_date(tmp->ptr, &name, &link, &date, &size)) == FTPDIR_NONE) continue; if (!strcmp(".", name) || !strcmp("..", name)) continue; len = strlen(name); if (!len) continue; if (ftype == FTPDIR_DIR) { len++; type_str = "/"; } else if (ftype == FTPDIR_LINK) { len++; type_str = "@"; } else { type_str = " "; } if (max_len < len) max_len = len; flist[nfile++] = Sprintf("%s%s\n%s %5s%s", name, type_str, date, size, link)->ptr; if (nfile == nfile_max) { nfile_max *= 2; flist = New_Reuse(char *, flist, nfile_max); } }
static Str unquote_mailcap_loop(char *qstr, char *type, char *name, char *attr, int *mc_stat, int flag0) { Str str, tmp, test, then; char *p; int status = MC_NORMAL, prev_status = MC_NORMAL, sp = 0, flag; if (mc_stat) *mc_stat = 0; if (qstr == NULL) return NULL; str = Strnew(); tmp = test = then = NULL; for (flag = flag0, p = qstr; *p; p++) { if (status == MC_QUOTED) { if (prev_status == MC_PREC2) Strcat_char(tmp, *p); else Strcat_char(str, *p); status = prev_status; continue; } else if (*p == '\\') { prev_status = status; status = MC_QUOTED; continue; } switch (status) { case MC_NORMAL: if (*p == '%') { status = MC_PREC; } else { if (*p == '\'') { if (!flag0 && flag & MCF_SQUOTED) flag &= ~MCF_SQUOTED; else if (!flag) flag |= MCF_SQUOTED; } else if (*p == '"') { if (!flag0 && flag & MCF_DQUOTED) flag &= ~MCF_DQUOTED; else if (!flag) flag |= MCF_DQUOTED; } Strcat_char(str, *p); } break; case MC_PREC: if (IS_ALPHA(*p)) { switch (*p) { case 's': if (name) { Strcat_charp(str, quote_mailcap(name, flag)->ptr); if (mc_stat) *mc_stat |= MCSTAT_REPNAME; } break; case 't': if (type) { Strcat_charp(str, quote_mailcap(type, flag)->ptr); if (mc_stat) *mc_stat |= MCSTAT_REPTYPE; } break; } status = MC_NORMAL; } else if (*p == '{') { status = MC_PREC2; test = then = NULL; tmp = Strnew(); } else if (*p == '%') { Strcat_char(str, *p); } break; case MC_PREC2: if (sp > 0 || *p == '{') { Strcat_char(tmp, *p); switch (*p) { case '{': ++sp; break; case '}': --sp; break; default: break; } } else if (*p == '}') { char *q; if (attr && (q = strcasestr(attr, tmp->ptr)) != NULL && (q == attr || IS_SPACE(*(q - 1)) || *(q - 1) == ';') && matchattr(q, tmp->ptr, tmp->length, &tmp)) { Strcat_charp(str, quote_mailcap(tmp->ptr, flag)->ptr); if (mc_stat) *mc_stat |= MCSTAT_REPPARAM; } status = MC_NORMAL; } else { Strcat_char(tmp, *p); } break; } } return str; }
Buffer * load_option_panel(void) { Str src; struct param_ptr *p; struct sel_c *s; #ifdef USE_M17N wc_ces_list *c; #endif int x, i; Str tmp; Buffer *buf; if (optionpanel_str == NULL) optionpanel_str = Sprintf(optionpanel_src1, w3m_version, html_quote(localCookie()->ptr), _(CMT_HELPER)); #ifdef USE_M17N #ifdef ENABLE_NLS OptionCharset = SystemCharset; /* FIXME */ #endif if (!OptionEncode) { optionpanel_str = wc_Str_conv(optionpanel_str, OptionCharset, InnerCharset); for (i = 0; sections[i].name != NULL; i++) { sections[i].name = wc_conv(_(sections[i].name), OptionCharset, InnerCharset)->ptr; for (p = sections[i].params; p->name; p++) { p->comment = wc_conv(_(p->comment), OptionCharset, InnerCharset)->ptr; if (p->inputtype == PI_SEL_C #ifdef USE_COLOR && p->select != colorstr #endif ) { for (s = (struct sel_c *)p->select; s->text != NULL; s++) { s->text = wc_conv(_(s->text), OptionCharset, InnerCharset)->ptr; } } } } #ifdef USE_COLOR for (s = colorstr; s->text; s++) s->text = wc_conv(_(s->text), OptionCharset, InnerCharset)->ptr; #endif OptionEncode = TRUE; } #endif src = Strdup(optionpanel_str); Strcat_charp(src, "<table><tr><td>"); for (i = 0; sections[i].name != NULL; i++) { Strcat_m_charp(src, "<h1>", sections[i].name, "</h1>", NULL); p = sections[i].params; Strcat_charp(src, "<table width=100% cellpadding=0>"); while (p->name) { Strcat_m_charp(src, "<tr><td>", p->comment, NULL); Strcat(src, Sprintf("</td><td width=%d>", (int)(28 * pixel_per_char))); switch (p->inputtype) { case PI_TEXT: Strcat_m_charp(src, "<input type=text name=", p->name, " value=\"", html_quote(to_str(p)->ptr), "\">", NULL); break; case PI_ONOFF: x = atoi(to_str(p)->ptr); Strcat_m_charp(src, "<input type=radio name=", p->name, " value=1", (x ? " checked" : ""), ">YES <input type=radio name=", p->name, " value=0", (x ? "" : " checked"), ">NO", NULL); break; case PI_SEL_C: tmp = to_str(p); Strcat_m_charp(src, "<select name=", p->name, ">", NULL); for (s = (struct sel_c *)p->select; s->text != NULL; s++) { Strcat_charp(src, "<option value="); Strcat(src, Sprintf("%s\n", s->cvalue)); if ((p->type != P_CHAR && s->value == atoi(tmp->ptr)) || (p->type == P_CHAR && (char)s->value == *(tmp->ptr))) Strcat_charp(src, " selected"); Strcat_char(src, '>'); Strcat_charp(src, s->text); } Strcat_charp(src, "</select>"); break; #ifdef USE_M17N case PI_CODE: tmp = to_str(p); Strcat_m_charp(src, "<select name=", p->name, ">", NULL); for (c = *(wc_ces_list **) p->select; c->desc != NULL; c++) { Strcat_charp(src, "<option value="); Strcat(src, Sprintf("%s\n", c->name)); if (c->id == atoi(tmp->ptr)) Strcat_charp(src, " selected"); Strcat_char(src, '>'); Strcat_charp(src, c->desc); } Strcat_charp(src, "</select>"); break; #endif } Strcat_charp(src, "</td></tr>\n"); p++; } Strcat_charp(src, "<tr><td></td><td><p><input type=submit value=\"OK\"></td></tr>"); Strcat_charp(src, "</table><hr width=50%>"); } Strcat_charp(src, "</table></form></body></html>"); buf = loadHTMLString(src); #ifdef USE_M17N if (buf) buf->document_charset = OptionCharset; #endif return buf; }
static Str wc_conv_to_ces(Str is, wc_ces ces) { Str os; wc_uchar *sp = (wc_uchar *)is->ptr; wc_uchar *ep = sp + is->length; wc_uchar *p; wc_status st; switch (ces) { case WC_CES_HZ_GB_2312: for (p = sp; p < ep && *p != '~' && *p < 0x80; p++) ; break; case WC_CES_TCVN_5712: case WC_CES_VISCII_11: case WC_CES_VPS: for (p = sp; p < ep && 0x20 <= *p && *p < 0x80; p++) ; break; default: for (p = sp; p < ep && *p < 0x80; p++) ; break; } if (p == ep) return is; os = Strnew_size(is->length); if (p > sp) p--; /* for precompose */ if (p > sp) Strcat_charp_n(os, is->ptr, (int)(p - sp)); wc_output_init(ces, &st); switch (ces) { case WC_CES_ISO_2022_JP: case WC_CES_ISO_2022_JP_2: case WC_CES_ISO_2022_JP_3: case WC_CES_ISO_2022_CN: case WC_CES_ISO_2022_KR: case WC_CES_HZ_GB_2312: case WC_CES_TCVN_5712: case WC_CES_VISCII_11: case WC_CES_VPS: #ifdef USE_UNICODE case WC_CES_UTF_8: case WC_CES_UTF_7: #endif while (p < ep) (*st.ces_info->push_to)(os, wtf_parse(&p), &st); break; default: while (p < ep) { if (*p < 0x80 && wtf_width(p + 1)) { Strcat_char(os, (char)*p); p++; } else (*st.ces_info->push_to)(os, wtf_parse(&p), &st); } break; } wc_push_end(os, &st); return os; }
void wc_push_to_viet(Str os, wc_wchar_t cc, wc_status *st) { wc_ccs ccs1 = st->ces_info->gset[1].ccs; wc_ccs ccs2 = 0, ccs3 = 0; wc_uint8 *map = NULL; switch (st->ces_info->id) { case WC_CES_CP1258: ccs3 = st->ces_info->gset[2].ccs; break; case WC_CES_TCVN_5712: map = wc_c0_tcvn57122_map; ccs2 = st->ces_info->gset[2].ccs; ccs3 = st->ces_info->gset[3].ccs; break; case WC_CES_VISCII_11: map = wc_c0_viscii112_map; ccs2 = st->ces_info->gset[2].ccs; break; case WC_CES_VPS: map = wc_c0_vps2_map; ccs2 = st->ces_info->gset[2].ccs; break; } while (1) { if (cc.ccs == ccs1) { Strcat_char(os, (char)(cc.code | 0x80)); return; } else if (cc.ccs == ccs2) { Strcat_char(os, (char)(cc.code & 0x7f)); return; } else if (cc.ccs == ccs3) { Strcat_char(os, (char)((cc.code >> 8) & 0xff)); Strcat_char(os, (char)(cc.code & 0xff)); return; } switch (cc.ccs) { case WC_CCS_US_ASCII: if (cc.code < 0x20 && map && map[cc.code]) Strcat_char(os, ' '); else Strcat_char(os, (char)cc.code); return; case WC_CCS_UNKNOWN_W: if (!WcOption.no_replace) Strcat_charp(os, WC_REPLACE_W); return; case WC_CCS_UNKNOWN: if (!WcOption.no_replace) Strcat_charp(os, WC_REPLACE); return; default: #ifdef USE_UNICODE if (WcOption.ucs_conv) cc = wc_any_to_any_ces(cc, st); else #endif cc.ccs = WC_CCS_IS_WIDE(cc.ccs) ? WC_CCS_UNKNOWN_W : WC_CCS_UNKNOWN; continue; } }
Str wc_char_conv_from_gb18030(wc_uchar c, wc_status *st) { static Str os; static wc_uchar gb[4]; wc_uint32 gbk; wc_wchar_t cc; #ifdef USE_UNICODE wc_uint32 ucs; #endif if (st->state == -1) { st->state = WC_GB18030_NOSTATE; os = Strnew_size(8); } switch (st->state) { case WC_GB18030_NOSTATE: switch (WC_GB18030_MAP[c]) { case UB: gb[0] = c; st->state = WC_GB18030_MBYTE1; return NULL; case C1: break; default: Strcat_char(os, (char)c); break; } break; case WC_GB18030_MBYTE1: if (WC_GB18030_MAP[c] & LB) { gbk = ((wc_uint32)gb[0] << 8) | c; if (wc_gbk_or_gbk_ext(gbk) == WC_CCS_GBK_EXT) wtf_push(os, WC_CCS_GBK_EXT, gbk); else if (gb[0] >= 0xA1 && c >= 0xA1) wtf_push(os, wc_gb2312_or_gbk(gbk), gbk); else wtf_push(os, WC_CCS_GBK, gbk); } else if (WC_GB18030_MAP[c] == L4) { gb[1] = c; st->state = WC_GB18030_MBYTE2; return NULL; } break; case WC_GB18030_MBYTE2: if (WC_GB18030_MAP[c] == UB) { gb[2] = c; st->state = WC_GB18030_MBYTE3; return NULL; } break; case WC_GB18030_MBYTE3: if (WC_GB18030_MAP[c] == L4) { cc.ccs = WC_CCS_GB18030_W; cc.code = ((wc_uint32)gb[0] << 24) | ((wc_uint32)gb[1] << 16) | ((wc_uint32)gb[2] << 8) | c; #ifdef USE_UNICODE if (WcOption.gb18030_as_ucs && (ucs = wc_gb18030_to_ucs(cc)) != WC_C_UCS4_ERROR) wtf_push(os, WC_CCS_GB18030 | (wc_ucs_to_ccs(ucs) & ~WC_CCS_A_SET), cc.code); else #endif wtf_push(os, cc.ccs, cc.code); } break; } st->state = -1; return os; }