Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / src / read-desktop.h
1 /* Reading Desktop Entry files.
2    Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2014-2015
3    Free Software Foundation, Inc.
4    This file was written by Daiki Ueno <ueno@gnu.org>.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _READ_DESKTOP_H
20 #define _READ_DESKTOP_H
21
22 #include <sys/types.h>
23 #include <stdio.h>
24 #include "hash.h"
25 #include "po-lex.h"
26 #include "str-list.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* Forward declaration.  */
33 struct desktop_reader_ty;
34
35
36 /* This first structure, playing the role of the "Class" in OO sense,
37    contains pointers to functions.  Each function is a method for the
38    class (base or derived).  Use a NULL pointer where no action is
39    required.  */
40
41 typedef struct desktop_reader_class_ty desktop_reader_class_ty;
42 struct desktop_reader_class_ty
43 {
44   /* how many bytes to malloc for an instance of this class */
45   size_t size;
46
47   /* what to do immediately after the instance is malloc()ed */
48   void (*constructor) (struct desktop_reader_ty *pop);
49
50   /* what to do immediately before the instance is free()ed */
51   void (*destructor) (struct desktop_reader_ty *pop);
52
53   /* what to do with a group header */
54   void (*handle_group) (struct desktop_reader_ty *pop,
55                         const char *group);
56
57   /* what to do with a key/value pair */
58   void (*handle_pair) (struct desktop_reader_ty *pop,
59                        lex_pos_ty *key_pos,
60                        const char *key,
61                        const char *locale,
62                        const char *value);
63
64   /* what to do with a comment */
65   void (*handle_comment) (struct desktop_reader_ty *pop, const char *s);
66
67   /* what to do with a blank line */
68   void (*handle_blank) (struct desktop_reader_ty *pop, const char *s);
69 };
70
71 /* This next structure defines the base class passed to the methods.
72    Derived methods will often need to cast their first argument before
73    using it (this corresponds to the implicit 'this' argument in C++).
74
75    When declaring derived classes, use the DESKTOP_READER_TY define
76    at the start of the structure, to declare inherited instance variables,
77    etc.  */
78
79 #define DESKTOP_READER_TY              \
80   desktop_reader_class_ty *methods;
81
82 typedef struct desktop_reader_ty desktop_reader_ty;
83 struct desktop_reader_ty
84 {
85   DESKTOP_READER_TY
86 };
87
88 desktop_reader_ty *desktop_reader_alloc (desktop_reader_class_ty *methods);
89 void desktop_reader_free (desktop_reader_ty *reader);
90
91 void desktop_reader_handle_group (desktop_reader_ty *reader,
92                                   const char *group);
93
94 void desktop_reader_handle_pair (desktop_reader_ty *reader,
95                                  lex_pos_ty *key_pos,
96                                  const char *key,
97                                  const char *locale,
98                                  const char *value);
99
100 void desktop_reader_handle_comment (desktop_reader_ty *reader,
101                                     const char *s);
102
103 void desktop_reader_handle_blank (desktop_reader_ty *reader,
104                                   const char *s);
105
106
107 void desktop_parse (desktop_reader_ty *reader, FILE *file,
108                     const char *real_filename, const char *logical_filename);
109
110
111 char *desktop_escape_string (const char *s, bool is_list);
112 char *desktop_unescape_string (const char *s, bool is_list);
113
114 void desktop_add_keyword (hash_table *keywords, const char *name, bool is_list);
115 void desktop_add_default_keywords (hash_table *keywords);
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121
122 #endif /* _READ_DESKTOP_H */