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>.
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.
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.
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/>. */
19 #ifndef _READ_DESKTOP_H
20 #define _READ_DESKTOP_H
22 #include <sys/types.h>
32 /* Forward declaration. */
33 struct desktop_reader_ty;
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
41 typedef struct desktop_reader_class_ty desktop_reader_class_ty;
42 struct desktop_reader_class_ty
44 /* how many bytes to malloc for an instance of this class */
47 /* what to do immediately after the instance is malloc()ed */
48 void (*constructor) (struct desktop_reader_ty *pop);
50 /* what to do immediately before the instance is free()ed */
51 void (*destructor) (struct desktop_reader_ty *pop);
53 /* what to do with a group header */
54 void (*handle_group) (struct desktop_reader_ty *pop,
57 /* what to do with a key/value pair */
58 void (*handle_pair) (struct desktop_reader_ty *pop,
64 /* what to do with a comment */
65 void (*handle_comment) (struct desktop_reader_ty *pop, const char *s);
67 /* what to do with a blank line */
68 void (*handle_blank) (struct desktop_reader_ty *pop, const char *s);
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++).
75 When declaring derived classes, use the DESKTOP_READER_TY define
76 at the start of the structure, to declare inherited instance variables,
79 #define DESKTOP_READER_TY \
80 desktop_reader_class_ty *methods;
82 typedef struct desktop_reader_ty desktop_reader_ty;
83 struct desktop_reader_ty
88 desktop_reader_ty *desktop_reader_alloc (desktop_reader_class_ty *methods);
89 void desktop_reader_free (desktop_reader_ty *reader);
91 void desktop_reader_handle_group (desktop_reader_ty *reader,
94 void desktop_reader_handle_pair (desktop_reader_ty *reader,
100 void desktop_reader_handle_comment (desktop_reader_ty *reader,
103 void desktop_reader_handle_blank (desktop_reader_ty *reader,
107 void desktop_parse (desktop_reader_ty *reader, FILE *file,
108 const char *real_filename, const char *logical_filename);
111 char *desktop_escape_string (const char *s, bool is_list);
112 char *desktop_unescape_string (const char *s, bool is_list);
114 void desktop_add_keyword (hash_table *keywords, const char *name, bool is_list);
115 void desktop_add_default_keywords (hash_table *keywords);
122 #endif /* _READ_DESKTOP_H */