PERFORCE change 155322 for review
Ed Schouten
ed at FreeBSD.org
Sat Dec 27 05:41:14 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=155322
Change 155322 by ed at ed_dull on 2008/12/27 13:40:50
Several improvements to libteken:
- Change the Makefile to a BSD makefile, using <bsd.prog.mk>
- Make the source code build with WARNS set to 6. There were a
lot of places where we did comparisons, which required signing
(because of subtraction). I've converted the statements to
work without this.
Affected files ...
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/Makefile#2 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/teken.c#10 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/teken_demo.c#2 edit
.. //depot/projects/mpsafetty/sys/dev/syscons/teken/teken_subr.h#19 edit
Differences ...
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/Makefile#2 (text+ko) ====
@@ -1,20 +1,13 @@
-CFLAGS=-O2 -Wall -Werror -Wmissing-prototypes -Wstrict-prototypes -g
-LDFLAGS=-lutil -lncurses
-OBJS=teken.o teken_demo.o
+# $FreeBSD$
-all: teken_demo
+PROG= teken_demo
+SRCS= teken_demo.c teken.c teken_state.h
+CLEANFILES= teken_state.h
+LDADD= -lncurses -lutil
+NO_MAN=
+WARNS?= 6
-teken_demo: $(OBJS)
- $(CC) -o teken_demo $(LDFLAGS) $(OBJS)
+teken_state.h: gensequences sequences
+ awk -f gensequences sequences > ${.TARGET}
-teken_state.h: sequences gensequences
- awk -f gensequences < sequences > teken_state.h
-
-teken.o: teken.c teken.h teken_state.h teken_subr.h teken_subr_compat.h
- $(CC) $(CFLAGS) -c teken.c
-
-teken_demo.o: teken_demo.c teken.h
- $(CC) $(CFLAGS) -c teken_demo.c
-
-clean:
- -rm -f teken_demo *.o teken_state.h teken.log
+.include <bsd.prog.mk>
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/teken.c#10 (text+ko) ====
@@ -26,6 +26,7 @@
* $FreeBSD$
*/
+#include <sys/cdefs.h>
#if defined(__FreeBSD__) && defined(_KERNEL)
#include <sys/param.h>
#include <sys/lock.h>
@@ -208,7 +209,6 @@
switch (c) {
case '\0':
- teken_subr_null_character(t);
break;
case '\a':
teken_subr_bell(t);
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/teken_demo.c#2 (text+ko) ====
@@ -73,7 +73,7 @@
#define NROWS 24
struct pixel buffer[NCOLS][NROWS];
-static int pt;
+static int ptfd;
static void
printchar(const teken_pos_t *p)
@@ -111,21 +111,21 @@
}
static void
-test_bell(void *s)
+test_bell(void *s __unused)
{
beep();
}
static void
-test_cursor(void *s, const teken_pos_t *p)
+test_cursor(void *s __unused, const teken_pos_t *p)
{
move(p->tp_row, p->tp_col);
}
static void
-test_putchar(void *s, const teken_pos_t *p, teken_char_t c,
+test_putchar(void *s __unused, const teken_pos_t *p, teken_char_t c,
const teken_attr_t *a)
{
@@ -147,7 +147,7 @@
}
static void
-test_copy(void *s, const teken_rect_t *r, const teken_pos_t *p)
+test_copy(void *s __unused, const teken_rect_t *r, const teken_pos_t *p)
{
int nrow, ncol, x, y; /* Has to be signed - >= 0 comparison */
teken_pos_t d;
@@ -214,7 +214,7 @@
}
static void
-test_param(void *s, int cmd, int value)
+test_param(void *s __unused, int cmd, int value)
{
switch (cmd) {
@@ -228,10 +228,10 @@
}
static void
-test_respond(void *s, const void *buf, size_t len)
+test_respond(void *s __unused, const void *buf, size_t len)
{
- write(pt, buf, len);
+ write(ptfd, buf, len);
}
static void
@@ -260,7 +260,7 @@
}
int
-main(int argc, char *argv[])
+main(int argc __unused, char *argv[] __unused)
{
struct winsize ws;
teken_t t;
@@ -274,7 +274,7 @@
tp.tp_row = ws.ws_row = NROWS;
tp.tp_col = ws.ws_col = NCOLS;
- switch (forkpty(&pt, NULL, NULL, &ws)) {
+ switch (forkpty(&ptfd, NULL, NULL, &ws)) {
case -1:
perror("forkpty");
exit(1);
@@ -300,14 +300,12 @@
redraw_border();
FD_ZERO(&rfds);
- FD_SET(STDIN_FILENO, &rfds);
- FD_SET(pt, &rfds);
for (;;) {
FD_SET(STDIN_FILENO, &rfds);
- FD_SET(pt, &rfds);
+ FD_SET(ptfd, &rfds);
- if (select(pt + 1, &rfds, NULL, NULL, NULL) < 0) {
+ if (select(ptfd + 1, &rfds, NULL, NULL, NULL) < 0) {
if (errno == EINTR) {
redraw_all();
refresh();
@@ -320,11 +318,11 @@
bl = read(STDIN_FILENO, b, sizeof b);
if (bl <= 0)
break;
- write(pt, b, bl);
+ write(ptfd, b, bl);
}
- if (FD_ISSET(pt, &rfds)) {
- bl = read(pt, b, sizeof b);
+ if (FD_ISSET(ptfd, &rfds)) {
+ bl = read(ptfd, b, sizeof b);
if (bl <= 0)
break;
teken_input(&t, b, bl);
==== //depot/projects/mpsafetty/sys/dev/syscons/teken/teken_subr.h#19 (text+ko) ====
@@ -251,7 +251,7 @@
{
teken_assert(t->t_cursor.tp_row < t->t_scrollreg.ts_end);
- if (nrows >= t->t_scrollreg.ts_end - t->t_cursor.tp_row)
+ if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end)
t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1;
else
t->t_cursor.tp_row += nrows;
@@ -263,7 +263,7 @@
teken_subr_cursor_forward(teken_t *t, unsigned int ncols)
{
- if (ncols >= t->t_winsize.tp_col - t->t_cursor.tp_col)
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col)
t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
else
t->t_cursor.tp_col += ncols;
@@ -332,7 +332,7 @@
teken_subr_cursor_up(teken_t *t, unsigned int nrows)
{
- if (nrows > ((int)t->t_cursor.tp_row - t->t_scrollreg.ts_begin))
+ if (t->t_scrollreg.ts_begin + nrows >= t->t_cursor.tp_row)
t->t_cursor.tp_row = t->t_scrollreg.ts_begin;
else
t->t_cursor.tp_row -= nrows;
@@ -349,14 +349,14 @@
tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
tr.tr_end.tp_col = t->t_winsize.tp_col;
- if (ncols < (t->t_winsize.tp_col - t->t_cursor.tp_col)) {
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) {
+ tr.tr_begin.tp_col = t->t_cursor.tp_col;
+ } else {
/* Copy characters to the left. */
tr.tr_begin.tp_col = t->t_cursor.tp_col + ncols;
teken_funcs_copy(t, &tr, &t->t_cursor);
tr.tr_begin.tp_col = t->t_winsize.tp_col - ncols;
- } else {
- tr.tr_begin.tp_col = t->t_cursor.tp_col;
}
/* Blank trailing columns. */
@@ -372,14 +372,14 @@
tr.tr_end.tp_row = t->t_scrollreg.ts_end;
tr.tr_end.tp_col = t->t_winsize.tp_col;
- if (nrows < ((int)t->t_scrollreg.ts_end - t->t_cursor.tp_row)) {
+ if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) {
+ tr.tr_begin.tp_row = t->t_cursor.tp_row;
+ } else {
/* Copy rows up. */
tr.tr_begin.tp_row = t->t_cursor.tp_row + nrows;
teken_funcs_copy(t, &tr, &t->t_cursor);
tr.tr_begin.tp_row = t->t_scrollreg.ts_end - nrows;
- } else {
- tr.tr_begin.tp_row = t->t_cursor.tp_row;
}
/* Blank trailing rows. */
@@ -387,7 +387,7 @@
}
static void
-teken_subr_device_control_string(teken_t *t)
+teken_subr_device_control_string(teken_t *t __unused)
{
teken_printf("device control string???\n");
@@ -407,14 +407,14 @@
}
static void
-teken_subr_double_height_double_width_line_top(teken_t *t)
+teken_subr_double_height_double_width_line_top(teken_t *t __unused)
{
teken_printf("double height double width top\n");
}
static void
-teken_subr_double_height_double_width_line_bottom(teken_t *t)
+teken_subr_double_height_double_width_line_bottom(teken_t *t __unused)
{
teken_printf("double height double width bottom\n");
@@ -428,10 +428,10 @@
tr.tr_begin = t->t_cursor;
tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
- if (ncols < (t->t_winsize.tp_col - t->t_cursor.tp_col))
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col)
+ tr.tr_end.tp_col = t->t_winsize.tp_col - 1;
+ else
tr.tr_end.tp_col = t->t_cursor.tp_col + ncols;
- else
- tr.tr_end.tp_col = t->t_winsize.tp_col - 1;
teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
}
@@ -550,7 +550,9 @@
tr.tr_begin = t->t_cursor;
tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
- if (ncols < (t->t_winsize.tp_col - t->t_cursor.tp_col)) {
+ if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) {
+ tr.tr_end.tp_col = t->t_winsize.tp_col;
+ } else {
teken_pos_t tp;
/* Copy characters to the right. */
@@ -560,8 +562,6 @@
teken_funcs_copy(t, &tr, &tp);
tr.tr_end.tp_col = t->t_cursor.tp_col + ncols;
- } else {
- tr.tr_end.tp_col = t->t_winsize.tp_col;
}
/* Blank current location. */
@@ -577,7 +577,9 @@
tr.tr_begin.tp_col = 0;
tr.tr_end.tp_col = t->t_winsize.tp_col;
- if (nrows < ((int)t->t_scrollreg.ts_end - t->t_cursor.tp_row)) {
+ if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) {
+ tr.tr_end.tp_row = t->t_scrollreg.ts_end;
+ } else {
teken_pos_t tp;
/* Copy lines down. */
@@ -587,8 +589,6 @@
teken_funcs_copy(t, &tr, &tp);
tr.tr_end.tp_row = t->t_cursor.tp_row + nrows;
- } else {
- tr.tr_end.tp_row = t->t_scrollreg.ts_end;
}
/* Blank current location. */
@@ -633,11 +633,6 @@
}
static void
-teken_subr_null_character(teken_t *t)
-{
-}
-
-static void
teken_subr_pan_down(teken_t *t, unsigned int nrows)
{
@@ -859,7 +854,7 @@
}
static void
-teken_subr_scs(teken_t *t)
+teken_subr_scs(teken_t *t __unused)
{
teken_printf("scs???\n");
@@ -1046,21 +1041,21 @@
}
static void
-teken_subr_single_height_double_width_line(teken_t *t)
+teken_subr_single_height_double_width_line(teken_t *t __unused)
{
teken_printf("single height double width???\n");
}
static void
-teken_subr_single_height_single_width_line(teken_t *t)
+teken_subr_single_height_single_width_line(teken_t *t __unused)
{
teken_printf("single height single width???\n");
}
static void
-teken_subr_string_terminator(teken_t *t)
+teken_subr_string_terminator(teken_t *t __unused)
{
teken_printf("string terminator???\n");
More information about the p4-projects
mailing list