/****************************************************************************
- * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* scroll operation worked, and the refresh() code only had to do a
* partial repaint.
*
- * $Id: view.c,v 1.93 2013/04/27 19:46:53 tom Exp $
+ * $Id: view.c,v 1.101 2017/04/15 20:14:01 tom Exp $
*/
#include <test.priv.h>
#include <widechars.h>
+#include <popup_msg.h>
#include <time.h>
for (j = k = 0; j < len; j++) {
#if USE_WIDEC_SUPPORT
rc = (size_t) check_mbytes(wch, src + j, len - j, state);
- if (rc == (size_t) -1 || rc == (size_t) -2)
+ if (rc == (size_t) -1 || rc == (size_t) -2) {
break;
+ }
j += rc - 1;
- if ((width = wcwidth(wch)) < 0)
- break;
- if ((width > 0 && l > 0) || l == CCHARW_MAX) {
+ width = wcwidth(wch);
+ if (width == 0) {
+ if (l == 0) {
+ wstr[l++] = L' ';
+ }
+ } else if ((l > 0) || (l == CCHARW_MAX)) {
wstr[l] = L'\0';
l = 0;
- if (setcchar(dst + k, wstr, 0, 0, NULL) != OK)
+ if (setcchar(dst + k, wstr, 0, 0, NULL) != OK) {
break;
+ }
++k;
}
- if (width == 0 && l == 0)
- wstr[l++] = L' ';
wstr[l++] = wch;
#else
dst[k++] = (chtype) UChar(src[j]);
int
main(int argc, char *argv[])
{
+ static const char *help[] =
+ {
+ "Commands:",
+ " q,^Q,ESC - quit this program",
+ "",
+ " p,<Up> - scroll the viewport up by one row",
+ " n,<Down> - scroll the viewport down by one row",
+ " l,<Left> - scroll the viewport left by one column",
+ " r,<Right> - scroll the viewport right by one column",
+ "",
+ " h,<Home> - scroll the viewport to top of file",
+ " e,<End> - scroll the viewport to end of file",
+ "",
+ " ^L - repaint using redrawwin()",
+ "",
+ " 0 through 9 - enter digits for count",
+ " s - use entered count for halfdelay() parameter",
+ " - if no entered count, stop nodelay()",
+ " <space> - begin nodelay()",
+ 0
+ };
+
int MAXLINES = 1000;
FILE *fp;
char buf[BUFSIZ];
/* convert tabs and nonprinting chars so that shift will work properly */
for (s = buf, d = temp, col = 0; (*d = *s) != '\0'; s++) {
if (*d == '\r') {
- if (s[1] == '\n')
+ if (s[1] == '\n') {
continue;
- else
+ } else {
break;
+ }
}
if (*d == '\n') {
*d = '\0';
col++;
d++;
} else {
- sprintf(d, "\\%03o", UChar(*s));
+ _nc_SPRINTF(d, _nc_SLIMIT(sizeof(temp) - (d - buf))
+ "\\%03o", UChar(*s));
d += strlen(d);
col = (int) (d - temp);
}
break;
case 'q':
+ case QUIT:
+ case ESCAPE:
done = TRUE;
break;
if (!my_delay)
napms(50);
break;
+ case HELP_KEY_1:
+ popup_msg(stdscr, help);
+ break;
default:
beep();
break;
time_t this_time;
#if CAN_RESIZE
- sprintf(temp, "%.20s (%3dx%3d) col %d ", tag, LINES, COLS, shift);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "%.20s (%3dx%3d) col %d ", tag, LINES, COLS, shift);
i = (int) strlen(temp);
if ((i + 7) < (int) sizeof(temp)) {
- sprintf(temp + i, "view %.*s",
- (int) (sizeof(temp) - 7 - (size_t) i),
- fname);
+ _nc_SPRINTF(temp + i, _nc_SLIMIT(sizeof(temp) - (size_t) i)
+ "view %.*s",
+ (int) (sizeof(temp) - 7 - (size_t) i),
+ fname);
}
#else
(void) tag;
- sprintf(temp, "view %.*s", (int) sizeof(temp) - 7, fname);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "view %.*s", (int) sizeof(temp) - 7, fname);
#endif
move(0, 0);
printw("%.*s", COLS, temp);
clrtoeol();
this_time = time((time_t *) 0);
- strncpy(temp, ctime(&this_time), 30);
+ _nc_STRNCPY(temp, ctime(&this_time), (size_t) 30);
if ((i = (int) strlen(temp)) != 0) {
temp[--i] = 0;
if (move(0, COLS - i - 2) != ERR)