File: txt_incl.c

package info (click to toggle)
xview 3.2p1.4-28.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 26,680 kB
  • ctags: 34,403
  • sloc: ansic: 241,397; yacc: 1,435; sh: 1,086; makefile: 148; lex: 76; perl: 54; asm: 50; cpp: 15
file content (498 lines) | stat: -rw-r--r-- 14,978 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#ifndef lint
#ifdef sccs
static char     sccsid[] = "@(#)txt_incl.c 1.35 93/06/28";
#endif
#endif

/*
 *	(c) Copyright 1989 Sun Microsystems, Inc. Sun design patents 
 *	pending in the U.S. and foreign countries. See LEGAL NOTICE 
 *	file for terms of the license.
 */

/*
 * Text include popup frame creation and support.
 */

#include <xview_private/primal.h>
#include <xview_private/txt_impl.h>
#include <xview_private/ev_impl.h>
#include <sys/time.h>
#include <signal.h>
#include <xview/notice.h>
#include <xview/frame.h>
#include <xview/panel.h>
#include <xview/textsw.h>
#include <xview/openmenu.h>
#include <xview/wmgr.h>
#include <xview/pixwin.h>
#include <xview/win_struct.h>
#include <xview/win_screen.h>
#include <xview/file_chsr.h>

#if defined(SVR4) || defined(__linux__)
#include <unistd.h>
#include <string.h>
#endif /* SVR4 */

#define		MAX_DISPLAY_LENGTH	50
#define   	MAX_STR_LENGTH		1024

#define HELP_INFO(s) XV_HELP_DATA, s,

typedef enum {
    FILE_CMD_ITEM = 0,
    DIR_STRING_ITEM = 1,
    FILE_STRING_ITEM = 2,
}               File_panel_item_enum;

Pkg_private Panel_item include_panel_items[];
Pkg_private Textsw_view_handle text_view_frm_p_itm();
Pkg_private Xv_Window frame_from_panel_item();


