1 /* SCCS-info %W% %E% */
2 
3 /*--------------------------------------------------------------------*/
4 /*								      */
5 /*		VCG : Visualization of Compiler Graphs		      */
6 /*		--------------------------------------		      */
7 /*								      */
8 /*   file:	   X11devfs.c					      */
9 /*   version:	   1.00.00					      */
10 /*   creation:	   9.4.93					      */
11 /*   author:	   I. Lemke  (...-Version 0.99.99)		      */
12 /*		   G. Sander (Version 1.00.00-...)		      */
13 /*		   Universitaet des Saarlandes, 66041 Saarbruecken    */
14 /*		   ESPRIT Project #5399 Compare 		      */
15 /*   description:  Device driver for X11, File Selector Dialog Box    */
16 /*   status:	   in work					      */
17 /*								      */
18 /*--------------------------------------------------------------------*/
19 
20 #ifndef lint
21 static char *id_string="$Id: X11devfs.c,v 1.7 1995/02/09 20:44:22 sander Exp $";
22 #endif
23 
24 /*
25  *   Copyright (C) 1993-2005 Saarland University
26  *
27  *  This program and documentation is free software; you can redistribute
28  *  it under the terms of the  GNU General Public License as published by
29  *  the  Free Software Foundation;  either version 2  of the License,  or
30  *  (at your option) any later version.
31  *
32  *  This  program  is  distributed  in  the hope that it will be useful,
33  *  but  WITHOUT ANY WARRANTY;  without  even  the  implied  warranty of
34  *  MERCHANTABILITY  or  FITNESS  FOR  A  PARTICULAR  PURPOSE.  See  the
35  *  GNU General Public License for more details.
36  *
37  *  You  should  have  received a copy of the GNU General Public License
38  *  along  with  this  program;  if  not,  write  to  the  Free Software
39  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40  *
41  *  The software is available per anonymous ftp at ftp.cs.uni-sb.de.
42  *  Contact  sander@cs.uni-sb.de  for additional information.
43  */
44 
45 
46 /*
47  * $Log: X11devfs.c,v $
48  * Revision 1.7  1995/02/09  20:44:22  sander
49  * Call of getwd removed.
50  *
51  * Revision 1.6  1995/02/08  11:11:14  sander
52  * Distribution version 1.3.
53  *
54  * Revision 1.5  1994/12/23  18:12:45  sander
55  * Manhatten layout added.
56  * Option interface cleared.
57  * infobox behaviour improved.
58  * First version of fisheye (carthesian).
59  * Options Noedge and nonode.
60  * Titles in the node title box are now sorted.
61  *
62  * Revision 1.4  1994/11/23  14:50:47  sander
63  * Drawing speed improved by removing some superfluous XSyncs.
64  *
65  * Revision 1.3  1994/08/03  13:58:44  sander
66  * Horizontal order mechanism changed.
67  * Attribute horizontal_order for edges added.
68  *
69  * Revision 1.2  1994/06/07  14:09:59  sander
70  * Splines implemented.
71  * HP-UX, Linux, AIX, Sun-Os, IRIX compatibility tested.
72  * The tool is now ready to be distributed.
73  *
74  * Revision 1.1  1994/05/16  08:56:03  sander
75  * Initial revision
76  *
77  */
78 
79 /************************************************************************
80  * Device driver for X11: File Selector Dialog Box
81  * -----------------------------------------------
82  *
83  * This module contains the management of the dialog box that appears
84  * if we want to select a file.
85  *
86  * This file provides the following functions:
87  * ------------------------------------------
88  *
89  *    x11_init_fisel_dialog(rd,rs)      initialize the dialogbox.
90  *    x11_destroy_fisel_dialog(rd,rs)   destroys   the dialogbox.
91  *
92  *    x11_print_fisel_dialog()
93  *
94  *    This function opens the dialog box that allows to enter the
95  *    name of a file.
96  *
97  ************************************************************************/
98 
99 #include <stdio.h>
100 #include <stdlib.h>
101 #include <string.h>
102 #include "globals.h"
103 
104 #ifdef X11
105 
106 /*#include <X11/Xos.h>*/
107 #include <X11/Xlib.h>
108 #include <X11/Xutil.h>
109 #include <X11/cursorfont.h>
110 #include <X11/Xproto.h>
111 #include <ctype.h>
112 #ifdef VMS
113 #include <unixio.h>
114 #include <unixlib.h>
115 #include <processes.h>
116 #include <file.h>
117 #include <descrip.h>
118 #include <rmsdef.h>
119 #include <rms.h>
120 #include <types.h>
121 #include <ssdef.h>
122 #include <stat.h>
123 #define STAT stat
124 #else
125 #include <sys/types.h>
126 #include <sys/stat.h>
127 /*#include <sys/param.h> */
128 #include <dirent.h>
129 #include <grp.h>
130 #include <pwd.h>
131 #endif
132 #include <time.h>
133 #include <string.h>
134 #include <math.h>
135 #include "options.h"
136 #include "main.h"
137 #include "grammar.h"
138 #include "X11devfs.h"
139 
140 
141 /*--------------------------------------------------------------------*/
142 
143 #undef EVENT_DEBUG
144 
145 
146 /* Types
147  * =====
148  */
149 
150 /*   Selection points: On/Off-Buttons, Radio/Buttons, Touch Buttons
151  *   Radio-Buttons are On-buttons, i.e. they don't go off, if we retouch
152  *   them. Further, all radio buttons of one section have the same glob.
153  */
154 
155 typedef struct gs_selection_point {
156 	Window w;			/* Window of the point             */
157 	char   *t;			/* Text of the point               */
158 	int    x;			/* X-Position                      */
159 	int    y;			/* Y-Position                      */
160 	int    is;			/* actual value                    */
161 	int    sel;			/* value, if the point is selected */
162 	int    *glob;			/* corresponding global value      */
163 	char   key;			/* key action                      */
164 } GS_SEL_POINT;
165 
166 
167 /*  Horizontal integer scroll bars
168  */
169 
170 
171 typedef struct gs_scroll_bar {
172 	Window ws;			/* Window of the bar itself        */
173 	Window wt;			/* Window of the scroll thumb      */
174 	char   *t;			/* Text of the scroll bar          */
175 	char   *f;			/* Format of the value             */
176 	int    yt;			/* Y-Position of the text          */
177 	int    yv;			/* Y-Position of the value         */
178 	int    yb;			/* Y-Position of the bar           */
179 	int    x;			/* X-Position                      */
180 	int    len;			/* Length of scrollbar             */
181 	int    is;			/* actual value                    */
182 	int    *glob;			/* corresponding global value      */
183 #ifdef ANSI_C
184 	void   (*rf)(int);		/* read function		   */
185 	void   (*sf)(void);		/* set function		   	   */
186 #else
187 	void   (*rf)();
188 	void   (*sf)();
189 #endif
190 } GS_SCROLL_BAR;
191 
192 
193 
194 
195 /* Prototypes
196  * ==========
197  */
198 
199 void    gs_exit         _PP((int x));
200 void    do_gblExpose    _PP((XEvent *eventp));
201 void    do_gblConfigureNotify  _PP((XEvent *eventp));
202 
203 
204 static void   allocateDialogBox         _PP((void));
205 static Window allocate_selection_point  _PP((int x,int y));
206 static Window allocate_button		_PP((int x,int y));
207 static Window allocate_general_button   _PP((int x,int y,int w,int h));
208 static Window allocate_scroll_bar	_PP((int x,int y,int len));
209 
210 static void draw_dialog_box     _PP((void));
211 static void draw_text           _PP(( int x, int y, char *m));
212 static void draw_underl_text    _PP(( int x, int y, char *m));
213 static void draw_dialog_point   _PP((Window w, int color));
214 static void draw_sizes		_PP((void));
215 static void draw_textwin	_PP((void));
216 static void normalize_point     _PP((Window w));
217 
218 
219 #ifdef EVENT_DEBUG
220 static void prologue    _PP((XEvent *eventp, char *event_name));
221 #else
222 #define prologue(a,b)
223 #endif
224 
225 static void     dialog_main_loop        _PP((void));
226 static void     do_KeyPress             _PP((XEvent *eventp));
227 static void     do_ButtonPress          _PP((XEvent *eventp));
228 static void     do_ButtonRelease        _PP((XEvent *eventp));
229 static void     do_EnterNotify          _PP((XEvent *eventp));
230 static void     do_LeaveNotify          _PP((XEvent *eventp));
231 static void     do_Expose               _PP((XEvent *eventp));
232 static void     do_ConfigureNotify      _PP((XEvent *eventp));
233 static void     do_MotionNotify         _PP((XEvent *eventp));
234 
235 static void 	read_fisel_scrollbar	_PP((int val));
236 static void 	set_fisel_scrollbar	_PP((void));
237 
238 static int 	calc_dir_entries	_PP((void));
239 static void 	alloc_fnames		_PP((void));
240 static void 	rescan_fnames		_PP((void));
241 static int      compare_fnames		_PP((const int *a,const int *b));
242 static int      compare_finfos		_PP((const int *a,const int *b));
243 
244 
245 /* Positions and Sizes
246  * ===================
247  */
248 
249 /* Size of a normal point */
250 
251 #define POINT_W  10
252 
253 /* Size of a normal button */
254 
255 #define BUTTON_W   130
256 
257 /* Sizes of a scrollbar and its thumb */
258 
259 #define SCROLL_W  286
260 #define SCROLLBAR_LEN 20
261 
262 /* Sizes of the scroll window */
263 
264 #define SCROLLW_W  460
265 #define SCROLLW_H  SCROLL_W
266 
267 
268 /* Positions of the radio points */
269 
270 #define SEL_POS  SCROLLW_W+35
271 
272 /* Position of the input text */
273 
274 #define TEXT_POS 55+SCROLLW_H
275 
276 /* Size of the dialog box */
277 
278 #define DIAL_W   660
279 #define DIAL_H   TEXT_POS+30+10
280 
281 /* Size of the filename */
282 
283 #define FNAMESIZE 34
284 
285 /* Size of the infofield */
286 
287 #define INFOSIZE  16
288 
289 
290 /* Variables
291  * =========
292  */
293 
294 /* Dialog handling: On success (i.e. Okay-Button), success becomes 1 */
295 
296 static int dialog_notready = 1;
297 static int dialog_success  = 0;
298 
299 #ifndef MAXPATHLEN
300 #define MAXPATHLEN 1024
301 #endif
302 
303 static char act_fisel[256];
304 static char act_path[MAXPATHLEN];
305 static char act_fpath[MAXPATHLEN];
306 static int  act_selection = -1;
307 static int  old_selection = -1;
308 
309 /* Buffers for the file names and infos
310  */
311 
312 static int act_fbuf_size = 0;
313 static int max_fname     = 0;
314 static char *act_fnames  = NULL;
315 static char *act_infos   = NULL;
316 static int  *act_fsort   = NULL;
317 static char *act_dirtag  = NULL;
318 
319 
320 /*  Radio buttons are partitioned into those that have the same global
321  *  variable. If a radio-button is selected, all other radio buttons
322  *  of the same partition became unselected.
323  */
324 
325 static int sel_mode = 0;
326 static int sort_mode = 1;
327 static int presel_mode = 0;
328 
329 #define MAX_RADIO_POINTS 13
330 static GS_SEL_POINT radio_point[MAX_RADIO_POINTS] = {
331 
332 /* window,  text                 , xpos,      ypos, isval,  selval     , globvar   , key */
333 {  0     ,  "size"               , SEL_POS,     41,    0,      0       , &sel_mode , 's' },
334 {  0     ,  "mode"               , SEL_POS,     59,    0,      1       , &sel_mode , 'm' },
335 {  0     ,  "date"               , SEL_POS,     77,    0,      2       , &sel_mode , 'd' },
336 {  0     ,  "owner"              , SEL_POS,     95,    0,      3       , &sel_mode , 'o' },
337 {  0     ,  "group"              , SEL_POS,    113,    0,      4       , &sel_mode , 'g' },
338 {  0     ,  "unsorted"           , SEL_POS,    131,    0,      0       , &sort_mode, 'u' },
339 {  0     ,  "sorted by name"     , SEL_POS,    149,    0,      1       , &sort_mode, 'b' },
340 {  0     ,  "sorted by info"     , SEL_POS,    167,    0,      2       , &sort_mode, 'i' },
341 
342 {  0     ,  "all"                , SEL_POS+80,  41,    0,      0       , &presel_mode , 'a' },
343 {  0     ,  "*.vcg"              , SEL_POS+80,  59,    0,      1       , &presel_mode , 'v' },
344 {  0     ,  "*.ps"               , SEL_POS+80,  77,    0,      2       , &presel_mode , ' ' },
345 {  0     ,  "*.pbm"              , SEL_POS+80,  95,    0,      3       , &presel_mode , ' ' },
346 {  0     ,  "*.ppm"              , SEL_POS+80, 113,    0,      4       , &presel_mode , ' ' }
347 
348 };
349 
350 
351 /*  Horizontal integer scrollbars are used to change a value by the read and
352  *  set functions. Here, these values must be integer values.
353  */
354 
355 static int my_scroll_val = 0;
356 
357 #define MAX_VSCROLLBARS 1
358 
359 #ifdef ANSI_C
360 static GS_SCROLL_BAR vscrollbar[MAX_VSCROLLBARS] = {
361 
362     {  0, 0, "" ,"", 27 , 27, 27, SCROLLW_W+5, SCROLL_W,
363 		0, &my_scroll_val , &read_fisel_scrollbar, &set_fisel_scrollbar }
364 };
365 #else
366 static GS_SCROLL_BAR vscrollbar[MAX_VSCROLLBARS] = {
367 
368     {  0, 0, "" ,"", 27 , 27, 27, SCROLLW_W+5, SCROLL_W,
369 		0, &my_scroll_val , read_fisel_scrollbar, set_fisel_scrollbar }
370 };
371 #endif
372 
373 
374 /* Root displays */
375 
376 static Display *root_display;	/* Root display          */
377 static int      root_screen;	/* and its screen number */
378 
379 
380 /* Windows */
381 
382 static Window	dialog_window;
383 static Window	scroll_show_window;
384 static Window	text_window;
385 static Window	path_window;
386 
387 static Window   resc_button;
388 static Window   okay_button;
389 static Window   cancel_button;
390 static Window   next_button;
391 static Window   prev_button;
392 
393 
394 /* Cursors */
395 
396 static Cursor scrollCursor;
397 static Cursor pointCursor;
398 static Cursor busyCursor;
399 
400 /* Mouse Buttons */
401 
402 #define G_MOUSE_LEFT  1
403 #define G_MOUSE_RIGHT 3
404 
405 
406 /* the panel font */
407 
408 extern char Xfontname[512];
409 static  XFontStruct *dialog_font = NULL;
410 
411 /* Flag wheter the dialog_box is initialized */
412 
413 static int dialog_box_there = 0;
414 
415 
416 
417 /*--------------------------------------------------------------------*/
418 /*  Dialog box initialization and entry points                        */
419 /*--------------------------------------------------------------------*/
420 
421 /*  Initialize the dialog box
422  *  -------------------------
423  *  This is done once at the beginning.
424  */
425 
426 #ifdef ANSI_C
427 void 	x11_init_fisel_dialog(Display *rd, int rs)
428 #else
429 void 	x11_init_fisel_dialog(rd, rs)
430 Display *rd;
431 int rs;
432 #endif
433 {
434 	if (dialog_box_there) return;
435 	root_display = rd;
436 	root_screen  = rs;
437 	dialog_font = XLoadQueryFont(root_display,Xfontname);
438 	if (!dialog_font) {
439 		Fatal_error("Font not found. Please use option -font","");
440 	}
441 
442 	allocateDialogBox();
443 
444 	dialog_box_there = 1;
445 }
446 
447 
448 
449 /*   Destroy the dialog box
450  *   ----------------------
451  *   This is done once on ExitDevice.
452  */
453 
454 #ifdef ANSI_C
455 void	x11_destroy_fisel_dialog(Display *rd, int rs)
456 #else
457 void	x11_destroy_fisel_dialog(rd, rs)
458 Display *rd;
459 int rs;
460 #endif
461 {
462 	if (!dialog_box_there) return;
463 	XDestroyWindow(root_display,dialog_window);
464 	dialog_box_there = 0;
465 }
466 
467 
468 
469 /*   Allocate the Dialog Box
470  *   -----------------------
471  *   Scrollbar-Thumbs are returned in last_tmb;
472  */
473 
474 static Window last_tmb;
475 static char x11_win_label[1024];
476 
477 #ifdef ANSI_C
allocateDialogBox(void)478 static void allocateDialogBox(void)
479 #else
480 static void allocateDialogBox()
481 #endif
482 {
483 	Window rret1, rret2;
484 	XSetWindowAttributes attr;
485 	unsigned long mask = 0L;
486 	int i;
487 	unsigned int j;
488 	int xpos, ypos;
489 	XSizeHints hints;
490 
491 	/* select for all events */
492 	attr.event_mask = KeyPressMask           |
493 			  ButtonPressMask        | ButtonReleaseMask  |
494 			  EnterWindowMask        |
495                           ExposureMask           | StructureNotifyMask |
496                           SubstructureNotifyMask |
497                           FocusChangeMask        | OwnerGrabButtonMask;
498 
499 	attr.background_pixel = XWhitePixel(root_display,root_screen);
500 	attr.border_pixel = XBlackPixel(root_display,root_screen);
501 
502 	mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
503 
504 	(void)XQueryPointer(root_display,RootWindow(root_display, root_screen),
505 		&rret1, &rret2,&xpos, &ypos, &i, &i, &j);
506 
507         dialog_window = XCreateWindow(root_display,
508 				      RootWindow(root_display, root_screen),
509 				      xpos, ypos,
510                            	      DIAL_W, DIAL_H,
511 				      Xmyborderwidth, (int)CopyFromParent,
512                                       InputOutput,
513 				      (Visual *)CopyFromParent,
514                            	      mask, &attr);
515 
516 	hints.flags = PPosition;
517 	hints.x = xpos;
518 	hints.y = ypos;
519 
520         strcpy(x11_win_label, "VCG ");
521         strcat(x11_win_label, Dataname);
522         strcat(x11_win_label, " File");
523 
524 	XStoreName(root_display, dialog_window, x11_win_label);
525 	XSetNormalHints(root_display, dialog_window, &hints);
526 
527         path_window = XCreateWindow(root_display, dialog_window,
528 				      5, TEXT_POS-22,
529                            	      DIAL_W-10, 25,
530 				      1, (int)CopyFromParent,
531                                       InputOutput,
532 				      (Visual *)CopyFromParent,
533                            	      mask, &attr);
534 
535         text_window = XCreateWindow(root_display, dialog_window,
536 				      5, TEXT_POS-22+28,
537                            	      DIAL_W-10, 25,
538 				      1, (int)CopyFromParent,
539                                       InputOutput,
540 				      (Visual *)CopyFromParent,
541                            	      mask, &attr);
542 
543         scroll_show_window = XCreateWindow(root_display, dialog_window,
544 				      5, 27,
545                                       SCROLLW_W, SCROLLW_H,
546 				      1, (int)CopyFromParent,
547                                       InputOutput,
548 				      (Visual *)CopyFromParent,
549                            	      mask, &attr);
550 
551 	XDefineCursor(root_display,path_window,
552 			XCreateFontCursor(root_display,XC_xterm));
553 	XDefineCursor(root_display,text_window,
554 			XCreateFontCursor(root_display,XC_xterm));
555 	pointCursor = XCreateFontCursor(root_display,XC_left_ptr);
556 	busyCursor  = XCreateFontCursor(root_display,XC_watch);
557 	XDefineCursor(root_display,dialog_window,pointCursor);
558 
559 	scrollCursor = XCreateFontCursor(root_display,XC_sb_v_double_arrow);
560 
561 	for (i=0; i<MAX_RADIO_POINTS; i++)
562 		radio_point[i].w = allocate_selection_point(
563 					radio_point[i].x,
564 					radio_point[i].y-10);
565 
566 	for (i=0; i<MAX_VSCROLLBARS; i++) {
567 		vscrollbar[i].ws = allocate_scroll_bar(vscrollbar[i].x,
568 						       vscrollbar[i].yb,
569 						       vscrollbar[i].len);
570 		vscrollbar[i].wt = last_tmb;
571 	}
572 
573 
574 	resc_button   = allocate_button(SEL_POS,181+34);
575 	cancel_button = allocate_button(SEL_POS,181+34+35);
576 	okay_button   = allocate_button(SEL_POS,181+34+70);
577 	next_button   = allocate_general_button(SEL_POS,181,60,20);
578 	prev_button   = allocate_general_button(SEL_POS+70,181,60,20);
579 }
580 
581 
582 
583 /*  Allocate a selection point (button or radio button)
584  *  ---------------------------------------------------
585  */
586 
587 #ifdef ANSI_C
588 static Window allocate_selection_point(int x,int y)
589 #else
590 static Window allocate_selection_point(x,y)
591 int x, y;
592 #endif
593 {
594 	return(allocate_general_button(x,y,POINT_W,POINT_W));
595 }
596 
597 
598 
599 /*  Allocate an normal button
600  *  -------------------------
601  */
602 
603 #ifdef ANSI_C
604 static Window allocate_button(int x,int y)
605 #else
606 static Window allocate_button(x,y)
607 int x, y;
608 #endif
609 {
610 	return(allocate_general_button(x,y,BUTTON_W,25));
611 }
612 
613 
614 
615 /*  Allocate a general button or point
616  *  ----------------------------------
617  */
618 
619 #ifdef ANSI_C
620 static Window allocate_general_button(int x,int y,int w,int h)
621 #else
622 static Window allocate_general_button(x,y,w,h)
623 int x, y, w, h;
624 #endif
625 {
626 	Window ww;
627 	XSetWindowAttributes attr;
628 	unsigned long mask = 0L;
629 
630 	/* select for all events */
631 	attr.event_mask = KeyPressMask           |
632 			  ButtonPressMask        | ButtonReleaseMask   |
633 			  EnterWindowMask        | LeaveWindowMask     |
634                           ExposureMask           | StructureNotifyMask |
635                           SubstructureNotifyMask |
636                           FocusChangeMask        | OwnerGrabButtonMask;
637 
638 	attr.background_pixel = XWhitePixel(root_display,root_screen);
639 	attr.border_pixel = XBlackPixel(root_display,root_screen);
640 
641 	mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
642 
643 	ww = XCreateWindow(root_display,
644 			dialog_window,
645 			x,y,
646 			w,h,
647 			1, (int)CopyFromParent,
648 			InputOutput,
649 			(Visual *)CopyFromParent,
650 			mask, &attr);
651 
652 	return(ww);
653 }
654 
655 
656 /*  Allocate a scroll bar
657  *  ---------------------
658  */
659 
660 #ifdef ANSI_C
661 static Window allocate_scroll_bar(int x,int y,int len)
662 #else
663 static Window allocate_scroll_bar(x,y,len)
664 int x, y, len;
665 #endif
666 {
667 	Window w, wt;
668 	XSetWindowAttributes attr;
669 	unsigned long mask = 0L;
670 
671         /* select for all events */
672         attr.event_mask = KeyPressMask           | ButtonMotionMask   |
673                           ButtonPressMask        | ButtonReleaseMask  |
674                           EnterWindowMask        | LeaveWindowMask    |
675                           ExposureMask           | ResizeRedirectMask |
676                           SubstructureNotifyMask |
677                           FocusChangeMask        | OwnerGrabButtonMask;
678 
679         attr.background_pixel = XWhitePixel(root_display,root_screen);
680         attr.border_pixel = XBlackPixel(root_display,root_screen);
681 
682         mask |= (CWBackPixel | CWBorderPixel | CWEventMask);
683 
684         w = XCreateWindow (root_display, dialog_window, x,y,
685                            8, len,
686                            1, (int)CopyFromParent,
687                            InputOutput,
688                            (Visual *)CopyFromParent,
689                            mask, &attr);
690         wt = XCreateSimpleWindow (root_display, w, 0,0,
691                                     6, SCROLLBAR_LEN,
692                                     1,
693                                     XWhitePixel(root_display,root_screen),
694                                     XBlackPixel(root_display,root_screen));
695 
696 	XDefineCursor(root_display,w,scrollCursor);
697 
698 	last_tmb = wt;
699 	return(w);
700 }
701 
702 
703 /*--------------------------------------------------------------------*/
704 /*   Entry point for the dialog                                       */
705 /*--------------------------------------------------------------------*/
706 
707 static int box_exposed;
708 static int first_exposed = 1;
709 
710 #ifdef ANSI_C
x11_print_fisel_dialog(void)711 char *x11_print_fisel_dialog(void)
712 #else
713 char *x11_print_fisel_dialog()
714 #endif
715 {
716 	XEvent event;
717         int i, x, y;
718         Window rret1, rret2;
719         unsigned int j;
720 
721         if (first_exposed) {
722                 first_exposed = 0;
723                 (void)XQueryPointer(root_display,RootWindow(root_display, root_screen),
724                         &rret1, &rret2,&x, &y, &i, &i, &j);
725                 XMoveWindow(root_display,dialog_window, x, y);
726         }
727 
728 	old_selection = -1;
729 	act_fisel[0]  = 0;
730 	act_path[0]   = 0;
731 	act_fpath[0]  = 0;
732 	act_selection = 0;
733 	sel_mode = presel_mode = 0;
734 	for (i=0; i<MAX_RADIO_POINTS; i++)
735 		radio_point[i].is = *(radio_point[i].glob);
736         if (!getcwd(act_path,MAXPATHLEN-1)) act_path[0]=0;
737 	SPRINTF(act_fpath,"Enter path: %s_",act_path);
738 	vscrollbar[0].is = 0;
739 	rescan_fnames();
740 	SPRINTF(act_fpath,"Enter path: %s_",act_path);
741 
742 	my_scroll_val = sel_mode = presel_mode = 0;
743 	sort_mode = 1;
744 	box_exposed = 0;
745 
746         XMapRaised(root_display, dialog_window);
747         XMapRaised(root_display, scroll_show_window);
748         XMapRaised(root_display, path_window);
749         XMapRaised(root_display, text_window);
750 
751 	for (i=0; i<MAX_RADIO_POINTS; i++) {
752 		XMapRaised(root_display, radio_point[i].w);
753 		normalize_point(radio_point[i].w);
754 	}
755 	for (i=0; i<MAX_VSCROLLBARS; i++) {
756         	XMapRaised(root_display, vscrollbar[i].ws);
757         	XMapRaised(root_display, vscrollbar[i].wt);
758 	}
759 
760         XMapRaised(root_display, resc_button);
761         XMapRaised(root_display, okay_button);
762         XMapRaised(root_display, cancel_button);
763         XMapRaised(root_display, next_button);
764         XMapRaised(root_display, prev_button);
765 	normalize_point(resc_button);
766 	normalize_point(okay_button);
767 	normalize_point(cancel_button);
768 	normalize_point(next_button);
769 	normalize_point(prev_button);
770 
771 	for (i=0; i<MAX_VSCROLLBARS; i++) (*(vscrollbar[i].sf))();
772 
773         XFlush(root_display);
774 
775         /*
776          * Wait for Exposure event.
777          */
778 #ifndef ULTRIX
779 #ifndef AIX
780         do { XNextEvent(root_display, &event);
781         } while (event.type != Expose && event.type != MapNotify);
782 #endif
783 #endif
784 
785 	if (event.type == Expose) do_Expose(&event);
786 	dialog_main_loop();
787 
788         XUnmapWindow(root_display, dialog_window);
789 
790 	i=0;
791 	while ((act_fisel[i]) && (i<253)) i++;
792 	if (act_fisel[i-1]=='_') i--;
793 	act_fisel[i]=0;
794 	i=0;
795 	while ((act_fpath[i]) && (i<MAXPATHLEN-3)) i++;
796 	if (act_fpath[i-1]=='_') i--;
797 	act_fpath[i]=0;
798 
799 #ifdef VMS
800 	SPRINTF(act_path,"%s%s",&(act_fpath[12]), &(act_fisel[16]) );
801 #else
802 	SPRINTF(act_path,"%s/%s",&(act_fpath[12]), &(act_fisel[16]) );
803 #endif
804 	if (dialog_success)  return(act_path);
805 	else		     return(NULL);
806 }
807 
808 
809 
810 /*--------------------------------------------------------------------*/
811 /*   Redraw routine                                                   */
812 /*--------------------------------------------------------------------*/
813 
814 /*  Draw dialog box
815  *  ---------------
816  */
817 
818 #ifdef ANSI_C
draw_dialog_box(void)819 static void draw_dialog_box(void)
820 #else
821 static void draw_dialog_box()
822 #endif
823 {
824 	int i;
825 
826 	XSetForeground(root_display,
827 		XDefaultGC(root_display, root_screen),
828 		XWhitePixel(root_display, root_screen));
829 	XFillRectangle(root_display,
830 		(Drawable)dialog_window,
831 		XDefaultGC(root_display, root_screen),
832 		0,0, DIAL_W, DIAL_H);
833 
834 	XSetForeground(root_display,
835 		XDefaultGC(root_display, root_screen),
836 		XBlackPixel(root_display, root_screen));
837 
838 	i = XTextWidth(dialog_font,"Cancel (Esc)",strlen("Cancel (Esc)"));
839 	i = (BUTTON_W-i)/2;
840 	XDrawString(root_display,
841 		(Drawable)cancel_button,
842 		XDefaultGC(root_display, root_screen),
843 		i,18,"Cancel (Esc)",strlen("Cancel (Esc)"));
844 
845 	i = XTextWidth(dialog_font,"Okay",strlen("Okay"));
846 	i = (BUTTON_W-i)/2;
847 	XDrawString(root_display,
848 		(Drawable)okay_button,
849 		XDefaultGC(root_display, root_screen),
850 		i,18,"Okay",strlen("Okay"));
851 
852 	i = XTextWidth(dialog_font,"next",strlen("next"));
853 	i = (60-i)/2;
854 	XDrawString(root_display,
855 		(Drawable)next_button,
856 		XDefaultGC(root_display, root_screen),
857 		i,16,"next",strlen("next"));
858 
859 	i = XTextWidth(dialog_font,"prev.",strlen("prev."));
860 	i = (60-i)/2;
861 	XDrawString(root_display,
862 		(Drawable)prev_button,
863 		XDefaultGC(root_display, root_screen),
864 		i,16,"prev.",strlen("prev."));
865 
866 	i = XTextWidth(dialog_font,"Rescan",strlen("Rescan"));
867 	i = (BUTTON_W-i)/2;
868 	XDrawString(root_display,
869 		(Drawable)resc_button,
870 		XDefaultGC(root_display, root_screen),
871 		i,18,"Rescan",strlen("Rescan"));
872 
873 
874 	draw_underl_text(5,18,"Select a filename");
875 
876 	for (i=0; i<MAX_RADIO_POINTS; i++)
877 		draw_text(radio_point[i].x+20,radio_point[i].y,
878 			  radio_point[i].t);
879 
880 	/* for (i=0; i<MAX_VSCROLLBARS; i++)
881 	 * 	draw_text(vscrollbar[i].x, vscrollbar[i].yt, vscrollbar[i].t);
882 	 */
883 
884 	for (i=0; i<MAX_RADIO_POINTS; i++)
885 		if (radio_point[i].is == radio_point[i].sel)
886 			draw_dialog_point(radio_point[i].w,1);
887 		else    draw_dialog_point(radio_point[i].w,0);
888 
889 	XSetForeground(root_display,
890 		XDefaultGC(root_display, root_screen),
891 		XWhitePixel(root_display, root_screen));
892 	XFillRectangle(root_display,
893 		(Drawable)path_window,
894 		XDefaultGC(root_display, root_screen),
895 		0,0, DIAL_W, 25);
896 	XFillRectangle(root_display,
897 		(Drawable)text_window,
898 		XDefaultGC(root_display, root_screen),
899 		0,0, DIAL_W, 25);
900 	draw_sizes();
901 
902 	for (i=0; i<MAX_VSCROLLBARS; i++) (*(vscrollbar[i].sf))();
903 
904 	XSync(root_display, 0);
905 }
906 
907 
908 
909 #ifdef ANSI_C
draw_sizes(void)910 static void draw_sizes(void)
911 #else
912 static void draw_sizes()
913 #endif
914 {
915 	int i, k, yp;
916 	char *c1,*c2,*c3,isdir;
917 
918 	XSetForeground(root_display,
919 		XDefaultGC(root_display, root_screen),
920 		XWhitePixel(root_display, root_screen));
921 	XFillRectangle(root_display,
922 		(Drawable)scroll_show_window,
923 		XDefaultGC(root_display, root_screen),
924 		0,0, SCROLLW_W, SCROLLW_H);
925 
926 	k = vscrollbar[0].is;
927 
928 	yp = 18;
929 	if (vscrollbar[0].is>=max_fname+2) vscrollbar[0].is = max_fname+1;
930 	if (act_selection   >=max_fname+2) act_selection    = max_fname+1;
931 	if (vscrollbar[0].is<0) vscrollbar[0].is = 0;
932 	if (act_selection<0)    act_selection    = 0;
933 
934 	for (i=0; i<(SCROLLW_H/18+1); i++) {
935 
936 		if (k+i==0)      { c1 = ".";  c2 = c3 = ""; isdir = 0; }
937 		else if (k+i==1) { c1 = ".."; c2 = c3 = ""; isdir = 1; }
938 		else if (k+i-2<max_fname) {
939 		  	c1 = c3 = &(act_fnames[ act_fsort[k+i-2] * FNAMESIZE]);
940 			c2 = &(act_infos[  act_fsort[k+i-2] * INFOSIZE]);
941 			isdir = act_dirtag[act_fsort[k+i-2]];
942 		}
943 		else { c1 = c2 = c3 = ""; isdir = 0; }
944 
945 		XSetForeground(root_display,
946 			XDefaultGC(root_display, root_screen),
947 			XBlackPixel(root_display, root_screen));
948 		if (k+i==old_selection) {
949 			XDrawLine(root_display,(Drawable)scroll_show_window,
950                 		XDefaultGC(root_display, root_screen),
951                 		14,yp-16,SCROLLW_W-2,yp-16);
952 			XDrawLine(root_display,(Drawable)scroll_show_window,
953                 		XDefaultGC(root_display, root_screen),
954                 		14,yp+2 ,SCROLLW_W-2,yp+2);
955 			XDrawLine(root_display,(Drawable)scroll_show_window,
956                 		XDefaultGC(root_display, root_screen),
957                 		14,yp-16 ,14,yp+2);
958 			XDrawLine(root_display,(Drawable)scroll_show_window,
959                 		XDefaultGC(root_display, root_screen),
960                 		SCROLLW_W-1,yp-16,SCROLLW_W-2,yp-16);
961 		}
962 		if (k+i==act_selection) {
963 			XFillRectangle(root_display,
964 				(Drawable)scroll_show_window,
965 				XDefaultGC(root_display, root_screen),
966 				0,yp-16, SCROLLW_W, 19);
967 			XSetForeground(root_display,
968 				XDefaultGC(root_display, root_screen),
969 				XWhitePixel(root_display, root_screen));
970 
971 			if (isdir) {
972 				if (k+i==1) {
973 					c1 = act_path;
974 					while (*c1++);
975 					while (c1>act_path) {
976 #ifdef VMS
977 						if (*c1==']') break;
978 #else
979 						if (*c1=='/') break;
980 #endif
981 						c1--;
982 					}
983 					*c1 = 0;
984 				}
985 				else {
986 #ifdef VMS
987 					strcat(act_path,"]");
988 #else
989 					strcat(act_path,"/");
990 #endif
991 					strcat(act_path,c3);
992 				}
993 				SPRINTF(act_fpath,"Enter path: %s_",act_path);
994 				vscrollbar[0].is = 0;
995 				rescan_fnames();
996 				old_selection = -1;
997 				act_selection = 0;
998 				draw_sizes();
999 				return;
1000 			}
1001 
1002 			SPRINTF(act_fisel,"Enter filename: %s_",c3);
1003 			if (*c3) SPRINTF(act_fpath,"Enter path: %s_",act_path);
1004 
1005 			XFillRectangle(root_display,
1006 				(Drawable)text_window,
1007 				XDefaultGC(root_display, root_screen),
1008 				0, 0, DIAL_W, 25);
1009 			XFillRectangle(root_display,
1010 				(Drawable)path_window,
1011 				XDefaultGC(root_display, root_screen),
1012 				0, 0, DIAL_W, 25);
1013 		}
1014 
1015 		if (isdir || (i+k==0)) {
1016 			XDrawLine(root_display,(Drawable)scroll_show_window,
1017                 		XDefaultGC(root_display, root_screen),
1018                 		2,yp-10,10,yp-10);
1019 			XDrawLine(root_display,(Drawable)scroll_show_window,
1020                 		XDefaultGC(root_display, root_screen),
1021                 		2,yp,2,yp-10);
1022 			XDrawLine(root_display,(Drawable)scroll_show_window,
1023                 		XDefaultGC(root_display, root_screen),
1024                 		10,yp,10,yp-10);
1025 			XDrawLine(root_display,(Drawable)scroll_show_window,
1026                 		XDefaultGC(root_display, root_screen),
1027                 		2,yp,10,yp);
1028 		}
1029 
1030 		XDrawString(root_display,
1031 			(Drawable)scroll_show_window,
1032 			XDefaultGC(root_display, root_screen),
1033 			17,yp,c1,strlen(c1));
1034 		XDrawString(root_display,
1035 			(Drawable)scroll_show_window,
1036 			XDefaultGC(root_display, root_screen),
1037 			330,yp,c2,strlen(c2));
1038 		yp += 18;
1039 	}
1040 	draw_textwin();
1041 }
1042 
1043 
1044 #ifdef ANSI_C
draw_textwin(void)1045 static void draw_textwin(void)
1046 #else
1047 static void draw_textwin()
1048 #endif
1049 {
1050 	int i;
1051 
1052 	XSetForeground(root_display,
1053 		XDefaultGC(root_display, root_screen),
1054 		XWhitePixel(root_display, root_screen));
1055 	i=0;
1056 	while ((act_fisel[i]) && (i<253)) i++;
1057 	if (act_fisel[i-1]=='_') i--;
1058 	act_fisel[i]=0;
1059 	XFillRectangle(root_display,
1060 		(Drawable)text_window,
1061 		XDefaultGC(root_display, root_screen),
1062 		5+XTextWidth(dialog_font,act_fisel,strlen(act_fisel)),
1063 		0, DIAL_W, 25);
1064 	act_fisel[i]='_';
1065 	act_fisel[i+1]=0;
1066 
1067 	i=0;
1068 	while ((act_fpath[i]) && (i<MAXPATHLEN-3)) i++;
1069 	if (act_fpath[i-1]=='_') i--;
1070 	act_fpath[i]=0;
1071 	XFillRectangle(root_display,
1072 		(Drawable)path_window,
1073 		XDefaultGC(root_display, root_screen),
1074 		5+XTextWidth(dialog_font,act_fpath,strlen(act_fpath)),
1075 		0, DIAL_W, 25);
1076 	act_fpath[i]='_';
1077 	act_fpath[i+1]=0;
1078 
1079 	XSetForeground(root_display,
1080 		XDefaultGC(root_display, root_screen),
1081 		XBlackPixel(root_display, root_screen));
1082 	XDrawString(root_display,
1083 		(Drawable)text_window,
1084 		XDefaultGC(root_display, root_screen),
1085 		5,18,act_fisel,strlen(act_fisel));
1086 	XDrawString(root_display,
1087 		(Drawable)path_window,
1088 		XDefaultGC(root_display, root_screen),
1089 		5,18,act_fpath,strlen(act_fpath));
1090 	XSync(root_display, 0);
1091 }
1092 
1093 
1094 
1095 /*  Draw text m into the dialog box at position x, y
1096  *  ------------------------------------------------
1097  */
1098 
1099 #ifdef ANSI_C
1100 static void draw_text(int x,int y,char *m)
1101 #else
1102 static void draw_text(x,y, m)
1103 int x, y;
1104 char *m;
1105 #endif
1106 {
1107 	XSetForeground(root_display,
1108 		XDefaultGC(root_display, root_screen),
1109 		XBlackPixel(root_display, root_screen));
1110 	XDrawString(root_display,
1111 		(Drawable)dialog_window,
1112 		XDefaultGC(root_display, root_screen),
1113 		x,y,m,strlen(m));
1114 }
1115 
1116 
1117 /*  Draw underlined text m into the dialog box at position x, y
1118  *  -----------------------------------------------------------
1119  */
1120 
1121 #ifdef ANSI_C
1122 static void draw_underl_text(int x,int y,char *m)
1123 #else
1124 static void draw_underl_text(x,y, m)
1125 int x, y;
1126 char *m;
1127 #endif
1128 {
1129 	int len;
1130 
1131 	XSetForeground(root_display,
1132 		XDefaultGC(root_display, root_screen),
1133 		XBlackPixel(root_display, root_screen));
1134 	XDrawString(root_display,
1135 		(Drawable)dialog_window,
1136 		XDefaultGC(root_display, root_screen),
1137 		x,y,m,strlen(m));
1138 	len = XTextWidth(dialog_font,m,strlen(m));
1139 	XDrawLine(root_display,(Drawable)dialog_window,
1140                 XDefaultGC(root_display, root_screen),
1141                 x,y+2,x+len,y+2);
1142 }
1143 
1144 
1145 /*  Draw a dialog point in a color
1146  *  ------------------------------
1147  */
1148 
1149 #ifdef ANSI_C
1150 static void draw_dialog_point(Window w, int color)
1151 #else
1152 static void draw_dialog_point(w, color)
1153 Window w;
1154 int color;
1155 #endif
1156 {
1157 	if (color==0) {
1158 		XSetForeground(root_display,
1159 			XDefaultGC(root_display, root_screen),
1160 			XWhitePixel(root_display, root_screen));
1161 	}
1162 	else {
1163 		XSetForeground(root_display,
1164 			XDefaultGC(root_display, root_screen),
1165 			XBlackPixel(root_display, root_screen));
1166 	}
1167 	XFillRectangle(root_display,(Drawable)w,
1168 			XDefaultGC(root_display, root_screen),
1169 			1,1,
1170 			POINT_W-2,POINT_W-2);
1171 	/* XSync(root_display, 0); */
1172         XFlush(root_display);
1173 }
1174 
1175 
1176 /* Normalize a button or point
1177  * ---------------------------
1178  */
1179 
1180 #ifdef ANSI_C
1181 static void normalize_point(Window w)
1182 #else
1183 static void normalize_point(w)
1184 Window w;
1185 #endif
1186 {
1187         XWindowAttributes retWinAttr;
1188 
1189         if (!XGetWindowAttributes(root_display,w,&retWinAttr)) {
1190                 FPRINTF(stderr,"Can't get window attributes.");
1191                 gs_exit(1);
1192         }
1193         if (retWinAttr.border_width==3) {
1194                 XMoveWindow(root_display,w,
1195                         retWinAttr.x+2, retWinAttr.y+2);
1196         }
1197         XSetWindowBorderWidth(root_display, w, 1L);
1198 }
1199 
1200 
1201 
1202 /*--------------------------------------------------------------------*/
1203 /*  Event handling                                                    */
1204 /*--------------------------------------------------------------------*/
1205 
1206 /* The main loop for interaction
1207  * =============================
1208  */
1209 
1210 #ifdef ANSI_C
dialog_main_loop(void)1211 static void dialog_main_loop(void)
1212 #else
1213 static void dialog_main_loop()
1214 #endif
1215 {
1216 	XEvent event;
1217 
1218 	dialog_notready = 1;
1219 	dialog_success  = 0;
1220 	while (dialog_notready) {
1221 
1222 		XNextEvent (root_display, &event);
1223 
1224 		if (event.type != Expose)
1225 			box_exposed = 0;
1226 
1227 		switch (event.type) {
1228 	  	case KeyPress:
1229 	   		prologue (&event, "KeyPress");
1230 	    		do_KeyPress (&event);
1231 	    		break;
1232 	  	case ButtonPress:
1233 	    		prologue (&event, "ButtonPress");
1234 	    		do_ButtonPress (&event);
1235 	    		break;
1236 	  	case ButtonRelease:
1237 	    		prologue (&event, "ButtonRelease");
1238 	    		do_ButtonRelease (&event);
1239 	    		break;
1240 	  	case EnterNotify:
1241 	    		prologue (&event, "EnterNotify");
1242 			do_EnterNotify(&event);
1243 	    		break;
1244 	  	case LeaveNotify:
1245 	    		prologue (&event, "LeaveNotify");
1246 			do_LeaveNotify(&event);
1247 	    		break;
1248 	  	case FocusIn:
1249 	    		prologue (&event, "FocusIn");
1250 	    		break;
1251 	  	case FocusOut:
1252 	    		prologue (&event, "FocusOut");
1253 	    		break;
1254 	  	case Expose:
1255 	    		prologue (&event, "Expose");
1256 	    		do_Expose (&event);
1257 	    		break;
1258 	  	case ConfigureNotify:
1259 	    		prologue (&event, "ConfigureNotify");
1260 	    		do_ConfigureNotify (&event);
1261 	    		break;
1262 	  	case MotionNotify:
1263 	    		prologue (&event, "MotionNotify");
1264 			do_MotionNotify(&event);
1265 	    		break;
1266 	  	case GravityNotify:
1267 	  	case CirculateRequest:
1268 	  	case PropertyNotify:
1269 	  	case SelectionClear:
1270 	  	case SelectionRequest:
1271 	  	case SelectionNotify:
1272 	  	case ColormapNotify:
1273 	  	case ClientMessage:
1274 	  	case MappingNotify:
1275 	  	case CreateNotify:
1276 	  	case DestroyNotify:
1277 	  	case CirculateNotify:
1278 	  	case VisibilityNotify:
1279 	 	case KeyRelease:
1280 	  	case KeymapNotify:
1281 	  	case NoExpose:
1282 	  	case GraphicsExpose:
1283 	    		prologue (&event, "Unhandled");
1284 	    		break;
1285 		}
1286     	}
1287 }
1288 
1289 
1290 #ifdef EVENT_DEBUG
1291 
1292 /* For debugging only: Print event message
1293  * ---------------------------------------
1294  */
1295 
1296 #ifdef ANSI_C
1297 static void prologue (XEvent *eventp, char *event_name)
1298 #else
1299 static void prologue (eventp, event_name)
1300 XEvent *eventp;
1301 char *event_name;
1302 #endif
1303 {
1304 	XAnyEvent *e = (XAnyEvent *) eventp;
1305 
1306 	PRINTF ("\n%s event, serial %ld, synthetic %s, window 0x%lx,\n",
1307 	    event_name, e->serial, e->send_event ? "Yes" : "No", e->window);
1308 }
1309 
1310 #endif /* EVENT_DEBUG */
1311 
1312 
1313 
1314 /* Keypress Events
1315  * ---------------
1316  */
1317 
1318 #ifdef ANSI_C
1319 static void do_KeyPress (XEvent *eventp)
1320 #else
1321 static void do_KeyPress (eventp)
1322 XEvent *eventp;
1323 #endif
1324 {
1325     	XKeyEvent *e = (XKeyEvent *) eventp;
1326     	KeySym ks;
1327     	int nbytes, i, j;
1328     	char str[256+1];
1329 	char lk, uk;
1330 
1331     	nbytes = XLookupString (e, str, 256, &ks, NULL);
1332     	if (nbytes < 0) nbytes = 0;
1333     	if (nbytes > 256) nbytes = 256;
1334     	str[nbytes] = '\0';
1335 
1336 	if (ks==0xff54) { /* Down */
1337 		old_selection = -1;
1338 		if (vscrollbar[0].is<max_fname-1) vscrollbar[0].is++;
1339 		set_fisel_scrollbar();
1340 		draw_sizes();
1341 		return;
1342 	}
1343 	else if (ks==0xff53) { /* Right */
1344 		old_selection = -1;
1345 		if (vscrollbar[0].is<max_fname-1) vscrollbar[0].is++;
1346 		set_fisel_scrollbar();
1347 		draw_sizes();
1348 		return;
1349 	}
1350 	else if (ks==0xff52) { /* Up */
1351 		old_selection = -1;
1352 		if (vscrollbar[0].is>0) vscrollbar[0].is--;
1353 		set_fisel_scrollbar();
1354 		draw_sizes();
1355 		return;
1356 	}
1357 	else if (ks==0xff51) { /* Left */
1358 		old_selection = -1;
1359 		if (vscrollbar[0].is>0) vscrollbar[0].is--;
1360 		set_fisel_scrollbar();
1361 		draw_sizes();
1362 		return;
1363 	}
1364 
1365 	if (nbytes==1) {
1366 
1367 		if (e->window == path_window) {
1368 			old_selection = -1;
1369 			act_selection = 0;
1370 			i = 0;
1371 			while ((act_fpath[i]) && (i<MAXPATHLEN-3)) i++;
1372 			if (act_fpath[i-1]=='_') i--;
1373 			act_fpath[i]=0;
1374 			XSetForeground(root_display,
1375 				XDefaultGC(root_display, root_screen),
1376 				XWhitePixel(root_display, root_screen));
1377 			XFillRectangle(root_display,
1378 				(Drawable)path_window,
1379 				XDefaultGC(root_display, root_screen),
1380 				5+XTextWidth(dialog_font,act_fpath,strlen(act_fpath)),
1381 				0, DIAL_W, 25);
1382 			if ((ks==0xff08)||(ks==0xffff)) {
1383 				i--;
1384 				if (i<12) i=12;
1385 				act_fpath[i]=0;
1386 			}
1387 			else if ((ks==0xff0a)||(ks==0xff0d)) {
1388 				dialog_notready = 0;
1389 				dialog_success  = 1;
1390 			}
1391 			else if (str[0]==27) {
1392 				dialog_notready = 0;
1393 				dialog_success  = 0;
1394 			}
1395 			else { 	/* assert((i<=MAXPATHLEN-3)); */
1396 				act_fpath[i]  = str[0];
1397 				act_fpath[i+1]= 0;
1398 			}
1399 			act_fpath[MAXPATHLEN-1] = 0;
1400 			draw_textwin();
1401 			return;
1402 		}
1403 		else if (e->window == text_window) {
1404 			old_selection = -1;
1405 			act_selection = 0;
1406 			i = 0;
1407 			while ((act_fisel[i]) && (i<253)) i++;
1408 			if (act_fisel[i-1]=='_') i--;
1409 			act_fisel[i]=0;
1410 			XSetForeground(root_display,
1411 				XDefaultGC(root_display, root_screen),
1412 				XWhitePixel(root_display, root_screen));
1413 			XFillRectangle(root_display,
1414 				(Drawable)text_window,
1415 				XDefaultGC(root_display, root_screen),
1416 				5+XTextWidth(dialog_font,act_fisel,strlen(act_fisel)),
1417 				0, DIAL_W, 25);
1418 			if ((ks==0xff08)||(ks==0xffff)) {
1419 				i--;
1420 				if (i<16) i=16;
1421 				act_fisel[i]=0;
1422 			}
1423 			else if ((ks==0xff0a)||(ks==0xff0d)) {
1424 				dialog_notready = 0;
1425 				dialog_success  = 1;
1426 			}
1427 			else if (str[0]==27) {
1428 				dialog_notready = 0;
1429 				dialog_success  = 0;
1430 			}
1431 			else { 	/* assert((i<=253)); */
1432 				act_fisel[i]  = str[0];
1433 				act_fisel[i+1]= 0;
1434 			}
1435 			act_fisel[255] = 0;
1436 			draw_textwin();
1437 			return;
1438 		}
1439 
1440 		/* No operation on ' ' */
1441 		if (str[0]==' ') return;
1442 
1443                	for (i=0; i<MAX_RADIO_POINTS; i++) {
1444                         lk = uk = radio_point[i].key;
1445                         lk = tolower(lk);
1446                         uk = toupper(uk);
1447                         if ((lk==str[0])||(uk==str[0])) {
1448                                 radio_point[i].is = radio_point[i].sel;
1449                                 break;
1450                         }
1451                 }
1452 
1453                 if (i<MAX_RADIO_POINTS) {
1454                         for (j=0; j<MAX_RADIO_POINTS; j++) {
1455                                 if ((i!=j) && (radio_point[i].glob==radio_point[j].glob))
1456                                         radio_point[j].is = radio_point[j].sel-1
1457 ;
1458                         }
1459 			draw_dialog_box();
1460 			rescan_fnames();
1461 			draw_dialog_box();
1462 			old_selection = -1;
1463 			return;
1464                 }
1465 
1466 		switch (str[0]) {
1467 		case '_' :
1468 		case '-' :
1469 		case 'p' :
1470 		case 'P' :
1471 			if (vscrollbar[0].is>0) vscrollbar[0].is--;
1472 			set_fisel_scrollbar();
1473 			old_selection = -1;
1474 			draw_sizes();
1475 			return;
1476 		case '*' :
1477 		case '+' :
1478 		case 'n' :
1479 		case 'N' :
1480 			if (vscrollbar[0].is<max_fname-1) vscrollbar[0].is++;
1481 			set_fisel_scrollbar();
1482 			old_selection = -1;
1483 			draw_sizes();
1484 			return;
1485 		case 'r' :
1486 		case 'R' :
1487 			vscrollbar[0].is = 0;
1488 			rescan_fnames();
1489 			act_selection = 0;
1490 			draw_sizes();
1491 			old_selection = -1;
1492 			return;
1493 		case '\r': /* Carriage Return */
1494 		case '\n': /* Carriage Return */
1495 			dialog_notready = 0;
1496 			dialog_success  = 1;
1497 			return;
1498 		case 27: /* Cancel */
1499 			dialog_notready = 0;
1500 			dialog_success  = 0;
1501 			return;
1502 		}
1503 		draw_dialog_box();
1504 	}
1505 }
1506 
1507 
1508 
1509 
1510 /* Button Press
1511  * ------------
1512  */
1513 
1514 static Window act_scroll_window = 0;
1515 
1516 #ifdef ANSI_C
1517 static void do_ButtonPress (XEvent *eventp)
1518 #else
1519 static void do_ButtonPress (eventp)
1520 XEvent *eventp;
1521 #endif
1522 {
1523 	XButtonEvent *e = (XButtonEvent *) eventp;
1524 	Window w;
1525 	int i,j;
1526 
1527 	w = e->window;
1528 
1529 	act_scroll_window = w;
1530 
1531 	for (i=0; i<MAX_RADIO_POINTS; i++) {
1532 		if (w == radio_point[i].w) {
1533 			radio_point[i].is = radio_point[i].sel;
1534 			break;
1535 		}
1536 	}
1537 
1538 	if (i<MAX_RADIO_POINTS) {
1539 		for (j=0; j<MAX_RADIO_POINTS; j++) {
1540 			if ((i!=j) && (radio_point[i].glob==radio_point[j].glob))
1541 				radio_point[j].is = radio_point[j].sel-1;
1542 		}
1543 		draw_dialog_point(radio_point[i].w,1);
1544 		rescan_fnames();
1545 		draw_sizes();
1546 		old_selection = -1;
1547 	}
1548 
1549 	for (i=0; i<MAX_RADIO_POINTS; i++)
1550 		if (radio_point[i].is == radio_point[i].sel)
1551 			draw_dialog_point(radio_point[i].w,1);
1552 		else    draw_dialog_point(radio_point[i].w,0);
1553 
1554 
1555 	for (i=0; i<MAX_VSCROLLBARS; i++) {
1556 		if (act_scroll_window==vscrollbar[i].ws) {
1557 		 	(*(vscrollbar[i].rf))(e->y);
1558 			draw_sizes();
1559 			old_selection = -1;
1560 		}
1561 	}
1562 
1563 	if (w==okay_button) {
1564 		dialog_notready = 0;
1565 		dialog_success  = 1;
1566 	}
1567 	else if (w==cancel_button) {
1568 		dialog_notready = 0;
1569 		dialog_success  = 0;
1570 	}
1571 	else if (w==resc_button) {
1572 		vscrollbar[0].is = 0;
1573 		rescan_fnames();
1574 		act_selection = 0;
1575 		draw_sizes();
1576 		old_selection = -1;
1577 	}
1578 	else if (w==next_button) {
1579 		if (vscrollbar[0].is<max_fname-1) vscrollbar[0].is++;
1580 		set_fisel_scrollbar();
1581 		draw_sizes();
1582 		old_selection = -1;
1583 	}
1584 	else if (w==prev_button) {
1585 		if (vscrollbar[0].is>0) vscrollbar[0].is--;
1586 		set_fisel_scrollbar();
1587 		draw_sizes();
1588 		old_selection = -1;
1589 	}
1590 	else if (w==scroll_show_window) {
1591 		if (old_selection == vscrollbar[0].is + (e->y)/18)
1592 			act_selection = vscrollbar[0].is + (e->y)/18;
1593 		old_selection = vscrollbar[0].is + (e->y)/18;
1594 		draw_sizes();
1595 	}
1596 }
1597 
1598 
1599 
1600 /* Button Release
1601  * --------------
1602  */
1603 
1604 #ifdef ANSI_C
1605 static void do_ButtonRelease (XEvent *eventp)
1606 #else
1607 static void do_ButtonRelease (eventp)
1608 XEvent *eventp;
1609 #endif
1610 {
1611 	XButtonEvent *e = (XButtonEvent *) eventp;
1612 	int i;
1613 
1614 	if (act_scroll_window && (e->window!=act_scroll_window)) {
1615 		for (i=0; i<MAX_VSCROLLBARS; i++) (*(vscrollbar[i].sf))();
1616 		draw_dialog_box();
1617 		act_scroll_window = 0;
1618 		return;
1619 	}
1620 
1621 	for (i=0; i<MAX_VSCROLLBARS; i++) {
1622 		if (act_scroll_window==vscrollbar[i].ws) {
1623 		 	(*(vscrollbar[i].rf))(e->y);
1624 			break;
1625 		}
1626 	}
1627 	if (i<MAX_VSCROLLBARS) draw_sizes();
1628 	act_scroll_window = 0;
1629 }
1630 
1631 
1632 
1633 /* Mark a selection point as selectable
1634  * ------------------------------------
1635  */
1636 
1637 #ifdef ANSI_C
1638 static void do_EnterNotify (XEvent *eventp)
1639 #else
1640 static void do_EnterNotify (eventp)
1641 XEvent *eventp;
1642 #endif
1643 {
1644     	XCrossingEvent *e = (XCrossingEvent *) eventp;
1645 	Window w;
1646 	XWindowAttributes retWinAttr;
1647 	int i, is_point;
1648 
1649 	is_point = 0;
1650 	w = e->window;
1651 
1652 	for (i=0; i<MAX_RADIO_POINTS; i++)
1653 		if (w==radio_point[i].w) is_point = 1;
1654 
1655 	if (  (w==okay_button)||(w==cancel_button)||(w==resc_button)
1656 	    ||(w==next_button)||(w==prev_button))   is_point = 1;
1657 
1658 	if (is_point) {
1659 	        if (!XGetWindowAttributes(root_display,w,&retWinAttr)) {
1660                		FPRINTF(stderr,"Can't get window attributes.");
1661                 	gs_exit(1);
1662         	}
1663 		if (retWinAttr.border_width==1) {
1664 			XMoveWindow(root_display,w,
1665 				retWinAttr.x-2, retWinAttr.y-2);
1666 		}
1667 		XSetWindowBorderWidth(root_display, w, 3L);
1668 	}
1669 }
1670 
1671 
1672 /* Unmark a selection point
1673  * ------------------------
1674  * The menupoint is not anymore selected.
1675  */
1676 
1677 #ifdef ANSI_C
1678 static void do_LeaveNotify (XEvent *eventp)
1679 #else
1680 static void do_LeaveNotify (eventp)
1681 XEvent *eventp;
1682 #endif
1683 {
1684     	XCrossingEvent *e = (XCrossingEvent *) eventp;
1685 	Window w;
1686 	int i, is_point;
1687 
1688 	is_point = 0;
1689 	w = e->window;
1690 
1691 	for (i=0; i<MAX_RADIO_POINTS; i++)
1692 		if (w==radio_point[i].w) is_point = 1;
1693 
1694 	if (  (w==okay_button)||(w==cancel_button)||(w==resc_button)
1695 	    ||(w==next_button)||(w==prev_button))   is_point = 1;
1696 
1697 	if (is_point) normalize_point(w);
1698 }
1699 
1700 
1701 /* Expose a window
1702  * ---------------
1703  */
1704 
1705 #ifdef ANSI_C
1706 static void do_Expose (XEvent *eventp)
1707 #else
1708 static void do_Expose (eventp)
1709 XEvent *eventp;
1710 #endif
1711 {
1712 	XExposeEvent *e = (XExposeEvent *) eventp;
1713 
1714 	if (e->window==dialog_window) {
1715 		if ((e->width>12)&&(e->height>12)&&(!box_exposed)) {
1716 			draw_dialog_box();
1717 			box_exposed = 1;
1718 		}
1719 	}
1720 	else box_exposed = 0;
1721 	old_selection = -1;
1722 	do_gblExpose(eventp);
1723 }
1724 
1725 
1726 /* Resize or move a window
1727  * -----------------------
1728  */
1729 
1730 #ifdef ANSI_C
1731 static void do_ConfigureNotify (XEvent *eventp)
1732 #else
1733 static void do_ConfigureNotify (eventp)
1734 XEvent *eventp;
1735 #endif
1736 {
1737 	XConfigureEvent *e = (XConfigureEvent *) eventp;
1738 
1739 	if (e->window==dialog_window) {
1740 		XResizeWindow(root_display,dialog_window,DIAL_W,DIAL_H);
1741 		draw_dialog_box();
1742 	}
1743         else do_gblConfigureNotify(eventp);
1744 
1745 	old_selection = -1;
1746 }
1747 
1748 
1749 /* Motion with pressed button
1750  * --------------------------
1751  */
1752 
1753 #ifdef ANSI_C
1754 static void do_MotionNotify (XEvent *eventp)
1755 #else
1756 static void do_MotionNotify (eventp)
1757 XEvent *eventp;
1758 #endif
1759 {
1760 	int i;
1761 
1762 	XMotionEvent *e = (XMotionEvent *) eventp;
1763 
1764 	for (i=0; i<MAX_VSCROLLBARS; i++) {
1765 		if (act_scroll_window==vscrollbar[i].ws) {
1766 		 	(*(vscrollbar[i].rf))(e->y);
1767 			break;
1768 		}
1769 	}
1770 	if (i<MAX_VSCROLLBARS) draw_sizes();
1771 	old_selection = -1;
1772 }
1773 
1774 
1775 /*--------------------------------------------------------------------*/
1776 /*  Scrollbar handling 						      */
1777 /*--------------------------------------------------------------------*/
1778 
1779 
1780 #ifdef ANSI_C
1781 static void read_fisel_scrollbar(int val)
1782 #else
1783 static void read_fisel_scrollbar(val)
1784 int val;
1785 #endif
1786 {
1787 	if (val<0) val = 0;
1788 	if (val+SCROLLBAR_LEN >= vscrollbar[0].len)
1789 		val = vscrollbar[0].len - SCROLLBAR_LEN;
1790 	XMoveResizeWindow(root_display,vscrollbar[0].wt,0,val,6,SCROLLBAR_LEN);
1791 	vscrollbar[0].is = (2+max_fname)*val/(vscrollbar[0].len-SCROLLBAR_LEN);
1792 }
1793 
1794 
1795 #ifdef ANSI_C
set_fisel_scrollbar(void)1796 static void set_fisel_scrollbar(void)
1797 #else
1798 static void set_fisel_scrollbar()
1799 #endif
1800 {
1801 	int val;
1802 
1803 	val =  (vscrollbar[0].is)*(vscrollbar[0].len-SCROLLBAR_LEN)/
1804 		(2+max_fname);
1805 	if (val<0) val = 0;
1806 	if (val+SCROLLBAR_LEN >= vscrollbar[0].len)
1807 		val = vscrollbar[0].len - SCROLLBAR_LEN;
1808 	XMoveResizeWindow(root_display, vscrollbar[0].wt,0,val,6,SCROLLBAR_LEN);
1809 }
1810 
1811 
1812 /*--------------------------------------------------------------------*/
1813 /*  Directory handling 						      */
1814 /*--------------------------------------------------------------------*/
1815 
1816 /* Calculate the number of entries of a directory
1817  * ----------------------------------------------
1818  */
1819 
1820 #ifdef ANSI_C
calc_dir_entries(void)1821 static int calc_dir_entries(void)
1822 #else
1823 static int calc_dir_entries()
1824 #endif
1825 {
1826 #ifdef VMS
1827 static 	char dirp[MAXPATHLEN];
1828 static 	char specif[255];
1829 	long context=0;
1830 	$DESCRIPTOR(lib_spec,specif);
1831 	$DESCRIPTOR(lib_result,dirp);
1832 #else
1833 	DIR *dirp;
1834 	struct dirent *dp;
1835 #endif
1836 	int result;
1837 	char *c;
1838 	struct stat file_stat;
1839 
1840 	result = 0;
1841 #ifdef VMS
1842 	if (act_path[0]) SPRINTF(specif,"%s*.*;*",act_path);
1843 	else SPRINTF(specif,"[]*.*;*");
1844 #else
1845 	if (act_path[0]) dirp = opendir(act_path);
1846 	else dirp = opendir(".");
1847 	if (!dirp) return(0);
1848 #endif
1849 
1850 #ifdef VMS
1851 	while (lib$find_file(&lib_spec,&lib_result,&context) != RMS$_NMF) {
1852 		if (!stat(dirp,&file_stat)) {
1853 			if( ((file_stat.st_mode)&S_IFMT) == S_IFDIR ) {
1854 				result++;
1855 				continue;
1856 			}
1857 		}
1858 		c = dirp;
1859 		while (*c) c++;
1860 		while ((c>(dirp)) && (*c!=';')) c--;
1861 		*c='\0';
1862 		while ((c>(dirp)) && (*c!='.')) c--;
1863 #else
1864 	while ((dp = readdir(dirp))!=NULL) {
1865 		if (dp->d_name[0]!='.') {
1866 			SPRINTF(act_fpath,"%s/%s",act_path,dp->d_name);
1867 			if (!stat(act_fpath,&file_stat)) {
1868 				if (S_ISDIR(file_stat.st_mode)) {
1869 					result++;
1870 					continue;
1871 				}
1872 			}
1873 			c = dp->d_name;
1874 			while (*c) c++;
1875 			while ((c>(dp->d_name)) && (*c!='.')) c--;
1876 #endif
1877 			switch (presel_mode) {
1878 			case 0: result++;
1879 				break;
1880 			case 1: if (strcmp(c,".vcg")==0) result++;
1881 			        if (strcmp(c,".VCG")==0) result++;
1882 				break;
1883 			case 2: if (strcmp(c,".ps")==0) result++;
1884 			        if (strcmp(c,".PS")==0) result++;
1885 				break;
1886 			case 3: if (strcmp(c,".pbm")==0) result++;
1887 			        if (strcmp(c,".PBM")==0) result++;
1888 				break;
1889 			case 4: if (strcmp(c,".ppm")==0) result++;
1890 			        if (strcmp(c,".PPM")==0) result++;
1891 				break;
1892 			}
1893 #ifndef VMS
1894 		}
1895 #endif
1896 	}
1897 #ifdef VMS
1898 	lib$find_file_end(&context);
1899 #else
1900 	(void)closedir(dirp);
1901 #endif
1902 	return(result);
1903 }
1904 
1905 
1906 /* Allocate filename array and info field array
1907  * --------------------------------------------
1908  */
1909 
1910 #ifdef ANSI_C
1911 static void alloc_fnames(void)
1912 #else
1913 static void alloc_fnames()
1914 #endif
1915 {
1916 	int newsize,i;
1917 
1918 	newsize = calc_dir_entries();
1919 	max_fname = newsize;
1920 	newsize = newsize + 2;
1921 
1922 	if (newsize>act_fbuf_size) {
1923 		if (act_fnames) free(act_fnames);
1924 		if (act_infos ) free(act_infos );
1925 		if (act_fsort ) free(act_fsort );
1926 		if (act_dirtag) free(act_dirtag);
1927 		act_fbuf_size = newsize;
1928 		act_fnames = (char *)malloc(FNAMESIZE*newsize);
1929 		act_infos  = (char *)malloc(INFOSIZE *newsize);
1930 		act_fsort  = (int *)malloc(sizeof(int)*newsize);
1931 		act_dirtag = (char*)malloc(sizeof(char)*newsize);
1932 		if (!act_fnames) Fatal_error("memory exhausted","");
1933 		if (!act_infos ) Fatal_error("memory exhausted","");
1934 		if (!act_fsort ) Fatal_error("memory exhausted","");
1935 		if (!act_dirtag) Fatal_error("memory exhausted","");
1936 	}
1937 
1938 	for (i=0; i<newsize; i++) {
1939 		act_fnames[i*FNAMESIZE]=0;
1940 		act_infos[i*INFOSIZE]  =0;
1941 		act_fsort[i]  = i;
1942 		act_dirtag[i] = 0;
1943 	}
1944 }
1945 
1946 
1947 /* Fill the filename array and info field array
1948  * --------------------------------------------
1949  */
1950 
1951 #ifdef ANSI_C
1952 static void rescan_fnames(void)
1953 #else
1954 static void rescan_fnames()
1955 #endif
1956 {
1957 #ifdef VMS
1958 static 	char dirp[MAXPATHLEN];
1959 static 	char specif[255];
1960 	long context = 0;
1961 	$DESCRIPTOR(lib_spec,specif);
1962 	$DESCRIPTOR(lib_result,dirp);
1963 	char d_name[MAXPATHLEN];
1964 #else
1965 	DIR *dirp;
1966 	struct dirent *dp;
1967 #endif
1968 	int i,j,month,is_okay;
1969 	struct stat   file_stat;
1970 	struct group  *gid_stat = 0;
1971 	struct passwd *uid_stat = 0;
1972 	char *c = 0;
1973 
1974 	XDefineCursor(root_display,dialog_window,busyCursor);
1975 	XSync(root_display, 0);
1976         XFlush(root_display);
1977 
1978 	i = 0;
1979 	while ((act_fpath[i]) && (i<MAXPATHLEN-3)) i++;
1980 	if (act_fpath[i-1]=='_') i--;
1981 #ifndef VMS
1982 	if (act_fpath[i-1]=='/') i--;
1983 #endif
1984 	act_fpath[i]=0;
1985 	SPRINTF(act_path,"%s",&(act_fpath[12]));
1986 
1987 	/* Initialize presel_mode, sel_mode and sort_mode */
1988 	for (i=0; i<MAX_RADIO_POINTS; i++)
1989 		if (radio_point[i].is == radio_point[i].sel)
1990 			*(radio_point[i].glob) = radio_point[i].is;
1991 
1992 	/* Allocate memory to contain the directory */
1993 	alloc_fnames();
1994 
1995 #ifdef VMS
1996 	if (act_path[0]) SPRINTF(specif,"%s*.*;*",act_path);
1997 	else SPRINTF(specif,"[]*.*;*");
1998 #else
1999 	if (act_path[0]) dirp = opendir(act_path);
2000 	else dirp = opendir(".");
2001 	if (!dirp) {
2002 		XDefineCursor(root_display,dialog_window,pointCursor);
2003 		return;
2004 	}
2005 #endif
2006 
2007 	i = 0;
2008 #ifdef VMS
2009 	while (lib$find_file(&lib_spec,&lib_result,&context) != RMS$_NMF) {
2010 		if (!stat(dirp,&file_stat)) {
2011 			is_okay = 0;
2012 			if( ((file_stat.st_mode)&S_IFMT)==S_IFDIR ) is_okay = 1;
2013 			c = dirp;
2014 			while ( (*c) && (*c!=']') ) c++;
2015 			c++;
2016 			strcpy(d_name,c);
2017 			while (*c) c++;
2018 			while ((c>(dirp)) && (*c!='.')) c--;
2019 #else
2020 	while ((dp = readdir(dirp))!=NULL) {
2021 		if (dp->d_name[0]=='.') continue;
2022 		SPRINTF(act_fpath,"%s/%s",act_path,dp->d_name);
2023 		if (!stat(act_fpath,&file_stat)) {
2024 			is_okay = 0;
2025 			if (S_ISDIR(file_stat.st_mode)) is_okay = 1;
2026 			c = dp->d_name;
2027 			while (*c) c++;
2028 			while ((c>(dp->d_name)) && (*c!='.')) c--;
2029 #endif
2030 			switch (presel_mode) {
2031 			case 0: is_okay = 1; break;
2032 			case 1: if (strncmp(c,".vcg",4)==0) is_okay = 1;
2033 			        if (strncmp(c,".VCG",4)==0) is_okay = 1;
2034 				break;
2035 			case 2: if (strncmp(c,".ps",4)==0)  is_okay = 1;
2036 			        if (strncmp(c,".PS",4)==0)  is_okay = 1;
2037 				break;
2038 			case 3: if (strncmp(c,".pbm",4)==0) is_okay = 1;
2039 			        if (strncmp(c,".PBM",4)==0) is_okay = 1;
2040 				break;
2041 			case 4: if (strncmp(c,".ppm",4)==0) is_okay = 1;
2042 			        if (strncmp(c,".PPM",4)==0) is_okay = 1;
2043 				break;
2044 			}
2045 			if (!is_okay) continue;
2046 			for (j=0; j<FNAMESIZE; j++) {
2047 #ifdef VMS
2048 				act_fnames[i*FNAMESIZE+j] = d_name[j];
2049 				if (d_name[j]==0) break;
2050 #else
2051 				act_fnames[i*FNAMESIZE+j] = dp->d_name[j];
2052 				if (dp->d_name[j]==0) break;
2053 #endif
2054 			}
2055 
2056 #ifdef VMS
2057 			if (((file_stat.st_mode)&S_IFMT)==S_IFDIR)
2058 				act_dirtag[i] = 1;
2059 #else
2060 			if (S_ISDIR(file_stat.st_mode)) act_dirtag[i] = 1;
2061 #endif
2062 			switch (sel_mode) {
2063 			case 0: /* size  */
2064 				SPRINTF(&(act_infos[i*INFOSIZE]),"%12d",file_stat.st_size);
2065 
2066 
2067 				break;
2068 			case 1: /* mode  */
2069 #ifdef VMS
2070 				if( ((file_stat.st_mode)&S_IFMT)==S_IFDIR )
2071 				     act_infos[i* INFOSIZE]='d';
2072 				else act_infos[i* INFOSIZE]='-';
2073 				if ((file_stat.st_mode)&S_IREAD)
2074 				     act_infos[i* INFOSIZE+1]='r';
2075 				else act_infos[i* INFOSIZE+1]='-';
2076 				if ((file_stat.st_mode)&S_IWRITE)
2077 			  	     act_infos[i* INFOSIZE+2]='w';
2078 				else act_infos[i* INFOSIZE+2]='-';
2079 				if ((file_stat.st_mode)&S_IEXEC)
2080 				     act_infos[i* INFOSIZE+3]='e';
2081 				else act_infos[i* INFOSIZE+3]='-';
2082 				act_infos[i* INFOSIZE+4]=0;
2083 #else
2084 				if (S_ISDIR(file_stat.st_mode)) act_infos[i* INFOSIZE]='d';
2085 				else act_infos[i* INFOSIZE]='-';
2086 				if ((file_stat.st_mode)&S_IRUSR) act_infos[i* INFOSIZE+1]='r';
2087 				else act_infos[i* INFOSIZE+1]='-';
2088 				if ((file_stat.st_mode)&S_IWUSR) act_infos[i* INFOSIZE+2]='w';
2089 				else act_infos[i* INFOSIZE+2]='-';
2090 				if ((file_stat.st_mode)&S_IXUSR) act_infos[i* INFOSIZE+3]='x';
2091 				else act_infos[i* INFOSIZE+3]='-';
2092 				if ((file_stat.st_mode)&S_IRGRP) act_infos[i* INFOSIZE+4]='r';
2093 				else act_infos[i* INFOSIZE+4]='-';
2094 				if ((file_stat.st_mode)&S_IWGRP) act_infos[i* INFOSIZE+5]='w';
2095 				else act_infos[i* INFOSIZE+5]='-';
2096 				if ((file_stat.st_mode)&S_IXGRP) act_infos[i* INFOSIZE+6]='x';
2097 				else act_infos[i* INFOSIZE+6]='-';
2098 				if ((file_stat.st_mode)&S_IROTH) act_infos[i* INFOSIZE+7]='r';
2099 				else act_infos[i* INFOSIZE+7]='-';
2100 				if ((file_stat.st_mode)&S_IWOTH) act_infos[i* INFOSIZE+8]='w';
2101 				else act_infos[i* INFOSIZE+8]='-';
2102 				if ((file_stat.st_mode)&S_IXOTH) act_infos[i* INFOSIZE+9]='x';
2103 				else act_infos[i* INFOSIZE+9]='-';
2104 				act_infos[i* INFOSIZE+10] = 0;
2105 #endif
2106 				break;
2107 			case 2: /* date  */
2108 				SPRINTF(act_fpath,"%s",
2109 #ifdef VMS
2110 					ctime(&(file_stat.st_ctime)));
2111 #else
2112 					asctime(gmtime(&(file_stat.st_ctime))));
2113 #endif
2114 				act_fpath[7]=0;
2115 				act_fpath[10]=0;
2116 				act_fpath[16]=0;
2117 				act_fpath[24]=0;
2118 				if (act_fpath[8]==' ') act_fpath[8]='0';
2119 				month = 0;
2120 				if (strcmp(&(act_fpath[4]),"Jan")==0) month=1;
2121 				if (strcmp(&(act_fpath[4]),"Feb")==0) month=2;
2122 				if (strcmp(&(act_fpath[4]),"Mar")==0) month=3;
2123 				if (strcmp(&(act_fpath[4]),"Apr")==0) month=4;
2124 				if (strcmp(&(act_fpath[4]),"May")==0) month=5;
2125 				if (strcmp(&(act_fpath[4]),"Jun")==0) month=6;
2126 				if (strcmp(&(act_fpath[4]),"Jul")==0) month=7;
2127 				if (strcmp(&(act_fpath[4]),"Aug")==0) month=8;
2128 				if (strcmp(&(act_fpath[4]),"Sep")==0) month=9;
2129 				if (strcmp(&(act_fpath[4]),"Oct")==0) month=10;
2130 				if (strcmp(&(act_fpath[4]),"Nov")==0) month=11;
2131 				if (strcmp(&(act_fpath[4]),"Dec")==0) month=12;
2132 				SPRINTF(&(act_infos[i*INFOSIZE]),
2133 					"%s/%2.2d/%s %s",
2134 					&(act_fpath[22]),
2135 					month,
2136 					&(act_fpath[8]),
2137 					&(act_fpath[11]));
2138 				break;
2139 			case 3: /* owner */
2140 #ifndef VMS
2141 				uid_stat = getpwuid(file_stat.st_uid);
2142 				if (uid_stat)
2143 					SPRINTF(&(act_infos[i*INFOSIZE]),
2144 						"%s",uid_stat->pw_name);
2145 				else
2146 #endif
2147 					SPRINTF(&(act_infos[i*INFOSIZE]),
2148 						"%12d",file_stat.st_uid);
2149 				break;
2150 			case 4: /* group */
2151 #ifndef VMS
2152 				gid_stat = getgrgid(file_stat.st_gid);
2153 
2154 				if (gid_stat)
2155 					SPRINTF(&(act_infos[i*INFOSIZE]),
2156 						"%s",gid_stat->gr_name);
2157 				else
2158 #endif
2159 					SPRINTF(&(act_infos[i*INFOSIZE]),
2160 						"%12d",file_stat.st_gid);
2161 				break;
2162 			}
2163 			i++;
2164 			act_fnames[i*FNAMESIZE-1] = 0;
2165 			act_infos[i*INFOSIZE-1]  = 0;
2166 			if (i>max_fname) break;
2167 		}
2168 	}
2169 #ifdef VMS
2170 	lib$find_file_end(&context);
2171 #else
2172 	(void)closedir(dirp);
2173 #endif
2174 
2175 	/* Sort the entries in act_fsort */
2176 	switch (sort_mode) {
2177 	case 0: break;
2178 	case 1:
2179 #ifdef ANSI_C
2180         	qsort(act_fsort,max_fname,sizeof(int),
2181                 	(int (*) (const void *, const void *))compare_fnames);
2182 #else
2183         	qsort(act_fsort,max_fname,sizeof(int), compare_fnames);
2184 #endif
2185 		break;
2186 	case 2:
2187 #ifdef ANSI_C
2188         	qsort(act_fsort,max_fname,sizeof(int),
2189                 	(int (*) (const void *, const void *))compare_finfos);
2190 #else
2191         	qsort(act_fsort,max_fname,sizeof(int), compare_finfos);
2192 #endif
2193 		break;
2194 	}
2195 	set_fisel_scrollbar();
2196 	SPRINTF(act_fpath,"Enter path: %s_",act_path);
2197 	XDefineCursor(root_display,dialog_window,pointCursor);
2198 	XSync(root_display, 0);
2199         XFlush(root_display);
2200 }
2201 
2202 
2203 /*  Compare function for sorting according filenames
2204  *  -------------------------------------------------
2205  */
2206 
2207 #ifdef ANSI_C
2208 static int      compare_fnames(const int *a,const int *b)
2209 #else
2210 static int      compare_fnames(a,b)
2211 int   *a;
2212 int   *b;
2213 #endif
2214 {
2215 	return(strcmp(	&(act_fnames[*a*FNAMESIZE]),
2216 			&(act_fnames[*b*FNAMESIZE])));
2217 }
2218 
2219 
2220 /*  Compare function for sorting according fileinfos
2221  *  ------------------------------------------------
2222  */
2223 
2224 #ifdef ANSI_C
2225 static int      compare_finfos(const int *a,const int *b)
2226 #else
2227 static int      compare_finfos(a,b)
2228 int   *a;
2229 int   *b;
2230 #endif
2231 {
2232 	return(strcmp(	&(act_infos[*a*INFOSIZE]),
2233 			&(act_infos[*b*INFOSIZE])));
2234 }
2235 
2236 
2237 
2238 /*--------------------------------------------------------------------*/
2239 
2240 #endif /* X11 */
2241 
2242