Debian Codegraph @

texk/gregorio/gregorio-src/src/dump/dump.c

raw
1 /*
2 * Gregorio is a program that translates gabc files to GregorioTeX.
3 * This file provides functions to dump out Gregorio structures.
4 *
5 * Copyright (C) 2007-2025 The Gregorio Project (see CONTRIBUTORS.md)
6 *
7 * This file is part of Gregorio.
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #include "config.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include "bool.h"
27 #include "struct.h"
28 #include "unicode.h"
29 #include "messages.h"
30 #include "plugins.h"
31 #include "support.h"
32
33 static const char *dump_style_to_string(grestyle_style style)
34 {
35 static char buf[50];
36
37 gregorio_snprintf(buf, sizeof buf, "%16s", grestyle_style_to_string(style));
38 return buf;
39 }
40
41 void dump_write_characters(FILE *const f,
42 const gregorio_character * current_character)
43 {
44 while (current_character) {
45 fprintf(f,
46 "---------------------------------------------------------------------\n");
47 if (current_character->is_character) {
48 fprintf(f, " character ");
49 gregorio_print_unichar(f, current_character->cos.character);
50 fprintf(f, "\n");
51 } else {
52 switch (current_character->cos.s.type) {
53 case ST_T_BEGIN:
54 fprintf(f, " beginning of style %s\n",
55 dump_style_to_string(current_character->cos.s.style));
56 break;
57 case ST_T_END:
58 fprintf(f, " end of style %s\n",
59 dump_style_to_string(current_character->cos.s.style));
60 break;
61 default:
62 /* not reachable unless there's a programming error */
63 /* LCOV_EXCL_START */
64 fprintf(f, " !! IMPROPER STYLE !! %s\n",
65 dump_style_to_string(current_character->cos.s.style));
66 break;
67 /* LCOV_EXCL_STOP */
68 }
69 }
70 current_character = current_character->next_character;
71 }
72 }
73
74 static const char *dump_bool(bool value) {
75 return value? "true" : "false";
76 }
77
78 static const char *dump_pitch(const char height, const char highest_pitch) {
79 static char buf[20];
80 if (height >= LOWEST_PITCH && height <= highest_pitch) {
81 char pitch = height + 'a' - LOWEST_PITCH;
82 if (pitch == 'o') {
83 pitch = 'p';
84 }
85 gregorio_snprintf(buf, 20, "%c", pitch);
86 } else {
87 /* not reachable unless there's a programming error */
88 gregorio_snprintf(buf, 20, "?%d", height); /* LCOV_EXCL_LINE */
89 }
90 return buf;
91 }
92
93 static void dump_hepisema_adjustment(FILE *const f, const gregorio_note *note,
94 const gregorio_sign_orientation orientation, const char *const which) {
95 unsigned short index = note->he_adjustment_index[orientation];
96 if (index) {
97 gregorio_hepisema_adjustment *adj = gregorio_get_hepisema_adjustment(
98 index);
99 fprintf(f, " %s hepisema group %d\n", which, index);
100 fprintf(f, " %s hep. vbasepos %d (%s)\n", which,
101 adj->vbasepos,
102 gregorio_hepisema_vbasepos_to_string(adj->vbasepos));
103 if (adj->nudge) {
104 fprintf(f, " %s hepisema nudge %s\n", which, adj->nudge);
105 }
106 }
107 }
108
109 void dump_write_score(FILE *f, gregorio_score *score)
110 {
111 gregorio_voice_info *voice_info = score->first_voice_info;
112 int i;
113 int annotation_num;
114 gregorio_syllable *syllable;
115 gregorio_header *header;
116
117 gregorio_assert(f, dump_write_score, "call with NULL file", return);
118
119 fprintf(f,
120 "=====================================================================\n"
121 " SCORE INFOS\n"
122 "=====================================================================\n");
123 if (score->number_of_voices) {
124 fprintf(f, " number_of_voices %d\n",
125 score->number_of_voices);
126 }
127 if (score->name) {
128 fprintf(f, " name %s\n", score->name);
129 }
130 if (score->gabc_copyright) {
131 fprintf(f, " gabc_copyright %s\n", score->gabc_copyright);
132 }
133 if (score->score_copyright) {
134 fprintf(f, " score_copyright %s\n", score->score_copyright);
135 }
136 if (score->author) {
137 fprintf(f, " author %s\n", score->author);
138 }
139 if (score->mode) {
140 fprintf(f, " mode %s\n", score->mode);
141 }
142 if (score->mode_modifier) {
143 fprintf(f, " mode_modifier %s\n", score->mode_modifier);
144 }
145 if (score->mode_differentia) {
146 fprintf(f, " mode_differentia %s\n", score->mode_differentia);
147 }
148 if (score->staff_lines != 4) {
149 fprintf(f, " staff_lines %d\n", (int)score->staff_lines);
150 }
151 if (score->nabc_lines) {
152 fprintf(f, " nabc_lines %d\n", (int)score->nabc_lines);
153 }
154 if (score->legacy_oriscus_orientation) {
155 fprintf(f, " oriscus-orientation legacy\n");
156 }
157 fprintf(f, "\n\n"
158 "=====================================================================\n"
159 " HEADERS\n"
160 "=====================================================================\n");
161 for (header = score->headers; header; header = header->next) {
162 fprintf(f, " %-25s %s\n", header->name, header->value);
163 }
164 fprintf(f, "\n\n"
165 "=====================================================================\n"
166 " VOICES INFOS\n"
167 "=====================================================================\n");
168 for (i = 0; i < score->number_of_voices; i++) {
169 fprintf(f, " Voice %d\n", i + 1);
170 if (voice_info->initial_clef.line) {
171 fprintf(f, " initial_key %d (%c%d)\n",
172 gregorio_calculate_new_key(voice_info->initial_clef),
173 gregorio_clef_to_char(voice_info->initial_clef.clef),
174 voice_info->initial_clef.line);
175 if (voice_info->initial_clef.flatted) {
176 fprintf(f, " flatted_key true\n");
177 }
178 if (voice_info->initial_clef.secondary_line) {
179 fprintf(f, " secondary_clef %c%d\n",
180 gregorio_clef_to_char(
181 voice_info->initial_clef.secondary_clef),
182 voice_info->initial_clef.secondary_line);
183 if (voice_info->initial_clef.secondary_flatted) {
184 fprintf(f, " secondary_flatted_key true\n");
185 }
186 }
187 }
188 for (annotation_num = 0; annotation_num < MAX_ANNOTATIONS;
189 ++annotation_num) {
190 if (score->annotation[annotation_num]) {
191 fprintf(f, " annotation %s\n",
192 score->annotation[annotation_num]);
193 }
194 }
195 voice_info = voice_info->next_voice_info;
196 }
197 fprintf(f, "\n\n"
198 "=====================================================================\n"
199 " SCORE\n"
200 "=====================================================================\n");
201 for (syllable = score->first_syllable; syllable;
202 syllable = syllable->next_syllable) {
203 gregorio_element *element;
204 fprintf(f, " type 0 (GRE_SYLLABLE)\n");
205 if (syllable->position) {
206 fprintf(f, " position %d (%s)\n",
207 syllable->position,
208 gregorio_word_position_to_string(syllable->position));
209 }
210 if (syllable->no_linebreak_area != NLBA_NORMAL) {
211 fprintf(f, " no line break area %s\n",
212 gregorio_nlba_to_string(syllable->no_linebreak_area));
213 }
214 if (syllable->euouae != EUOUAE_NORMAL) {
215 fprintf(f, " euouae %s\n",
216 gregorio_euouae_to_string(syllable->euouae));
217 }
218 if (syllable->clear) {
219 fprintf(f, " clear true\n");
220 }
221 if (syllable->text) {
222 if (syllable->translation) {
223 fprintf(f, "\n Text\n");
224 }
225 dump_write_characters(f, syllable->text);
226 }
227 if ((syllable->translation
228 && syllable->translation_type != TR_WITH_CENTER_END)
229 || syllable->translation_type == TR_WITH_CENTER_END) {
230 fprintf(f, "\n Translation type %s",
231 gregorio_tr_centering_to_string
232 (syllable->translation_type));
233 if (syllable->translation_type == TR_WITH_CENTER_END) {
234 fprintf(f, "\n");
235 }
236 }
237 if (syllable->translation) {
238 fprintf(f, "\n Translation\n");
239 dump_write_characters(f, syllable->translation);
240 }
241 if (syllable->abovelinestext) {
242 fprintf(f, "\n Abovelinestext\n %s", syllable->abovelinestext);
243 }
244 for (element = *syllable->elements; element; element = element->next) {
245 gregorio_glyph *glyph;
246 fprintf(f, "---------------------------------------------------------------------\n");
247 if (element->type) {
248 fprintf(f, " type %d (%s)\n",
249 element->type, gregorio_type_to_string(element->type));
250 }
251 switch (element->type) {
252 case GRE_CUSTOS:
253 if (element->u.misc.pitched.pitch) {
254 fprintf(f, " pitch %s\n",
255 dump_pitch(element->u.misc.pitched.pitch,
256 score->highest_pitch));
257 }
258 if (element->u.misc.pitched.force_pitch) {
259 fprintf(f, " force_pitch true\n");
260 }
261 break;
262 case GRE_SUPPRESS_CUSTOS:
263 /* not handling this would generate an error below */
264 break;
265 case GRE_SPACE:
266 if (element->u.misc.unpitched.info.space) {
267 char *factor = element->u.misc.unpitched.info.
268 ad_hoc_space_factor;
269 fprintf(f, " space %d (%s)%s%s\n",
270 element->u.misc.unpitched.info.space,
271 gregorio_space_to_string(
272 element->u.misc.unpitched.info.space),
273 factor? " x " : "", factor? factor : "");
274 }
275 break;
276 case GRE_TEXVERB_ELEMENT:
277 fprintf(f, " TeX string \"%s\"\n",
278 gregorio_texverb(element->texverb));
279 break;
280 case GRE_NLBA:
281 fprintf(f, " nlba %d (%s)\n",
282 element->u.misc.unpitched.info.nlba,
283 gregorio_nlba_to_string(element->u.misc.unpitched.info.
284 nlba));
285 break;
286 case GRE_ALT:
287 fprintf(f, " Above lines text \"%s\"\n",
288 gregorio_texverb(element->texverb));
289 break;
290 case GRE_BAR:
291 if (element->u.misc.unpitched.info.bar) {
292 fprintf(f, " bar %d (%s)\n",
293 element->u.misc.unpitched.info.bar,
294 gregorio_bar_to_string(element->u.misc.unpitched.
295 info.bar));
296 if (element->u.misc.unpitched.special_sign) {
297 fprintf(f, " special sign %d (%s)\n",
298 element->u.misc.unpitched.special_sign,
299 gregorio_sign_to_string(element->
300 u.misc.unpitched.special_sign));
301 }
302 }
303 break;
304 case GRE_CLEF:
305 if (element->u.misc.clef.line) {
306 fprintf(f, " clef %d (%c%d)\n",
307 gregorio_calculate_new_key(element->u.misc.clef),
308 gregorio_clef_to_char(element->u.misc.clef.clef),
309 element->u.misc.clef.line);
310 if (element->u.misc.clef.flatted) {
311 fprintf(f, " flatted_key true\n");
312 }
313 if (element->u.misc.clef.secondary_line) {
314 fprintf(f, " secondary_clef %c%d\n",
315 gregorio_clef_to_char(
316 element->u.misc.clef.secondary_clef),
317 element->u.misc.clef.secondary_line);
318 if (element->u.misc.clef.secondary_flatted) {
319 fprintf(f, " secondary_flatted_key true\n");
320 }
321 }
322 }
323 break;
324 case GRE_END_OF_LINE:
325 if (element->u.misc.unpitched.info.eol_ragged) {
326 fprintf(f, " ragged true\n");
327 }
328 if (element->u.misc.unpitched.info.eol_forces_custos) {
329 fprintf(f, " forces custos %s\n",
330 dump_bool(element
331 ->u.misc.unpitched.info.eol_forces_custos_on));
332 }
333 break;
334 case GRE_ELEMENT:
335 for (glyph = element->u.first_glyph; glyph;
336 glyph = glyph->next) {
337 gregorio_note *note;
338 fprintf(f, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
339 if (glyph->type) {
340 fprintf(f, " type %d (%s)\n",
341 glyph->type, gregorio_type_to_string(glyph->
342 type));
343 }
344 switch (glyph->type) {
345 case GRE_TEXVERB_GLYPH:
346 fprintf(f, " TeX string \"%s\"\n",
347 gregorio_texverb(glyph->texverb));
348 break;
349
350 case GRE_SPACE:
351 fprintf(f, " space %d (%s)\n",
352 glyph->u.misc.unpitched.info.space,
353 gregorio_space_to_string(glyph->u.misc.
354 unpitched.info.space));
355 break;
356
357 case GRE_GLYPH:
358 fprintf(f, " glyph_type %d (%s)\n",
359 glyph->u.notes.glyph_type,
360 gregorio_glyph_type_to_string(glyph->u.notes.
361 glyph_type));
362 if (glyph->u.notes.is_cavum) {
363 fprintf(f, " is_cavum true\n");
364 }
365 if (glyph->u.notes.liquescentia) {
366 fprintf(f, " liquescentia %d (%s)\n",
367 glyph->u.notes.liquescentia,
368 gregorio_liquescentia_to_string(
369 glyph->u.notes.liquescentia));
370 }
371 break;
372
373 default:
374 /* not reachable unless there's a programming error */
375 /* LCOV_EXCL_START */
376 fprintf(f, " !!! NOT ALLOWED !!! %s\n",
377 gregorio_type_to_string(glyph->type));
378 break;
379 /* LCOV_EXCL_STOP */
380 }
381 if (glyph->type == GRE_GLYPH) {
382 for (note = glyph->u.notes.first_note; note;
383 note = note->next) {
384 fprintf(f, "- - - - - - - - - - - - - - - - - - - - - - - \n");
385 if (note->type) {
386 fprintf(f, " type %d (%s)\n",
387 note->type,
388 gregorio_type_to_string(note->type));
389 }
390 switch (note->type) {
391 case GRE_NOTE:
392 if (note->u.note.pitch) {
393 fprintf(f, " pitch %s\n",
394 dump_pitch(note->u.note.pitch,
395 score->highest_pitch));
396 }
397 if (note->u.note.shape) {
398 fprintf(f, " shape %d (%s)\n",
399 note->u.note.shape,
400 gregorio_shape_to_string(
401 note->u.note.shape));
402 }
403 if (note->u.note.is_cavum) {
404 fprintf(f, " is_cavum true\n");
405 }
406 if (note->u.note.liquescentia) {
407 fprintf(f, " liquescentia %d (%s)\n",
408 note->u.note.liquescentia,
409 gregorio_liquescentia_to_string(
410 note->u.note.liquescentia));
411 }
412 break;
413
414 default:
415 /* not reachable unless there's a programming error */
416 /* LCOV_EXCL_START */
417 fprintf(f, " !!! NOT ALLOWED !!! %s\n",
418 gregorio_type_to_string(note->type));
419 break;
420 /* LCOV_EXCL_STOP */
421 }
422 if (note->texverb) {
423 fprintf(f, " TeX string \"%s\"\n",
424 gregorio_texverb(note->texverb));
425 }
426 if (note->choral_sign) {
427 fprintf(f, " choral sign \"%s\"\n",
428 note->choral_sign);
429 }
430 if (note->shape_hint) {
431 fprintf(f, " shape hint \"%s\"\n",
432 note->shape_hint);
433 }
434 if (note->signs) {
435 fprintf(f, " signs %d (%s)\n",
436 note->signs,
437 gregorio_sign_to_string(note->signs));
438 }
439 if (note->signs & _V_EPISEMA && note->v_episema_height) {
440 if (note->v_episema_height < note->u.note.pitch) {
441 fprintf(f, " v episema forced BELOW\n");
442 }
443 else {
444 fprintf(f, " v episema forced ABOVE\n");
445 }
446 }
447 if ((note->signs == _PUNCTUM_MORA
448 || note->signs == _V_EPISEMA_PUNCTUM_MORA)
449 && note->mora_vposition) {
450 fprintf(f, " mora vposition %s\n",
451 gregorio_vposition_to_string(note->
452 mora_vposition));
453 }
454 if (note->special_sign) {
455 fprintf(f, " special sign %d (%s)\n",
456 note->special_sign,
457 gregorio_sign_to_string(
458 note->special_sign));
459 }
460 if (note->h_episema_above == HEPISEMA_AUTO
461 && note->h_episema_below == HEPISEMA_AUTO) {
462 fprintf(f, " auto hepisema size %d (%s)\n",
463 note->h_episema_above_size,
464 grehepisema_size_to_string(note->
465 h_episema_above_size));
466 fprintf(f, " auto hepisema bridge %s\n",
467 dump_bool(note->h_episema_above_connect));
468 }
469 else {
470 if (note->h_episema_above == HEPISEMA_FORCED) {
471 fprintf(f, " above hepisema size %d (%s)\n",
472 note->h_episema_above_size,
473 grehepisema_size_to_string(note->
474 h_episema_above_size));
475 fprintf(f, " above hepisema bridge %s\n",
476 dump_bool(note->h_episema_above_connect));
477 }
478 if (note->h_episema_below == HEPISEMA_FORCED) {
479 fprintf(f, " below hepisema size %d (%s)\n",
480 note->h_episema_below_size,
481 grehepisema_size_to_string(note->
482 h_episema_below_size));
483 fprintf(f, " below hepisema bridge %s\n",
484 dump_bool(note->h_episema_below_connect));
485 }
486 }
487 dump_hepisema_adjustment(f, note, SO_OVER, "above");
488 dump_hepisema_adjustment(f, note, SO_UNDER,
489 "below");
490 switch (note->high_ledger_specificity) {
491 case LEDGER_SUPPOSED:
492 break;
493 case LEDGER_EXPLICIT:
494 fprintf(f, " explicit high line %s\n",
495 dump_bool(note->high_ledger_line));
496 break;
497 case LEDGER_DRAWN:
498 fprintf(f, " drawn high line %s\n",
499 dump_bool(note->high_ledger_line));
500 break;
501 case LEDGER_EXPLICITLY_DRAWN:
502 fprintf(f, " forced drawn high line %s\n",
503 dump_bool(note->high_ledger_line));
504 break;
505 }
506 switch (note->low_ledger_specificity) {
507 case LEDGER_SUPPOSED:
508 break;
509 case LEDGER_EXPLICIT:
510 fprintf(f, " explicit low line %s\n",
511 dump_bool(note->low_ledger_line));
512 break;
513 case LEDGER_DRAWN:
514 fprintf(f, " drawn low line %s\n",
515 dump_bool(note->low_ledger_line));
516 break;
517 case LEDGER_EXPLICITLY_DRAWN:
518 fprintf(f, " forced drawn low line %s\n",
519 dump_bool(note->low_ledger_line));
520 break;
521 }
522 }
523 }
524 }
525 break;
526
527 default:
528 /* not reachable unless there's a programming error */
529 /* LCOV_EXCL_START */
530 fprintf(f, " !!! NOT ALLOWED !!! %s\n",
531 gregorio_type_to_string(element->type));
532 break;
533 /* LCOV_EXCL_STOP */
534 }
535 if (element->nabc_lines) {
536 fprintf(f, " nabc_lines %d\n",
537 (int)element->nabc_lines);
538 }
539 if (element->nabc_lines && element->nabc) {
540 for (i = 0; i < (int)element->nabc_lines; i++) {
541 if (element->nabc[i]) {
542 fprintf(f, " nabc_line %d \"%s\"\n",
543 (int)(i+1), element->nabc[i]);
544 }
545 }
546 }
547 }
548 fprintf(f, "=====================================================================\n");
549 }
550 }