static int
do_include_proc(folio, ie)
    Textsw_folio    folio;
    Event          *ie;
{
    CHAR           *file_str, *dir_str;
    register int    locx, locy;
    CHAR            curr_dir[MAX_STR_LENGTH];
#ifdef OW_I18N
    char            curr_dir_mb[MAX_STR_LENGTH];
#endif
    Frame           popup_frame;
    Frame           frame;
    Xv_Notice       text_notice;
    int		    textsw_changed_directory;

#ifdef OW_I18N
    dir_str = (CHAR *) xv_get(include_panel_items[(int) DIR_STRING_ITEM],
			      PANEL_VALUE_WCS);
    file_str = (CHAR *) xv_get(include_panel_items[(int) FILE_STRING_ITEM],
			       PANEL_VALUE_WCS);
#else
    dir_str = (char *) xv_get(include_panel_items[(int) DIR_STRING_ITEM],
			      PANEL_VALUE);
    file_str = (char *) xv_get(include_panel_items[(int) FILE_STRING_ITEM],
			       PANEL_VALUE);
#endif

    if AN_ERROR
	(ie == 0)
	    locx = locy = 0;
    else {
	locx = ie->ie_locx;
	locy = ie->ie_locy;
    }
#ifdef OW_I18N
    if (textsw_expand_filename(folio, dir_str, MAX_STR_LENGTH, locx, locy)) {
	/* error handled inside routine */
	return TRUE;
    }
    if (textsw_expand_filename(folio, file_str, MAX_STR_LENGTH, locx, locy)) {
	/* error handled inside routine */
	return TRUE;
    }
#else
    if (textsw_expand_filename(folio, dir_str, locx, locy)) {
	/* error handled inside routine */
	return TRUE;
    }
    if (textsw_expand_filename(folio, file_str, locx, locy)) {
	/* error handled inside routine */
	return TRUE;
    }
#endif

    /* if "cd" is not disabled and the "cd" dir is not the current dir */
#ifdef OW_I18N
#if defined(SVR4) || defined(__linux__)
    (void) getcwd(curr_dir_mb, MAX_STR_LENGTH);
#else
    (void) getwd(curr_dir_mb);
#endif /* SVR4 */
    (void) mbstowcs(curr_dir, curr_dir_mb, MAX_STR_LENGTH);
#else /* OW_I18N */
#if defined(SVR4) || defined(__linux__)
    (void) getcwd(curr_dir, MAX_STR_LENGTH);
#else
    (void) getwd(curr_dir);
#endif /* SVR4 */
#endif /* OW_I18N */

    textsw_changed_directory = FALSE;
    if (STRCMP(curr_dir, dir_str) != 0) {
	if (!(folio->state & TXTSW_NO_CD)) {
	    if (textsw_change_directory(folio, dir_str, FALSE, locx, locy) != 0)
		return TRUE;
	    else
	    /*
	    * kludge to prevent including file from changing
	    * your directory too.
	    */
		textsw_changed_directory = TRUE;
	} else {
	    frame = (Frame)FRAME_FROM_FOLIO_OR_VIEW(folio);
            text_notice = (Xv_Notice)xv_get(frame, 
                                        XV_KEY_DATA, text_notice_key, NULL);
            if (!text_notice)  {
                text_notice = xv_create(frame, NOTICE,
                                    NOTICE_LOCK_SCREEN, FALSE,
			  	    NOTICE_BLOCK_THREAD, TRUE,
                                    NOTICE_MESSAGE_STRINGS,
				    XV_MSG("Cannot change directory.\n\
Change Directory Has Been Disabled."),
                                    0,
                                    NOTICE_BUTTON_YES, 
					XV_MSG("Continue"),
                                    XV_SHOW, TRUE,
                                    0);

                xv_set(frame, 
                        XV_KEY_DATA, text_notice_key, text_notice,
                        NULL);
            }
            else  {
                xv_set(text_notice, 
                        NOTICE_LOCK_SCREEN, FALSE,
			NOTICE_BLOCK_THREAD, TRUE,
                        NOTICE_MESSAGE_STRINGS,
		        XV_MSG("Cannot change directory.\n\
Change Directory Has Been Disabled."),
                        0,
                        NOTICE_BUTTON_YES, 
				XV_MSG("Continue"),
                        XV_SHOW, TRUE, 
                        NULL);
            }
	    return TRUE;
	}
    }
    if ((int)STRLEN(file_str) > 0) {
	if (textsw_file_stuff_from_str(VIEW_FROM_FOLIO_OR_VIEW(folio),
				       file_str, locx, locy) == 0) {
	    popup_frame =
		frame_from_panel_item(include_panel_items[(int) FILE_CMD_ITEM]);
	    (void) xv_set(popup_frame, XV_SHOW, FALSE, 0);
	    if (textsw_changed_directory)
	        textsw_change_directory(folio, curr_dir, FALSE, locx, locy);
	    return FALSE;
	}
	if (textsw_changed_directory)
	    textsw_change_directory(folio, curr_dir, FALSE, locx, locy);
	return TRUE;
    }

    frame = (Frame)FRAME_FROM_FOLIO_OR_VIEW(folio);
    text_notice = (Xv_Notice)xv_get(frame, XV_KEY_DATA, text_notice_key, NULL);
    if (!text_notice)  {
        text_notice = xv_create(frame, NOTICE,
                            NOTICE_LOCK_SCREEN, FALSE,
			    NOTICE_BLOCK_THREAD, TRUE,
                            NOTICE_MESSAGE_STRINGS,
			    XV_MSG("No file name was specified.\n\
Specify a file name to Include File."),
                            0,
                            NOTICE_BUTTON_YES, 
				XV_MSG("Continue"),
                            XV_SHOW, TRUE,
                            0);

        xv_set(frame, 
            XV_KEY_DATA, text_notice_key, text_notice,
            NULL);
    }
    else  {
        xv_set(text_notice, 
            NOTICE_LOCK_SCREEN, FALSE,
	    NOTICE_BLOCK_THREAD, TRUE,
            NOTICE_MESSAGE_STRINGS,
	    XV_MSG("No file name was specified.\n\
Specify a file name to Include File."),
            0,
            NOTICE_BUTTON_YES, XV_MSG("Continue"),
            XV_SHOW, TRUE, 
            NULL);
    }   
    if (textsw_changed_directory)
        textsw_change_directory(folio, curr_dir, FALSE, locx, locy);
    /* if we made it here then there was an error or notice */
    return TRUE;
}

static          Panel_setting
old_include_cmd_proc(item, event)
    Panel_item      item;
    Event          *event;
{
    Textsw_view_handle view = text_view_frm_p_itm(item);
    Textsw_folio    folio = FOLIO_FOR_VIEW(view);
    int             error;

    if (item == include_panel_items[(int) FILE_CMD_ITEM]) {
	error = do_include_proc(folio, event);
	if (error) {
	    xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, 0);
	}
	return PANEL_NONE;
    }
    return PANEL_NEXT;
}

