Darling build of shell_cmds-207.40.1

Note: I didn't really look through much of the Xcode build files; I only added stuff that changed. Everything looks good and builds, but it might need to be reviewed later.
This commit is contained in:
Ariel Abreu 2020-08-19 09:55:53 -04:00
parent 74fe64ca01
commit 411ea2ba68
No known key found for this signature in database
GPG Key ID: ECF8C2B9E8AD3E6B
10 changed files with 1192 additions and 7 deletions

3
.gitignore vendored
View File

@ -2,3 +2,6 @@
xcuserdata/
build/
project.xcworkspace/
gen/sh/mknodes
gen/sh/mksyntax

View File

@ -6,8 +6,9 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
include(darling_exe)
# add_definitions(-DSUPPORT_UTMPX)
add_compile_definitions(
__FBSDID=__RCSID
)
add_definitions(
-Wno-incompatible-pointer-types
@ -49,15 +50,21 @@ add_darling_executable(shlock shlock/shlock.c)
add_darling_executable(sleep sleep/sleep.c)
add_darling_executable(systime systime/systime.c)
add_darling_executable(tee tee/tee.c)
#add_darling_executable(test-bin test/test.c)
#set_target_properties(test-bin PROPERTIES OUTPUT_NAME test)
add_darling_executable(test-bin test/test.c)
set_target_properties(test-bin PROPERTIES OUTPUT_NAME test)
add_darling_executable(time time/time.c)
add_darling_executable(uname uname/uname.c)
add_darling_executable(users users/users.c)
add_darling_executable(what what/what.c)
add_darling_executable(whereis whereis/whereis.c)
add_darling_executable(which which/which.c)
#add_darling_executable(who who/who.c who/utmpentry.c)
add_darling_executable(who who/who.c who/utmpentry.c)
target_compile_definitions(who PRIVATE
_UTMPX_COMPAT
SUPPORT_UTMPX
)
add_darling_executable(xargs xargs/strnsubst.c xargs/xargs.c)
add_darling_executable(find find/find.c find/function.c find/ls.c find/main.c find/misc.c find/operator.c find/option.c ${CMAKE_CURRENT_BINARY_DIR}/find_getdate.c)
add_darling_executable(hexdump hexdump/conv.c hexdump/display.c hexdump/hexdump.c hexdump/hexsyntax.c hexdump/odsyntax.c hexdump/parse.c)
@ -68,13 +75,20 @@ add_darling_executable(logname logname/logname.c)
add_darling_executable(path_helper path_helper/path_helper.c)
add_darling_executable(expr ${CMAKE_CURRENT_BINARY_DIR}/expr.c)
install(TARGETS date echo pwd kill sleep expr
# Apple now includes ash (predecessor of dash), but it seems they don't install it
# according to `sh.xcconfig`, there are plans to replace `/bin/sh` with ash, but for now they still use the bash version
# so for now, if users want this, they have to use ADDITIONAL_PACKAGES
if(ADDITIONAL_PACKAGES)
add_subdirectory(sh)
endif()
install(TARGETS date echo pwd kill sleep expr test-bin
DESTINATION libexec/darling/bin)
install(TARGETS env which basename dirname apply nohup getopt true false killall mktemp
nice printenv printf renice script seq systime shlock id
tee time uname jot lastcomm logname
users what whereis xargs find hexdump hostname yes
users what whereis xargs find hexdump hostname yes who
DESTINATION libexec/darling/usr/bin)
install(TARGETS path_helper DESTINATION libexec/darling/usr/libexec

102
gen/sh/builtins.c Normal file
View File

@ -0,0 +1,102 @@
/*
* This file was generated by the mkbuiltins program.
*/
#include <stdlib.h>
#include "shell.h"
#include "builtins.h"
int (*const builtinfunc[])(int, char **) = {
bltincmd,
aliascmd,
bgcmd,
bindcmd,
breakcmd,
cdcmd,
commandcmd,
dotcmd,
echocmd,
evalcmd,
execcmd,
exitcmd,
letcmd,
exportcmd,
falsecmd,
fgcmd,
freebsd_wordexpcmd,
getoptscmd,
hashcmd,
histcmd,
jobidcmd,
jobscmd,
killcmd,
localcmd,
printfcmd,
pwdcmd,
readcmd,
returncmd,
setcmd,
setvarcmd,
shiftcmd,
testcmd,
timescmd,
trapcmd,
truecmd,
typecmd,
ulimitcmd,
umaskcmd,
unaliascmd,
unsetcmd,
waitcmd,
wordexpcmd,
};
const unsigned char builtincmd[] = {
"\007\000builtin"
"\005\001alias"
"\002\002bg"
"\004\003bind"
"\005\204break"
"\010\204continue"
"\002\005cd"
"\005\005chdir"
"\007\006command"
"\001\207."
"\004\010echo"
"\004\211eval"
"\004\212exec"
"\004\213exit"
"\003\014let"
"\006\215export"
"\010\215readonly"
"\005\016false"
"\002\017fg"
"\017\020freebsd_wordexp"
"\007\021getopts"
"\004\022hash"
"\002\023fc"
"\005\024jobid"
"\004\025jobs"
"\004\026kill"
"\005\027local"
"\006\030printf"
"\003\031pwd"
"\004\032read"
"\006\233return"
"\003\234set"
"\006\035setvar"
"\005\236shift"
"\004\037test"
"\001\037["
"\005\240times"
"\004\241trap"
"\001\242:"
"\004\042true"
"\004\043type"
"\006\044ulimit"
"\005\045umask"
"\007\046unalias"
"\005\247unset"
"\004\050wait"
"\007\051wordexp"
};

115
gen/sh/builtins.h Normal file
View File

@ -0,0 +1,115 @@
/*
* This file was generated by the mkbuiltins program.
*/
#include <sys/cdefs.h>
#define BLTINCMD 0
#define ALIASCMD 1
#define BGCMD 2
#define BINDCMD 3
#define BREAKCMD 4
#define CDCMD 5
#define COMMANDCMD 6
#define DOTCMD 7
#define ECHOCMD 8
#define EVALCMD 9
#define EXECCMD 10
#define EXITCMD 11
#define LETCMD 12
#define EXPORTCMD 13
#define FALSECMD 14
#define FGCMD 15
#define FREEBSD_WORDEXPCMD 16
#define GETOPTSCMD 17
#define HASHCMD 18
#define HISTCMD 19
#define JOBIDCMD 20
#define JOBSCMD 21
#define KILLCMD 22
#define LOCALCMD 23
#define PRINTFCMD 24
#define PWDCMD 25
#define READCMD 26
#define RETURNCMD 27
#define SETCMD 28
#define SETVARCMD 29
#define SHIFTCMD 30
#define TESTCMD 31
#define TIMESCMD 32
#define TRAPCMD 33
#define TRUECMD 34
#define TYPECMD 35
#define ULIMITCMD 36
#define UMASKCMD 37
#define UNALIASCMD 38
#define UNSETCMD 39
#define WAITCMD 40
#define WORDEXPCMD 41
#define BUILTIN_SPECIAL 0x80
extern int (*const builtinfunc[])(int, char **);
extern const unsigned char builtincmd[];
int bltincmd(int, char **);
int aliascmd(int, char **);
int bgcmd(int, char **);
int bindcmd(int, char **);
int breakcmd(int, char **);
int cdcmd(int, char **);
int commandcmd(int, char **);
int dotcmd(int, char **);
int echocmd(int, char **);
int evalcmd(int, char **);
int execcmd(int, char **);
int exitcmd(int, char **);
int letcmd(int, char **);
int exportcmd(int, char **);
int falsecmd(int, char **);
int fgcmd(int, char **);
int freebsd_wordexpcmd(int, char **);
int getoptscmd(int, char **);
int hashcmd(int, char **);
int histcmd(int, char **);
int jobidcmd(int, char **);
int jobscmd(int, char **);
int killcmd(int, char **);
int localcmd(int, char **);
int printfcmd(int, char **);
int pwdcmd(int, char **);
int readcmd(int, char **);
int returncmd(int, char **);
int setcmd(int, char **);
int setvarcmd(int, char **);
int shiftcmd(int, char **);
int testcmd(int, char **);
int timescmd(int, char **);
int trapcmd(int, char **);
int truecmd(int, char **);
int typecmd(int, char **);
int ulimitcmd(int, char **);
int umaskcmd(int, char **);
int unaliascmd(int, char **);
int unsetcmd(int, char **);
int waitcmd(int, char **);
int wordexpcmd(int, char **);
static inline int
safe_builtin_always(int idx)
{
if (idx == BLTINCMD ||
idx == COMMANDCMD ||
idx == ECHOCMD ||
idx == FALSECMD ||
idx == JOBIDCMD ||
idx == JOBSCMD ||
idx == KILLCMD ||
idx == PRINTFCMD ||
idx == PWDCMD ||
idx == TESTCMD ||
idx == TIMESCMD ||
idx == TRUECMD ||
idx == TYPECMD)
return (1);
return(0);
}

376
gen/sh/nodes.c Normal file
View File

@ -0,0 +1,376 @@
/*
* This file was generated by the mknodes program.
*/
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nodes.c.pat 8.2 (Berkeley) 5/4/95
* $FreeBSD: head/bin/sh/nodes.c.pat 314436 2017-02-28 23:42:47Z imp $
*/
#include <sys/param.h>
#include <stdlib.h>
#include <stddef.h>
/*
* Routine for dealing with parsed shell commands.
*/
#include "shell.h"
#include "nodes.h"
#include "memalloc.h"
#include "mystring.h"
struct nodesize {
int blocksize; /* size of structures in function */
int stringsize; /* size of strings in node */
};
struct nodecopystate {
pointer block; /* block to allocate function from */
char *string; /* block to allocate strings from */
};
static const short nodesize[27] = {
ALIGN(sizeof (struct nbinary)),
ALIGN(sizeof (struct ncmd)),
ALIGN(sizeof (struct npipe)),
ALIGN(sizeof (struct nredir)),
ALIGN(sizeof (struct nredir)),
ALIGN(sizeof (struct nredir)),
ALIGN(sizeof (struct nbinary)),
ALIGN(sizeof (struct nbinary)),
ALIGN(sizeof (struct nif)),
ALIGN(sizeof (struct nbinary)),
ALIGN(sizeof (struct nbinary)),
ALIGN(sizeof (struct nfor)),
ALIGN(sizeof (struct ncase)),
ALIGN(sizeof (struct nclist)),
ALIGN(sizeof (struct nclist)),
ALIGN(sizeof (struct narg)),
ALIGN(sizeof (struct narg)),
ALIGN(sizeof (struct nfile)),
ALIGN(sizeof (struct nfile)),
ALIGN(sizeof (struct nfile)),
ALIGN(sizeof (struct nfile)),
ALIGN(sizeof (struct nfile)),
ALIGN(sizeof (struct ndup)),
ALIGN(sizeof (struct ndup)),
ALIGN(sizeof (struct nhere)),
ALIGN(sizeof (struct nhere)),
ALIGN(sizeof (struct nnot)),
};
static void calcsize(union node *, struct nodesize *);
static void sizenodelist(struct nodelist *, struct nodesize *);
static union node *copynode(union node *, struct nodecopystate *);
static struct nodelist *copynodelist(struct nodelist *, struct nodecopystate *);
static char *nodesavestr(const char *, struct nodecopystate *);
struct funcdef {
unsigned int refcount;
union node n;
};
/*
* Make a copy of a parse tree.
*/
struct funcdef *
copyfunc(union node *n)
{
struct nodesize sz;
struct nodecopystate st;
struct funcdef *fn;
if (n == NULL)
return NULL;
sz.blocksize = offsetof(struct funcdef, n);
sz.stringsize = 0;
calcsize(n, &sz);
fn = ckmalloc(sz.blocksize + sz.stringsize);
fn->refcount = 1;
st.block = (char *)fn + offsetof(struct funcdef, n);
st.string = (char *)fn + sz.blocksize;
copynode(n, &st);
return fn;
}
union node *
getfuncnode(struct funcdef *fn)
{
return fn == NULL ? NULL : &fn->n;
}
static void
calcsize(union node *n, struct nodesize *result)
{
if (n == NULL)
return;
result->blocksize += nodesize[n->type];
switch (n->type) {
case NSEMI:
case NAND:
case NOR:
case NWHILE:
case NUNTIL:
calcsize(n->nbinary.ch2, result);
calcsize(n->nbinary.ch1, result);
break;
case NCMD:
calcsize(n->ncmd.redirect, result);
calcsize(n->ncmd.args, result);
break;
case NPIPE:
sizenodelist(n->npipe.cmdlist, result);
break;
case NREDIR:
case NBACKGND:
case NSUBSHELL:
calcsize(n->nredir.redirect, result);
calcsize(n->nredir.n, result);
break;
case NIF:
calcsize(n->nif.elsepart, result);
calcsize(n->nif.ifpart, result);
calcsize(n->nif.test, result);
break;
case NFOR:
result->stringsize += strlen(n->nfor.var) + 1;
calcsize(n->nfor.body, result);
calcsize(n->nfor.args, result);
break;
case NCASE:
calcsize(n->ncase.cases, result);
calcsize(n->ncase.expr, result);
break;
case NCLIST:
case NCLISTFALLTHRU:
calcsize(n->nclist.body, result);
calcsize(n->nclist.pattern, result);
calcsize(n->nclist.next, result);
break;
case NDEFUN:
case NARG:
sizenodelist(n->narg.backquote, result);
result->stringsize += strlen(n->narg.text) + 1;
calcsize(n->narg.next, result);
break;
case NTO:
case NFROM:
case NFROMTO:
case NAPPEND:
case NCLOBBER:
calcsize(n->nfile.fname, result);
calcsize(n->nfile.next, result);
break;
case NTOFD:
case NFROMFD:
calcsize(n->ndup.vname, result);
calcsize(n->ndup.next, result);
break;
case NHERE:
case NXHERE:
calcsize(n->nhere.doc, result);
calcsize(n->nhere.next, result);
break;
case NNOT:
calcsize(n->nnot.com, result);
break;
};
}
static void
sizenodelist(struct nodelist *lp, struct nodesize *result)
{
while (lp) {
result->blocksize += ALIGN(sizeof(struct nodelist));
calcsize(lp->n, result);
lp = lp->next;
}
}
static union node *
copynode(union node *n, struct nodecopystate *state)
{
union node *new;
if (n == NULL)
return NULL;
new = state->block;
state->block = (char *)state->block + nodesize[n->type];
switch (n->type) {
case NSEMI:
case NAND:
case NOR:
case NWHILE:
case NUNTIL:
new->nbinary.ch2 = copynode(n->nbinary.ch2, state);
new->nbinary.ch1 = copynode(n->nbinary.ch1, state);
break;
case NCMD:
new->ncmd.redirect = copynode(n->ncmd.redirect, state);
new->ncmd.args = copynode(n->ncmd.args, state);
break;
case NPIPE:
new->npipe.cmdlist = copynodelist(n->npipe.cmdlist, state);
new->npipe.backgnd = n->npipe.backgnd;
break;
case NREDIR:
case NBACKGND:
case NSUBSHELL:
new->nredir.redirect = copynode(n->nredir.redirect, state);
new->nredir.n = copynode(n->nredir.n, state);
break;
case NIF:
new->nif.elsepart = copynode(n->nif.elsepart, state);
new->nif.ifpart = copynode(n->nif.ifpart, state);
new->nif.test = copynode(n->nif.test, state);
break;
case NFOR:
new->nfor.var = nodesavestr(n->nfor.var, state);
new->nfor.body = copynode(n->nfor.body, state);
new->nfor.args = copynode(n->nfor.args, state);
break;
case NCASE:
new->ncase.cases = copynode(n->ncase.cases, state);
new->ncase.expr = copynode(n->ncase.expr, state);
break;
case NCLIST:
case NCLISTFALLTHRU:
new->nclist.body = copynode(n->nclist.body, state);
new->nclist.pattern = copynode(n->nclist.pattern, state);
new->nclist.next = copynode(n->nclist.next, state);
break;
case NDEFUN:
case NARG:
new->narg.backquote = copynodelist(n->narg.backquote, state);
new->narg.text = nodesavestr(n->narg.text, state);
new->narg.next = copynode(n->narg.next, state);
break;
case NTO:
case NFROM:
case NFROMTO:
case NAPPEND:
case NCLOBBER:
new->nfile.fname = copynode(n->nfile.fname, state);
new->nfile.next = copynode(n->nfile.next, state);
new->nfile.fd = n->nfile.fd;
break;
case NTOFD:
case NFROMFD:
new->ndup.vname = copynode(n->ndup.vname, state);
new->ndup.dupfd = n->ndup.dupfd;
new->ndup.next = copynode(n->ndup.next, state);
new->ndup.fd = n->ndup.fd;
break;
case NHERE:
case NXHERE:
new->nhere.doc = copynode(n->nhere.doc, state);
new->nhere.next = copynode(n->nhere.next, state);
new->nhere.fd = n->nhere.fd;
break;
case NNOT:
new->nnot.com = copynode(n->nnot.com, state);
break;
};
new->type = n->type;
return new;
}
static struct nodelist *
copynodelist(struct nodelist *lp, struct nodecopystate *state)
{
struct nodelist *start;
struct nodelist **lpp;
lpp = &start;
while (lp) {
*lpp = state->block;
state->block = (char *)state->block +
ALIGN(sizeof(struct nodelist));
(*lpp)->n = copynode(lp->n, state);
lp = lp->next;
lpp = &(*lpp)->next;
}
*lpp = NULL;
return start;
}
static char *
nodesavestr(const char *s, struct nodecopystate *state)
{
const char *p = s;
char *q = state->string;
char *rtn = state->string;
while ((*q++ = *p++) != '\0')
continue;
state->string = q;
return rtn;
}
void
reffunc(struct funcdef *fn)
{
if (fn)
fn->refcount++;
}
/*
* Decrement the reference count of a function definition, freeing it
* if it falls to 0.
*/
void
unreffunc(struct funcdef *fn)
{
if (fn) {
fn->refcount--;
if (fn->refcount > 0)
return;
ckfree(fn);
}
}

163
gen/sh/nodes.h Normal file
View File

@ -0,0 +1,163 @@
/*
* This file was generated by the mknodes program.
*/
#define NSEMI 0
#define NCMD 1
#define NPIPE 2
#define NREDIR 3
#define NBACKGND 4
#define NSUBSHELL 5
#define NAND 6
#define NOR 7
#define NIF 8
#define NWHILE 9
#define NUNTIL 10
#define NFOR 11
#define NCASE 12
#define NCLIST 13
#define NCLISTFALLTHRU 14
#define NDEFUN 15
#define NARG 16
#define NTO 17
#define NFROM 18
#define NFROMTO 19
#define NAPPEND 20
#define NCLOBBER 21
#define NTOFD 22
#define NFROMFD 23
#define NHERE 24
#define NXHERE 25
#define NNOT 26
struct nbinary {
int type;
union node *ch1;
union node *ch2;
};
struct ncmd {
int type;
union node *args;
union node *redirect;
};
struct npipe {
int type;
int backgnd;
struct nodelist *cmdlist;
};
struct nredir {
int type;
union node *n;
union node *redirect;
};
struct nif {
int type;
union node *test;
union node *ifpart;
union node *elsepart;
};
struct nfor {
int type;
union node *args;
union node *body;
char *var;
};
struct ncase {
int type;
union node *expr;
union node *cases;
};
struct nclist {
int type;
union node *next;
union node *pattern;
union node *body;
};
struct narg {
int type;
union node *next;
char *text;
struct nodelist *backquote;
};
struct nfile {
int type;
int fd;
union node *next;
union node *fname;
char *expfname;
};
struct ndup {
int type;
int fd;
union node *next;
int dupfd;
union node *vname;
};
struct nhere {
int type;
int fd;
union node *next;
union node *doc;
const char *expdoc;
};
struct nnot {
int type;
union node *com;
};
union node {
int type;
struct nbinary nbinary;
struct ncmd ncmd;
struct npipe npipe;
struct nredir nredir;
struct nif nif;
struct nfor nfor;
struct ncase ncase;
struct nclist nclist;
struct narg narg;
struct nfile nfile;
struct ndup ndup;
struct nhere nhere;
struct nnot nnot;
};
struct nodelist {
struct nodelist *next;
union node *n;
};
struct funcdef;
struct funcdef *copyfunc(union node *);
union node *getfuncnode(struct funcdef *);
void reffunc(struct funcdef *);
void unreffunc(struct funcdef *);

192
gen/sh/syntax.c Normal file
View File

@ -0,0 +1,192 @@
/*
* This file was generated by the mksyntax program.
*/
#include "parser.h"
#include "shell.h"
#include "syntax.h"
/* syntax table used when not in quotes */
const char basesyntax[SYNBASE + CHAR_MAX + 1] = {
[SYNBASE + PEOF] = CEOF,
[SYNBASE + CTLESC] = CCTL,
[SYNBASE + CTLVAR] = CCTL,
[SYNBASE + CTLENDVAR] = CCTL,
[SYNBASE + CTLBACKQ] = CCTL,
[SYNBASE + CTLBACKQ + CTLQUOTE] = CCTL,
[SYNBASE + CTLARI] = CCTL,
[SYNBASE + CTLENDARI] = CCTL,
[SYNBASE + CTLQUOTEMARK] = CCTL,
[SYNBASE + CTLQUOTEEND] = CCTL,
[SYNBASE + '\n'] = CNL,
[SYNBASE + '\\'] = CBACK,
[SYNBASE + '\''] = CSQUOTE,
[SYNBASE + '"'] = CDQUOTE,
[SYNBASE + '`'] = CBQUOTE,
[SYNBASE + '$'] = CVAR,
[SYNBASE + '}'] = CENDVAR,
[SYNBASE + '<'] = CSPCL,
[SYNBASE + '>'] = CSPCL,
[SYNBASE + '('] = CSPCL,
[SYNBASE + ')'] = CSPCL,
[SYNBASE + ';'] = CSPCL,
[SYNBASE + '&'] = CSPCL,
[SYNBASE + '|'] = CSPCL,
[SYNBASE + ' '] = CSPCL,
[SYNBASE + '\t'] = CSPCL,
};
/* syntax table used when in double quotes */
const char dqsyntax[SYNBASE + CHAR_MAX + 1] = {
[SYNBASE + PEOF] = CEOF,
[SYNBASE + CTLESC] = CCTL,
[SYNBASE + CTLVAR] = CCTL,
[SYNBASE + CTLENDVAR] = CCTL,
[SYNBASE + CTLBACKQ] = CCTL,
[SYNBASE + CTLBACKQ + CTLQUOTE] = CCTL,
[SYNBASE + CTLARI] = CCTL,
[SYNBASE + CTLENDARI] = CCTL,
[SYNBASE + CTLQUOTEMARK] = CCTL,
[SYNBASE + CTLQUOTEEND] = CCTL,
[SYNBASE + '\n'] = CNL,
[SYNBASE + '\\'] = CBACK,
[SYNBASE + '"'] = CENDQUOTE,
[SYNBASE + '`'] = CBQUOTE,
[SYNBASE + '$'] = CVAR,
[SYNBASE + '}'] = CENDVAR,
[SYNBASE + '!'] = CCTL,
[SYNBASE + '*'] = CCTL,
[SYNBASE + '?'] = CCTL,
[SYNBASE + '['] = CCTL,
[SYNBASE + ']'] = CCTL,
[SYNBASE + '='] = CCTL,
[SYNBASE + '~'] = CCTL,
[SYNBASE + ':'] = CCTL,
[SYNBASE + '/'] = CCTL,
[SYNBASE + '-'] = CCTL,
[SYNBASE + '^'] = CCTL,
};
/* syntax table used when in single quotes */
const char sqsyntax[SYNBASE + CHAR_MAX + 1] = {
[SYNBASE + PEOF] = CEOF,
[SYNBASE + CTLESC] = CCTL,
[SYNBASE + CTLVAR] = CCTL,
[SYNBASE + CTLENDVAR] = CCTL,
[SYNBASE + CTLBACKQ] = CCTL,
[SYNBASE + CTLBACKQ + CTLQUOTE] = CCTL,
[SYNBASE + CTLARI] = CCTL,
[SYNBASE + CTLENDARI] = CCTL,
[SYNBASE + CTLQUOTEMARK] = CCTL,
[SYNBASE + CTLQUOTEEND] = CCTL,
[SYNBASE + '\n'] = CNL,
[SYNBASE + '\\'] = CSBACK,
[SYNBASE + '\''] = CENDQUOTE,
[SYNBASE + '!'] = CCTL,
[SYNBASE + '*'] = CCTL,
[SYNBASE + '?'] = CCTL,
[SYNBASE + '['] = CCTL,
[SYNBASE + ']'] = CCTL,
[SYNBASE + '='] = CCTL,
[SYNBASE + '~'] = CCTL,
[SYNBASE + ':'] = CCTL,
[SYNBASE + '/'] = CCTL,
[SYNBASE + '-'] = CCTL,
[SYNBASE + '^'] = CCTL,
};
/* syntax table used when in arithmetic */
const char arisyntax[SYNBASE + CHAR_MAX + 1] = {
[SYNBASE + PEOF] = CEOF,
[SYNBASE + CTLESC] = CCTL,
[SYNBASE + CTLVAR] = CCTL,
[SYNBASE + CTLENDVAR] = CCTL,
[SYNBASE + CTLBACKQ] = CCTL,
[SYNBASE + CTLBACKQ + CTLQUOTE] = CCTL,
[SYNBASE + CTLARI] = CCTL,
[SYNBASE + CTLENDARI] = CCTL,
[SYNBASE + CTLQUOTEMARK] = CCTL,
[SYNBASE + CTLQUOTEEND] = CCTL,
[SYNBASE + '\n'] = CNL,
[SYNBASE + '\\'] = CBACK,
[SYNBASE + '`'] = CBQUOTE,
[SYNBASE + '"'] = CIGN,
[SYNBASE + '$'] = CVAR,
[SYNBASE + '}'] = CENDVAR,
[SYNBASE + '('] = CLP,
[SYNBASE + ')'] = CRP,
};
/* character classification table */
const char is_type[SYNBASE + CHAR_MAX + 1] = {
[SYNBASE + '0'] = ISDIGIT,
[SYNBASE + '1'] = ISDIGIT,
[SYNBASE + '2'] = ISDIGIT,
[SYNBASE + '3'] = ISDIGIT,
[SYNBASE + '4'] = ISDIGIT,
[SYNBASE + '5'] = ISDIGIT,
[SYNBASE + '6'] = ISDIGIT,
[SYNBASE + '7'] = ISDIGIT,
[SYNBASE + '8'] = ISDIGIT,
[SYNBASE + '9'] = ISDIGIT,
[SYNBASE + 'a'] = ISLOWER,
[SYNBASE + 'b'] = ISLOWER,
[SYNBASE + 'c'] = ISLOWER,
[SYNBASE + 'd'] = ISLOWER,
[SYNBASE + 'e'] = ISLOWER,
[SYNBASE + 'f'] = ISLOWER,
[SYNBASE + 'g'] = ISLOWER,
[SYNBASE + 'h'] = ISLOWER,
[SYNBASE + 'i'] = ISLOWER,
[SYNBASE + 'j'] = ISLOWER,
[SYNBASE + 'k'] = ISLOWER,
[SYNBASE + 'l'] = ISLOWER,
[SYNBASE + 'm'] = ISLOWER,
[SYNBASE + 'n'] = ISLOWER,
[SYNBASE + 'o'] = ISLOWER,
[SYNBASE + 'p'] = ISLOWER,
[SYNBASE + 'q'] = ISLOWER,
[SYNBASE + 'r'] = ISLOWER,
[SYNBASE + 's'] = ISLOWER,
[SYNBASE + 't'] = ISLOWER,
[SYNBASE + 'u'] = ISLOWER,
[SYNBASE + 'v'] = ISLOWER,
[SYNBASE + 'w'] = ISLOWER,
[SYNBASE + 'x'] = ISLOWER,
[SYNBASE + 'y'] = ISLOWER,
[SYNBASE + 'z'] = ISLOWER,
[SYNBASE + 'A'] = ISUPPER,
[SYNBASE + 'B'] = ISUPPER,
[SYNBASE + 'C'] = ISUPPER,
[SYNBASE + 'D'] = ISUPPER,
[SYNBASE + 'E'] = ISUPPER,
[SYNBASE + 'F'] = ISUPPER,
[SYNBASE + 'G'] = ISUPPER,
[SYNBASE + 'H'] = ISUPPER,
[SYNBASE + 'I'] = ISUPPER,
[SYNBASE + 'J'] = ISUPPER,
[SYNBASE + 'K'] = ISUPPER,
[SYNBASE + 'L'] = ISUPPER,
[SYNBASE + 'M'] = ISUPPER,
[SYNBASE + 'N'] = ISUPPER,
[SYNBASE + 'O'] = ISUPPER,
[SYNBASE + 'P'] = ISUPPER,
[SYNBASE + 'Q'] = ISUPPER,
[SYNBASE + 'R'] = ISUPPER,
[SYNBASE + 'S'] = ISUPPER,
[SYNBASE + 'T'] = ISUPPER,
[SYNBASE + 'U'] = ISUPPER,
[SYNBASE + 'V'] = ISUPPER,
[SYNBASE + 'W'] = ISUPPER,
[SYNBASE + 'X'] = ISUPPER,
[SYNBASE + 'Y'] = ISUPPER,
[SYNBASE + 'Z'] = ISUPPER,
[SYNBASE + '_'] = ISUNDER,
[SYNBASE + '#'] = ISSPECL,
[SYNBASE + '?'] = ISSPECL,
[SYNBASE + '$'] = ISSPECL,
[SYNBASE + '!'] = ISSPECL,
[SYNBASE + '-'] = ISSPECL,
[SYNBASE + '*'] = ISSPECL,
[SYNBASE + '@'] = ISSPECL,
};

54
gen/sh/syntax.h Normal file
View File

@ -0,0 +1,54 @@
/*
* This file was generated by the mksyntax program.
*/
#include <sys/cdefs.h>
#include <limits.h>
/* Syntax classes */
#define CWORD 0 /* character is nothing special */
#define CNL 1 /* newline character */
#define CBACK 2 /* a backslash character */
#define CSBACK 3 /* a backslash character in single quotes */
#define CSQUOTE 4 /* single quote */
#define CDQUOTE 5 /* double quote */
#define CENDQUOTE 6 /* a terminating quote */
#define CBQUOTE 7 /* backwards single quote */
#define CVAR 8 /* a dollar sign */
#define CENDVAR 9 /* a '}' character */
#define CLP 10 /* a left paren in arithmetic */
#define CRP 11 /* a right paren in arithmetic */
#define CEOF 12 /* end of file */
#define CCTL 13 /* like CWORD, except it must be escaped */
#define CSPCL 14 /* these terminate a word */
#define CIGN 15 /* character should be ignored */
/* Syntax classes for is_ functions */
#define ISDIGIT 01 /* a digit */
#define ISUPPER 02 /* an upper case letter */
#define ISLOWER 04 /* a lower case letter */
#define ISUNDER 010 /* an underscore */
#define ISSPECL 020 /* the name of a special parameter */
#define SYNBASE (1 - CHAR_MIN)
#define PEOF -SYNBASE
#define BASESYNTAX (basesyntax + SYNBASE)
#define DQSYNTAX (dqsyntax + SYNBASE)
#define SQSYNTAX (sqsyntax + SYNBASE)
#define ARISYNTAX (arisyntax + SYNBASE)
#define is_digit(c) ((unsigned int)((c) - '0') <= 9)
#define is_eof(c) ((c) == PEOF)
#define is_alpha(c) ((is_type+SYNBASE)[(int)c] & (ISUPPER|ISLOWER))
#define is_name(c) ((is_type+SYNBASE)[(int)c] & (ISUPPER|ISLOWER|ISUNDER))
#define is_in_name(c) ((is_type+SYNBASE)[(int)c] & (ISUPPER|ISLOWER|ISUNDER|ISDIGIT))
#define is_special(c) ((is_type+SYNBASE)[(int)c] & (ISSPECL|ISDIGIT))
#define digit_val(c) ((c) - '0')
extern const char basesyntax[];
extern const char dqsyntax[];
extern const char sqsyntax[];
extern const char arisyntax[];
extern const char is_type[];

112
gen/sh/token.h Normal file
View File

@ -0,0 +1,112 @@
#define TEOF 0
#define TNL 1
#define TSEMI 2
#define TBACKGND 3
#define TAND 4
#define TOR 5
#define TPIPE 6
#define TLP 7
#define TRP 8
#define TENDCASE 9
#define TFALLTHRU 10
#define TREDIR 11
#define TWORD 12
#define TIF 13
#define TTHEN 14
#define TELSE 15
#define TELIF 16
#define TFI 17
#define TWHILE 18
#define TUNTIL 19
#define TFOR 20
#define TDO 21
#define TDONE 22
#define TBEGIN 23
#define TEND 24
#define TCASE 25
#define TESAC 26
#define TNOT 27
/* Array indicating which tokens mark the end of a list */
static const char tokendlist[] = {
1,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
0,
0,
0,
1,
1,
1,
1,
0,
0,
0,
1,
1,
0,
1,
0,
1,
0,
};
static const char *const tokname[] = {
"end of file",
"newline",
"\";\"",
"\"&\"",
"\"&&\"",
"\"||\"",
"\"|\"",
"\"(\"",
"\")\"",
"\";;\"",
"\";&\"",
"redirection",
"word",
"\"if\"",
"\"then\"",
"\"else\"",
"\"elif\"",
"\"fi\"",
"\"while\"",
"\"until\"",
"\"for\"",
"\"do\"",
"\"done\"",
"\"{\"",
"\"}\"",
"\"case\"",
"\"esac\"",
"\"!\"",
};
#define KWDOFFSET 13
const char *const parsekwd[] = {
"if",
"then",
"else",
"elif",
"fi",
"while",
"until",
"for",
"do",
"done",
"{",
"}",
"case",
"esac",
"!",
0
};

54
sh/CMakeLists.txt Normal file
View File

@ -0,0 +1,54 @@
project(shell_cmds-sh)
add_compile_definitions(
SHELL
)
include_directories(
../gen/sh
${CMAKE_CURRENT_SOURCE_DIR}
)
add_darling_executable(ash
alias.c
arith_yacc.c
arith_yylex.c
cd.c
error.c
eval.c
exec.c
expand.c
histedit.c
input.c
jobs.c
mail.c
main.c
memalloc.c
miscbltin.c
mystring.c
options.c
output.c
parser.c
redir.c
show.c
trap.c
var.c
bltin/echo.c
../gen/sh/builtins.c
../gen/sh/nodes.c
../gen/sh/syntax.c
../kill/kill.c
../printf/printf.c
../test/test.c
)
target_link_libraries(ash
edit
)
install(TARGETS ash DESTINATION libexec/darling/bin)
install(FILES sh.1 DESTINATION libexec/darling/usr/share/man/man1 RENAME ash.1)