Call libtoolize. (#82836) Fix stupid segfault in set_scrollback_lines. vte_0_3_20
authorNalin Dahyabhai <nalin@src.gnome.org>
Fri, 24 May 2002 18:46:28 +0000 (18:46 +0000)
committerNalin Dahyabhai <nalin@src.gnome.org>
Fri, 24 May 2002 18:46:28 +0000 (18:46 +0000)
* autogen.sh: Call libtoolize. (#82836)
* src/vte.c: Fix stupid segfault in set_scrollback_lines.  (Patch from notting.)
Make another attempt to convert Pango font descriptions to xlfds.
* src/vte.c, src/vte.h: Expose set_emulation().
* src/vteapp.c: Add -c, -f, -t command-line flags for easier testing.

ChangeLog
README
src/vte.c
src/vte.h
src/vteapp.c
vte.spec

index 5ccc0dd..3200cf4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2002-05-24 nalin
+       * autogen.sh: Call libtoolize. (#82836)
+       * src/vte.c: Fix stupid segfault in set_scrollback_lines.  (Patch
+       from notting.)  Make another attempt to convert Pango font descriptions
+       to xlfds.
+       * src/vteapp.c: Add -c, -f, -t command-line flags for easier testing.
+
 2002-05-22 nalin
        * src/vte.c: Fix hiliting of matched strings.
 
diff --git a/README b/README
index b8e7d32..af4eff6 100644 (file)
--- a/README
+++ b/README
@@ -32,6 +32,7 @@
 - Sequence matching is greedy, so that C=AB matches C and not A and then B.
 - Bold doesn't work right if the default foreground color isn't gray.  Need
   to move to 20-color palette to fix this right.
+- Matching doesn't always work right.
 - I'm not sure the widget implementation itself is correct.  There are many
   changes in going from GTK+ 1.2 to 2.0, and examples of the proper way to do
   things is currently scarce, so some of it's guesswork.
index 1731585..583ca0f 100644 (file)
--- a/src/vte.c
+++ b/src/vte.c
@@ -837,7 +837,7 @@ vte_terminal_match_check_int(VteTerminal *terminal, long column,
                                     j++) {
                                        /* The offsets should be "sane". */
                                        g_assert(matches[j].rm_so + coffset < terminal->pvt->match_attributes->len);
-                                       g_assert(matches[j].rm_eo + coffset < terminal->pvt->match_attributes->len);
+                                       g_assert(matches[j].rm_eo + coffset <= terminal->pvt->match_attributes->len);
 #ifdef VTE_DEBUG
                                        if (vte_debug_on(VTE_DEBUG_MISC)) {
                                                char *match;
@@ -7164,68 +7164,61 @@ xft_pattern_from_pango_font_description(const PangoFontDescription *font_desc)
 #endif
 
 static char *
-xlfd_from_pango_font_description(const PangoFontDescription *fontdesc)
-{
-       int weighti, stylei, stretchi, size, count;
-       const char *weight, *style, *stretch, *family;
-       char *ret = NULL;
-       char **fonts;
-
-       family = pango_font_description_get_family(fontdesc);
-       weighti = pango_font_description_get_weight(fontdesc);
-       if (weighti > ((PANGO_WEIGHT_NORMAL + PANGO_WEIGHT_BOLD) / 2)) {
-               weight = "bold";
-       } else {
-               weight = "medium";
-       }
-       stylei = pango_font_description_get_style(fontdesc);
-       switch (stylei) {
-               case PANGO_STYLE_ITALIC:
-                       style = "i";
-                       break;
-               case PANGO_STYLE_OBLIQUE:
-                       style = "o";
-                       break;
-               default:
-                       style = "r";
-                       break;
-       }
-       stretchi = pango_font_description_get_stretch(fontdesc);
-       if (stretchi <= PANGO_STRETCH_CONDENSED) {
-               stretch = "condensed";
-       } else
-       if (stretchi <= PANGO_STRETCH_SEMI_CONDENSED) {
-               stretch = "semicondensed";
-       } else {
-               stretch = "normal";
+xlfd_from_pango_font_description(GtkWidget *widget,
+                                const PangoFontDescription *fontdesc)
+{
+       char *spec;
+       PangoContext *context;
+       PangoFont *font;
+       PangoXSubfont *subfont_ids;
+       PangoFontMap *fontmap;
+       int *subfont_charsets, i, count;
+       char *xlfd = NULL, *tmp, *subfont, *charset;
+
+       g_return_val_if_fail(fontdesc != NULL, NULL);
+       g_return_val_if_fail(GTK_IS_WIDGET(widget), NULL);
+
+       context = gtk_widget_get_pango_context(GTK_WIDGET(widget));
+       fontmap = pango_x_font_map_for_display(GDK_DISPLAY());
+       font = pango_font_map_load_font(fontmap, context, fontdesc);
+
+       if (font == NULL) {
+               g_print("no font loaded\n");
+               return g_strdup("fixed");
+       }
+
+       charset = g_strdup(nl_langinfo(CODESET));       /* FIXME */
+
+       count = pango_x_list_subfonts(font, &charset, 1,
+                                     &subfont_ids, &subfont_charsets);
+       g_print("pango_x_list_subfonts returned %d\n", count);
+
+       for (i = 0; i < count; i++) {
+               subfont = pango_x_font_subfont_xlfd(font, subfont_ids[i]);
+               if (xlfd) {
+                       tmp = g_strconcat(xlfd, ",", subfont, NULL);
+                       g_free(xlfd);
+                       g_free(subfont);
+                       xlfd = tmp;
+               } else {
+                       xlfd = subfont;
+               }
        }
 
-       size = pango_font_description_get_size(fontdesc);
+       spec = pango_font_description_to_string(fontdesc);
 
-       ret = g_strdup_printf("-*-%s*-%s-%s-%s--%d-*-*-*-*-*-*-*",
-                             family, weight, style, stretch,
-                             PANGO_PIXELS(size));
-       fonts = XListFonts(GDK_DISPLAY(), ret, 1, &count);
-       if (fonts != NULL) {
-#ifdef VTE_DEBUG
-               if (vte_debug_on(VTE_DEBUG_MISC)) {
-                       int i;
-                       char *desc = pango_font_description_to_string(fontdesc);
-                       for (i = 0; i < count; i++) {
-                               fprintf(stderr, "Font `%s' matched `%s'.\n",
-                                       desc, fonts[i]);
-                       }
-                       g_free(desc);
-               }
-#endif
-               XFreeFontNames(fonts);
+       g_print("Converted `%s' to `%s'.\n", spec, xlfd);
+
+       if (subfont_ids != NULL) {
+               g_free(subfont_ids);
        }
-       if (count > 0) {
-               return ret;
-       } else {
-               g_free(ret);
-               return NULL;
+       if (subfont_charsets != NULL) {
+               g_free(subfont_charsets);
        }
+       g_free(charset);
+       g_free(spec);
+
+       return xlfd;
 }
 
 /* Set the fontset used for rendering text into the widget. */
@@ -7294,7 +7287,7 @@ vte_terminal_set_font(VteTerminal *terminal,
                                                       terminal->pvt->fontdesc);
                        if (PANGO_IS_FONT(font)) {
                                /* We got a font, reset the description so that
-                                * it describes this font, and read metrics. */
+                                * it describes this font, and read its metrics. */
                                desc = pango_font_describe(font);
                                pango_font_description_free(terminal->pvt->fontdesc);
                                terminal->pvt->fontdesc = desc;
@@ -7306,9 +7299,9 @@ vte_terminal_set_font(VteTerminal *terminal,
                        }
                        /* Pull character cell size info from the metrics. */
                        if (pmetrics != NULL) {
-                               ascent = howmany(pango_font_metrics_get_ascent(pmetrics), PANGO_SCALE);
-                               descent = howmany(pango_font_metrics_get_descent(pmetrics), PANGO_SCALE);
-                               width = howmany(pango_font_metrics_get_approximate_char_width(pmetrics), PANGO_SCALE);
+                               ascent = pango_font_metrics_get_ascent(pmetrics) / PANGO_SCALE;
+                               descent = pango_font_metrics_get_descent(pmetrics) / PANGO_SCALE;
+                               width = pango_font_metrics_get_approximate_char_width(pmetrics) / PANGO_SCALE;
                                height = ascent + descent;
                                pango_font_metrics_unref(pmetrics);
                        }
@@ -7472,13 +7465,13 @@ vte_terminal_set_font(VteTerminal *terminal,
                        }
                }
 #endif
+               xlfds = NULL;
                if (font_desc) {
-                       xlfds = xlfd_from_pango_font_description(font_desc);
-               } else {
-                       xlfds = "-misc-fixed-medium-r-normal--12-*-*-*-*-*-*-*";
+                       xlfds = xlfd_from_pango_font_description(GTK_WIDGET(widget),
+                                                                font_desc);
                }
                if (xlfds == NULL) {
-                       xlfds = "-misc-fixed-medium-r-normal--12-*-*-*-*-*-*-*";
+                       xlfds = g_strdup("-misc-fixed-medium-r-normal--12-*-*-*-*-*-*-*");
                }
                if (terminal->pvt->fontset != NULL) {
                        XFreeFontSet(GDK_DISPLAY(), terminal->pvt->fontset);
@@ -7532,6 +7525,8 @@ vte_terminal_set_font(VteTerminal *terminal,
                        }
                        font_name_list = NULL;
                }
+               g_free(xlfds);
+               xlfds = NULL;
        }
 
        /* Now save the values. */
@@ -7692,7 +7687,7 @@ vte_terminal_set_scroll_adjustment(VteTerminal *terminal,
 }
 
 /* Set the type of terminal we're emulating. */
-static void
+void
 vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation)
 {
        const char *code, *value;
@@ -7748,7 +7743,7 @@ vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation)
                        vte_termcap_strip(tmp, &stripped, &stripped_length);
                        vte_trie_add(terminal->pvt->trie,
                                     stripped, stripped_length,
-                                    vte_terminal_capability_strings[i].capability,
+                                    code,
                                     0);
                        g_free(stripped);
                }
@@ -7756,6 +7751,7 @@ vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation)
        }
 
        /* Add emulator-specific sequences. */
+       if (strstr(emulation, "xterm") || strstr(emulation, "dtterm"))
        for (i = 0; vte_xterm_capability_strings[i].value != NULL; i++) {
                code = vte_xterm_capability_strings[i].code;
                value = vte_xterm_capability_strings[i].value;
@@ -7764,6 +7760,25 @@ vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation)
                             value, 0);
                g_free(stripped);
        }
+
+       /* Always define cr and lf. */
+       tmp = vte_termcap_find_string(terminal->pvt->termcap,
+                                     terminal->pvt->terminal,
+                                     "cr");
+       if (tmp == NULL) {
+               vte_trie_add(terminal->pvt->trie, "\r", 1, "cr", 0);
+       } else {
+               g_free(tmp);
+       }
+       tmp = vte_termcap_find_string(terminal->pvt->termcap,
+                                     terminal->pvt->terminal,
+                                     "sf");
+       if (tmp == NULL) {
+               vte_trie_add(terminal->pvt->trie, "\n", 1, "sf", 0);
+       } else {
+               g_free(tmp);
+       }
+
 #ifdef VTE_DEBUG
        if (vte_debug_on(VTE_DEBUG_MISC)) {
                fprintf(stderr, "Trie contents:\n");
@@ -7970,6 +7985,19 @@ vte_terminal_init(VteTerminal *terminal, gpointer *klass)
        }
 #endif
 
+#ifdef VTE_DEBUG
+       if (vte_debug_on(VTE_DEBUG_MISC)) {
+               if (terminal->pvt->use_xft) {
+                       fprintf(stderr, "Using Xft.\n");
+               } else
+               if (terminal->pvt->use_pango) {
+                       fprintf(stderr, "Using Pango.\n");
+               } else {
+                       fprintf(stderr, "Using core fonts.\n");
+               }
+       }
+#endif
+
        /* Set the default font. */
        vte_terminal_set_font(terminal, NULL);
 
@@ -7983,6 +8011,7 @@ vte_terminal_init(VteTerminal *terminal, gpointer *klass)
        }
 
        /* Initialize the screen history. */
+       pvt->normal_screen.row_data = NULL;
        vte_terminal_reset_rowdata(&pvt->normal_screen.row_data,
                                   pvt->scrollback_lines);
        pvt->normal_screen.cursor_current.row = 0;
@@ -7995,6 +8024,7 @@ vte_terminal_init(VteTerminal *terminal, gpointer *klass)
        pvt->normal_screen.insert_mode = FALSE;
        pvt->normal_screen.reverse_mode = FALSE;
 
+       pvt->alternate_screen.row_data = NULL;
        vte_terminal_reset_rowdata(&pvt->alternate_screen.row_data,
                                   pvt->scrollback_lines);
        pvt->alternate_screen.cursor_current.row = 0;
@@ -10460,6 +10490,11 @@ vte_terminal_set_scrollback_lines(VteTerminal *terminal, long lines)
        /* We require a minimum buffer size. */
        lines = MAX(lines, VTE_SCROLLBACK_MIN);
 
+       /* We need to resize both scrollback buffers, and this beats copying
+        * and pasting the same code twice. */
+       screens[0] = &terminal->pvt->normal_screen;
+       screens[1] = &terminal->pvt->alternate_screen;
+
        /* If we're being asked to resize to the same size, just save ourselves
         * the trouble, nod our heads, and smile. */
        if ((terminal->pvt->scrollback_lines != 0) &&
@@ -10468,10 +10503,8 @@ vte_terminal_set_scrollback_lines(VteTerminal *terminal, long lines)
                return;
        }
 
-       /* We need to resize both scrollback buffers, and this beats copying
-        * and pasting the same code twice. */
-       screens[0] = &terminal->pvt->normal_screen;
-       screens[1] = &terminal->pvt->alternate_screen;
+       /* We want to do the same thing to both screens, so we use a loop
+        * to avoid cut/paste madness. */
        for (i = 0; i < G_N_ELEMENTS(screens); i++) {
                /* Resize the buffers, but keep track of where the last data
                 * in the buffer is so that we can compensate for it being
index 7086407..7b79ad9 100644 (file)
--- a/src/vte.h
+++ b/src/vte.h
@@ -239,6 +239,9 @@ int vte_terminal_match_add(VteTerminal *terminal, const char *match);
 char *vte_terminal_match_check(VteTerminal *terminal, long column, long row,
                               int *tag);
 
+/* Set the emulation type.  Most of the time you won't need this. */
+void vte_terminal_set_emulation(VteTerminal *terminal, const char *emulation);
+
 G_END_DECLS
 
 #endif
index a1ed577..c785995 100644 (file)
@@ -19,6 +19,7 @@
 #ident "$Id$"
 #include "../config.h"
 #include <sys/stat.h>
+#include <getopt.h>
 #include <string.h>
 #include <gtk/gtk.h>
 #include <glib-object.h>
@@ -76,7 +77,26 @@ main(int argc, char **argv)
 {
        GtkWidget *window, *hbox, *scrollbar, *widget;
        const char *message = "Launching interactive shell...\r\n";
+       const char *font = NULL;
+       const char *terminal = NULL;
+       const char *command = NULL;
        struct stat st;
+       int opt;
+
+       /* Parse some command-line options. */
+       while ((opt = getopt(argc, argv, "c:f:t:")) != -1) {
+               switch (opt) {
+                       case 'c':
+                               command = optarg;
+                               break;
+                       case 'f':
+                               font = optarg;
+                               break;
+                       case 't':
+                               terminal = optarg;
+                               break;
+               }
+       }
 
        gtk_init(&argc, &argv);
 
@@ -130,10 +150,13 @@ main(int argc, char **argv)
                vte_terminal_set_background_transparent(VTE_TERMINAL(widget),
                                                        TRUE);
        }
+       if (terminal != NULL) {
+               vte_terminal_set_emulation(VTE_TERMINAL(widget), terminal);
+       }
 
        /* Set the default font. */
        vte_terminal_set_font_from_string(VTE_TERMINAL(widget),
-                                         "fixed 12");
+                                         font ? font : "fixed 12");
 
        /* Match "abcdefg". */
        vte_terminal_match_add(VTE_TERMINAL(widget), "abcdefg");
@@ -145,7 +168,7 @@ main(int argc, char **argv)
                                  strlen(message));
        }
 #endif
-       vte_terminal_fork_command(VTE_TERMINAL(widget), NULL, NULL);
+       vte_terminal_fork_command(VTE_TERMINAL(widget), command, NULL);
        vte_terminal_feed_child(VTE_TERMINAL(widget), "pwd\n", -1);
 
        /* Go for it! */
index 8899244..567a484 100644 (file)
--- a/vte.spec
+++ b/vte.spec
@@ -1,5 +1,5 @@
 Name: vte
-Version: 0.3.19
+Version: 0.3.20
 Release: 1
 Summary: An experimental terminal emulator.
 License: LGPL
@@ -53,6 +53,9 @@ make install DESTDIR=$RPM_BUILD_ROOT
 %{_libdir}/pkgconfig/*
 
 %changelog
+* Fri May 24 2002 Nalin Dahyabhai <nalin@redhat.com> 0.3.20-1
+- fixes from notting and otaylor
+
 * Tue May 21 2002 Nalin Dahyabhai <nalin@redhat.com> 0.3.19-1
 - fixes from andersca and Hidetoshi Tajima