1 
2 /* asutil.c  -  some Motif utilities used in the asedit program
3 		Last revision 23.02.1994
4 */
5 
6 /*
7  * Copyright 1991 - 1994,  Andrzej Stochniol, London, UK
8  *
9  * ASEDIT text editor, both binary and source (hereafter, Software) is
10  * copyrighted by Andrzej Stochniol (hereafter, AS) and ownership remains
11  * with AS.
12  *
13  * AS grants you (hereafter, Licensee) a license to use the Software
14  * for academic, research and internal business purposes only, without a
15  * fee.  Licensee may distribute the binary and source code (if released)
16  * to third parties provided that the copyright notice and this statement
17  * appears on all copies and that no charge is associated with such copies.
18  *
19  * Licensee may make derivative works.  However, if Licensee distributes
20  * any derivative work based on or derived from the Software, then
21  * Licensee will:
22  * (1) notify AS regarding its distribution of the derivative work, and
23  * (2) clearly notify users that such derivative work is a modified version
24  *      and not the original ASEDIT distributed by AS.
25  *
26  * Any Licensee wishing to make commercial use of the Software should
27  * contact AS to negotiate an appropriate license for such commercial use.
28  * Commercial use includes:
29  * (1) integration of all or part of the source code into a product for sale
30  *     or license by or on behalf of Licensee to third parties, or
31  * (2) distribution of the binary code or source code to third parties that
32  *     need it to utilize a commercial product sold or licensed by or on
33  *     behalf of Licensee.
34  *
35  * A. STOCHNIOL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS
36  * SOFTWARE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
37  * IMPLIED WARRANTY.  IN NO EVENT SHALL A. STOCHNIOL BE LIABLE FOR ANY
38  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
39  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
40  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
41  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42  *
43  * By using or copying this Software, Licensee agrees to abide by the
44  * copyright law and all other applicable laws, and the terms of this
45  * license.
46  * AS shall have the right to terminate this license immediately by
47  * written notice upon Licensee's breach of, or non-compliance with, any
48  * of its terms.  Licensee may be held legally responsible for any
49  * copyright infringement that is caused or encouraged by Licensee's
50  * failure to abide by the terms of this license.
51  *
52  *
53  * 	Andrzej Stochniol	(A.Stochniol@ic.ac.uk)
54  * 	30 Hatch Road
55  * 	London SW16 4PN
56  * 	UK
57  */
58 
59 
60 
61 #include <stdio.h>
62 #include <string.h>
63 #include <stdlib.h>
64 #include <ctype.h>		/* for isspace definition */
65 
66 #include <X11/Intrinsic.h>
67 
68 #include <Xm/Xm.h>
69 #include <Xm/MessageB.h>
70 #include <Xm/SelectioB.h>
71 #include <Xm/Label.h>
72 #include <Xm/RowColumn.h>
73 #include <Xm/Text.h>
74 
75 #include <Xm/AtomMgr.h> 	/* for XmInternAtom */
76 
77 #if (XmVersion == 1000)
78 /*  for Motif 1.0  all TRAVERSE constants are defined in a private Header XmP.h
79     (at least this is the case for our IBM RS/6000). Since Motif 1.1 they are defined
80     in Xm.h.
81 */
82 #include <Xm/XmP.h>
83 #endif  /* XmVersion... */
84 
85 #if (XmVersion < 1002)
86 /* for Motif < 1.2 we use a private function  _XmStringSourceGetString & _XmTextDisableRedisplay; include TextP.h */
87 #include <Xm/TextP.h>
88 #endif
89 
90 
91 #include "asedit.h"		/* for new  aseditWindowStruct definitions ... */
92 #include "asedit.ico"
93 
94 #if defined(__alpha) || defined(GET_PIXMAP_BUG)
95 #   include "warning.xbm"
96 #endif
97 
98 
99 /*
100 **	create_4buttons_dialog
101 **		create special 4 buttons  dialog box out of a
102 **		selection box and supports graphical pixmap.
103 **		The message contains of the pixmap and string
104 **		If you do not want use any pixmap
105 **		specify None  pixmap like this:  None
106 */
107 #ifdef _NO_PROTO
create_4buttons_dialog(parent,name,pixmap,message,arglist,argcount)108 Widget create_4buttons_dialog (parent, name, pixmap, message, arglist, argcount)
109 	Widget parent;
110 	String name;
111 	Pixmap pixmap;
112 	String message;
113 	Arg arglist[];
114 	int argcount;
115 #else  /* _NO_PROTO */
116 Widget create_4buttons_dialog (Widget parent, String name, Pixmap pixmap,
117 	String message, Arg arglist[], int argcount)
118 #endif
119 {
120 	Widget 		message_dialog;	/*  special message selection box */
121 	Widget		apply_button;	/*  4th button which should be managed */
122 	Widget          kid[5];         /*  children		          */
123 	Arg             al[10];         /*  arg list		          */
124 	register int    ac;             /*  arg count		          */
125 	XmString  	label_string;   /*  work string */
126 	Widget 		work_area;	/*  rowcolumn for pixmap and text */
127 	Widget 		pixmap_label;	/*  pixmap label 		  */
128 	Widget 		text_label;	/*  text label 			  */
129 
130 
131 	message_dialog = XmCreatePromptDialog(parent, name, arglist, argcount);
132 
133 
134 	ac = 0;
135 	XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
136 	work_area = XmCreateRowColumn(message_dialog, "workarea", al, ac);
137 	XtManageChild(work_area);
138 
139 	if(pixmap != None)
140 	{
141 		ac = 0;
142 		XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
143 		XtSetArg(al[ac], XmNlabelPixmap, pixmap); ac++;
144 		pixmap_label = XmCreateLabel(work_area, "pixmap_label", al, ac);
145 		XtManageChild(pixmap_label);
146 	}
147 
148 	ac = 0;
149 	label_string = XmStringCreateLtoR(message, charset);
150 	XtSetArg(al[ac], XmNlabelString, label_string ); ac++;
151 	text_label = XmCreateLabel(work_area, "text_label", al, ac);
152 	XtManageChild(text_label);
153 	XmStringFree(label_string);
154 
155         /* store the text_label widget in the userData !!!, that will allow us to change
156            dynamically the message string !!!
157         */
158         ac = 0;
159         XtSetArg(al[ac], XmNuserData, text_label);  ac++;
160         XtSetValues(message_dialog, al, ac);
161 
162 	/* manage the apply button */
163 	apply_button = XmSelectionBoxGetChild (message_dialog,
164 						 XmDIALOG_APPLY_BUTTON);
165 	XtManageChild(apply_button);
166 
167 	/*      Unmanage unneeded children.    */
168 	ac = 0;
169 	kid[ac++] = XmSelectionBoxGetChild (message_dialog, XmDIALOG_TEXT);
170 	kid[ac++] = XmSelectionBoxGetChild (message_dialog,
171 						     XmDIALOG_SELECTION_LABEL);
172 	XtUnmanageChildren (kid, ac);
173 
174 	return(message_dialog);
175 
176 }	/* create_4buttons_dialog */
177 
178 
179 
180 /*-------------------------------------------------------------
181 **	create_4buttons_image_dialog
182 **		Create special 4 button message box out of a
183 **	Selection box.
184 */
185 #ifdef _NO_PROTO
create_4buttons_image_dialog(parent,name,image_string,message,arglist,argcount)186 Widget create_4buttons_image_dialog (parent, name,
187 	image_string, message, arglist, argcount)
188 	Widget parent;
189 	String name;
190 	String image_string;
191 	String message;
192 	Arg arglist[];
193 	int argcount;
194 #else  /* _NO_PROTO */
195 Widget create_4buttons_image_dialog (Widget parent, String name,
196 	String image_string, String message, Arg arglist[], int argcount)
197 #endif
198 {
199 	Widget 		warning_dialog;	/*  special warning selection box */
200 	Widget 		work_area;	/*  rowcolumn for pixmap and text */
201 	Widget 		pixmap_label;	/*  pixmap label 		  */
202 	Widget 		text_label;	/*  text label 			  */
203 	Widget 		apply_button;	/*  apply button		  */
204 	Widget          kid[5];         /*  buttons		          */
205 	Pixel		foreground;	/*  dialog foreground		  */
206 	Pixel		background;	/*  dialog background		  */
207 	Pixmap		pixmap;		/*  dialog pixmap		  */
208 	register int    i;              /*  kid index			  */
209 	Arg             al[10];         /*  arg list		          */
210 	register int    ac;             /*  arg count		          */
211 	XmString  	label_string;   /*  work string */
212 
213 
214 	warning_dialog = XmCreatePromptDialog(parent, name, arglist, argcount);
215 
216 	ac = 0;
217 	XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
218 	work_area = XmCreateRowColumn(warning_dialog, "workarea", al, ac);
219 	XtManageChild(work_area);
220 
221 	ac = 0;
222 	XtSetArg(al[ac], XmNforeground, &foreground); ac++;
223 	XtSetArg(al[ac], XmNbackground, &background); ac++;
224 	XtGetValues(warning_dialog, al, ac);
225 
226 	ac = 0;
227 	XtSetArg(al[ac], XmNlabelType, XmPIXMAP); ac++;
228 #if !defined(__alpha) && !defined(GET_PIXMAP_BUG)
229 	pixmap = XmGetPixmap(XtScreen(warning_dialog), image_string,
230 			     foreground, background);
231 #else
232         /* a hack to avoid DEC ALPHA/OSF problem with caching images (needed by XmGetPixmap) */
233         /* we use a standard "as" warning bitmap  and create pixmap explicitly */
234         pixmap =XCreatePixmapFromBitmapData(display, DefaultRootWindow (display),
235               warning_bits, warning_width, warning_height,
236               foreground, background,
237               DefaultDepthOfScreen (DefaultScreenOfDisplay (display)));
238 #endif /* !GET_PIXMAP_BUG */
239 
240 	XtSetArg(al[ac], XmNlabelPixmap, pixmap); ac++;
241 	pixmap_label = XmCreateLabel(work_area, "pixmap_label", al, ac);
242 	XtManageChild(pixmap_label);
243 
244 	ac = 0;
245 	label_string = XmStringCreateLtoR(message, charset);
246 	XtSetArg(al[ac], XmNlabelString, label_string ); ac++;
247 	text_label = XmCreateLabel(work_area, "text_label", al, ac);
248 	XtManageChild(text_label);
249 	/* because XmString is copied into an internal area by the label widget
250 	   we can free the storage associated with the string by calling XmStringFree
251 	   (after XtCreateManagedWidget or XtSetValues (etc.) are finished) */
252 	XmStringFree(label_string);
253 
254 	/* store the text_label widget in the userData !!!, that will allow us to change
255            dynamically the message string !!!
256  	*/
257 	ac = 0;
258 	XtSetArg(al[ac], XmNuserData, text_label);  ac++;
259 	XtSetValues(warning_dialog, al, ac);
260 
261 	apply_button = XmSelectionBoxGetChild (warning_dialog,
262 						 XmDIALOG_APPLY_BUTTON);
263 	XtManageChild(apply_button);
264 
265 
266 
267 	/*      Unmanage unneeded children.    */
268 	i = 0;
269 	kid[i++] = XmSelectionBoxGetChild (warning_dialog, XmDIALOG_TEXT);
270 	kid[i++] = XmSelectionBoxGetChild (warning_dialog,
271 						     XmDIALOG_SELECTION_LABEL);
272 	XtUnmanageChildren (kid, i);
273 
274 	return(warning_dialog);
275 
276 }	/* create_4buttons_image_dialog */
277 
278 /************************************************************************
279  *
280  *  CreateDefaultImage - create a default images for warning symbol.
281  *
282  **********************************<->***********************************/
283 #ifdef _NO_PROTO
CreateDefaultImage(bits,width,height)284 XImage * CreateDefaultImage (bits, width, height)
285     char *bits;
286     int width;
287     int height;
288 #else  /* _NO_PROTO */
289 XImage * CreateDefaultImage (char *bits, int width, int height)
290 #endif
291 {
292     XImage *image;
293 
294     image = (XImage *) XtMalloc (sizeof (XImage));
295     image->width = width;
296     image->height = height;
297     image->data = bits;
298     image->depth = 1;
299     image->xoffset = 0;
300     image->format = XYBitmap;
301     image->byte_order = LSBFirst;
302     image->bitmap_unit = 8;
303     image->bitmap_bit_order = LSBFirst;
304     image->bitmap_pad = 8;
305     image->bytes_per_line = (width+7)/8;
306     return (image);
307 }   /* CreateDefaultImage */
308 
309 
310 #ifdef _NO_PROTO
show_error_message(win,message)311 void show_error_message(win, message)
312 	aseditWindowStruct *win;
313 	char *message;
314 #else  /* _NO_PROTO */
315 void show_error_message(aseditWindowStruct *win, char *message)
316 #endif
317 {
318     /* procedure is used to show the error message widget with the current
319 	message using the preset character set "charset";
320 	if the error_message widget is not available yet create it first
321 	as a child of menu_bar */
322 
323     Arg			al[5];		/*  arg list		*/
324     register    int	ac = 0;		/*  arg count		*/
325     XmString  message_string =XmStringCreateLtoR(message, charset);
326 
327     if(win->error_message == NULL)		/* create error_message widget first */
328     {
329 	Widget 		kids[3];	/*  children widgets 	*/
330 	int     	i;
331 
332 	XtSetArg(al[ac], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); ac++;
333 	/* we are using the Cancel button for the closing of that message
334 	   mainly because that button will be automatically centered */
335 	/* The default button needs to be set now to the Cancel button. Otherwise
336 	   when we press Enter the button won't change the colour to the select
337 	   colour etc. (the standard defaults to OK button) */
338 	XtSetArg(al[ac], XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON); ac++;
339 
340 	win->error_message = XmCreateErrorDialog (win->menu_bar, "error_message",al,ac);
341 
342 	/* unmanage the unneeded buttons */
343 	i=0;
344 	kids[i++] = XmMessageBoxGetChild(win->error_message, XmDIALOG_HELP_BUTTON);
345 	kids[i++] = XmMessageBoxGetChild(win->error_message, XmDIALOG_OK_BUTTON);
346 	XtUnmanageChildren (kids, i);
347 	/* let's add the proper callback (just in case that somebody set
348 	   wrongly the autoUnmanage to False ....) */
349 	XtAddCallback (win->error_message, XmNcancelCallback,
350 		(XtCallbackProc)DialogCancelCB,  mk_asdat(ERROR_MESSAGE) );
351     }
352 
353     ac = 0;
354     XtSetArg(al[ac], XmNmessageString, message_string);  ac++;
355     XtSetValues(win->error_message, al, ac);
356     XmStringFree(message_string);	/* free memory allocated for XmString */
357 
358     asManageDialog (win->error_message);
359 
360 }   /* show_error_message */
361 
362 
363 static Pixmap icon_pixmap = (Pixmap)NULL;	/* globally accessible for about program message */
364 
365 
366 
367 /*
368 **	CreateAboutProgramMessage	- create simple message widget
369 */
370 #ifdef _NO_PROTO
CreateAboutProgramMessage(parent)371 Widget CreateAboutProgramMessage (parent)
372 	Widget parent;
373 #else  /* _NO_PROTO */
374 Widget CreateAboutProgramMessage (Widget parent)
375 #endif
376 {
377 	Widget		button;
378 	Widget		message_box;	/*  Message Dialog 	*/
379 	Arg		al[10];		/*  arg list		*/
380 	register int	n;		/*  arg count		*/
381 
382 	char		message[1000];	/*  help text	*/
383 
384 	XmString	title_string = NULL;
385 	XmString	message_string = NULL;
386 	XmString	button_string = NULL;
387 	char 		work[128];
388 
389 
390 
391 	/*	Generate message to display.
392 	*/
393 
394 #undef ABOUT_M_SET
395 
396 
397 
398 #ifndef ABOUT_M_SET
399 	sprintf (message, "\
400 ASEDIT editor\n\
401 Version 1.3.2 (non-commercial)\n\
402 Copyright (C) A. Stochniol, 1992-94.\n\
403 (A.Stochniol@ic.ac.uk)");
404 #endif
405 
406 	message_string = XmStringCreateLtoR (message, charset);
407 
408 	/*	Create MessageBox dialog.	*/
409 	n = 0;
410 	/* specify the icon_pixmap as the symbol pixmap */
411 	if(icon_pixmap != (Pixmap)NULL)
412 	{
413 	    XtSetArg(al[n], XmNsymbolPixmap, icon_pixmap);  n++;
414 	}
415 
416 	/* let's unmanage OK and Help button so the
417 	   original cancel button will be positioned in the centre of the widget
418 	   i.e. in the visually recommended position ... */
419 	/* The default button needs to be set now to the Cancel button. Otherwise
420 	   when we press Enter the button won't change the colour to the select
421 	   colour etc. (the standard defaults to OK button) */
422 	XtSetArg(al[n], XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON); n++;
423 
424 	XtSetArg (al[n], XmNmessageString, message_string);  n++;
425 	XtSetArg (al[n], XmNmessageAlignment, XmALIGNMENT_CENTER); n++;
426 	message_box = XmCreateMessageDialog (parent, "about", al, n);
427 
428 	/* unmanage OK and Help buttons */
429 	button = XmMessageBoxGetChild (message_box, XmDIALOG_OK_BUTTON);
430 	XtUnmanageChild (button);
431 	button = XmMessageBoxGetChild (message_box, XmDIALOG_HELP_BUTTON);
432 	XtUnmanageChild (button);
433 
434 
435 	/*	Free strings and return MessageBox.	*/
436 
437 	XmStringFree(  title_string);
438 	XmStringFree(message_string);
439 	XmStringFree( button_string);
440 
441 	return (message_box);
442 
443 }	/* CreateAboutProgramMessage */
444 
445 
446 /*****************************  show_about_message  **************************
447 **
448 **  Show about_program_message for the specified asedit window. If it does not exist yet
449 **  create it first as a child of menu_bar.
450 */
451 
452 #ifdef _NO_PROTO
show_about_message(win)453 void show_about_message (win)
454         aseditWindowStruct *win;
455 #else  /* ! _NO_PROTO */
456 
457 void show_about_message (aseditWindowStruct *win)
458 #endif
459 {
460     if(win->about_program_message == NULL)        /* first create the widget  */
461     {
462             /*  create an About message (we need the icon_pixmap; already available) */
463         win->about_program_message = CreateAboutProgramMessage (win->menu_bar);
464 
465         /* add the help callback to accept F1 (help key) press inside the message */
466         XtAddCallback (win->about_program_message,  XmNhelpCallback,
467                          (XtCallbackProc) HelpCB, mk_asdat(MENU_H_ABOUT));
468     }
469 
470     asManageDialog (win->about_program_message);
471 
472 }   /* show_about_message */
473 
474 
475 
476 /****************************  set_appl_icon_pixmap  ***********************
477  *
478  * Set the icon for the application shell widget (top level) to the icon_pixmap.
479  * Use the modern method of setting pixmap.
480  * This version is better suited for SGI bigger icons.
481  *
482  * For some old window managers you might use set_appl_icon_pixmap_uni;
483  * you also should use the other
484  * method if you want to draw something dynamically into the icon window.
485  *
486 */
487 
488 #ifdef _NO_PROTO
set_appl_icon_pixmap(shell,icon_pixmap)489 static void set_appl_icon_pixmap (shell, icon_pixmap)
490     Widget shell;
491     Pixmap icon_pixmap;
492 #else  /* _NO_PROTO */
493 static void set_appl_icon_pixmap (Widget shell, Pixmap icon_pixmap)
494 #endif
495 {
496     Arg al[4];
497     register int ac;
498 
499     /* use a modern method using XmNiconPixmap and
500        hope that the window managers understand it */
501     ac = 0;
502     XtSetArg(al[ac], XmNiconPixmap, icon_pixmap);  ac++;
503     XtSetValues(shell, al, ac);
504     return;
505 
506 }   /* set_appl_icon_pixmap */
507 
508 
509 /****************************  set_appl_icon_pixmap_uni  ***********************
510  *
511  * Set the icon for the application shell widget (top level) to the icon_pixmap.
512  * For the best results in portability into environments where the user may
513  * not be running the most up-to-date window manager (that supports setting
514  * iconPixmap directly) the icon window is created directly. Additionally, once
515  * done we can paint whatever image we like in that window ! So, the function
516  * may also be called repeatedly to dynamically update shell's icon window.
517  *
518 */
519 
520 #ifdef _NO_PROTO
set_appl_icon_pixmap_uni(shell,icon_pixmap)521 static void set_appl_icon_pixmap_uni (shell, icon_pixmap)
522     Widget shell;
523     Pixmap icon_pixmap;
524 #else  /* _NO_PROTO */
525 static void set_appl_icon_pixmap_uni (Widget shell, Pixmap icon_pixmap)
526 #endif
527 {
528     Window icon_window, root_window;
529     int x, y;
530     unsigned int width, height, border_width, depth;
531     Status status;
532     Arg al[4];
533     register int ac;
534     Display *display = XtDisplay(shell);
535 
536     /* get the current icon window associated with the shell */
537     ac = 0;
538     XtSetArg(al[ac], XmNiconWindow, &icon_window );  ac++;
539     XtGetValues(shell, al, ac);
540 
541     /* if there is no window associated with the shell create one.
542        (first call - shell has not yet had its icon window set).
543     */
544     if(!icon_window)
545     {
546 	/* get the size of the icon_pixmap, then create an InputOutput window */
547 	status = XGetGeometry(display, icon_pixmap, &root_window, &x, &y,
548 			&width, &height, &border_width, &depth);
549 
550 	if(!status || !(icon_window = XCreateSimpleWindow (display, root_window,
551 				0, 0, width, height, border_width,
552 				CopyFromParent, CopyFromParent)))
553 	{
554 	    /* in the unlikely event that XGetGeometry or XCreateSimpleWindow
555 	       fails, we fall back on a modern method using XmNiconPixmap and
556 	       hope that the window managers understand it */
557 	    ac = 0;
558 	    XtSetArg(al[ac], XmNiconPixmap, icon_pixmap);  ac++;
559 	    XtSetValues(shell, al, ac);
560 	    return;
561 	}
562 	/* set the window created as the icon window */
563 	ac = 0;
564 	XtSetArg(al[ac], XmNiconWindow, icon_window);  ac++;
565 	XtSetValues(shell, al, ac);
566     }
567     /* set the current icon_pixmap as the window's background pixmap */
568     XSetWindowBackgroundPixmap(display, icon_window, icon_pixmap);
569     XClearWindow(display, icon_window);		/* to redisplay this window */
570 
571 }   /* set_appl_icon_pixmap_uni */
572 
573 /****************************  set_asedit_icon  *****************************
574     procedure first creates a pixmap from bitmap then calls procedure to create
575     an icon for the application
576 */
577 #ifdef _NO_PROTO
set_asedit_icon(shell,colours_source,icon_name)578 void set_asedit_icon(shell, colours_source, icon_name)
579     Widget shell;
580     Widget colours_source;
581     char *icon_name;
582 #else  /* _NO_PROTO */
583 void set_asedit_icon(Widget shell, Widget colours_source, char *icon_name)
584 #endif
585 {
586     /**Pixmap icon_pixmap; ** making it globally accessible for CreateAboutProgram .. */
587     Pixel background, foreground;
588     Arg al[4];
589     register int ac;
590 
591     /* get the foreground and background colours from colours_source widget;
592        from a shell widget only background can be obtained (foreground is not
593        defined); for asedit the most appropriate colours are those from the
594        edit_text window (set that widget on a call for this procedure) */
595 
596     ac = 0;
597     XtSetArg(al[ac], XmNforeground, &foreground );  ac++;
598     XtSetArg(al[ac], XmNbackground, &background);   ac++;
599     XtGetValues(colours_source, al, ac);
600 
601     /* create a pixmap from a bitmap using colours just obtained */
602     icon_pixmap = XCreatePixmapFromBitmapData (XtDisplay(shell),
603 	    RootWindowOfScreen(XtScreen(shell)),
604 	    (char *)asedit_icon_bits, asedit_icon_width, asedit_icon_height,
605 	    foreground, background,
606 	    DefaultDepthOfScreen(XtScreen(shell)));
607 
608     /* there are still many windows manager around that do NOT understand the modern
609        way of setting the ICON; let's return to the old way of setting it, i.e. instead
610        of using "set_appl_icon_pixmap" we use "set_appl_icon_pixmap_uni" (16 June 1994)
611     */
612     set_appl_icon_pixmap_uni (shell, icon_pixmap);
613 
614     /* finally set the icon name */
615     ac = 0;
616     XtSetArg (al[ac], XmNiconName, icon_name);     ac++;
617     XtSetValues (shell, al, ac);
618 
619 }   /* set_asedit_icon */
620 
621 
622 #ifdef _NO_PROTO
set_dialog_title(w,title)623 void set_dialog_title(w, title)
624     Widget w;
625     char *title;
626 #else  /* _NO_PROTO */
627 void set_dialog_title(Widget w, char *title)
628 #endif
629 {	/* sets the dialogTitle of the widget w using character set 'charset'
630 	   and adding in front of the 'title' string PROGRAM_NAME and a dash */
631 
632     register int  ac;		/* arg count		    */
633     Arg 	  al[3];	/* arg list		    */
634     XmString  	  xmstr;	/* work XmString */
635     char	  work[256];
636 
637     ac = 0;
638     sprintf(work, "%s", title);
639     xmstr =XmStringCreateLtoR(work, charset);
640     XtSetArg (al[ac], XmNdialogTitle, xmstr);   ac++;
641 
642     XtSetValues(w, al, ac);
643     XmStringFree(xmstr);	/* free memory allocated for XmString */
644 
645 }   /* set_dialog_title */
646 
647 
648 #ifdef _NO_PROTO
set_titles_mwindow_icon(win,filename,extra)649 void set_titles_mwindow_icon(win, filename, extra)
650 	   aseditWindowStruct *win;
651 	   char *filename;
652 	   char *extra;
653 #else  /* ! _NO_PROTO */
654 
655 void set_titles_mwindow_icon(aseditWindowStruct *win, char *filename, char *extra)
656 #endif
657 {
658     /* 	setting a new title of the main window. It includes the name
659 	of just opened file (when it is different from NULL);
660 	For the icon we set only the name of the file and without the path
661 	(if the file name is NULL we set the PROGRAM_NAME instead)
662     */
663     char main_title[286];		/* program_name + file name + extra*/
664     char icon_name[276];
665     char *filename_without_path;
666     char *filename_without_home;
667     register int ac;			/* arg count		    */
668     Arg al[10];				/* widget arg list	    */
669     char *home_dir = NULL;
670     int len;
671     Atom string_atom;		/* used to fix sun 8-bit problem */
672 
673 
674     if(filename)
675     {
676 	/* main title consists of a program name, a dash and a file name */
677 	sprintf(main_title,"%s - %s",PROGRAM_NAME, filename);
678 	/*      Get filename without leading path    */
679 	if (( filename_without_path = strrchr(filename, (int) '/')) == NULL)
680 		filename_without_path = filename;
681 	else
682 		filename_without_path++;
683 	strcpy(icon_name, filename_without_path);
684 
685 	/* if the file name include home directory skip it and replace
686 	   it with the "~" symbol
687 	*/
688 	home_dir = getenv("HOME");
689 	if(home_dir)
690 	{
691 	    len = strlen(home_dir);
692 	    if(strncmp(filename, home_dir, len) == 0)
693 	    {
694 		filename_without_home = filename+len;
695 		sprintf(main_title, "%s - ~%s",PROGRAM_NAME, filename_without_home);
696 	    }
697  	}
698 
699 	/* now check if the extra string is not empty; if not add it with a leading space
700 	   to the titles
701 	*/
702 	if(extra && (strlen(extra) > (size_t)0) )
703 	{
704 	    strcat(main_title, " ");
705 	    strcat(main_title, extra);
706 
707 	    strcat(icon_name, " ");
708 	    strcat(icon_name, extra);
709 	}
710 
711     }
712     else
713     {
714 	strcpy(icon_name, PROGRAM_NAME);
715 	strcpy(main_title, PROGRAM_NAME);
716     }
717     ac=0;
718     XtSetArg(al[ac], XmNtitle, 	main_title); ac++;
719     XtSetArg(al[ac], XmNiconName,icon_name); ac++;
720 
721 
722     XtSetValues(win->topshell, al, ac);
723 
724 }   /* set_titles_mwindow_icon */
725 
726 
727 
728 
729 #ifdef _NO_PROTO
focusTO(data,dummy)730 static void focusTO(data, dummy)
731     void *data;
732     XtIntervalId *dummy;
733 #else  /* ! _NO_PROTO */
734 
735 static void focusTO(void *data, XtIntervalId *dummy)
736 #endif
737 {
738 #if (XmVersion == 1000)
739     /* in Motif 1.0 traversal was private and may not work (it does not always
740        on my IBM RS/6000) ;
741        a right version of it appears in Motif 1.1 */
742     _XmProcessTraversal((Widget) data, XmTRAVERSE_CURRENT);
743 #else
744     XmProcessTraversal((Widget) data, XmTRAVERSE_CURRENT);
745 #endif
746 
747 }   /* focusTO */
748 
749 
750 #ifdef _NO_PROTO
focusCB(w,data,dummy)751 void focusCB(w, data, dummy)
752     Widget w;
753     XtPointer data;
754     XtPointer dummy;
755 #else  /* ! _NO_PROTO */
756 
757 void focusCB(Widget w, XtPointer data, XtPointer dummy)
758 #endif
759 {
760     XtRemoveCallback(w, XmNfocusCallback,
761 		(XtCallbackProc)focusCB, data);
762     XtAppAddTimeOut(XtWidgetToApplicationContext(w), 10L,
763 		(XtTimerCallbackProc)focusTO, data);
764 
765 }   /* focusCB */
766 
767 
768 
769 #ifdef _NO_PROTO
saveLoadQFont(name)770 static XFontStruct *saveLoadQFont (name)
771     char *name;
772 #else  /* ! _NO_PROTO */
773 
774 static XFontStruct *saveLoadQFont (char *name)
775 #endif
776 {
777   XFontStruct *font = XLoadQueryFont (display, name);
778   if (font == NULL)
779     {
780       fprintf (stderr, (char *)lstr.load_font_err, name);
781       font = XLoadQueryFont (display, "fixed");
782     }
783   return (font);
784 
785 } /* saveLoadQFont */
786 
787 
788 
789 #ifdef _NO_PROTO
create_set_font_list(w,font_name)790 void create_set_font_list(w, font_name)
791     Widget w;
792     char *font_name;
793 #else  /* ! _NO_PROTO */
794 
795 void create_set_font_list(Widget w, char *font_name)
796 #endif
797 {
798     register int ac;            /* arg count                */
799     Arg al[10];                 /* arg list                 */
800     XmFontList font_list;
801     font_list = XmFontListCreate((saveLoadQFont(font_name)), charset);
802     ac = 0;
803     XtSetArg(al[ac], XmNfontList, font_list); ac++;
804     XtSetValues(w, al, ac);
805     /* now we can free the font list because the widget had
806        copied it already using XmFontListCopy ...
807     */
808     XmFontListFree(font_list);
809 
810 }   /* create_set_font_list */
811 
812 
813 #ifdef _NO_PROTO
create_set2_font_list(w,w2,font_name)814 void create_set2_font_list(w, w2, font_name)
815     Widget w;
816     Widget w2;
817     char *font_name;
818 #else  /* ! _NO_PROTO */
819 
820 void create_set2_font_list(Widget w, Widget w2, char *font_name)
821 #endif
822 {
823     register int ac;            /* arg count                */
824     Arg al[10];                 /* arg list                 */
825     XmFontList font_list;
826     font_list = XmFontListCreate((saveLoadQFont(font_name)), charset);
827     ac = 0;
828     XtSetArg(al[ac], XmNfontList, font_list); ac++;
829     XtSetValues(w, al, ac);
830     XtSetValues(w2, al, ac);
831     /* now we can free the font list because the widget had
832        copied it already using XmFontListCopy ...
833     */
834     XmFontListFree(font_list);
835 
836 }   /* create_set2_font_list */
837 
838 
839 
840 #ifdef _NO_PROTO
asManageDialog(w)841 void asManageDialog(w)
842     Widget w;
843 #else  /* ! _NO_PROTO */
844 
845 void asManageDialog(Widget w)
846 #endif
847 {
848     /* use this procedure instead of XtManageChild when you would like to
849        raise the dialog to the top of the window stack even when the
850        dialog is already managed
851     */
852     Atom string_atom;           /* used to fix sun 8-bit problem */
853     register int ac;            /* arg count                */
854     Arg al[2];                 /* arg list                 */
855 
856 
857     if (XtIsManaged (w))
858 	XMapRaised (XtDisplay (w), XtWindow (XtParent(w)));
859     else
860 	XtManageChild (w);
861 
862 
863 }   /* asManageDialog */
864 
865 
866 
867 /*** L_tmpnam is defined in stdio.h on ANSI systems (but let's be sure...)
868      for the make_tmpnam following include files should be used: stdio.h,
869      stdlib.h, string.h
870 ***/
871 
872 #ifndef L_tmpnam
873 #define L_tmpnam 32
874 #endif
875 
876 
877 #ifdef _NO_PROTO
make_tmpnam()878 char *make_tmpnam ()
879 #else  /* ! _NO_PROTO */
880 
881 char *make_tmpnam (void)
882 #endif
883 {
884     char *tempname = (char *)XtMalloc (sizeof (char) * L_tmpnam);
885     char *tmpdir = NULL;
886 
887     tmpnam (tempname);		/* get the default temp name */
888 
889 
890     /* asedit temp file is created in a directory specified by
891        (listed by decreasing priority):
892        (i)   *tmpDir X resource (stored in lstr.tmpDir);
893        (ii)  TMPDIR environmental variable;
894        (iii) wide system default place (you get here where both the above
895 	     are NULL)
896     */
897 
898     tmpdir = (char *)lstr.tmpDir;
899     /*   check if lstr.tmpDir is NULL; if so check the TMPDIR environmet;
900 	 if one of them  is not NULL, use it & create a temp file name there */
901 
902     if(!tmpdir)
903     {
904 	tmpdir = getenv("TMPDIR");	/* we might get NULL here ... */
905     }
906 
907     if(!tmpdir)	return(tempname);	/* temp file in system default place */
908     else
909     {
910 	/* put the tempfile in the user specified place ...*/
911 	char *tmp;
912 	char *just_name = NULL;
913 	/*  Get just the name (without path)  (for DOS you should use '\')  */
914 	if (( just_name = strrchr(tempname, (int) '/')) == NULL)
915 		just_name = tempname;
916 	else
917 		just_name++;
918 
919 	tmp = (char *)XtMalloc (sizeof (char) * (strlen (tmpdir) +
920 					     strlen (just_name) + 2));
921 	if (tmpdir[strlen(tmpdir)-1] == '/')
922 	{
923 	    /* Trailing slash in temp directory */
924 	    sprintf (tmp, "%s%s", tmpdir, just_name);
925 	}
926 	else
927 	{
928 	    /* No trailing slash (so put it explicitly). */
929 	    sprintf (tmp, "%s/%s", tmpdir, just_name);
930 	}
931 
932 
933 	XtFree (tempname);
934 	return tmp;
935     }
936 
937 }   /* make_tmpnam */
938 
939 
940 #ifdef _NO_PROTO
empty_name(str)941 Boolean empty_name(str)
942    char *str;
943 #else  /* ! _NO_PROTO */
944 
945 Boolean empty_name(char *str)
946 #endif
947 {
948     int i, len;
949     Boolean res=True;
950 
951     if(str == NULL) return(res);
952     else
953     {
954 	/* check if the string has a zero length or consists of spaces only */
955 	len = strlen(str);
956 	if(len == 0) return(res);
957 
958 	for(i=0; i < len; i++)
959 	{
960 	    if(!isspace((int) ((unsigned char)str[i]) )) { res = False; break; }
961 	}
962     }
963     return(res);
964 
965 }   /* empty_name */
966 
967 
968 #ifdef _NO_PROTO
checkSyntax(argc,argv,program_name,introStr,syntaxStr)969 Boolean checkSyntax(argc, argv, program_name, introStr, syntaxStr)
970    unsigned int argc;
971    char *argv[];
972    char *program_name;
973    char *introStr;
974    char *syntaxStr;
975 #else  /* ! _NO_PROTO */
976 
977 Boolean checkSyntax(unsigned int argc, char *argv[], char *program_name,
978 		char *introStr, char *syntaxStr)
979 #endif
980 {
981     /* check the syntax of the command line (if all command
982        switches were properly processed);
983        if not show the syntax error message and return error code
984     */
985 
986     int i, ierr;
987     Boolean error=False;
988 
989     for (i=1; i < argc; i++)
990     {
991 	if(argv[i][0] == '-' || argv[i][0] == '=' || argv[i][0] == '+') { ierr= i; error= True; }
992     }
993 
994 
995     if(error)
996     {
997 	fprintf(stderr,"\n%s: ", program_name);
998 	if(strcmp(argv[ierr], "-help") != 0) fprintf(stderr, introStr, argv[ierr]);
999 	fprintf(stderr, syntaxStr);		/* print out the syntax */
1000     }
1001     return(error);
1002 
1003 } /* checkSyntax */
1004 
1005 
1006 
1007 #ifdef _NO_PROTO
checkCommandForOption(argc,argv,option)1008 Boolean checkCommandForOption(argc, argv, option)
1009    unsigned int argc;
1010    char *argv[];
1011    char *option;
1012 #else  /* ! _NO_PROTO */
1013 
1014 Boolean checkCommandForOption(unsigned int argc, char *argv[], char *option )
1015 #endif
1016 {
1017     /* check the syntax of the command line for the option;
1018        it is is there - return True;
1019     */
1020 
1021     int i, ierr;
1022     Boolean found=False;
1023 
1024     for (i=1; i < argc; i++)
1025     {
1026 	if(strcmp(argv[i], option)  == 0 ) { found= True;  break;}
1027     }
1028 
1029     return(found);
1030 
1031 } /* checkCommandForOption */
1032 
1033 
1034 #ifdef _NO_PROTO
disableRedisplay(win)1035 void disableRedisplay(win)
1036         aseditWindowStruct *win;
1037 #else  /* _NO_PROTO */
1038 void disableRedisplay(aseditWindowStruct *win)
1039 #endif
1040 {
1041     /* used in conjunction with enableRedisplay to prevent visual flashing
1042        when multiple updates of edit widget(s) occur
1043     */
1044 #if (XmVersion > 1001)
1045 #  define disableRedisplayScrolledText(stext) if(stext  && XtIsManaged(XtParent(stext)))       \
1046 	XmTextDisableRedisplay(stext);
1047 #else
1048 #  define disableRedisplayScrolledText(stext) if(stext  && XtIsManaged(XtParent(stext)))       \
1049 	_XmTextDisableRedisplay((XmTextWidget)stext, False);
1050 #endif /* Motif 1.2 */
1051 
1052     disableRedisplayScrolledText(win->edit_text);
1053 
1054 
1055 }   /* disableRedisplay */
1056 
1057 
1058 #ifdef _NO_PROTO
enableRedisplay(win)1059 void enableRedisplay(win)
1060         aseditWindowStruct *win;
1061 #else  /* _NO_PROTO */
1062 void enableRedisplay(aseditWindowStruct *win)
1063 #endif
1064 {
1065     /* used in conjunction with enableRedisplay to prevent visual flashing
1066        when multiple updates of edit widget(s) occur
1067     */
1068 
1069 #if (XmVersion > 1001)
1070 #   define enableRedisplayScrolledText(stext) if(stext  && XtIsManaged(XtParent(stext)))       \
1071 	XmTextEnableRedisplay(stext);
1072 #else
1073 #   define enableRedisplayScrolledText(stext) if(stext  && XtIsManaged(XtParent(stext)))       \
1074 	_XmTextEnableRedisplay((XmTextWidget)stext);
1075 #endif /* Motif 1.2 */
1076 
1077     enableRedisplayScrolledText(win->edit_text);
1078 
1079 
1080 }   /* enableRedisplay */
1081 
1082 #ifdef _NO_PROTO
getTextSubstring(w,start,num_chars)1083 char *getTextSubstring(w, start, num_chars)
1084     Widget w;
1085     XmTextPosition start;
1086     int num_chars;
1087 #else  /* _NO_PROTO */
1088 char *getTextSubstring(Widget w, XmTextPosition start, int num_chars)
1089 #endif
1090 {
1091     /* get the substring from the text widget; the calling procedure should
1092        free the allocated memory
1093     */
1094     int buffer_size, status;
1095     char *buffer=NULL;
1096     XmTextPosition last;
1097 
1098     if(start < 0) start = 0;		/* auto correction */
1099 
1100     last = XmTextGetLastPosition(w);
1101     if(start >= last ) return NULL;	/* sanity check */
1102 
1103     /* correct the num_chars if neccessary */
1104     if(start+num_chars > last) num_chars = last - start;
1105 
1106 
1107 #if (XmVersion >= 1002)
1108     /* use Motif 1.2 new GetSubstring routine (note we have to allocate memory for it) */
1109 
1110     buffer_size = (num_chars +1) * sizeof(char);	/* for multibyte characters use (num_chars * MB_CUR_MAX) + 1 */
1111     buffer = XtMalloc(buffer_size);
1112     status = XmTextGetSubstring(w, start, num_chars, buffer_size, buffer);
1113     if(status == XmCOPY_FAILED)
1114     {
1115 	/* return nothing */
1116 	XtFree(buffer);
1117 	buffer = NULL;
1118     }
1119 
1120 #   else
1121     /* use internal Motif routine (here Motif 1.0 might have been different, but
1122        I can't check it because none is available around any more; anyway I don't
1123        know anybody still using Motif 1.0 today, January 1994)
1124     */
1125 
1126     buffer = _XmStringSourceGetString((XmTextWidget)w, start, (XmTextPosition)(start+num_chars));
1127 
1128 #   endif /* Motif 1.2 */
1129 
1130     return buffer;
1131 
1132 }   /* getTextSubstring */
1133 
1134 
1135 #ifdef _NO_PROTO
checkRadioBoxSetting(w,deflt)1136 void checkRadioBoxSetting(w, deflt)
1137     Widget w;
1138     int deflt;
1139 #else  /* _NO_PROTO */
1140 void checkRadioBoxSetting(Widget w, int deflt)
1141 #endif
1142 {
1143         /* the default radio button is set via resources (since 1.32); check
1144            for a not unique setup (and correct it if needed); the correction is
1145            mainly implemented to use the 1.3 and 1.31 app-defs without any
1146            corrections;
1147         */
1148 
1149 	Arg                 al[3];          /*  arg list            */
1150 	register  int       ac = 0;         /*  arg count           */
1151 	WidgetList	buttons;	/* radio buttons */
1152         Cardinal	n;		/* number of buttons */
1153 	Boolean   	*state;
1154 	int 	  	i, counter=0;
1155 
1156 
1157 	/* make sure that the widget w is a subclass of RowColumn */
1158 	if(!XmIsRowColumn(w))
1159  	{
1160 	    fprintf(stderr, "Error: checkRadioBoxSetting requires RowColumn widget!\n");
1161 	    return;
1162 	}
1163 	ac = 0;
1164 	XtSetArg(al[ac], XmNchildren, &buttons);	ac++;
1165 	XtSetArg(al[ac], XmNnumChildren, &n);		ac++;
1166 
1167 	XtGetValues(w, al, ac);
1168 
1169 	if(n <= 0) return;		/* do nothing; no children */
1170 
1171 	/* allocate memory for the state array */
1172 	state = (Boolean *) XtMalloc(n * sizeof(Boolean));
1173 
1174 	/* get the state of all buttons */
1175 	ac = 0;
1176 	for (i=0; i < n; i++)
1177 	{
1178 	    XtSetArg(al[0], XmNset, &(state[i]));
1179 	    XtGetValues(buttons[i], al, 1);
1180 	}
1181 
1182 
1183 	/* count the number of buttons that are set to on; if it is different
1184 	   than one, the setup is wrong; set than the default button on
1185 	*/
1186 
1187 	for(i=0; i<n; i++) if(state[i]) counter++;
1188 
1189 
1190 	if(counter != 1)
1191 	{
1192 	    if(deflt < 0 || deflt >=n) deflt = 0;	/* correct the wrong default */
1193 	    for(i=0; i<n; i++)
1194 	    {
1195 		if(i == deflt) XtSetArg(al[0], XmNset, True);
1196 		else		 XtSetArg(al[0], XmNset, False);
1197 		XtSetValues(buttons[i], al, 1);
1198 	    }
1199 	}
1200 
1201 	XtFree((char *)state);
1202 
1203 
1204 } 	/* check RadioBoxSetting */
1205 
1206 
1207 /* extra addition for the NEXTSTEP (undert co-Xist) */
1208 
1209 #if defined (NeXT)
getcwd(char * pathname)1210 char *getcwd (char *pathname)
1211 {
1212   return (getwd(pathname));
1213 }
1214 #endif
1215 
1216