示例#1
0
static bool is_query_valid(struct cursor *cursor, uint64_t potential_size, uint8_t offset)
{
    SLOG(LOG_DEBUG, "  Check query valid of potential size %"PRIu64" and offset %"PRIu8, potential_size, offset);
    // We check if last character is printable
    uint64_t last_char_pos = MIN(cursor->cap_len, potential_size) - 1;
    uint8_t last_char = cursor_peek_u8(cursor, last_char_pos);
    if (!is_print(last_char)) {
        SLOG(LOG_DEBUG, "  Last char 0x%02x at pos %"PRIu64" is not printable", last_char, last_char_pos);
        return false;
    }
    // We check if last character + 1 is not printable. If it is printable, size might be incorrect
    // We assume chunked string if size >= 0x40
    if (potential_size < MAX_OCI_CHUNK && potential_size < cursor->cap_len) {
        if (cursor->cap_len - 1 > potential_size)  {
            char next_char = cursor_peek_u8(cursor, potential_size + 1);
            if (is_print(next_char)) {
                SLOG(LOG_DEBUG, "  Char following last char 0x%02x is printable", next_char);
                return false;
            }
        }
    }
    // We check if first characters are printable
    if (PROTO_OK == is_range_print(cursor, MIN_QUERY_SIZE, offset)) {
        return true;
    }
    return false;
}
示例#2
0
文件: buffer.c 项目: dcreager/libcork
void
cork_buffer_append_binary(struct cork_buffer *dest, size_t indent,
                          const char *chars, size_t length)
{
    size_t  i;
    bool  newline = false;

    /* If there are any non-printable characters, print out a hex dump */
    for (i = 0; i < length; i++) {
        if (!is_print(chars[i]) && !is_space(chars[i])) {
            cork_buffer_append_literal(dest, "(hex)\n");
            cork_buffer_append_indent(dest, indent);
            cork_buffer_append_hex_dump(dest, indent, chars, length);
            return;
        } else if (chars[i] == '\n') {
            newline = true;
            /* Don't immediately use the multiline format, since there might be
             * a non-printable character later on that kicks us over to the hex
             * dump format. */
        }
    }

    if (newline) {
        cork_buffer_append_literal(dest, "(multiline)\n");
        cork_buffer_append_indent(dest, indent);
        cork_buffer_append_multiline(dest, indent, chars, length);
    } else {
        cork_buffer_append(dest, chars, length);
    }
}
示例#3
0
static bool check_fixed_query(struct cursor *cursor, uint8_t current,
        uint8_t next, struct query_candidate *candidate)
{
    if (is_print(current) && is_print(next)) {
        for (unsigned i = 0; i < candidate->num_candidate_size; ++i) {
            uint64_t size = candidate->candidate_sizes[i];
            if (is_query_valid(cursor, size, 0)) {
                candidate->query_size = candidate->candidate_sizes[i];
                SLOG(LOG_DEBUG, " Found a fixed query string of size %u", candidate->query_size);
                candidate->is_chunked = false;
                return true;
            }
        }
    }
    return false;
}
示例#4
0
std::string identify_client(peer_id const& p)
{
    peer_id::const_iterator PID = p.begin();
    boost::optional<fingerprint> f;

    if (p.is_all_zeros()) return "Unknown";

    // ----------------------
    // non standard encodings
    // ----------------------

    int num_generic_mappings = sizeof(generic_mappings) / sizeof(generic_mappings[0]);

    for (int i = 0; i < num_generic_mappings; ++i)
    {
        generic_map_entry const& e = generic_mappings[i];
        if (find_string(PID + e.offset, e.id)) return e.name;
    }

    if (find_string(PID, "-BOW") && PID[7] == '-')
        return "Bits on Wheels " + std::string((char const*)PID + 4, (char const*)PID + 7);


    if (find_string(PID, "eX"))
    {
        std::string user((char const*)PID + 2, (char const*)PID + 14);
        return std::string("eXeem ('") + user.c_str() + "')";
    }

    if (std::equal(PID, PID + 13, "\0\0\0\0\0\0\0\0\0\0\0\0\x97"))
        return "Experimental 3.2.1b2";

    if (std::equal(PID, PID + 13, "\0\0\0\0\0\0\0\0\0\0\0\0\0"))
        return "Experimental 3.1";


    // look for azureus style id
    f = parse_az_style(p);
    if (f) return lookup(*f);

    // look for shadow style id
    f = parse_shadow_style(p);
    if (f) return lookup(*f);

    // look for mainline style id
    f = parse_mainline_style(p);
    if (f) return lookup(*f);


    if (std::equal(PID, PID + 12, "\0\0\0\0\0\0\0\0\0\0\0\0"))
        return "Generic";

    std::string unknown("Unknown [");
    for (peer_id::const_iterator i = p.begin(); i != p.end(); ++i)
    {
        unknown += is_print(char(*i))?*i:'.';
    }
    unknown += "]";
    return unknown;
}
示例#5
0
static bool check_chuncked_query(struct cursor *cursor, uint8_t current,
        uint8_t next, struct query_candidate *candidate)
{
    if (is_print(next) && current > MIN_QUERY_SIZE && is_query_valid(cursor, current, 1)) {
        SLOG(LOG_DEBUG, " Found a chunked query with size %"PRIu8, current);
        candidate->query_size = current;
        candidate->is_chunked = true;
        return true;
    }
    return false;
}
示例#6
0
bool print_function(const std::vector<std::string> & tokens, std::ofstream & out_file)
{
	if (not is_print(tokens) )
		return false;
	out_file << "\n\tstd::cout<<"<<tokens[2];
	if(tokens[0] == "println")
		out_file << "<<std::endl;";
	else
		out_file << ';';
	return true;
}
	std::string identify_client_impl(peer_id const& p)
	{
		char const* PID = p.data();

		if (p.is_all_zeros()) return "Unknown";

		// ----------------------
		// non standard encodings
		// ----------------------

		for (auto const& e : generic_mappings)
		{
			if (find_string(PID + e.offset, e.id)) return e.name;
		}

		if (find_string(PID, "-BOW") && PID[7] == '-')
			return "Bits on Wheels " + std::string(PID + 4, PID + 7);

		if (find_string(PID, "eX"))
		{
			std::string user(PID + 2, 12);
			return std::string("eXeem ('") + user + "')";
		}
		bool const is_equ_zero = std::equal(PID, PID + 12, "\0\0\0\0\0\0\0\0\0\0\0\0");

		if (is_equ_zero && PID[12] == '\x97')
			return "Experimental 3.2.1b2";

		if (is_equ_zero && PID[12] == '\0')
			return "Experimental 3.1";

		// look for azureus style id
		boost::optional<fingerprint> f = parse_az_style(p);
		if (f) return lookup(*f);

		// look for shadow style id
		f = parse_shadow_style(p);
		if (f) return lookup(*f);

		// look for mainline style id
		f = parse_mainline_style(p);
		if (f) return lookup(*f);


		if (is_equ_zero)
			return "Generic";

		std::string unknown("Unknown [");
		for (unsigned char const c : p)
			unknown += is_print(char(c)) ? char(c) : '.';
		unknown += "]";
		return unknown;
	}
