Supplementary message concering lack of source in packaged doc/ and the GPL
[adesklets.git] / src / main.c
blob5818b37364676241cfe07f6fe4ebd7c0043c64cb
1 /*--- main.c -------------------------------------------------------------------
2 Copyright (C) 2004, 2005 Sylvain Fourmanoit <syfou@users.sourceforge.net>
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to
6 deal in the Software without restriction, including without limitation the
7 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 sell copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies of the Software and its documentation and acknowledgment shall be
13 given in the documentation and software packages that this Software was
14 used.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ------------------------------------------------------------------------------*/
23 #include "adesklets.h" /* Main application header */
25 /*----------------------------------------------------------------------------*/
26 /* Main routine
27 There are only two ways to invoke adesklets:
29 - Without arguments: adesklets is used as a simple
30 program launcher: all desklets
31 in ~/.adesklets are run in forked
32 process, and adesklets finally exits.
33 All adesklets instances for current user
34 that were already running are all killed
35 before the launch.
36 Environment variable ADESKLETS_ID
37 is also set according to config_file
38 in all children.
39 - With arguments: adesklets is used as an interpreter,
40 either interactive of not.
42 If adesklets is used non-iteractively:
44 - If its first free-form argument is an absolute
45 file name to something the current user
46 can execute, the windows property
47 will be remembered and updated in
48 ~/.adesklets and:
49 * If ADESKLETS_ID do not exists
50 in the environment, it will be set
51 to next available unsigned integer
52 * If it exists, it will kept and
53 used to chose configuration bethween
54 different instances of the script.
56 - If its first free-form argument is a file name
57 to something the current user can execute,
58 either absolute or not, restarting the desklet
59 will be possible.
61 - If its first free-form argument is something
62 else, it will simply be discarded.
64 If adesklets is used interactively:
66 - the first free-form argument is always discarded,
67 an a prompt is given.
69 To complicate things a little further, there is also a customization,
70 scriptable shell-based layer on top on this: adesklets_frontend.sh,
71 installed by default inside the $pqgdata_dir directory (yet, the binary
72 interpreter is fully standalone, and will work without its intervention).
73 Basically, this adesklets_frontend.sh script, when detected, is
74 automatically executed before all regular call to the binary. Go read it,
75 from ../utils/adesklets_frontend.sh, for details.
77 int
78 main(int argc, char ** argv)
80 #ifdef DEBUG
81 /* First of all, initialize debug output if applicable */
82 debug_init();
83 #endif
85 #ifdef FRONTEND_SHELL_DRIVER
86 /* Go through the frontend, as needed */
87 if (!getenv("ADESKLETS_FRONTEND")) {
88 debug("Frontend signature not detected: try to execve it.\n");
89 #ifndef DEBUG
90 /* Make it possible to run the frontend in-place in case of
91 debugging compilation or help2man extraction */
92 if (getenv("ADESKLETS_HELP2MAN"))
93 #endif
94 execv("../utils/adesklets_frontend.sh", argv);
95 execv(PKGDATADIR "/adesklets_frontend.sh", argv);
96 debug("Could not execute the frontend.\n");
98 #endif
100 /* Now, perform the core execution */
101 if(argc>1) {
102 /* adesklets used as an interpreter */
103 if (adesklets_init(argc,argv)) {
104 adesklets_events_loop();
105 adesklets_free();
107 } else {
108 /* adesklets used as a desklets launcher */
109 #ifdef FRONTEND_SHELL_DRIVER
110 unsetenv("ADESKLETS_FRONTEND");
111 #endif
112 cfgfile_loadall();