summaryrefslogtreecommitdiffstats
path: root/src/h_bash.c
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@alpinelinux.org>2008-04-09 16:01:31 +0000
committerNathan Angelacos <nangel@alpinelinux.org>2008-04-09 16:01:31 +0000
commited4b386b68d5a073444af04d92a3df0609cfd251 (patch)
treebe02cea2cb48a93a38c369ad12096c1e2315ee89 /src/h_bash.c
parentef1e6197212624d629602763711ec99d23fe3542 (diff)
downloadhaserl-ed4b386b68d5a073444af04d92a3df0609cfd251.tar.bz2
haserl-ed4b386b68d5a073444af04d92a3df0609cfd251.tar.xz
9.2.24rc
Diffstat (limited to 'src/h_bash.c')
-rw-r--r--src/h_bash.c387
1 files changed, 216 insertions, 171 deletions
diff --git a/src/h_bash.c b/src/h_bash.c
index a3f3f55..661b398 100644
--- a/src/h_bash.c
+++ b/src/h_bash.c
@@ -87,16 +87,16 @@ bash_setup (char *shell, list_t * env)
av[count] = argv[count].string;
count--;
}
-
+
/* populate the environment */
- while (env)
- {
- next = env->next;
- putenv (env->buf);
- env = next;
- }
-
+ while (env)
+ {
+ next = env->next;
+ putenv (env->buf);
+ env = next;
+ }
+
execv (argv[0].string, av);
free (argv);
@@ -184,27 +184,30 @@ bash_eval (buffer_t * buf, char *str, size_t len)
void
bash_if (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for if'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for if'\nexit 99\n";
static char if_start[] = "if [[ ";
static char if_end[] = " ]]\nthen\n";
static char ex_start[] = "if ";
static char ex_end[] = "\nthen\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
else if (str[0] == '|')
- {
- str[0] = ' ';
- buffer_add (buf, ex_start, strlen (ex_start));
- buffer_add (buf, str, len);
- buffer_add (buf, ex_end, strlen (ex_end));
- } else {
- buffer_add (buf, if_start, strlen (if_start));
- buffer_add (buf, str, len);
- buffer_add (buf, if_end, strlen (if_end));
- }
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ }
+ else
+ {
+ buffer_add (buf, if_start, strlen (if_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, if_end, strlen (if_end));
+ }
}
@@ -212,27 +215,30 @@ bash_if (buffer_t * buf, char *str, size_t len)
void
bash_elif (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for elif'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for elif'\nexit 99\n";
static char elif_start[] = "elif [[ ";
static char elif_end[] = " ]]\nthen\n";
static char ex_start[] = "elif ";
static char ex_end[] = "\nthen\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
else if (str[0] == '|')
- {
- str[0] = ' ';
- buffer_add (buf, ex_start, strlen (ex_start));
- buffer_add (buf, str, len);
- buffer_add (buf, ex_end, strlen (ex_end));
- } else {
- buffer_add (buf, elif_start, strlen (elif_start));
- buffer_add (buf, str, len);
- buffer_add (buf, elif_end, strlen (elif_end));
- }
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ }
+ else
+ {
+ buffer_add (buf, elif_start, strlen (elif_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, elif_end, strlen (elif_end));
+ }
}
@@ -245,12 +251,14 @@ bash_else (buffer_t * buf, char *str, size_t len)
static char else_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, else_start, strlen (else_start));
- } else {
- buffer_add (buf, else_start2, strlen (else_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, else_start, strlen (else_start));
+ }
+ else
+ {
+ buffer_add (buf, else_start2, strlen (else_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, else_end, strlen (else_end));
}
@@ -263,13 +271,15 @@ bash_endif (buffer_t * buf, char *str, size_t len)
static char fi_start2[] = "fi #";
static char fi_end[] = "\n";
- if (len == 0 )
- {
- buffer_add (buf, fi_start, strlen (fi_start));
- } else {
- buffer_add (buf, fi_start2, strlen (fi_start2));
- buffer_add (buf, str, len);
- }
+ if (len == 0)
+ {
+ buffer_add (buf, fi_start, strlen (fi_start));
+ }
+ else
+ {
+ buffer_add (buf, fi_start2, strlen (fi_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, fi_end, strlen (fi_end));
}
@@ -278,18 +288,21 @@ bash_endif (buffer_t * buf, char *str, size_t len)
void
bash_case (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for case'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for case'\nexit 99\n";
static char case_start[] = "case ";
static char case_end[] = " in\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- } else {
- buffer_add (buf, case_start, strlen (case_start));
- buffer_add (buf, str, len);
- buffer_add (buf, case_end, strlen (case_end));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else
+ {
+ buffer_add (buf, case_start, strlen (case_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, case_end, strlen (case_end));
+ }
}
@@ -297,16 +310,19 @@ bash_case (buffer_t * buf, char *str, size_t len)
void
bash_when (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for when'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for when'\nexit 99\n";
static char elif_end[] = ")\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- } else {
- buffer_add (buf, str, len-1);
- buffer_add (buf, elif_end, strlen (elif_end));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else
+ {
+ buffer_add (buf, str, len - 1);
+ buffer_add (buf, elif_end, strlen (elif_end));
+ }
}
@@ -319,12 +335,14 @@ bash_otherwise (buffer_t * buf, char *str, size_t len)
static char otherwise_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, otherwise_start, strlen (otherwise_start));
- } else {
- buffer_add (buf, otherwise_start2, strlen (otherwise_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, otherwise_start, strlen (otherwise_start));
+ }
+ else
+ {
+ buffer_add (buf, otherwise_start2, strlen (otherwise_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, otherwise_end, strlen (otherwise_end));
}
@@ -337,13 +355,15 @@ bash_endcase (buffer_t * buf, char *str, size_t len)
static char endcase_start2[] = "esac #";
static char endcase_end[] = "\n";
- if (len == 0 )
- {
- buffer_add (buf, endcase_start, strlen (endcase_start));
- } else {
- buffer_add (buf, endcase_start2, strlen (endcase_start2));
- buffer_add (buf, str, len);
- }
+ if (len == 0)
+ {
+ buffer_add (buf, endcase_start, strlen (endcase_start));
+ }
+ else
+ {
+ buffer_add (buf, endcase_start2, strlen (endcase_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, endcase_end, strlen (endcase_end));
}
@@ -352,27 +372,30 @@ bash_endcase (buffer_t * buf, char *str, size_t len)
void
bash_while (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for while'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for while'\nexit 99\n";
static char while_start[] = "while [[ ";
static char while_end[] = " ]]\ndo\n";
static char ex_start[] = "while ";
static char ex_end[] = "\ndo\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
else if (str[0] == '|')
- {
- str[0] = ' ';
- buffer_add (buf, ex_start, strlen (ex_start));
- buffer_add (buf, str, len);
- buffer_add (buf, ex_end, strlen (ex_end));
- } else {
- buffer_add (buf, while_start, strlen (while_start));
- buffer_add (buf, str, len);
- buffer_add (buf, while_end, strlen (while_end));
- }
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ }
+ else
+ {
+ buffer_add (buf, while_start, strlen (while_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, while_end, strlen (while_end));
+ }
}
@@ -385,12 +408,14 @@ bash_endwhile (buffer_t * buf, char *str, size_t len)
static char endwhile_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, endwhile_start, strlen (endwhile_start));
- } else {
- buffer_add (buf, endwhile_start2, strlen (endwhile_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, endwhile_start, strlen (endwhile_start));
+ }
+ else
+ {
+ buffer_add (buf, endwhile_start2, strlen (endwhile_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, endwhile_end, strlen (endwhile_end));
}
@@ -399,27 +424,30 @@ bash_endwhile (buffer_t * buf, char *str, size_t len)
void
bash_until (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for until'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for until'\nexit 99\n";
static char until_start[] = "until [[ ";
static char until_end[] = " ]]\ndo\n";
static char ex_start[] = "until ";
static char ex_end[] = "\ndo\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
else if (str[0] == '|')
- {
- str[0] = ' ';
- buffer_add (buf, ex_start, strlen (ex_start));
- buffer_add (buf, str, len);
- buffer_add (buf, ex_end, strlen (ex_end));
- } else {
- buffer_add (buf, until_start, strlen (until_start));
- buffer_add (buf, str, len);
- buffer_add (buf, until_end, strlen (until_end));
- }
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ }
+ else
+ {
+ buffer_add (buf, until_start, strlen (until_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, until_end, strlen (until_end));
+ }
}
@@ -432,12 +460,14 @@ bash_enduntil (buffer_t * buf, char *str, size_t len)
static char enduntil_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, enduntil_start, strlen (enduntil_start));
- } else {
- buffer_add (buf, enduntil_start2, strlen (enduntil_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, enduntil_start, strlen (enduntil_start));
+ }
+ else
+ {
+ buffer_add (buf, enduntil_start2, strlen (enduntil_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, enduntil_end, strlen (enduntil_end));
}
@@ -446,18 +476,21 @@ bash_enduntil (buffer_t * buf, char *str, size_t len)
void
bash_for (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for for'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for for'\nexit 99\n";
static char for_start[] = "for ";
static char for_end[] = "\ndo\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- } else {
- buffer_add (buf, for_start, strlen (for_start));
- buffer_add (buf, str, len);
- buffer_add (buf, for_end, strlen (for_end));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
+ else
+ {
+ buffer_add (buf, for_start, strlen (for_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, for_end, strlen (for_end));
+ }
}
@@ -470,12 +503,14 @@ bash_endfor (buffer_t * buf, char *str, size_t len)
static char endfor_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, endfor_start, strlen (endfor_start));
- } else {
- buffer_add (buf, endfor_start2, strlen (endfor_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, endfor_start, strlen (endfor_start));
+ }
+ else
+ {
+ buffer_add (buf, endfor_start2, strlen (endfor_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, endfor_end, strlen (endfor_end));
}
@@ -484,27 +519,30 @@ bash_endfor (buffer_t * buf, char *str, size_t len)
void
bash_unless (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for unless'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for unless'\nexit 99\n";
static char unless_start[] = "if [[ ! ( ";
static char unless_end[] = " ) ]]\nthen\n";
static char ex_start[] = "if ! ";
static char ex_end[] = "\nthen\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
else if (str[0] == '|')
- {
- str[0] = ' ';
- buffer_add (buf, ex_start, strlen (ex_start));
- buffer_add (buf, str, len);
- buffer_add (buf, ex_end, strlen (ex_end));
- } else {
- buffer_add (buf, unless_start, strlen (unless_start));
- buffer_add (buf, str, len);
- buffer_add (buf, unless_end, strlen (unless_end));
- }
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ }
+ else
+ {
+ buffer_add (buf, unless_start, strlen (unless_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, unless_end, strlen (unless_end));
+ }
}
@@ -512,27 +550,30 @@ bash_unless (buffer_t * buf, char *str, size_t len)
void
bash_elun (buffer_t * buf, char *str, size_t len)
{
- static char err_msg[] = "echo 'error: missing expression for elun'\nexit 99\n";
+ static char err_msg[] =
+ "echo 'error: missing expression for elun'\nexit 99\n";
static char elun_start[] = "elif [[ ! ( ";
static char elun_end[] = " ) ]]\nthen\n";
static char ex_start[] = "elif ! ";
static char ex_end[] = "\nthen\n";
if (len == 0)
- {
- buffer_add (buf, err_msg, strlen (err_msg));
- }
+ {
+ buffer_add (buf, err_msg, strlen (err_msg));
+ }
else if (str[0] == '|')
- {
- str[0] = ' ';
- buffer_add (buf, ex_start, strlen (ex_start));
- buffer_add (buf, str, len);
- buffer_add (buf, ex_end, strlen (ex_end));
- } else {
- buffer_add (buf, elun_start, strlen (elun_start));
- buffer_add (buf, str, len);
- buffer_add (buf, elun_end, strlen (elun_end));
- }
+ {
+ str[0] = ' ';
+ buffer_add (buf, ex_start, strlen (ex_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, ex_end, strlen (ex_end));
+ }
+ else
+ {
+ buffer_add (buf, elun_start, strlen (elun_start));
+ buffer_add (buf, str, len);
+ buffer_add (buf, elun_end, strlen (elun_end));
+ }
}
@@ -545,12 +586,14 @@ bash_unelse (buffer_t * buf, char *str, size_t len)
static char unelse_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, unelse_start, strlen (unelse_start));
- } else {
- buffer_add (buf, unelse_start2, strlen (unelse_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, unelse_start, strlen (unelse_start));
+ }
+ else
+ {
+ buffer_add (buf, unelse_start2, strlen (unelse_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, unelse_end, strlen (unelse_end));
}
@@ -564,12 +607,14 @@ bash_endunless (buffer_t * buf, char *str, size_t len)
static char endunless_end[] = "\n";
if (len == 0)
- {
- buffer_add (buf, endunless_start, strlen (endunless_start));
- } else {
- buffer_add (buf, endunless_start2, strlen (endunless_start2));
- buffer_add (buf, str, len);
- }
+ {
+ buffer_add (buf, endunless_start, strlen (endunless_start));
+ }
+ else
+ {
+ buffer_add (buf, endunless_start2, strlen (endunless_start2));
+ buffer_add (buf, str, len);
+ }
buffer_add (buf, endunless_end, strlen (endunless_end));
}
#endif