Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3303 → Rev 3304

/branches/shell/uspace/app/bdsh/input.c
32,10 → 32,7
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#ifdef HELENOS
#include <io/stream.h>
#endif
 
#include "config.h"
#include "util.h"
121,7 → 118,6
return rc;
}
 
#ifdef HELENOS
/* Borrowed from Jiri Svoboda's 'cli' uspace app */
void read_line(char *buffer, int n)
{
148,9 → 144,7
putchar('\n');
buffer[chars] = '\0';
}
#endif
 
/* This is soupy, fix me */
void get_input(cliuser_t *usr)
{
char line[INPUT_MAX];
157,11 → 151,7
size_t len = 0;
 
printf("%s", usr->prompt);
#ifdef HELENOS
read_line(line, INPUT_MAX);
#else
fgets(line, INPUT_MAX, stdin);
#endif
len = strlen(line);
/* Make sure we don't have rubbish or a C/R happy user */
if (len == 0 || line[0] == '\n')
168,12 → 158,8
return;
if (len == 1 && line[len-1] == '\n')
return;
#ifndef HELENOS
/* Null terminate line */
if (len > 0 && line[len-1] == '\n')
line[len-1] = '\0';
#endif
usr->line = cli_strdup(line);
 
return;
}
 
/branches/shell/uspace/app/bdsh/input.h
7,9 → 7,6
extern int tok_input(cliuser_t *);
extern void get_input(cliuser_t *);
extern void cli_restricted(char *);
 
#ifdef HELENOS
extern void read_line(char *, int);
#endif
 
#endif
/branches/shell/uspace/app/bdsh/cmds/builtins/cd/cd.c
32,11 → 32,8
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifdef HELENOS
#include <errno.h>
#else
#include <sys/errno.h>
#endif
 
#include "util.h"
#include "errors.h"
#include "entry.h"
/branches/shell/uspace/app/bdsh/config.h
4,11 → 4,9
* ports */
 
/* Specific port work-arounds : */
#ifdef HELENOS
#define PATH_MAX 255
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 0
#endif
 
/* Work around for getenv() */
#define PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
/branches/shell/uspace/app/bdsh/exec.c
40,12 → 40,6
#include <string.h>
#include <fcntl.h>
 
#ifndef HELENOS
#include <linux/limits.h>
#include <sys/errno.h>
#include <sys/wait.h>
#endif
 
#include "config.h"
#include "util.h"
#include "exec.h"
81,23 → 75,10
found = (char *)malloc(PATH_MAX);
 
/* The user has specified a full or relative path, just give it back. */
#ifdef HELENOS
if (-1 != try_access(cmd))
#else
if (-1 != access(cmd, F_OK))
#endif
{
if (-1 != try_access(cmd)) {
return (char *) cmd;
}
 
#ifdef HELENOS
path_orig = PATH;
#else
path_orig = getenv("PATH");
if (NULL == path_orig)
path_orig = PATH;
#endif
 
path_tok = cli_strdup(path_orig);
 
/* Extract the PATH env to a path[] array */
116,12 → 97,7
for (i=0; path[i]; i++) {
memset(found, 0, sizeof(found));
snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);
#ifdef HELENOS
if (-1 != try_access(found))
#else
if (-1 != access(found, F_OK))
#endif
{
if (-1 != try_access(found)) {
free(path_tok);
return (char *) found;
}
133,7 → 109,6
return (char *) cmd;
}
 
#ifdef HELENOS
task_id_t try_exec(char *cmd, char **argv)
{
task_id_t tid;
155,74 → 130,3
 
return tid;
}
 
#else
int try_exec(char *cmd, char **argv)
{
char *tmp;
pid_t pid;
int status;
 
/* Copy the result of allocated 'found' */
tmp = cli_strdup(find_command(cmd));
/* free the pointer, no longer needed */
free(found);
 
if (-1 == (access(tmp, F_OK))) {
cli_error(CL_EFAIL,
"%s : No such external, modular or builtin command", tmp);
free(tmp);
return CL_EFAIL;
}
 
/* Create a child to run the program */
pid = fork();
if (pid == 0) {
execv(tmp, argv);
exit(errno);
} else if (pid > 0) {
/* Block until we get a PID (and result) */
wait(&status);
status = status / 256;
} else {
/* Could not fork, ulimit or out of memory */
cli_error(CL_ENOMEM, "Could not fork");
free(tmp);
return CL_ENOMEM;
}
 
free(tmp);
 
/* Decode any errors from execv() (these explain themselves) */
switch (status) {
case ENOTDIR:
cli_error(CL_EFAIL, "%s : No such file or directory", tmp);
status = CL_EFAIL;
break;
case EISDIR:
cli_error(CL_EFAIL, "%s : Command is a directory", tmp);
status = CL_EFAIL;
break;
case EACCES:
cli_error(CL_EPERM, "%s :", tmp);
status = CL_EFAIL;
break;
case ENOMEM:
cli_error(CL_ENOMEM, "%s :", tmp);
status = CL_EFAIL;
break;
case ENAMETOOLONG:
cli_error(CL_EFAIL, "Argument list too long");
status = CL_EFAIL;
break;
case EFAULT:
cli_error(CL_EFAIL, "Invalid argument pointer\n(please report "
"this to %s)", PACKAGE_BUGREPORT);
status = CL_EFAIL;
break;
}
 
return status;
}
 
#endif /* HELENOS */
/branches/shell/uspace/app/bdsh/exec.h
1,13 → 1,10
#ifndef EXEC_H
#define EXEC_H
 
#include <task.h>
 
extern char *find_command(char *);
#ifdef HELENOS
#include <task.h>
extern task_id_t try_exec(char *, char **);
#else
extern int try_exec(char *, char **);
#endif
extern unsigned int try_access(const char *);
 
#endif
/branches/shell/uspace/app/bdsh/scli.c
39,10 → 39,6
#include "errors.h"
#include "cmds/cmds.h"
 
#ifndef HELENOS
#include <linux/limits.h>
#endif
 
/* See scli.h */
static cliuser_t usr;
 
/branches/shell/uspace/app/bdsh/Makefile
36,7 → 36,7
SOFTINT_PREFIX = ../../lib/softint
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS += -I../../srv/kbd/include -DHELENOS
CFLAGS += -I../../srv/kbd/include
 
LIBS = $(LIBC_PREFIX)/libc.a
DEFS += -DRELEASE=\"$(RELEASE)\"