summaryrefslogtreecommitdiff
path: root/gettext-tools/src/read-desktop.h
blob: eebd681f80b95d87c6e9996091a2df6923f79e08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* Reading Desktop Entry files.
   Copyright (C) 1995-1998, 2000-2003, 2005-2006, 2008-2009, 2014-2015
   Free Software Foundation, Inc.
   This file was written by Daiki Ueno <ueno@gnu.org>.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef _READ_DESKTOP_H
#define _READ_DESKTOP_H

#include <sys/types.h>
#include <stdio.h>
#include "hash.h"
#include "po-lex.h"
#include "str-list.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Forward declaration.  */
struct desktop_reader_ty;


/* This first structure, playing the role of the "Class" in OO sense,
   contains pointers to functions.  Each function is a method for the
   class (base or derived).  Use a NULL pointer where no action is
   required.  */

typedef struct desktop_reader_class_ty desktop_reader_class_ty;
struct desktop_reader_class_ty
{
  /* how many bytes to malloc for an instance of this class */
  size_t size;

  /* what to do immediately after the instance is malloc()ed */
  void (*constructor) (struct desktop_reader_ty *pop);

  /* what to do immediately before the instance is free()ed */
  void (*destructor) (struct desktop_reader_ty *pop);

  /* what to do with a group header */
  void (*handle_group) (struct desktop_reader_ty *pop,
                        const char *group);

  /* what to do with a key/value pair */
  void (*handle_pair) (struct desktop_reader_ty *pop,
                       lex_pos_ty *key_pos,
                       const char *key,
                       const char *locale,
                       const char *value);

  /* what to do with a comment */
  void (*handle_comment) (struct desktop_reader_ty *pop, const char *s);

  /* what to do with a blank line */
  void (*handle_blank) (struct desktop_reader_ty *pop, const char *s);
};

/* This next structure defines the base class passed to the methods.
   Derived methods will often need to cast their first argument before
   using it (this corresponds to the implicit 'this' argument in C++).

   When declaring derived classes, use the DESKTOP_READER_TY define
   at the start of the structure, to declare inherited instance variables,
   etc.  */

#define DESKTOP_READER_TY              \
  desktop_reader_class_ty *methods;

typedef struct desktop_reader_ty desktop_reader_ty;
struct desktop_reader_ty
{
  DESKTOP_READER_TY
};

desktop_reader_ty *desktop_reader_alloc (desktop_reader_class_ty *methods);
void desktop_reader_free (desktop_reader_ty *reader);

void desktop_reader_handle_group (desktop_reader_ty *reader,
                                  const char *group);

void desktop_reader_handle_pair (desktop_reader_ty *reader,
                                 lex_pos_ty *key_pos,
                                 const char *key,
                                 const char *locale,
                                 const char *value);

void desktop_reader_handle_comment (desktop_reader_ty *reader,
                                    const char *s);

void desktop_reader_handle_blank (desktop_reader_ty *reader,
                                  const char *s);


void desktop_parse (desktop_reader_ty *reader, FILE *file,
                    const char *real_filename, const char *logical_filename);


char *desktop_escape_string (const char *s, bool is_list);
char *desktop_unescape_string (const char *s, bool is_list);

void desktop_add_keyword (hash_table *keywords, const char *name, bool is_list);
void desktop_add_default_keywords (hash_table *keywords);

#ifdef __cplusplus
}
#endif


#endif /* _READ_DESKTOP_H */