# To unbundle, sh this file echo HELP 1>&2 cat >HELP <<'End of HELP' validate_graph - Perform validations on a binary graph. For more info see: Haggard (1980) \"Excursions in Graph Theory\" http://www.amazon.com/Excursions-Graph-Theory-Haggard/dp/0891010408 End of HELP echo Makefile 1>&2 cat >Makefile <<'End of Makefile' O_FILES = validate_graph.o usage.o help.o CFLAGS = CC = gcc validate_graph: $(O_FILES) $(CC) $(CFLAGS) -o validate_graph $(O_FILES) End of Makefile echo Test 1>&2 cat >Test <<'End of Test' # bar cat in.txt bar ./validate_graph -n 3 < in.txt > out.txt cat out.txt bar cat in2.txt bar ./validate_graph -n 3 < in2.txt > out2.txt cat out2.txt bar End of Test echo USAGE 1>&2 cat >USAGE <<'End of USAGE' flag meaning default ------------- -------------------------- ------- -C chatty FALSE -D debug FALSE -n number of rows & columns 6 -u usage (this message) End of USAGE echo help.c 1>&2 cat >help.c <<'End of help.c' /* * help - give program help */ #include help(argv) char** argv; { fprintf(stderr, "%s: HELP:\n", argv[0]); fprintf(stderr, "\n"); fprintf(stderr, " validate_graph - Perform validations on a binary graph.\n"); fprintf(stderr, "\n"); fprintf(stderr, " For more info see: Haggard (1980) \"Excursions in Graph Theory\"\n"); fprintf(stderr, "\n"); fprintf(stderr, " http://www.amazon.com/Excursions-Graph-Theory-Haggard/dp/0891010408\n"); fprintf(stderr, "\n"); } /* end of help */ End of help.c echo mkFunctions 1>&2 cat >mkFunctions <<'End of mkFunctions' # mkHelp -n `wc -l < HELP` < HELP > help.c mkUsage -n `wc -l < USAGE` < USAGE > usage.c End of mkFunctions echo validate_graph.c 1>&2 cat >validate_graph.c <<'End of validate_graph.c' /** ** validate_graph - simulate Martingale betting system ** ** CREATED: 2012.06.20 ABS copied from lose_the_farm ** MODIFIED: 2012 ** **/ #include "validate_graph.h" main(argc, argv) int argc; char** argv; { /* declare functions */ double atof(); /* declare local variables */ int r, c, i; int valid; /* Boolean */ /* initialize global variables (including parameters) */ defaultParms(); parseArgs(argc, argv); if (Debug != FALSE) { fprintf(stderr, "%s: DEBUG: N_MatrixSize = %d\n", argv[0], N_MatrixSize); } /* initialize local variables */ valid = TRUE; /* read & debug write */ for (r = 0; r < N_MatrixSize; r++) { for (c = 0; c < N_MatrixSize; c++) { /* read next matrix element */ fscanf(stdin, "%d", &i); matrix[r][c] = i; if (Debug != FALSE) { fprintf(stderr, "%s: DEBUG: r = %d\n", argv[0], r); fprintf(stderr, "%s: DEBUG: c = %d\n", argv[0], c); fprintf(stderr, "%s: DEBUG: i = %d\n", argv[0], i); } } /* end for c */ } /* end for r */ for (r = 0; r < N_MatrixSize; r++) { for (c = 0; c < N_MatrixSize; c++) { if (matrix[r][c] != matrix[c][r]) { valid = FALSE; if (Debug != FALSE) { fprintf(stderr, "%s: DEBUG: matrix[%d][%d] = %d\n", argv[0], r, c, matrix[r][c]); fprintf(stderr, "%s: DEBUG: matrix[%d][%d] = %d\n", argv[0], c, r, matrix[c][r]); } } /* end if */ } /* end for c */ } /* end for r */ fprintf(stdout, "matrix is "); if (valid == FALSE) { fprintf(stdout, "not "); } fprintf(stdout, "valid\n"); } /* end main */ /* * defaultParms - initialize global variables */ defaultParms() { Debug = FALSE; Chatty = FALSE; N_MatrixSize = 6; } /* end defaultParms() */ /* * parseArgs - parse arguments into global variables */ parseArgs(argc, argv) int argc; char** argv; { int i; for (i = 0; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'C' : Chatty = TRUE; break; case 'D' : Debug = TRUE; break; case 'h' : help(argv); exit(0); break; case 'n' : N_MatrixSize = atoi(&argv[++i][0]); break; case 't' : Type = atoi(&argv[++i][0]); break; case 'u' : usage(argv); exit(0); break; default: fprintf(stderr, "%s: ERROR: illegal flag: %s\n", argv[0], argv[i]); usage(argv); exit(0); break; } /* end switch */ } /* end if */ } /* end for(i) */ } /* end parseArgs() */ End of validate_graph.c echo validate_graph.h 1>&2 cat >validate_graph.h <<'End of validate_graph.h' /* * validate_graph.h -- include file for validate_graph.c */ /* includes */ #include #include #include #include #include #include "../graph_theory_lib.h" /* constants */ #define TRUE (1) #define FALSE (0) #define MAX_N (256) /* global variables */ int matrix[MAX_N][MAX_N]; /* flag-settable parameters (global variables) */ int Debug; /* Boolean: TRUE = debug writes */ int Chatty; /* Boolean */ int N_MatrixSize; int Type; End of validate_graph.h echo in.txt 1>&2 cat >in.txt <<'End of in.txt' 0 1 1 1 0 1 1 0 0 End of in.txt echo in2.txt 1>&2 cat >in2.txt <<'End of in2.txt' 0 1 1 1 0 1 1 1 0 End of in2.txt