int main(int argc, char **argv) { int format = TT_ANY, r, prec = 0, version = 3, silent = 0; int compress_mode = -1; char *inf = NULL; char *outf = NULL; mFILE *ofp = mstdout(); int normalise = 0; for (argc--, argv++; argc > 0; argc--, argv++) { if (strcmp(*argv, "-8") == 0) { prec = 1; } else if (strcmp(*argv, "-2") == 0) { version = 2; } else if (strcmp(*argv, "-3") == 0) { version = 3; } else if (strcmp(*argv, "-normalise") == 0) { normalise = 1; } else if (strcmp(*argv, "-s") == 0) { silent = 1; } else if (strcasecmp(*argv, "-abi") == 0) { format = TT_ABI; inf = *++argv; argc--; } else if (strcasecmp(*argv, "-alf") == 0) { format = TT_ALF; inf = *++argv; argc--; } else if (strcasecmp(*argv, "-scf") == 0) { format = TT_SCF; inf = *++argv; argc--; } else if (strcasecmp(*argv, "-ztr") == 0) { format = TT_ZTR; inf = *++argv; argc--; } else if (strcasecmp(*argv, "-any") == 0) { format = TT_ANY; inf = *++argv; argc--; } else if (strcasecmp(*argv, "-output") == 0) { outf = *++argv; argc--; } else if (strcasecmp(*argv, "-compress") == 0) { compress_mode = compress_str2int(*++argv); argc--; } else { break; } } /* if no args left than input file must have been specified */ if (!argc && !inf) usage(); /* if outfile set, then using original syntax, so don't expect any extra args */ if (argc && outf) usage(); if (!silent) { printf("makeSCF v3.06\n"); printf("Copyright (c) MRC Laboratory of Molecular Biology, 2001. All rights reserved.\n"); } set_scf_version(version); if(!argc) { /* original calling syntax */ if (outf) { ofp = mfopen(outf, "wb+"); if (NULL == ofp) { perror(outf); return 1; } } r = convert(inf, ofp, outf, format, prec, compress_mode, normalise); mfclose(ofp); return r; } /* else */ { /* new calling syntax, handling multiple files */ int result=0; for (; argc > 0; argc--, argv++) { if (inf) { /* got infile, so get outfile and process */ outf= *argv; ofp = mfopen(outf, "wb+"); if (NULL == ofp) { perror(outf); if(!result) result=1; continue; } r = convert(inf, ofp, outf, format, prec, compress_mode, normalise); mfclose(ofp); if(!result) /* keep track of the first error */ result=r; /* now need to get another infile */ inf=NULL; } else { /* need infile */ inf= *argv; } } return result; } }
int main(int argc, char **argv) { struct opts opts; opts.in_format = TT_ANY; opts.out_format = TT_ZTR; opts.scale = 0; opts.sub_background = 0; opts.normalise = 0; opts.name = NULL; opts.compress_mode = -1; opts.dots = 0; opts.fofn = NULL; opts.passed = NULL; opts.failed = NULL; opts.error = NULL; for (argc--, argv++; argc > 0; argc--, argv++) { if (**argv != '-') break; if (strcmp(*argv, "-scale") == 0) { opts.scale = atoi(*++argv); argc--; } else if (strcmp(*argv, "-fofn") == 0) { opts.fofn = *++argv; argc--; } else if (strcmp(*argv, "-passed") == 0) { opts.passed = *++argv; argc--; } else if (strcmp(*argv, "-failed") == 0) { opts.failed = *++argv; argc--; } else if (strcmp(*argv, "-error") == 0) { opts.error = *++argv; fprintf(stderr,"* Detected error argument %s\n", opts.error); argc--; } else if (strcmp(*argv, "-subtract_background") == 0) { opts.sub_background = 1; } else if (strcmp(*argv, "-normalise") == 0) { opts.normalise = 1; } else if (strcmp(*argv, "-dots") == 0) { opts.dots = 1; } else if (strcmp(*argv, "-in_format") == 0) { argv++; argc--; if (TT_UNK == (opts.in_format = trace_type_str2int(*argv))) opts.in_format = atoi(*argv); } else if (strcmp(*argv, "-name") == 0) { opts.name = *++argv; argc--; } else if (strcmp(*argv, "-out_format") == 0) { argv++; argc--; if (TT_UNK == (opts.out_format = trace_type_str2int(*argv))) opts.out_format = atoi(*argv); } else if (strcasecmp(*argv, "-compress") == 0) { opts.compress_mode = compress_str2int(*++argv); argc--; } else if (strcmp(*argv, "-abi_data") == 0) { int c1, c2, c3, c4; argc--; if (4 == sscanf(*++argv, "%d,%d,%d,%d", &c1, &c2, &c3, &c4)) { abi_set_data_counts(c1, c2, c3, c4); } else { usage(); } } else if (strcmp(*argv, "--") == 0) { break; } else { usage(); } } if (argc == 2) { /* Old syntax, for backwards compatibility */ if (TT_UNK == (opts.in_format = trace_type_str2int(argv[0]))) opts.in_format = atoi(argv[0]); if (TT_UNK == (opts.out_format = trace_type_str2int(argv[1]))) opts.out_format = atoi(argv[1]); } else if (argc != 0) { usage(); } // Added by SAK: Allow redirection of error output to file, due to problems with Java exec if( NULL != opts.error){ int fd; fprintf(stderr,"* Redirecting stderr to %s\n", opts.error); close(2); // close fd with stderr fd = creat(opts.error, -1 ); if(fd == -1){ exit(-1); } } if (!opts.fofn) { return convert(stdin, stdout, "(stdin)", "(stdout)", &opts); } else { FILE *fpin, *fpout; FILE *fppassed = NULL, *fpfailed = NULL; char *infname, *outfname; int ret, ret_all = 0; char line[8192], line2[8192]; FILE *fofn_fp; if (NULL == (fofn_fp = fopen(opts.fofn, "r"))) { perror(opts.fofn); return -1; } if (opts.passed && NULL == (fppassed = fopen(opts.passed, "w"))) { perror(opts.passed); return -1; } if (opts.failed && NULL == (fpfailed = fopen(opts.failed, "w"))) { perror(opts.failed); return -1; } while (fgets(line, 8192, fofn_fp) != NULL) { int i, j, len; time_t ret_time; // SAK /* Find input and output name, escaping spaces as needed */ len = strlen(line); outfname = NULL; for (i = j = 0; i < len; i++) { if (line[i] == '\\' && i != len-1) { line2[j++] = line[++i]; } else if (line[i] == ' ') { line2[j++] = 0; outfname = &line2[j]; } else if (line[i] != '\n') { line2[j++] = line[i]; } } line2[j] = 0; infname = line2; /* Open input and output files */ if (NULL == (fpin = fopen(infname, "rb"))) { char buf[2048]; sprintf(buf, "ERROR %s", infname); perror(buf); if (opts.dots) { fputc('!', stdout); fflush(stdout); } if (fpfailed) fprintf(fpfailed, "%s\n", infname); continue; } if (outfname) { if (NULL == (fpout = fopen(outfname, "wb+"))) { char buf[2048]; sprintf(buf, "ERROR %s", outfname); perror(buf); fclose(fpin); if (opts.dots) { fputc('!', stdout); fflush(stdout); } if (fpfailed) fprintf(fpfailed, "%s\n", infname); continue; } } else { outfname = "(stdout)"; fpout = stdout; } /* Convert */ ret = convert(fpin, fpout, infname, outfname, &opts); ret_time = time(NULL); // SAK ret_all |= ret; if (opts.dots) { fputc(ret ? '!' : '.', stdout); fflush(stdout); } if (ret) { if (fpfailed) fprintf(fpfailed, "%s %s", infname, ctime(&ret_time)); // SAK } else { if (fppassed) fprintf(fppassed, "%s %s", infname, ctime(&ret_time)); // SAK } /* Tidy up */ fclose(fpin); if (fpout != stdout) fclose(fpout); } if(ret_all) fprintf(stderr,"* ret_all = %d\n", ret_all); fclose(fofn_fp); return ret_all; } return 0; }