示例#8
0
 char const*
 parse_token_to_eol(
     char const* p,
     char const* last,
     char const*& token_last,
     error_code& ec)
 {
     for(;; ++p)
     {
         if(p >= last)
         {
             ec = error::need_more;
             return p;
         }
         if(BOOST_UNLIKELY(! is_print(*p)))
             if((BOOST_LIKELY(static_cast<
                     unsigned char>(*p) < '\040') &&
                 BOOST_LIKELY(*p != '\011')) ||
                 BOOST_UNLIKELY(*p == '\177'))
                 goto found_control;
     }
 found_control:
     if(BOOST_LIKELY(*p == '\r'))
     {
         if(++p >= last)
         {
             ec = error::need_more;
             return last;
         }
         if(*p++ != '\n')
         {
             ec = error::bad_line_ending;
             return last;
         }
         token_last = p - 2;
     }
 #if 0
     // VFALCO This allows `\n` by itself
     //        to terminate a line
     else if(*p == '\n')
     {
         token_last = p;
         ++p;
     }
 #endif
     else
     {
         // invalid character
         return nullptr;
     }
     return p;
 }
示例#9
0
static enum proto_parse_status is_range_print(struct cursor *cursor, size_t size, size_t offset)
{
    CHECK(size + offset);
    SLOG(LOG_DEBUG, "Check range print with size %zu, and offset %zu", size, offset);
    for (size_t i = 0; i < size; i++) {
        uint8_t chr = cursor_peek_u8(cursor, i + offset);
        if (!is_print(chr)) {
            SLOG(LOG_DEBUG, "Character 0x%"PRIx8" at %zu is not printable", chr, i);
            return PROTO_PARSE_ERR;
        }
    }
    return PROTO_OK;
}
示例#10
0
int256_t P2(int128_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_int128(limit))
    throw primesum_error("P2(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);
  return P2(x, y, threads);
}
示例#11
0
文件: term.c 项目: joshuaeilers/jos
void term_putchar(uint8_t c) {
	if (c == '\n') {
		term_col = 0;
		term_row++;
	} else if (is_print(c)) {
		term_buf[term_row * VGA_WIDTH + term_col] = term_char(c, term_rgb);

		if (++term_col >= VGA_WIDTH) {
			term_col = 0;
			term_row++;
		}
	}

	if (term_row >= VGA_HEIGHT) {
		memcpy(term_buf, term_buf + VGA_WIDTH, (VGA_HEIGHT - 1) * VGA_WIDTH * sizeof(uint16_t));
		memsetw(term_buf + (VGA_HEIGHT - 1) * VGA_WIDTH, term_char(' ', term_rgb), VGA_WIDTH);
		term_row = VGA_HEIGHT - 1;
	}
}
示例#12
0
int split_string(char const** tags, int buf_size, char* in)
{
    int ret = 0;
    char* i = in;
    for (; *i; ++i)
    {
        if (!is_print(*i) || is_space(*i))
        {
            *i = 0;
            if (ret == buf_size) return ret;
            continue;
        }
        if (i == in || i[-1] == 0)
        {
            tags[ret++] = i;
        }
    }
    return ret;
}
示例#13
0
int256_t S2_hard(int128_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_int128(limit))
    throw primesum_error("S2_hard(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);
  int64_t z = (int64_t) (x / y);
  int64_t c = PhiTiny::get_c(y);

  return S2_hard(x, y, z, c, threads);
}
示例#14
0
maxint_t P2(maxint_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_maxint(limit))
    throw primecount_error("P2(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);

  if (x <= numeric_limits<int64_t>::max())
    return P2((int64_t) x, y, threads);
  else
    return P2(x, y, threads);
}
示例#15
0
文件: match.c 项目: sylware/lwl
//input: *c=='[' **pc==':'
static u16 bracket_class(u8 *c,u8 **pc,u8 **sc,u8 not,u8 sc_folded)
{
  u8 char_class[CHAR_CLASS_MAX+1];//don't forget the 0 terminating char

  u16 r=bracket_char_class_get(c,pc,not,sc_folded,&char_class[0]);
  if(r!=OK) return r;

  if((STREQ(char_class,"alnum")&&is_alnum(**sc))
     ||(STREQ(char_class,"alpha")&&is_alpha(**sc))
     ||(STREQ(char_class,"blank")&&is_blank(**sc))
     ||(STREQ(char_class,"cntrl")&&is_cntrl(**sc))
     ||(STREQ(char_class,"digit")&&is_digit(**sc))
     ||(STREQ(char_class,"graph")&&is_graph(**sc))
     ||(STREQ(char_class,"lower")&&is_lower(**sc))
     ||(STREQ(char_class,"print")&&is_print(**sc))
     ||(STREQ(char_class,"punct")&&is_punct(**sc))
     ||(STREQ(char_class,"space")&&is_space(**sc))
     ||(STREQ(char_class,"upper")&&is_upper(**sc))
     ||(STREQ(char_class,"xdigit")&&is_xdigit(**sc)))
    return bracket_matched(c,pc,not);
  *c=*(*pc)++;
  return OK;
}
示例#16
0
maxint_t S2_hard(maxint_t x, int threads)
{
  if (x < 1)
    return 0;

  double alpha = get_alpha_deleglise_rivat(x);
  string limit = get_max_x(alpha);

  if (x > to_maxint(limit))
    throw primecount_error("S2_hard(x): x must be <= " + limit);

  if (is_print())
    set_print_variables(true);

  int64_t y = (int64_t) (iroot<3>(x) * alpha);
  int64_t z = (int64_t) (x / y);
  int64_t c = PhiTiny::get_c(y);

  if (x <= numeric_limits<int64_t>::max())
    return S2_hard((int64_t) x, y, z, c, (int64_t) Ri(x), threads);
  else
    return S2_hard(x, y, z, c, Ri(x), threads);
}
示例#17
0
	void entry::to_string_impl(std::string& out, int const indent) const
	{
		TORRENT_ASSERT(indent >= 0);
		for (int i = 0; i < indent; ++i) out += ' ';
		switch (type())
		{
		case int_t:
			out += libtorrent::to_string(integer()).data();
			out += '\n';
			break;
		case string_t:
			{
				bool binary_string = false;
				for (auto const i : string())
				{
					if (!is_print(i))
					{
						binary_string = true;
						break;
					}
				}
				if (binary_string)
				{
					out += aux::to_hex(string());
					out += '\n';
				}
				else
				{
					out += string();
					out += '\n';
				}
			} break;
		case list_t:
			{
				out += "list\n";
				for (auto const& i : list())
				{
					i.to_string_impl(out, indent + 1);
				}
			} break;
		case dictionary_t:
			{
				out += "dictionary\n";
				for (auto const& i : dict())
				{
					bool binary_string = false;
					for (auto const k : i.first)
					{
						if (!is_print(k))
						{
							binary_string = true;
							break;
						}
					}
					for (int j = 0; j < indent + 1; ++j) out += ' ';
					out += '[';
					if (binary_string) out += aux::to_hex(i.first);
					else out += i.first;
					out += ']';

					if (i.second.type() != entry::string_t
						&& i.second.type() != entry::int_t)
						out += '\n';
					else out += ' ';
					i.second.to_string_impl(out, indent + 2);
				}
			} break;
		case preformatted_t:
			out += "<preformatted>\n";
			break;
		case undefined_t:
			out += "<uninitialized>\n";
		}
	}
