Skip to content

Commit

Permalink
Add #env stuff to lesskey.
Browse files Browse the repository at this point in the history
Fix MS-DOS build.
  • Loading branch information
gwsw committed Mar 22, 1995
1 parent 1f8b372 commit 85fdd69
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 81 deletions.
6 changes: 3 additions & 3 deletions Makefile.dsu
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
CC = cl
LIBDIR = \msc6.0\lib

CFLAGS = -O /Alfw
CFLAGS = -O -Alfw
LDFLAGS = -O
LIBS = ${LIBDIR}\llibce.lib ${LIBDIR}\graphics.lib
LIBS = $(LIBDIR)\llibce.lib $(LIBDIR)\graphics.lib

#### End of system configuration section. ####

# This rule allows us to supply the necessary -D options
# in addition to whatever the user asks for.
.c.obj:
${CC} -c -I. ${CPPFLAGS} ${CFLAGS} $<
$(CC) -c -I. $(CPPFLAGS) $(CFLAGS) $<

SRC = main.c doscreen.c brac.c ch.c charset.c cmdbuf.c command.c \
decode.c edit.c filename.c forwback.c help.c ifile.c \
Expand Down
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ configure: configure.in
lint:
lint -I. ${CPPFLAGS} ${SRC}
newfuncs:
mv -f funcs.h funcs.h.old
awk -f mkfuncs.awk ${SRC} >funcs.h
mv -f ${srcdir}/funcs.h ${srcdir}/funcs.h.old
awk -f ${srcdir}/mkfuncs.awk ${SRC:%=${srcdir}/%} >${srcdir}/funcs.h
clean:
rm -f *.${O} core less lesskey

Expand Down
6 changes: 3 additions & 3 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,19 @@ init_charset()
{
register char *s;

s = getenv("LESSBINFMT");
s = lgetenv("LESSBINFMT");
setbinfmt(s);

/*
* See if environment variable LESSCHARSET is defined.
*/
s = getenv("LESSCHARSET");
s = lgetenv("LESSCHARSET");
if (icharset(s))
return;
/*
* LESSCHARSET is not defined: try LESSCHARDEF.
*/
s = getenv("LESSCHARDEF");
s = lgetenv("LESSCHARDEF");
if (s != NULL && *s != '\0')
{
ichardef(s);
Expand Down
2 changes: 2 additions & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@
#define EC_NOHISTORY 02
#define EC_NOCOMPLETE 04

/* Environment variable stuff */
#define EV_OK 01
60 changes: 53 additions & 7 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct tablelist
*/
static struct tablelist *list_fcmd_tables = NULL;
static struct tablelist *list_ecmd_tables = NULL;
static struct tablelist *list_var_tables = NULL;


/*
Expand Down Expand Up @@ -270,6 +271,18 @@ add_ecmd_table(buf, len)
error("Warning: some edit commands disabled", NULL_PARG);
}

/*
* Add an environment variable table.
*/
public void
add_var_table(buf, len)
char *buf;
int len;
{
if (add_cmd_table(&list_var_tables, buf, len) < 0)
error("Warning: environment variables from lesskey file unavailable", NULL_PARG);
}

/*
* Search a single command table for the command string in cmd.
*/
Expand Down Expand Up @@ -403,7 +416,29 @@ ecmd_decode(cmd, sp)
return (cmd_decode(list_ecmd_tables, cmd, sp));
}

/*
* Get the value of an environment variable.
* Looks first in the lesskey file, then in the real environment.
*/
public char *
lgetenv(var)
char *var;
{
int a;
char *s;

a = cmd_decode(list_var_tables, var, &s);
if (a == EV_OK)
return (s);
return (getenv(var));
}

#if USERFILE
/*
* Get an "integer" from a lesskey file.
* Integers are stored in a funny format:
* two bytes, low order first, in radix KRADIX.
*/
static int
gint(sp)
char **sp;
Expand All @@ -415,6 +450,9 @@ gint(sp)
return (n);
}

/*
* Process an old (pre-v241) lesskey file.
*/
static int
old_lesskey(buf, len)
char *buf;
Expand All @@ -433,14 +471,16 @@ old_lesskey(buf, len)
return (0);
}

/*
* Process a new (post-v241) lesskey file.
*/
static int
new_lesskey(buf, len)
char *buf;
int len;
{
char *p;
register int c;
register int done;
register int n;

/*
Expand All @@ -452,8 +492,7 @@ new_lesskey(buf, len)
buf[len-1] != C2_END_LESSKEY_MAGIC)
return (-1);
p = buf + 4;
done = 0;
while (!done)
for (;;)
{
c = *p++;
switch (c)
Expand All @@ -468,15 +507,21 @@ new_lesskey(buf, len)
add_ecmd_table(p, n);
p += n;
break;
case VAR_SECTION:
n = gint(&p);
add_var_table(p, n);
p += n;
break;
case END_SECTION:
done = 1;
break;
return (0);
default:
free(buf);
/*
* Unrecognized section type.
*/
return (-1);
}
}
return (0);
}

/*
Expand Down Expand Up @@ -641,7 +686,8 @@ editchar(c, flags)
* This does NOT include the original character that was
* passed in as a parameter.
*/
while (nch > 1) {
while (nch > 1)
{
ungetcc(usercmd[--nch]);
}
} else
Expand Down
37 changes: 28 additions & 9 deletions defines.ds
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,19 @@
#define HAVE_VOID 1

