aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/vidcontrol
diff options
context:
space:
mode:
authorBruce Evans <bde@FreeBSD.org>2017-04-03 10:47:01 +0000
committerBruce Evans <bde@FreeBSD.org>2017-04-03 10:47:01 +0000
commit8f92a81b815f0aa5c1d06703c6aaec7e4444b756 (patch)
treedd071df7e74e04f636414cd1ecb2c37063387c42 /usr.sbin/vidcontrol
parent709557d9037d3fe76438b9567913d8c971ba4c8a (diff)
downloadsrc-8f92a81b815f0aa5c1d06703c6aaec7e4444b756.tar.gz
src-8f92a81b815f0aa5c1d06703c6aaec7e4444b756.zip
Remove the global variable 'info' and fix associated bugs and style bugs.
This variable was used 4 times in 1 function and all uses were wrong. The 4 uses were in he test_frame() (show) function, to try to restore 4 colors, 2 unnecessarily and these 2 now broken. This was wrong because it is the previous colors that must be restored, but the global holds the original colors. Excessive setting of colors at the end restored the previous colors correctly in most cases, but I removed this a couple of revisions ago. Originally, this variable had 1 correct use, to test for being on a vty as a side effect of initializing it. This is now down in init(), and init() also leaves a better-named global with the same contents. Fix this by reading the current console info into a local variable in test_frame(), as is done for several other functions. Fix style bugs in this reading for all callers: - extra blank lines - all error messages different. The first one now in init() is not as specific as the old one, but it is after a different specific one for another ioctl and is unlikely to be reached when the first ioctl succeeds. Ones after the first are to repeat the ioctl, so are even more likely to be reached. The correctness of full removal of the old global depends on the error handling for failure to initialize it being unreachable. - err() instead of warn() for failure in load_font(). This is almost unreachable, and it makes no sense to continue after undoing previous changes with revert(). - unreachable return after err() for failure in dump_screen(). Undo large renaming of local variables from the good name 'info' to the bad name _info, which was done to protect the buggy global's bad name from -Wshadow warnings.
Notes
Notes: svn path=/head/; revision=316453
Diffstat (limited to 'usr.sbin/vidcontrol')
-rw-r--r--usr.sbin/vidcontrol/vidcontrol.c78
1 files changed, 37 insertions, 41 deletions
diff --git a/usr.sbin/vidcontrol/vidcontrol.c b/usr.sbin/vidcontrol/vidcontrol.c
index 2cd9bfe53a1a..508f3aebf031 100644
--- a/usr.sbin/vidcontrol/vidcontrol.c
+++ b/usr.sbin/vidcontrol/vidcontrol.c
@@ -96,7 +96,6 @@ static int vesa_rows;
static int font_height;
static int vt4_mode = 0;
static int video_mode_changed;
-static struct vid_info info;
static struct video_info new_mode_info;
@@ -121,7 +120,6 @@ init(void)
err(1, "getting active vty");
cur_info.console_info.size = sizeof(cur_info.console_info);
-
if (ioctl(0, CONS_GETINFO, &cur_info.console_info) == -1)
err(1, "getting console information");
@@ -487,7 +485,7 @@ load_font(const char *type, const char *filename)
const char *b[] = {filename, NULL};
const char *c[] = {"", size_sufx, NULL};
const char *d[] = {"", ".fnt", NULL};
- vid_info_t _info;
+ vid_info_t info;
struct sizeinfo {
int w;
@@ -501,14 +499,13 @@ load_font(const char *type, const char *filename)
if (vt4_mode) {
size_sufx[0] = '\0';
} else {
- _info.size = sizeof(_info);
- if (ioctl(0, CONS_GETINFO, &_info) == -1) {
+ info.size = sizeof(info);
+ if (ioctl(0, CONS_GETINFO, &info) == -1) {
revert();
- warn("failed to obtain current video mode parameters");
- return;
+ err(1, "getting console information");
}
- snprintf(size_sufx, sizeof(size_sufx), "-8x%d", _info.font_size);
+ snprintf(size_sufx, sizeof(size_sufx), "-8x%d", info.font_size);
}
fd = openguess((vt4_mode == 0) ? a : vt4a, b, c, d, &name);
@@ -1074,7 +1071,7 @@ static void
show_mode_info(void)
{
char buf[80];
- struct video_info _info;
+ struct video_info info;
int c;
int mm;
int mode;
@@ -1084,28 +1081,28 @@ show_mode_info(void)
printf("---------------------------------------"
"---------------------------------------\n");
- memset(&_info, 0, sizeof(_info));
+ memset(&info, 0, sizeof(info));
for (mode = 0; mode <= M_VESA_MODE_MAX; ++mode) {
- _info.vi_mode = mode;
- if (ioctl(0, CONS_MODEINFO, &_info))
+ info.vi_mode = mode;
+ if (ioctl(0, CONS_MODEINFO, &info))
continue;
- if (_info.vi_mode != mode)
+ if (info.vi_mode != mode)
continue;
- if (_info.vi_width == 0 && _info.vi_height == 0 &&
- _info.vi_cwidth == 0 && _info.vi_cheight == 0)
+ if (info.vi_width == 0 && info.vi_height == 0 &&
+ info.vi_cwidth == 0 && info.vi_cheight == 0)
continue;
printf("%3d (0x%03x)", mode, mode);
- printf(" 0x%08x", _info.vi_flags);
- if (_info.vi_flags & V_INFO_GRAPHICS) {
+ printf(" 0x%08x", info.vi_flags);
+ if (info.vi_flags & V_INFO_GRAPHICS) {
c = 'G';
- if (_info.vi_mem_model == V_INFO_MM_PLANAR)
+ if (info.vi_mem_model == V_INFO_MM_PLANAR)
snprintf(buf, sizeof(buf), "%dx%dx%d %d",
- _info.vi_width, _info.vi_height,
- _info.vi_depth, _info.vi_planes);
+ info.vi_width, info.vi_height,
+ info.vi_depth, info.vi_planes);
else {
- switch (_info.vi_mem_model) {
+ switch (info.vi_mem_model) {
case V_INFO_MM_PACKED:
mm = 'P';
break;
@@ -1126,25 +1123,25 @@ show_mode_info(void)
break;
}
snprintf(buf, sizeof(buf), "%dx%dx%d %c",
- _info.vi_width, _info.vi_height,
- _info.vi_depth, mm);
+ info.vi_width, info.vi_height,
+ info.vi_depth, mm);
}
} else {
c = 'T';
snprintf(buf, sizeof(buf), "%dx%d",
- _info.vi_width, _info.vi_height);
+ info.vi_width, info.vi_height);
}
printf(" %c %-15s", c, buf);
snprintf(buf, sizeof(buf), "%dx%d",
- _info.vi_cwidth, _info.vi_cheight);
+ info.vi_cwidth, info.vi_cheight);
printf(" %-5s", buf);
printf(" 0x%05zx %2dk %2dk",
- _info.vi_window, (int)_info.vi_window_size/1024,
- (int)_info.vi_window_gran/1024);
+ info.vi_window, (int)info.vi_window_size/1024,
+ (int)info.vi_window_gran/1024);
printf(" 0x%08zx %dk\n",
- _info.vi_buffer, (int)_info.vi_buffer_size/1024);
+ info.vi_buffer, (int)info.vi_buffer_size/1024);
}
}
@@ -1169,8 +1166,13 @@ show_info(char *arg)
static void
test_frame(void)
{
+ vid_info_t info;
int i, fore;
+ info.size = sizeof(info);
+ if (ioctl(0, CONS_GETINFO, &info) == -1)
+ err(1, "getting console information");
+
fore = 15;
fprintf(stdout, "\033[=0G\n\n");
@@ -1199,21 +1201,19 @@ static void
dump_screen(int mode, int opt)
{
scrshot_t shot;
- vid_info_t _info;
-
- _info.size = sizeof(_info);
+ vid_info_t info;
- if (ioctl(0, CONS_GETINFO, &_info) == -1) {
+ info.size = sizeof(info);
+ if (ioctl(0, CONS_GETINFO, &info) == -1) {
revert();
- err(1, "obtaining current video mode parameters");
- return;
+ err(1, "getting console information");
}
shot.x = shot.y = 0;
- shot.xsize = _info.mv_csz;
- shot.ysize = _info.mv_rsz;
+ shot.xsize = info.mv_csz;
+ shot.ysize = info.mv_rsz;
if (opt == DUMP_ALL)
- shot.ysize += _info.mv_hsz;
+ shot.ysize += info.mv_hsz;
shot.buf = alloca(shot.xsize * shot.ysize * sizeof(u_int16_t));
if (shot.buf == NULL) {
@@ -1329,10 +1329,6 @@ main(int argc, char **argv)
init();
- info.size = sizeof(info);
-
- if (ioctl(0, CONS_GETINFO, &info) == -1)
- err(1, "must be on a virtual console");
dumpmod = 0;
dumpopt = DUMP_FBF;
termmode = NULL;