1 /* $Xorg: dsimple.c,v 1.4 2001/02/09 02:05:54 xorgcvs Exp $ */
4 Copyright 1993, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of The Open Group shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
29 /* $XFree86: xc/programs/xlsfonts/dsimple.c,v 3.6 2001/12/14 20:02:09 dawes Exp $ */
33 #include <X11/Xutil.h>
34 #include <X11/cursorfont.h>
39 * Other_stuff.h: Definitions of routines in other_stuff.
41 * Written by Mark Lillibridge. Last updated 7/1/87
47 * Just_display: A group of routines designed to make the writting of simple
48 * X11 applications which open a display but do not open
49 * any windows much faster and easier. Unless a routine says
50 * otherwise, it may be assumed to require program_name, dpy,
51 * and screen already defined on entry.
53 * Written by Mark Lillibridge. Last updated 7/1/87
57 /* This stuff is defined in the calling program by just_display.h */
58 char *program_name = "unknown_program";
63 * Malloc: like malloc but handles out of memory using Fatal_Error.
70 if (!(data = malloc(size)))
71 Fatal_Error("Out of memory!");
78 * Realloc: like Malloc except for realloc, handles NULL using Malloc.
81 Realloc(char *ptr, int size)
88 if (!(new_ptr = realloc(ptr, size)))
89 Fatal_Error("Out of memory!");
96 * Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete)
97 * If found, remove it from command line. Don't go past a lone -.
100 Get_Display_Name(int *pargc/* MODIFIED */, char **argv/* MODIFIED */)
103 char **pargv = argv+1;
104 char *displayname = NULL;
107 for (i = 1; i < argc; i++) {
110 if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) {
111 if (++i >= argc) usage ();
113 displayname = argv[i];
117 if (!strcmp(arg,"-")) {
119 *pargv++ = argv[i++];
126 return (displayname);
131 * Open_Display: Routine to open a display with correct error handling.
132 * Does not require dpy or screen defined on entry.
135 Open_Display(char *display_name)
139 d = XOpenDisplay(display_name);
141 fprintf (stderr, "%s: unable to open display '%s'\n",
142 program_name, XDisplayName (display_name));
151 * Setup_Display_And_Screen: This routine opens up the correct display (i.e.,
152 * it calls Get_Display_Name) and then stores a
153 * pointer to it in dpy. The default screen
154 * for this display is then stored in screen.
155 * Does not require dpy or screen defined.
158 Setup_Display_And_Screen(int *argc/* MODIFIED */, char **argv/* MODIFIED */)
160 char *displayname = Get_Display_Name(argc, argv);
162 dpy = Open_Display (displayname);
163 screen = XDefaultScreen(dpy);
167 * Close_Display: Close display
169 void Close_Display(void)
180 * Standard fatal error routine - call like printf but maximum of 7 arguments.
181 * Does not require dpy or screen defined.
183 void Fatal_Error(char *msg, ...)
188 fprintf(stderr, "%s: error: ", program_name);
190 vfprintf(stderr, msg, args);
192 fprintf(stderr, "\n");