builtins.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $XConsortium: builtins.c /main/3 1995/11/01 15:50:47 rswiston $ */
  24. /***************************************************************
  25. * *
  26. * AT&T - PROPRIETARY *
  27. * *
  28. * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF *
  29. * AT&T BELL LABORATORIES *
  30. * AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN *
  31. * ACCORDANCE WITH APPLICABLE AGREEMENTS *
  32. * *
  33. * Copyright (c) 1994 AT&T Bell Laboratories *
  34. * Unpublished & Not for Publication *
  35. * All Rights Reserved *
  36. * *
  37. * The copyright notice above does not evidence any *
  38. * actual or intended publication of such source code *
  39. * *
  40. * This software was created by the *
  41. * Advanced Software Technology Department *
  42. * AT&T Bell Laboratories *
  43. * *
  44. * For further information contact *
  45. * {research,attmail}!dgk *
  46. * dgk@research.att.com *
  47. * David Korn 908-582-7975 *
  48. * *
  49. ***************************************************************/
  50. /* : : generated by proto : : */
  51. #line 1
  52. #if !defined(__PROTO__)
  53. #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
  54. #if defined(__cplusplus)
  55. #define __MANGLE__ "C"
  56. #else
  57. #define __MANGLE__
  58. #endif
  59. #define __STDARG__
  60. #define __PROTO__(x) x
  61. #define __OTORP__(x)
  62. #define __PARAM__(n,o) n
  63. #if !defined(__STDC__) && !defined(__cplusplus)
  64. #if !defined(c_plusplus)
  65. #define const
  66. #endif
  67. #define signed
  68. #define void int
  69. #define volatile
  70. #define __V_ char
  71. #else
  72. #define __V_ void
  73. #endif
  74. #else
  75. #define __PROTO__(x) ()
  76. #define __OTORP__(x) x
  77. #define __PARAM__(n,o) o
  78. #define __MANGLE__
  79. #define __V_ char
  80. #define const
  81. #define signed
  82. #define void int
  83. #define volatile
  84. #endif
  85. #if defined(__cplusplus) || defined(c_plusplus)
  86. #define __VARARG__ ...
  87. #else
  88. #define __VARARG__
  89. #endif
  90. #if defined(__STDARG__)
  91. #define __VA_START__(p,a) va_start(p,a)
  92. #else
  93. #define __VA_START__(p,a) va_start(p)
  94. #endif
  95. #endif
  96. #line 3
  97. #define mount _AST_mount
  98. #include <shell.h>
  99. #include <signal.h>
  100. #include "shtable.h"
  101. #include "name.h"
  102. #ifdef KSHELL
  103. # include "builtins.h"
  104. # include "jobs.h"
  105. # include "FEATURE/cmds"
  106. #if defined(__STDC__) || defined(__STDPP__)
  107. # define bltin(x) (b_##x)
  108. #else
  109. # define bltin(x) (b_/**/x)
  110. #endif
  111. #line 13
  112. #else
  113. # define bltin(x) 0
  114. #endif
  115. #include <X11/X.h>
  116. #include <X11/Intrinsic.h>
  117. #include <X11/IntrinsicP.h>
  118. #define NO_AST
  119. #include "dtksh.h"
  120. #undef NO_AST
  121. #include "dtextra.h"
  122. #include "xmextra.h"
  123. #include "msgs.h"
  124. /*
  125. * The order up through "[" is significant
  126. */
  127. const struct shtable3 shtab_builtins[] =
  128. {
  129. "login", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(login),
  130. "exec", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(exec),
  131. "set", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(set),
  132. ":", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(true),
  133. "true", NV_BLTIN|BLT_ENV, bltin(true),
  134. "command", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(command),
  135. "cd", NV_BLTIN|BLT_ENV, bltin(cd),
  136. "break", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(brk_cont),
  137. "continue", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(brk_cont),
  138. "typeset", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(typeset),
  139. "test", NV_BLTIN|BLT_ENV|NV_NOFREE, bltin(test),
  140. "[", NV_BLTIN|BLT_ENV, bltin(test),
  141. #ifdef _bin_newgrp
  142. "newgrp", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(login),
  143. #endif /* _bin_newgrp */
  144. ".", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(dot_cmd),
  145. "alias", NV_BLTIN|BLT_SPC|BLT_DCL, bltin(alias),
  146. "hash", NV_BLTIN|BLT_SPC|BLT_DCL, bltin(alias),
  147. "exit", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(ret_exit),
  148. "export", NV_BLTIN|BLT_SPC|BLT_DCL, bltin(read_export),
  149. "eval", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_EXIT,bltin(eval),
  150. "fc", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(hist),
  151. "hist", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(hist),
  152. "readonly", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(read_export),
  153. "return", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(ret_exit),
  154. "shift", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(shift),
  155. "trap", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(trap),
  156. "unalias", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(unalias),
  157. "unset", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(unset),
  158. "builtin", NV_BLTIN, bltin(builtin),
  159. #ifdef SHOPT_ECHOPRINT
  160. "echo", NV_BLTIN|BLT_ENV, bltin(print),
  161. #else
  162. "echo", NV_BLTIN|BLT_ENV, bltin(echo),
  163. #endif /* SHOPT_ECHOPRINT */
  164. #ifdef JOBS
  165. # ifdef SIGTSTP
  166. "bg", NV_BLTIN|BLT_ENV, bltin(bg_fg),
  167. "fg", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(bg_fg),
  168. "disown", NV_BLTIN|BLT_ENV, bltin(bg_fg),
  169. "kill", NV_BLTIN|BLT_ENV|NV_NOFREE, bltin(kill),
  170. # else
  171. "/bin/kill", NV_BLTIN|BLT_ENV|NV_NOFREE, bltin(kill),
  172. # endif /* SIGTSTP */
  173. "jobs", NV_BLTIN|BLT_ENV, bltin(jobs),
  174. #endif /* JOBS */
  175. "false", NV_BLTIN|BLT_ENV, bltin(false),
  176. "getconf", NV_BLTIN|BLT_ENV, bltin(getconf),
  177. "getopts", NV_BLTIN|BLT_ENV, bltin(getopts),
  178. "let", NV_BLTIN|BLT_ENV, bltin(let),
  179. "print", NV_BLTIN|BLT_ENV, bltin(print),
  180. "printf", NV_BLTIN|NV_NOFREE, bltin(printf),
  181. "pwd", NV_BLTIN|NV_NOFREE, bltin(pwd),
  182. "read", NV_BLTIN|BLT_ENV, bltin(read),
  183. "sleep", NV_BLTIN|NV_NOFREE, bltin(sleep),
  184. "alarm", NV_BLTIN, bltin(alarm),
  185. "ulimit", NV_BLTIN|BLT_ENV, bltin(ulimit),
  186. "umask", NV_BLTIN|BLT_ENV, bltin(umask),
  187. #ifdef _cmd_universe
  188. "universe", NV_BLTIN|BLT_ENV, bltin(universe),
  189. #endif /* _cmd_universe */
  190. #ifdef SHOPT_FS_3D
  191. "vpath", NV_BLTIN|BLT_ENV, bltin(vpath_map),
  192. "vmap", NV_BLTIN|BLT_ENV, bltin(vpath_map),
  193. #endif /* SHOPT_FS_3D */
  194. "wait", NV_BLTIN|BLT_ENV|BLT_EXIT, bltin(wait),
  195. "type", NV_BLTIN|BLT_ENV, bltin(whence),
  196. "whence", NV_BLTIN|BLT_ENV, bltin(whence),
  197. #ifdef apollo
  198. "inlib", NV_BLTIN|BLT_ENV, bltin(inlib),
  199. "rootnode", NV_BLTIN, bltin(rootnode),
  200. "ver", NV_BLTIN, bltin(ver),
  201. #endif /* apollo */
  202. "/bin/basename",NV_BLTIN|NV_NOFREE, bltin(basename),
  203. "/bin/chmod", NV_BLTIN|NV_NOFREE, bltin(chmod),
  204. "/bin/dirname", NV_BLTIN|NV_NOFREE, bltin(dirname),
  205. "/bin/head", NV_BLTIN|NV_NOFREE, bltin(head),
  206. "/bin/mkdir", NV_BLTIN|NV_NOFREE, bltin(mkdir),
  207. #if defined(_usr_bin_logname) && !defined(_bin_logname)
  208. "/usr/bin/logname", NV_BLTIN|NV_NOFREE, bltin(logname),
  209. #else
  210. "/bin/logname", NV_BLTIN|NV_NOFREE, bltin(logname),
  211. #endif
  212. "/bin/cat", NV_BLTIN|NV_NOFREE, bltin(cat),
  213. "/bin/cmp", NV_BLTIN|NV_NOFREE, bltin(cmp),
  214. #if defined(_usr_bin_cut) && !defined(_bin_cut)
  215. "/usr/bin/cut", NV_BLTIN|NV_NOFREE, bltin(cut),
  216. #else
  217. "/bin/cut", NV_BLTIN|NV_NOFREE, bltin(cut),
  218. #endif
  219. "/bin/uname", NV_BLTIN|NV_NOFREE, bltin(uname),
  220. #if defined(_usr_bin_wc) && !defined(_bin_wc)
  221. "/usr/bin/wc", NV_BLTIN|NV_NOFREE, bltin(wc),
  222. #else
  223. # if defined(_usr_ucb_wc) && !defined(_bin_wc)
  224. "/usr/ucb/wc", NV_BLTIN|NV_NOFREE, bltin(wc),
  225. # else
  226. "/bin/wc", NV_BLTIN|NV_NOFREE, bltin(wc),
  227. # endif
  228. #endif
  229. DTK_EXTRA_TABLE
  230. DTK_EXTRA_TABLE2
  231. DTK_TK_EXTRA_TABLE
  232. DTK_TK_LIST_TABLE
  233. DTK_TK_TEXT_TABLE
  234. "", 0, 0
  235. };
  236. const char sh_optalarm[] = "r [varname seconds]";
  237. const char sh_optalias[] = "ptx [name=[value]...]";
  238. const char sh_optbuiltin[] = "dsf:[library] [name...]";
  239. const char sh_optcd[] = "LP [dir] [change]";
  240. const char sh_optcflow[] = " [n]";
  241. const char sh_optcommand[] = "pvV name [arg]...";
  242. const char sh_optdot[] = " name [arg...]";
  243. #ifndef ECHOPRINT
  244. const char sh_optecho[] = " [-n] [arg...]";
  245. #endif /* !ECHOPRINT */
  246. const char sh_opteval[] = " [arg...]";
  247. const char sh_optexec[] = "a:[name]c [command [args...] ]";
  248. const char sh_optexport[] = "p [name[=value]...]";
  249. const char sh_optgetopts[] = ":a:[name] optstring name [args...]";
  250. const char sh_optgetconf[] = " [name [pathname] ]";
  251. const char sh_optjoblist[] = " [job...]";
  252. const char sh_opthist[] = "e:[editor]lnrsN# [first] [last]";
  253. const char sh_optjobs[] = "nlp [job...]";
  254. const char sh_optkill[] = "ln#[signum]s:[signame] sig...";
  255. const char sh_optlet[] = " expr...";
  256. const char sh_optprint[] = "f:[format]enprsu:[filenum] [arg...]";
  257. const char sh_optprintf[] = " format [arg...]";
  258. const char sh_optpwd[] = "LP";
  259. const char sh_optread[] = "Ad:[delim]prst#[timeout]u#[filenum] [name...]";
  260. #ifdef SHOPT_KIA
  261. const char sh_optksh[] = "+DircabefhkmnpstuvxCR:[file]o:?[option] [arg...]";
  262. const char sh_optset[] = "+abefhkmnpstuvxCR:[file]o:?[option]A:[name] [arg...]";
  263. #else
  264. const char sh_optksh[] = "+DircabefhkmnpstuvxCo:?[option] [arg...]";
  265. const char sh_optset[] = "+abefhkmnpstuvxCo:?[option]A:[name] [arg...]";
  266. #endif /* SHOPT_KIA */
  267. const char sh_optsleep[] = " seconds";
  268. const char sh_opttrap[] = "p [action condition...]";
  269. #ifdef SHOPT_OO
  270. const char sh_opttypeset[] = "+AC:E#?F#?H:[name]L#?R#?Z#?fi#?[base]lnprtux [name=[value]...]";
  271. #else
  272. const char sh_opttypeset[] = "+AE#?F#?HL#?R#?Z#?fi#?[base]lnprtux [name=[value]...]";
  273. #endif /* SHOPT_OO */
  274. const char sh_optulimit[] = "HSacdfmnstv [limit]";
  275. const char sh_optumask[] = "S [mask]";
  276. const char sh_optuniverse[] = " [name]";
  277. const char sh_optunset[] = "fnv name...";
  278. const char sh_optunalias[] = "a name...";
  279. #ifdef SHOPT_FS_3D
  280. const char sh_optvpath[] = " [top] [base]";
  281. const char sh_optvmap[] = " [dir] [list]";
  282. #endif /* SHOPT_FS_3D */
  283. const char sh_optwhence[] = "afpv name...";
  284. const char e_alrm1[] = "alarm -r %s +%.3g\n";
  285. const char e_alrm2[] = "alarm %s %.3f\n";
  286. const char e_badfun[] = "%s: illegal function name";
  287. const char e_baddisc[] = "%s: invalid discipline function";
  288. const char e_nospace[] = "out of memory";
  289. const char e_nofork[] = "cannot fork";
  290. const char e_nosignal[] = "%s: unknown signal name";
  291. const char e_numeric[] = "*([0-9])?(.)*([0-9])";
  292. const char e_condition[] = "condition(s) required";
  293. const char e_cneedsarg[] = "-c requires argument";