/* * Print the label and '(' for open block tk */ static void print_open_token(printer_t *p, pp_open_token_t *tk) { uint32_t new_col; if (p->area.truncate) { if (p->col + 4 <= p->margin) { /* * truncate mode, line not full, nothing pending */ assert(!p->full_line && p->pending_tokens.size == 0); print_blank(p); new_col = p->col + tk->label_size + tk_has_par(tk); if (new_col + 4 <= p->margin) { // tk fits and there's room for ' ...' after it print_label(p, tk); } else if (new_col <= p->margin) { // we can't tell whether tk fits yet // because we may need ellipsis p->pending_col = p->col; p->col = new_col; pvector_push(&p->pending_tokens, tag_open(tk)); } else { // tk does not fit: print it truncated print_label_truncated(p, tk); p->full_line = true;; } } else if (!p->full_line) { /* * truncate mode, line not full, tokens pending */ assert(p->col <= p->margin && p->pending_tokens.size > 0); // add tk to the pending tokens if it fits new_col = p->col + tk->bsize + tk_has_par(tk) + (! p->no_space); if (new_col <= p->margin) { p->col = new_col; pvector_push(&p->pending_tokens, tag_open(tk)); } else { // the pending tokens don't fit // print what we can + ellipsis print_pending_truncated(p); free_open_token(p, tk); p->full_line = true; } } else { /* * truncate mode, line full, nothing pending */ assert(p->pending_tokens.size == 0); free_open_token(p, tk); } } else { /* * don't truncate */ print_blank(p); print_label(p, tk); } }
int main(int argc, char *argv[]) { /* Silly program to demonstrate some C languaage syntax */ int i = 3; double pi = 3.14; char c = 'a'; // single quotes char s[] = "Hello, world"; // double quotes printf("%s, pi=%.2f, num=%d, char=%c\n", s, pi, i, c); print_blank(); // Initializing a struct point p = {.z = 2.0, .x = 3.0}; printf("Point is (%.4f, %.4f, %.4f)\n", p.x, p.y, p.z); print_blank(); // Get some numbers from command line arguments int n1 = atoi(argv[1]); int n2 = atoi(argv[2]); // Using arrays with automatic memory int v1[n1]; for (int i=0; i<n1; i++) { v1[i] = i*i; } // Using the ternary ?: operator to print either ", " or "\n" for (int i=0; i<n1; i++) { printf("%d%s", v1[i], i < (n1-1) ? ", " : "\n"); } print_blank(); // Using arrays with manual (or dynamic) memory double *v2 = malloc(n1 * sizeof(int)); for (int i=0; i<n1; i++) { v2[i] = sin(i*i); } for (int i=0; i<n1; i++) { printf("%.4f%s", v2[i], i < (n1-1) ? ", " : "\n"); } print_blank(); // Using 2D arrays with automatic memory double m1[n1][n2]; for (int i=0; i<n1; i++) { for (int j=0; j<n2; j++) { m1[i][j] = i*n2 + j; } } for (int i=0; i<n1; i++) { for (int j=0; j<n2; j++) { printf("%8.4f%s", m1[i][j], j < (n2-1) ? ", " : "\n"); } } print_blank(); // Using 2D arrays with manual memory double **m2 = malloc(n1 * sizeof(double)); for (int i=0; i<n1; i++) { m2[i] = calloc(n2, sizeof(double)); } for (int i=0; i<n1; i++) { for (int j=0; j<n2; j++) { m2[i][j] = sqrt(i*n2 + j); } } for (int i=0; i<n1; i++) { for (int j=0; j<n2; j++) { printf("%8.4f%s", m2[i][j], j < (n2-1) ? ", " : "\n"); } } print_blank(); printf("The sum of entries in m2 is %.4f\n", array2d_sum(m2, n1, n2)); // free memory after usage free(v2); for (int i=0; i<n1; i++) { free(m2[i]); } free(m2); }
int main(int argc, char **argv) { int i,j; int initial,fixup,spec2k6,legend; int num_benchmarks; char temp_input[BUFSIZ]; parse_command_line(argc,argv, &num_runs,&initial, &legend,&spec2k6,&num_benchmarks); if (initial) fixup=FIXUP_NONE; else fixup=FIXUP_ALL; machines=spec2k_machines; printf("\\begin{table*}[tbp]\n"); printf("\\begin{sf}\n"); printf("\\begin{scriptsize}\n"); printf("\\begin{center}\n"); printf("\\begin{tabular}{|l||r||r|r|r||"); for(i=0;i<REAL_MACHINES;i++) { if (!(!machines[i].is_spec2k6&&spec2k6)) { printf("r|"); } } printf("}\n"); printf("\\hline\n"); printf("Benchmark & "); printf("\\parbox[b]{1.2cm}{\\flushright Overall\\\\Standard\\\\Deviation\\\\(mean)} & "); printf("\\begin{sideways}\\parbox{2cm}{Pin}\\end{sideways} &"); printf("\\begin{sideways}\\parbox{2cm}{Qemu}\\end{sideways} &"); printf("\\begin{sideways}\\parbox{2cm}{Valgrind}\\end{sideways} "); for(i=0;i<REAL_MACHINES;i++) { if (!(!machines[i].is_spec2k6&&spec2k6)) { printf("& "); printf("\\begin{sideways}\\parbox{2cm}{"); printf("%s",machines[i].processor2); printf("\\\\%s",machines[i].processor1); printf("}\\end{sideways} "); } } printf("\\\\\n"); printf("\\hline\n"); our_stats=calloc(sizeof(struct stats),num_benchmarks); for(j=0;j<num_benchmarks;j++) { load_stats(num_runs,spec2k6,our_stats,argv[(j*2)+BENCH_START], argv[(j*2)+BENCH_START+1],argv[TREE_ARG],j,fixup); } for(j=0;j<num_benchmarks;j++) { if (!strcmp("makerand",argv[(j*2)+BENCH_START+1])) { strcpy(temp_input,"mkrnd"); } else if (!strcmp("default",argv[(j*2)+BENCH_START+1])) { strcpy(temp_input," "); } else if (!strcmp("foreman_baseline",argv[(j*2)+BENCH_START+1])) { strcpy(temp_input,"forebase"); } else if (!strcmp("foreman_main",argv[(j*2)+BENCH_START+1])) { strcpy(temp_input,"foremain"); } else if (!strcmp("sss_main",argv[(j*2)+BENCH_START+1])) { strcpy(temp_input,"sss"); } else { strcpy(temp_input,argv[(j*2)+BENCH_START+1]); } printf("%s %s &",argv[(j*2)+BENCH_START],temp_input); /* mean */ print_diff((long long)(our_stats[j].bench_stdev),LO,MID,HI); //print_commas( (long long)(our_stats[j].bench_stdev)); printf(" & "); /* PIN */ if (!our_stats[j].machine_mean_valid[PIN]) { print_blank(); } else { print_diff((long long)(our_stats[j].machine_stdev[PIN]),LO,MID,HI); print_num_points(our_stats[j].num_points[PIN]); } printf(" & "); /* QEMU */ if (!our_stats[j].machine_mean_valid[QEMU]) { print_blank(); } else { print_diff((long long)(our_stats[j].machine_stdev[QEMU]),LO,MID,HI); print_num_points(our_stats[j].num_points[QEMU]); } printf(" & "); if (!our_stats[j].machine_mean_valid[VALGRIND]) { print_blank(); } else { print_diff((long long)(our_stats[j].machine_stdev[VALGRIND]),LO,MID,HI); print_num_points(our_stats[j].num_points[VALGRIND]); } for(i=0;i<REAL_MACHINES;i++) { if (!(!machines[i].is_spec2k6&&spec2k6)) { printf(" & "); if (!our_stats[j].machine_mean_valid[i]) { print_blank(); } else { print_diff((long long)(our_stats[j].machine_stdev[i]),LO,MID,HI); print_num_points(our_stats[j].num_points[i]); } } } printf("\\\\\n"); if (j%5==4) printf("\\hline\n"); } printf("\\hline\n"); printf("\\end{tabular}\n"); printf("\\end{center}\n"); return 0; }