void pretty_print_commit(struct pretty_print_context *pp, const struct commit *commit, struct strbuf *sb) { unsigned long beginning_of_body; int indent = 4; const char *msg; const char *reencoded; const char *encoding; int need_8bit_cte = pp->need_8bit_cte; if (pp->fmt == CMIT_FMT_USERFORMAT) { format_commit_message(commit, user_format, sb, pp); return; } encoding = get_log_output_encoding(); msg = reencoded = logmsg_reencode(commit, NULL, encoding); if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL) indent = 0; /* * We need to check and emit Content-type: to mark it * as 8-bit if we haven't done so. */ if (pp->fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) { int i, ch, in_body; for (in_body = i = 0; (ch = msg[i]); i++) { if (!in_body) { /* author could be non 7-bit ASCII but * the log may be so; skip over the * header part first. */ if (ch == '\n' && msg[i+1] == '\n') in_body = 1; } else if (non_ascii(ch)) { need_8bit_cte = 1; break; } } } pp_header(pp, encoding, commit, &msg, sb); if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) { strbuf_addch(sb, '\n'); } /* Skip excess blank lines at the beginning of body, if any... */ msg = skip_empty_lines(msg); /* These formats treat the title line specially. */ if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL) pp_title_line(pp, &msg, sb, encoding, need_8bit_cte); beginning_of_body = sb->len; if (pp->fmt != CMIT_FMT_ONELINE) pp_remainder(pp, &msg, sb, indent); strbuf_rtrim(sb); /* Make sure there is an EOLN for the non-oneline case */ if (pp->fmt != CMIT_FMT_ONELINE) strbuf_addch(sb, '\n'); /* * The caller may append additional body text in e-mail * format. Make sure we did not strip the blank line * between the header and the body. */ if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body) strbuf_addch(sb, '\n'); unuse_commit_buffer(commit, reencoded); }
void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, struct strbuf *sb, const struct pretty_print_context *context) { unsigned long beginning_of_body; int indent = 4; const char *msg = commit->buffer; char *reencoded; const char *encoding; int need_8bit_cte = context->need_8bit_cte; if (fmt == CMIT_FMT_USERFORMAT) { format_commit_message(commit, user_format, sb, context); return; } reencoded = reencode_commit_message(commit, &encoding); if (reencoded) { msg = reencoded; } if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) indent = 0; /* * We need to check and emit Content-type: to mark it * as 8-bit if we haven't done so. */ if (fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) { int i, ch, in_body; for (in_body = i = 0; (ch = msg[i]); i++) { if (!in_body) { /* author could be non 7-bit ASCII but * the log may be so; skip over the * header part first. */ if (ch == '\n' && msg[i+1] == '\n') in_body = 1; } else if (non_ascii(ch)) { need_8bit_cte = 1; break; } } } pp_header(fmt, context->abbrev, context->date_mode, encoding, commit, &msg, sb); if (fmt != CMIT_FMT_ONELINE && !context->subject) { strbuf_addch(sb, '\n'); } /* Skip excess blank lines at the beginning of body, if any... */ msg = skip_empty_lines(msg); /* These formats treat the title line specially. */ if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) pp_title_line(fmt, &msg, sb, context->subject, context->after_subject, encoding, need_8bit_cte); beginning_of_body = sb->len; if (fmt != CMIT_FMT_ONELINE) pp_remainder(fmt, &msg, sb, indent); strbuf_rtrim(sb); /* Make sure there is an EOLN for the non-oneline case */ if (fmt != CMIT_FMT_ONELINE) strbuf_addch(sb, '\n'); /* * The caller may append additional body text in e-mail * format. Make sure we did not strip the blank line * between the header and the body. */ if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body) strbuf_addch(sb, '\n'); if (context->show_notes) format_display_notes(commit->object.sha1, sb, encoding, NOTES_SHOW_HEADER | NOTES_INDENT); free(reencoded); }
int main(void) { struct nl_sock *nsd; uint32_t pid, min = 0, max = 5; int family, i; struct net_mat_hdr_node *hdr_gph_node; struct net_mat_tbl_node *tbl_gph_node; struct net_mat_hdr *headers; struct net_mat_action *actions; struct net_mat_tbl *tables; struct net_mat_port *ports; uint32_t phys_port_id = 0; uint32_t glort = 0, lport = 0; uint8_t bus, device, function; int err; nsd = match_nl_get_socket(); if (!nsd) { fprintf(stderr, "Error: socket allocation failed\n"); return -EINVAL; } pid = match_pid_lookup(); if (pid == 0) return -EINVAL; family = NET_MAT_DFLT_FAMILY; fprintf(stderr, "%s: pid %i family %i\n", __func__, pid, family); printf("----------------------------------------\n"); printf("Header Graph:\n"); printf("----------------------------------------\n"); headers = match_nl_get_headers(nsd, pid, 0, family); if (!headers) { fprintf(stderr, "Error: get_headers failed\n"); return -EINVAL; } hdr_gph_node = match_nl_get_hdr_graph(nsd, pid, 0, family); if (!hdr_gph_node) { fprintf(stderr, "Error: get_header_graph failed\n"); free(headers); return -EINVAL; } pp_header_graph(stdout, true, hdr_gph_node); free(hdr_gph_node); free(headers); printf("\n"); printf("----------------------------------------\n"); printf("Table Graph:\n"); printf("----------------------------------------\n"); actions = match_nl_get_actions(nsd, pid, 0, family); if (!actions) { fprintf(stderr, "Error: get_actions failed\n"); return -EINVAL; } match_push_actions_ary(actions); tables = match_nl_get_tables(nsd, pid, 0, family); if (!tables) { fprintf(stderr, "Error: get_tables failed\n"); free(actions); return -EINVAL; } match_push_tables_a(tables); tbl_gph_node = match_nl_get_tbl_graph(nsd, pid, 0, family); if (!tbl_gph_node) { fprintf(stderr, "Error: get_table_graph failed\n"); free(tables); free(actions); return -EINVAL; } pp_table_graph(stdout, true, tbl_gph_node); free(tbl_gph_node); free(tables); free(actions); printf("\n"); printf("----------------------------------------\n"); printf("Headers:\n"); printf("----------------------------------------\n"); headers = match_nl_get_headers(nsd, pid, 0, family); if (!headers) { fprintf(stderr, "Error: get_headers failed\n"); return -EINVAL; } for (i = 0 ; headers[i].uid ; i++) pp_header(stdout, true, &headers[i]); free(headers); printf("\n"); printf("----------------------------------------\n"); printf("Actions:\n"); printf("----------------------------------------\n"); actions = match_nl_get_actions(nsd, pid, 0, family); if (!actions) { fprintf(stderr, "Error: get_actions failed\n"); return -EINVAL; } pp_actions(stdout, true, actions); free(actions); printf("\n"); printf("----------------------------------------\n"); printf("Tables:\n"); printf("----------------------------------------\n"); headers = match_nl_get_headers(nsd, pid, 0, family); if (!headers) { fprintf(stderr, "Error: get_headers failed\n"); return -EINVAL; } hdr_gph_node = match_nl_get_hdr_graph(nsd, pid, 0, family); if (!hdr_gph_node) { fprintf(stderr, "Error: get_header_graph failed\n"); free(headers); return -EINVAL; } actions = match_nl_get_actions(nsd, pid, 0, family); if (!actions) { fprintf(stderr, "Error: get_actions failed\n"); free(hdr_gph_node); free(headers); return -EINVAL; } match_push_actions_ary(actions); tables = match_nl_get_tables(nsd, pid, 0, family); if (!tables) { fprintf(stderr, "Error: get_tables failed\n"); free(actions); free(hdr_gph_node); free(headers); return -EINVAL; } for (i = 0 ; tables[i].uid ; i++) pp_table(stdout, true, &tables[i]); free(tables); free(actions); free(hdr_gph_node); free(headers); printf("\n"); printf("----------------------------------------\n"); printf("Ports:\n"); printf("----------------------------------------\n"); ports = match_nl_get_ports(nsd, pid, 0, family, min, max); if (!ports) { fprintf(stderr, "Error: get_ports failed\n"); return -EINVAL; } pp_ports(stdout, true, ports); free(ports); printf("\n"); printf("----------------------------------------\n"); printf("pci to Logical Port Map:\n"); printf("----------------------------------------\n"); bus = 6; device = 0; function = 0; err = match_nl_pci_lport(nsd, pid, 0, family, bus, device, function, &lport, &glort); if (err) { fprintf(stderr, "Error: match_nl_pci_lport failed\n"); return -EINVAL; } else printf("pci BUS:DEVICE.FUNCTION %02x:%02x.%d is logical port %d\n", bus, device, function, lport); printf("\n"); printf("----------------------------------------\n"); printf("Logical Port to Physical Port Map:\n"); printf("----------------------------------------\n"); err = match_nl_lport_to_phys_port(nsd, pid, 0, family, lport, &phys_port_id, &glort); if (err) { fprintf(stderr, "Error: lport_to_phys_port failed\n"); return -EINVAL; } else printf("logical port %d is physical port %d\n", lport, phys_port_id); printf("\n"); return 0; }
void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, struct strbuf *sb, int abbrev, const char *subject, const char *after_subject, enum date_mode dmode, int need_8bit_cte) { unsigned long beginning_of_body; int indent = 4; const char *msg = commit->buffer; char *reencoded; const char *encoding; if (fmt == CMIT_FMT_USERFORMAT) { format_commit_message(commit, user_format, sb); return; } encoding = (git_log_output_encoding ? git_log_output_encoding : git_commit_encoding); if (!encoding) encoding = "utf-8"; reencoded = logmsg_reencode(commit, encoding); if (reencoded) { msg = reencoded; } if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) indent = 0; /* * We need to check and emit Content-type: to mark it * as 8-bit if we haven't done so. */ if (fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) { int i, ch, in_body; for (in_body = i = 0; (ch = msg[i]); i++) { if (!in_body) { /* author could be non 7-bit ASCII but * the log may be so; skip over the * header part first. */ if (ch == '\n' && msg[i+1] == '\n') in_body = 1; } else if (non_ascii(ch)) { need_8bit_cte = 1; break; } } } pp_header(fmt, abbrev, dmode, encoding, commit, &msg, sb); if (fmt != CMIT_FMT_ONELINE && !subject) { strbuf_addch(sb, '\n'); } /* Skip excess blank lines at the beginning of body, if any... */ for (;;) { int linelen = get_one_line(msg); int ll = linelen; if (!linelen) break; if (!is_empty_line(msg, &ll)) break; msg += linelen; } /* These formats treat the title line specially. */ if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) pp_title_line(fmt, &msg, sb, subject, after_subject, encoding, need_8bit_cte); beginning_of_body = sb->len; if (fmt != CMIT_FMT_ONELINE) pp_remainder(fmt, &msg, sb, indent); strbuf_rtrim(sb); /* Make sure there is an EOLN for the non-oneline case */ if (fmt != CMIT_FMT_ONELINE) strbuf_addch(sb, '\n'); /* * The caller may append additional body text in e-mail * format. Make sure we did not strip the blank line * between the header and the body. */ if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body) strbuf_addch(sb, '\n'); free(reencoded); }