/* Define HAVE_TIME_T if your system supports the "time_t" type. */
#define HAVE_TIME_T 0
#define HAVE_TIME_T 1

/* Define HAVE_STRERROR if you have the strerror() function. */
#define HAVE_STRERROR 0
#define HAVE_STRERROR 1

/* Define HAVE_FILENO if you have the fileno() macro. */
#define HAVE_FILENO 0
#define HAVE_FILENO 1

/* Define HAVE_ERRNO if you have the errno variable */
#define HAVE_ERRNO 0

/* Define HAVE_SYS_ERRLIST if you have the sys_errlist[] variable */
#define HAVE_SYS_ERRLIST 0
#define HAVE_SYS_ERRLIST 1

/* Define HAVE_OSPEED if your termcap library has the ospeed variable */
#define HAVE_OSPEED 0
Expand All @@ -216,7 +216,7 @@
#define MUST_DEFINE_OSPEED 0

/* Define HAVE_LOCALE if you have locale.h and setlocale. */
#define HAVE_LOCALE 0
#define HAVE_LOCALE 1

/* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr */
#define HAVE_TERMIOS_FUNCS 0
Expand All @@ -243,7 +243,7 @@
#define HAVE_CTYPE_H 1

/* Define if you have the <errno.h> header file. */
#define HAVE_ERRNO_H 0
#define HAVE_ERRNO_H 1

/* Define if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1
Expand All @@ -261,19 +261,38 @@
#define HAVE_SYS_STREAM_H 0

/* Define if you have the <termcap.h> header file. */
/* #undef HAVE_TERMCAP_H */
#define HAVE_TERMCAP_H 0

/* Define if you have the <termio.h> header file. */
#define HAVE_TERMIO_H 0

/* Define if you have the <termios.h> header file. */
#define HAVE_TERMIOS_H 1
#define HAVE_TERMIOS_H 0

/* Define if you have the <time.h> header file. */
#define HAVE_TIME_H 1

/* Define if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
#define HAVE_UNISTD_H 0

/* Define if you have the <values.h> header file. */
#define HAVE_VALUES_H 0

#if _MSC_VER >= 700
/*
* The names of these things changed in Microsoft C version 7.0.
*/
#define videoconfig _videoconfig
#define rccoord _rccoord
#define off_t _off_t
#define O_RDONLY _O_RDONLY
#define O_WRONLY _O_WRONLY
#define O_APPEND _O_APPEND
#define O_BINARY _O_BINARY
#define O_TEXT _O_TEXT
#define find_t _find_t
#define stat _stat
#define S_IFMT _S_IFMT
#define S_IFDIR _S_IFDIR
#define S_IFREG _S_IFREG
#endif
43 changes: 40 additions & 3 deletions doscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public int bo_s_width, bo_e_width; /* Printing width of boldface seq */
public int ul_s_width, ul_e_width; /* Printing width of underline seq */
public int so_s_width, so_e_width; /* Printing width of standout seq */
public int bl_s_width, bl_e_width; /* Printing width of blink seq */
public int can_goto_line; /* Can move cursor to any line */

public int nm_fg_color = 7; /* Color of normal text */
public int nm_bg_color = 0;
Expand All @@ -69,7 +70,6 @@ extern int quiet; /* If VERY_QUIET, use visual bell for bell */
extern int know_dumb; /* Don't complain about a dumb terminal */
extern int back_scroll;
extern int swindow;
extern char *getenv();

/*
* Change terminal to "raw mode", or restore to "normal" mode.
Expand Down Expand Up @@ -110,14 +110,14 @@ scrsize(p_height, p_width)

if (w.numtextrows)
*p_height = w.numtextrows;
else if ((s = getenv("LINES")) != NULL && *s != '\0')
else if ((s = lgetenv("LINES")) != NULL && *s != '\0')
*p_height = atoi(s);
if (*p_height <= 0)
*p_height = 24;

if (w.numtextcols > 0)
*p_width = w.numtextcols;
else if ((s = getenv("COLUMNS")) != NULL)
else if ((s = lgetenv("COLUMNS")) != NULL)
*p_width = atoi(s);
if (*p_width <= 0)
*p_width = 80;
Expand Down Expand Up @@ -180,6 +180,31 @@ get_term()
*/


/*
* Initialize the screen to the correct color at startup.
*/
static void
initcolor()
{
struct videoconfig w;
char *blanks;
int row;
int col;

/*
* Create a complete, blank screen using "normal" colors.
*/
_settextcolor(nm_fg_color);
_setbkcolor(nm_bg_color);
_getvideoconfig(&w);
blanks = (char *) ecalloc(w.numtextcols, sizeof(char));
for (col = 0; col < w.numtextcols; col++)
blanks[col] = ' ';
for (row = w.numtextrows; row > 0; row--)
_outmem(blanks, w.numtextcols);
free(blanks);
}

/*
* Initialize terminal
*/
Expand All @@ -189,6 +214,7 @@ init()
/* {{ What could we take no_init (-X) to mean? }} */
sy_bg_color = _getbkcolor();
sy_fg_color = _gettextcolor();
initcolor();
flush();
init_done = 1;
}
Expand Down Expand Up @@ -275,6 +301,17 @@ lower_left()
_settextposition(sc_height,1);
}

/*
* Goto a specific line on the screen.
*/
public void
goto_line(slinenum)
int slinenum;
{
flush();
_settextposition(slinenum, 1);
}

/*
* Delay for a specified number of milliseconds.
*/
Expand Down
Loading

0 comments on commit 85fdd69

Please sign in to comment.