poe

Уређивач .po фајлова
git clone https://git.sr.ht/~strahinja/poe
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

po.h (4520B)


      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 } ParseState;
     26 
     27 #define PS_COMMENT                                            \
     28 	((PS_COMMENT_TRAN | PS_COMMENT_EXTR | PS_COMMENT_FLAG \
     29 		| PS_COMMENT_REFN | PS_COMMENT_OBSO))
     30 /* Complete list at:
     31  *
     32  * https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
     33  *
     34  * - JS, awk and sh using gettext, seriously?
     35  *   "Let's just shove every programming and scripting language there is into
     36  *   flags!" /s
     37  *   Where are the flags for Pascal and Ada, by the way, hmm? [SR]
     38  *
     39  * - Including just the sane values, will strip the rest. */
     40 typedef enum {
     41 	FL_NONE	       = 0,
     42 	FL_FUZZY       = 1,
     43 	FL_C_FORMAT    = 1 << 1,
     44 	FL_NO_C_FORMAT = 1 << 2
     45 } Flags;
     46 
     47 struct PoEntry {
     48 	Flags flags;
     49 	int obsolete;
     50 	int warning;
     51 	uint32_t* msgid;
     52 	ssize_t msgid_size;
     53 	ssize_t msgid_len;
     54 	uint32_t* msgid_plural;
     55 	size_t msgid_plural_size;
     56 	size_t msgid_plural_len;
     57 	uint32_t* plural_forms;
     58 	ssize_t plural_forms_size;
     59 	ssize_t plural_forms_len;
     60 	uint32_t** msgstr;
     61 	int msgstr_count;
     62 	ssize_t* msgstr_size;
     63 	ssize_t* msgstr_len;
     64 	uint32_t** comments;
     65 	ssize_t comment_lines;
     66 	uint32_t** extr_comments;
     67 	ssize_t extr_comment_lines;
     68 	char** ref_comments;
     69 	ssize_t ref_comment_lines;
     70 };
     71 
     72 int add_ref_comment(struct PoEntry* entry, const char* comment);
     73 char* format_flags(char* buffer, const size_t max, const struct PoEntry* entry,
     74 	const int draw_box);
     75 void free_po_entry(struct PoEntry* entry);
     76 void init_po_entry(struct PoEntry* entry);
     77 int load_file(struct DrawState* state, long* lineno, long* col);
     78 int parse_po_line(const char* line, struct DrawState* dstate,
     79 	struct PoEntry** current_entry, ParseState* pstate, long* col,
     80 	int* msgstr_index);
     81 int save_comment(FILE* output, struct DrawState* state,
     82 	const struct PoEntry* current);
     83 int save_extr_comment(FILE* output, struct DrawState* state,
     84 	const struct PoEntry* current);
     85 int save_file(struct DrawState* state);
     86 int save_flags(FILE* output, const struct PoEntry* current);
     87 int save_msgid(FILE* output, struct DrawState* state,
     88 	const struct PoEntry* current);
     89 int save_msgid_plural(FILE* output, struct DrawState* state,
     90 	const struct PoEntry* current);
     91 int save_msgstrs(FILE* output, struct DrawState* state,
     92 	const struct PoEntry* current);
     93 int save_ref_comment(FILE* output, const struct PoEntry* current);
     94 int set_flags(struct PoEntry* entry, const Flags flags);
     95 int set_msgid(struct DrawState* state, struct PoEntry* entry, const char* msgid,
     96 	int append);
     97 int set_msgid_plural(struct DrawState* state, struct PoEntry* entry,
     98 	const char* msgid_plural, int append);
     99 int set_msgstr(struct DrawState* state, struct PoEntry* entry,
    100 	const char* msgstr, int msgstr_index, int append);
    101 int set_nplurals(struct DrawState* state, struct PoEntry* entry);
    102 int set_plural_forms(struct DrawState* state, struct PoEntry* entry,
    103 	const char* plural_forms, int append);
    104 int u32_add_comment(struct PoEntry* entry, const uint32_t* comment);
    105 int u32_add_extr_comment(struct PoEntry* entry, const uint32_t* extr_comment);
    106 int u32_set_msgid(struct DrawState* state, struct PoEntry* entry,
    107 	const uint32_t* msgid, ssize_t msgid_size, int append);
    108 int u32_set_msgid_plural(struct DrawState* state, struct PoEntry* entry,
    109 	const uint32_t* msgid_plural, ssize_t msgid_plural_size, int append);
    110 int u32_set_msgstr(struct DrawState* state, struct PoEntry* entry,
    111 	const uint32_t* msgstr, int msgstr_index, int append);
    112 int u32_set_plural_forms(struct DrawState* state, struct PoEntry* entry,
    113 	const uint32_t* plural_forms, const ssize_t plural_forms_len,
    114 	int append);
    115 void update_statistics(const struct PoEntry* entries, struct DrawState* state,
    116 	struct PoEntry* entry);
    117 void update_warning(const uint32_t* msgid, const uint32_t* msgstr, int* warning);