/* Output from p2c, the Pascal-to-C translator */ /* From input file "process.pas" */ #include typedef struct arc { uchar bi, bj, ei, ej, nr; long count; } arc; Static long depth_count[30][30]; Static boolean start[30][30]; Static FILE *result_file, *process_file; Static long total, nodes; Static arc arcs[1000]; Static short nr_arcs; Static Void init_arcs() { nr_arcs = 0; } Static Void store_arc(nbi, nbj, nei, nej, nnr, ncount) uchar nbi, nbj, nei, nej, nnr; long ncount; { uchar i; boolean go; arc *WITH; nr_arcs++; i = nr_arcs; go = true; while (go && i > 1) { if (arcs[i - 2].count <= ncount) go = false; else { arcs[i - 1] = arcs[i - 2]; i--; } } WITH = &arcs[i - 1]; WITH->bi = nbi; WITH->bj = nbj; WITH->ei = nei; WITH->ej = nej; WITH->nr = nnr; WITH->count = ncount; } Static Void print_arcs(out) FILE **out; { uchar i, FORLIM; arc *WITH; FORLIM = nr_arcs; for (i = 0; i < FORLIM; i++) { WITH = &arcs[i]; fprintf(*out, " (%12d,%12d)\t-> (%12d,%12d)\t%5d\t%12ld\013", WITH->bi, WITH->bj, WITH->ei, WITH->ej, WITH->nr, WITH->count); } } Static Void init_start(n, m) uchar n, m; { uchar i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) start[i][j] = true; } } Static Void remove_start(n, m, i, j) uchar n, m, i, j; { start[i - 1][j - 1] = false; start[n - i][j - 1] = false; start[i - 1][m - j] = false; start[n - i][m - j] = false; } Static Void process_values(n, m, i, j) uchar n, m, i, j; { uchar i1, j1, c, maxj; if (j + j == m + 1) maxj = j; else maxj = m; start[i - 1][j - 1] = false; for (i1 = 1; i1 <= n; i1++) { for (j1 = 1; j1 <= maxj; j1++) { if (start[i1 - 1][j1 - 1] && depth_count[i1 - 1][j1 - 1] != 0) { if (i + i1 == n + 1 && j + j1 == m + 1) { if (i == i1 || j == j1) c = 1; else c = 2; } else if ((i + i1 == n + 1 || j + j1 == m + 1) && (i == i1 || j == j1)) c = 2; else c = 4; store_arc(i, j, i1, j1, c, depth_count[i1 - 1][j1 - 1]); total += depth_count[i1 - 1][j1 - 1] * c; nodes += c; } } } remove_start(n, m, i, j); } /* Local variables for process_eq_values: */ struct LOC_process_eq_values { uchar n, i, j, i1, j1, c; } ; Local Void add(LINK) struct LOC_process_eq_values *LINK; { if (!(start[LINK->i1 - 1][LINK->j1 - 1] && depth_count[LINK->i1 - 1][LINK->j1 - 1] != 0)) return; if (LINK->i + LINK->i1 == LINK->n + 1 && LINK->j + LINK->j1 == LINK->n + 1) { if (LINK->i == LINK->i1 || LINK->j == LINK->j1 || LINK->i == LINK->j || LINK->i + LINK->j == LINK->n + 1) LINK->c = 2; else LINK->c = 4; } else if (LINK->i + LINK->i1 == LINK->n + 1 && LINK->j == LINK->j1 || LINK->j + LINK->j1 == LINK->n + 1 && LINK->i == LINK->i1 || LINK->i + LINK->i1 == LINK->n + 1 && LINK->i == LINK->i1 || LINK->j + LINK->j1 == LINK->n + 1 && LINK->j == LINK->j1 || (abs(LINK->i - LINK->i1) == abs(LINK->j - LINK->j1) && (LINK->i + LINK->i1 == LINK->j + LINK->j1 || LINK->i + LINK->i1 + LINK->j + LINK->j1 == LINK->n + LINK->n + 2))) LINK->c = 4; else LINK->c = 8; store_arc(LINK->i, LINK->j, LINK->i1, LINK->j1, LINK->c, depth_count[LINK->i1 - 1][LINK->j1 - 1]); total += depth_count[LINK->i1 - 1][LINK->j1 - 1] * LINK->c; nodes += LINK->c; } Static Void process_eq_values(n_, i_, j_) uchar n_, i_, j_; { struct LOC_process_eq_values V; Char ch; uchar FORLIM, FORLIM1; V.n = n_; V.i = i_; V.j = j_; printf("%3d%3d", V.i, V.j); start[V.i - 1][V.j - 1] = false; if (V.i == V.j) { FORLIM = V.n; for (V.i1 = 1; V.i1 <= FORLIM; V.i1++) { FORLIM1 = V.n; for (V.j1 = V.i1; V.j1 <= FORLIM1; V.j1++) add(&V); } } else { if (V.j + V.j == V.n + 1) { FORLIM = V.n; for (V.i1 = 1; V.i1 <= FORLIM; V.i1++) { FORLIM1 = V.n; for (V.j1 = V.j; V.j1 <= FORLIM1; V.j1++) add(&V); } } else { FORLIM = V.n; for (V.i1 = 1; V.i1 <= FORLIM; V.i1++) { FORLIM1 = V.n; for (V.j1 = 1; V.j1 <= FORLIM1; V.j1++) { if (V.j1 != V.i || V.i1 + V.j != V.n + 1) add(&V); } } } } remove_start(V.n, V.n, V.i, V.j); remove_start(V.n, V.n, V.j, V.i); } Static Void process_one_size() { Char ch; uchar n, m, i, j; long nm, count; uchar i1, j1; boolean first; int TEMP, TEMP1, TEMP2, TEMP3; nodes = 0; total = 0; first = true; init_arcs(); do { ch = getc(result_file); if (ch == '\n') ch = ' '; if (ch == 't') { fscanf(result_file, "%*[^\n]"); getc(result_file); fscanf(result_file, "%*[^\n]"); getc(result_file); fscanf(result_file, "%*[^\n]"); getc(result_file); } else { fscanf(result_file, "%d%d%d%d%ld%*[^\n]", &TEMP, &TEMP1, &TEMP2, &TEMP3, &count); getc(result_file); n = TEMP; m = TEMP1; i = TEMP2; j = TEMP3; if (first) { init_start(n, m); fprintf(process_file, "size %3d%3d\013\013\013", n, m); first = false; } for (i1 = 0; i1 < n; i1++) { for (j1 = 0; j1 < m; j1++) fscanf(result_file, "%ld", &depth_count[i1][j1]); fscanf(result_file, "%*[^\n]"); getc(result_file); } if (n == m) process_eq_values(n, i, j); else process_values(n, m, i, j); fscanf(result_file, "%*[^\n]"); getc(result_file); } } while (ch != 't'); print_arcs(&process_file); fprintf(process_file, "\013 total = %12ld\n", total); nm = n * m; printf(" %5ld%5ld\n", nodes, nm * (nm - 1) / 2); } main(argc, argv) int argc; Char *argv[]; { /* p2c: process.pas, line 201: Warning: * Don't know how to ASSIGN to a non-explicit file variable [207] */ PASCAL_MAIN(argc, argv); process_file = NULL; result_file = NULL; result_file = fopen("result.dat", "r"); /* p2c: process.pas, line 202: Warning: * Don't know how to ASSIGN to a non-explicit file variable [207] */ process_file = fopen("process4.doc", "w"); rewind(result_file); if (process_file != NULL) { /* p2c: process.pas, line 204: * Note: REWRITE does not specify a name [181] */ rewind(process_file); } else process_file = tmpfile(); if (process_file == NULL) _EscIO(FileNotFound); while (!P_eof(result_file)) process_one_size(); if (process_file != NULL) fclose(process_file); process_file = NULL; if (result_file != NULL) fclose(result_file); if (process_file != NULL) fclose(process_file); exit(EXIT_SUCCESS); } /* End. */