File: dialog.c

package info (click to toggle)
moxftp 2.2-18.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 4,160 kB
  • ctags: 3,837
  • sloc: ansic: 43,420; makefile: 353; perl: 262; sh: 192
file content (524 lines) | stat: -rw-r--r-- 10,631 bytes parent folder | download | duplicates (4)
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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/*
 * Copyright (c) 1993 The Regents of the University of Texas System.
 * Copyright (c) 1994 The Regents of the University of Texas System.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted provided
 * that the above copyright notice and this paragraph are duplicated in all
 * such forms and that any documentation, advertising materials,  and other
 * materials  related to such  distribution  and use  acknowledge  that the
 * software  was  developed  by the  University of Texas.  The  name of the
 * University may not be  used to endorse or promote  products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1993 The Regents of the University of Texas System.\n\
 All rights reserved.\n";
static char rcsid[] =
"$Id: dialog.c,v 1.2 1994/05/20 20:12:12 jones Exp $\n";
static char rcspath[] =
"$Source: /mintaka/u0/xx/ss/jones/jones.old/mftp.src/moxftp-2.0/RCS/dialog.c,v $\n";
#endif

/* $Log: dialog.c,v $
 * Revision 1.2  1994/05/20  20:12:12  jones
 * Glob should select files not unselect them.
 *
 * Revision 1.1  1994/03/14  18:55:53  jones
 * Initial revision
 *
 */

#include "machine.h"
#include "defs.h"
#include "wc.h"
#include "proto/dialog.h"

extern Widget Top;
extern XtAppContext  App_context;

/*
 * Local definitions.
 */
static CB  *c_cb   = NULL;

static Widget Continue_Dialog_W = NULL;
static Widget Glob_Dialog_W = NULL;
static Widget Search_Dialog_W = NULL;
static Widget Search_Host_Dialog_W = NULL;

#define GLOB_GLOB   0
#define GLOB_REG    1
#define GLOB_CANCEL 2
#define GLOB_HELP   3

#define SEARCH_GLOB   0
#define SEARCH_REG    1
#define SEARCH_CANCEL 2
#define SEARCH_HELP   3

#define SEARCH_HOST_REG    0
#define SEARCH_HOST_CANCEL 1
#define SEARCH_HOST_HELP   2

#define CONTINUE_IGNORE    0
#define CONTINUE_CONTINUE  1
#define CONTINUE_CANCEL    2
#define CONTINUE_HELP      3

static void
CreateContinueDialog_cb(w, closure, call_data)	
Widget w;
XtPointer closure;
XtPointer call_data;
{
    Continue_Dialog_W = CreateSimpleDialog(w,
				          "Shellcontinuedialog",
				          "Temp",
					  0,
				          "Ignore Errors", CONTINUE_IGNORE, 
				          "Continue"     , CONTINUE_CONTINUE, 
				          "Cancel"       , CONTINUE_CANCEL,
				          "Help"         , CONTINUE_HELP,
				          continue_cb);
}


static void
CreateGlobDialog_cb(w, closure, call_data)	
Widget w;
XtPointer closure;
XtPointer call_data;
{

    if (Glob_Dialog_W != NULL) return;
    Glob_Dialog_W = CreateSimpleDialog(w,
				       "Shellglobdialog",
				       "Enter String:",
				       1,
				       "Glob",         GLOB_GLOB, 
				       "Regular exp" , GLOB_REG, 
				       "Cancel",       GLOB_CANCEL,
				       "Help"  ,       GLOB_HELP,
				        glob_cb);
}


static void
CreateSearchHostDialog_cb(w, closure, call_data)	
Widget w;
XtPointer closure;
XtPointer call_data;
{

    if (Search_Host_Dialog_W != NULL) return;
    Search_Host_Dialog_W = CreateSimpleDialog(w,
				        "Shellsearchhostdialog",
				        "Enter Search String:",
				        1,
				        "Search"       , SEARCH_HOST_REG,
				        "Cancel"       , SEARCH_HOST_CANCEL,
					 NULL	       , 0,
				        "Help"         , SEARCH_HOST_HELP,
				         search_host_cb);
}

