Annotation of 43BSD/contrib/X/xfd/xfd.c, revision 1.1.1.1

1.1       root        1: #include <X/mit-copyright.h>
                      2: 
                      3: /* Copyright 1985, Massachusetts Institute of Technology */
                      4: #ifndef lint
                      5: static char *rcsid_xfd_c = "$Header: xfd.c,v 10.8 86/02/01 15:58:54 tony Rel $";
                      6: #endif
                      7: 
                      8: #include <X/Xlib.h>
                      9: #include <stdio.h>
                     10: #include <strings.h>
                     11: 
                     12: short gray_bits[16] = {
                     13:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
                     14:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
                     15:     0xaaaa, 0x5555, 0xaaaa, 0x5555,
                     16:     0xaaaa, 0x5555, 0xaaaa, 0x5555};
                     17: 
                     18: 
                     19: char chars[9];
                     20: int last_line;
                     21: 
                     22: main(argc, argv) 
                     23:     int argc;
                     24:     char **argv;
                     25:     {
                     26:     Window w;
                     27:     FontInfo *fontInfo;
                     28:     int width;
                     29:     char *fontname = "vtsingle";
                     30:     register char *option;
                     31:     char *border_color;
                     32:     char *back_color;
                     33:     char *fore_color;
                     34:     int border_width;
                     35:     int reverse = 0;
                     36:     char *geometry;                    /* user supplied geometry spec */
                     37:     char def[32];                      /* default size */
                     38:     int defwidth;
                     39:     int defheight;
                     40:     char display[128];
                     41:     register int i;
                     42:     OpaqueFrame window;                        /* frame for the window */
                     43:     Pixmap border_pixmap;
                     44:     int background;                    /* color of background */
                     45:     int foreground;                    /* color of graph */
                     46:     int highlight;                     /* color of text, scale */
                     47:     Color cdef;
                     48: 
                     49:     if ((option = XGetDefault(argv[0],"ReverseVideo")) != NULL )
                     50:                if (strcmp (option, "on") == 0)
                     51:                        reverse = 1;
                     52:     if ((option = XGetDefault(argv[0],"BorderWidth")) != NULL)
                     53:        border_width = atoi(option);
                     54:     if ((border_color = XGetDefault(argv[0],"Border")) == NULL)
                     55:        border_color = XGetDefault(argv[0],"BorderColor");
                     56:     back_color = XGetDefault(argv[0],"Background");
                     57:     fore_color = XGetDefault(argv[0],"Foreground");
                     58:     display[0] = '\0';
                     59: 
                     60:     for (i = 1; i < argc; i++) {                       /* Parse line */
                     61:        if (argv[i][0] == '=') {
                     62:            geometry = argv[i];
                     63:            continue;
                     64:        }
                     65:        if (index(argv[i], ':') != NULL) {        /* host:display */
                     66:            (void)strncpy(display, argv[i], sizeof(display));
                     67:            continue;
                     68:        }
                     69:        if (strcmp(argv[i], "-rv") == 0 ||
                     70:            strcmp(argv[i], "-reverse") == 0) {         /* black on white */
                     71:            reverse = 1;
                     72:            continue;
                     73:        }
                     74:        if (strcmp(argv[i], "-fw") == 0 ||
                     75:            strcmp(argv[i], "-forward") == 0) {         /* white on black */
                     76:            reverse = 0;
                     77:            continue;
                     78:        }
                     79:        if (strcmp(argv[i], "-bw") == 0 ||
                     80:            strcmp(argv[i], "-border") == 0) {          /* border width */
                     81:            if (++i >= argc) usage(argv[0]);
                     82:            border_width = atoi(argv[i]);
                     83:            continue;
                     84:        }
                     85:        if (strcmp(argv[i], "-bd") == 0 ||
                     86:            strcmp(argv[i], "-color") == 0) {          /* border color */
                     87:           if (++i >= argc) usage(argv[0]);
                     88:           border_color = argv[i];
                     89:           continue;
                     90:        }
                     91:        if (strcmp(argv[i], "-fg") == 0 ||
                     92:            strcmp(argv[i], "-foreground") == 0) {     /* foreground color */
                     93:           if (++i >= argc) usage(argv[0]);
                     94:           fore_color = argv[i];
                     95:           continue;
                     96:        }
                     97:        if (strcmp(argv[i], "-bg") == 0 ||
                     98:            strcmp(argv[i], "-background") == 0) {     /* background color */
                     99:           if (++i >= argc) usage(argv[0]);
                    100:           back_color = argv[i];
                    101:           continue;
                    102:        }
                    103:        if (argv[i][0] == '-') usage (argv[0]);
                    104:        fontname = argv[i];
                    105:     }
                    106:     if (!XOpenDisplay(display)) {
                    107:                fprintf (stderr, "%s: Could not open display %s!\n", argv[0], display);
                    108:        exit(1);
                    109:     }
                    110:     if (!(fontInfo = XOpenFont (fontname))) {
                    111:                fprintf (stderr, "%s: Could not open font %s!\n", argv[0], fontname);
                    112:        exit(1);
                    113:     }
                    114:     last_line = (unsigned char)(fontInfo->lastchar)/8;
                    115:     width = ComputeWidth (fontInfo);
                    116: 
                    117:     if (border_color && DisplayCells() > 2 &&
                    118:        XParseColor(border_color, &cdef) && XGetHardwareColor(&cdef))
                    119:        border_pixmap = XMakeTile(cdef.pixel);
                    120:     else if (border_color && strcmp(border_color, "black") == 0)
                    121:        border_pixmap = BlackPixmap;
                    122:     else if (border_color && strcmp(border_color, "white") == 0)
                    123:        border_pixmap = WhitePixmap;
                    124:     else
                    125:        border_pixmap = XMakePixmap (XStoreBitmap (16, 16, gray_bits),
                    126:                                        BlackPixel, WhitePixel);
                    127: 
                    128:     if (back_color && DisplayCells() > 2 &&
                    129:        XParseColor(back_color, &cdef) && XGetHardwareColor(&cdef)) {
                    130:        background = cdef.pixel;
                    131:     } else if (back_color && strcmp(back_color, "white") == 0) {
                    132:        background = WhitePixel;
                    133:        reverse = 0;
                    134:     } else if (back_color && strcmp(back_color, "black") == 0) {
                    135:        background = BlackPixel;
                    136:        reverse = 0;
                    137:     } else
                    138:        background = BlackPixel;
                    139: 
                    140:     if (fore_color && DisplayCells() > 2 &&
                    141:        XParseColor(fore_color, &cdef) && XGetHardwareColor(&cdef)) {
                    142:        foreground = cdef.pixel;
                    143:     } else if (fore_color && strcmp(fore_color, "black") == 0) {
                    144:        foreground = BlackPixel;
                    145:        reverse = 0;
                    146:     } else if (fore_color && strcmp(fore_color, "white") == 0) {
                    147:        foreground = WhitePixel;
                    148:        reverse = 0;
                    149:     } else
                    150:        foreground = WhitePixel;
                    151: 
                    152:     if (reverse) {
                    153:        highlight = background;
                    154:        background = foreground;
                    155:        foreground = highlight;
                    156:     }
                    157: 
                    158:     window.bdrwidth = border_width;
                    159:     window.border = border_pixmap;
                    160:     window.background = XMakeTile(background);
                    161: 
                    162:     defwidth = width + 10;
                    163:     defheight = fontInfo->height * (last_line + 1) + 10;
                    164:     (void) sprintf(def, "=%dx%d+300+300", defwidth, defheight);
                    165:     w = XCreate ("Font Display", argv[0], geometry, def, &window,
                    166:                defwidth, defheight);
                    167: 
                    168:     if (!w) {
                    169:        fprintf (stderr, "XCreateWindow failed\n");
                    170:        exit(1);
                    171:     }
                    172:     XSelectInput (w, ExposeWindow | ButtonPressed);
                    173:     XMapWindow (w);
                    174:     while (1) {
                    175:        XEvent event;
                    176:        int i, j;
                    177:        XWindowEvent (w, ExposeWindow | ButtonPressed, &event);
                    178:        if(event.type == ButtonPressed) exit(0);
                    179:        for (i=0;i<=last_line;i++) {
                    180:                    for (j=0;j<8;j++)
                    181:                chars[j] = (char)((8*i)+j);
                    182:                    XText (w, 5, 5+(i*fontInfo->height), chars, 8,
                    183:              fontInfo->id, foreground, background);
                    184:                    }
                    185:        }
                    186:     }    
                    187: 
                    188: usage (program)
                    189:        char *program;
                    190:     {
                    191:        fprintf(stderr,
                    192:                "usage: %s [host:display] [=geom] [-fw] [-rv] [-bw] [-bd] [-fg] [-bg] fontname\n", program);
                    193:        exit(1);
                    194:     }
                    195: 
                    196: ComputeWidth (fontInfo)
                    197:     FontInfo *fontInfo;
                    198:     {
                    199:     int maxwidth, i, j;
                    200: 
                    201:     /* Horrible hack needed for first line because line starts
                    202:        with \0, and XStringWidth considers \0 to terminate string */
                    203:     for (j=1;j<8;j++)
                    204:        chars[j] = j;
                    205:     maxwidth = XStringWidth (&chars[1], fontInfo, 0, 0);
                    206:     /* add the width of the '\0' character, if it has one */
                    207:     if (fontInfo->firstchar == '\0')
                    208:        maxwidth += (fontInfo->fixedwidth ? 
                    209:            fontInfo->width : fontInfo->widths[0]);
                    210:     
                    211:     /* now measure the width of remaining lines */
                    212:     for (i=1;i<=last_line;i++) {
                    213:        int this_width;
                    214:        for (j=0;j<8;j++)
                    215:            chars[j] = (char)((8*i)+j);
                    216:        this_width = XStringWidth (chars, fontInfo, 0, 0);
                    217:        if (this_width > maxwidth)
                    218:            maxwidth = this_width;
                    219:        }
                    220:     return (maxwidth);
                    221:     }
                    222:            

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.