1 /* Copyright (C) 2006-2007 Claus-Justus Heine
2  *
3  * This file is part of Geomview.
4  *
5  * Geomview is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * Geomview is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with Geomview; see the file COPYING.  If not, write
17  * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
18  * USA, or visit http://www.gnu.org.
19  */
20 
21 /* simplistic help-system spawner (i.e. view the manual via external
22  * browsers)
23  */
24 
25 #if HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28 
29 #include <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 
33 #include "lisp.h"
34 
35 static char htmlbrowser[PATH_MAX] = { '\0', }, pdfviewer[PATH_MAX] = { '\0', };
36 
ui_manual_browser(const char * type)37 void ui_manual_browser(const char *type)
38 {
39   char helper[PATH_MAX];
40   char *docdir;
41   char *browser;
42   char *lang;
43   const char *file = NULL, *dfltfile, *langfile;
44 
45   if ((docdir = getenv("GEOMVIEW_DOC_DIR")) == NULL) {
46     docdir = DOCDIR; /* compile-time default */
47   }
48 
49   if (strncasecmp(type, "html", strlen("html")) == 0) {
50     if (*htmlbrowser == '\0') {
51       if ((browser = getenv("WEBBROWSER")) == NULL) {
52 	browser = DFLTHTMLBROWSER;
53       }
54     } else {
55       browser = htmlbrowser;
56     }
57     dfltfile = "%s/html/index.html";
58     langfile = "%s/html/%s/index.html";
59   } else { /* if (strncasecmp(type, "pdf", strlen("pdf")) == 0) { */
60     if (*pdfviewer == '\0') {
61       if ((browser = getenv("PDFVIEWER")) == NULL) {
62 	browser = DFLTPDFVIEWER;
63       }
64     } else {
65       browser = pdfviewer;
66     }
67     dfltfile = "%s/geomview.pdf";
68     langfile = "%s/geomview-%s.pdf";
69   }
70 
71   if ((lang = getenv("LANG")) != NULL) {
72     snprintf(helper, PATH_MAX, langfile, docdir, lang);
73     file = findfile(NULL, helper);
74   }
75   if (file == NULL) {
76     snprintf(helper, PATH_MAX, dfltfile, docdir);
77     file = findfile(NULL, helper);
78   }
79   if (file == NULL) {
80     OOGLError(0, "Unable to locate the Geomview manual (\"%s\").", helper);
81   } else {
82     int dummy;
83     snprintf(helper, PATH_MAX, "%s %s &", browser, file);
84     dummy = system(helper);
85     (void)dummy;
86   }
87 }
88 
89 LDEFINE(ui_html_browser, LVOID,
90 	"(ui-html-browser HTMLBROWSER)\n"
91 	"Use HTMLBROWSER when the `Manual (HTML)' menu item is selected "
92 	"in the help menu. If the `(ui-html-browser...)' command was never "
93 	"executed, then the default is to use the browser stored in the "
94 	"`WEBBROWSER' environment variable. If the environment variable is "
95 	"unset then `"DFLTHTMLBROWSER"' is used.")
96 {
97   char *browser = NULL;
98 
99   LDECLARE(("ui-html-browser", LBEGIN,
100 	    LSTRING, &browser,
101 	    LEND));
102 
103   if (browser != NULL) {
104     strncpy(htmlbrowser, browser, PATH_MAX);
105   }
106 
107   return Lt;
108 }
109 
110 LDEFINE(ui_pdf_viewer, LVOID,
111 	"(ui-pdf-browser PDFVIEWER\n"
112 	"Use PDFVIEWER when the `Manual (PDF)' menu item is selected "
113 	"in the help menu. If the `(ui-pdf-viewer...)' command was never "
114 	"executed, then the default is to use the viewer stored in the "
115 	"`PDFVIEWER' environment variable. If the environment variable is "
116 	"unset then `"DFLTPDFVIEWER"' is used.")
117 {
118   char *browser = NULL;
119 
120   LDECLARE(("ui-pdf-viewer", LBEGIN,
121 	    LSTRING, &browser,
122 	    LEND));
123 
124   if (browser != NULL) {
125     strncpy(pdfviewer, browser, PATH_MAX);
126   }
127 
128   return Lt;
129 }
130 
131 
132 
133 
134 /*
135  * Local Variables: ***
136  * c-basic-offset: 2 ***
137  * End: ***
138  */
139