if (!value) return NULL;
+ c = (struct context){.b = c.buffer, .alias = 1};
strcpy(c.buffer, value);
- l = strlen(value);
- c.buffer[l + 1] = '\0';
- c.buffer[l] = ';';
- c.b = c.buffer;
- c.alias = 1;
+ l = strlen(c.buffer);
+ c.buffer[l++] = ';';
+ c.buffer[l] = '\0';
if (!parse(&c)) return NULL;
if (!(dir = opendir("./")))
err(EXIT_FAILURE, "Unable to open current directory");
- dprintf(listfd, "#include <stddef.h>\n\n#include \"builtin.h\"\n"
- "#include \"list.h\"\n\n");
+ dprintf(listfd, "#include <stddef.h>\n\n#include \"builtin.h\"\n\n");
src = srcs;
errno = 0;
#include <string.h>
#include "builtin.h"
-#include "list.h"
#include "utils.h"
int (*getbuiltin(char *name))(char **args, size_t numargs) {
+extern struct builtin {
+ char *name;
+ int (*func)(char **args, size_t numargs);
+} builtins[];
+
int (*getbuiltin(char *name))(char **args, size_t numargs);
int usage(char *program, char *options);
return EXIT_FAILURE;
}
l = strlen(buffer);
- buffer[l + 1] = '\0';
- buffer[l] = '/';
+ buffer[l++] = '/';
+ buffer[l] = '\0';
break;
default:
return usage(args[0], "[directory]");
exit(EXIT_SUCCESS);
}
if (sigint) sigint = 0;
+ if (sigwinch) sigwinch = 0;
}
setsig(SIGCHLD, &defaultaction);
fgjob.done = errno = 0;
return 1;
}
-void deinitfg(void) {
- setconfig(&canonical);
-}
-
int fg(char **args, size_t numargs) {
struct bgjob job;
long l;
int setconfig(struct termios *mode);
void initfg(void);
int runfg(pid_t id);
-void deinitfg(void);
+++ /dev/null
-struct builtin {
- char *name;
- int (*func)(char **args, size_t numargs);
-};
-
-extern struct builtin builtins[];
note("Unable to get current working directory");
return EXIT_FAILURE;
}
- l = strlen(buffer);
- if (buffer[l - 1] != '/') {
- buffer[l] = '/';
- buffer[l + 1] = '\0';
+ if (buffer[(l = strlen(buffer)) - 1] != '/') {
+ buffer[l++] = '/';
+ buffer[l] = '\0';
}
if (setenv("PWD", buffer, 1) == -1) {
note("Unable to set $PWD$");
end = c->string;
while (*end && *end != '\n') ++end;
l = end - c->string;
- while (*end == '\n') ++end; /* `scriptinput()' uses `stringinput()' */
+ while (*end == '\n') ++end;
if (l > MAXCHARS) {
note("Line too long, exceeds %d character limit", MAXCHARS);
return 0;
}
strncpy(c->buffer, c->string, l);
- c->buffer[l] = ';';
- c->buffer[l + 1] = '\0';
+ c->buffer[l++] = ';';
+ c->buffer[l] = '\0';
c->string = end;
return 1;
case '\\':
if (!quote) break;
switch (*(c->b + 1)) {
+ default:
+ memmove(c->b, c->b + 1, end-- - c->b);
+ --c->b;
+ *(c->b + 1) = *c->b;
case '$':
case '~':
case '"':
case '\\':
- break;
- default:
- memmove(c->b, c->b + 1, end-- - c->b--);
- *(c->b + 1) = *c->b;
+ memmove(c->b, c->b + 1, end-- - c->b);
}
- memmove(c->b, c->b + 1, end-- - c->b);
break;
case '*':
case '?':
#include "utils.h"
-int sigwinch, sigquit, sigint;
+int sigquit, sigint, sigwinch;
sigset_t shellsigmask, childsigmask;
struct sigaction defaultaction;
fatal("Unable to install %s handler", strsignal(sig));
}
-static void sigwinchhandler(int sig) {
- (void)sig;
-
- sigwinch = 1;
-}
-
static void sigquithandler(int sig) {
(void)sig;
sigint = 1;
}
+static void sigwinchhandler(int sig) {
+ (void)sig;
+
+ sigwinch = 1;
+}
+
void initsignals(void) {
struct sigaction action;
setsig(SIGTTOU, &defaultaction);
setsig(SIGTTIN, &defaultaction);
- action = (struct sigaction){.sa_handler = sigwinchhandler};
- setsig(SIGWINCH, &action);
-
action = (struct sigaction){.sa_handler = sigquithandler};
setsig(SIGHUP, &action);
setsig(SIGQUIT, &action);
action = (struct sigaction){.sa_handler = siginthandler};
setsig(SIGINT, &action);
+
+ action = (struct sigaction){.sa_handler = sigwinchhandler};
+ setsig(SIGWINCH, &action);
}
note("Unable to update $SHLVL$ environment variable");
if (!(home = getenv("HOME"))) fatal("Unable to find home directory");
- l = strlen(home);
- if (home[l - 1] != '/') {
+ if (home[(l = strlen(home)) - 1] != '/') {
strcpy(buffer, home);
- buffer[l] = '/';
- buffer[l + 1] = '\0';
+ buffer[l++] = '/';
+ buffer[l] = '\0';
if (setenv("HOME", buffer, 1) == -1 || !(home = getenv("HOME")))
note("Unable to append trailing slash to $HOME$");
}
if (!getcwd(buffer, PATH_MAX)) fatal("Unable to find current directory");
l = strlen(buffer);
- buffer[l] = '/';
- buffer[l + 1] = '\0';
+ buffer[l++] = '/';
+ buffer[l] = '\0';
if (setenv("PWD", buffer, 1) == -1)
note("Unable to append trailing slash to $PWD$");
size_t l;
int slash;
- l = strlen(dir);
- slash = dir[l - 1] == '/';
+ slash = dir[(l = strlen(dir)) - 1] == '/';
if (l + slash + strlen(filename) + 1 > PATH_MAX) {
note("Path name `%s%s%s' too long", dir, slash ? "/" : "", filename);
return NULL;
}
char *quoted(char *token) {
- char *p, *q, quote;
+ char *p, *end, quote;
enum {
NONE,
DOUBLE,
degree = NONE;
for (p = token; *p; ++p) switch(*p) {
case '[':
- for (q = p; *q; ++q) if (*q == ']') break;
- if (!*q) continue;
+ for (end = p; *end; ++end) if (*end == ']') break;
+ if (!*end) continue;
case '>':
case '<':
case '*':
p = buffer;
*p++ = quote;
strcpy(p, token);
- for (q = p; *q; ++q);
+ for (end = p; *end; ++end);
if (degree != SINGLE) for (; *p; ++p) switch (*p)
case '$':
case '~':
case '"':
if (degree == ESCAPEDOUBLE) {
case '\\':
- memmove(p + 1, p, ++q - p);
+ memmove(p + 1, p, ++end - p);
*p++ = '\\';
}
- *q++ = quote;
- *q++ = '\0';
+ *end++ = quote;
+ *end = '\0';
return buffer;
}
void deinit(void) {
deinithistory();
deinitbg();
- deinitfg();
+ setconfig(&canonical);
}
strcat(path, "bin/");
if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork");
- else if (cpid == 0)
- run("/bin/mkdir", LIST("mkdir", "-p", path), "create", path);
+ if (!cpid) run("/bin/mkdir", LIST("mkdir", "-p", path), "create", path);
await(cpid, "create", path);
strcat(path, "thus");
if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork");
- else if (cpid == 0)
+ if (!cpid)
run("/bin/cp", LIST("cp", "-f", "bin/thus", path), "copy", "bin/thus");
await(cpid, "copy", "bin/thus");
if (argc != 1) err(EXIT_FAILURE, "usage: %s\n", argv[0]);
if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork");
- else if (cpid == 0)
+ if (!cpid)
run("/bin/rm", LIST("rm", STR(PATH), "uninstall"), "remove", STR(PATH));
await(cpid, "remove", STR(PATH));