lint
[nvi.git] / motif / m_main.c
blobbd8648a9be30356ab666dbba7087e9a7592204d4
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_main.c,v 8.29 1996/12/16 17:24:17 bostic Exp $ (Berkeley) $Date: 1996/12/16 17:24:17 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
21 #include <Xm/MainW.h>
23 #include <bitstring.h>
24 #include <signal.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include "../common/common.h"
30 #include "../motif_l/vi_mextern.h"
31 #include "extern.h"
33 #if XtSpecificationRelease == 4
34 #define ArgcType Cardinal *
35 #else
36 #define ArgcType int *
37 #endif
39 #include "nvi.xbm" /* Icon bitmap. */
41 static pid_t pid;
42 static Pixel icon_fg,
43 icon_bg;
44 static Pixmap icon_pm;
45 static Widget top_level;
46 static XtAppContext ctx;
48 static void onchld __P((int));
49 static void onexit __P((void));
52 /* resources for the vi widgets unless the user overrides them */
53 String fallback_rsrcs[] = {
55 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
56 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
57 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
58 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
59 "*pointerShape: xterm",
60 "*busyShape: watch",
61 "*iconName: vi",
63 /* coloring for the icons */
64 "*iconForeground: XtDefaultForeground",
65 "*iconBackground: XtDefaultBackground",
67 /* layout for the tag stack dialog */
68 "*Tags*visibleItemCount: 5",
70 /* for the text ruler */
71 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
72 "*rulerBorder: 5",
74 /* layout for the new, temporary preferences page */
75 "*toggleOptions.numColumns: 6", /* also used by Find */
76 "*Preferences*tabWidthPercentage: 0",
77 "*Preferences*tabs.shadowThickness: 2",
78 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
80 /* --------------------------------------------------------------------- *
81 * anything below this point is only defined when we are not running CDE *
82 * --------------------------------------------------------------------- */
84 /* Do not define default colors when running under CDE
85 * (e.g. VUE on HPUX). The result is that you don't look
86 * like a normal desktop application
88 "?background: gray75",
89 "?screen.background: wheat",
90 "?highlightColor: red",
91 "?Preferences*options.background: gray90",
94 #if defined(__STDC__)
95 static String *get_fallback_rsrcs( String name )
96 #else
97 static String *get_fallback_rsrcs( name )
98 String name;
99 #endif
101 String *copy = (String *) malloc( (1+XtNumber(fallback_rsrcs))*sizeof(String) );
102 int i, running_cde;
103 Display *d;
105 /* connect to server and see if the CDE atoms are present */
106 d = XOpenDisplay(0);
107 running_cde = is_cde( d );
108 XCloseDisplay(d);
110 for ( i=0; i<XtNumber(fallback_rsrcs); i++ ) {
112 /* stop here if running CDE */
113 if ( fallback_rsrcs[i][0] == '?' ) {
114 if ( running_cde ) break;
115 fallback_rsrcs[i] = strdup(fallback_rsrcs[i]);
116 fallback_rsrcs[i][0] = '*';
119 copy[i] = malloc( strlen(name) + strlen(fallback_rsrcs[i]) + 1 );
120 strcpy( copy[i], name );
121 strcat( copy[i], fallback_rsrcs[i] );
124 copy[i] = NULL;
125 return copy;
129 /* create the shell widgetry */
131 #if defined(__STDC__)
132 static void create_top_level_shell( int *argc, char **argv )
133 #else
134 static void create_top_level_shell( argc, argv )
135 int *argc;
136 char **argv;
137 #endif
139 char *ptr;
140 Widget main_w, editor;
141 Display *display;
143 /* X gets quite upset if the program name is not simple */
144 if (( ptr = strrchr( argv[0], '/' )) != NULL ) argv[0] = ++ptr;
145 vi_progname = argv[0];
147 /* create a top-level shell for the window manager */
148 top_level = XtVaAppInitialize( &ctx,
149 vi_progname,
150 NULL, 0, /* options */
151 (ArgcType) argc,
152 argv, /* might get modified */
153 get_fallback_rsrcs( argv[0] ),
154 NULL
156 display = XtDisplay(top_level);
158 /* might need to go technicolor... */
159 XutInstallColormap( argv[0], top_level );
161 /* create our icon
162 * do this *before* realizing the shell widget in case the -iconic
163 * option was specified.
165 icon_pm = XCreatePixmapFromBitmapData(
166 display,
167 DefaultRootWindow(display),
168 (char *) nvi_bits,
169 nvi_width,
170 nvi_height,
171 icon_fg,
172 icon_bg,
173 DefaultDepth( display, DefaultScreen(display) )
175 XutSetIcon( top_level, nvi_height, nvi_width, icon_pm );
177 /* in the shell, we will stack a menubar an editor */
178 main_w = XtVaCreateManagedWidget( "main",
179 xmMainWindowWidgetClass,
180 top_level,
181 NULL
184 /* create the menubar */
185 XtManageChild( (Widget) vi_create_menubar( main_w ) );
187 /* add the VI widget from the library */
188 editor = vi_create_editor( "editor", main_w, onexit );
190 /* put it up */
191 XtRealizeWidget( top_level );
193 /* We *may* want all keyboard events to go to the editing screen.
194 * If the editor is the only widget in the shell that accepts
195 * keyboard input, then the user will expect that he can type when
196 * the pointer is over the scrollbar (for example). This call
197 * causes that to happen.
199 XtSetKeyboardFocus( top_level, XtNameToWidget( editor, "*screen" ) );
204 main(argc, argv)
205 int argc;
206 char *argv[];
208 int i_fd;
211 * Initialize the X widgetry. We must do this before picking off
212 * arguments as well-behaved X programs have common argument lists
213 * (e.g. -rv for reverse video).
215 create_top_level_shell(&argc, argv);
217 /* We need to know if the child process goes away. */
218 (void)signal(SIGCHLD, onchld);
220 /* Run vi: the parent returns, the child is the vi process. */
221 (void)vi_run(argc, argv, &i_fd, &vi_ofd, &pid);
223 /* Tell X that we are interested in input on the pipe. */
224 XtAppAddInput(ctx, i_fd,
225 (XtPointer)XtInputReadMask, vi_input_func, NULL);
227 /* Main loop. */
228 XtAppMainLoop(ctx);
230 /* NOTREACHED */
231 abort();
235 * onchld --
236 * Handle SIGCHLD.
238 static void
239 onchld(signo)
240 int signo;
242 /* If the vi process goes away, we exit as well. */
243 if (kill(pid, 0))
244 vi_fatal_message(top_level, "The vi process died. Exiting.");
248 * onexit --
249 * Function called when the editor "quits".
251 static void
252 onexit()
254 exit (0);