bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Console and console-client patches


From: M. Gerards
Subject: Console and console-client patches
Date: Tue, 29 Apr 2003 21:58:10 +0200
User-agent: Internet Messaging Program (IMP) 3.1

Hi,

The first part of the patch, a patch for the console server, makes the width,
height and the number of scrollback lines configurable. The second part, a patch
for the vga driver for the console client calculates the height of the display
instead of using the constant 25, this is usefull when using a small font. (Or
when using svgatextmode after it has been ported or integrated with the vga
driver :)).

Both patches should be applied in order to work properly.

Thanks,
Marco Gerards

ChangeLog entry for the console server:

2003-04-29  Marco Gerards   <metgerards@student.han.nl>
        * display.c (display_create): Added arguments width, height and
        lines, variables with the same name were removed.
        * display.h (display_creat): Add missing arguments to prototype.
        * console.c (DEFAULT_WIDTH): New macro.
        (DEFAULT_HEIGHT): Likewise.
        (DEFAULT_LINES): Likewise.
        (STRX): Likewise.
        (STR): Likewise.
        (struct cons): New members lines, width and height.
        (vcons_lookup): Add missing arguments to display_create.
        (options): Add options width, height and lines.
        (parse_opt): Parse width, height and lines.
        (newfs_append_args): Append arguments width, height and lines.
        (main): Initialize cons with default width, height and lines.

ChangeLog entry for the console server:

2003-04-29  Marco Gerards   <metgerards@student.han.nl>
        * vga-dynafont.c (dynafont_get_width): New function.
        (dynafont_get_width): Likewise.
        * vga-dynafont.h ((dynafont_get_width): Add prototype.
        (dynafont_get_width): Add prototype.
        * vga.c (struct vga_display): Change refmatrix from a 2
        dimensional array to a pointer.
        (vga_display_init): Do not set the width and height yet...
        (vga_display_start): ...calculate it here. Also reserve memory for
        the refmatrix.
        (vga_display_scroll): Change code to handle new type of refmatrix.
        (vga_display_clear): Likewise.
        (vga_display_write): Likewise.

The patch:

Only in hurd.mg/console: CVS
diff -upr hurd/console/console.c hurd.mg/console/console.c
--- hurd/console/console.c      2003-02-26 21:06:13.000000000 +0100
+++ hurd.mg/console/console.c   2003-04-29 12:48:38.000000000 +0200
@@ -1,5 +1,5 @@
 /* console.c -- A console server.
-   Copyright (C) 1997, 1999, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1999, 2002, 2003 Free Software Foundation, Inc.
    Written by Miles Bader and Marcus Brinkmann.

    This program is free software; you can redistribute it and/or
@@ -61,6 +61,13 @@ volatile struct mapped_time_value *conso
 #define DEFAULT_BLINKING 0
 #define DEFAULT_REVERSED 0
 #define DEFAULT_CONCEALED 0
+#define DEFAULT_WIDTH 80
+#define DEFAULT_HEIGHT 25
+#define DEFAULT_LINES 50
+/* Stringification of a macro.  */
+#define STRX(s) #s
+#define STR(s) STRX(s)
+
 /* For the help output.  */
 #define DEFAULT_ATTRIBUTE_NAME "normal"
 #define DEFAULT_FOREGROUND CONS_COLOR_WHITE
@@ -128,6 +135,11 @@ struct cons
   mach_port_t underlying;
   /* A template for the stat information of all nodes.  */
   struct stat stat_template;
+
+  /* The amount of lines, width and height.  */
+  unsigned int lines;
+  unsigned int width;
+  unsigned int height;
 };