static          Panel_setting
include_cmd_proc_accel(item, event)
    Panel_item      item;
    Event          *event;
{
    Textsw_view_handle view = text_view_frm_p_itm(item);
    Textsw_folio    folio = FOLIO_FOR_VIEW(view);
    int             error;

    if (item == include_panel_items[(int) FILE_STRING_ITEM]) {
	error = do_include_proc(folio, event);
	if (error) {
	    xv_set(item, PANEL_NOTIFY_STATUS, XV_ERROR, 0);
	}
	return PANEL_NONE;
    }
    return PANEL_NEXT;
}
static void
create_include_items(panel, view)
    Panel           panel;
    Textsw_view_handle view;
{

    CHAR            include_string[MAX_STR_LENGTH];
    char            current_dir_include_string[MAX_STR_LENGTH];
    int             dummy;

    include_string[0] = NULL;
    (void) textsw_get_selection(view, &dummy, &dummy, include_string,
				MAX_STR_LENGTH);
#if defined(SVR4) || defined(__linux__)
 (void) getcwd(current_dir_include_string, MAX_STR_LENGTH);
#else
  (void) getwd(current_dir_include_string);
#endif /* SVR4 */
    include_panel_items[(int) DIR_STRING_ITEM] =
	panel_create_item(panel, PANEL_TEXT,
			  PANEL_LABEL_X, ATTR_COL(0),
			  PANEL_LABEL_Y, ATTR_ROW(0),
			  PANEL_VALUE_DISPLAY_LENGTH, MAX_DISPLAY_LENGTH,
			  PANEL_VALUE_STORED_LENGTH, MAX_STR_LENGTH,
			  PANEL_VALUE, current_dir_include_string,
			  PANEL_LABEL_STRING, 
				XV_MSG("Directory:"),
			  HELP_INFO("textsw:dirstring")
			  0);
    include_panel_items[(int) FILE_STRING_ITEM] =
	panel_create_item(panel, PANEL_TEXT,
			  PANEL_LABEL_X, ATTR_COL(5),
			  PANEL_LABEL_Y, ATTR_ROW(1),
			  PANEL_VALUE_DISPLAY_LENGTH, MAX_DISPLAY_LENGTH,
			  PANEL_VALUE_STORED_LENGTH, MAX_STR_LENGTH,
#ifdef OW_I18N
			  PANEL_VALUE_WCS, include_string,
#else
			  PANEL_VALUE, include_string,
#endif
			  PANEL_LABEL_STRING, 
				XV_MSG("File:"),
			  PANEL_NOTIFY_LEVEL, PANEL_SPECIFIED,
			  PANEL_NOTIFY_STRING, "\n\r",
			  PANEL_NOTIFY_PROC, include_cmd_proc_accel,
			  HELP_INFO("textsw:includestring")
			  0);
    xv_set(panel, PANEL_CARET_ITEM,
	   include_panel_items[(int) FILE_STRING_ITEM], 0);

    include_panel_items[(int) FILE_CMD_ITEM] =
	panel_create_item(panel, PANEL_BUTTON,
			  PANEL_LABEL_X, ATTR_COL(26),
			  PANEL_LABEL_Y, ATTR_ROW(2),
			  PANEL_LABEL_STRING, 
				XV_MSG("Include File"),
			  PANEL_NOTIFY_PROC, old_include_cmd_proc,
			  HELP_INFO("textsw:includefile")
			  0);
    (void) xv_set(panel,
	       PANEL_DEFAULT_ITEM, include_panel_items[(int) FILE_CMD_ITEM],
		  0);
}

Pkg_private          Panel
textsw_create_include_panel(frame, view)
    Frame           frame;
    Textsw_view_handle view;
{
    Panel           panel;

    panel = (Panel) xv_get(frame, FRAME_CMD_PANEL,
			   HELP_INFO("textsw:includepanel")
			   0);
    (void) create_include_items(panel, view);

    return (panel);
}