示例#18
0
static enum proto_parse_status tns_parse_sql_query_oci(struct sql_proto_info *info, struct cursor *cursor)
{
    SLOG(LOG_DEBUG, "Parsing an oci query");
    uint8_t query_size = parse_query_header(cursor);
    struct query_candidate candidate = {.num_candidate_size = 0};
    if (query_size > 0) {
        candidate.candidate_sizes[candidate.num_candidate_size++] = query_size;
    }

    bool has_query = lookup_query(cursor, &candidate);
    info->u.query.sql[0] = '\0';
    info->u.query.truncated = 0;
    if (has_query) {
        SLOG(LOG_DEBUG, "Found a query, parsing it");
        if (candidate.is_chunked) {
            cursor_read_chunked_string(cursor, info->u.query.sql, sizeof(info->u.query.sql), MAX_OCI_CHUNK);
        } else {
            cursor_read_fixed_string(cursor, info->u.query.sql, sizeof(info->u.query.sql), candidate.query_size);
        }
    }
    SLOG(LOG_DEBUG, "Sql parsed: %s", info->u.query.sql);
    info->set_values |= SQL_SQL;
    // Drop the rest
    if(cursor->cap_len > 0) cursor_drop(cursor, cursor->cap_len - 1);
    return PROTO_OK;
}

