Add missing libraries to examples' Makefiles
[dockapps.git] / libdockapp / src / dautil.c
blobbbaf8651c4857cf6c0643944adc9f3bb3e17fab4
1 /*
2 * Copyright (c) 1999-2005 Alfredo K. Kojima, Alban G. Hertroys
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 deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * 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 or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #include <string.h>
25 #include "daargs.h"
26 #include "dautil.h"
28 extern struct DAContext *_daContext;
31 * Function prototypes
33 void _message(const char *label, const char *fmt, va_list args);
37 * Exported functions.
39 void
40 DASetExpectedVersion(unsigned long expectedVersion)
42 DAExpectedVersion = expectedVersion;
44 if (expectedVersion > DA_VERSION)
45 DAWarning("Version of libdockapp (%u) is older than "
46 "version expected (%u)",
47 DA_VERSION,
48 DAExpectedVersion);
52 Display *
53 DAGetDisplay(char *d, ...)
55 /* Be backward compatible */
56 if (DAExpectedVersion < 20030126) {
57 va_list ap;
58 int argc;
59 char **argv;
61 va_start(ap, d);
62 argc = va_arg(ap, int);
63 argv = va_arg(ap, char **);
64 va_end(ap);
66 DAOpenDisplay(d, argc, argv);
68 DAWarning("Expected version of libdockapp is not set.");
69 DAWarning("Obsolete call to DAGetDisplay().");
71 return NULL;
74 return DADisplay;
78 void
79 DASetDisplay(Display *display)
81 DADisplay = display;
85 Window
86 DAGetWindow(void)
88 return DAWindow;
92 void
93 DASetWindow(Window window)
95 DAWindow = window;
99 Window
100 DAGetLeader(void)
102 return DALeader;
106 void
107 DASetLeader(Window leader)
109 DALeader = leader;
113 Window
114 DAGetIconWindow(void)
116 return DAIcon;
120 void
121 DASetIconWindow(Window icon_win)
123 DAIcon = icon_win;
128 DAGetDepth(void)
130 return DADepth;
134 void
135 DASetDepth(int depth)
137 DADepth = depth;
141 Visual *
142 DAGetVisual(void)
144 return DAVisual;
148 void
149 DASetVisual(Visual *visual)
151 DAVisual = visual;
154 void
155 DAWarning(const char *fmt, ...)
157 va_list args;
159 va_start(args, fmt);
160 _message("Warning", fmt, args);
161 va_end(args);
164 void
165 DAError(const char *fmt, ...)
167 va_list args;
169 va_start(args, fmt);
170 _message("Error", fmt, args);
171 exit(1);
172 va_end(args);
177 * Local functions
180 void
181 _message(const char *label, const char *fmt, va_list args)
183 char *w_fmt;
185 if (_daContext->programName != NULL) {
186 /* put default string in front of message, add newline */
187 w_fmt = malloc((strlen(_daContext->programName) + strlen(fmt) + 13) * sizeof(char));
188 sprintf(w_fmt, "%s: %s: %s\n", _daContext->programName, label, fmt);
189 } else {
190 w_fmt = malloc((strlen(fmt) + 1) * sizeof(char));
191 sprintf(w_fmt, "%s\n", fmt);
194 /* print the message */
195 vfprintf(stderr, w_fmt, args);
196 free(w_fmt);
200 void
201 debug(const char *fmt, ...)
203 #ifdef DEBUG
204 va_list args;
206 va_start(args, fmt);
207 _message("debug", fmt, args);
208 va_end(args);
209 #endif