| 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 | #include <stdio.h> |
| 54 | #include <errno(*__errno_location ()).h> |
| 55 | #include <X11/Xos.h> |
| 56 | #include <X11/Xlib.h> |
| 57 | #include <X11/Xutil.h> |
| 58 | #include <ctype.h> |
| 59 | #include <stdlib.h> |
| 60 | |
| 61 | static Window win; |
| 62 | |
| 63 | static char *ProgramName; |
| 64 | |
| 65 | static void _X_NORETURN__attribute((noreturn)) |
| 66 | Syntax(void) |
| 67 | { |
| 68 | fprintf (stderrstderr, "usage: %s [-options] [geometry] [display]\n\n%s", |
| 69 | ProgramName, |
| 70 | "where the available options are:\n" |
| 71 | " -display host:dpy or -d\n" |
| 72 | " -geometry WxH+X+Y or -g spec\n" |
| 73 | " -black use BlackPixel\n" |
| 74 | " -white use WhitePixel\n" |
| 75 | " -solid colorname use the color indicated\n" |
| 76 | " -root use the root background\n" |
| 77 | " -none no background in window\n"); |
| 78 | fprintf (stderrstderr, "\nThe default is: %s -none\n\n", ProgramName); |
| 79 | exit (1); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | static int |
| 88 | parse_boolean_option(char *option) |
| 89 | { |
| 90 | static const struct _booltable { |
| 91 | const char *name; |
| 92 | int value; |
| 93 | } booltable[] = { |
| 94 | { "off", 0 }, { "n", 0 }, { "no", 0 }, { "false", 0 }, |
| 95 | { "on", 1 }, { "y", 1 }, { "yes", 1 }, { "true", 1 }, |
| 96 | { NULL((void*)0), -1 }}; |
| 97 | register const struct _booltable *t; |
| 98 | register char *cp; |
| 99 | |
| 100 | for (cp = option; *cp; cp++) { |
| 101 | if (isascii (*cp)(((*cp) & ~0x7f) == 0) && isupper (*cp)((*__ctype_b_loc ())[(int) ((*cp))] & (unsigned short int ) _ISupper)) *cp = tolower (*cp); |
| 102 | } |
| 103 | |
| 104 | for (t = booltable; t->name; t++) { |
| 105 | if (strcmp (option, t->name) == 0) return (t->value); |
| 106 | } |
| 107 | return (-1); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | static Boolint |
| 117 | isabbreviation(const char *arg, char *s, int minslen) |
| 118 | { |
| 119 | int arglen; |
| 120 | int slen; |
| 121 | |
| 122 | |
| 123 | if (strcmp (arg, s) == 0) return (True1); |
| 124 | |
| 125 | arglen = strlen (arg); |
| 126 | slen = strlen (s); |
| 127 | |
| 128 | |
| 129 | if (slen >= arglen || slen < minslen) return (False0); |
| 130 | |
| 131 | |
| 132 | if (strncmp (arg, s, slen) == 0) return (True1); |
| 133 | |
| 134 | |
| 135 | return (False0); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | enum e_action {doDefault, doBlack, doWhite, doSolid, doNone, doRoot}; |
| 140 | |
| 141 | static const struct s_pair { |
| 142 | const char *resource_name; |
| 143 | enum e_action action; |
| 144 | } pair_table[] = { |
| 145 | { "Black", doBlack }, |
| 146 | { "White", doWhite }, |
| 147 | { "None", doNone }, |
| 148 | { "Root", doRoot }, |
| 149 | { NULL((void*)0), doDefault }}; |
| 150 | |
| 151 | int |
| 152 | main(int argc, char *argv[]) |
| 153 | { |
| 154 | Visual visual; |
| 155 | XSetWindowAttributes xswa; |
| 156 | int i; |
| 157 | char *displayname = NULL((void*)0); |
| 158 | Display *dpy; |
| 159 | Colormap cmap; |
| 160 | enum e_action action = doDefault; |
| 161 | unsigned long mask; |
| 162 | int screen; |
| 163 | int x, y, width, height; |
| 164 | char *geom = NULL((void*)0); |
| 165 | int geom_result; |
| 166 | int display_width, display_height; |
| 167 | char *solidcolor = NULL((void*)0); |
| 168 | XColor cdef; |
| 169 | |
| 170 | ProgramName = argv[0]; |
| 171 | |
| 172 | for (i = 1; i < argc; i++) { |
| 1 | Assuming 'i' is >= 'argc' |
|
| 2 | Loop condition is false. Execution continues on line 209 |
|
| 173 | char *arg = argv[i]; |
| 174 | |
| 175 | if (arg[0] == '-') { |
| 176 | if (isabbreviation ("-display", arg, 2)) { |
| 177 | if (++i >= argc) Syntax (); |
| 178 | displayname = argv[i]; |
| 179 | continue; |
| 180 | } else if (isabbreviation ("-geometry", arg, 2)) { |
| 181 | if (++i >= argc) Syntax (); |
| 182 | geom = argv[i]; |
| 183 | continue; |
| 184 | } else if (isabbreviation ("-black", arg, 2)) { |
| 185 | action = doBlack; |
| 186 | continue; |
| 187 | } else if (isabbreviation ("-white", arg, 2)) { |
| 188 | action = doWhite; |
| 189 | continue; |
| 190 | } else if (isabbreviation ("-solid", arg, 2)) { |
| 191 | if (++i >= argc) Syntax (); |
| 192 | solidcolor = argv[i]; |
| 193 | action = doSolid; |
| 194 | continue; |
| 195 | } else if (isabbreviation ("-none", arg, 2)) { |
| 196 | action = doNone; |
| 197 | continue; |
| 198 | } else if (isabbreviation ("-root", arg, 2)) { |
| 199 | action = doRoot; |
| 200 | continue; |
| 201 | } else |
| 202 | Syntax (); |
| 203 | } else if (arg[0] == '=') |
| 204 | geom = arg; |
| 205 | else |
| 206 | Syntax (); |
| 207 | } |
| 208 | |
| 209 | if ((dpy = XOpenDisplay(displayname)) == NULL((void*)0)) { |
| |
| 210 | fprintf (stderrstderr, "%s: unable to open display '%s'\n", |
| 211 | ProgramName, XDisplayName (displayname)); |
| 212 | exit (1); |
| 213 | } |
| 214 | |
| 215 | if (action == doDefault) { |
| |
| 216 | char *def; |
| 217 | |
| 218 | if ((def = XGetDefault (dpy, ProgramName, "Solid")) != NULL((void*)0)) { |
| |
| 219 | solidcolor = strdup (def); |
| 220 | if (solidcolor == NULL((void*)0)) { |
| 221 | fprintf (stderrstderr, |
| 222 | "%s: unable to allocate memory for string.\n", |
| 223 | ProgramName); |
| 224 | exit (1); |
| 225 | } |
| 226 | action = doSolid; |
| 227 | } else { |
| 228 | const struct s_pair *pp; |
| 229 | |
| 230 | for (pp = pair_table; pp->resource_name != NULL((void*)0); pp++) { |
| 6 | Loop condition is true. Entering loop body |
|
| 8 | Loop condition is true. Entering loop body |
|
| 10 | Loop condition is false. Execution continues on line 239 |
|
| 231 | def = XGetDefault (dpy, ProgramName, pp->resource_name); |
| 232 | if (def && parse_boolean_option (def) == 1) { |
| |
| |
| 233 | action = pp->action; |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if (geom == NULL((void*)0)) geom = XGetDefault (dpy, ProgramName, "Geometry"); |
| |
| 240 | |
| 241 | screen = DefaultScreen (dpy)(((_XPrivDisplay)dpy)->default_screen); |
| 242 | display_width = DisplayWidth (dpy, screen)((&((_XPrivDisplay)dpy)->screens[screen])->width); |
| 243 | display_height = DisplayHeight (dpy, screen)((&((_XPrivDisplay)dpy)->screens[screen])->height); |
| 244 | x = y = 0; |
| 245 | width = display_width; |
| 246 | height = display_height; |
| 247 | |
| 248 | if (DisplayCells (dpy, screen)(((&((_XPrivDisplay)dpy)->screens[screen])->root_visual )->map_entries) <= 2 && action == doSolid) { |
| 12 | Assuming 'action' is equal to doSolid |
|
| |
| 249 | if (strcmp (solidcolor, "black") == 0) |
| 14 | Null pointer passed as an argument to a 'nonnull' parameter |
|
| 250 | action = doBlack; |
| 251 | else if (strcmp (solidcolor, "white") == 0) |
| 252 | action = doWhite; |
| 253 | else { |
| 254 | fprintf (stderrstderr, |
| 255 | "%s: can't use colors on a monochrome display.\n", |
| 256 | ProgramName); |
| 257 | action = doNone; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (geom) |
| 262 | geom_result = XParseGeometry (geom, &x, &y, |
| 263 | (unsigned int *)&width, |
| 264 | (unsigned int *)&height); |
| 265 | else |
| 266 | geom_result = NoValue0x0000; |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | if (geom_result & XNegative0x0010) { |
| 284 | if (geom_result & WidthValue0x0004) { |
| 285 | x = display_width - width + x; |
| 286 | } else { |
| 287 | width = display_width + x; |
| 288 | x = 0; |
| 289 | } |
| 290 | } |
| 291 | if (geom_result & YNegative0x0020) { |
| 292 | if (geom_result & HeightValue0x0008) { |
| 293 | y = display_height - height + y; |
| 294 | } else { |
| 295 | height = display_height + y; |
| 296 | y = 0; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | mask = 0; |
| 301 | switch (action) { |
| 302 | case doBlack: |
| 303 | xswa.background_pixel = BlackPixel (dpy, screen)((&((_XPrivDisplay)dpy)->screens[screen])->black_pixel ); |
| 304 | mask |= CWBackPixel(1L<<1); |
| 305 | break; |
| 306 | case doWhite: |
| 307 | xswa.background_pixel = WhitePixel (dpy, screen)((&((_XPrivDisplay)dpy)->screens[screen])->white_pixel ); |
| 308 | mask |= CWBackPixel(1L<<1); |
| 309 | break; |
| 310 | case doSolid: |
| 311 | cmap = DefaultColormap (dpy, screen)((&((_XPrivDisplay)dpy)->screens[screen])->cmap); |
| 312 | if (XParseColor (dpy, cmap, solidcolor, &cdef) && |
| 313 | XAllocColor (dpy, cmap, &cdef)) { |
| 314 | xswa.background_pixel = cdef.pixel; |
| 315 | mask |= CWBackPixel(1L<<1); |
| 316 | } else { |
| 317 | fprintf (stderrstderr,"%s: unable to allocate color '%s'.\n", |
| 318 | ProgramName, solidcolor); |
| 319 | xswa.background_pixmap = None0L; |
| 320 | mask |= CWBackPixmap(1L<<0); |
| 321 | } |
| 322 | break; |
| 323 | case doDefault: |
| 324 | case doNone: |
| 325 | xswa.background_pixmap = None0L; |
| 326 | mask |= CWBackPixmap(1L<<0); |
| 327 | break; |
| 328 | case doRoot: |
| 329 | xswa.background_pixmap = ParentRelative1L; |
| 330 | mask |= CWBackPixmap(1L<<0); |
| 331 | break; |
| 332 | } |
| 333 | xswa.override_redirect = True1; |
| 334 | xswa.backing_store = NotUseful0; |
| 335 | xswa.save_under = False0; |
| 336 | mask |= (CWOverrideRedirect(1L<<9) | CWBackingStore(1L<<6) | CWSaveUnder(1L<<10)); |
| 337 | visual.visualid = CopyFromParent0L; |
| 338 | win = XCreateWindow(dpy, DefaultRootWindow(dpy)((&((_XPrivDisplay)dpy)->screens[(((_XPrivDisplay)dpy) ->default_screen)])->root), x, y, width, height, |
| 339 | 0, DefaultDepth(dpy, screen)((&((_XPrivDisplay)dpy)->screens[screen])->root_depth ), InputOutput1, &visual, mask, &xswa); |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | XMapWindow (dpy, win); |
| 346 | |
| 347 | XCloseDisplay (dpy); |
| 348 | exit (0); |
| 349 | } |
| 350 | |