style(9)
This commit is contained in:
parent
65f0044ceb
commit
5e619e1ef3
5
eval.c
5
eval.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.12 2006/05/10 18:54:09 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.13 2006/08/01 13:43:26 tg Exp $");
|
||||
|
||||
/*
|
||||
* string expansion
|
||||
@ -1074,7 +1074,8 @@ globit(XString *xs, /* dest string */
|
||||
xp = Xstring(*xs, xp) + prefix_len;
|
||||
}
|
||||
closedir(dirp);
|
||||
Nodir:;
|
||||
Nodir:
|
||||
;
|
||||
}
|
||||
|
||||
if (np != NULL)
|
||||
|
10
exec.c
10
exec.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.15 2006/05/10 18:54:10 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.16 2006/08/01 13:43:26 tg Exp $");
|
||||
|
||||
static int comexec(struct op *, struct tbl *volatile, char **,
|
||||
int volatile);
|
||||
@ -318,7 +318,7 @@ execute(struct op *volatile t,
|
||||
gmatchx(cp, s, false))
|
||||
goto Found;
|
||||
break;
|
||||
Found:
|
||||
Found:
|
||||
rv = execute(t->left, flags & XERROK);
|
||||
break;
|
||||
|
||||
@ -348,7 +348,7 @@ execute(struct op *volatile t,
|
||||
else
|
||||
errorf("%s: %s", s, strerror(errno));
|
||||
}
|
||||
Break:
|
||||
Break:
|
||||
exstat = rv;
|
||||
|
||||
quitenv(NULL); /* restores IO */
|
||||
@ -654,7 +654,7 @@ comexec(struct op *t, struct tbl *volatile tp, char **ap, volatile int flags)
|
||||
rv = exchild(&texec, flags, -1);
|
||||
break;
|
||||
}
|
||||
Leave:
|
||||
Leave:
|
||||
if (flags & XEXEC) {
|
||||
exstat = rv;
|
||||
unwind(LLEAVE);
|
||||
@ -841,7 +841,7 @@ findcom(const char *name, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
Search:
|
||||
Search:
|
||||
if ((!tp || (tp->type == CTALIAS && !(tp->flag&ISSET))) &&
|
||||
(flags & FC_PATH)) {
|
||||
if (!tp) {
|
||||
|
8
funcs.c
8
funcs.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.28 2006/07/03 12:16:30 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.29 2006/08/01 13:43:26 tg Exp $");
|
||||
|
||||
int
|
||||
c_cd(char **wp)
|
||||
@ -2254,16 +2254,16 @@ c_mknod(char **wp)
|
||||
if (mknod(argv[0], mode, dv))
|
||||
goto c_mknod_failed;
|
||||
} else if (mkfifo(argv[0], mode)) {
|
||||
c_mknod_failed:
|
||||
c_mknod_failed:
|
||||
bi_errorf("%s: %s", *wp, strerror(errno));
|
||||
c_mknod_err:
|
||||
c_mknod_err:
|
||||
rv = 1;
|
||||
}
|
||||
|
||||
if (set)
|
||||
umask(oldmode);
|
||||
return (rv);
|
||||
c_mknod_usage:
|
||||
c_mknod_usage:
|
||||
bi_errorf("usage: mknod [-m mode] name [b | c] major minor");
|
||||
bi_errorf("usage: mknod [-m mode] name p");
|
||||
return (1);
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.17 2006/08/01 13:19:42 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.18 2006/08/01 13:43:27 tg Exp $");
|
||||
|
||||
static int histfd;
|
||||
static int hsize;
|
||||
@ -669,8 +669,7 @@ hist_init(Source *s)
|
||||
hist_finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (hsize > 0) {
|
||||
} else if (hsize > 0) {
|
||||
/*
|
||||
* we have some data
|
||||
*/
|
||||
|
4
jobs.c
4
jobs.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.8 2006/05/10 18:54:11 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.9 2006/08/01 13:43:27 tg Exp $");
|
||||
|
||||
/* Order important! */
|
||||
#define PRUNNING 0
|
||||
@ -1045,7 +1045,7 @@ j_sigchld(int sig __attribute__((unused)))
|
||||
for (p = j->proc_list; p != NULL; p = p->next)
|
||||
if (p->pid == pid)
|
||||
goto found;
|
||||
found:
|
||||
found:
|
||||
if (j == NULL) {
|
||||
/* Can occur if process has kids, then execs shell
|
||||
warningf(true, "bad process waited for (pid = %d)",
|
||||
|
15
lex.c
15
lex.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.13 2006/07/03 12:16:30 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.14 2006/08/01 13:43:27 tg Exp $");
|
||||
|
||||
/* Structure to keep track of the lexing state and the various pieces of info
|
||||
* needed for each particular state. */
|
||||
@ -102,8 +102,7 @@ yylex(int cf)
|
||||
char *sp, *dp;
|
||||
int c2;
|
||||
|
||||
|
||||
Again:
|
||||
Again:
|
||||
states[0].ls_state = -1;
|
||||
states[0].ls_info.base = NULL;
|
||||
statep = &states[1];
|
||||
@ -178,7 +177,7 @@ yylex(int cf)
|
||||
break;
|
||||
}
|
||||
/* FALLTHRU */
|
||||
Sbase1: /* includes *(...|...) pattern (*+?@!) */
|
||||
Sbase1: /* includes *(...|...) pattern (*+?@!) */
|
||||
if (c == '*' || c == '@' || c == '+' || c == '?' ||
|
||||
c == '!') {
|
||||
c2 = getsc();
|
||||
@ -191,7 +190,7 @@ yylex(int cf)
|
||||
ungetsc(c2);
|
||||
}
|
||||
/* FALLTHRU */
|
||||
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
|
||||
Sbase2: /* doesn't include *(...|...) pattern (*+?@!) */
|
||||
switch (c) {
|
||||
case '\\':
|
||||
c = getsc();
|
||||
@ -212,7 +211,7 @@ yylex(int cf)
|
||||
}
|
||||
break;
|
||||
|
||||
Subst:
|
||||
Subst:
|
||||
switch (c) {
|
||||
case '\\':
|
||||
c = getsc();
|
||||
@ -226,7 +225,7 @@ yylex(int cf)
|
||||
*wp++ = QCHAR, *wp++ = c;
|
||||
break;
|
||||
default:
|
||||
heredocquote:
|
||||
heredocquote:
|
||||
Xcheck(ws, wp);
|
||||
if (c) { /* trailing \ is lost */
|
||||
*wp++ = CHAR, *wp++ = '\\';
|
||||
@ -601,7 +600,7 @@ heredocquote:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Done:
|
||||
Done:
|
||||
Xcheck(ws, wp);
|
||||
if (statep != &states[1])
|
||||
/* XXX figure out what is missing */
|
||||
|
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
||||
#define EXTERN /* define EXTERNs in sh.h */
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.43 2006/08/01 12:22:26 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.44 2006/08/01 13:43:27 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -1161,7 +1161,7 @@ ktenter(struct table *tp, const char *n, unsigned int h)
|
||||
|
||||
if (tp->size == 0)
|
||||
texpand(tp, INIT_TBLS);
|
||||
Search:
|
||||
Search:
|
||||
/* search for name in hashed table */
|
||||
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||
if (*p->name == *n && strcmp(p->name, n) == 0)
|
||||
|
6
misc.c
6
misc.c
@ -3,7 +3,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.11 2006/05/10 18:54:11 tg Exp $"
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.12 2006/08/01 13:43:28 tg Exp $"
|
||||
"\t" MKSH_SH_H_ID);
|
||||
|
||||
short chtypes[UCHAR_MAX+1]; /* type bits for unsigned char */
|
||||
@ -778,7 +778,7 @@ qsort1(void **base, void **lim, int (*f) (void *, void *))
|
||||
size_t n;
|
||||
int c;
|
||||
|
||||
top:
|
||||
top:
|
||||
n = (lim - base) / 2;
|
||||
if (n == 0)
|
||||
return;
|
||||
@ -799,7 +799,7 @@ qsort1(void **base, void **lim, int (*f) (void *, void *))
|
||||
}
|
||||
}
|
||||
|
||||
begin:
|
||||
begin:
|
||||
if (j > hptr) {
|
||||
if ((c = (*f)(*hptr, *j)) == 0) {
|
||||
hptr ++;
|
||||
|
11
setmode.c
11
setmode.c
@ -48,7 +48,7 @@
|
||||
#endif
|
||||
|
||||
__SCCSID("@(#)setmode.c 8.2 (Berkeley) 3/25/94");
|
||||
__RCSID("$MirOS: src/bin/mksh/setmode.c,v 1.2 2006/07/03 12:16:31 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/setmode.c,v 1.3 2006/08/01 13:43:28 tg Exp $");
|
||||
|
||||
#define SET_LEN 6 /* initial # of bitcmd struct to malloc */
|
||||
#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */
|
||||
@ -103,7 +103,8 @@ getmode(const void *bbox, mode_t omode)
|
||||
|
||||
case 'o':
|
||||
value = newmode & S_IRWXO;
|
||||
common: if (set->cmd2 & CMD2_CLR) {
|
||||
common:
|
||||
if (set->cmd2 & CMD2_CLR) {
|
||||
clrval =
|
||||
(set->cmd2 & CMD2_SET) ? S_IRWXO : value;
|
||||
if (set->cmd2 & CMD2_UBITS)
|
||||
@ -238,7 +239,8 @@ setmode(const char *p)
|
||||
}
|
||||
}
|
||||
|
||||
getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
|
||||
getop:
|
||||
if ((op = *p++) != '+' && op != '-' && op != '=') {
|
||||
free(saveset);
|
||||
return (NULL);
|
||||
}
|
||||
@ -318,7 +320,8 @@ getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
|
||||
}
|
||||
}
|
||||
|
||||
apply: if (!*p)
|
||||
apply:
|
||||
if (!*p)
|
||||
break;
|
||||
if (*p != ',')
|
||||
goto getop;
|
||||
|
117
strlfun.c
Normal file
117
strlfun.c
Normal file
@ -0,0 +1,117 @@
|
||||
/* $MirOS: src/bin/mksh/strlfun.c,v 1.3 2006/08/01 13:43:28 tg Exp $ */
|
||||
/* _MirOS: src/lib/libc/string/strlfun.c,v 1.7 2006/08/01 13:41:49 tg Exp $ */
|
||||
/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
|
||||
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2004, 2005, 2006 Thorsten Glaser <tg@mirbsd.de>
|
||||
* Thanks to Bodo Eggert for optimisation hints
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
# include <lib/libkern/libkern.h>
|
||||
# undef HAVE_STRLCPY
|
||||
# undef HAVE_STRLCAT
|
||||
#else
|
||||
# ifdef HAVE_CONFIG_H /* usually when packaged with third-party software */
|
||||
# include "config.h"
|
||||
# endif
|
||||
# include <sys/types.h>
|
||||
|
||||
extern size_t strlen(const char *);
|
||||
|
||||
#ifndef __RCSID
|
||||
#define __RCSID(x) static const char __rcsid[] = (x)
|
||||
#endif
|
||||
|
||||
#ifndef __predict_false
|
||||
#define __predict_false(exp) ((exp) != 0)
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/strlfun.c,v 1.3 2006/08/01 13:43:28 tg Exp $");
|
||||
#endif
|
||||
|
||||
size_t strlcat(char *, const char *, size_t);
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
const char *s = src;
|
||||
|
||||
if (__predict_false(!siz))
|
||||
goto traverse_src;
|
||||
|
||||
/* copy as many chars as will fit */
|
||||
for (; --siz && (*dst++ = *s++); )
|
||||
;
|
||||
|
||||
/* not enough room in dst */
|
||||
if (__predict_false(!siz)) {
|
||||
/* safe to NUL-terminate dst since copied <= siz-1 chars */
|
||||
*dst = '\0';
|
||||
traverse_src:
|
||||
/* traverse rest of src */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
/* count doesn't include NUL */
|
||||
return (s - src - 1);
|
||||
}
|
||||
#endif /* !HAVE_STRLCPY */
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
size_t dl, n = siz;
|
||||
const size_t sl = strlen(src);
|
||||
|
||||
while (n-- && (*d++ != '\0'))
|
||||
;
|
||||
if (!++n && (*d != '\0'))
|
||||
return (strlen(src));
|
||||
|
||||
dl = --d - dst; /* original strlen(dst), max. siz-1 */
|
||||
n = siz - dl;
|
||||
dl += sl;
|
||||
|
||||
if (__predict_false(!n--))
|
||||
return (dl);
|
||||
|
||||
if (__predict_false(n > sl))
|
||||
n = sl; /* number of chars to copy */
|
||||
for (; n-- && (*d++ = *src++); )
|
||||
;
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
return (dl);
|
||||
}
|
||||
#endif /* !HAVE_STRLCAT */
|
8
syn.c
8
syn.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.7 2006/05/10 18:54:13 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.8 2006/08/01 13:43:28 tg Exp $");
|
||||
|
||||
struct nesting_state {
|
||||
int start_token; /* token than began nesting (eg, FOR) */
|
||||
@ -264,10 +264,10 @@ get_command(int cf)
|
||||
goto Leave;
|
||||
}
|
||||
}
|
||||
Leave:
|
||||
Leave:
|
||||
break;
|
||||
|
||||
Subshell:
|
||||
Subshell:
|
||||
case '(':
|
||||
t = nested(TPAREN, '(', ')');
|
||||
break;
|
||||
@ -682,7 +682,7 @@ syntaxerr(const char *what)
|
||||
what = "unexpected";
|
||||
REJECT;
|
||||
c = token(0);
|
||||
Again:
|
||||
Again:
|
||||
switch (c) {
|
||||
case 0:
|
||||
if (nesting.start_token) {
|
||||
|
Loading…
Reference in New Issue
Block a user