Skip to content

Commit

Permalink
Ports: Add mrsh port
Browse files Browse the repository at this point in the history
  • Loading branch information
bugaevc authored and awesomekling committed Feb 5, 2020
1 parent b3a24d7 commit ce56770
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Ports/mrsh/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash ../.port_include.sh
port=mrsh
version=d9763a32e7da572677d1681bb1fc67f117d641f3
files="https://codeload.github.com/emersion/mrsh/legacy.tar.gz/d9763a32e7da572677d1681bb1fc67f117d641f3 emersion-mrsh-d9763a3.tar.gz"
useconfigure=true
makeopts=
workdir=emersion-mrsh-d9763a3
45 changes: 45 additions & 0 deletions Ports/mrsh/patches/disable-fnmatch.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--- a/shell/task/task.c 2020-02-03 18:16:49.579018362 +0300
+++ b/shell/task/task.c 2020-02-03 18:24:17.149890856 +0300
@@ -2,7 +2,7 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
-#include <fnmatch.h>
+// #include <fnmatch.h>
#include <mrsh/ast.h>
#include <stdio.h>
#include <stdlib.h>
@@ -218,7 +218,7 @@
}
char *pattern = word_to_pattern(*word_ptr);
if (pattern != NULL) {
- selected = fnmatch(pattern, word_str, 0) == 0;
+ // selected = fnmatch(pattern, word_str, 0) == 0;
free(pattern);
} else {
char *str = mrsh_word_str(*word_ptr);
--- a/shell/task/word.c 2020-02-03 18:25:52.544717475 +0300
+++ b/shell/task/word.c 2020-02-03 18:26:47.036189658 +0300
@@ -1,7 +1,7 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <errno.h>
-#include <fnmatch.h>
+// #include <fnmatch.h>
#include <mrsh/buffer.h>
#include <mrsh/parser.h>
#include <stdio.h>
@@ -364,11 +364,13 @@
trimmed = buf;
}

+/*
if (fnmatch(pattern, match, 0) == 0) {
char *result = strdup(trimmed);
free(buf);
return result;
}
+*/

buf[i] = ch;
}
34 changes: 34 additions & 0 deletions Ports/mrsh/patches/disable-glob.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- a/shell/word.c 2020-02-04 15:23:40.077301321 +0300
+++ b/shell/word.c 2020-02-04 15:24:09.428550187 +0300
@@ -1,7 +1,7 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <ctype.h>
-#include <glob.h>
+// #include <glob.h>
#include <mrsh/buffer.h>
#include <pwd.h>
#include <stdbool.h>
@@ -338,11 +338,13 @@
const struct mrsh_array *fields) {
for (size_t i = 0; i < fields->len; ++i) {
const struct mrsh_word *field = fields->data[i];
-
+/*
char *pattern = word_to_pattern(field);
if (pattern == NULL) {
+*/
mrsh_array_add(expanded, mrsh_word_str(field));
continue;
+/*
}

glob_t glob_buf;
@@ -361,6 +363,7 @@
}

free(pattern);
+*/
}

return true;
11 changes: 11 additions & 0 deletions Ports/mrsh/patches/disable-pipebuf.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/shell/redir.c 2020-02-03 18:09:07.918039522 +0300
+++ b/shell/redir.c 2020-02-03 18:10:13.701606476 +0300
@@ -46,7 +46,7 @@

// We can write at most PIPE_BUF bytes without blocking. If we want to write
// more, we need to fork and continue writing in another process.
- size_t remaining = PIPE_BUF;
+ size_t remaining = 0;
bool more = false;
size_t i;
for (i = 0; i < lines->len; ++i) {
17 changes: 17 additions & 0 deletions Ports/mrsh/patches/disable-sysctl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--- a/builtin/times.c 2020-02-03 17:40:26.634489515 +0300
+++ b/builtin/times.c 2020-02-03 17:41:52.351246681 +0300
@@ -16,11 +16,14 @@
}

struct tms buf;
+/*
long clk_tck = sysconf(_SC_CLK_TCK);
if (clk_tck == -1) {
perror("sysconf");
return 1;
}
+*/
+ long clk_tck = 1000;

if (times(&buf) == (clock_t)-1) {
perror("times");
18 changes: 18 additions & 0 deletions Ports/mrsh/patches/disable-ulimit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- a/builtin/ulimit.c 2020-02-03 17:43:24.961064732 +0300
+++ b/builtin/ulimit.c 2020-02-03 17:46:08.082450486 +0300
@@ -14,6 +14,9 @@
static const char ulimit_usage[] = "usage: ulimit [-f] [blocks]\n";

int builtin_ulimit(struct mrsh_state *state, int argc, char *argv[]) {
+ fprintf(stderr, "unimplemented\n");
+ return 1;
+/*
mrsh_optind = 0;
int opt;
while ((opt = mrsh_getopt(argc, argv, ":f")) != -1) {
@@ -58,4 +61,5 @@
}

return 0;
+*/
}
26 changes: 26 additions & 0 deletions Ports/mrsh/patches/hardcode-default-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/shell/path.c 2020-02-03 18:04:51.852832611 +0300
+++ b/shell/path.c 2020-02-03 18:06:50.023851071 +0300
@@ -27,18 +27,23 @@
return NULL;
}
} else {
+/*
size_t pathe_size = confstr(_CS_PATH, NULL, 0);
if (pathe_size == 0) {
return NULL;
}
pathe = malloc(pathe_size);
+*/
+ pathe = strdup("/bin:/usr/bin");
if (pathe == NULL) {
return NULL;
}
+/*
if (confstr(_CS_PATH, pathe, pathe_size) != pathe_size) {
free(pathe);
return NULL;
}
+*/
}