/*
 * | 1 byte | 1 + 0-8 bytes | 1 byte | 1 + 0-4 bytes  | Lots of unknown bytes | variable  |
 * | Unk    | Sql len       | Unk    | Num end fields | Unk                   | sql query |
 */
static enum proto_parse_status tns_parse_sql_query_jdbc(struct sql_proto_info *info, struct cursor *cursor)
{
    SLOG(LOG_DEBUG, "Parsing a jdbc query");
    enum proto_parse_status status = PROTO_OK;

    DROP_FIX(cursor, 1);

    uint_least64_t sql_len;
    if (PROTO_OK != (status = cursor_read_variable_int(cursor, &sql_len))) return status;
    SLOG(LOG_DEBUG, "Size sql %zu", sql_len);

    DROP_FIX(cursor, 1);
    DROP_VAR(cursor);
    DROP_FIX(cursor, 2);

    info->u.query.sql[0] = '\0';
    info->u.query.truncated = 0; // TODO Handle truncated
    if (sql_len > 0) {
        // Some unknown bytes
        while (cursor->cap_len > 1 && PROTO_OK != is_range_print(cursor, MIN(MIN_QUERY_SIZE, sql_len), 1)) {
            // TODO drop to the first non printable
            cursor_drop(cursor, 1);
        }
        CHECK(1);
        if (sql_len > 0xff && 0xff == cursor_peek_u8(cursor, 0)) {
            SLOG(LOG_DEBUG, "Looks like prefixed length chunks of size 0xff...");
            status = cursor_read_chunked_string(cursor, info->u.query.sql, sizeof(info->u.query.sql), 0xff);
        } else if (sql_len > MAX_OCI_CHUNK && MAX_OCI_CHUNK == cursor_peek_u8(cursor, 0)) {
            SLOG(LOG_DEBUG, "Looks like prefixed length chunks of size 0x40...");
            status = cursor_read_chunked_string(cursor, info->u.query.sql, sizeof(info->u.query.sql),
                    MAX_OCI_CHUNK);
        } else {
            // We don't care about the first non printable character
            cursor_drop(cursor, 1);
            CHECK(1);
            // In rare occurrence where sql_len == first character, we check the byte after the expected query,
            // if it's printable, the first character is probably the prefixed size.
            if (cursor_peek_u8(cursor, 0) == sql_len && sql_len < cursor->cap_len && is_print(cursor_peek_u8(cursor, sql_len)))
                cursor_drop(cursor, 1);
            SLOG(LOG_DEBUG, "Looks like a fixed string of size %zu", sql_len);
            int written_bytes = cursor_read_fixed_string(cursor, info->u.query.sql,
                    sizeof(info->u.query.sql), sql_len);
            if (written_bytes < 0) return PROTO_TOO_SHORT;
        }
        if (status != PROTO_OK) return status;
    }
    SLOG(LOG_DEBUG, "Sql parsed: %s", info->u.query.sql);
    info->set_values |= SQL_SQL;

