Debian Codegraph @

sim4dbutils/headPolishes.C

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5
6 #include "sim4.H"
7
8 // Writes n polishes from stdin to stdout, default 1.
9
10 int
11 main(int argc, char **argv) {
12 uint32 numToPrint = 1;
13 sim4polishReader *R = 0L;
14 sim4polishWriter *W = 0L;
15
16 sim4polishStyle style = sim4polishStyleDefault;
17
18 int arg = 1;
19 int err = 0;
20 while (arg < argc) {
21 if (strncmp(argv[arg], "-h", 2) == 0) {
22 err++;
23
24 } else if (strncmp(argv[arg], "-n", 2) == 0) {
25 numToPrint = atoi(argv[++arg]);
26
27 } else if (strcmp(argv[arg], "-gff3") == 0) {
28 style = sim4polishGFF3;
29
30 } else if (strncmp(argv[arg], "-", 1) == 0) {
31 numToPrint = atoi(argv[arg] + 1);
32
33 } else {
34 R = new sim4polishReader(argv[arg]);
35 }
36
37 arg++;
38 }
39 if ((err) || ((R == 0L) && (isatty(fileno(stdin))))) {
40 fprintf(stderr, "usage: %s [-h] [-# | -n #] [-gff3] [polishes-file]\n", argv[0]);
41 exit(1);
42 }
43
44 if (R == 0L)
45 R = new sim4polishReader("-");
46
47 if (W == 0L)
48 W = new sim4polishWriter("-", style);
49
50 if (R->getsim4polishStyle() != style)
51 fprintf(stderr, "warning: Input format and output format differ.\n");
52
53 sim4polish *p = 0L;
54
55 while ((numToPrint--) && (R->nextAlignment(p)))
56 W->writeAlignment(p);
57
58 delete W;
59 delete R;
60
61 return(0);
62 }
63