aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2010-10-08 13:46:26 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2010-10-08 13:46:26 -0700
commitf2330884f94b131481042a5742711f518eac84cf (patch)
treef6803993fcf6dfb7eece35b621b4290238056bde
parente670d25fb0819ee54be6dd0e1e1ce24810997dd7 (diff)
parentf9900a7bd9320b0a844a573be2ab22d3b6d9ae7e (diff)
downloadsyslinux-f2330884f94b131481042a5742711f518eac84cf.tar.gz
syslinux-f2330884f94b131481042a5742711f518eac84cf.tar.xz
syslinux-f2330884f94b131481042a5742711f518eac84cf.zip
Merge remote branch 'genec/rosh_for_hpa'
-rw-r--r--com32/rosh/Makefile20
-rw-r--r--com32/rosh/rosh.c59
-rw-r--r--com32/rosh/rosh.h44
3 files changed, 99 insertions, 24 deletions
diff --git a/com32/rosh/Makefile b/com32/rosh/Makefile
index 7bf5059c..f4b7d866 100644
--- a/com32/rosh/Makefile
+++ b/com32/rosh/Makefile
@@ -1,6 +1,8 @@
## -----------------------------------------------------------------------
##
## Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
+## Copyright 2010 Intel Corporation; author: H. Peter Anvin
+## Copyright 2008-2010 Gene Cumm - All Rights Reserved
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
@@ -11,18 +13,34 @@
## -----------------------------------------------------------------------
##
-## samples for syslinux users
+## ROSH Read Only Shell
##
topdir = ../..
include MCONFIG
+# from com32/sysdump/Makefile
+# The DATE is set on the make command line when building binaries for
+# official release. Otherwise, substitute a hex string that is pretty much
+# guaranteed to be unique to be unique from build to build.
+ifndef HEXDATE
+HEXDATE := $(shell $(PERL) $(topdir)/now.pl $(SRCS) $(wildcard *.h))
+endif
+ifndef DATE
+DATE := $(shell sh $(topdir)/gen-id.sh $(VERSION) $(HEXDATE))
+endif
+
+CFLAGS += -DDATE='"$(DATE)"'
+LNXCFLAGS += -DDATE='"$(DATE)"'
+
rosh.o: rosh.h
rosh.lo: rosh.h
all: rosh.c32
+allgrc: rosh.c32 rosh.lnx
+
tidy dist:
rm -f *.o *.lo *.a *.lst *.elf .*.d *.tmp
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index bf1176fb..9efa35ef 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -32,17 +32,24 @@
* debugging enabled; Comment to remove.
*/
#include "rosh.h"
+#include "../../version.h"
#define APP_LONGNAME "Read-Only Shell"
#define APP_NAME "rosh"
#define APP_AUTHOR "Gene Cumm"
#define APP_YEAR "2010"
-#define APP_VER "beta-b062"
+#define APP_VER "beta-b068"
-void rosh_version(void)
+void rosh_version(int vtype)
{
- printf("%s v %s; (c) %s %s.\n", APP_LONGNAME, APP_VER, APP_YEAR,
- APP_AUTHOR);
+ char env[256];
+ env[0] = 0;
+ printf("%s v %s; (c) %s %s.\n\tFrom Syslinux %s, %s\n", APP_LONGNAME, APP_VER, APP_YEAR, APP_AUTHOR, VERSION_STR, DATE);
+ switch (vtype) {
+ case 1:
+ rosh_get_env_ver(env, 256);
+ printf("\tRunning on %s\n", env);
+ }
}
void print_beta(void)
@@ -124,7 +131,7 @@ void rosh_help(int type, const char *cmdstr)
case 2:
istr += rosh_search_nonsp(cmdstr, rosh_search_sp(cmdstr, 0));
if ((cmdstr == NULL) || (strcmp(istr, "") == 0)) {
- rosh_version();
+ rosh_version(0);
puts(rosh_help_str2);
} else {
switch (istr[0]) {
@@ -138,7 +145,7 @@ void rosh_help(int type, const char *cmdstr)
break;
case 1:
default:
- rosh_version();
+ rosh_version(0);
puts(rosh_help_str1);
}
}
@@ -775,15 +782,14 @@ void rosh_dir(const char *cmdstr)
/* Page through a buffer string
* buf Buffer to page through
*/
-//HERE: minor pagination issue; sometimes prints 1 less than rows
-void rosh_more_buf(char *buf, int buflen, int rows, int cols)
+void rosh_more_buf(char *buf, int buflen, int rows, int cols, char *scrbuf)
{
char *bufp, *bufeol, *bufeol2; /* Pointer to current and next
end-of-line position in buffer */
int bufpos, bufcnt; /* current position, count characters */
- char scrbuf[ROSH_SBUF_SZ];
int inc;
int i, numln; /* Index, Number of lines */
+ int elpl; /* Extra lines per line read */
(void)cols;
@@ -799,10 +805,19 @@ void rosh_more_buf(char *buf, int buflen, int rows, int cols)
bufeol = buf + buflen;
i = numln;
} else {
- i += ((bufeol2 - bufeol) / cols);
- bufeol = bufeol2 + 1;
+ elpl = ((bufeol2 - bufeol - 1) / cols);
+ if (elpl < 0)
+ elpl = 0;
+ i += elpl;
+ ROSH_DEBUG2(" %d/%d ", elpl, i+1);
+ /* If this will not push too much, use it */
+ /* but if it's the first line, use it */
+ /* //HERE: We should probably snip the line off */
+ if ((i < numln) || (i == elpl))
+ bufeol = bufeol2 + 1;
}
}
+ ROSH_DEBUG2("\n");
bufcnt = bufeol - bufp;
printf("--(%d/%d @%d)\n", bufcnt, buflen, bufpos);
memcpy(scrbuf, bufp, bufcnt);
@@ -829,7 +844,7 @@ void rosh_more_buf(char *buf, int buflen, int rows, int cols)
/* Page through a single file using the open file stream
* fd File Descriptor
*/
-void rosh_more_fd(int fd, int rows, int cols)
+void rosh_more_fd(int fd, int rows, int cols, char *scrbuf)
{
struct stat fdstat;
int status;
@@ -851,7 +866,7 @@ void rosh_more_fd(int fd, int rows, int cols)
((int)fdstat.st_size - bufpos), f);
}
fclose(f);
- rosh_more_buf(buf, bufpos, rows, cols);
+ rosh_more_buf(buf, bufpos, rows, cols, scrbuf);
}
} else {
}
@@ -868,13 +883,16 @@ void rosh_more(const char *cmdstr)
char filestr[ROSH_PATH_SZ];
int cmdpos;
int rows, cols;
+ char *scrbuf;
+ int ret;
ROSH_DEBUG("CMD: '%s'\n", cmdstr);
/* Initialization */
filestr[0] = 0;
cmdpos = 0;
- if (getscreensize(1, &rows, &cols)) {
- ROSH_DEBUG("getscreensize() fail; fall back\n");
+ ret = getscreensize(1, &rows, &cols);
+ if (ret) {
+ ROSH_DEBUG("getscreensize() fail(%d); fall back\n", ret);
ROSH_DEBUG("\tROWS='%d'\tCOLS='%d'\n", rows, cols);
/* If either fail, go under normal size, just in case */
if (!rows)
@@ -883,6 +901,10 @@ void rosh_more(const char *cmdstr)
cols = 75;
}
ROSH_DEBUG("\tUSE ROWS='%d'\tCOLS='%d'\n", rows, cols);
+ /* 32 bit align beginning of row and over allocate */
+ scrbuf = malloc(rows * ((cols+3)&(INT_MAX - 3)));
+ if (!scrbuf)
+ return;
/* skip the first word */
cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
@@ -895,7 +917,7 @@ void rosh_more(const char *cmdstr)
printf("--File = '%s'\n", filestr);
fd = open(filestr, O_RDONLY);
if (fd != -1) {
- rosh_more_fd(fd, rows, cols);
+ rosh_more_fd(fd, rows, cols, scrbuf);
close(fd);
} else {
rosh_error(errno, "more", filestr);
@@ -905,6 +927,7 @@ void rosh_more(const char *cmdstr)
}
rosh_console_std();
}
+ free(scrbuf);
} /* rosh_more */
/* Page a file with rewind
@@ -1109,7 +1132,7 @@ char rosh_command(const char *cmdstr, const char *ipwdstr)
case 'v':
case 'V':
if (strncasecmp("version", tstr, tlen) == 0)
- rosh_version();
+ rosh_version(1);
else
rosh_help(1, NULL);
break;
@@ -1168,7 +1191,7 @@ int main(int argc, char *argv[])
if (argc != 1) {
rv = rosh_argcat(cmdstr, argc, argv, 1);
} else {
- rosh_version();
+ rosh_version(0);
print_beta();
cmdstr[0] = '\0';
}
diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h
index a8edda6a..b016e2f2 100644
--- a/com32/rosh/rosh.h
+++ b/com32/rosh/rosh.h
@@ -32,6 +32,7 @@
#include <stdbool.h> /* macro: true false */
#include <string.h> /* strcpy() strlen() memcpy() strchr() */
#include <sys/types.h>
+#include <limits.h>
#include <sys/stat.h> /* fstat() */
#include <fcntl.h> /* open(); open mode macros */
#include <dirent.h> /* fdopendir() opendir() readdir() closedir() DIR */
@@ -41,7 +42,7 @@
#include <ctype.h> /* isspace() */
#include <getkey.h>
-#include <consoles.h>
+#include <consoles.h> /* console_ansi_raw() console_ansi_std() */
#ifdef DO_DEBUG
# define ROSH_DEBUG printf
@@ -89,8 +90,17 @@ int stat(const char *pathname, struct stat *buf)
return ret;
}
+int rosh_get_env_ver(char *dest, size_t n)
+{
+ const struct syslinux_version *slv = syslinux_version();
+ strncpy(dest, slv->version_string, n);
+ return 0;
+}
+
#else
# include <termios.h>
+# include <sys/ioctl.h>
+# include <sys/utsname.h>
# define ROSH_IS_COM32 0
static inline char *syslinux_config_file(void)
@@ -98,19 +108,43 @@ static inline char *syslinux_config_file(void)
return "";
}
+int rosh_get_env_ver(char *dest, size_t n)
+{
+ int ret, len;
+ struct utsname env;
+ ret= uname(&env);
+ if (ret >= 0) {
+ strncpy(dest, env.sysname, n);
+ len = strlen(dest);
+ strncpy(dest + len, " ", (n - len));
+ len = strlen(dest);
+ strncpy(dest + len, env.release, (n - len));
+ }
+ return ret;
+}
+
static inline int getscreensize(int fd, int *rows, int *cols)
{
char *str;
int rv;
- *rows = 0;
- *cols = 0;
+ struct winsize ws;
+ if (rows)
+ *rows = 0;
+ if (cols)
+ *cols = 0;
+ str = NULL;
if (fd == 1) {
- if (rows) {
+ ioctl(0, TIOCGWINSZ, &ws);
+/* if (rows)
+ *rows = ws.ws_row;
+ if (cols)
+ *cols = ws.ws_col;*/
+ if (rows && !*rows) {
str = getenv("LINES");
if (str)
*rows = atoi(str);
}
- if (cols) {
+ if (cols && !*cols) {
str = getenv("COLUMNS");
if (str)
*cols = atoi(str);