    return PROTO_OK;
}
示例#19
0
static void
output_tables (const char *filename, const char *version)
{
  FILE *stream;
  unsigned int ch;

  stream = fopen (filename, "w");
  if (stream == NULL)
    {
      fprintf (stderr, "cannot open '%s' for writing\n", filename);
      exit (1);
    }

  fprintf (stream, "escape_char /\n");
  fprintf (stream, "comment_char %%\n");
  fprintf (stream, "\n");
  fprintf (stream, "%% Generated automatically by gen-unicode-ctype for Unicode %s.\n",
	   version);
  fprintf (stream, "\n");

  fprintf (stream, "LC_IDENTIFICATION\n");
  fprintf (stream, "title     \"Unicode %s FDCC-set\"\n", version);
  fprintf (stream, "source    \"UnicodeData.txt, PropList.txt\"\n");
  fprintf (stream, "address   \"\"\n");
  fprintf (stream, "contact   \"\"\n");
  fprintf (stream, "email     \"[email protected]\"\n");
  fprintf (stream, "tel       \"\"\n");
  fprintf (stream, "fax       \"\"\n");
  fprintf (stream, "language  \"\"\n");
  fprintf (stream, "territory \"Earth\"\n");
  fprintf (stream, "revision  \"%s\"\n", version);
  {
    time_t now;
    char date[11];
    now = time (NULL);
    strftime (date, sizeof (date), "%Y-%m-%d", gmtime (&now));
    fprintf (stream, "date      \"%s\"\n", date);
  }
  fprintf (stream, "category  \"unicode:2001\";LC_CTYPE\n");
  fprintf (stream, "END LC_IDENTIFICATION\n");
  fprintf (stream, "\n");

  /* Verifications. */
  for (ch = 0; ch < 0x110000; ch++)
    {
      /* toupper restriction: "Only characters specified for the keywords
	 lower and upper shall be specified.  */
      if (to_upper (ch) != ch && !(is_lower (ch) || is_upper (ch)))
	fprintf (stderr,
		 "%s is not upper|lower but toupper(0x%04X) = 0x%04X\n",
		 ucs_symbol (ch), ch, to_upper (ch));

      /* tolower restriction: "Only characters specified for the keywords
	 lower and upper shall be specified.  */
      if (to_lower (ch) != ch && !(is_lower (ch) || is_upper (ch)))
	fprintf (stderr,
		 "%s is not upper|lower but tolower(0x%04X) = 0x%04X\n",
		 ucs_symbol (ch), ch, to_lower (ch));

      /* alpha restriction: "Characters classified as either upper or lower
	 shall automatically belong to this class.  */
      if ((is_lower (ch) || is_upper (ch)) && !is_alpha (ch))
	fprintf (stderr, "%s is upper|lower but not alpha\n", ucs_symbol (ch));

      /* alpha restriction: "No character specified for the keywords cntrl,
	 digit, punct or space shall be specified."  */
      if (is_alpha (ch) && is_cntrl (ch))
	fprintf (stderr, "%s is alpha and cntrl\n", ucs_symbol (ch));
      if (is_alpha (ch) && is_digit (ch))
	fprintf (stderr, "%s is alpha and digit\n", ucs_symbol (ch));
      if (is_alpha (ch) && is_punct (ch))
	fprintf (stderr, "%s is alpha and punct\n", ucs_symbol (ch));
      if (is_alpha (ch) && is_space (ch))
	fprintf (stderr, "%s is alpha and space\n", ucs_symbol (ch));

      /* space restriction: "No character specified for the keywords upper,
	 lower, alpha, digit, graph or xdigit shall be specified."
	 upper, lower, alpha already checked above.  */
      if (is_space (ch) && is_digit (ch))
	fprintf (stderr, "%s is space and digit\n", ucs_symbol (ch));
      if (is_space (ch) && is_graph (ch))
	fprintf (stderr, "%s is space and graph\n", ucs_symbol (ch));
      if (is_space (ch) && is_xdigit (ch))
	fprintf (stderr, "%s is space and xdigit\n", ucs_symbol (ch));

      /* cntrl restriction: "No character specified for the keywords upper,
	 lower, alpha, digit, punct, graph, print or xdigit shall be
	 specified."  upper, lower, alpha already checked above.  */
      if (is_cntrl (ch) && is_digit (ch))
	fprintf (stderr, "%s is cntrl and digit\n", ucs_symbol (ch));
      if (is_cntrl (ch) && is_punct (ch))
	fprintf (stderr, "%s is cntrl and punct\n", ucs_symbol (ch));
      if (is_cntrl (ch) && is_graph (ch))
	fprintf (stderr, "%s is cntrl and graph\n", ucs_symbol (ch));
      if (is_cntrl (ch) && is_print (ch))
	fprintf (stderr, "%s is cntrl and print\n", ucs_symbol (ch));
      if (is_cntrl (ch) && is_xdigit (ch))
	fprintf (stderr, "%s is cntrl and xdigit\n", ucs_symbol (ch));

      /* punct restriction: "No character specified for the keywords upper,
	 lower, alpha, digit, cntrl, xdigit or as the <space> character shall
	 be specified."  upper, lower, alpha, cntrl already checked above.  */
      if (is_punct (ch) && is_digit (ch))
	fprintf (stderr, "%s is punct and digit\n", ucs_symbol (ch));
      if (is_punct (ch) && is_xdigit (ch))
	fprintf (stderr, "%s is punct and xdigit\n", ucs_symbol (ch));
      if (is_punct (ch) && (ch == 0x0020))
	fprintf (stderr, "%s is punct\n", ucs_symbol (ch));

      /* graph restriction: "No character specified for the keyword cntrl
	 shall be specified."  Already checked above.  */

      /* print restriction: "No character specified for the keyword cntrl
	 shall be specified."  Already checked above.  */

      /* graph - print relation: differ only in the <space> character.
	 How is this possible if there are more than one space character?!
	 I think susv2/xbd/locale.html should speak of "space characters",
	 not "space character".  */
      if (is_print (ch) && !(is_graph (ch) || /* ch == 0x0020 */ is_space (ch)))
	fprintf (stderr,
		 "%s is print but not graph|<space>\n", ucs_symbol (ch));
      if (!is_print (ch) && (is_graph (ch) || ch == 0x0020))
	fprintf (stderr,
		 "%s is graph|<space> but not print\n", ucs_symbol (ch));
    }

  fprintf (stream, "LC_CTYPE\n");
  output_charclass (stream, "upper", is_upper);
  output_charclass (stream, "lower", is_lower);
  output_charclass (stream, "alpha", is_alpha);
  output_charclass (stream, "digit", is_digit);
  output_charclass (stream, "outdigit", is_outdigit);
  output_charclass (stream, "blank", is_blank);
  output_charclass (stream, "space", is_space);
  output_charclass (stream, "cntrl", is_cntrl);
  output_charclass (stream, "punct", is_punct);
  output_charclass (stream, "xdigit", is_xdigit);
  output_charclass (stream, "graph", is_graph);
  output_charclass (stream, "print", is_print);
  output_charclass (stream, "class \"combining\";", is_combining);
  output_charclass (stream, "class \"combining_level3\";", is_combining_level3);
  output_charmap (stream, "toupper", to_upper);
  output_charmap (stream, "tolower", to_lower);
  output_charmap (stream, "map \"totitle\";", to_title);
  output_widthmap (stream);
  fprintf (stream, "END LC_CTYPE\n");

  if (ferror (stream) || fclose (stream))
    {
      fprintf (stderr, "error writing to '%s'\n", filename);
      exit (1);
    }
}
示例#20
0
	void entry::to_string_impl(std::string& out, int indent) const
	{
		TORRENT_ASSERT(indent >= 0);
		for (int i = 0; i < indent; ++i) out += " ";
		switch (m_type)
		{
		case int_t:
			out += libtorrent::to_string(integer()).elems;
			out += "\n";
			break;
		case string_t:
			{
				bool binary_string = false;
				for (std::string::const_iterator i = string().begin(); i != string().end(); ++i)
				{
					if (!is_print(static_cast<unsigned char>(*i)))
					{
						binary_string = true;
						break;
					}
				}
				if (binary_string)
				{
					out += to_hex(string());
					out += "\n";
				}
				else
				{
					out += string();
					out += "\n";
				}
			} break;
		case list_t:
			{
				out += "list\n";
				for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
				{
					i->to_string_impl(out, indent+1);
				}
			} break;
		case dictionary_t:
			{
				out += "dictionary\n";
				for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
				{
					bool binary_string = false;
					for (std::string::const_iterator k = i->first.begin(); k != i->first.end(); ++k)
					{
						if (!is_print(static_cast<unsigned char>(*k)))
						{
							binary_string = true;
							break;
						}
					}
					for (int j = 0; j < indent+1; ++j) out += " ";
					out += "[";
					if (binary_string) out += to_hex(i->first);
					else out += i->first;
					out += "]";

					if (i->second.type() != entry::string_t
						&& i->second.type() != entry::int_t)
						out += "\n";
					else out += " ";
					i->second.to_string_impl(out, indent+2);
				}
			} break;
		case undefined_t:
		default:
			out += "<uninitialized>\n";
		}
	}
