]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blobdiff - zephyr/zwgc/xshow.c
r4275@bucket (orig r265): kcr | 2008-01-21 02:57:32 -0500
[1ts-debian.git] / zephyr / zwgc / xshow.c
index 81c0d24d19e8e9c6ff55e0de66bcd48f8af4eac6..666701336082d94d94c8db976ea12b32e71c5375 100644 (file)
@@ -4,7 +4,7 @@
  *
  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
  *
- *      $Id: xshow.c,v 1.15 1999/08/13 00:19:52 danw Exp $
+ *      $Id$
  *
  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
  *      For copying and distribution information, see the file
@@ -14,7 +14,7 @@
 #include <sysdep.h>
 
 #if (!defined(lint) && !defined(SABER))
-static const char rcsid_xshow_c[] = "$Id: xshow.c,v 1.15 1999/08/13 00:19:52 danw Exp $";
+static const char rcsid_xshow_c[] = "$Id$";
 #endif
 
 #include <zephyr/mit-copyright.h>
@@ -26,9 +26,11 @@ static const char rcsid_xshow_c[] = "$Id: xshow.c,v 1.15 1999/08/13 00:19:52 dan
 #include <X11/Xresource.h>
 #include "pointer_dictionary.h"
 #include "new_memory.h"
+#include "new_string.h"
 #include "formatter.h"
 #include "variables.h"
 #include "zwgc.h"
+#include "X_driver.h"
 #include "X_fonts.h"
 #include "X_gram.h"
 #include "xmode_stack.h"
@@ -36,15 +38,13 @@ static const char rcsid_xshow_c[] = "$Id: xshow.c,v 1.15 1999/08/13 00:19:52 dan
 #define max(a,b)   ((a)>(b)?(a):(b))
 
 XContext desc_context;
-static pointer_dictionary colorname_dict = NULL;
 
 extern int internal_border_width;
 extern unsigned long default_bgcolor;
 extern unsigned long default_fgcolor;
-extern unsigned long x_string_to_color();
 
 void
-xshowinit()
+xshowinit(void)
 {
     desc_context = XUniqueContext();
 }
@@ -55,9 +55,9 @@ struct res_dict_type {
     char *             resclass;
 };
 