int
include_cmd_proc(fc,path,file,client_data)
    Frame             fc;
    CHAR             *path;
    CHAR             *file;
    Xv_opaque         client_data;
 {

    Textsw_view_handle view = (Textsw_view_handle)window_get(fc,WIN_CLIENT_DATA,0);
    Textsw_folio       folio = FOLIO_FOR_VIEW(view);
    int                error;
    Textsw          textsw = FOLIO_REP_TO_ABS(folio);
    CHAR           *dir_str;
    register int    locx, locy;
    CHAR            curr_dir[MAX_STR_LENGTH];
#ifdef OW_I18N
    char            curr_dir_mb[MAX_STR_LENGTH];
#endif
    Frame           popup_frame;
    Frame           frame;
    Xv_Notice       text_notice;
    int		    textsw_changed_directory;

#ifdef OW_I18N
    dir_str = (CHAR *) xv_get(fc,FILE_CHOOSER_DIRECTORY_WCS) ;
#else
    dir_str = (char *) xv_get(fc, FILE_CHOOSER_DIRECTORY);
    
#endif
	    locx = locy = 0;


#ifdef OW_I18N
    if (textsw_expand_filename(folio, dir_str, MAX_STR_LENGTH, locx, locy)) {
	/* error handled inside routine */
	return TRUE;
    }
    if (textsw_expand_filename(folio, file, MAX_STR_LENGTH, locx, locy)) {
	/* error handled inside routine */
	return TRUE;
    }
#else
#endif

    /* if "cd" is not disabled and the "cd" dir is not the current dir */
#ifdef OW_I18N
#if defined(SVR4) || defined(__linux__)
    (void) getcwd(curr_dir_mb, MAX_STR_LENGTH);
#else
    (void) getwd(curr_dir_mb);
#endif /* SVR4 */
    (void) mbstowcs(curr_dir, curr_dir_mb, MAX_STR_LENGTH);
#else /* OW_I18N */
#if defined(SVR4) || defined(__linux__)
    (void) getcwd(curr_dir, MAX_STR_LENGTH);
#else
    (void) getwd(curr_dir);
#endif /* SVR4 */
#endif /* OW_I18N */

    textsw_changed_directory = FALSE;
    if (STRCMP(curr_dir, dir_str) != 0) {
	if (!(folio->state & TXTSW_NO_CD)) {
	    if (textsw_change_directory(folio, dir_str, FALSE, locx, locy) != 0)
		return TRUE;
	    else
	    /*
	    * kludge to prevent including file from changing
	    * your directory too.
	    */
		textsw_changed_directory = TRUE;
	} else {
	    frame = (Frame)FRAME_FROM_FOLIO_OR_VIEW(folio);
            text_notice = (Xv_Notice)xv_get(frame, 
                                        XV_KEY_DATA, text_notice_key, NULL);
            if (!text_notice)  {
                text_notice = xv_create(frame, NOTICE,
                                    NOTICE_LOCK_SCREEN, FALSE,
			  	    NOTICE_BLOCK_THREAD, TRUE,
                                    NOTICE_MESSAGE_STRINGS,
				    XV_MSG("Cannot change directory.\n\
Change Directory Has Been Disabled."),
                                    0,
                                    NOTICE_BUTTON_YES, 
					XV_MSG("Continue"),
                                    XV_SHOW, TRUE,
                                    0);

                xv_set(frame, 
                        XV_KEY_DATA, text_notice_key, text_notice,
                        NULL);
            }
            else  {
                xv_set(text_notice, 
                        NOTICE_LOCK_SCREEN, FALSE,
			NOTICE_BLOCK_THREAD, TRUE,
                        NOTICE_MESSAGE_STRINGS,
		        XV_MSG("Cannot change directory.\n\
Change Directory Has Been Disabled."),
                        0,
                        NOTICE_BUTTON_YES, 
				XV_MSG("Continue"),
                        XV_SHOW, TRUE, 
                        NULL);
            }
	    return TRUE;
	}
    }
    if ((int)STRLEN(file) > 0) {
	if (textsw_file_stuff_from_str(VIEW_FROM_FOLIO_OR_VIEW(folio),
				       file, locx, locy) == 0) {
	    
	    (void) xv_set(fc, XV_SHOW, FALSE, 0);
	    if (textsw_changed_directory)
	        textsw_change_directory(folio, curr_dir, FALSE, locx, locy);
	    return FALSE;
	}
	if (textsw_changed_directory)
	    textsw_change_directory(folio, curr_dir, FALSE, locx, locy);
	return TRUE;
    }

    frame = (Frame)FRAME_FROM_FOLIO_OR_VIEW(folio);
    text_notice = (Xv_Notice)xv_get(frame, XV_KEY_DATA, text_notice_key, NULL);
    if (!text_notice)  {
        text_notice = xv_create(frame, NOTICE,
                            NOTICE_LOCK_SCREEN, FALSE,
			    NOTICE_BLOCK_THREAD, TRUE,
                            NOTICE_MESSAGE_STRINGS,
			    XV_MSG("No file name was specified.\n\
Specify a file name to Include File."),
                            0,
                            NOTICE_BUTTON_YES, 
				XV_MSG("Continue"),
                            XV_SHOW, TRUE,
                            0);

        xv_set(frame, 
            XV_KEY_DATA, text_notice_key, text_notice,
            NULL);
    }
    else  {
        xv_set(text_notice, 
            NOTICE_LOCK_SCREEN, FALSE,
	    NOTICE_BLOCK_THREAD, TRUE,
            NOTICE_MESSAGE_STRINGS,
	    XV_MSG("No file name was specified.\n\
Specify a file name to Include File."),
            0,
            NOTICE_BUTTON_YES, XV_MSG("Continue"),
            XV_SHOW, TRUE, 
            NULL);
    }   
    if (textsw_changed_directory)
        textsw_change_directory(folio, curr_dir, FALSE, locx, locy);
    /* if we made it here then there was an error or notice */
    return TRUE;
}