#include #include "allocate.h" #include #define TRUE 1 #define FALSE 0 #define ONE "1 " #define ZERO "0 " void main(int argc, char **argv) { int row, col, maxrow, maxcol, okay, tabwarn, order; char line[100]; FILE *fp; char **vax; char current, c1, c2; int match = FALSE; if (argc < 2) fp = stdin; else { fp = fopen(argv[1],"r"); if (fp == NULL) { printf("Could not open %s for input\n",argv[1]); exit(1); } } /* parse comments in header */ do { fgets(line, 100, fp); } while (line[0] == '#'); /* get size */ sscanf(line,"%d %d",&maxrow,&maxcol); if (maxrow == 0 || maxcol == 0) { printf("Invalid input file.\n"); exit(1); } order = maxrow / 2; /* make space with one space of padding on all four sides*/ vax = (char **) Allocate_2D(maxrow + 2, maxcol + 2, 1); /* initialize array */ for (row = 0; row < maxrow + 2; row++) for (col = 0; col < maxcol + 2; col++) vax[row][col] = ' '; okay = TRUE; /* is this a valid matching?...not yet */ for (row = 0; row <= maxrow; row ++) { for (col = 0; col <= maxcol; col ++) { current = fgetc(fp); if (feof(fp) == FALSE) { if (strchr("E3MWAVX<> \t\n",current) == NULL) { printf("Illegal character '%c' in input file at row %d col %d.\n",current, row, col); exit(1); } /* display warning if tabs are present */ if (current == '\t') if (tabwarn == FALSE) { fprintf(stderr,"Warning, in input file being interpreted as single space.\n"); tabwarn = TRUE; current = ' '; } /* add one to col and row for padding */ if (current != '\n') vax[row+1][col+1] = current; if (current == '\n') col = maxcol + 3; } else { row = maxrow + 3; col = maxcol + 3; } } if (col < maxcol + 3) { printf("The input file size does not indicate enough columns.\n"); exit(1); } } if (row < maxrow + 3) { printf("The input file size does not indicate enough rows.\n"); exit(1); } printf("%d\n", order); for (row = 0; row < order; row ++) { /* handle even rows */ for (col = 0; col < order; col ++) { /* handle even column, c1 points up to c2 */ c1 = vax[row + order - col + 1][col + row + 1]; c2 = vax[row + order - col][col + row + 1]; if ((strchr("WV<>XI",c1) != NULL) && (strchr("MA<>XI",c2) != NULL)) printf(ONE); else printf(ZERO); /* handle odd column, c1 points right to c2 */ c1 = vax[row + order - col][col + row + 1]; c2 = vax[row + order - col][col + row + 2]; if ((strchr("EAVX=",c2) != NULL)) printf(ONE); else printf(ZERO); } printf("\n"); /* handle odd rows */ for (col = 0; col < order; col ++) { /* handle even column, c1 points right to c2 */ c1 = vax[row + order - col + 1][col + row + 1]; c2 = vax[row + order - col + 1][col + row + 2]; if ((strchr("EAVX=",c2) != NULL)) printf(ONE); else printf(ZERO); /* handle odd column, c1 points up to c2 */ c1 = vax[row + order - col + 1][col + row + 2]; c2 = vax[row + order - col][col + row + 2]; if ((strchr("WV<>XI",c1) != NULL) && (strchr("MA<>XI",c2) != NULL)) printf(ONE); else printf(ZERO); } printf("\n"); } }