File: help.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 (491 lines) | stat: -rw-r--r-- 11,031 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
/*
 * Copyright (c) 1992 The Regents of the University of Texas System.
 * 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: help.c,v 1.1 1994/03/14 18:55:53 jones Exp $\n";
static char rcspath[] =
"$Source: /mintaka/u0/xx/ss/jones/jones.old/mftp.src/moxftp-2.0/RCS/help.c,v $\n";
#endif

/* $Log: help.c,v $
 * Revision 1.1  1994/03/14  18:55:53  jones
 * Initial revision
 *
 */

#include "machine.h"
#include "defs.h"
#include "class.h"
#if defined(MOTIF)
#include <Xm/Xm.h>
#endif

#define HELP_TEXT_WINDOW "*help_text"

#include <X11/Xlib.h>
#include "wc.h"
#include "proto/help.h"

extern XtAppContext  App_context;
extern Widget Top;
extern char *Ftpname;
static int once = 1;
static void Set_Help_Title_cb();
Widget Help_Shell  = NULL;
Widget Help_w     = NULL;
Widget Help_title = NULL;

char *title_name[7] = {
#define T_GENERAL  0
    "General", 
#define T_SHELL    1
    "Shells", 
#define T_DIALOG   2    
    "Dialogs", 
#define T_BUTTON   3    
    "Buttons", 
#define T_WINODW   4
    "Window", 
#define T_MENU     5 
    "Menu", 
#define T_SUBMENU  6 
    "Submenus"
};


typedef struct _help_t {
	String help;
} help_t, *help_t_p; 

char *help_general = GENERAL_HELP;
static char *tran  = NULL;

help_t help_res;

XtResource r_help[] =
{ 
    { "help_text", "Help_text", XtRString, sizeof(String), 
       XtOffset(help_t_p, help), XtRString, (caddr_t)NULL },
};

char *help_text = NULL;
char *help_title = NULL;

#define MAX_HELP_MENU 100
struct _help_menu {
	char  *title;
	char   *name;
	Widget w;
} help_menu[MAX_HELP_MENU];
int NUM_HELP_MENU = 0;
static MENU_ONCE = 0;

void
Create_Help_Menu()
{ 
    int max;
    int last;
    int current;
    Widget w, parent, child;
#if defined(XAW)
    extern Widget CreateHelpPopupChild();
#endif
#if defined(OPENWINDOW)
    Widget pane;
#else
    Widget menu;
#endif

    if (MENU_ONCE) return;

#if defined(OPENWINDOW)
    w = WcFullNameToWidget(Top, "*helpmenu*pane"); 
#else
    w = WcFullNameToWidget(Top, "*helpmenu"); 
#endif

    qsort((void *)help_menu, NUM_HELP_MENU, sizeof(struct _help_menu), 
          compare_menu );
    MENU_ONCE++;
    max = NUM_HELP_MENU;
    last = title_type(help_menu[0].title);
#if defined(OPENWINDOW)
    parent = WcCreateChild(w, "help_sub");
    pane = WcFullNameToWidget(parent, "*pane"); 
    XtManageChild(parent);
    XtManageChild(pane);
#endif
#if defined(MOTIF)
    parent = WcCreateChild(w, "help_sub");
    menu   = WcCreateChild(w, "help_menu");
    XtVaSetValues(parent, XmNsubMenuId, menu, NULL);
    XtManageChild(parent);
#endif
#if defined(XAW)
    parent = WcCreateChild(w, "help_sub");
    menu   = CreateHelpPopupChild(w, "help_menu");
    Bind_Menu(parent, NULL, menu);
    XtManageChild(parent);
#endif
    SetLabel(parent, title_name[last]);
    for (NUM_HELP_MENU=0; NUM_HELP_MENU < max; NUM_HELP_MENU++)  {
        current  = title_type(help_menu[NUM_HELP_MENU].title);
	if (last != current) {
            last = current;
#if defined(OPENWINDOW)
            parent = WcCreateChild(w, "help_sub");
            pane = WcFullNameToWidget(parent, "*pane"); 
    	    XtManageChild(pane);
#endif
#if defined(MOTIF)
    	    parent = WcCreateChild(w, "help_sub");
    	    menu   = WcCreateChild(w, "help_menu");
            XtVaSetValues(parent, XmNsubMenuId, menu, NULL);
#endif
#if defined(XAW)
    	    parent = WcCreateChild(w, "help_sub");
            menu   = CreateHelpPopupChild(w, "help_menu");
            Bind_Menu(parent, NULL, menu);
#endif
            XtManageChild(parent);
            SetLabel(parent, title_name[last]);
	}
#if defined(OPENWINDOW)
    	child =  WcCreateChild(pane, "helpmenu1");
        Set_Help_Title_cb(child, NULL, NULL);
#else
    	child =  WcCreateChild(menu, "helpmenu1");
        Set_Help_Title_cb(child, NULL, NULL);
#endif
        XtManageChild(child);
    }
}