static void
CreateSearchDialog_cb(w, closure, call_data)	
Widget w;
XtPointer closure;
XtPointer call_data;
{

    if (Search_Dialog_W != NULL) return;
    Search_Dialog_W = CreateSimpleDialog(w,
				        "Shellsearchdialog",
				        "Enter Search String:",
				        1,
				        "Glob"         , SEARCH_GLOB, 
				        "Regular exp"  , SEARCH_REG,
				        "Cancel"       , SEARCH_CANCEL,
				        "Help"         , SEARCH_HELP,
				         search_cb);
}

void
Continue_Dialog(label, cb)
char *label;
CB   *cb;
{

     c_cb   = cb;

     if (label != NULL) {
          SetDialogLabel(Continue_Dialog_W, label);
     } else {
          SetDialogLabel(Continue_Dialog_W, "Error");
     }
     PopDialog(Continue_Dialog_W, "*Shellcontinuedialog");
}

void
Search_Dialog()
{
     PopDialog(Search_Dialog_W, "*Shellsearchdialog");
}

void
Search_Host_Dialog()
{
     PopDialog(Search_Host_Dialog_W, "*Shellsearchhostdialog");
}

static void
PopDialog(w, name)
Widget w;
char *name;
{
#if defined(MOTIF)
     XtManageChild(w);
#else
     Position_Dialog_cb(Top, name, NULL);
     XtPopup(w, XtGrabNone);
#endif
}

void
Dialog_Restart(type, cb)
int type;
CB *cb;
{
    CB *cbp;
    extern int aborting;

    if (type < 0) type = CONTINUE_CONTINUE;
    if (type == DIALOG_RESTART_IGNORE) type = CONTINUE_IGNORE;
    if (type == DIALOG_RESTART_CONTINUE) type = CONTINUE_CONTINUE;
    aborting = 0;
    WcSetInsensitiveCB(Top, "*reconnect", NULL);
    cbp = link_callback(NULL, restart_cb, (DATA)type, cb);
    Start_Reconnect(cbp);
}

void
Reset_Search_String()
{
     Reset_D_String(Search_Dialog_W);
     Reset_D_String(Glob_Dialog_W);
}

void
Reset_Host_Search_String()
{
     Reset_D_String(Search_Host_Dialog_W);
}


static void
restart_cb(data, code, cb)
DATA  data;
int   code;
CB   *cb;
{
    int type = (int)data;

    if (ftp_response[code].status & FTP_ERROR) {
     	    Clean_Up(0, cb);
	    return;
    } else {
        switch (type) {
	    case CONTINUE_CANCEL:
     	    	Clean_Up(0, cb);
	    	break;
	    case CONTINUE_CONTINUE:
            	Restart_List(cb, 0);
	    	break;
	    case CONTINUE_IGNORE:
            	Restart_List(cb, 1);
		break;
	}
    }
}

static void
continue_cb(w, closure, call_data)
Widget w;
XtPointer closure;
XtPointer call_data;
{
    int type = (int)closure;
    CB *cbp;
    extern int aborting;


#if defined(MOTIF)
    XtUnmanageChild(Continue_Dialog_W);
#endif
#if defined(XAW)
    XtPopdown(Continue_Dialog_W);
#endif
    /*
     * This will mostly work.
     */
    if (connected == 0 && type != CONTINUE_CANCEL) {
	Dialog_Restart(type, c_cb);
	return;
    }

    switch (type) {
	case CONTINUE_CANCEL:
     	    Clean_Up(0, c_cb);
	    break;
	case CONTINUE_CONTINUE:
            Restart_List(c_cb, 0);
	    break;
	case CONTINUE_IGNORE:
            Restart_List(c_cb, 1);
    }

}

static void
glob_cb(w, closure, call_data)
Widget w;
XtPointer closure;
XtPointer call_data;
{
    char *glob;
    char *GetText();
    int type = (int)closure;

#if defined(MOTIF)
    XtUnmanageChild(Glob_Dialog_W);
#endif
#if defined(XAW)
    XtPopdown(Glob_Dialog_W);
#endif

    glob = GetDialogText(Glob_Dialog_W);

    switch (type) {
	case GLOB_GLOB:
            glob = makeglob(glob);
	    Glob_Files(glob, 1);
	    break;
	case GLOB_REG:
	    Glob_Files(glob, 1);
	    break;
    }
    XtFree(glob);
}