示例#21
0
static enum proto_parse_status tns_parse_end(struct sql_proto_info *info, struct cursor *cursor)
{
    SLOG(LOG_DEBUG, "Parsing tns end packet");
    enum proto_parse_status status;

    uint_least64_t var[6];
    for (unsigned i = 0; i < 6; i++) {
        if (PROTO_OK != (status = cursor_read_variable_int(cursor, var + i))) return status;
    }

    uint_least64_t nb_rows;
    uint_least64_t error_code;

    // let's use the double 0x00 to guess the position of row number and error code
    if (var[0] > 0 && var[4] == 0 && var[5] == 0) {
        // var[0] is unknown?
        // var[1] == sequence
        // var[2] == rows
        // var[3] == error code
        SLOG(LOG_DEBUG, "Unknown bits after ttc code");
        nb_rows = var[2];
        error_code = var[3];
        DROP_VAR(cursor);
    } else if (var[3] == 0 && var[4] == 0) {
        // var[0] == sequence
        // var[1] == rows
        // var[2] == error code
        nb_rows = var[1];
        error_code = var[2];
    } else {
        // var[0] == rows
        // var[1] == error code
        nb_rows = var[0];
        error_code = var[1];
    }

    if (info->msg_type == SQL_QUERY) {
        sql_set_row_count(info, nb_rows);
        SLOG(LOG_DEBUG, "Nb rows %d", info->u.query.nb_rows);
    }
    SLOG(LOG_DEBUG, "Error code is %zu", error_code);

    DROP_VARS(cursor, 1);
    DROP_FIX(cursor, 2);
    DROP_VARS(cursor, 2);
    DROP_FIX(cursor, 2);
    DROP_VARS(cursor, 2);
    DROP_FIX(cursor, 1);
    DROP_VARS(cursor, 3);

