/* usage: extract-records [-i] ID-file|- tbl-file */ #define MAX_LEN 50000 #define TRUE 1 #define FALSE 0 #include main (argc, argv) int argc; char *argv []; { FILE *finp_ID, *finp_tbl; char ID[480], record_ID[480], record[MAX_LEN]; int ids_only = FALSE; argv++; if (!strcmp(*argv, "-i")) { ids_only = TRUE; argv++; if (!(finp_tbl = fopen(*argv, "r"))) { fprintf(stderr, "ERROR: File \"%s\" not found !!\n", *argv); exit(1); } } else if (argc == 3) { if (*argv[0] == '-') finp_ID = stdin; else if (!(finp_ID = fopen(*argv, "r"))) { fprintf(stderr, "ERROR: File \"%s\" not found !!\n", *argv); exit(1); } argv++; if (!(finp_tbl = fopen(*argv, "r"))) { fprintf(stderr, "ERROR: File \"%s\" not found !!\n", *argv); exit(1); } } else { fprintf(stderr, "Usage: extract-records [-i] ID-file record-file\n"); exit(1); } if (!ids_only) { while (fscanf(finp_ID, "%s", ID) != EOF) { do { if (fscanf(finp_tbl, "%s ", record_ID) == EOF) { fprintf(stderr, "ERROR: locus \"%s\" NOT found !!; continuing ...\n", ID); rewind(finp_tbl); if (fscanf(finp_ID, "%s", ID) == EOF) exit(1); } fgets (record, MAX_LEN, finp_tbl); } while (strcmp(ID, record_ID)); fprintf(stdout, "%s\t%s", ID, record); fflush(stdout); } } else { while (fscanf(finp_tbl, "%s ", record_ID) != EOF) { fgets (record, MAX_LEN, finp_tbl); fprintf(stdout, "%s\n", record_ID); fflush(stdout); } } }