示例#1
0
文件: pretty.c 项目: CookieChen/git
static void add_rfc2047(struct strbuf *sb, const char *line, size_t len,
		       const char *encoding, enum rfc2047_type type)
{
	static const int max_encoded_length = 76; /* per rfc2047 */
	int i;
	int line_len = last_line_length(sb);

	strbuf_grow(sb, len * 3 + strlen(encoding) + 100);
	strbuf_addf(sb, "=?%s?q?", encoding);
	line_len += strlen(encoding) + 5; /* 5 for =??q? */

	while (len) {
		/*
		 * RFC 2047, section 5 (3):
		 *
		 * Each 'encoded-word' MUST represent an integral number of
		 * characters.  A multi-octet character may not be split across
		 * adjacent 'encoded- word's.
		 */
		const unsigned char *p = (const unsigned char *)line;
		int chrlen = mbs_chrlen(&line, &len, encoding);
		int is_special = (chrlen > 1) || is_rfc2047_special(*p, type);

		/* "=%02X" * chrlen, or the byte itself */
		const char *encoded_fmt = is_special ? "=%02X"    : "%c";
		int	    encoded_len = is_special ? 3 * chrlen : 1;

		/*
		 * According to RFC 2047, we could encode the special character
		 * ' ' (space) with '_' (underscore) for readability. But many
		 * programs do not understand this and just leave the
		 * underscore in place. Thus, we do nothing special here, which
		 * causes ' ' to be encoded as '=20', avoiding this problem.
		 */

		if (line_len + encoded_len + 2 > max_encoded_length) {
			/* It won't fit with trailing "?=" --- break the line */
			strbuf_addf(sb, "?=\n =?%s?q?", encoding);
			line_len = strlen(encoding) + 5 + 1; /* =??q? plus SP */
		}

		for (i = 0; i < chrlen; i++)
			strbuf_addf(sb, encoded_fmt, p[i]);
		line_len += encoded_len;
	}
	strbuf_addstr(sb, "?=");
}
示例#2
0
static void output_scalar(SkScalar num, int emSize, SkString* out) {
    num /= emSize;
    if (num == (int) num) {
       out->appendS32((int) num);
    } else {
        SkString str;
        str.printf("%1.6g", num);
        int width = (int) str.size();
        const char* cStr = str.c_str();
        while (cStr[width - 1] == '0') {
            --width;
        }
        str.remove(width, str.size() - width);
        out->appendf("%sf", str.c_str());
    }
    *out += ',';
    *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
}
示例#3
0
文件: pretty.c 项目: AmyOrchid188/git
void pp_title_line(const struct pretty_print_context *pp,
		   const char **msg_p,
		   struct strbuf *sb,
		   const char *encoding,
		   int need_8bit_cte)
{
	static const int max_length = 78; /* per rfc2047 */
	struct strbuf title;

	strbuf_init(&title, 80);
	*msg_p = format_subject(&title, *msg_p,
				pp->preserve_subject ? "\n" : " ");

	strbuf_grow(sb, title.len + 1024);
	if (pp->subject) {
		strbuf_addstr(sb, pp->subject);
		if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
			add_rfc2047(sb, title.buf, title.len,
						encoding, RFC2047_SUBJECT);
		else
			strbuf_add_wrapped_bytes(sb, title.buf, title.len,
					 -last_line_length(sb), 1, max_length);
	} else {
		strbuf_addbuf(sb, &title);
	}
	strbuf_addch(sb, '\n');

	if (need_8bit_cte > 0) {
		const char *header_fmt =
			"MIME-Version: 1.0\n"
			"Content-Type: text/plain; charset=%s\n"
			"Content-Transfer-Encoding: 8bit\n";
		strbuf_addf(sb, header_fmt, encoding);
	}
	if (pp->after_subject) {
		strbuf_addstr(sb, pp->after_subject);
	}
	if (pp->fmt == CMIT_FMT_EMAIL) {
		strbuf_addch(sb, '\n');
	}
	strbuf_release(&title);
}
示例#4
0
文件: pretty.c 项目: AmyOrchid188/git
static void add_rfc2047(struct strbuf *sb, const char *line, int len,
		       const char *encoding, enum rfc2047_type type)
{
	static const int max_encoded_length = 76; /* per rfc2047 */
	int i;
	int line_len = last_line_length(sb);

	strbuf_grow(sb, len * 3 + strlen(encoding) + 100);
	strbuf_addf(sb, "=?%s?q?", encoding);
	line_len += strlen(encoding) + 5; /* 5 for =??q? */
	for (i = 0; i < len; i++) {
		unsigned ch = line[i] & 0xFF;
		int is_special = is_rfc2047_special(ch, type);

		/*
		 * According to RFC 2047, we could encode the special character
		 * ' ' (space) with '_' (underscore) for readability. But many
		 * programs do not understand this and just leave the
		 * underscore in place. Thus, we do nothing special here, which
		 * causes ' ' to be encoded as '=20', avoiding this problem.
		 */

		if (line_len + 2 + (is_special ? 3 : 1) > max_encoded_length) {
			strbuf_addf(sb, "?=\n =?%s?q?", encoding);
			line_len = strlen(encoding) + 5 + 1; /* =??q? plus SP */
		}

		if (is_special) {
			strbuf_addf(sb, "=%02X", ch);
			line_len += 3;
		} else {
			strbuf_addch(sb, ch);
			line_len++;
		}
	}
	strbuf_addstr(sb, "?=");
}
示例#5
0
文件: pretty.c 项目: CookieChen/git
void pp_user_info(struct pretty_print_context *pp,
		  const char *what, struct strbuf *sb,
		  const char *line, const char *encoding)
{
	struct ident_split ident;
	char *line_end;
	const char *mailbuf, *namebuf;
	size_t namelen, maillen;
	int max_length = 78; /* per rfc2822 */

	if (pp->fmt == CMIT_FMT_ONELINE)
		return;

	line_end = strchrnul(line, '\n');
	if (split_ident_line(&ident, line, line_end - line))
		return;

	mailbuf = ident.mail_begin;
	maillen = ident.mail_end - ident.mail_begin;
	namebuf = ident.name_begin;
	namelen = ident.name_end - ident.name_begin;

	if (pp->mailmap)
		map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);

	if (pp->fmt == CMIT_FMT_EMAIL) {
		if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) {
			struct strbuf buf = STRBUF_INIT;

			strbuf_addstr(&buf, "From: ");
			strbuf_add(&buf, namebuf, namelen);
			strbuf_addstr(&buf, " <");
			strbuf_add(&buf, mailbuf, maillen);
			strbuf_addstr(&buf, ">\n");
			string_list_append(&pp->in_body_headers,
					   strbuf_detach(&buf, NULL));

			mailbuf = pp->from_ident->mail_begin;
			maillen = pp->from_ident->mail_end - mailbuf;
			namebuf = pp->from_ident->name_begin;
			namelen = pp->from_ident->name_end - namebuf;
		}

		strbuf_addstr(sb, "From: ");
		if (needs_rfc2047_encoding(namebuf, namelen, RFC2047_ADDRESS)) {
			add_rfc2047(sb, namebuf, namelen,
				    encoding, RFC2047_ADDRESS);
			max_length = 76; /* per rfc2047 */
		} else if (needs_rfc822_quoting(namebuf, namelen)) {
			struct strbuf quoted = STRBUF_INIT;
			add_rfc822_quoted(&quoted, namebuf, namelen);
			strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
							-6, 1, max_length);
			strbuf_release(&quoted);
		} else {
			strbuf_add_wrapped_bytes(sb, namebuf, namelen,
						 -6, 1, max_length);
		}

		if (max_length <
		    last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
			strbuf_addch(sb, '\n');
		strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf);
	} else {
		strbuf_addf(sb, "%s: %.*s%.*s <%.*s>\n", what,
			    (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0, "    ",
			    (int)namelen, namebuf, (int)maillen, mailbuf);
	}

	switch (pp->fmt) {
	case CMIT_FMT_MEDIUM:
		strbuf_addf(sb, "Date:   %s\n",
			    show_ident_date(&ident, pp->date_mode));
		break;
	case CMIT_FMT_EMAIL:
		strbuf_addf(sb, "Date: %s\n",
			    show_ident_date(&ident, DATE_RFC2822));
		break;
	case CMIT_FMT_FULLER:
		strbuf_addf(sb, "%sDate: %s\n", what,
			    show_ident_date(&ident, pp->date_mode));
		break;
	default:
		/* notin' */
		break;
	}
}
示例#6
0
文件: pretty.c 项目: KarthikNayak/git
void pp_title_line(struct pretty_print_context *pp,
		   const char **msg_p,
		   struct strbuf *sb,
		   const char *encoding,
		   int need_8bit_cte)
{
	static const int max_length = 78; /* per rfc2047 */
	struct strbuf title;

	strbuf_init(&title, 80);
	*msg_p = format_subject(&title, *msg_p,
				pp->preserve_subject ? "\n" : " ");

	strbuf_grow(sb, title.len + 1024);
	if (pp->print_email_subject) {
		if (pp->rev)
			fmt_output_email_subject(sb, pp->rev);
		if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
			add_rfc2047(sb, title.buf, title.len,
						encoding, RFC2047_SUBJECT);
		else
			strbuf_add_wrapped_bytes(sb, title.buf, title.len,
					 -last_line_length(sb), 1, max_length);
	} else {
		strbuf_addbuf(sb, &title);
	}
	strbuf_addch(sb, '\n');

	if (need_8bit_cte == 0) {
		int i;
		for (i = 0; i < pp->in_body_headers.nr; i++) {
			if (has_non_ascii(pp->in_body_headers.items[i].string)) {
				need_8bit_cte = 1;
				break;
			}
		}
	}

	if (need_8bit_cte > 0) {
		const char *header_fmt =
			"MIME-Version: 1.0\n"
			"Content-Type: text/plain; charset=%s\n"
			"Content-Transfer-Encoding: 8bit\n";
		strbuf_addf(sb, header_fmt, encoding);
	}
	if (pp->after_subject) {
		strbuf_addstr(sb, pp->after_subject);
	}
	if (cmit_fmt_is_mail(pp->fmt)) {
		strbuf_addch(sb, '\n');
	}

	if (pp->in_body_headers.nr) {
		int i;
		for (i = 0; i < pp->in_body_headers.nr; i++) {
			strbuf_addstr(sb, pp->in_body_headers.items[i].string);
			free(pp->in_body_headers.items[i].string);
		}
		string_list_clear(&pp->in_body_headers, 0);
		strbuf_addch(sb, '\n');
	}

	strbuf_release(&title);
}
示例#7
0
文件: pretty.c 项目: AmyOrchid188/git
void pp_user_info(const struct pretty_print_context *pp,
		  const char *what, struct strbuf *sb,
		  const char *line, const char *encoding)
{
	struct strbuf name;
	struct strbuf mail;
	struct ident_split ident;
	int linelen;
	char *line_end, *date;
	const char *mailbuf, *namebuf;
	size_t namelen, maillen;
	int max_length = 78; /* per rfc2822 */
	unsigned long time;
	int tz;

	if (pp->fmt == CMIT_FMT_ONELINE)
		return;

	line_end = strchr(line, '\n');
	if (!line_end) {
		line_end = strchr(line, '\0');
		if (!line_end)
			return;
	}

	linelen = ++line_end - line;
	if (split_ident_line(&ident, line, linelen))
		return;


	mailbuf = ident.mail_begin;
	maillen = ident.mail_end - ident.mail_begin;
	namebuf = ident.name_begin;
	namelen = ident.name_end - ident.name_begin;

	if (pp->mailmap)
		map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);

	strbuf_init(&mail, 0);
	strbuf_init(&name, 0);

	strbuf_add(&mail, mailbuf, maillen);
	strbuf_add(&name, namebuf, namelen);

	namelen = name.len + mail.len + 3; /* ' ' + '<' + '>' */
	time = strtoul(ident.date_begin, &date, 10);
	tz = strtol(date, NULL, 10);

	if (pp->fmt == CMIT_FMT_EMAIL) {
		strbuf_addstr(sb, "From: ");
		if (needs_rfc2047_encoding(name.buf, name.len, RFC2047_ADDRESS)) {
			add_rfc2047(sb, name.buf, name.len,
				    encoding, RFC2047_ADDRESS);
			max_length = 76; /* per rfc2047 */
		} else if (needs_rfc822_quoting(name.buf, name.len)) {
			struct strbuf quoted = STRBUF_INIT;
			add_rfc822_quoted(&quoted, name.buf, name.len);
			strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
							-6, 1, max_length);
			strbuf_release(&quoted);
		} else {
			strbuf_add_wrapped_bytes(sb, name.buf, name.len,
						 -6, 1, max_length);
		}
		if (namelen - name.len + last_line_length(sb) > max_length)
			strbuf_addch(sb, '\n');

		strbuf_addf(sb, " <%s>\n", mail.buf);
	} else {
		strbuf_addf(sb, "%s: %.*s%s <%s>\n", what,
			      (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
			      "    ", name.buf, mail.buf);
	}

	strbuf_release(&mail);
	strbuf_release(&name);

	switch (pp->fmt) {
	case CMIT_FMT_MEDIUM:
		strbuf_addf(sb, "Date:   %s\n", show_date(time, tz, pp->date_mode));
		break;
	case CMIT_FMT_EMAIL:
		strbuf_addf(sb, "Date: %s\n", show_date(time, tz, DATE_RFC2822));
		break;
	case CMIT_FMT_FULLER:
		strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, pp->date_mode));
		break;
	default:
		/* notin' */
		break;
	}
}
示例#8
0
void pp_user_info(const struct pretty_print_context *pp,
                  const char *what, struct strbuf *sb,
                  const char *line, const char *encoding)
{
    int max_length = 78; /* per rfc2822 */
    char *date;
    int namelen;
    unsigned long time;
    int tz;

    if (pp->fmt == CMIT_FMT_ONELINE)
        return;
    date = strchr(line, '>');
    if (!date)
        return;
    namelen = ++date - line;
    time = strtoul(date, &date, 10);
    tz = strtol(date, NULL, 10);

    if (pp->fmt == CMIT_FMT_EMAIL) {
        char *name_tail = strchr(line, '<');
        int display_name_length;
        if (!name_tail)
            return;
        while (line < name_tail && isspace(name_tail[-1]))
            name_tail--;
        display_name_length = name_tail - line;
        strbuf_addstr(sb, "From: ");
        if (needs_rfc2047_encoding(line, display_name_length, RFC2047_ADDRESS)) {
            add_rfc2047(sb, line, display_name_length,
                        encoding, RFC2047_ADDRESS);
            max_length = 76; /* per rfc2047 */
        } else if (needs_rfc822_quoting(line, display_name_length)) {
            struct strbuf quoted = STRBUF_INIT;
            add_rfc822_quoted(&quoted, line, display_name_length);
            strbuf_add_wrapped_bytes(sb, quoted.buf, quoted.len,
                                     -6, 1, max_length);
            strbuf_release(&quoted);
        } else {
            strbuf_add_wrapped_bytes(sb, line, display_name_length,
                                     -6, 1, max_length);
        }
        if (namelen - display_name_length + last_line_length(sb) > max_length) {
            strbuf_addch(sb, '\n');
            if (!isspace(name_tail[0]))
                strbuf_addch(sb, ' ');
        }
        strbuf_add(sb, name_tail, namelen - display_name_length);
        strbuf_addch(sb, '\n');
    } else {
        strbuf_addf(sb, "%s: %.*s%.*s\n", what,
                    (pp->fmt == CMIT_FMT_FULLER) ? 4 : 0,
                    "    ", namelen, line);
    }
    switch (pp->fmt) {
    case CMIT_FMT_MEDIUM:
        strbuf_addf(sb, "Date:   %s\n", show_date(time, tz, pp->date_mode));
        break;
    case CMIT_FMT_EMAIL:
        strbuf_addf(sb, "Date: %s\n", show_date(time, tz, DATE_RFC2822));
        break;
    case CMIT_FMT_FULLER:
        strbuf_addf(sb, "%sDate: %s\n", what, show_date(time, tz, pp->date_mode));
        break;
    default:
        /* notin' */
        break;
    }
}
示例#9
0
static void output_fixed(SkScalar num, int emSize, SkString* out) {
    int hex = (int) (num * 65536 / emSize);
    out->appendf("0x%08x,", hex);
    *out += (int) last_line_length(*out) >= kMaxLineLength ? '\n' : ' ';
}