static char path[PATH_MAX + 1];
33 changes: 33 additions & 0 deletions Ports/mrsh/patches/workaround-limits-include-order.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--- a/builtin/cd.c 2020-02-03 17:38:39.619544218 +0300
+++ b/builtin/cd.c 2020-02-03 17:39:18.387886672 +0300
@@ -10,6 +10,8 @@
#include <unistd.h>
#include "builtin.h"

+#define PATH_MAX 4096
+
static const char cd_usage[] = "usage: cd [-L|-P] [-|directory]\n";

static int cd(struct mrsh_state *state, const char *path) {
--- a/shell/entry.c 2020-02-03 18:02:41.502709181 +0300
+++ b/shell/entry.c 2020-02-03 18:03:02.254888038 +0300
@@ -12,6 +12,8 @@
#include "parser.h"
#include "shell/trap.h"

+#define PATH_MAX 4096
+
static char *expand_str(struct mrsh_state *state, const char *src) {
struct mrsh_parser *parser = mrsh_parser_with_data(src, strlen(src));
if (parser == NULL) {
--- a/shell/path.c 2020-02-03 18:03:55.014342748 +0300
+++ b/shell/path.c 2020-02-03 18:04:08.167456108 +0300
@@ -8,6 +8,8 @@
#include <unistd.h>
#include "shell/path.h"

+#define PATH_MAX 4096
+
const char *expand_path(struct mrsh_state *state, const char *file, bool exec,
bool default_path) {
if (strchr(file, '/')) {
110 changes: 110 additions & 0 deletions Ports/mrsh/patches/workaround-warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
--- a/ast.c 2020-02-03 17:32:44.302405596 +0300
+++ b/ast.c 2020-02-03 17:35:40.520962185 +0300
@@ -576,6 +576,7 @@
return;
}
assert(false);
+ return;
case MRSH_NODE_COMMAND:;
struct mrsh_command *cmd = mrsh_node_get_command(node);
switch (cmd->type) {
@@ -626,6 +627,7 @@
return;
}
assert(false);
+ return;
case MRSH_NODE_WORD:;
struct mrsh_word *word = mrsh_node_get_word(node);
switch (word->type) {
@@ -653,8 +655,10 @@
return;
}
assert(false);
+ return;
}
assert(false);
+ return;
}

static void position_next(struct mrsh_position *dst,
@@ -700,6 +704,7 @@
return;
case MRSH_WORD_ARITHMETIC:
assert(false); // TODO
+ return;
case MRSH_WORD_LIST:;
struct mrsh_word_list *wl = mrsh_word_get_list(word);
if (wl->children.len == 0) {
@@ -713,6 +718,7 @@
return;
}
assert(false);
+ return;
}

void mrsh_command_range(struct mrsh_command *cmd, struct mrsh_position *begin,
@@ -800,8 +806,10 @@
mrsh_command_get_function_definition(cmd);
*begin = fd->name_range.begin;
mrsh_command_range(fd->body, NULL, end);
+ return;
}
assert(false);
+ return;
}

static void buffer_append_str(struct mrsh_buffer *buf, const char *str) {
@@ -818,6 +826,7 @@
case MRSH_WORD_COMMAND:
case MRSH_WORD_ARITHMETIC:
assert(false);
+ return;
case MRSH_WORD_LIST:;
const struct mrsh_word_list *wl = mrsh_word_get_list(word);
for (size_t i = 0; i < wl->children.len; ++i) {
@@ -827,6 +836,7 @@
return;
}
assert(false);
+ return;
}

char *mrsh_word_str(const struct mrsh_word *word) {
@@ -891,6 +901,7 @@
return;
}
assert(false);
+ return;
case MRSH_NODE_COMMAND:;
struct mrsh_command *cmd = mrsh_node_get_command(node);
switch (cmd->type) {
@@ -956,6 +967,7 @@
return;
}
assert(false);
+ return;
case MRSH_NODE_WORD:;
// TODO: quoting
struct mrsh_word *word = mrsh_node_get_word(node);
@@ -1002,8 +1014,10 @@
return;
}
assert(false);
+ return;
}
assert(false);
+ return;
}

char *mrsh_node_format(struct mrsh_node *node) {
--- a/main.c 2020-02-03 18:40:40.433381483 +0300
+++ b/main.c 2020-02-03 18:39:57.708015856 +0300
@@ -14,7 +14,7 @@
#include <unistd.h>
#include "frontend.h"

-extern char **environ;
+// extern char **environ;

int main(int argc, char *argv[]) {
struct mrsh_state *state = mrsh_state_create();

0 comments on commit ce56770

Please sign in to comment.