    if (error_code != 0) {
        SLOG(LOG_DEBUG, "Parsing error message");
        char *error_msg = tempstr();
        unsigned error_len;

        // Drop an unknown number of bytes here
        while(cursor->cap_len > 2 && (cursor_peek_u8(cursor, 0) == 0 || !is_print(cursor_peek_u8(cursor, 1)))){
            DROP_FIX(cursor, 1);
        }
        SLOG(LOG_DEBUG, "First printable char is %c", cursor_peek_u8(cursor, 1));
        status = cursor_read_variable_string(cursor, error_msg, TEMPSTR_SIZE, &error_len);
        if (status != PROTO_OK) return status;
        if (error_len < 12) return PROTO_PARSE_ERR;
        // Split "ORA-XXXX: msg"
        // Part before : is the error code
        // Part after is the localized message
        char *colon_pos = memchr(error_msg, ':', error_len);
        sql_set_request_status(info, SQL_REQUEST_ERROR);
        if (colon_pos) {
            // We extract the error code
            unsigned error_code_size = colon_pos - error_msg;
            int size_err = MIN(error_code_size, sizeof(info->error_code));
            memcpy(info->error_code, error_msg, size_err);
            info->error_code[size_err] = '\0';
            info->set_values |= SQL_ERROR_CODE;
            if (0 == strcmp("ORA-01403", info->error_code))
                info->request_status = SQL_REQUEST_COMPLETE;

            // We skip ':' in errror message
            char const *start_message = colon_pos + 1;
            // We skip spaces before errror message
            while (start_message < error_len + error_msg && *start_message == ' ')
                start_message++;

            copy_string(info->error_message, start_message, sizeof(info->error_message));
            info->set_values |= SQL_ERROR_MESSAGE;
        } else {
            copy_string(info->error_message, error_msg, sizeof(info->error_message));
            info->set_values |= SQL_ERROR_MESSAGE;
        }
    }

