1 /*	$OpenBSD: help.c,v 1.5 2003/04/14 14:33:57 millert Exp $	*/
2 
3 /*
4  * Copyright (c) 1984,1985,1989,1994,1995  Mark Nudelman
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice in the documentation and/or other materials provided with
14  *    the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
22  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 /*
31  * Display some help.
32  * Just invoke another "less" to display the help file.
33  *
34  * {{ This makes this function very simple, and makes changing the
35  *    help file very easy, but it may present difficulties on
36  *    (non-Unix) systems which do not supply the "system()" function. }}
37  */
38 
39 #include  "less.h"
40 
41 extern char *progname;
42 
43 	public void
help(nomsg)44 help(nomsg)
45 	int nomsg;
46 {
47 #ifdef HELPFILE
48 	char *helpfile;
49 	char *cmd;
50 	size_t len;
51 
52 	helpfile = find_helpfile();
53 	if (helpfile == NULL)
54 	{
55 		error("Cannot find help file", NULL_PARG);
56 		return;
57 	}
58 #if !HAVE_SYSTEM
59 	/*
60 	 * Just examine the help file.
61 	 */
62 	(void) edit(helpfile);
63 #else
64 	/*
65 	 * Use lsystem() to invoke a new instance of less
66 	 * to view the help file.
67 	 */
68 #if MSDOS_COMPILER
69 	putenv("LESS=-m -H -+E -+s -PmHELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done");
70 	len = strlen(helpfile) + strlen(progname) + 3;
71 	cmd = (char *) ecalloc(len, sizeof(char));
72 	snprintf(cmd, len, "-%s %s", progname, helpfile);
73 #else
74 	len = strlen(helpfile) + strlen(progname) + 150;
75 	cmd = (char *) ecalloc(len, sizeof(char));
76 #if OS2
77 	snprintf(cmd, len,
78 	 "-%s -m -H -+E -+s \"-PmHELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done \" %s",
79 		progname, helpfile);
80 #else
81 	snprintf(cmd, len,
82 	 "-%s -m -H -+E -+s '-PmHELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done ' %s",
83 		progname, helpfile);
84 #endif
85 #endif
86 	free(helpfile);
87 	lsystem(cmd, (char*)NULL);
88 	if (!nomsg)
89 		error("End of help", NULL_PARG);
90 	free(cmd);
91 #endif
92 #else
93 	error("Cannot find help file", NULL_PARG);
94 #endif
95 }
96