void
Help(w, string, flag)
Widget  w;
char    *string;
int     flag;
{
    char * WcWidgetToFullName();
    char *name;
    char *start, *end;
    char *cp;
  
    if (string) {
	name = start = XtNewString(string);
    } else {
	name = WcWidgetToFullName(w);
	start = RINDEX(name, '.');
    	if (start == NULL) {
	    start = name;
	} else {
	    start++;
	}
    }

    help_res.help = NULL;
    XtGetSubresources(Top, (XtPointer)&help_res, 
		      start, start, r_help, XtNumber(r_help),
		      NULL, 0);
    /*
     * Walk up the name tree.
     */
    while (help_res.help == NULL)  {
	cp = RINDEX(name, '.');
	if (cp) {
       	    *cp = '\0';
 	} else {
	    break;
	}
	start = RINDEX(name, '.');
    	if (start == NULL) {
	    start = name;
	} else {
	    start++;
	}
        XtGetSubresources(Top, (XtPointer)&help_res, start, start, r_help, 
			  XtNumber(r_help), NULL, 0);
    }
    if (help_res.help == NULL)  {
        XtGetSubresources(Top, (XtPointer)&help_res, help_general, 
			  help_general, r_help, XtNumber(r_help), NULL, 0);
    }
    if (help_res.help == NULL) return;
    if (help_text)  XtFree(help_text);
    if (help_title) XtFree(help_title);
    start = help_res.help;
    while (start = bsdstrstr(start, "XXXX")) {
	strncpy(start, Ftpname, 4);
	start += 4;
    }
    start = help_res.help;
    end = INDEX(help_res.help, '\n');
    if (end) {
	int n;
	n = end - start;
	help_title = XtMalloc(n+1);
	strncpy(help_title, start, n);
	help_title[n] = '\0';
	start = end+1;
    } else {
	help_title = XtNewString(" ");
    }
    help_text = XtNewString(start);
    if (flag) return;
    help_once(w);
}

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

static void
Help_Once_cb(w, stuff, unused)
Widget  w;
char    *stuff;
caddr_t unused;
{
    help_once(w);

}

static void
Help_by_title_cb(w, stuff, unused)
Widget  w;
char    *stuff;
caddr_t unused;
{
    char *cp;
    int   i;

    for (i=0; i<NUM_HELP_MENU; i++) {
	if (help_menu[i].w == w) {
      	    Help(w, help_menu[i].name, 0);
	    return;
	}
    }
    if (XtIsWidget(w))
	fprintf(stderr, "Could not find widget %s\n", w->core.name);
}

int
Help_dead_cb(w, stuff, unused)
Widget  w;
char    *stuff;
caddr_t unused;
{
     Help_Shell   = NULL;
     Help_w      = NULL;
     Help_title = NULL;
}

static void
Help_register_cb(w, stuff, unused)
Widget  w;
char    *stuff;
caddr_t unused;
{
     char *name, *start;
     char *cp;
     int i;
     char *WcWidgetToFullName();

     if (stuff && *stuff && *stuff != ' ') {
	cp = stuff;
     } else {
        name = WcWidgetToFullName(w);
	start = RINDEX(name, '.');
    	if (start == NULL) {
	    start = name;
	} else {
	    start++;
	}
	cp = start;
     }
     Help(w, cp, 1);
     for (i=0; i<NUM_HELP_MENU;i++) {
	if (strcmp(help_menu[i].title, help_title) == 0) return;
     }
     help_menu[NUM_HELP_MENU].name = XtNewString(cp);
     help_menu[NUM_HELP_MENU].title = XtNewString(help_title);
     NUM_HELP_MENU++;

}