    return PROTO_OK;
}
示例#22
0
文件: entry.cpp 项目: kknet/PopcornTV
void entry::print(std::ostream& os, int indent) const
{
    TORRENT_ASSERT(indent >= 0);
    for (int i = 0; i < indent; ++i) os << " ";
    switch (m_type)
    {
    case int_t:
        os << integer() << "\n";
        break;
    case string_t:
    {
        bool binary_string = false;
        for (std::string::const_iterator i = string().begin(); i != string().end(); ++i)
        {
            if (!is_print(static_cast<unsigned char>(*i)))
            {
                binary_string = true;
                break;
            }
        }
        if (binary_string) os << to_hex(string()) << "\n";
        else os << string() << "\n";
    }
    break;
    case list_t:
    {
        os << "list\n";
        for (list_type::const_iterator i = list().begin(); i != list().end(); ++i)
        {
            i->print(os, indent+1);
        }
    }
    break;
    case dictionary_t:
    {
        os << "dictionary\n";
        for (dictionary_type::const_iterator i = dict().begin(); i != dict().end(); ++i)
        {
            bool binary_string = false;
            for (std::string::const_iterator k = i->first.begin(); k != i->first.end(); ++k)
            {
                if (!is_print(static_cast<unsigned char>(*k)))
                {
                    binary_string = true;
                    break;
                }
            }
            for (int j = 0; j < indent+1; ++j) os << " ";
            os << "[";
            if (binary_string) os << to_hex(i->first);
            else os << i->first;
            os << "]";

            if (i->second.type() != entry::string_t
                    && i->second.type() != entry::int_t)
                os << "\n";
            else os << " ";
            i->second.print(os, indent+2);
        }
    }
    break;
    default:
        os << "<uninitialized>\n";
    }
}
示例#23
0
文件: char.hpp 项目: semenovf/pfs
inline bool is_print<unicode::char_t> (unicode::char_t c)
{
    return c.value <= 127 && is_print(static_cast<char>(c.value));
}
示例#24
0
文件: edit.c 项目: ISLEcode/kornshell
void	ed_setup(register Edit_t *ep, int fd, int reedit)
{
	Shell_t *shp = ep->sh;
	register char *pp;
	register char *last, *prev;
	char *ppmax;
	int myquote = 0, n;
	register int qlen = 1, qwid;
	char inquote = 0;
	ep->e_fd = fd;
	ep->e_multiline = sh_isoption(SH_MULTILINE)!=0;
#ifdef SIGWINCH
	if(!(shp->sigflag[SIGWINCH]&SH_SIGFAULT))
	{
		signal(SIGWINCH,sh_fault);
		shp->sigflag[SIGWINCH] |= SH_SIGFAULT;
	}
	pp = shp->st.trapcom[SIGWINCH];
	shp->st.trapcom[SIGWINCH] = 0;
	sh_fault(SIGWINCH);
	shp->st.trapcom[SIGWINCH] = pp;
	ep->sh->winch = 0;
#endif
#if SHOPT_EDPREDICT
	ep->hlist = 0;
	ep->nhlist = 0;
	ep->hoff = 0;
#endif /* SHOPT_EDPREDICT */
#if KSHELL
	ep->e_stkptr = stakptr(0);
	ep->e_stkoff = staktell();
	if(!(last = shp->prompt))
		last = "";
	shp->prompt = 0;
#else
	last = ep->e_prbuff;
#endif /* KSHELL */
	if(shp->gd->hist_ptr)
	{
		register History_t *hp = shp->gd->hist_ptr;
		ep->e_hismax = hist_max(hp);
		ep->e_hismin = hist_min(hp);
	}
	else
	{
		ep->e_hismax = ep->e_hismin = ep->e_hloff = 0;
	}
	ep->e_hline = ep->e_hismax;
	if(!sh_isoption(SH_VI) && !sh_isoption(SH_EMACS) && !sh_isoption(SH_GMACS))
		ep->e_wsize = MAXLINE;
	else
		ep->e_wsize = ed_window()-2;
	ep->e_winsz = ep->e_wsize+2;
	ep->e_crlf = 1;
	ep->e_plen = 0;
	pp = ep->e_prompt;
	ppmax = pp+PRSIZE-1;
	*pp++ = '\r';
	{
		register int c;
		while(prev = last, c = mbchar(last)) switch(c)
		{
			case ESC:
			{
				int skip=0;
				ep->e_crlf = 0;
				*pp++ = c;
				for(n=1; c = *last++; n++)
				{
					if(pp < ppmax)
						*pp++ = c;
					if(c=='\a' || c==ESC || c=='\r')
						break;
					if(skip || (c>='0' && c<='9'))
					{
						skip = 0;
						continue;
					}
					if(n>1 && c==';')
						skip = 1;
					else if(n>2 || (c!= '[' &&  c!= ']'))
						break;
				}
				if(c==0 || c==ESC || c=='\r')
					last--;
				qlen += (n+1);
				break;
			}
			case '\b':
				if(pp>ep->e_prompt+1)
					pp--;
				break;
			case '\r':
				if(pp == (ep->e_prompt+2)) /* quote char */
					myquote = *(pp-1);
				/*FALLTHROUGH*/

			case '\n':
				/* start again */
				ep->e_crlf = 1;
				qlen = 1;
				inquote = 0;
				pp = ep->e_prompt+1;
				break;

			case '\t':
				/* expand tabs */
				while((pp-ep->e_prompt)%TABSIZE)
				{
					if(pp >= ppmax)
						break;
					*pp++ = ' ';
				}
				break;

			case '\a':
				/* cut out bells */
				break;

			default:
				if(c==myquote)
				{
					qlen += inquote;
					inquote ^= 1;
				}
				if(pp < ppmax)
				{
					if(inquote)
						qlen++;
					else if(!is_print(c))
						ep->e_crlf = 0;
					if((qwid = last - prev) > 1)
						qlen += qwid - mbwidth(c);
					while(prev < last && pp < ppmax)
						*pp++ = *prev++;
				}
				break;
		}
	}
	if(pp-ep->e_prompt > qlen)
		ep->e_plen = pp - ep->e_prompt - qlen;
	*pp = 0;
	if(!ep->e_multiline && (ep->e_wsize -= ep->e_plen) < 7)
	{
		register int shift = 7-ep->e_wsize;
		ep->e_wsize = 7;
		pp = ep->e_prompt+1;
		strcpy(pp,pp+shift);
		ep->e_plen -= shift;
		last[-ep->e_plen-2] = '\r';
	}
	sfsync(sfstderr);
	if(fd == sffileno(sfstderr))
	{
		/* can't use output buffer when reading from stderr */
		static char *buff;
		if(!buff)
			buff = (char*)malloc(MAXLINE);
		ep->e_outbase = ep->e_outptr = buff;
		ep->e_outlast = ep->e_outptr + MAXLINE;
		return;
	}
	qlen = sfset(sfstderr,SF_READ,0);
	/* make sure SF_READ not on */
	ep->e_outbase = ep->e_outptr = (char*)sfreserve(sfstderr,SF_UNBOUND,SF_LOCKR);
	ep->e_outlast = ep->e_outptr + sfvalue(sfstderr);
	if(qlen)
		sfset(sfstderr,SF_READ,1);
	sfwrite(sfstderr,ep->e_outptr,0);
	ep->e_eol = reedit;
	if(ep->e_multiline)
	{
#ifdef _cmd_tput
		char *term;
		if(!ep->e_term)
			ep->e_term = nv_search("TERM",shp->var_tree,0);
		if(ep->e_term && (term=nv_getval(ep->e_term)) && strlen(term)<sizeof(ep->e_termname) && strcmp(term,ep->e_termname))
		{
			sh_trap(".sh.subscript=$(tput cuu1 2>/dev/null)",0);
			if(pp=nv_getval(SH_SUBSCRNOD))
				strncpy(CURSOR_UP,pp,sizeof(CURSOR_UP)-1);
			nv_unset(SH_SUBSCRNOD);
			strcpy(ep->e_termname,term);
		}
#endif
		ep->e_wsize = MAXLINE - (ep->e_plen+1);
	}
	if(ep->e_default && (pp = nv_getval(ep->e_default)))
	{
		n = strlen(pp);
		if(n > LOOKAHEAD)
			n = LOOKAHEAD;
		ep->e_lookahead = n;
		while(n-- > 0)
			ep->e_lbuf[n] = *pp++;
		ep->e_default = 0;
	}
}