11b5d7088f505cdc4f678d3451d63bed4a3019f9 kent Fri May 26 13:28:25 2017 -0700 Adding maxCols option so can handle more than 16. diff --git src/utils/addCols/addCols.c src/utils/addCols/addCols.c index 98435b9..9c5b198 100644 --- src/utils/addCols/addCols.c +++ src/utils/addCols/addCols.c @@ -1,53 +1,63 @@ /* addCols - Add together columns. */ #include "common.h" #include "linefile.h" +#include "options.h" +int clMaxCols=16; void usage() /* Explain usage and exit. */ { errAbort( "addCols - Sum columns in a text file.\n" "usage:\n" " addCols \n" - "adds all columns (up to 16 columns) in the given file, \n" + "adds all columns in the given file, \n" "outputs the sum of each column. can be the\n" - "name: stdin to accept input from stdin."); + "name: stdin to accept input from stdin.\n" + "Options:\n" + " -maxCols=N - maximum number of colums (defaults to %d)\n", clMaxCols); } +/* Command line validation table. */ +static struct optionSpec options[] = { + {"maxCols", OPTION_INT}, + {NULL, 0}, +}; + + void addCols(char *fileName) /* addCols - Add together columns. */ { struct lineFile *lf; -char *words[16]; +char **words; +AllocArray(words, clMaxCols); int wordCount; -static double totals[16]; +double *totals; +AllocArray(totals, clMaxCols); int maxCount = 0; int i; -if (sameString(fileName, "stdin")) - lf = lineFileStdin(TRUE); -else lf = lineFileOpen(fileName, TRUE); -for (i=0; i