| 1 |
/* |
| 2 |
* Gregorio is a program that translates gabc files to GregorioTeX |
| 3 |
* This header prototypes gabc-format handling data structures and entry points. |
| 4 |
* |
| 5 |
* Copyright (C) 2006-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 |
#ifndef GABC_H |
| 24 |
#define GABC_H |
| 25 |
|
| 26 |
#include "struct.h" |
| 27 |
|
| 28 |
/* functions to read gabc */ |
| 29 |
gregorio_note *gabc_det_notes_from_string(char *str, char *macros[10], |
| 30 |
gregorio_scanner_location *loc, const gregorio_score *score); |
| 31 |
void gabc_det_notes_finish(void); |
| 32 |
gregorio_element *gabc_det_elements_from_string(char *str, int *current_key, |
| 33 |
char *macros[10], gregorio_scanner_location *loc, |
| 34 |
gregorio_shape *punctum_inclinatum_orientation, |
| 35 |
const gregorio_score *const score); |
| 36 |
gregorio_glyph *gabc_det_glyphs_from_notes(gregorio_note *current_note, |
| 37 |
int *current_key, gregorio_shape *punctum_inclinatum_orientation, |
| 38 |
const gregorio_score *score); |
| 39 |
void gabc_digest(const void *buf, size_t size); |
| 40 |
int gabc_score_determination_lex_destroy(void); |
| 41 |
int gabc_notes_determination_lex_destroy(void); |
| 42 |
char *gabc_unescape(const char *string); |
| 43 |
|
| 44 |
/* see comments on gregorio_add_note_to_a_glyph for meaning of these |
| 45 |
* variables */ |
| 46 |
typedef enum gabc_determination { |
| 47 |
DET_NO_END, |
| 48 |
DET_END_OF_CURRENT, |
| 49 |
DET_END_OF_PREVIOUS, |
| 50 |
DET_END_OF_BOTH |
| 51 |
} gabc_determination; |
| 52 |
|
| 53 |
static __inline void gabc_update_location(gregorio_scanner_location *const loc, |
| 54 |
const char *const bytes, const size_t length) |
| 55 |
{ |
| 56 |
size_t i; |
| 57 |
|
| 58 |
/* to be compatible with LilyPond, this algorithm is based on Lilypond's |
| 59 |
* Source_file::get_counts */ |
| 60 |
|
| 61 |
/* possible future enhancement: make the tabstop size configurable */ |
| 62 |
|
| 63 |
loc->first_line = loc->last_line; |
| 64 |
loc->first_column = loc->last_column; |
| 65 |
loc->first_offset = loc->last_offset; |
| 66 |
|
| 67 |
for (i = 0; i < length; ++i) { |
| 68 |
if (bytes[i] == '\n') { |
| 69 |
++loc->last_line; |
| 70 |
loc->last_column = 0; |
| 71 |
loc->last_offset = 0; |
| 72 |
} else if (((unsigned char)bytes[i] & 0xc0u) != 0x80u) { |
| 73 |
/* if two highest bits are 1 and 0, it's a continuation byte, |
| 74 |
* so count everything else, which is either a single-byte |
| 75 |
* character or the first byte of a multi-byte sequence */ |
| 76 |
|
| 77 |
if (bytes[i] == '\t') { |
| 78 |
loc->last_column = (loc->last_column / 8 + 1) * 8; |
| 79 |
} else { |
| 80 |
++loc->last_column; |
| 81 |
} |
| 82 |
++loc->last_offset; |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
#endif |