+install
+uninstall
*build
*.o
build("./");
build("src/");
+ build("tools/");
return EXIT_SUCCESS;
}
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
+#include <sys/wait.h>
#include <termios.h>
#include "bg.h"
status = builtinp->func(n, args);
return 1;
}
+
return 0;
}
int usage(char *program, char *options) {
- fprintf(stderr, "Usage: %s %s\n", program, options);
+ fprintf(stderr, "Usage: %s", program);
+ if (options) fprintf(stderr, " %s", options);
+ fputc('\n', stderr);
+
return EXIT_FAILURE;
}
--- /dev/null
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "builtin.h"
+#include "utils.h"
+
+BUILTIN(pwd) {
+ char *cwd, buffer[PATH_MAX];
+
+ if (argc != 1) return usage(argv[0], NULL);
+
+ if (!(cwd = getenv("PWD")) && !(cwd = getcwd(buffer, PATH_MAX)))
+ fatal("Unable to get current working directory");
+
+ puts(cwd);
+
+ return EXIT_SUCCESS;
+}
+#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include "builtin.h"
#include "context.h"
void config(char *name) {
char path[PATH_MAX];
+ int fd;
- source(2, (char *[]){"source", catpath(home, name, path), NULL});
+ if (!catpath(home, name, path)) return;
+
+ if ((fd = open(path, O_RDONLY | O_CREAT, 0644)) == -1) {
+ note("Unable to create `%s'", path);
+ return;
+ }
+ if (close(fd) == -1) {
+ note("Unable to close `%s'", path);
+ return;
+ }
+
+ source(2, (char *[]){"source", path, NULL});
}
+#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
void inithistory(void) {
FILE *file;
- if (!catpath(home, ".ashhistory", history.path)) exit(EXIT_FAILURE);
+ if (!catpath(home, ".thushistory", history.path)) exit(EXIT_FAILURE);
if (!(file = fopen(history.path, "r"))) {
if (errno == ENOENT) return;
fatal("Unable to open history file for reading");
}
void deinithistory(void) {
+ int fd;
FILE *file;
- if (!(file = fopen(history.path, "w"))) {
+ if ((fd = open(history.path, O_WRONLY | O_CREAT | O_TRUNC, 0600)) == -1) {
note("Unable to open history file for writing");
return;
}
+ if (!(file = fdopen(fd, "w"))) {
+ note("Unable to open history file descriptor as FILE pointer");
+ return;
+ }
for (history.c = history.b; history.c != history.t; INC(c)) {
if (fputs(history.entries[history.c], file) == EOF) {
note("Unable to write to history file");
void fatal(char *fmt, ...) {
va_list args;
va_start(args, fmt);
- (errno ? vwarn : vwarnx)(fmt, args);
- va_end(args);
- exit(EXIT_FAILURE);
+ (errno ? verr : verrx)(EXIT_FAILURE, fmt, args);
}
void init(void) {
}
char *catpath(char *dir, char *filename, char *buffer) {
+ size_t l;
int slash;
- slash = dir[strlen(dir) - 1] == '/';
- if (strlen(dir) + slash + strlen(filename) + 1 > PATH_MAX) {
+ l = strlen(dir);
+ slash = dir[l - 1] == '/';
+ if (l + slash + strlen(filename) + 1 > PATH_MAX) {
note("Path name `%s%s%s' too long", dir, slash ? "/" : "", filename);
return NULL;
}
--- /dev/null
+#include "../external/cbs/cbs.c"
+
+int main(void) {
+ build("./");
+
+ cflags = LIST("-I../external/cbs/");
+ compile("install");
+ load('x', "../install", LIST("install"));
+
+ return EXIT_SUCCESS;
+}
--- /dev/null
+#include <limits.h>
+
+#include "cbs.c"
+
+int main(int argc, char **argv) {
+ char define[7 + 1 + PATH_MAX + 1], *path;
+ size_t l;
+ int slash;
+ pid_t cpid;
+
+ if (argc > 2) errx(EXIT_FAILURE, "%s [prefix]", argv[0]);
+
+ path = stpcpy(define, "-DPATH=\"");
+ if (argc == 2) {
+ l = strlen(argv[1]);
+ slash = argv[1][l - 1] == '/';
+ if (l + slash + strlen("bin/thus") + 1 > PATH_MAX)
+ errx(EXIT_FAILURE, "Path name `%s%sbin/thus' too long",
+ argv[1], slash ? "/" : "");
+ strcpy(path, argv[1]);
+ if (!slash) strcat(path, "/");
+ } else strcpy(path, "/usr/local/");
+
+ 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);
+ await(cpid, "create", path);
+
+ strcat(path, "thus");
+ if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork");
+ else if (cpid == 0)
+ run("/bin/cp", LIST("cp", "bin/thus", path), "copy", "bin/thus");
+ await(cpid, "copy", "bin/thus");
+
+ l = strlen(define);
+ define[l] = '\"';
+ define[l + 1] = '\0';
+ cflags = LIST(define, "-Iexternal/cbs");
+ compile("tools/uninstall");
+ load('x', "uninstall", LIST("tools/uninstall"));
+
+ return EXIT_SUCCESS;
+}
--- /dev/null
+#include <stdlib.h>
+
+#include "cbs.c"
+
+int main(void) {
+ pid_t cpid;
+
+ if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork");
+ else if (cpid == 0)
+ run("/bin/rm", LIST("rm", PATH, "uninstall"), "remove", PATH);
+ await(cpid, "remove", PATH);
+
+ return EXIT_SUCCESS;
+}