-static char *xres_get_resource (restype, style)
-    struct res_dict_type *restype;
-    char *style;
+static char *
+xres_get_resource(struct res_dict_type *restype,
+                 char *style)
 {
    char *desc;
    pointer_dictionary_binding *binding;
@@ -102,10 +102,10 @@ static struct res_dict_type fgcolor_resources = {
 };
 
 /*ARGSUSED*/
-char *mode_to_colorname (dpy, style, mode)
-    Display *dpy;
-    char *style;
-    xmode *mode;
+char *
+mode_to_colorname (Display *dpy,
+                  char *style,
+                  xmode *mode)
 {
     char *desc, *result;
 
@@ -116,16 +116,15 @@ char *mode_to_colorname (dpy, style, mode)
     return result;
 }
 
-void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
-                   beepcount)
-     Display *dpy;
-     char *style;
-     xblock *blocks;
-     xauxblock *auxblocks;
-     int num;
-     xlinedesc *lines;
-     int numlines;
-     int beepcount;
+void
+fixup_and_draw(Display *dpy,
+              char *style,
+              xauxblock *auxblocks,
+              xblock *blocks,
+              int num,
+              xlinedesc *lines,
+              int numlines,
+              int beepcount)
 {
     int gram_xalign = 1;
     int gram_yalign = 1;
@@ -134,7 +133,7 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
     x_gram *gram;
     int strindex = 0;
 
-    int line, block;
+    int line, block=0;
     int maxwidth=0, chars=0, maxascent, maxdescent;
     int ssize,  lsize,csize, rsize, width;
     int i, ascent, descent;
@@ -156,8 +155,7 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
        
        /* add up sizes for each block, get max ascent and descent */
        
-       for (i=0, block=lines[line].startblock; i<lines[line].numblock;
-            i++,block++) {
+       for (i=0; i<lines[line].numblock; i++,block++) {
            chars += auxblocks[block].len;
            ssize = XTextWidth(auxblocks[block].font, auxblocks[block].str,
                               auxblocks[block].len);
@@ -165,19 +163,19 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
            ascent = auxblocks[block].font->ascent;
            descent = auxblocks[block].font->descent;
            if (ascent>maxascent)
-               maxascent = ascent;
+             maxascent = ascent;
            if (descent>maxdescent)
-               maxdescent = descent;
+             maxdescent = descent;
            switch (auxblocks[block].align) {
-           case LEFTALIGN:
+             case LEFTALIGN:
                lsize += ssize;
                break;
-
-           case CENTERALIGN:
+               
+             case CENTERALIGN:
                csize += ssize;
                break;
-
-           case RIGHTALIGN:
+               
+             case RIGHTALIGN:
                rsize += ssize;
                break;
            }
@@ -247,6 +245,7 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
     /* set x1,y1,x2,y2 of each block also. */
 
     gram->text = (char *)malloc(chars);
+    block = 0;
 
     for (line=0; line<numlines; line++) {
        lofs = internal_border_width;
@@ -257,8 +256,7 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
        yend = yofs+lines[line].descent+1;   /* +1 because lines look scrunched
                                                without it. */
 
-       for (i=0, block=lines[line].startblock; i<lines[line].numblock;
-            i++,block++) {
+       for (i=0; i<lines[line].numblock; i++,block++) {
            blocks[block].fid = auxblocks[block].font->fid;
            switch (auxblocks[block].align) {
              case LEFTALIGN:
@@ -292,20 +290,8 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
            strindex += blocks[block].strlen;
        }
 
-       blocks[block].fid = block?blocks[block-1].fid:auxblocks[0].font->fid;
-       blocks[block].x = maxwidth + internal_border_width;
-       blocks[block].x1 = (lines[line].rsize?rofs:
-                          (lines[line].csize?cofs:
-                           lofs));
-       blocks[block].x2 = maxwidth + internal_border_width*2;
-       blocks[block].y = yofs;
-       blocks[block].y1 = ystart;
-       blocks[block].y2 = yend;
-       blocks[block].strindex = 0;
-       blocks[block].strlen = -1; /* magic value indicates newline */
-       block++;
-
        yofs = yend;
+
     }
 
     if ((geometry = var_get_variable("X_geometry")),(geometry[0]=='\0')) 
@@ -351,8 +337,8 @@ void fixup_and_draw(dpy, style, auxblocks, blocks, num, lines, numlines,
 }
 
 /* Silly almost-but-not-quite-useless helper function */
-char *no_dots_downcase_var(str)
-     char *str;
+char *
+no_dots_downcase_var(char *str)
 {
    register char *var, *var2;
 
@@ -367,11 +353,11 @@ char *no_dots_downcase_var(str)
 #define MODE_TO_FONT(dpy,style,mode) \
   get_font((dpy),(style),(mode)->font?(mode)->font:(mode)->substyle, \
           (mode)->size, (mode)->bold+(mode)->italic*2)
-void xshow(dpy, desc, numstr, numnl)
-     Display *dpy;
-     desctype *desc;
-     int numstr;
-     int numnl;
+void
+xshow(Display *dpy,
+      desctype *desc,
+      int numstr,
+      int numnl)
 {
     XFontStruct *font;
     xmode_stack modes = xmode_stack_create();
@@ -387,8 +373,8 @@ void xshow(dpy, desc, numstr, numnl)
 
     lines = (xlinedesc *)malloc(sizeof(xlinedesc)*(numnl+1));
 
-    blocks = (xblock *)malloc(sizeof(xblock)*(numstr+numnl+1));
-    auxblocks = (xauxblock *)malloc(sizeof(xauxblock)*(numstr+numnl+1));
+    blocks = (xblock *)malloc(sizeof(xblock)*numstr);
+    auxblocks = (xauxblock *)malloc(sizeof(xauxblock)*numstr);
 
     curmode.bold = 0;
     curmode.italic = 0;
@@ -517,24 +503,12 @@ void xshow(dpy, desc, numstr, numnl)
            break;
 
          case DT_NL:
-           font = MODE_TO_FONT(dpy,style,&curmode);
-
-           auxblocks[nextblock].len = -1;
-           auxblocks[nextblock].font = font;
-           if (curmode.expcolor)
-              blocks[nextblock].fgcolor = curmode.color;
-           else
-              blocks[nextblock].fgcolor =
-                x_string_to_color(mode_to_colorname(dpy,style,&curmode),
-                                  default_fgcolor);
-           nextblock++;
-
            lines[line].startblock = linestart;
-           lines[line].numblock = (nextblock-linestart)-1;
+           lines[line].numblock = nextblock-linestart;
+           font = MODE_TO_FONT(dpy,style,&curmode);
            lines[line].ascent = font->ascent;
            lines[line].descent = font->descent;
            line++;
-
            linestart = nextblock;
            break;
        }
@@ -543,19 +517,9 @@ void xshow(dpy, desc, numstr, numnl)
     /* case DT_EOF:    will drop through to here. */
 
     if (linestart != nextblock) {
-       font = MODE_TO_FONT(dpy,style,&curmode);
-       auxblocks[nextblock].len = -1;
-       auxblocks[nextblock].font = font;
-       if (curmode.expcolor)
-         blocks[nextblock].fgcolor = curmode.color;
-       else
-         blocks[nextblock].fgcolor =
-            x_string_to_color(mode_to_colorname(dpy,style,&curmode),
-                              default_fgcolor);
-       nextblock++;
-
        lines[line].startblock = linestart;
-       lines[line].numblock = (nextblock-linestart)-1;
+       lines[line].numblock = nextblock-linestart;
+       font = MODE_TO_FONT(dpy,style,&curmode);
        lines[line].ascent = 0;
        lines[line].descent = 0;
        line++;
@@ -570,10 +534,10 @@ void xshow(dpy, desc, numstr, numnl)
       free(style);
 }
 
-static void xhandleevent(dpy, w, event)
-     Display *dpy;
-     Window w;
-     XEvent *event;
+static void
+xhandleevent(Display *dpy,
+            Window w,
+            XEvent *event)
 {
     x_gram *gram;
     
@@ -588,8 +552,8 @@ static void xhandleevent(dpy, w, event)
     XFlush(dpy);
 }
 
-void x_get_input(dpy)
-     Display *dpy;
+void
+x_get_input(Display *dpy)
 {
     XEvent event;