Jspice3
help.c File Reference
#include "spice.h"
#include "cpdefs.h"
Include dependency graph for help.c:

Go to the source code of this file.

Functions

static char * tilde_expand ()
 
int main (int argc, char **argv)
 
void fatal ()
 
bool cp_getvar (char *n, int t, char *r)
 
void cp_pathfix (char *buf)
 
static char * tilde_expand (char *string)
 

Variables

bool cp_interactive = true
 
FILE * cp_in
 
FILE * cp_out
 
FILE * cp_err
 
bool hlp_usex
 
bool hlp_killx
 
char * Help_Path
 
char * kw_hcopydev = "hcopydev"
 

Function Documentation

bool cp_getvar ( char *  n,
int  t,
char *  r 
)

Definition at line 184 of file help.c.

188 {
189  if (!strcmp(n, kw_hcopydev)) {
190  strcpy(r, hcopydev);
191  return (True);
192  }
193  return (false);
194 }
char * strcpy()
#define True
Definition: scedstub.c:16
char * kw_hcopydev
Definition: help.c:105
Definition: cddefs.h:162
void cp_pathfix ( char *  buf)

Definition at line 198 of file help.c.

201 {
202 #ifdef MSDOS
203  char *s, *t;
204  int bcnt = 0, ecnt = 0;
205 
206  s = t = buf;
207  while (*t != '\0') {
208  if (*t == '/' || *t == '\\') {
209  *s++ = '\\';
210  t++;
211  bcnt = 0;
212  ecnt = 0;
213  }
214  else if (*t == '.') {
215  *s++ = *t++;
216  ecnt = 1;
217  }
218  else if (!ecnt) {
219  if (bcnt++ < 8) *s++ = *t++;
220  else t++;
221  }
222  else {
223  if (ecnt++ < 4) *s++ = *t++;
224  else t++;
225  }
226  }
227  *s = '\0';
228 
229 #else
230  char *s;
231 
232  if (index(buf,'~')) {
233  s = tilde_expand(buf);
234  if (s) {
235  strcpy(buf,s);
236  txfree(s);
237  }
238  }
239 #endif
240 }
static char buf[MAXPROMPT]
Definition: arg.c:18
char * strcpy()
Definition: cddefs.h:119
void txfree()
char * index(char *s, char c) const
Definition: string.c:294
static char * tilde_expand()
Definition: cddefs.h:192
void fatal ( )

Definition at line 174 of file help.c.

176 {
177  fprintf(stderr, "fatal error\n");
178  exit(1);
179 }
int main ( int  argc,
char **  argv 
)

Definition at line 116 of file help.c.

120 {
121  wordlist *wl = NULL;
122  char *s;
123 
124  /* SPICE_HELP defined with -D cmdline option */
125  Help_Path = copy(SPICE_HELP);
126  if ((s = getenv("SPICE_HELP")) != NULL)
127  Help_Path = copy(s);
128  else if ((s = getenv("SPICE_LIB_DIR")) != NULL) {
129  Help_Path = tmalloc(strlen(s) + 10);
130  sprintf(Help_Path,"%s/helpdir",s);
131  }
132  if ((s = getenv("PRINTER")) != NULL)
133  hcopydev = copy(s);
134  else
135  hcopydev = "lp";
136  cp_in = stdin;
137  cp_out = stdout;
138  cp_err = stderr;
139 
140 #ifdef HAVE_X11
141  hlp_usex = 1;
142  hlp_killx = 1;
143 
144  /* initialize X toolkit */
145  XtToolkitInitialize();
146  app_con = XtCreateApplicationContext();
147  XtAppSetFallbackResources(app_con, fallback_resources);
148  Xdisplay = XtOpenDisplay(app_con, NULL, NULL, "Help", NULL, 0,
149  &argc, argv);
150  if (!Xdisplay) {
151  fprintf(stderr, "Error: Can't open X display");
152  return (1);
153  }
154  XSetErrorHandler(errorhandler);
155  XtAppAddActions(app_con, actions, XtNumber(actions));
156 #endif
157 
158 out:
159  if (argc > 1)
160  wl = wl_build(argv + 1);
161  hlp_main(Help_Path, wl);
162 
163 #ifdef HAVE_X11
164  if (hlp_usex) {
165  XtAppMainLoop(app_con);
166  }
167 #endif
168 
169  return (EXIT_NORMAL);
170 }
Definition: cddefs.h:119
char * Help_Path
Definition: help.c:104
bool hlp_killx
#define EXIT_NORMAL
Definition: misc.h:25
Definition: library.c:18
void hlp_main()
char * copy()
char * getenv(char *c)
Definition: libfuncs.c:106
FILE * cp_err
Definition: help.c:101
char * tmalloc()
#define NULL
Definition: spdefs.h:121
FILE * cp_out
Definition: help.c:101
wordlist * wl_build()
Definition: cpstd.h:21
static int errorhandler()
FILE * cp_in
Definition: help.c:101
bool hlp_usex
Definition: provide.c:15
Display * Xdisplay
#define XtNumber(arr)
Definition: display.c:114
static char* tilde_expand ( )
static
static char* tilde_expand ( char *  string)
static

Definition at line 244 of file help.c.

247 {
248 #ifdef HAVE_GETPWUID
249  struct passwd *pw;
250  char *tail;
251  char buf[BSIZE_SP];
252  char *k, c;
253 
254  if (!string)
255  return (NULL);
256 
257  while (*string && isspace(*string))
258  string++;
259 
260  if (*string != '~')
261  return copy(string);
262 
263  string += 1;
264 
265  if (!*string || *string == '/') {
266  pw = getpwuid(getuid());
267  *buf = 0;
268  }
269  else {
270  k = buf;
271  while ((c = *string) && c != '/')
272  *k++ = c, string++;
273  *k = 0;
274  pw = getpwnam(buf);
275  }
276 
277  if (pw) {
278  strcpy(buf, pw->pw_dir);
279  if (*string)
280  strcat(buf, string);
281  }
282  else
283  return (NULL);
284 
285  return (copy(buf));
286 
287 #else
288  return (copy(string));
289 #endif
290 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
char * strcpy()
char * copy()
#define NULL
Definition: spdefs.h:121
static double c
Definition: vectors.c:16

Variable Documentation

FILE * cp_err

Definition at line 101 of file help.c.

FILE* cp_in

Definition at line 101 of file help.c.

bool cp_interactive = true

Definition at line 100 of file help.c.

FILE * cp_out

Definition at line 101 of file help.c.

char* Help_Path

Definition at line 104 of file help.c.

bool hlp_killx
bool hlp_usex

Definition at line 15 of file provide.c.

char* kw_hcopydev = "hcopydev"

Definition at line 105 of file help.c.