po.h (4568B)
1 /* This program is licensed under the terms of GNU GPL v3 or (at your option) 2 * any later version. Copyright (C) 2021-2026 Страхиња Радић. 3 * See the file LICENSE for exact copyright and license details. */ 4 5 #include <stdint.h> 6 #include <stdlib.h> 7 8 /* lines to tolerate the lack of msgid */ 9 #define PO_DETECTION_LINES 24 10 11 struct DrawState; 12 13 typedef enum { 14 PS_NONE = 0, 15 PS_COMMENT_TRAN = 1, /* "translator-comments" : # */ 16 PS_COMMENT_EXTR = 1 << 1, /* "extracted-comments" : #. */ 17 PS_COMMENT_REFN = 1 << 2, /* "reference" : #: */ 18 PS_COMMENT_FLAG = 1 << 3, /* "flag" : #, */ 19 PS_COMMENT_OBSO = 1 << 4, /* obsolete (undocumented) : #~ */ 20 PS_MSGID = 1 << 5, 21 PS_MSGID_PLURAL = 1 << 6, 22 PS_MSGSTR = 1 << 7, 23 PS_MSGSTR_ARRAY = 1 << 8, 24 PS_STRING = 1 << 9, /* string literal */ 25 PS_PLURAL_FORMS = 1 << 10 /* Plural-Forms: */ 26 } ParseState; 27 28 #define PS_COMMENT \ 29 ((PS_COMMENT_TRAN | PS_COMMENT_EXTR | PS_COMMENT_FLAG \ 30 | PS_COMMENT_REFN | PS_COMMENT_OBSO)) 31 /* Complete list at: 32 * 33 * https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html 34 * 35 * - JS, awk and sh using gettext, seriously? 36 * "Let's just shove every programming and scripting language there is into 37 * flags!" /s 38 * Where are the flags for Pascal and Ada, by the way, hmm? [SR] 39 * 40 * - Including just the sane values, will strip the rest. */ 41 typedef enum { 42 FL_NONE = 0, 43 FL_FUZZY = 1, 44 FL_C_FORMAT = 1 << 1, 45 FL_NO_C_FORMAT = 1 << 2 46 } Flags; 47 48 struct PoEntry { 49 Flags flags; 50 int obsolete; 51 int warning; 52 uint32_t* msgid; 53 ssize_t msgid_size; 54 ssize_t msgid_len; 55 uint32_t* msgid_plural; 56 size_t msgid_plural_size; 57 size_t msgid_plural_len; 58 uint32_t* plural_forms; 59 ssize_t plural_forms_size; 60 ssize_t plural_forms_len; 61 uint32_t** msgstr; 62 int msgstr_count; 63 ssize_t* msgstr_size; 64 ssize_t* msgstr_len; 65 uint32_t** comments; 66 ssize_t comment_lines; 67 uint32_t** extr_comments; 68 ssize_t extr_comment_lines; 69 char** ref_comments; 70 ssize_t ref_comment_lines; 71 }; 72 73 int add_ref_comment(struct PoEntry* entry, const char* comment); 74 char* format_flags(char* buffer, const size_t max, const struct PoEntry* entry, 75 const int draw_box); 76 void free_po_entry(struct PoEntry* entry); 77 void init_po_entry(struct PoEntry* entry); 78 int load_file(struct DrawState* state, long* lineno, long* col); 79 int parse_po_line(const char* line, struct DrawState* dstate, 80 struct PoEntry** current_entry, ParseState* pstate, long* col, 81 int* msgstr_index); 82 int save_comment(FILE* output, struct DrawState* state, 83 const struct PoEntry* current); 84 int save_extr_comment(FILE* output, struct DrawState* state, 85 const struct PoEntry* current); 86 int save_file(struct DrawState* state); 87 int save_flags(FILE* output, const struct PoEntry* current); 88 int save_msgid(FILE* output, struct DrawState* state, 89 const struct PoEntry* current); 90 int save_msgid_plural(FILE* output, struct DrawState* state, 91 const struct PoEntry* current); 92 int save_msgstrs(FILE* output, struct DrawState* state, 93 const struct PoEntry* current); 94 int save_ref_comment(FILE* output, const struct PoEntry* current); 95 int set_flags(struct PoEntry* entry, const Flags flags); 96 int set_msgid(struct DrawState* state, struct PoEntry* entry, const char* msgid, 97 int append); 98 int set_msgid_plural(struct DrawState* state, struct PoEntry* entry, 99 const char* msgid_plural, int append); 100 int set_msgstr(struct DrawState* state, struct PoEntry* entry, 101 const char* msgstr, int msgstr_index, int append); 102 int set_nplurals(struct DrawState* state, struct PoEntry* entry); 103 int set_plural_forms(struct DrawState* state, struct PoEntry* entry, 104 const char* plural_forms, int append); 105 int u32_add_comment(struct PoEntry* entry, const uint32_t* comment); 106 int u32_add_extr_comment(struct PoEntry* entry, const uint32_t* extr_comment); 107 int u32_set_msgid(struct DrawState* state, struct PoEntry* entry, 108 const uint32_t* msgid, ssize_t msgid_size, int append); 109 int u32_set_msgid_plural(struct DrawState* state, struct PoEntry* entry, 110 const uint32_t* msgid_plural, ssize_t msgid_plural_size, int append); 111 int u32_set_msgstr(struct DrawState* state, struct PoEntry* entry, 112 const uint32_t* msgstr, int msgstr_index, int append); 113 int u32_set_plural_forms(struct DrawState* state, struct PoEntry* entry, 114 const uint32_t* plural_forms, const ssize_t plural_forms_len, 115 int append); 116 void update_statistics(const struct PoEntry* entries, struct DrawState* state, 117 struct PoEntry* entry); 118 void update_warning(const uint32_t* msgid, const uint32_t* msgstr, int* warning);