2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: dtksh.c /main/3 1995/11/01 15:53:19 rswiston $ */
24 /* Copyright (c) 1991, 1992 UNIX System Laboratories, Inc. */
25 /* All Rights Reserved */
27 /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */
28 /* UNIX System Laboratories, Inc. */
29 /* The copyright notice above does not evidence any */
30 /* actual or intended publication of such source code. */
38 #define CONSTCHAR (const char *)
43 #define DTKSHBINDIR "/usr/bin"
53 sprintf(path, "%s/%s", dir, file);
54 return(stat(path, &sbuf) != -1);
58 * Bootstrap dtksh by calling xmcoeksh and forcing it to execute
59 * an rc file that calls the dtksh init function and does some
60 * other minor housekeeping.
62 * The rc file then sees if there was a previous user rc file (in $_HOLDENV_)
63 * and if so executes it.
73 char *executable, *envfile;
78 * Set the ENV variable to the standard dtksh rc file, which
79 * will do a libdirload of the dtksh shared object file and add all
80 * the dtksh commands and widgets to the exksh. If the user already
81 * had an ENV file, then set the variable _HOLDENV_ to it so the
82 * standard dtksh rc file can execute it later.
84 env = getenv((const char *)"ENV");
85 buf = (char *)malloc((env ? strlen(env) : 0) + 12);
86 strcpy(buf, "_HOLDENV_=");
87 strcat(buf, env ? env : "");
90 executable = "xmcoeksh";
91 envfile = "xmcoeksh.rc";
94 * Search order for DTKSH binaries:
96 * 1. if $DTKSHBINDIR is set, use that path if it exists.
97 * 2. if the hard-wired #define DTKSHBINDIR is set and is a
98 * readable directory, use it.
102 if ((bindir = getenv((const char *)"DTKSHBINDIR")) != NULL) {
103 if ((!FileExists(bindir, executable)) ||
104 (!FileExists(bindir, envfile)))
112 bindir = DTKSHBINDIR;
114 if ((!FileExists(bindir, executable)) ||
115 (!FileExists(bindir, envfile)))
121 if (bindir == NULL) {
123 "dtksh: bootstrap failed. Unable to locate both\nxmcoeksh and xmcoeksh.rc in the same directory.\n Try setting $DTKSHBINDIR.\n");
126 sprintf(envbuf, "DTKSHBINDIR=%s", bindir);
127 putenv(strdup(envbuf));
129 sprintf(envbuf, "ENV=%s/%s", bindir, envfile);
130 putenv(strdup(envbuf));
131 sprintf(envbuf, "%s/%s", bindir, executable);
134 fprintf(stderr, "dtksh: Bootstrap of dtksh failed: '%s'\n", envbuf);
136 return(1); /* failure */