lorid

convert chordpro to pdf
git clone git://git.relim.de/lorid.git
Log | Files | Refs | README | LICENSE

commit 2a254ebb6b6bde06688b62cc295662104f5754e3
parent a2b5b214ba55c25c224975571a08d0ff751dada0
Author: nibo <nibo@relim.de>
Date:   Sat, 12 Oct 2024 09:46:00 +0200

Change function definition style

Diffstat:
Mchordpro.c | 267+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mchordpro.h | 1+
Mconfig.c | 60++++++++++++++++++++++++++++++++++++++++--------------------
Mfontconfig.c | 6++++--
Mlorid.c | 3++-
Mout_pdf.c | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mutil.c | 33++++++++++++++++++++++-----------
7 files changed, 311 insertions(+), 155 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -244,7 +244,8 @@ const char *style_property_type_enums[] = { "SPT_COLOR" }; -static void cho_debug_chord_print(struct ChoChord *chord) +static void +cho_debug_chord_print(struct ChoChord *chord) { printf("---- BEGIN CHORD ----\n"); printf("is_canonical: %d\n", chord->is_canonical); @@ -270,7 +271,8 @@ static void cho_debug_chord_print(struct ChoChord *chord) #endif /* DEBUG */ -static void cho_log(enum LogLevel level, const char *msg, ...) +static void +cho_log(enum LogLevel level, const char *msg, ...) { va_list va; va_start(va, msg); @@ -328,7 +330,8 @@ static void cho_log(enum LogLevel level, const char *msg, ...) #endif } -static inline bool is_whitespace(char c) +static inline bool +is_whitespace(char c) { if ( c == '\t' || @@ -341,7 +344,8 @@ static inline bool is_whitespace(char c) return false; } -struct RGBColor *cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue) +struct RGBColor * +cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue) { struct RGBColor *color = malloc(sizeof(struct RGBColor)); color->red = red; @@ -350,7 +354,8 @@ struct RGBColor *cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue) return color; } -struct RGBColor *cho_rgbcolor_copy(struct RGBColor *color) +struct RGBColor * +cho_rgbcolor_copy(struct RGBColor *color) { struct RGBColor *copy = malloc(sizeof(struct RGBColor)); copy->red = color->red; @@ -359,7 +364,8 @@ struct RGBColor *cho_rgbcolor_copy(struct RGBColor *color) return copy; } -const char *cho_rgbcolor_to_string(struct RGBColor *color) +const char * +cho_rgbcolor_to_string(struct RGBColor *color) { static char str[8]; str[7] = 0; @@ -367,7 +373,8 @@ const char *cho_rgbcolor_to_string(struct RGBColor *color) return (const char *)&str; } -struct RGBColor *cho_rgbcolor_parse(const char *str) +struct RGBColor * +cho_rgbcolor_parse(const char *str) { struct RGBColor *color = malloc(sizeof(struct RGBColor)); size_t len = strlen(str); @@ -469,7 +476,8 @@ struct RGBColor *cho_rgbcolor_parse(const char *str) return color; } -struct RGBColor *cho_color_parse(const char *str) +struct RGBColor * +cho_color_parse(const char *str) { struct RGBColor *color = malloc(sizeof(struct RGBColor)); if (str[0] == '#') { @@ -526,7 +534,8 @@ struct RGBColor *cho_color_parse(const char *str) return color; } -struct Font *cho_font_new(void) +struct Font * +cho_font_new(void) { struct Font *font = malloc(sizeof(struct Font)); font->name = NULL; @@ -537,7 +546,8 @@ struct Font *cho_font_new(void) return font; } -struct Font *cho_font_copy(struct Font *font) +struct Font * +cho_font_copy(struct Font *font) { struct Font *copy = malloc(sizeof(struct Font)); if (font->name) @@ -551,13 +561,15 @@ struct Font *cho_font_copy(struct Font *font) return copy; } -void cho_font_free(struct Font *font) +void +cho_font_free(struct Font *font) { free(font->name); free(font); } -void cho_fonts_free(struct Font **fonts) +void +cho_fonts_free(struct Font **fonts) { int i = 0; while (fonts[i] != NULL) { @@ -567,7 +579,8 @@ void cho_fonts_free(struct Font **fonts) free(fonts); } -enum FontFamily cho_font_family_parse(const char *str) +enum FontFamily +cho_font_family_parse(const char *str) { if (!strcmp(str, font_families[FF_SANS])) { return FF_SANS; @@ -582,12 +595,14 @@ enum FontFamily cho_font_family_parse(const char *str) } } -const char *cho_font_family_to_config_string(enum FontFamily font_family) +const char * +cho_font_family_to_config_string(enum FontFamily font_family) { return font_families[font_family]; } -enum FontStyle cho_font_style_parse(const char *str) +enum FontStyle +cho_font_style_parse(const char *str) { if (!strcmp(str, font_styles[FS_ITALIC])) { return FS_ITALIC; @@ -600,12 +615,14 @@ enum FontStyle cho_font_style_parse(const char *str) } } -const char *cho_font_style_to_config_string(enum FontStyle style) +const char * +cho_font_style_to_config_string(enum FontStyle style) { return font_styles[style]; } -enum FontWeight cho_font_weight_parse(const char *str) +enum FontWeight +cho_font_weight_parse(const char *str) { if (strcasecmp(str, "bold") == 0) { return FW_BOLD; @@ -616,12 +633,14 @@ enum FontWeight cho_font_weight_parse(const char *str) } } -const char *cho_font_weight_to_config_string(enum FontWeight weight) +const char * +cho_font_weight_to_config_string(enum FontWeight weight) { return font_weights[weight]; } -void cho_font_print_as_toml(struct Font *font, const char *section) +void +cho_font_print_as_toml(struct Font *font, const char *section) { printf("[output.styles.%s.font]\n", section); printf("\n"); @@ -633,7 +652,8 @@ void cho_font_print_as_toml(struct Font *font, const char *section) printf("\n"); } -void cho_font_print(struct Font *font) +void +cho_font_print(struct Font *font) { printf("---- BEGIN FONT ----\n"); if (font->name) @@ -647,7 +667,8 @@ void cho_font_print(struct Font *font) printf("---- END FONT ------\n"); } -enum LineStyle cho_linestyle_parse(const char *str) +enum LineStyle +cho_linestyle_parse(const char *str) { if (!strcmp(str, "single")) { return LS_SINGLE; @@ -660,14 +681,16 @@ enum LineStyle cho_linestyle_parse(const char *str) } } -const char *cho_linestyle_to_config_string(enum LineStyle linestyle) +const char * +cho_linestyle_to_config_string(enum LineStyle linestyle) { return line_styles[linestyle]; } #ifdef DEBUG -static void cho_debug_the_default_style_properties(void) +static void +cho_debug_the_default_style_properties(void) { unsigned int i; for (i = 0; i<LENGTH(default_style_properties); i++) { @@ -698,7 +721,8 @@ static void cho_debug_the_default_style_properties(void) } } -void cho_debug_style_print(struct Style *style) +void +cho_debug_style_print(struct Style *style) { printf("---- BEGIN STYLE ----\n"); cho_font_print(style->font); @@ -722,7 +746,8 @@ void cho_debug_style_print(struct Style *style) #endif /* DEBUG */ -static bool cho_style_property_apply_default(enum SongFragmentType current_ftype, enum StylePropertyType ptype, struct Style *style) +static bool +cho_style_property_apply_default(enum SongFragmentType current_ftype, enum StylePropertyType ptype, struct Style *style) { unsigned int i; for (i = 0; i<LENGTH(default_style_properties); i++) { @@ -766,7 +791,8 @@ static bool cho_style_property_apply_default(enum SongFragmentType current_ftype return false; } -static void cho_style_apply_default(enum SongFragmentType current_ftype, struct Style *style) +static void +cho_style_apply_default(enum SongFragmentType current_ftype, struct Style *style) { if (current_ftype == SF_CHORUS) { if (!cho_style_property_apply_default(SF_CHORUS, SPT_FONT, style)) { @@ -785,7 +811,8 @@ static void cho_style_apply_default(enum SongFragmentType current_ftype, struct } } -struct Style *cho_style_new(void) +struct Style * +cho_style_new(void) { struct Style *style = malloc(sizeof(struct Style)); style->font = cho_font_new(); @@ -804,7 +831,8 @@ struct Style *cho_style_new(void) return style; } -struct Style *cho_style_copy(struct Style *style) +struct Style * +cho_style_copy(struct Style *style) { struct Style *copy = malloc(sizeof(struct Style)); copy->font = cho_font_copy(style->font); @@ -823,7 +851,8 @@ struct Style *cho_style_copy(struct Style *style) return copy; } -struct Style *cho_style_new_from_config(enum SongFragmentType ftype) +struct Style * +cho_style_new_from_config(enum SongFragmentType ftype) { struct PrintableItem *printable_item; switch (ftype) { @@ -854,14 +883,16 @@ struct Style *cho_style_new_from_config(enum SongFragmentType ftype) } } -struct Style *cho_style_new_default(void) +struct Style * +cho_style_new_default(void) { struct Style *style = cho_style_new_from_config(g_current_ftype); cho_style_apply_default(g_current_ftype, style); return style; } -void cho_style_free(struct Style *style) +void +cho_style_free(struct Style *style) { cho_font_free(style->font); free(style->foreground_color); @@ -874,7 +905,8 @@ void cho_style_free(struct Style *style) free(style); } -struct Font *cho_style_font_desc_parse(const char *str) +struct Font * +cho_style_font_desc_parse(const char *str) { if (strlen(str) == 0) { return NULL; @@ -986,7 +1018,8 @@ struct Font *cho_style_font_desc_parse(const char *str) return font; } -struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct Style *inherited_style) +struct Style * +cho_style_parse(const char *tag_name, struct Attr **attrs, struct Style *inherited_style) { size_t value_len, last_char; struct RGBColor *rgb_color; @@ -1259,7 +1292,8 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct return style; } -void cho_style_print_as_toml(struct Style *style, const char *section) +void +cho_style_print_as_toml(struct Style *style, const char *section) { printf("foreground_color = \"%s\"\n", cho_rgbcolor_to_string(style->foreground_color)); printf("background_color = \"%s\"\n", cho_rgbcolor_to_string(style->background_color)); @@ -1277,7 +1311,8 @@ void cho_style_print_as_toml(struct Style *style, const char *section) cho_font_print_as_toml(style->font, section); } -static bool cho_style_change_default(struct StyleProperty sprop) +static bool +cho_style_change_default(struct StyleProperty sprop) { if (sprop.type == SPT_EMPTY) return false; @@ -1316,7 +1351,8 @@ static bool cho_style_change_default(struct StyleProperty sprop) return false; } -static bool cho_style_reset_default(void) +static bool +cho_style_reset_default(void) { unsigned int i; for (i = 0; i<LENGTH(default_style_properties); i++) { @@ -1340,7 +1376,8 @@ static bool cho_style_reset_default(void) return false; } -static struct Attr *cho_tag_attr_new(void) +static struct Attr * +cho_tag_attr_new(void) { struct Attr *attr = malloc(sizeof(struct Attr)); attr->name = NULL; @@ -1348,14 +1385,16 @@ static struct Attr *cho_tag_attr_new(void) return attr; } -static void cho_tag_attr_free(struct Attr *attr) +static void +cho_tag_attr_free(struct Attr *attr) { free(attr->name); free(attr->value); free(attr); } -static void cho_tag_attrs_free(struct Attr **attrs) +static void +cho_tag_attrs_free(struct Attr **attrs) { int a = 0; while (attrs[a] != NULL) { @@ -1365,7 +1404,8 @@ static void cho_tag_attrs_free(struct Attr **attrs) free(attrs); } -static struct Tag *cho_tag_new(void) +static struct Tag * +cho_tag_new(void) { struct Tag *tag = malloc(sizeof(struct Tag)); tag->name = NULL; @@ -1375,7 +1415,8 @@ static struct Tag *cho_tag_new(void) return tag; } -static void cho_tag_free(struct Tag *tag) +static void +cho_tag_free(struct Tag *tag) { free(tag->name); cho_style_free(tag->style); @@ -1384,7 +1425,8 @@ static void cho_tag_free(struct Tag *tag) free(tag); } -static bool cho_tag_close_last_unclosed(const char *tag_name, struct Tag **tags, int last_index) +static bool +cho_tag_close_last_unclosed(const char *tag_name, struct Tag **tags, int last_index) { int i = last_index; while (i >= 0) { @@ -1398,7 +1440,8 @@ static bool cho_tag_close_last_unclosed(const char *tag_name, struct Tag **tags, return false; } -static struct Style *cho_tag_style_inherit(struct Tag **tags, int prev_index) +static struct Style * +cho_tag_style_inherit(struct Tag **tags, int prev_index) { int i = prev_index; while (i >= 0) { @@ -1415,7 +1458,8 @@ static struct Style *cho_tag_style_inherit(struct Tag **tags, int prev_index) return NULL; } -static struct ChoMetadata *cho_metadata_new(void) +static struct ChoMetadata * +cho_metadata_new(void) { struct ChoMetadata *meta = malloc(sizeof(struct ChoMetadata)); meta->name = NULL; @@ -1424,7 +1468,8 @@ static struct ChoMetadata *cho_metadata_new(void) return meta; } -static void cho_metadata_free(struct ChoMetadata *meta) +static void +cho_metadata_free(struct ChoMetadata *meta) { free(meta->name); free(meta->value); @@ -1432,7 +1477,8 @@ static void cho_metadata_free(struct ChoMetadata *meta) free(meta); } -const char *cho_metadata_get(struct ChoMetadata **metadata, const char *name) +const char * +cho_metadata_get(struct ChoMetadata **metadata, const char *name) { int m; for (m = 0; metadata[m]; m++) { @@ -1443,7 +1489,8 @@ const char *cho_metadata_get(struct ChoMetadata **metadata, const char *name) return NULL; } -static struct ChoMetadata *cho_metadata_split(const char *directive_value) +static struct ChoMetadata * +cho_metadata_split(const char *directive_value) { struct ChoMetadata *meta = cho_metadata_new(); char *value = str_remove_leading_whitespace(directive_value); @@ -1483,7 +1530,8 @@ static struct ChoMetadata *cho_metadata_split(const char *directive_value) } } -static bool transposition_parse(const char *str, int *transpose) +static bool +transposition_parse(const char *str, int *transpose) { long i; char *endptr; @@ -1501,7 +1549,8 @@ static bool transposition_parse(const char *str, int *transpose) return true; } -static char *transposition_calc_chord_root(int index, enum NoteType type) +static char * +transposition_calc_chord_root(int index, enum NoteType type) { int transpose = *g_transpose; if (transpose == 0) { @@ -1578,7 +1627,8 @@ static char *transposition_calc_chord_root(int index, enum NoteType type) return NULL; } -static struct ChoChord *cho_chord_new(void) +static struct ChoChord * +cho_chord_new(void) { struct ChoChord *chord = malloc(sizeof(struct ChoChord)); chord->style = cho_style_new_default(); @@ -1592,7 +1642,8 @@ static struct ChoChord *cho_chord_new(void) } /* INFO: copy every field except for 'style' */ -static void cho_chord_complete(struct ChoChord *first, struct ChoChord *second) +static void +cho_chord_complete(struct ChoChord *first, struct ChoChord *second) { first->name = strdup(second->name); first->is_canonical = second->is_canonical; @@ -1609,7 +1660,8 @@ static void cho_chord_complete(struct ChoChord *first, struct ChoChord *second) } -static void cho_chord_free(struct ChoChord *chord) +static void +cho_chord_free(struct ChoChord *chord) { cho_style_free(chord->style); free(chord->name); @@ -1619,7 +1671,8 @@ static void cho_chord_free(struct ChoChord *chord) free(chord); } -static struct ChoChord *cho_chord_copy(struct ChoChord *chord) +static struct ChoChord * +cho_chord_copy(struct ChoChord *chord) { struct ChoChord *copy = malloc(sizeof(struct ChoChord)); copy->style = cho_style_copy(chord->style); @@ -1633,7 +1686,8 @@ static struct ChoChord *cho_chord_copy(struct ChoChord *chord) } /* returns how many bytes make up the root; returns 0 if no root was found */ -static int cho_chord_root_parse(const char *str, struct ChoChord *chord) +static int +cho_chord_root_parse(const char *str, struct ChoChord *chord) { const char *note = NULL; const char *sharp = NULL; @@ -1675,7 +1729,8 @@ static int cho_chord_root_parse(const char *str, struct ChoChord *chord) return 0; } -static char *cho_chord_qualifier_strip(const char *str) +static char * +cho_chord_qualifier_strip(const char *str) { if (str_starts_with(str, "m") || str_starts_with(str, "-")) { return strdup((char *)&str[1]); @@ -1683,7 +1738,8 @@ static char *cho_chord_qualifier_strip(const char *str) return strdup(str); } -static int cho_chord_qualifier_and_extension_parse(const char *str, struct ChoChord *chord) +static int +cho_chord_qualifier_and_extension_parse(const char *str, struct ChoChord *chord) { int i; for (i = 0; chord_extensions_major[i]; i++) { @@ -1725,7 +1781,8 @@ static int cho_chord_qualifier_and_extension_parse(const char *str, struct ChoCh return 0; } -static int cho_chord_bass_parse(const char *str, struct ChoChord *chord) +static int +cho_chord_bass_parse(const char *str, struct ChoChord *chord) { if (str[0] == '/') { const char *note = NULL; @@ -1759,7 +1816,8 @@ static int cho_chord_bass_parse(const char *str, struct ChoChord *chord) return 0; } -static struct ChoChord *cho_chord_parse(const char *str) +static struct ChoChord * +cho_chord_parse(const char *str) { struct ChoChord *chord = cho_chord_new(); size_t str_len = strlen(str); @@ -1791,7 +1849,8 @@ static struct ChoChord *cho_chord_parse(const char *str) return chord; } -char *cho_chord_name_generate(struct ChoChord *chord) +char * +cho_chord_name_generate(struct ChoChord *chord) { if (chord->is_canonical) { int n = 0; @@ -1838,7 +1897,8 @@ char *cho_chord_name_generate(struct ChoChord *chord) return strdup(chord->name); } -static struct ChoAnnotation *cho_annotation_new(void) +static struct ChoAnnotation * +cho_annotation_new(void) { struct ChoAnnotation *annot = malloc(sizeof(struct ChoAnnotation)); annot->style = cho_style_new_default(); @@ -1846,14 +1906,16 @@ static struct ChoAnnotation *cho_annotation_new(void) return annot; } -static void cho_annotation_free(struct ChoAnnotation *annot) +static void +cho_annotation_free(struct ChoAnnotation *annot) { cho_style_free(annot->style); free(annot->text); free(annot); } -static struct ChoAnnotation *cho_annotation_copy(struct ChoAnnotation *annot) +static struct ChoAnnotation * +cho_annotation_copy(struct ChoAnnotation *annot) { struct ChoAnnotation *copy = malloc(sizeof(struct ChoAnnotation)); copy->style = cho_style_copy(annot->style); @@ -1861,7 +1923,8 @@ static struct ChoAnnotation *cho_annotation_copy(struct ChoAnnotation *annot) return copy; } -int cho_text_above_count(struct ChoLineItemAbove **text_above) +int +cho_text_above_count(struct ChoLineItemAbove **text_above) { int i = 0; while (text_above[i] != NULL) @@ -1869,7 +1932,8 @@ int cho_text_above_count(struct ChoLineItemAbove **text_above) return i; } -static void cho_text_above_free(struct ChoLineItemAbove *text_above) +static void +cho_text_above_free(struct ChoLineItemAbove *text_above) { if (text_above->is_chord) { cho_chord_free(text_above->u.chord); @@ -1879,7 +1943,8 @@ static void cho_text_above_free(struct ChoLineItemAbove *text_above) free(text_above); } -static struct ChoLineItemAbove *cho_text_above_copy(struct ChoLineItemAbove *text_above) +static struct ChoLineItemAbove * +cho_text_above_copy(struct ChoLineItemAbove *text_above) { struct ChoLineItemAbove *copy = malloc(sizeof(struct ChoLineItemAbove)); copy->position = text_above->position; @@ -1892,7 +1957,8 @@ static struct ChoLineItemAbove *cho_text_above_copy(struct ChoLineItemAbove *tex return copy; } -static struct ChoLineItem *cho_line_item_new(void) +static struct ChoLineItem * +cho_line_item_new(void) { struct ChoLineItem *item = malloc(sizeof(struct ChoLineItem)); item->style = cho_style_new_default(); @@ -1900,14 +1966,16 @@ static struct ChoLineItem *cho_line_item_new(void) return item; } -static void cho_line_item_free(struct ChoLineItem *item) +static void +cho_line_item_free(struct ChoLineItem *item) { cho_style_free(item->style); free(item->text); free(item); } -static struct ChoLineItem *cho_line_item_copy(struct ChoLineItem *item) +static struct ChoLineItem * +cho_line_item_copy(struct ChoLineItem *item) { struct ChoLineItem *copy = malloc(sizeof(struct ChoLineItem)); copy->style = cho_style_copy(item->style); @@ -1915,7 +1983,8 @@ static struct ChoLineItem *cho_line_item_copy(struct ChoLineItem *item) return copy; } -int cho_line_item_count(struct ChoLineItem **items) +int +cho_line_item_count(struct ChoLineItem **items) { int i = 0; while (items[i] != NULL) @@ -1923,7 +1992,8 @@ int cho_line_item_count(struct ChoLineItem **items) return i; } -static struct ChoLine *cho_line_new(void) +static struct ChoLine * +cho_line_new(void) { struct ChoLine *line = malloc(sizeof(struct ChoLine)); line->text_above = NULL; @@ -1932,7 +2002,8 @@ static struct ChoLine *cho_line_new(void) return line; } -static void cho_line_free(struct ChoLine *line) +static void +cho_line_free(struct ChoLine *line) { int i; for (i = 0; line->lyrics[i]; i++) { @@ -1946,7 +2017,8 @@ static void cho_line_free(struct ChoLine *line) free(line); } -static int cho_line_compute_chord_position(struct ChoLine *line, int ly, int te) +static int +cho_line_compute_chord_position(struct ChoLine *line, int ly, int te) { if (ly == 0) return te; @@ -1959,7 +2031,8 @@ static int cho_line_compute_chord_position(struct ChoLine *line, int ly, int te) return lyrics_len + te; } -static struct ChoLabel *cho_section_label_copy(struct ChoLabel *label) +static struct ChoLabel * +cho_section_label_copy(struct ChoLabel *label) { struct ChoLabel *copy = malloc(sizeof(struct ChoLabel)); copy->name = strdup(label->name); @@ -1967,14 +2040,16 @@ static struct ChoLabel *cho_section_label_copy(struct ChoLabel *label) return copy; } -static void cho_section_label_free(struct ChoLabel *label) +static void +cho_section_label_free(struct ChoLabel *label) { free(label->name); cho_style_free(label->style); free(label); } -static struct ChoSection *cho_section_new(void) +static struct ChoSection * +cho_section_new(void) { struct ChoSection *section = malloc(sizeof(struct ChoSection)); section->type = ST_EMPTY; @@ -1983,7 +2058,8 @@ static struct ChoSection *cho_section_new(void) return section; } -static void cho_section_free(struct ChoSection *section) +static void +cho_section_free(struct ChoSection *section) { if (section->label) { cho_section_label_free(section->label); @@ -1996,7 +2072,8 @@ static void cho_section_free(struct ChoSection *section) free(section); } -static struct ChoSection *cho_section_copy(struct ChoSection *section) +static struct ChoSection * +cho_section_copy(struct ChoSection *section) { struct ChoSection *copy = malloc(sizeof(struct ChoSection)); copy->type = section->type; @@ -2029,7 +2106,8 @@ static struct ChoSection *cho_section_copy(struct ChoSection *section) return copy; } -static struct ChoSong *cho_song_new(void) +static struct ChoSong * +cho_song_new(void) { struct ChoSong *song = malloc(sizeof(struct ChoSong)); song->metadata = NULL; @@ -2037,7 +2115,8 @@ static struct ChoSong *cho_song_new(void) return song; } -int cho_song_count(struct ChoSong **songs) +int +cho_song_count(struct ChoSong **songs) { int i = 0; while (songs[i] != NULL) @@ -2045,7 +2124,8 @@ int cho_song_count(struct ChoSong **songs) return i; } -static void cho_song_free(struct ChoSong *song) +static void +cho_song_free(struct ChoSong *song) { int i; for (i = 0; song->metadata[i]; i++) { @@ -2059,7 +2139,8 @@ static void cho_song_free(struct ChoSong *song) free(song); } -void cho_songs_free(struct ChoSong **songs) +void +cho_songs_free(struct ChoSong **songs) { int so = 0; while (songs[so] != NULL) { @@ -2069,7 +2150,8 @@ void cho_songs_free(struct ChoSong **songs) free(songs); } -static struct ChoImage *cho_image_new(void) +static struct ChoImage * +cho_image_new(void) { struct ChoImage *image = malloc(sizeof(struct ChoImage)); image->id = NULL; @@ -2091,7 +2173,8 @@ static struct ChoImage *cho_image_new(void) return image; } -static void cho_image_free(struct ChoImage *image) +static void +cho_image_free(struct ChoImage *image) { free(image->id); free(image->src); @@ -2104,7 +2187,8 @@ enum OptionState { OS_VALUE }; -static struct ChoImage *cho_image_directive_parse(const char *str) +static struct ChoImage * +cho_image_directive_parse(const char *str) { struct ChoImage *image = cho_image_new(); int i = 0; @@ -2197,7 +2281,8 @@ static struct ChoImage *cho_image_directive_parse(const char *str) { } */ -static struct ChoSection *cho_find_previous_chorus(struct ChoSection **sections, int se) +static struct ChoSection * +cho_find_previous_chorus(struct ChoSection **sections, int se) { int i; for (i = se; i>=0; i--) { @@ -2208,7 +2293,8 @@ static struct ChoSection *cho_find_previous_chorus(struct ChoSection **sections, return NULL; } -static struct ChoDirective *cho_directive_new(void) +static struct ChoDirective * +cho_directive_new(void) { struct ChoDirective *directive = malloc(sizeof(struct ChoDirective)); directive->dtype = DT_EMPTY; @@ -2221,13 +2307,15 @@ static struct ChoDirective *cho_directive_new(void) return directive; } -static void cho_directive_free(struct ChoDirective *directive) +static void +cho_directive_free(struct ChoDirective *directive) { cho_style_free(directive->style); free(directive); } -static struct ChoDirective *cho_directive_parse(const char *name) +static struct ChoDirective * +cho_directive_parse(const char *name) { struct ChoDirective *directive = cho_directive_new(); int i = 0; @@ -2507,7 +2595,8 @@ END: return directive; } -struct ChoSong **cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) +struct ChoSong ** +cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) { g_config = config; g_chordpro_filepath = chordpro_filepath; diff --git a/chordpro.h b/chordpro.h @@ -256,6 +256,7 @@ enum BreakType { INFO: Depending on the 'dtype' the other fields have a meaningful value or not. */ + struct ChoDirective { enum DirectiveType dtype; enum SectionType stype; diff --git a/config.c b/config.c @@ -103,7 +103,8 @@ static struct Note notes_nashville[] = { { .note = "7", .sharp = NULL, .flat = "7b" }, }; -static struct PrintableItem *config_printable_item_new(const char *name) +static struct PrintableItem * +config_printable_item_new(const char *name) { struct PrintableItem *item = malloc(sizeof(struct PrintableItem)); item->name = strdup(name); @@ -111,14 +112,16 @@ static struct PrintableItem *config_printable_item_new(const char *name) return item; } -static void config_printable_item_free(struct PrintableItem *item) +static void +config_printable_item_free(struct PrintableItem *item) { free(item->name); cho_style_free(item->style); free(item); } -struct PrintableItem *config_printable_item_get(struct PrintableItem **items, const char *name) +struct PrintableItem * +config_printable_item_get(struct PrintableItem **items, const char *name) { int i = 0; while (items[i] != NULL) { @@ -130,7 +133,8 @@ struct PrintableItem *config_printable_item_get(struct PrintableItem **items, co return NULL; } -static enum NamingSystem config_naming_system_parse(const char *str) +static enum NamingSystem +config_naming_system_parse(const char *str) { if (!strcmp(str, naming_systems[NS_COMMON]) || !strcmp(str, "dutch")) { return NS_COMMON; @@ -149,12 +153,14 @@ static enum NamingSystem config_naming_system_parse(const char *str) } } -static const char *config_naming_system_to_config_string(enum NamingSystem system) +static const char * +config_naming_system_to_config_string(enum NamingSystem system) { return naming_systems[system]; } -static struct Note *config_note_new(void) +static struct Note * +config_note_new(void) { struct Note *note = malloc(sizeof(struct Note)); note->note = NULL; @@ -163,7 +169,8 @@ static struct Note *config_note_new(void) return note; } -static void config_note_free(struct Note *note) +static void +config_note_free(struct Note *note) { free(note->note); free(note->sharp); @@ -171,7 +178,8 @@ static void config_note_free(struct Note *note) free(note); } -static void config_notes_free(struct Note **notes) +static void +config_notes_free(struct Note **notes) { int n; for (n = 0; notes[n]; n++) { @@ -180,7 +188,8 @@ static void config_notes_free(struct Note **notes) free(notes); } -static struct Note **config_notes_new_default(enum NamingSystem system) +static struct Note ** +config_notes_new_default(enum NamingSystem system) { struct Note **notes_default = malloc(8 * sizeof(struct Note *)); struct Note *notes; @@ -221,7 +230,8 @@ static struct Note **config_notes_new_default(enum NamingSystem system) return notes_default; } -static struct Note **config_notes_load(toml_table_t *notes, const char *system) +static struct Note ** +config_notes_load(toml_table_t *notes, const char *system) { struct Note **custom_notes = malloc(8 * sizeof(struct Note *)); toml_array_t *arr = toml_table_array(notes, system); @@ -270,7 +280,8 @@ static struct Note **config_notes_load(toml_table_t *notes, const char *system) return NULL; } -static void config_notes_print_as_toml(enum NamingSystem system, struct Note **notes) +static void +config_notes_print_as_toml(enum NamingSystem system, struct Note **notes) { printf("%s = [\n", config_naming_system_to_config_string(system)); int i; @@ -288,12 +299,14 @@ static void config_notes_print_as_toml(enum NamingSystem system, struct Note **n printf("]\n\n"); } -static const char *config_parse_mode_to_config_string(enum ParseMode mode) +static const char * +config_parse_mode_to_config_string(enum ParseMode mode) { return parse_modes[mode]; } -static struct Config *config_load_default(void) +static struct Config * +config_load_default(void) { struct Config *config = malloc(sizeof(struct Config)); config->output = malloc(sizeof(struct ConfigOutput)); @@ -342,13 +355,15 @@ static struct Config *config_load_default(void) return config; } -static void config_printable_item_print_as_toml(struct PrintableItem *item) +static void +config_printable_item_print_as_toml(struct PrintableItem *item) { printf("[output.styles.%s]\n\n", item->name); cho_style_print_as_toml(item->style, item->name); } -void config_print_default(void) +void +config_print_default(void) { struct Config *config = config_load_default(); printf("[notes]\n\n"); @@ -371,7 +386,8 @@ void config_print_default(void) config_free(config); } -static bool config_load_font(struct Font *font, toml_table_t *table, const char *key_name) +static bool +config_load_font(struct Font *font, toml_table_t *table, const char *key_name) { enum FontFamily family; enum FontStyle style; @@ -422,7 +438,8 @@ static bool config_load_font(struct Font *font, toml_table_t *table, const char return true; } -static bool config_load_style(struct Style *style, toml_table_t *table, const char *key_name) +static bool +config_load_style(struct Style *style, toml_table_t *table, const char *key_name) { toml_value_t value; struct RGBColor *color; @@ -547,7 +564,8 @@ static bool config_load_style(struct Style *style, toml_table_t *table, const ch return true; } -static bool config_is_style(const char *str) +static bool +config_is_style(const char *str) { int i = 0; while (g_valid_styles[i] != NULL) { @@ -558,7 +576,8 @@ static bool config_is_style(const char *str) return false; } -struct Config *config_load(const char *filepath) +struct Config * +config_load(const char *filepath) { struct Config *config = config_load_default(); char *home = getenv("HOME"); @@ -692,7 +711,8 @@ struct Config *config_load(const char *filepath) return config; } -void config_free(struct Config *config) +void +config_free(struct Config *config) { int i; free(config->output->chorus->label); diff --git a/fontconfig.c b/fontconfig.c @@ -6,7 +6,8 @@ #include "fontconfig.h" #include "util.h" -static bool file_extension_is_ttc(const char *filepath) +static bool +file_extension_is_ttc(const char *filepath) { int mark = -1; int i = 0; @@ -21,7 +22,8 @@ static bool file_extension_is_ttc(const char *filepath) return false; } -char *fontconfig_fontpath_find(struct Font *font, enum FontType font_type) +char * +fontconfig_fontpath_find(struct Font *font, enum FontType font_type) { char *filepath = NULL; FcObjectSet *obj = FcObjectSetBuild(FC_FAMILY, FC_SLANT, FC_WEIGHT, FC_FONTFORMAT, FC_FONT_WRAPPER, FC_FILE, NULL); diff --git a/lorid.c b/lorid.c @@ -9,7 +9,8 @@ #include "out_pdf.h" #include "util.h" -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { static struct option long_options[] = { { "print-default-config", no_argument, 0, 'p' }, diff --git a/out_pdf.c b/out_pdf.c @@ -14,7 +14,8 @@ static char g_current_font_name[200]; static double g_current_font_size; static pdfio_obj_t *g_current_font_obj = NULL; -static pdfio_obj_t *out_pdf_fnt_obj_get_by_name(const char *name) +static pdfio_obj_t * +out_pdf_fnt_obj_get_by_name(const char *name) { int i = 0; while (g_fonts[i] != NULL) { @@ -25,7 +26,8 @@ static pdfio_obj_t *out_pdf_fnt_obj_get_by_name(const char *name) return NULL; } -static bool out_pdf_font_add_if_not_in(struct Font *font, struct Font ***array) +static bool +out_pdf_font_add_if_not_in(struct Font *font, struct Font ***array) { int a = 0; if (!*array) { @@ -51,7 +53,8 @@ static bool out_pdf_font_add_if_not_in(struct Font *font, struct Font ***array) } } -static void out_pdf_add_fonts(struct Font *font, struct Font ***fonts) +static void +out_pdf_add_fonts(struct Font *font, struct Font ***fonts) { bool added = false; char part[100]; @@ -95,7 +98,8 @@ static void out_pdf_add_fonts(struct Font *font, struct Font ***fonts) cho_font_free(new_font); } -static struct Font **out_pdf_font_get_all(struct ChoSong **songs, struct Config *config) +static struct Font ** +out_pdf_font_get_all(struct ChoSong **songs, struct Config *config) { struct Font **fonts = NULL; struct Font *font; @@ -148,7 +152,8 @@ static struct Font **out_pdf_font_get_all(struct ChoSong **songs, struct Config return fonts; } -static char *out_pdf_filename_generate_from_songs(struct ChoSong **songs) +static char * +out_pdf_filename_generate_from_songs(struct ChoSong **songs) { char *filename; char *normalized_title; @@ -171,7 +176,8 @@ static char *out_pdf_filename_generate_from_songs(struct ChoSong **songs) return strdup("collection-of-songs.pdf"); } -static char *out_pdf_filename_create(struct ChoSong **songs, const char *cho_filepath, const char *out) +static char * +out_pdf_filename_create(struct ChoSong **songs, const char *cho_filepath, const char *out) { char *pdf_filepath = NULL; char *pdf_filename; @@ -230,7 +236,8 @@ static char *out_pdf_filename_create(struct ChoSong **songs, const char *cho_fil } } -static struct Fnt *out_pdf_fnt_new(void) +static struct Fnt * +out_pdf_fnt_new(void) { struct Fnt *fnt = malloc(sizeof(struct Fnt)); fnt->name = NULL; @@ -238,7 +245,8 @@ static struct Fnt *out_pdf_fnt_new(void) return fnt; } -static char *out_pdf_fnt_name_create(struct Font *font) +static char * +out_pdf_fnt_name_create(struct Font *font) { char *name = str_normalize(font->name); const char *family = cho_font_family_to_config_string(font->family); @@ -281,13 +289,15 @@ static char *out_pdf_fnt_name_create(struct Font *font) return fnt_name; } -static void out_pdf_fnt_free(struct Fnt *fnt) +static void +out_pdf_fnt_free(struct Fnt *fnt) { free(fnt->name); free(fnt); } -static void out_pdf_fnts_free(struct Fnt **fnts) +static void +out_pdf_fnts_free(struct Fnt **fnts) { int i = 0; while (fnts[i] != NULL) { @@ -297,7 +307,8 @@ static void out_pdf_fnts_free(struct Fnt **fnts) free(fnts); } -static void out_pdf_fnt_add(struct Fnt *fnt, struct Fnt ***array) +static void +out_pdf_fnt_add(struct Fnt *fnt, struct Fnt ***array) { int a = 0; if (!*array) { @@ -313,7 +324,8 @@ static void out_pdf_fnt_add(struct Fnt *fnt, struct Fnt ***array) } } -static bool out_pdf_font_set(pdfio_stream_t *stream, struct Font *font) +static bool +out_pdf_font_set(pdfio_stream_t *stream, struct Font *font) { char *name = out_pdf_fnt_name_create(font); if (!strcmp(name, g_current_font_name) && font->size == g_current_font_size) { @@ -336,7 +348,8 @@ static bool out_pdf_font_set(pdfio_stream_t *stream, struct Font *font) return true; } -static double text_line_set_lineheight(struct TextLine *line, enum SongFragmentType ftype) +static double +text_line_set_lineheight(struct TextLine *line, enum SongFragmentType ftype) { double biggest_font_size = 0.0; int tli; @@ -355,7 +368,8 @@ static double text_line_set_lineheight(struct TextLine *line, enum SongFragmentT return line->height; } -static struct TextLine *text_line_create(const char *str, struct Style *style) +static struct TextLine * +text_line_create(const char *str, struct Style *style) { struct TextLine *line = malloc(sizeof(struct TextLine)); line->items = malloc(2 * sizeof(struct TextLineItem *)); @@ -369,7 +383,8 @@ static struct TextLine *text_line_create(const char *str, struct Style *style) return line; } -static double text_width(struct TextLineItem *item) +static double +text_width(struct TextLineItem *item) { char *name = out_pdf_fnt_name_create(item->style->font); pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name); @@ -381,7 +396,8 @@ static double text_width(struct TextLineItem *item) return pdfioContentTextMeasure(font_obj, item->text, item->style->font->size); } -static enum Bool text_fits(const char *str, struct Style *style) +static enum Bool +text_fits(const char *str, struct Style *style) { double width; char *name = out_pdf_fnt_name_create(style->font); @@ -398,7 +414,8 @@ static enum Bool text_fits(const char *str, struct Style *style) return B_TRUE; } -static int find_whitespace(const char *str, size_t start) +static int +find_whitespace(const char *str, size_t start) { int i; for (i = start; i>=0; i--) { @@ -409,7 +426,8 @@ static int find_whitespace(const char *str, size_t start) return -1; } -static char *text_find_fitting(const char *str, struct Style *style) +static char * +text_find_fitting(const char *str, struct Style *style) { size_t len = strlen(str); size_t start = len - 1; @@ -434,7 +452,8 @@ static char *text_find_fitting(const char *str, struct Style *style) return strdup((char *)&tmp); } -static struct TextLine **text_split_by_whitespace(const char *str, struct Style *style) +static struct TextLine ** +text_split_by_whitespace(const char *str, struct Style *style) { struct TextLine **lines = NULL; struct TextLine *line; @@ -478,7 +497,8 @@ static struct TextLine **text_split_by_whitespace(const char *str, struct Style return lines; } -static enum Bool text_line_fits(struct TextLine *line) +static enum Bool +text_line_fits(struct TextLine *line) { double width; int i = 0; @@ -499,7 +519,8 @@ static enum Bool text_line_fits(struct TextLine *line) return B_TRUE; } -static bool out_pdf_draw_line(pdfio_stream_t *stream, struct TextLineItem *item, double y, double width, enum LineLocation line_location) +static bool +out_pdf_draw_line(pdfio_stream_t *stream, struct TextLineItem *item, double y, double width, enum LineLocation line_location) { double red, green, blue; switch (line_location) { @@ -541,7 +562,8 @@ static bool out_pdf_draw_line(pdfio_stream_t *stream, struct TextLineItem *item, return true; } -static bool out_pdf_text_show(pdfio_stream_t *stream, struct TextLineItem *item, double y) +static bool +out_pdf_text_show(pdfio_stream_t *stream, struct TextLineItem *item, double y) { double red, green, blue, width; // TODO: Maybe store the width in TextLineItem @@ -616,7 +638,8 @@ static bool out_pdf_text_show(pdfio_stream_t *stream, struct TextLineItem *item, return true; } -static double line_width_until_chord(struct ChoLine *line, struct ChoLineItemAbove *text_above, struct SpaceNeeded *space) +static double +line_width_until_chord(struct ChoLine *line, struct ChoLineItemAbove *text_above, struct SpaceNeeded *space) { int i = -1; int ly = -1; @@ -663,7 +686,8 @@ static double line_width_until_chord(struct ChoLine *line, struct ChoLineItemAbo return width; } -static enum Bool out_pdf_text_above_is_enough_space(struct ChoLine *line, struct ChoLineItemAbove *prev_text_above, struct ChoLineItemAbove *text_above, struct SpaceNeeded *space) +static enum Bool +out_pdf_text_above_is_enough_space(struct ChoLine *line, struct ChoLineItemAbove *prev_text_above, struct ChoLineItemAbove *text_above, struct SpaceNeeded *space) { double prev_text_above_width; double cur = line_width_until_chord(line, text_above, NULL); @@ -703,7 +727,8 @@ static enum Bool out_pdf_text_above_is_enough_space(struct ChoLine *line, struct return B_TRUE; } -static struct SpaceNeeded *needs_space(struct SpaceNeeded **spaces, int ly, int i) +static struct SpaceNeeded * +needs_space(struct SpaceNeeded **spaces, int ly, int i) { int sn; for (sn = 0; spaces[sn]; sn++) { @@ -714,7 +739,8 @@ static struct SpaceNeeded *needs_space(struct SpaceNeeded **spaces, int ly, int return NULL; } -static struct Text **text_create(struct ChoSong **songs, struct Config *config) +static struct Text ** +text_create(struct ChoSong **songs, struct Config *config) { struct PrintableItem *printable_item; int so, se, li, ly, ch; @@ -1097,7 +1123,8 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) return text; } -static void text_free(struct Text **text) +static void +text_free(struct Text **text) { int t, tl, tli; for (t = 0; text[t]; t++) { @@ -1118,7 +1145,8 @@ static void text_free(struct Text **text) free(text); } -static pdfio_dict_t *annot_create(pdfio_file_t *pdf, const char *uri, pdfio_rect_t *rect) +static pdfio_dict_t * +annot_create(pdfio_file_t *pdf, const char *uri, pdfio_rect_t *rect) { pdfio_dict_t *annot = pdfioDictCreate(pdf); if (!pdfioDictSetName(annot, "Subtype", "Link")) { @@ -1145,7 +1173,8 @@ static pdfio_dict_t *annot_create(pdfio_file_t *pdf, const char *uri, pdfio_rect return annot; } -static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text **text) +static bool +annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text **text) { struct TextLineItem *item; pdfio_dict_t *annot; @@ -1204,7 +1233,8 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text return true; } -static bool out_pdf_set_title(pdfio_file_t *pdf, struct ChoSong **songs) +static bool +out_pdf_set_title(pdfio_file_t *pdf, struct ChoSong **songs) { // INFO: Set pdf title only if single song exist if (songs[0] && !songs[1]) { @@ -1219,7 +1249,8 @@ static bool out_pdf_set_title(pdfio_file_t *pdf, struct ChoSong **songs) return true; } -static pdfio_stream_t *out_pdf_page_create(pdfio_file_t *pdf, pdfio_array_t *annots, int page_no) +static pdfio_stream_t * +out_pdf_page_create(pdfio_file_t *pdf, pdfio_array_t *annots, int page_no) { pdfio_dict_t *page_dict; pdfio_array_t *page_annots; @@ -1254,7 +1285,8 @@ static pdfio_stream_t *out_pdf_page_create(pdfio_file_t *pdf, pdfio_array_t *ann return page_stream; } -char *out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, struct ChoSong **songs, struct Config *config) +char * +out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, struct ChoSong **songs, struct Config *config) { memset(&g_current_font_name, 0, sizeof(g_current_font_name)); char *pdf_filename = out_pdf_filename_create(songs, cho_filepath, output_folder_or_file); diff --git a/util.c b/util.c @@ -8,7 +8,8 @@ #include <errno.h> #include "util.h" -void util_log(enum LogLevel level, const char *msg, ...) +void +util_log(enum LogLevel level, const char *msg, ...) { #if COLOR == 1 const char *log_level = ""; @@ -53,7 +54,8 @@ void util_log(enum LogLevel level, const char *msg, ...) #endif } -bool str_starts_with(const char *str, const char *part) +bool +str_starts_with(const char *str, const char *part) { unsigned int i; size_t part_len = strlen(part); @@ -66,7 +68,8 @@ bool str_starts_with(const char *str, const char *part) return true; } -char *str_normalize(const char *str) +char * +str_normalize(const char *str) { char *normalized = NULL; int i = 0; @@ -91,7 +94,8 @@ char *str_normalize(const char *str) return normalized; } -char *str_trim(const char *str) +char * +str_trim(const char *str) { char *trimmed = NULL; int begin = 0; @@ -132,7 +136,8 @@ char *str_trim(const char *str) return trimmed; } -char *str_remove_leading_whitespace(const char *str) +char * +str_remove_leading_whitespace(const char *str) { int i = 0; while (str[i] == ' ' || str[i] == '\t') { @@ -141,7 +146,8 @@ char *str_remove_leading_whitespace(const char *str) return strdup(&str[i]); } -short str_parse_as_percent(const char *str) +short +str_parse_as_percent(const char *str) { if (strlen(str) > 4) { return -1; @@ -161,7 +167,8 @@ short str_parse_as_percent(const char *str) return (short)l; } -enum FileType file_type(const char *path) +enum FileType +file_type(const char *path) { struct stat s; if (stat(path, &s) != 0) { @@ -176,7 +183,8 @@ enum FileType file_type(const char *path) return F_OTHER; } -char *file_extension_replace_or_add(const char *old, const char *extension) +char * +file_extension_replace_or_add(const char *old, const char *extension) { size_t extension_len = strlen(extension); char *new = NULL; @@ -219,7 +227,8 @@ char *file_extension_replace_or_add(const char *old, const char *extension) return new; } -char *filepath_add_ending_slash_if_missing(const char *path) +char * +filepath_add_ending_slash_if_missing(const char *path) { size_t len = strlen(path); if (path[len-1] == '/') { @@ -233,7 +242,8 @@ char *filepath_add_ending_slash_if_missing(const char *path) } } -char *filepath_basename(const char *path) +char * +filepath_basename(const char *path) { int begin = 0; int i; @@ -245,7 +255,8 @@ char *filepath_basename(const char *path) return strdup(&path[begin]); } -char *filepath_dirname(const char *path) +char * +filepath_dirname(const char *path) { char *dirname; int end = 0;