static string parse_identifier (string s, int &i) { int n= N(s), start= i; if (i<n && start_ident (s[i])) { decode_from_utf8 (s, i); while (i<n && continue_ident (s[i])) decode_from_utf8 (s, i); } return as_string (from_verbatim (s (start, i))); }
static void listen_ready_read (int fd) { int s; struct SOCKADDR_IN saddr; int siz = sizeof(saddr); #ifdef CONFIG_IPV6 char buf[HOSTLEN+1]; #else char buf[16]; #endif struct htlc_conn *htlc; s = accept(fd, (struct SOCKADDR *)&saddr, &siz); if (s < 0) { hxd_log("htls: accept: %s", strerror(errno)); return; } if (s >= hxd_open_max) { hxd_log("%s:%d: %d >= hxd_open_max (%d)", __FILE__, __LINE__, s, hxd_open_max); close(s); return; } fd_closeonexec(s, 1); fd_blocking(s, 0); #ifdef CONFIG_IPV6 inet_ntop(AFINET, (char *)&saddr.SIN_ADDR, buf, sizeof(buf)); #else inet_ntoa_r(saddr.SIN_ADDR, buf, sizeof(buf)); #endif hxd_log("%s:%u -- htlc connection accepted", buf, ntohs(saddr.SIN_PORT)); htlc = xmalloc(sizeof(struct htlc_conn)); memset(htlc, 0, sizeof(struct htlc_conn)); htlc->sockaddr = saddr; hxd_files[s].ready_read = htlc_read; hxd_files[s].ready_write = htlc_write; hxd_files[s].conn.htlc = htlc; htlc->fd = s; htlc->rcv = rcv_magic; htlc->trans = 1; htlc->chattrans = 1; htlc->put_limit = hxd_cfg.limits.individual_uploads > HTXF_PUT_MAX ? HTXF_PUT_MAX : hxd_cfg.limits.individual_uploads; htlc->get_limit = hxd_cfg.limits.individual_downloads > HTXF_GET_MAX ? HTXF_GET_MAX : hxd_cfg.limits.individual_downloads; htlc->limit_out_Bps = hxd_cfg.limits.out_Bps; INITLOCK_HTXF(htlc); if (high_fd < s) high_fd = s; htlc->flags.visible = 1; htlc->identfd = -1; if (check_banlist(htlc)) return; htlc->access_extra.can_login = 1; timer_add_secs(14, login_timeout, htlc); if (hxd_cfg.options.ident) { start_ident(htlc); } else { qbuf_set(&htlc->in, 0, HTLC_MAGIC_LEN); FD_SET(s, &hxd_rfds); } }
static tree coqdoc_to_tree (string s) { bool newline= true; int i=0, n= N(s); tree coqdoc (DOCUMENT), line (CONCAT); if (starts (s, "(**")) { line << "(**"; i+= 3; } while (i < n) { if (test (s, i, "[[\n")) { add_line (line, coqdoc); tree vernac= vernac_to_tree (parse_delimited (s, i, "[[\n", "\n]]", false)); coqdoc << compound ("coqdoc-vernac", vernac); newline= true; } else if (s[i] == '[') line << compound ("coqdoc-coq", from_verbatim (parse_delimited (s, i, "[", "]", false))); else if (newline && (test (s, i, "**** ") || test (s, i, "*** ") || test (s, i, "** ") || test (s, i, "* "))) { string header= "section"; if (test (s, i, "** ")) header= "subsection"; if (test (s, i, "*** ")) header= "subsubsection"; if (test (s, i, "**** ")) header= "paragraph"; while (i<n && s[i] == '*') i++; while (i<n && is_spacing (s[i])) i++; int start= i; while (i<n && (s[i] != '\n' && !test (s, i, "*)"))) i++; line << compound (header, coqdoc_to_tree (s (start, i))); } else if (newline && is_defining_pretty_printing (s, i)) { string str= parse_delimited (s, i, "(*", "*)", false); parse_pretty_printing_definition (str); } else if (newline && is_removing_pretty_printing (s, i)) { string str= parse_delimited (s, i, "(*", "*)", false); parse_pretty_printing_removal (str); } else if (test (s, i, "%%")) { line << "%"; newline= false; i+= 2; } else if (test (s, i, "$$")) { line << "$"; newline= false; i+= 2; } else if (test (s, i, "##")) { line << "#"; newline= false; i+= 2; } else if (s[i] == '#' || s[i] == '%' || s[i] == '$') { newline= false; char delim= s[i]; string ext= unescape_coqdoc (parse_delimited (s, i, delim)); tree tm; if (delim == '#') tm= compound ("coqdoc-html", generic_to_tree (ext, "html-snippet")); else if (delim == '$') tm= compound ("coqdoc-latex", generic_to_tree ("$"*ext*"$", "latex-snippet")); else if (delim == '%') tm= compound ("coqdoc-latex", generic_to_tree (ext, "latex-snippet")); if (is_multi_paragraph (tm)) { add_line (line, coqdoc); coqdoc << tm; } else line << tm; } else if (is_list_begining (s, i)) { tree list= parse_list (s, i); add_line (line, coqdoc); coqdoc << list; newline= true; } else if (test (s, i, "\n<<")) { add_line (line, coqdoc); string parsed= parse_delimited (s, i, "\n<<", "\n>>", false); if (N(parsed) > 0 && parsed[0] == '\n') parsed= parsed(1, N(parsed)); tree verb= verbatim_to_tree (parsed, false, "SourceCode"); if (is_atomic (verb)) verb= document (verb); coqdoc << compound ("coqdoc-verbatim", verb); newline= true; } else if (test (s, i, "<<")) { string parsed= parse_delimited (s, i, "<<", ">>", false); tree verb= verbatim_to_tree (parsed, true, "SourceCode"); line << compound ("coqdoc-verbatim", verb); } else if (s[i] == '_' && (i == 0 || !start_ident(s[i-1]))) { line << coqdoc_parse_emphasis (s, i); newline= false; } else if (test (s, i, "----")) { i+= 4; add_line (line, coqdoc); coqdoc << compound ("hrule"); while (i<n && s[i] == '-') i++; newline= true; } else if (s[i] == '\n') { add_line (line, coqdoc); i++; if (is_whiteline (s, i)) { coqdoc << ""; do skip_whiteline (s, i); while (is_whiteline (s, i)); i--; } newline= true; } else if (s[i] == '<') { line << "<less>"; i++; newline= false; } else if (s[i] == '>') { line << "<gtr>"; i++; newline= false; } else { if (!is_spacing (s[i])) newline= false; int start= i; decode_from_utf8 (s, i); line << from_verbatim (s(start, i)); } } if (N(line) > 0) add_line (line, coqdoc); if (N(coqdoc) == 0) return ""; else if (N(coqdoc) == 1) return coqdoc[0]; else return coqdoc; }
static tree coqdoc_parse_emphasis (string s, int &i) { int n= N(s), start= ++i; while (i<n && !(s[i] == '_' && (i+1 >= n || !start_ident (s[i+1])))) i++; return compound ("em", coqdoc_to_tree (s (start, i++))); }
static bool continue_ident (char c) { return start_ident (c) || is_digit (c) || c == '\''; }