@@ -222,7 +234,8 @@ vcons_lookup (cons_t cons, int id, int c

   mutex_init (&vcons->lock);
   err = display_create (&vcons->display, cons->encoding ?: DEFAULT_ENCODING,
-                       cons->attribute);
+                       cons->attribute, cons->lines, cons->width,
+                       cons->height);
   if (err)
     {
       free (vcons->name);
@@ -1335,6 +1348,12 @@ static const struct argp_option options[
     " (default `" DEFAULT_ATTRIBUTE_NAME "')" },
   { "encoding",        'e', "NAME", 0, "Set encoding of virtual consoles to"
     " NAME (default `" DEFAULT_ENCODING "')" },
+  { "width", 'w', "WIDTH", 0, "Set width to WIDTH (default `"
+    STR(DEFAULT_WIDTH) "')" },
+  { "height", 'h', "HEIGHT", 0, "Set height to HEIGHT (default `"
+    STR(DEFAULT_HEIGHT) "')" },
+  { "lines", 'l', "LINES", 0, "Set amount of scrollback lines to LINES "
+    "(default `" STR(DEFAULT_LINES) "')" },
   {0}
 };

@@ -1443,7 +1462,8 @@ parse_opt (int opt, char *arg, struct ar
   cons_t cons = state->input ?: netfs_root_node->nn->cons;
   error_t err;
   int color = 0;
-
+  char *tail;
+
   switch (opt)
     {
     default:
@@ -1479,6 +1499,33 @@ parse_opt (int opt, char *arg, struct ar
       if (err)
        argp_error (state, "Invalid attribute specifier: %s", arg);
       break;
+
+    case 'l':
+      errno = 0;
+      cons->lines = strtoul (arg, &tail, 0);
+      if (tail == NULL || tail == arg || *tail != '\0')
+       argp_error (state, "LINES is not a number: %s", arg);
+      if (errno)
+       argp_error (state, "Overflow in argument LINES %s", arg);
+      break;
+
+    case 'w':
+      errno = 0;
+      cons->width = strtoul (arg, &tail, 0);
+      if (tail == NULL || tail == arg || *tail != '\0')
+       argp_error (state, "WIDTH is not a number: %s", arg);
+      if (errno)
+       argp_error (state, "Overflow in argument WIDTH %s", arg);
+      break;
+
+    case 'h':
+      errno = 0;
+      cons->height = strtoul (arg, &tail, 0);
+      if (tail == NULL || tail == arg || *tail != '\0')
+       argp_error (state, "HEIGHT is not a number: %s", arg);
+      if (errno)
+       argp_error (state, "Overflow in argument HEIGHT %s", arg);
+      break;

     case 'e':
       /* XXX Check validity of encoding.  Can we perform all necessary
@@ -1537,6 +1584,33 @@ netfs_append_args (char **argz, size_t *
       else
        err = errno;
     }
+  if (!err && cons->lines != DEFAULT_LINES)
+    {
+      char *buf;
+      asprintf (&buf, "--lines=%d", cons->lines);
+      if (buf)
+       err = argz_add (argz, argz_len, buf);
+      else
+       err = errno;
+    }
+  if (!err && cons->width != DEFAULT_WIDTH)
+    {
+      char *buf;
+      asprintf (&buf, "--width=%d", cons->lines);
+      if (buf)
+       err = argz_add (argz, argz_len, buf);
+      else
+       err = errno;
+    }
+  if (!err && cons->height != DEFAULT_HEIGHT)
+    {
+      char *buf;
+      asprintf (&buf, "--height=%d", cons->height);
+      if (buf)
+       err = argz_add (argz, argz_len, buf);
+      else
+       err = errno;
+    }
   if (!err && cons->attribute.intensity != DEFAULT_INTENSITY)
     {
       if (attrp != attr)
@@ -1930,6 +2004,9 @@ main (int argc, char **argv)
     error (1, ENOMEM, "Cannot create console structure");
   mutex_init (&cons->lock);
   cons->encoding = NULL;
+  cons->width = DEFAULT_WIDTH;
+  cons->height = DEFAULT_HEIGHT;
+  cons->lines = DEFAULT_LINES;
   cons->attribute.intensity = DEFAULT_INTENSITY;
   cons->attribute.underlined = DEFAULT_UNDERLINED;
   cons->attribute.blinking = DEFAULT_BLINKING;
diff -upr hurd/console/display.c hurd.mg/console/display.c
--- hurd/console/display.c      2002-10-21 23:01:52.000000000 +0200
+++ hurd.mg/console/display.c   2003-04-28 19:23:27.000000000 +0200
@@ -1,6 +1,6 @@
 /* display.c - The display component of a virtual console.
    Copyright (C) 1999 Kalle Olavi Niemitalo (emu.c from colortext 0.3).
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann and Kalle Olavi Niemitalo.

    This file is part of the GNU Hurd.
@@ -1801,13 +1801,11 @@ display_init (void)
    being ENCODING.  */
 error_t
 display_create (display_t *r_display, const char *encoding,
-               conchar_attr_t def_attr)
+               conchar_attr_t def_attr, unsigned int lines,
+               unsigned int width, unsigned int height)
 {
   error_t err = 0;
   display_t display;
-  int width = 80;
-  int height = 25;
-  int lines = 50;      /* XXX For now.  */

   *r_display = NULL;
   display = calloc (1, sizeof *display);
diff -upr hurd/console/display.h hurd.mg/console/display.h
--- hurd/console/display.h      2004-08-30 19:40:49.000000000 +0200
+++ hurd.mg/console/display.h   2003-04-29 11:42:13.000000000 +0200
@@ -1,5 +1,5 @@
 /* display.h - Interface to the display component of a virtual console.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This file is part of the GNU Hurd.
@@ -31,7 +31,9 @@ void display_init (void);
 /* Create a new virtual console display, with the system encoding
    being ENCODING and the default colors being FOREGROUND and BACKGROUND.  */
 error_t display_create (display_t *r_display, const char *encoding,
-                       conchar_attr_t attr);
+                       conchar_attr_t def_attr, unsigned int lines,
+                       unsigned int width, unsigned int height);
+

 /* Destroy the display DISPLAY.  */
 void display_destroy (display_t display);
Only in hurd.mg/console-client: CVS
diff -upr hurd/console-client/vga-dynafont.c 
hurd.mg/console-client/vga-dynafont.c
--- hurd/console-client/vga-dynafont.c  2002-10-03 21:33:43.000000000 +0200
+++ hurd.mg/console-client/vga-dynafont.c       2003-04-29 11:53:43.000000000 
+0200
@@ -1,5 +1,5 @@
 /* vga-dynafont.c - Dynamic font handling for VGA cards.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This file is part of the GNU Hurd.
@@ -606,6 +606,19 @@ dynafont_free (dynafont_t df)
   free (df);
 }

+/* Get dynafont width.  */
+int
+dynafont_get_width (dynafont_t df)
+{
+  return df->font->bbox.width;
+}
+
+/* Get dynafont height.  */
+int
+dynafont_get_height (dynafont_t df)
+{
+  return df->font->bbox.height;
+}


 /* Determine if CHR is a character that needs to be continuous in the
    horizontal direction by repeating the last (eighth) column in
diff -upr hurd/console-client/vga-dynafont.h 
hurd.mg/console-client/vga-dynafont.h
--- hurd/console-client/vga-dynafont.h  2002-09-17 14:26:10.000000000 +0200
+++ hurd.mg/console-client/vga-dynafont.h       2003-04-29 11:54:15.000000000 
+0200
@@ -1,5 +1,5 @@
 /* vga-dynafont.h - Interface to the dynamic font handling for VGA cards.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This file is part of the GNU Hurd.
@@ -50,6 +50,12 @@ error_t dynafont_new (bdf_font_t font, b
 /* Release a dynafont object and its associated resources.  */
 void dynafont_free (dynafont_t df);

+/* Get dynafont width.  */
+int dynafont_get_width (dynafont_t df);
+
+/* Get dynafont height.  */
+int dynafont_get_height (dynafont_t df);
+
 /* Look up the vga font index for an UCS-4 character.  If not already
    mapped, try to find space for a new entry and add the mapping.
    Acquires an additional reference to the character.  Might return
diff -upr hurd/console-client/vga.c hurd.mg/console-client/vga.c
--- hurd/console-client/vga.c   2002-09-17 14:26:10.000000000 +0200
+++ hurd.mg/console-client/vga.c        2003-04-29 11:57:50.000000000 +0200
@@ -1,5 +1,5 @@
 /* vga.c - The VGA device display driver.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    Written by Marcus Brinkmann.

    This file is part of the GNU Hurd.
@@ -46,7 +46,7 @@



 #define VGA_DISP_WIDTH 80
-#define VGA_DISP_HEIGHT 25
+#define VGA_VERT_RES 400

 /* The font file.  */
 #define DEFAULT_VGA_FONT "/lib/hurd/fonts/vga-system.bdf"
@@ -100,7 +100,7 @@ struct vga_display
   /* Remember for each cell on the display the glyph written to it and
      the colors (in the upper byte) assigned.  0 means unassigned.  */

-  struct refchr refmatrix[VGA_DISP_HEIGHT][VGA_DISP_WIDTH];
+  struct refchr *refmatrix;
 };


@@ -208,8 +208,6 @@ vga_display_init (void **handle, int no_

   /* Set this to 256 for full color support.  */
   disp->df_size = 512;
-  disp->width = VGA_DISP_WIDTH;
-  disp->height = VGA_DISP_HEIGHT;

   *handle = disp;
   return 0;
@@ -263,6 +261,12 @@ vga_display_start (void *handle)
     }
   dynafont_activate (disp->df);

+  disp->width = VGA_DISP_WIDTH;
+  disp->height = VGA_VERT_RES / dynafont_get_height (disp->df);
+
+  disp->refmatrix = calloc (sizeof (struct refchr),
+                           disp->width * disp->height);
+
   disp->dc = (disp->df_size == 512) ? dynacolor_init_8 : dynacolor_init_16;
   dynacolor_activate (&disp->dc);

@@ -346,13 +350,13 @@ vga_display_scroll (void *handle, int de
     {
       memmove (vga_videomem, vga_videomem + 2 * count,
               2 * disp->width * (disp->height - delta));
-      refpos = &disp->refmatrix[0][0];
+      refpos = disp->refmatrix;
     }
   else
     {
       memmove (vga_videomem + 2 * count, vga_videomem,
               2 * disp->width * (disp->height + delta));
-      refpos = &disp->refmatrix[disp->height + delta][0];
+      refpos = &disp->refmatrix[(disp->height + delta) * disp->width];
     }

   for (i = 0; i < count; i++)
@@ -370,15 +374,15 @@ vga_display_scroll (void *handle, int de

   if (delta > 0)
     {
-      memmove (&disp->refmatrix[0][0], &disp->refmatrix[0][0] + count,
+      memmove (disp->refmatrix, disp->refmatrix + count,
               sizeof (struct refchr) * disp->width * (disp->height - delta));
-      refpos = &disp->refmatrix[disp->height - delta][0];
+      refpos = &disp->refmatrix[(disp->height - delta) * disp->width];
     }
   else
     {
-      memmove (&disp->refmatrix[0][0] + count, &disp->refmatrix[0][0],
+      memmove (disp->refmatrix + count, disp->refmatrix,
               sizeof (struct refchr) * disp->width * (disp->height + delta));
-      refpos = &disp->refmatrix[0][0];
+      refpos = disp->refmatrix;
     }

   for (i = 0; i < count; i++)
@@ -471,7 +475,7 @@ static error_t
 vga_display_clear (void *handle, size_t length, uint32_t col, uint32_t row)
 {
   struct vga_display *disp = handle;
-  struct refchr *refpos = &disp->refmatrix[row][col];
+  struct refchr *refpos = &disp->refmatrix[row * disp->width + col];

   while (length > 0)
     {
@@ -498,7 +502,7 @@ vga_display_write (void *handle, conchar
 {
   struct vga_display *disp = handle;
   char *pos = vga_videomem + 2 * (row * disp->width + col);
-  struct refchr *refpos = &disp->refmatrix[row][col];
+  struct refchr *refpos = &disp->refmatrix[row * disp->width + col];

   /* Although all references to the current fgcol or bgcol could have
      been released here, for example due to a scroll operation, we




reply via email to

[Prev in Thread] Current Thread [Next in Thread]