File: help.c

package info (click to toggle)
geomview 1.9.5-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 22,892 kB
  • ctags: 12,254
  • sloc: ansic: 93,691; sh: 12,051; cpp: 1,215; makefile: 1,079; objc: 263; yacc: 152; tcl: 76; lex: 74
file content (138 lines) | stat: -rw-r--r-- 3,720 bytes parent folder | download | duplicates (3)
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
/* Copyright (C) 2006-2007 Claus-Justus Heine 
 *
 * This file is part of Geomview.
 * 
 * Geomview is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * Geomview 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Geomview; see the file COPYING.  If not, write
 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
 * USA, or visit http://www.gnu.org.
 */

/* simplistic help-system spawner (i.e. view the manual via external
 * browsers)
 */

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "lisp.h"

static char htmlbrowser[PATH_MAX] = { '\0', }, pdfviewer[PATH_MAX] = { '\0', };

void ui_manual_browser(const char *type)
{
  char helper[PATH_MAX];
  char *docdir;
  char *browser;
  char *lang;
  const char *file = NULL, *dfltfile, *langfile;
  
  if ((docdir = getenv("GEOMVIEW_DOC_DIR")) == NULL) {
    docdir = DOCDIR; /* compile-time default */
  }

  if (strncasecmp(type, "html", strlen("html")) == 0) {
    if (*htmlbrowser == '\0') {
      if ((browser = getenv("WEBBROWSER")) == NULL) {
	browser = DFLTHTMLBROWSER;
      }
    } else {
      browser = htmlbrowser;
    }
    dfltfile = "%s/html/index.html";
    langfile = "%s/html/%s/index.html";
  } else { /* if (strncasecmp(type, "pdf", strlen("pdf")) == 0) { */
    if (*pdfviewer == '\0') {
      if ((browser = getenv("PDFVIEWER")) == NULL) {
	browser = DFLTPDFVIEWER;
      }
    } else {
      browser = pdfviewer;
    }
    dfltfile = "%s/geomview.pdf";
    langfile = "%s/geomview-%s.pdf";
  }

  if ((lang = getenv("LANG")) != NULL) {
    snprintf(helper, PATH_MAX, langfile, docdir, lang);
    file = findfile(NULL, helper);
  }
  if (file == NULL) {
    snprintf(helper, PATH_MAX, dfltfile, docdir);
    file = findfile(NULL, helper);
  }
  if (file == NULL) {
    OOGLError(0, "Unable to locate the Geomview manual (\"%s\").", helper);
  } else {
    int dummy;
    snprintf(helper, PATH_MAX, "%s %s &", browser, file);
    dummy = system(helper);
    (void)dummy;
  }
}

LDEFINE(ui_html_browser, LVOID,
	"(ui-html-browser HTMLBROWSER)\n"
	"Use HTMLBROWSER when the `Manual (HTML)' menu item is selected "
	"in the help menu. If the `(ui-html-browser...)' command was never "
	"executed, then the default is to use the browser stored in the "
	"`WEBBROWSER' environment variable. If the environment variable is "
	"unset then `"DFLTHTMLBROWSER"' is used.")
{
  char *browser = NULL;
  
  LDECLARE(("ui-html-browser", LBEGIN,
	    LSTRING, &browser,
	    LEND));
  
  if (browser != NULL) {
    strncpy(htmlbrowser, browser, PATH_MAX);
  }
  
  return Lt;
}

LDEFINE(ui_pdf_viewer, LVOID,
	"(ui-pdf-browser PDFVIEWER\n"
	"Use PDFVIEWER when the `Manual (PDF)' menu item is selected "
	"in the help menu. If the `(ui-pdf-viewer...)' command was never "
	"executed, then the default is to use the viewer stored in the "
	"`PDFVIEWER' environment variable. If the environment variable is "
	"unset then `"DFLTPDFVIEWER"' is used.")
{
  char *browser = NULL;
  
  LDECLARE(("ui-pdf-viewer", LBEGIN,
	    LSTRING, &browser,
	    LEND));
  
  if (browser != NULL) {
    strncpy(pdfviewer, browser, PATH_MAX);
  }
  
  return Lt;
}




/*
 * Local Variables: ***
 * c-basic-offset: 2 ***
 * End: ***
 */