static char *
makeglob(reg)
char *reg;
{
    char *cp1, *cp2;
    char *glob;

    if (!reg || !*reg) return NULL;

    cp1 = reg;
    cp2 = glob = XtMalloc(2*strlen(reg)+2+1);
    *cp2 = '^';
    *cp2++;

    while (*cp1) {
	switch (*cp1) {
	    case '*': 
		*cp2 = '.';
		cp2++;
		*cp2 = '*';
		cp2++;
		break;
	    case '?':
		*cp2 = '.';
		cp2++;
		break;

	    case '^':
	    case '$':
		*cp2 = '\\';
		cp2++;
		*cp2 = *cp1;
		cp2++;
		break;

	    default:
		*cp2 = *cp1;
		cp2++;
		break;
	}
	cp1++;
    }
    *cp2 = '$';
    *cp2++;
    *cp2 = '\0';

    XtFree(reg);
    return glob;

}


static void
search_clear_act(w, event, params, nparams)
Widget          w;
XEvent         *event;
String         *params;
Cardinal       *nparams;
{
    Reset_Search();
}

static void
search_host_cb(w, closure, call_data)
Widget w;
XtPointer closure;
XtPointer call_data;
{
    char *search;
    char *GetText();
    int type = (int)closure;

#if defined(MOTIF)
    XtUnmanageChild(Search_Host_Dialog_W);
#endif
#if defined(XAW)
    XtPopdown(Search_Host_Dialog_W);
#endif

    search = GetDialogText(Search_Host_Dialog_W);

    switch (type) {
	case SEARCH_HOST_REG:
	    Search_Host(search);
	    break;
    }
    if(search) XtFree(search);
}

static void
search_cb(w, closure, call_data)
Widget w;
XtPointer closure;
XtPointer call_data;
{
    char *search;
    char *GetText();
    int type = (int)closure;

#if defined(MOTIF)
    XtUnmanageChild(Search_Dialog_W);
#endif
#if defined(XAW)
    XtPopdown(Search_Dialog_W);
#endif

    search = GetDialogText(Search_Dialog_W);

    switch (type) {
	case SEARCH_GLOB:
	    search = makeglob(search);
            Search_Files(search, 0);
	    break;
	case SEARCH_REG:
            Search_Files(search, 0);
	    break;
    }
    if(search) XtFree(search);
}

static void
set_glob_text_act(w, event, params, nparams)
Widget          w;
XEvent         *event;
String         *params;
Cardinal       *nparams;
{
    char *glob;
    char *GetText();

    glob = GetDialogText(Glob_Dialog_W);

    if (params && *params) {
	if (strcmp("glob", *params) == 0) {
            glob = makeglob(glob);
	}

    }
    if (glob) {
        Glob_Files(glob, 1);
        XtFree(glob);
    }
}

static void
set_search_host_act(w, event, params, nparams)
Widget          w;
XEvent         *event;
String         *params;
Cardinal       *nparams;
{
    char *search;
    char *GetText();

    search = GetDialogText(Search_Host_Dialog_W);

    if (params && *params) {
	if (strcmp("glob", *params) == 0) {
	    search = makeglob(search);
	} else if (strcmp("clear", *params) == 0) {
	    printf("Clearing\n");
	}

    }
    Search_Host(search);
    if (search) XtFree(search);
}

static void
set_search_text_act(w, event, params, nparams)
Widget          w;
XEvent         *event;
String         *params;
Cardinal       *nparams;
{
    char *search;
    char *GetText();

    search = GetDialogText(Search_Dialog_W);

    if (params && *params) {
	if (strcmp("glob", *params) == 0) {
	    search = makeglob(search);
	}

    }
    Search_Files(search, 0);
    if (search) XtFree(search);
}

static XtActionsRec Actions[] = {
    {"set_search_text", set_search_text_act},
    {"set_search_host", set_search_host_act},
    {"set_glob_text",   set_glob_text_act},
    {"search_clear"   , search_clear_act}
};

int
Register_dialog_c_a_a()
{
     XtAppAddActions(App_context, Actions,
                        sizeof(Actions)/sizeof(XtActionsRec));
    RCALL("CreateGlobDialog"       , CreateGlobDialog_cb);
    RCALL("CreateSearchDialog"     , CreateSearchDialog_cb);
    RCALL("CreateHostSearchDialog" , CreateSearchHostDialog_cb);
    RCALL("CreateContinueDialog"   , CreateContinueDialog_cb);
}