void
Register_help_CallBacks_and_Actions()
{
     RACCT("set_help"	        , Set_help_action);
     RACCT("help_once"		, Help_Once_action);
     RCALL("help_register"	, Help_register_cb);
     RCALL("help_dead"	        , Help_dead_cb);
     RCALL("help_by_title"	, Help_by_title_cb);
     RCALL("set_help"		, Set_help_cb);
     RCALL("SetHelpTitle"	, Set_Help_Title_cb);
     RCALL("help_once"		, Help_Once_cb);
}

static void
Set_Help_Title_cb(w, stuff, unused)
Widget  w;
char    *stuff;
caddr_t unused;
{
    SetLabel(w, help_menu[NUM_HELP_MENU].title);
    help_menu[NUM_HELP_MENU].w = w;
}

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

static void
Set_help_cb(w, stuff, unused)
Widget  w;
char    *stuff;
caddr_t unused;
{
    set_help_text(w);
}

static void
clear_help(w, stuff, xxx)
Widget w;
char   *stuff;
char   *xxx;
{
#if defined(XAW)||defined(OPENWINDOW)
    XtPopdown(Help_Shell);
#endif
}

static int
compare_menu(x,y)
void *x;
void *y;
{
    struct _help_menu *a = x;
    struct _help_menu *b = y;
    int   avalue;
    int   bvalue;
    int   n;

    avalue  = title_type(a->title);
    bvalue  = title_type(b->title);

    if (avalue > bvalue) return  1;
    if (avalue < bvalue) return -1;
    n = strcmp(a->title, b->title);
    if (n > 0) return  1;
    if (n < 0) return -1;
    return 0;
}

static void
help_once(w)
Widget w;
{
    XWMHints wmhints;

    if (!Help_Shell) {
        Help_Shell = WcFullNameToWidget(Top, "*Shellhelp"); 
        if (!Help_Shell) {
	    WcCreateNamedPopups ( Top, "Shellhelp" );
        }
        Help_Shell = WcFullNameToWidget(Top, "*Shellhelp"); 
	if (!Help_Shell) return;
    }
    Create_Help_Menu();
    XtPopup(Help_Shell, XtGrabNone);
    XRaiseWindow(XtDisplay(Help_Shell), XtWindow(Help_Shell));
    WM_DELETE(Help_Shell, clear_help, "help");
    Set_Icon(Help_Shell, "help");
    SetWidget(Help_w, HELP_TEXT_WINDOW, 0);
    set_help_text(Help_w);
}

static void
set_help_text(w)
Widget w;
{
    if (!Help_Shell) return;
    SetWidget(Help_w, HELP_TEXT_WINDOW, 0);
    if (help_text) {
	set_the_help_text(Help_w, help_text);
    } else {
	set_the_help_text(Help_w, "No help!");
    }
    if(!help_title) return;
    SetWidget(Help_title, "*help_title", 0);
    SetLabel(Help_title, help_title);
}

static void
set_the_help_text(w, text)
Widget w;
char   *text;
{
#if defined(OPENWINDOW)
   SetStringSource(w, text);
#else
   SetText(w, text);
#endif
}

static int
title_type(string)
char *string;
{
    int type;
    char *mystring();

    if (bsdstrstr(string, "SubMenu") != NULL) {
	type = T_SUBMENU;
    } else if (bsdstrstr(string, "Menu") != NULL) {
	type = T_MENU;
    } else if (bsdstrstr(string, "Window") != NULL) {
	type = T_WINODW;
    } else if (bsdstrstr(string, "Button") != NULL) {
	type = T_BUTTON;
    } else if (bsdstrstr(string, "Dialog") != NULL) {
	type = T_DIALOG;	
    } else if (bsdstrstr(string, "Shell") != NULL) {
	type = T_SHELL;	
    } else {
       	type = T_GENERAL ;
    }
    return type;
}