-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp.c
151 lines (133 loc) · 4.21 KB
/
help.c
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
/* @(#)help.c 1.28 01/01/99 */
/*
* Copyright (c) 1991-1998 Shiwon Cho. All rights reserved.
*
* help.c - part of SM/Editor
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Writen by Shiwon Cho (stsolaris_at_gmail.com)
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef hpux
#include <strings.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <X11/Intrinsic.h>
#include <Xm/Text.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/SeparatoG.h>
#define HELP_ENV "SMED_HELP"
#define HELP_FILE "smed.help"
Widget help_text;
#ifdef _NO_PROTO
void closeHelpDialog_cb(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
#else
void closeHelpDialog_cb(Widget w, XtPointer client_data, XtPointer call_data)
#endif
{
Widget dialog = (Widget)client_data;
XtUnmanageChild(dialog);
}
#ifdef _NO_PROTO
Widget CreateHelpDialog(parent, name)
Widget parent;
char *name;
#else
Widget CreateHelpDialog(Widget parent, char *name)
#endif
{
static Widget form, seperator_w, ok_button;
Arg args[10];
int arg;
arg = 0;
XtSetArg(args[arg], XmNfractionBase, 5); arg++;
XtSetArg(args[arg], XmNnoResize, True); arg++;
XtSetArg(args[arg], XmNresizePolicy, XmRESIZE_NONE); arg++;
form = XmCreateFormDialog(parent, name, args, arg);
arg = 0;
XtSetArg(args[arg], XmNeditMode, XmMULTI_LINE_EDIT); arg++;
XtSetArg(args[arg], XmNeditMode, False); arg++;
XtSetArg(args[arg], XmNeditable, False); arg++;
XtSetArg(args[arg], XmNtopAttachment, XmATTACH_FORM); arg++;
XtSetArg(args[arg], XmNtopOffset, 5); arg++;
XtSetArg(args[arg], XmNleftAttachment, XmATTACH_FORM); arg++;
XtSetArg(args[arg], XmNleftOffset, 5); arg++;
XtSetArg(args[arg], XmNrightAttachment, XmATTACH_FORM); arg++;
XtSetArg(args[arg], XmNrightOffset, 5); arg++;
XtSetArg(args[arg], XmNtraversalOn, False); arg++;
help_text = XmCreateScrolledText(form, "helpText", args, arg);
XtManageChild(help_text);
seperator_w = XtVaCreateManagedWidget("Separator",
xmSeparatorGadgetClass, form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, help_text,
XmNtopOffset, 2,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
ok_button = XtVaCreateManagedWidget("helpOk",
xmPushButtonWidgetClass, form,
XmNshowAsDefault, True,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, seperator_w,
XmNtopOffset, 5,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 2,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 3,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 5,
NULL);
XtAddCallback(ok_button,
XmNactivateCallback, closeHelpDialog_cb, (XtPointer)form);
return (form);
}
void loadHelpText()
{
char *str, buf[BUFSIZ];
FILE *fp;
struct stat statb;
char *env;
env = getenv(HELP_ENV);
if (env != NULL)
(void)sprintf(buf, "%s/%s", env, HELP_FILE);
else
(void)sprintf(buf, "/usr/lib/X11/%s", HELP_FILE, HELP_FILE);
if ((fp = fopen(buf, "r"))) {
(void)stat(buf, &statb);
str = XtMalloc((Cardinal)statb.st_size + 1);
if (fread(str, sizeof(char), (int)statb.st_size, fp) != (size_t)statb.st_size)
(void)sprintf(buf, "\nWarning: did not read entire file!\n");
str[statb.st_size] = '\0';
fclose(fp);
XmTextSetString(help_text, str);
XtFree(str);
}
else {
str = XtMalloc((Cardinal)BUFSIZ);
(void)sprintf(str, "\n\t\tHelp file : %s not found", HELP_FILE);
XmTextSetString(help_text, str);
XtFree(str);
}
}