730e30d353962933ce8286de4fb9f46f58a7440e kent Wed Sep 4 13:02:37 2019 -0700 Added a new small function aking to fieldedTableMustFindFieldIx, but without the must. Just returns a -1 on problem rather than errAborting. diff --git src/lib/fieldedTable.c src/lib/fieldedTable.c index 6a74092..0742669 100644 --- src/lib/fieldedTable.c +++ src/lib/fieldedTable.c @@ -292,34 +292,40 @@ fputc('\t', f); fputs(fr->row[i], f); } fputc('\n', f); } carefulClose(&f); } void fieldedTableToTabFile(struct fieldedTable *table, char *fileName) /* Write out a fielded table back to file */ { fieldedTableToTabFileWithId(table, fileName, NULL, 0); } +int fieldedTableFindFieldIx(struct fieldedTable *table, char *field) +/* Return index of field in a table's row or -1 if not found */ +{ +return stringArrayIx(field, table->fields, table->fieldCount); +} + int fieldedTableMustFindFieldIx(struct fieldedTable *table, char *field) /* Find index of field in table's row. Abort if field not found. */ { -int ix = stringArrayIx(field, table->fields, table->fieldCount); +int ix = fieldedTableFindFieldIx(table, field); if (ix < 0) errAbort("Field %s not found in table %s", field, table->name); return ix; } struct hash *fieldedTableIndex(struct fieldedTable *table, char *field) /* Return hash of fieldedRows keyed by values of given field */ { int fieldIx = fieldedTableMustFindFieldIx(table, field); struct hash *hash = hashNew(0); struct fieldedRow *fr; for (fr = table->rowList; fr != NULL; fr = fr->next) { hashAdd(hash,fr->row[fieldIx], fr); }