aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/eina/eina_vpath.h
blob: 77c1e35afed2f4c7652347aad59b1550aa2ce461 (plain) (blame)
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
#ifndef EINA_VPATH_H
#define EINA_VPATH_H

#include "eina_prefix.h"

#ifdef EFL_BETA_API_SUPPORT

/**
 * Eina vpath is a path that can be prefixed with a virtual path.
 *
 * A virtual path can either start with (:XXXXXXXX:) that indicates a virtual
 * path with XXXXXXXX as the location, OR a normal path with / or a relative
 * path like ./ or ../ or even shell common locators like ~/ or ~username/
 *
 * The string between (: and :) is used as key to lookup the real value.
 * The key has to be set by an interface before, otherwise you will get an
 * error.
 *
 * Sample paths:
 *
 *   ~/myfiles/file.png
 *   ~bob/dir/file.txt
 *   /path/to/file.cfg
 *   ./file/relative/path.txt
 *   file/relative/path.txt
 *   (:tmp:)/some-temp-file/file.txt
 *   (:home:)/myfiles/file.png
 *
 *   (:app.dir:)/bin/app-executable
 *   (:app.bin:)/app-executable-file
 *   (:app.lib:)/app-library.so
 *   (:app.data:)/application/datafile.png
 *   (:app.locale:)/en_US/LC_MESSAGES/app.mo
 *   (:app.config:)/application-config.xml
 *   (:app.local:)/application-data-file.jpg
 *   (:app.tmp:)/some-temp-file/path/file.txt
 *
 *   (:usr.desktop:)/file-in-users-desktop-directory.txt
 *   (:usr.documents:)/letter-to-grandma.doc
 *   (:usr.downloads:)/file-downloaded-here.zip
 *   (:usr.music:)/fave-song.mp3
 *   (:usr.pictures:)/a-photo.,jpg
 *   (:usr.public:)/some-publicly-shared-file
 *   (:usr.templates:)/some-template-document.txt
 *   (:usr.videos:)/some-video-file.mp4
 *   (:usr.data:)/file-in-user-data-dir
 *   (:usr.config:)/file-in-user-config-dir
 *   (:usr.cache:)/file-in-user-cache-dir
 *   (:usr.run:)/file-in-xdg-runtime-dir
 *   (:usr.tmp:)/some-temp-file/path/file.txt
 *
 * Commonly mapped to real path (but may vary):
 *
 *   (:tmp:) - /tmp
 *   (:home:) - ~/
 *
 *   (:app.dir:) - /usr - (assuming app install PREFIX of /usr. may be /usr/local or others too)
 *   (:app.bin:) - /usr/bin - (almost always PREFIX/bin)
 *   (:app.lib:) - /usr/lib - (almost always PREFIX/lib)
 *   (:app.data:) - /usr/share/appname - (almost always PREFIX/share/appname)
 *   (:app.locale:) - /usr/share/locale - (almost always PREFIX/locale)
 *   (:app.config:) - ~/.config/appname
 *   (:app.local:) - ~/.local/share/appname
 *   (:app.tmp:) - ~/.local/tmp/appname
 *
 *   (:usr.desktop:) - ~/Desktop
 *   (:usr.documents:) - ~/Documents
 *   (:usr.downloads:) - ~/Downloads
 *   (:usr.music:) - ~/Music
 *   (:usr.pictures:) - ~/Pictures
 *   (:usr.public:) - ~/Public
 *   (:usr.templates:) - ~/Templates
 *   (:usr.videos:) - ~/Videos
 *   (:usr.data:) - ~/.local/share
 *   (:usr.config:) - ~/.config
 *   (:usr.cache:) - ~/.cache
 *   (:usr.run:) - /var/run/user/1000
 *   (:usr.tmp:) - ~/.local/tmp
 *
 * Additional info: https://phab.enlightenment.org/w/eina_vpath/
 *
 * @since 1.21
 *
 */
typedef const char * Eina_Vpath;

/**
 * Translate a virtual path into a normal path.
 * 
 * The return string is a string allocated by malloc and should be freed with
 * free() when no longer needed.
 *
 * @param[in] path The path.
 * @return NULL if failed, or a full normal string file path that is resolved
 *
 * @since 1.21
 *
 */
EAPI char *eina_vpath_resolve(Eina_Vpath path);

/**
 * Translate a virtual path into a normal path, and print it into str.
 *
 * @param[out] str the buffer to stuff the characters into
 * @param[in] size the size of the buffer
 * @param[in] format A snprintf style format string, which will get evaluated after the vpath strings are getting replaced
 * @param[in] ... The arguments for the format string
 *
 * @return the number of characters that are written into str, on a error a value < 0 is returned.
 *
 * @since 1.21
 *
 */
EAPI int eina_vpath_resolve_snprintf(char *str, size_t size, const char *format, ...);
#endif
#endif