Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/tksh/uinit.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1996-2012 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* David Korn <[email protected]> *
18
* Jeff Korn <@google.com> *
19
* *
20
***********************************************************************/
21
#pragma prototyped
22
23
#include "tksh.h"
24
25
static char **av;
26
static int ac;
27
28
static void tksh_userinit(Shell_t* shp, int subshell)
29
{
30
char *end = av[0] + strlen(av[0]);
31
int len = strlen(av[0]);
32
char *args[2];
33
Namval_t *np;
34
35
if(np = nv_open("source",shp->alias_tree,NV_NOADD))
36
{
37
nv_unset(np);
38
nv_close(np);
39
}
40
if (subshell < 0)
41
{
42
if(nv_open("tkloop",shp->fun_tree,NV_NOADD))
43
sh_trap("tkloop", 0);
44
return;
45
}
46
else if (subshell > 0)
47
{
48
TkshSubShell();
49
return;
50
}
51
52
#ifndef DO_TK
53
/* sfsetbuf(sfstdout, NULL, 0); */
54
args[0] = av[0]; args[1] = NULL;
55
if ((len >= 4) && (strcmp(end-4, "tksh") == 0))
56
/* b_tkinit(0, (char **) 0, (void *) 0); */
57
b_tkinit(1, args, (Shbltin_t *) 0);
58
else if ((len >= 6) && (strcmp(end-6, "tclksh") == 0))
59
/* b_tclinit(0, (char **) 0, (void *) 0); */
60
b_tclinit(1, args, (Shbltin_t *) 0);
61
else
62
{
63
sh_addbuiltin("tclinit", b_tclinit, (void *) 0);
64
sh_addbuiltin("tkinit", b_tkinit, (void *) 0);
65
}
66
#else
67
sh_addbuiltin("tkinit", b_tkinit, (void *) 0);
68
if ((len >= 6) && (strcmp(end-6, "tclksh") == 0))
69
b_tclinit(0, (char **) 0, (Shbltin_t *) 0);
70
else
71
sh_addbuiltin("tclinit", b_tclinit, (void *) 0);
72
#endif
73
}
74
75
int main(int argc, char *argv[])
76
{
77
return (sh_main(ac=argc, av=argv, tksh_userinit));
78
}
79
80