1 | |
---|
2 | #include "phylip.h" |
---|
3 | #include "moves.h" |
---|
4 | |
---|
5 | |
---|
6 | void inpnum(long *n, boolean *success) |
---|
7 | { |
---|
8 | /* used by dnamove, dolmove, move, & retree */ |
---|
9 | int fields; |
---|
10 | char line[100]; |
---|
11 | |
---|
12 | #ifdef WIN32 |
---|
13 | phyFillScreenColor(); |
---|
14 | #endif |
---|
15 | getstryng(line); |
---|
16 | *n = atof(line); |
---|
17 | fields = sscanf(line,"%ld",n); |
---|
18 | *success = (fields == 1); |
---|
19 | } /* inpnum */ |
---|
20 | |
---|
21 | |
---|
22 | void prereverse(boolean local_ansi) |
---|
23 | { |
---|
24 | /* turn on reverse video */ |
---|
25 | printf(local_ansi ? "\033[7m": ""); |
---|
26 | } /* prereverse */ |
---|
27 | |
---|
28 | |
---|
29 | void postreverse(boolean local_ansi) |
---|
30 | { |
---|
31 | /* turn off reverse video */ |
---|
32 | printf(local_ansi ? "\033[0m" : ""); |
---|
33 | } /* postreverse */ |
---|
34 | |
---|
35 | |
---|
36 | void chwrite(Char ch, long num, long *pos, long leftedge, long screenwidth) |
---|
37 | { |
---|
38 | long i; |
---|
39 | |
---|
40 | for (i = 1; i <= num; i++) { |
---|
41 | if ((*pos) >= leftedge && (*pos) - leftedge + 1 < screenwidth) |
---|
42 | putchar(ch); |
---|
43 | (*pos)++; |
---|
44 | } |
---|
45 | } /* chwrite */ |
---|
46 | |
---|
47 | |
---|
48 | void nnwrite(long nodenum,long num,long *pos,long leftedge,long screenwidth) |
---|
49 | { |
---|
50 | long i, leftx; |
---|
51 | |
---|
52 | leftx = leftedge - (*pos); |
---|
53 | if ((*pos) >= leftedge && (*pos) - leftedge + num < screenwidth) |
---|
54 | printf("%*ld", (int)num, nodenum); |
---|
55 | else if (leftx > 0 && leftx < 3) |
---|
56 | for(i=0;i<num-leftx;i++) |
---|
57 | printf(" "); |
---|
58 | (*pos) += num; |
---|
59 | } /* nnwrite */ |
---|
60 | |
---|
61 | |
---|
62 | void stwrite(const char *s,long local_length,long *pos,long leftedge, |
---|
63 | long screenwidth) |
---|
64 | { |
---|
65 | |
---|
66 | if ((*pos) >= leftedge && (*pos) - leftedge + 1 < screenwidth) |
---|
67 | printf("%*s", (int)local_length, s); |
---|
68 | (*pos) += local_length; |
---|
69 | } /* stwrite */ |
---|
70 | |
---|
71 | |
---|
72 | void help(const char *letters) |
---|
73 | { |
---|
74 | /* display help information */ |
---|
75 | char input[100]; |
---|
76 | |
---|
77 | printf("\n\nR Rearrange a tree by moving a node or group\n"); |
---|
78 | printf("# Show the states of the next %s that doesn't fit tree\n", letters); |
---|
79 | printf("+ Show the states of the next %s\n", letters); |
---|
80 | printf("- ... of the previous %s\n", letters); |
---|
81 | printf("S Show the states of a given %s\n", letters); |
---|
82 | printf(". redisplay the same tree again\n"); |
---|
83 | printf("T Try all possible positions of a node or group\n"); |
---|
84 | printf("U Undo the most recent rearrangement\n"); |
---|
85 | printf("W Write tree to a file\n"); |
---|
86 | printf("O select an Outgroup for the tree\n"); |
---|
87 | printf("F Flip (rotate) branches at a node\n"); |
---|
88 | printf("H Move viewing window to the left\n"); |
---|
89 | printf("J Move viewing window downward\n"); |
---|
90 | printf("K Move viewing window upward\n"); |
---|
91 | printf("L Move viewing window to the right\n"); |
---|
92 | printf("C show only one Clade (subtree) (useful if tree is too big)\n"); |
---|
93 | printf("? Help (this screen)\n"); |
---|
94 | printf("Q (Quit) Exit from program\n"); |
---|
95 | printf("X Exit from program\n\n\n"); |
---|
96 | printf("TO CONTINUE, PRESS ON THE Return OR Enter KEY"); |
---|
97 | #ifdef WIN32 |
---|
98 | phyFillScreenColor(); |
---|
99 | #endif |
---|
100 | getstryng(input); |
---|
101 | } /* help */ |
---|
102 | |
---|
103 | |
---|
104 | void treeoptions(boolean waswritten, Char *ch, FILE **fp_outtree, |
---|
105 | Char *outtreename, Char *progname) |
---|
106 | { /* interactively get options for writing a tree */ |
---|
107 | char input[100]; |
---|
108 | |
---|
109 | if (waswritten) { |
---|
110 | printf("\nTree file already was open.\n"); |
---|
111 | printf(" A Add to this tree to tree file\n"); |
---|
112 | printf(" R Replace tree file contents by this tree\n"); |
---|
113 | printf(" F Write out tree to a different tree file\n"); |
---|
114 | printf(" N Do Not write out this tree\n"); |
---|
115 | do { |
---|
116 | printf("Which should we do? "); |
---|
117 | #ifdef WIN32 |
---|
118 | phyFillScreenColor(); |
---|
119 | #endif |
---|
120 | getstryng(input); |
---|
121 | *ch = input[0]; |
---|
122 | uppercase(ch); |
---|
123 | } while (*ch != 'A' && *ch != 'R' && *ch != 'N' && *ch != 'F'); |
---|
124 | } |
---|
125 | if (*ch == 'F'){ |
---|
126 | outtreename[0] = '\0'; |
---|
127 | while (outtreename[0] =='\0'){ |
---|
128 | printf("Please enter a tree file name>"); |
---|
129 | #ifdef MAC |
---|
130 | fixmacfile(outtreename); |
---|
131 | #endif |
---|
132 | #ifdef WIN32 |
---|
133 | phyFillScreenColor(); |
---|
134 | #endif |
---|
135 | getstryng(outtreename); |
---|
136 | } |
---|
137 | FClose(*fp_outtree); |
---|
138 | } |
---|
139 | if (*ch == 'R' || *ch == 'A' || *ch == 'F' || !waswritten){ |
---|
140 | openfile(fp_outtree,outtreename,"output tree file", |
---|
141 | (*ch == 'A' && waswritten) ? "a" : "w", |
---|
142 | progname,outtreename); |
---|
143 | } |
---|
144 | } /* treeoptions */ |
---|
145 | |
---|
146 | |
---|
147 | void window(adjwindow action, long *leftedge, long *topedge, long hscroll, |
---|
148 | long vscroll, long treelines, long screenlines, |
---|
149 | long screenwidth, long farthest, boolean subtree) |
---|
150 | { |
---|
151 | /* move viewing window of tree */ |
---|
152 | switch (action) { |
---|
153 | |
---|
154 | case left: |
---|
155 | if (*leftedge != 1) |
---|
156 | *leftedge -= hscroll; |
---|
157 | break; |
---|
158 | |
---|
159 | case downn: |
---|
160 | /* The 'topedge + 6' is needed to allow downward scrolling |
---|
161 | when part of the tree is above the screen and only 1 or 2 lines |
---|
162 | are below it. */ |
---|
163 | if (treelines - *topedge + 6 >= screenlines) |
---|
164 | *topedge += vscroll; |
---|
165 | break; |
---|
166 | |
---|
167 | case upp: |
---|
168 | if (*topedge != 1) |
---|
169 | *topedge -= vscroll; |
---|
170 | break; |
---|
171 | |
---|
172 | case right: |
---|
173 | if ((farthest + 6 + nmlngth + ((subtree) ? 8 : 0)) > |
---|
174 | (*leftedge + screenwidth)) |
---|
175 | *leftedge += hscroll; |
---|
176 | break; |
---|
177 | } |
---|
178 | } /* window */ |
---|
179 | |
---|
180 | |
---|
181 | void pregraph(boolean local_ansi) |
---|
182 | { |
---|
183 | /* turn on graphic characters */ |
---|
184 | /* used in move & dolmove */ |
---|
185 | printf(local_ansi ? "\033(0" : ""); |
---|
186 | } /* pregraph */ |
---|
187 | |
---|
188 | |
---|
189 | void pregraph2(boolean local_ansi) |
---|
190 | { |
---|
191 | /* turn on graphic characters */ |
---|
192 | /* used in dnamove & retree */ |
---|
193 | if (local_ansi) { |
---|
194 | printf("\033(0"); |
---|
195 | printf("\033[10m"); |
---|
196 | } |
---|
197 | } /* pregraph2 */ |
---|
198 | |
---|
199 | |
---|
200 | void postgraph(boolean local_ansi) |
---|
201 | { |
---|
202 | /* turn off graphic characters */ |
---|
203 | /* used in move & dolmove */ |
---|
204 | printf(local_ansi ? "\033(B" : ""); |
---|
205 | } /* postgraph */ |
---|
206 | |
---|
207 | |
---|
208 | void postgraph2(boolean local_ansi) |
---|
209 | { |
---|
210 | /* turn off graphic characters */ |
---|
211 | /* used in dnamove & retree */ |
---|
212 | if (local_ansi) { |
---|
213 | printf("\033[11m"); |
---|
214 | printf("\033(B"); |
---|
215 | } |
---|
216 | } /* postgraph2 */ |
---|
217 | |
---|
218 | |
---|
219 | void nextinc(long *dispchar, long *dispword, long *dispbit, long chars, |
---|
220 | long local_bits, boolean *display, steptr numsteps, steptr weight) |
---|
221 | { |
---|
222 | /* show next incompatible character */ |
---|
223 | /* used in move & dolmove */ |
---|
224 | long disp0; |
---|
225 | boolean done; |
---|
226 | |
---|
227 | *display = true; |
---|
228 | disp0 = *dispchar; |
---|
229 | done = false; |
---|
230 | do { |
---|
231 | (*dispchar)++; |
---|
232 | if (*dispchar > chars) { |
---|
233 | *dispchar = 1; |
---|
234 | done = (disp0 == 0); |
---|
235 | } |
---|
236 | } while (!(numsteps[*dispchar - 1] > |
---|
237 | weight[*dispchar - 1] || |
---|
238 | *dispchar == disp0 || done)); |
---|
239 | *dispword = (*dispchar - 1) / local_bits + 1; |
---|
240 | *dispbit = (*dispchar - 1) % local_bits + 1; |
---|
241 | } /* nextinc */ |
---|
242 | |
---|
243 | |
---|
244 | void nextchar(long *dispchar, long *dispword, long *dispbit, long chars, |
---|
245 | long local_bits, boolean *display) |
---|
246 | { |
---|
247 | /* show next character */ |
---|
248 | /* used in move & dolmove */ |
---|
249 | *display = true; |
---|
250 | (*dispchar)++; |
---|
251 | if (*dispchar > chars) |
---|
252 | *dispchar = 1; |
---|
253 | *dispword = (*dispchar - 1) / local_bits + 1; |
---|
254 | *dispbit = (*dispchar - 1) % local_bits + 1; |
---|
255 | } /* nextchar */ |
---|
256 | |
---|
257 | |
---|
258 | void prevchar(long *dispchar, long *dispword, long *dispbit, long chars, |
---|
259 | long local_bits, boolean *display) |
---|
260 | { |
---|
261 | /* show previous character */ |
---|
262 | /* used in move & dolmove */ |
---|
263 | *display = true; |
---|
264 | (*dispchar)--; |
---|
265 | if (*dispchar < 1) |
---|
266 | *dispchar = chars; |
---|
267 | *dispword = (*dispchar - 1) / local_bits + 1; |
---|
268 | *dispbit = (*dispchar - 1) % local_bits + 1; |
---|
269 | } /* prevchar */ |
---|
270 | |
---|
271 | |
---|
272 | void show(long *dispchar, long *dispword, long *dispbit, long chars, |
---|
273 | long local_bits, boolean *display) |
---|
274 | { |
---|
275 | /* used in move & dolmove */ |
---|
276 | long i; |
---|
277 | boolean ok; |
---|
278 | |
---|
279 | do { |
---|
280 | printf("SHOW: (Character number or 0 to see none)? "); |
---|
281 | inpnum(&i, &ok); |
---|
282 | ok = (ok && (i == 0 || (i >= 1 && i <= chars))); |
---|
283 | if (ok && i != 0) { |
---|
284 | *display = true; |
---|
285 | *dispchar = i; |
---|
286 | *dispword = (i - 1) / local_bits + 1; |
---|
287 | *dispbit = (i - 1) % local_bits + 1; |
---|
288 | } |
---|
289 | if (ok && i == 0) |
---|
290 | *display = false; |
---|
291 | } while (!ok); |
---|
292 | } /* show */ |
---|
293 | |
---|