Annotation of researchv9/X11/src/X.V11R1/clients/emacs/xterm.c, revision 1.1.1.1

1.1       root        1: #define BIGDEBUG
                      2: /* X Communication module for terminals which understand the X protocol.
                      3:    Copyright (C) 1985, 1986 Free Software Foundation, Inc.
                      4: 
                      5: This file is part of GNU Emacs.
                      6: 
                      7: GNU Emacs is distributed in the hope that it will be useful,
                      8: but WITHOUT ANY WARRANTY.  No author or distributor
                      9: accepts responsibility to anyone for the consequences of using it
                     10: or for whether it serves any particular purpose or works at all,
                     11: unless he says so in writing.  Refer to the GNU Emacs General Public
                     12: License for full details.
                     13: 
                     14: Everyone is granted permission to copy, modify and redistribute
                     15: GNU Emacs, but only under the conditions described in the
                     16: GNU Emacs General Public License.   A copy of this license is
                     17: supposed to have been given to you along with GNU Emacs so you
                     18: can know your rights and responsibilities.  It should be in a
                     19: file named COPYING.  Among other things, the copyright notice
                     20: and this notice must be preserved on all copies.  */
                     21: 
                     22: /* Written by Yakim Martillo, mods and things by Robert Krawitz  */
                     23: /* Redone for X11 by Robert French */
                     24: 
                     25: /*
                     26:  *     $Source: /@/orpheus/u1/X11/clients/emacs/RCS/xterm.c,v $
                     27:  *     $Author: newman $
                     28:  *     $Locker:  $
                     29:  *     $Header: xterm.c,v 1.2 87/09/12 16:34:06 newman Exp $
                     30:  */
                     31: 
                     32: #ifndef lint
                     33: static char *rcsid_xterm_c = "$Header: xterm.c,v 1.2 87/09/12 16:34:06 newman Exp $";
                     34: #endif lint
                     35: 
                     36: #include "config.h"
                     37: 
                     38: #ifdef HAVE_X_WINDOWS
                     39: 
                     40: #include "lisp.h"
                     41: #undef NULL
                     42: 
                     43: /* On 4.3 this loses if it comes after xterm.h.  */
                     44: #include <signal.h>
                     45: 
                     46: /* This may include sys/types.h, and that somehow loses
                     47:  * if this is not done before the other system files.  */
                     48: 
                     49: /*#include "xdebug.h"*/
                     50: 
                     51: #include "xterm.h"
                     52: 
                     53: /* Load sys/types.h if not already loaded.
                     54:    In some systems loading it twice is suicidal.  */
                     55: #ifndef makedev
                     56: #include <sys/types.h>
                     57: #endif
                     58: 
                     59: #include <sys/time.h>
                     60: #include <sys/ioctl.h>
                     61: #include <fcntl.h>
                     62: #include <stdio.h>
                     63: #include <ctype.h>
                     64: #include <errno.h>
                     65: #ifdef BSD
                     66: #include <strings.h>
                     67: #endif
                     68: #include <sys/stat.h>
                     69: 
                     70: #include "dispextern.h"
                     71: #include "termhooks.h"
                     72: #include "termopts.h"
                     73: #include "termchar.h"
                     74: #include "sink.h"
                     75: #include "sinkmask.h"
                     76: 
                     77: #define min(a,b) ((a)<(b) ? (a) : (b))
                     78: #define max(a,b) ((a)>(b) ? (a) : (b))
                     79: #define sigunblockx(sig) sigblock (0)
                     80: #define sigblockx(sig) sigblock (1 << ((sig) - 1))
                     81: 
                     82: #define METABIT 0200
                     83: #define MINWIDTH 12
                     84: #define MINHEIGHT 5
                     85: 
                     86: int pixelwidth;
                     87: int pixelheight;
                     88: char *progname;
                     89: 
                     90: XEvent *XXm_queue[XMOUSEBUFSIZE];
                     91: int XXm_queue_num;
                     92: char *XXcurrentfont;
                     93: XFontStruct *fontinfo;
                     94: Font XXfid;
                     95: int XXfontw,XXfonth,XXbase,XXisColor;
                     96: Colormap XXColorMap;
                     97: char *default_window;
                     98: int configure_pending;
                     99: extern struct display_line *DesiredScreen[], *PhysScreen[];
                    100: extern int initialized;
                    101: 
                    102: extern char *alternate_display;
                    103: 
                    104: int XXdebug;
                    105: int XXpid;
                    106: extern int screen_garbaged;
                    107: int XXxoffset, XXyoffset;
                    108: 
                    109: int WindowMapped;
                    110: 
                    111: static int flexlines;          /* last line affected by dellines or */
                    112:                                /* inslines functions */
                    113: extern int errno;
                    114: int VisibleX, VisibleY;                /* genuine location of cursor on screen */
                    115:                                /* if it is there */
                    116: static int SavedX, SavedY;     /* Where the cursor was before update */
                    117:                                /* started */
                    118: 
                    119: int CursorExists;              /* during updates cursor is turned off */
                    120: static int InUpdate;           /* many of functions here may be invoked */
                    121:                                /* even if no update in progress, when */
                    122:                                /* no update is in progress the action */
                    123:                                /* can be slightly different */
                    124: 
                    125: Display *XXdisplay;
                    126: Window XXwindow;
                    127: GC XXgc_norm,XXgc_rev,XXgc_curs,XXgc_temp;
                    128: XGCValues XXgcv;
                    129: Cursor EmacsCursor;
                    130: Pixmap SinkPixmap, SinkMaskPixmap;
                    131: 
                    132: char *fore_color;      /* Variables to store colors */
                    133: char *back_color;
                    134: char *brdr_color;
                    135: char *curs_color;
                    136: char *mous_color;
                    137: 
                    138: unsigned long fore;
                    139: unsigned long back;
                    140: unsigned long brdr;
                    141: unsigned long curs;
                    142: unsigned long mous;
                    143: 
                    144: char *desiredwindow;
                    145: 
                    146: int CurHL;                     /* Current Highlighting actually being */
                    147:                                /* being used for bold font right now*/
                    148: 
                    149: int XXborder;
                    150: int XXInternalBorder;
                    151: 
                    152: int (*handler)();
                    153: 
                    154: char *rindex();
                    155: 
                    156: extern Display *XOpenDisplay ();
                    157: extern Window XCreateSimpleWindow();
                    158: extern XFontStruct *XLoadQueryFont();
                    159: 
                    160: #ifdef BIGDEBUG
                    161: char debug_string[500000];
                    162: #endif BIGDEBUG
                    163: 
                    164: /* HLmode -- Changes the GX function for output strings.  Could be used to
                    165:  * change font.  Check an XText library function call. 
                    166:  */
                    167: 
                    168: HLmode (new)
                    169:      int new;
                    170: {
                    171:        CurHL =  new;
                    172: }
                    173: 
                    174: 
                    175: /* External interface to control of standout mode.
                    176:    Call this when about to modify line at position VPOS
                    177:    and not change whether it is highlighted.  */
                    178: 
                    179: XTreassert_line_highlight (highlight, vpos)
                    180:      int highlight, vpos;
                    181: {
                    182:        HLmode (highlight);
                    183: }
                    184: 
                    185: /* Call this when about to modify line at position VPOS
                    186:    and change whether it is highlighted.  */
                    187: 
                    188: XTchange_line_highlight (new_highlight, vpos, first_unused_hpos)
                    189:      int new_highlight, vpos, first_unused_hpos;
                    190: {
                    191:        HLmode (new_highlight);
                    192:        XTtopos (vpos, 0);
                    193:        XTclear_end_of_line (0);
                    194: }
                    195: 
                    196: 
                    197: /* Used for starting or restarting (after suspension) the X window.  Puts the
                    198:  * cursor in a known place, update does not begin with this routine but only
                    199:  * with a call to DoDsp.
                    200:  */
                    201: 
                    202: XTset_terminal_modes ()
                    203: {
                    204:        int stuffpending;
                    205: #ifdef XDEBUG
                    206:        fprintf (stderr, "XTset_terminal_modes\n");
                    207: #endif
                    208: 
                    209:        InUpdate = 0;
                    210:        stuffpending = 0;
                    211:        if (!initialized) {
                    212:                CursorExists = 0;
                    213:                VisibleX = 0;
                    214:                VisibleY = 0;
                    215:        }
                    216:        XTclear_screen ();
                    217: 
                    218: #ifdef FIONREAD
                    219:        ioctl (0, FIONREAD, &stuffpending);
                    220:        if (stuffpending)
                    221:                read_events_block ();
                    222: #endif
                    223: 
                    224: }
                    225: 
                    226: /* XTtopos moves the cursor to the correct location and checks whether an
                    227:  * update is in progress in order to toggle it on.
                    228:  */
                    229: 
                    230: XTtopos (row, col)
                    231:      register int row, col;
                    232: {
                    233:        int mask = sigblock (sigmask (SIGIO));
                    234: #ifdef XDEBUG
                    235:        fprintf (stderr, "XTtopos (X %d, Y %d)\n",col,row);
                    236: #endif
                    237: 
                    238:        cursX = col;
                    239:        cursY = row;
                    240: 
                    241:        if (InUpdate) {
                    242:                if (CursorExists)
                    243:                        CursorToggle ();
                    244:                sigsetmask (mask);
                    245:                return;
                    246:                /* Generally, XTtopos will be invoked */
                    247:                /* when InUpdate with !CursorExists */
                    248:                /* so that wasteful XFlush is not called */
                    249:        }
                    250:        if ((row == VisibleY) && (col == VisibleX)) {
                    251:                if (!CursorExists)
                    252:                        CursorToggle ();
                    253:                XFlush (XXdisplay);
                    254:                sigsetmask (mask);
                    255:                return;
                    256:        }
                    257:        if (CursorExists)
                    258:                CursorToggle ();
                    259:        VisibleX = col;
                    260:        VisibleY = row;
                    261:        if (!CursorExists)
                    262:                CursorToggle ();
                    263:        XFlush (XXdisplay);
                    264:        sigsetmask (mask);
                    265: }
                    266: 
                    267: /* Used to get the terminal back to a known state after resets.  Usually
                    268:  * used when restarting suspended or waiting emacs
                    269:  */
                    270: 
                    271: cleanup ()
                    272: {
                    273:        inverse_video = 0;
                    274:        HLmode (0);
                    275: }
                    276: 
                    277: /* wipes out numcols columns starting a current column on the current line */
                    278:   
                    279: XTclear_end_of_line (first_blank)
                    280:      register int first_blank;
                    281: {
                    282:        register int numcols;
                    283:        int mask;
                    284: 
                    285: #ifdef XDEBUG
                    286:        fprintf (stderr, "XTclear_end_of_line (blank %d)\n",first_blank);
                    287: #endif
                    288: 
                    289:        if (cursY < 0 || cursY >= screen_height)
                    290:                return;
                    291: 
                    292: #ifdef notdef
                    293:        if (first_blank >= screen_width)
                    294:                return;
                    295: 
                    296:        if (first_blank < 0)
                    297:                first_blank = 0;
                    298: #endif notdef
                    299:        
                    300:        mask = sigblock (sigmask (SIGIO));
                    301:        numcols = screen_width - cursX;
                    302:        if (cursY == VisibleY && VisibleX >= first_blank && CursorExists)
                    303:                CursorToggle ();
                    304: 
                    305:        if (CurHL)
                    306:                XFillRectangle (XXdisplay, XXwindow, XXgc_norm,
                    307:                                cursX*XXfontw+XXInternalBorder,
                    308:                                cursY*XXfonth+XXInternalBorder,
                    309:                                XXfontw*numcols,
                    310:                                XXfonth);
                    311:        else
                    312:                XClearArea (XXdisplay, XXwindow, 
                    313:                            cursX*XXfontw+XXInternalBorder, 
                    314:                            cursY*XXfonth+XXInternalBorder, 
                    315:                            XXfontw*numcols,
                    316:                            XXfonth,
                    317:                            0);
                    318:        XTtopos (cursY, first_blank);
                    319:        sigsetmask (mask);
                    320: }
                    321: 
                    322: XTreset_terminal_modes ()
                    323: {
                    324: #ifdef XDEBUG
                    325:        fprintf (stderr, "XTreset_terminal_modes\n");
                    326: #endif
                    327: 
                    328:        XTclear_screen ();
                    329: }
                    330: 
                    331: XTclear_screen ()
                    332: {
                    333:        int mask = sigblock (sigmask (SIGIO));
                    334: 
                    335: #ifdef XDEBUG
                    336:        fprintf (stderr, "XTclear_screen\n");
                    337: #endif
                    338: 
                    339:        HLmode (0);
                    340:        CursorExists = 0;
                    341:   
                    342:        cursX = 0;
                    343:        cursY = 0;
                    344:        SavedX = 0;
                    345:        SavedY = 0;
                    346:        VisibleX = 0;
                    347:        VisibleY = 0;
                    348:        XClearWindow(XXdisplay, XXwindow);
                    349:        CursorToggle ();
                    350:        if (!InUpdate)
                    351:                XFlush (XXdisplay);
                    352:        sigsetmask (mask);
                    353: }
                    354: 
                    355: /* used by dumprectangle which is usually invoked upon Expose
                    356:  * events which come from bit blt's or moving an obscuring opaque window
                    357:  */
                    358: 
                    359: dumpchars (ActiveScreen, numcols, tempX, tempY, tempHL)
                    360:      register struct display_line **ActiveScreen;
                    361:      register int numcols;
                    362:      register int tempX, tempY, tempHL;
                    363: {
                    364:        if (numcols <= 0)
                    365:                return;
                    366: 
                    367:        if (numcols-1+tempX > screen_width)
                    368:                numcols = screen_width-tempX+1;
                    369: 
                    370:        if (tempX < 0 || tempX >= screen_width ||
                    371:            tempY < 0 || tempY >= screen_height)
                    372:                return;
                    373: 
                    374:        XDrawImageString(XXdisplay, XXwindow, tempHL ? XXgc_rev : XXgc_norm,
                    375:                         tempX*XXfontw+XXInternalBorder,
                    376:                         tempY*XXfonth+XXInternalBorder+XXbase,
                    377:                         &ActiveScreen[tempY+1]->body[tempX],
                    378:                         numcols);
                    379: }
                    380: 
                    381: /* When a line has been changed this function is called.  X is so fast
                    382:  * that the actual sequence is ignore.  Rather, the new version of the
                    383:  * line is simply output if this function is invoked while in UpDate.
                    384:  * Sometimes writechars can be invoked when not in update if text is to
                    385:  * be output at the end of the line.  In this case the whole line is not
                    386:  * output.  Simply the new text at the current cursor position given
                    387:  * by VisibleX,Y.  The cursor is moved to the end of the new text.
                    388:  */
                    389: 
                    390: writechars (start, end)
                    391:      register char *start, *end;
                    392: {
                    393:        int mask = sigblock (sigmask (SIGIO));
                    394: 
                    395:        if (cursY < 0 || cursY >= screen_height) {
                    396:                sigsetmask (mask);
                    397:                return;
                    398:        }
                    399: 
                    400:        if (CursorExists)
                    401:                CursorToggle ();
                    402: 
                    403:        if (cursY < 0 || cursY >= screen_height ||
                    404:            cursX < 0 || cursX >= screen_width) {
                    405:                sigsetmask (mask);
                    406:                return;
                    407:        }
                    408:        
                    409:        if (end-start+cursX >= screen_width)
                    410:                end = start+screen_width-cursX -1;
                    411: 
                    412:        if (end >= start) {
                    413:                if (start)
                    414:                        XDrawImageString(XXdisplay, XXwindow,
                    415:                                         CurHL ? XXgc_rev : XXgc_norm,
                    416:                                         cursX * XXfontw+XXInternalBorder,
                    417:                                         cursY * XXfonth+XXInternalBorder+XXbase,
                    418:                                         start,
                    419:                                         end-start+1);
                    420:                else
                    421:                        if (CurHL)
                    422:                                XFillRectangle (XXdisplay, XXwindow, XXgc_norm,
                    423:                                                cursX*XXfontw+XXInternalBorder,
                    424:                                                cursY*XXfonth+XXInternalBorder,
                    425:                                                (end-start+1)*XXfontw,
                    426:                                                XXfonth);
                    427:                        else
                    428:                                XClearArea (XXdisplay, XXwindow, 
                    429:                                            cursX*XXfontw+XXInternalBorder, 
                    430:                                            cursY*XXfonth+XXInternalBorder, 
                    431:                                            (end-start+1)*XXfontw,
                    432:                                            XXfonth,0);
                    433:                VisibleX = cursX+end-start+1;
                    434:                if (InUpdate)
                    435:                        cursX = VisibleX;
                    436:        } 
                    437:        if (!InUpdate && !CursorExists)
                    438:                CursorToggle();
                    439:        sigsetmask (mask);
                    440: }
                    441: 
                    442: static 
                    443: XTwrite_chars (start, len)
                    444:      register char *start;
                    445:      register int len;
                    446: {
                    447: #ifdef XDEBUG
                    448:        fprintf (stderr, "XTwrite_chars (len %d)\n",len);
                    449: #endif
                    450: 
                    451:        writechars (start, start+len-1);
                    452: }
                    453: 
                    454: /* The following routine is for the deaf or for the pervert who prefers 
                    455:  * that his terminal flashes at him rather than beep at him.
                    456:  */
                    457: 
                    458: static int flashedback;
                    459: 
                    460: XTflash ()
                    461: {
                    462:        XGCValues gcv_temp;
                    463:        struct itimerval itimer;
                    464:        int mask = sigblock (sigmask (SIGIO));
                    465: 
                    466:        extern int flashback ();
                    467: 
                    468: #ifdef XDEBUG
                    469:        fprintf (stderr, "XTflash\n");
                    470: #endif
                    471: 
                    472:        XXgc_temp = XCreateGC(XXdisplay, XXwindow, 0, &gcv_temp);
                    473:        XSetState(XXdisplay, XXgc_temp, WhitePixel(XXdisplay,0),
                    474:                  BlackPixel(XXdisplay,0), GXinvert,
                    475:                  AllPlanes);
                    476:        
                    477:        signal (SIGALRM, flashback);
                    478:        getitimer (ITIMER_REAL, &itimer);
                    479:        itimer.it_value.tv_usec += 250000;
                    480:        itimer.it_interval.tv_sec = 0;
                    481:        itimer.it_interval.tv_usec = 0;
                    482:        flashedback = 0;
                    483: 
                    484:        setitimer (ITIMER_REAL, &itimer, 0);
                    485: 
                    486:        XFillRectangle (XXdisplay, XXwindow, XXgc_temp, 0, 0,
                    487:                        screen_width*XXfontw+2*XXInternalBorder,
                    488:                        screen_height*XXfonth+2*XXInternalBorder);
                    489:        XFlush (XXdisplay);
                    490: 
                    491:        sigsetmask (mask);
                    492: 
                    493:        while (!flashedback)
                    494:                pause ();
                    495: 
                    496:        XFreeGC(XXdisplay, XXgc_temp);
                    497: }
                    498: 
                    499: flashback ()
                    500: {
                    501:        int mask = sigblock (sigmask (SIGIO) | sigmask (SIGALRM));
                    502: 
                    503:        XFillRectangle (XXdisplay, XXwindow, XXgc_temp, 0, 0,
                    504:                        screen_width*XXfontw+2*XXInternalBorder,
                    505:                        screen_height*XXfonth+2*XXInternalBorder);
                    506:        XFlush (XXdisplay);
                    507: 
                    508:        flashedback = 1;
                    509:        sigsetmask (mask);
                    510: }      
                    511: 
                    512: XTfeep ()
                    513: {
                    514:        int mask = sigblock (sigmask (SIGIO));
                    515: #ifdef XDEBUG
                    516:        fprintf (stderr, "XTfeep\n");
                    517: #endif
                    518:        XBell (XXdisplay,50);
                    519:        sigsetmask (mask);
                    520: }
                    521: 
                    522: /* Artificially creating a cursor is hard, the actual position on the
                    523:  * screen (either where it is or last was) is tracked with VisibleX,Y.
                    524:  * Gnu Emacs code tends to assume a cursor exists in hardward at cursX,Y
                    525:  * and that output text will appear there.  During updates, the cursor is
                    526:  * supposed to be blinked out and will only reappear after the update 
                    527:  * finishes.
                    528:  */
                    529: 
                    530: CursorToggle ()
                    531: {
                    532:        register struct display_line **ActiveScreen;
                    533: 
                    534:        if (!WindowMapped) {
                    535:                CursorExists = 0;
                    536:                return 0;
                    537:                /* Currently the return values are not */
                    538:                /* used, but I could anticipate using */
                    539:                /* them in the future. */
                    540:        }
                    541:        
                    542:        if (VisibleX < 0 || VisibleX >= screen_width ||
                    543:            VisibleY < 0 || VisibleY >= screen_height) {
                    544:                /* Not much can be done */
                    545:                XFlush (XXdisplay);
                    546:                CursorExists = 0;
                    547:                return 0;
                    548:        }
                    549: 
                    550:        ActiveScreen = PhysScreen;
                    551: 
                    552:        if (ActiveScreen && ActiveScreen[VisibleY+1] &&
                    553:            VisibleX < ActiveScreen[VisibleY+1]->length)
                    554:                if (CursorExists)
                    555:                        XDrawImageString(XXdisplay, XXwindow, XXgc_norm,
                    556:                                    VisibleX*XXfontw+XXInternalBorder,
                    557:                                    VisibleY*XXfonth+XXInternalBorder+XXbase,
                    558:                                    &ActiveScreen[VisibleY+1]->body[VisibleX],
                    559:                                    1);
                    560:                else
                    561:                        XDrawImageString(XXdisplay, XXwindow, XXgc_curs,
                    562:                                    VisibleX*XXfontw+XXInternalBorder,
                    563:                                    VisibleY*XXfonth+XXInternalBorder+XXbase,
                    564:                                    &ActiveScreen[VisibleY+1]->body[VisibleX],
                    565:                                    1);
                    566:        else
                    567:                if (CursorExists)
                    568:                        XClearArea (XXdisplay, XXwindow,
                    569:                                    VisibleX*XXfontw+XXInternalBorder,
                    570:                                    VisibleY*XXfonth+XXInternalBorder,
                    571:                                    XXfontw, XXfonth, 0);
                    572:                else
                    573:                        XFillRectangle (XXdisplay, XXwindow, XXgc_norm,
                    574:                                        VisibleX*XXfontw+XXInternalBorder,
                    575:                                        VisibleY*XXfonth+XXInternalBorder,
                    576:                                        XXfontw, XXfonth);
                    577: 
                    578:        CursorExists = !CursorExists;
                    579: 
                    580:        if (!InUpdate)
                    581:                XFlush (XXdisplay);
                    582: 
                    583:        return 1;
                    584: }
                    585: 
                    586: /* This routine is used by routines which are called to paint regions */
                    587: /* designated by Expose events.  If the cursor may be in the exposed */
                    588: /* region, this routine makes sure it is gone so that dumprectangle can */
                    589: /* toggle it back into existance if dumprectangle is invoked when not in */
                    590: /* the midst of a screen update. */
                    591: 
                    592: static 
                    593: ClearCursor ()
                    594: {
                    595:        int mask = sigblock (sigmask (SIGIO));
                    596: 
                    597:        if (!WindowMapped) {
                    598:                CursorExists = 0;
                    599:                sigsetmask (mask);
                    600:                return;
                    601:        }
                    602: 
                    603:        if (VisibleX < 0 || VisibleX >= screen_width ||
                    604:            VisibleY < 0 || VisibleY >= screen_height) {
                    605:                /* Not much can be done */
                    606:                CursorExists = 0;
                    607:                sigsetmask (mask);
                    608:                return;
                    609:        }
                    610: 
                    611:        XClearArea (XXdisplay, XXwindow,
                    612:                    VisibleX*XXfontw+XXInternalBorder,
                    613:                    VisibleY*XXfonth+XXInternalBorder,
                    614:                    XXfontw, XXfonth, 0);
                    615: 
                    616:        CursorExists = 0;
                    617:        sigsetmask (mask);
                    618: }
                    619: 
                    620: XTupdate_begin ()
                    621: {
                    622:        int mask = sigblock (sigmask (SIGIO));
                    623: 
                    624: #ifdef XDEBUG
                    625:        fprintf (stderr, "XTupdate_begin\n");
                    626: #endif
                    627: 
                    628:        InUpdate = 1;
                    629:        if (CursorExists) 
                    630:                CursorToggle ();
                    631: 
                    632:        SavedX = cursX;
                    633:        SavedY = cursY;
                    634:        /* Thw initial "hardware" cursor position is */
                    635:        /* saved because that is where gnu emacs */
                    636:        /* expects the cursor to be at the end of */
                    637:        /* the update */
                    638: 
                    639:        sigsetmask (mask);
                    640: }
                    641: 
                    642: XTupdate_end ()
                    643: {      
                    644:        int mask = sigblock (sigmask (SIGIO));
                    645: 
                    646: #ifdef XDEBUG
                    647:        fprintf (stderr, "XTupdate_end\n");
                    648: #endif
                    649: 
                    650:        if (CursorExists)
                    651:                CursorToggle ();
                    652: 
                    653:        InUpdate = 0;
                    654:        XTtopos (SavedY, SavedX); /* XTtopos invokes cursor toggle */
                    655:        XFlush (XXdisplay);
                    656:        sigsetmask (mask);
                    657: }
                    658: 
                    659: /* Used for Expose events.  Have to get the text
                    660:  * back into the newly blank areas.
                    661:  */
                    662: 
                    663: dumprectangle (top, left, rows, cols)
                    664:      register int top, left, rows, cols;
                    665: {
                    666:        register struct display_line **ActiveScreen;
                    667:        register int ourindex;
                    668:        int localX, localY, localHL;
                    669: 
                    670:        rows += top;
                    671:        cols += left;
                    672:        top /= XXfonth;
                    673:        /* Get row and col containing up and */
                    674:        /* left borders of exposed region -- */
                    675:        /* round down here*/
                    676:        left /= XXfontw;
                    677:        rows += XXfonth-1;
                    678:        cols += XXfontw-1;
                    679:        rows /= XXfonth;
                    680:        /* Get row and col containing bottom and */
                    681:        /* right borders -- round up here */
                    682:        rows -= top;
                    683:        cols /= XXfontw;
                    684:        cols -= left;
                    685: 
                    686:        if (rows < 0)
                    687:                return;
                    688:        if (cols < 0)
                    689:                return;
                    690:        if (top > screen_height - 1)
                    691:                return;
                    692:        if (left > screen_width - 1)
                    693:                return;
                    694:        if (VisibleX >= left && VisibleX < left + cols &&
                    695:            VisibleY >= top && VisibleY < top + rows)
                    696:                ClearCursor ();
                    697: 
                    698:        if (InUpdate && DesiredScreen)
                    699:                ActiveScreen = DesiredScreen;
                    700:        else
                    701:                if (PhysScreen)
                    702:                        /* When queue is dumped in update this */
                    703:                        ActiveScreen = PhysScreen;
                    704:        else
                    705:                return;
                    706: 
                    707:        /* should perhaps be DesiredScreen */
                    708:        /* but PhysScreen is guaranteed to contain */
                    709:        /* data which was good for every line on */
                    710:        /* screen. For desired screen only for */
                    711:        /* lines which are changing.  Emacs does */
                    712:        /* not consider a line within a newly */
                    713:        /* exposed region necessarily to have */
                    714:        /* been changed.  Emacs knows nothing */
                    715:        /* about Expose events. */
                    716:        
                    717:        for (localY = top, ourindex = 0;
                    718:             ourindex < rows && localY < screen_height;
                    719:             ++ourindex, ++localY) {
                    720:                if (localY < 0 || localY >= screen_height ||
                    721:                    !ActiveScreen[localY+1] ||
                    722:                    left+1 > ActiveScreen[localY+1]->length)
                    723:                        continue;
                    724:                localX = left;
                    725:                localHL = ActiveScreen[localY+1]->highlighted;
                    726:                dumpchars (ActiveScreen,
                    727:                           min (cols,
                    728:                                ActiveScreen[localY+1]->length-localX),
                    729:                           localX, localY, localHL);
                    730:        }
                    731:        if (!InUpdate && !CursorExists)
                    732:                CursorToggle ();
                    733:        /* Routine usually called */
                    734:        /* when not in update */
                    735: }
                    736: 
                    737: /* What sections of the window will be modified from the UpdateDisplay
                    738:  * routine is totally under software control.  Any line with Y coordinate
                    739:  * greater than flexlines will not change during an update.  This is really
                    740:  * used only during dellines and inslines routines (scraplines and stufflines)
                    741:  */
                    742: 
                    743: XTset_terminal_window (n)
                    744:      register int n;
                    745: {
                    746: #ifdef XDEBUG
                    747:        fprintf (stderr, "XTset_terminal_window\n");
                    748: #endif
                    749: 
                    750:        if (n <= 0 || n > screen_height)
                    751:                flexlines = screen_height;
                    752:        else
                    753:                flexlines = n;
                    754: }
                    755: 
                    756: XTins_del_lines (vpos, n)
                    757:      int vpos, n;
                    758: {
                    759: #ifdef XDEBUG
                    760:        fprintf (stderr, "XTins_del_lines\n");
                    761: #endif
                    762: 
                    763:        XTtopos (vpos, 0);
                    764:        if (n >= 0)
                    765:                stufflines (n);
                    766:        else
                    767:                scraplines (-n);
                    768: }
                    769: 
                    770: static 
                    771: XTinsert_chars (start, len)
                    772:      register char *start;
                    773:      register int len;
                    774: {
                    775:        int mask = sigblock (sigmask (SIGIO));
                    776:        
                    777: #ifdef XDEBUG
                    778:        fprintf (stderr, "XTinsert_chars\n");
                    779: #endif
                    780: 
                    781:        if (len > 0) {
                    782:                XCopyArea (XXdisplay, XXwindow, XXwindow, XXgc_norm,
                    783:                           cursX*XXfontw+XXInternalBorder,
                    784:                           cursY*XXfonth+XXInternalBorder,
                    785:                           (screen_width-cursX-len)*XXfontw,
                    786:                           XXfonth,
                    787:                           (cursX+len)*XXfontw+XXInternalBorder,
                    788:                           cursY*XXfonth+XXInternalBorder);
                    789:                writechars (start, start+len-1);
                    790:        }
                    791: 
                    792:        sigsetmask(mask);
                    793: }
                    794: 
                    795: static 
                    796: XTdelete_chars (n)
                    797:      register int n;
                    798: {
                    799:        int mask = sigblock (sigmask (SIGIO));
                    800:        
                    801: #ifdef XDEBUG
                    802:        fprintf (stderr, "XTdelete_chars (num %d)\n",n);
                    803: #endif
                    804: 
                    805:        /* XXX WARNING!  This is dangerous...We aren't waiting for the
                    806:         * exposures from the copyarea because it slows things down too
                    807:         * much.  This could cause updating problems under some
                    808:         * circumstances. */
                    809:        
                    810:        if (n > 0) {
                    811:                XCopyArea (XXdisplay, XXwindow, XXwindow, XXgc_norm,
                    812:                           (cursX+n)*XXfontw+XXInternalBorder,
                    813:                           cursY*XXfonth+XXInternalBorder,
                    814:                           (screen_width-cursX-n)*XXfontw,
                    815:                           XXfonth,
                    816:                           cursX*XXfontw+XXInternalBorder,
                    817:                           cursY*XXfonth+XXInternalBorder);
                    818:        }
                    819:        
                    820:        if (n >= 0) {
                    821:                XClearArea (XXdisplay, XXwindow,
                    822:                            (screen_width-n)*XXfontw+XXInternalBorder,
                    823:                            cursY*XXfonth+XXInternalBorder,
                    824:                            n*XXfontw+XXInternalBorder,
                    825:                            XXfonth,0);
                    826:        }
                    827:        cursX += n;
                    828:        
                    829:        sigsetmask (mask);
                    830: }
                    831: 
                    832: stufflines (n)
                    833:      register int n;
                    834: {
                    835:        register int topregion, bottomregion;
                    836:        register int length, newtop, mask;
                    837: 
                    838:        if (cursY >= flexlines)
                    839:                return;
                    840:   
                    841:        mask = sigblock (sigmask (SIGIO));
                    842: 
                    843:        if (CursorExists)
                    844:                CursorToggle ();
                    845: 
                    846:        sigsetmask (mask);
                    847:        topregion = cursY;
                    848:        bottomregion = flexlines-(n+1);
                    849:        newtop = cursY+n;
                    850:        length = bottomregion-topregion+1;
                    851: 
                    852:        if (length > 0 && newtop <= flexlines) {
                    853:                mask = sigblock (sigmask (SIGIO));
                    854:                XCopyArea (XXdisplay, XXwindow, XXwindow, XXgc_norm,
                    855:                           XXInternalBorder,
                    856:                           topregion*XXfonth+XXInternalBorder,
                    857:                           screen_width*XXfontw,
                    858:                           length*XXfonth,
                    859:                           XXInternalBorder, newtop*XXfonth+XXInternalBorder);
                    860:        }
                    861: 
                    862:        newtop = min (newtop, flexlines-1);
                    863:        length = newtop-topregion;
                    864:        if (length > 0)
                    865:                XClearArea (XXdisplay, XXwindow,
                    866:                            XXInternalBorder,
                    867:                            topregion*XXfonth+XXInternalBorder,
                    868:                            screen_width*XXfontw,
                    869:                            n*XXfonth, 0);
                    870: }
                    871: 
                    872: scraplines (n)
                    873:      register int n;
                    874: {
                    875:        int mask;
                    876: 
                    877:        if (cursY >= flexlines)
                    878:                return;
                    879: 
                    880:        mask = sigblock (sigmask (SIGIO));
                    881: 
                    882:        if (CursorExists)
                    883:                CursorToggle ();
                    884: 
                    885:        if (cursY+n >= flexlines) {
                    886:                if (flexlines >= (cursY + 1))
                    887:                        XClearArea (XXdisplay, XXwindow,
                    888:                                    XXInternalBorder,
                    889:                                    cursY*XXfonth+XXInternalBorder,
                    890:                                    screen_width*XXfontw,
                    891:                                    (flexlines-cursY) * XXfonth,
                    892:                                    0);
                    893:                sigsetmask (mask);
                    894:        }
                    895:        else {
                    896:                XCopyArea (XXdisplay, XXwindow, XXwindow, XXgc_norm,
                    897:                           XXInternalBorder,
                    898:                           (cursY+n)*XXfonth+XXInternalBorder,
                    899:                           screen_width*XXfontw,
                    900:                           (flexlines-cursY-n)*XXfonth,
                    901:                           XXInternalBorder, cursY*XXfonth+XXInternalBorder);
                    902: 
                    903:                XClearArea (XXdisplay, XXwindow, XXInternalBorder,
                    904:                            (flexlines-n)*XXfonth+XXInternalBorder,
                    905:                            screen_width*XXfontw,
                    906:                            n*XXfonth, 0);
                    907:                sigsetmask (mask);
                    908:        }
                    909: }
                    910:        
                    911: /* Substitutes for standard read routine.  Under X not interested in individual
                    912:  * bytes but rather individual packets.
                    913:  */
                    914: 
                    915: XTread_socket (sd, bufp, numchars)
                    916:      register int sd;
                    917:      register char *bufp;
                    918:      register int numchars;
                    919: {
                    920: #ifdef XDEBUG
                    921:        fprintf(stderr,"XTread_socket\n");
                    922: #endif
                    923: 
                    924:        return (internal_socket_read (bufp, numchars));
                    925: }
                    926: 
                    927: read_events_block ()
                    928: {
                    929:        unsigned char buf[64];
                    930:        int i, nread;
                    931: 
                    932: #ifdef XDEBUG
                    933:        fprintf(stderr,"read_events_block\n");
                    934: #endif
                    935:        
                    936:        nread = internal_socket_read (buf, sizeof buf);
                    937:        if (!nread)
                    938:                return;
                    939:        
                    940:        for (i=0; i < nread; i++) {
                    941:                kbd_buffer_store_char (buf[i]);
                    942:                /* Don't look at input that follows a C-g too closely.
                    943:                 * This reduces lossage due to autorepeat on C-g.  */
                    944:                if (buf[i] == ('G' & 037))
                    945:                        break;
                    946:        }
                    947: }
                    948: 
                    949: internal_socket_read(bufp, numchars)
                    950:        register unsigned char *bufp;
                    951:        register int numchars;
                    952: {
                    953:        int count,nbytes,rows,cols;
                    954:        char mapping_buf[20];
                    955:        int mask = sigblock (sigmask (SIGIO));
                    956:        XEvent event;
                    957:        XComposeStatus status;
                    958: 
                    959:        extern int input_pending;
                    960: 
                    961:        count = 0;
                    962: 
                    963: #ifdef BIGDEBUG
                    964:        my_log("Entering internal_socket_read input_pending = %d\n",input_pending);
                    965: #endif BIGDEBUG
                    966:        
                    967:        while (XPending (XXdisplay)) {
                    968:                XNextEvent (XXdisplay,&event);
                    969: 
                    970: #ifdef BIGDEBUG
                    971:                my_log("Got event %d\n",event.type);
                    972: #endif BIGDEBUG
                    973: 
                    974:                switch (event.type) {
                    975: 
                    976:                default:
                    977:                        break;
                    978: 
                    979:                case ConfigureNotify:
                    980:                        XXxoffset = event.xconfigure.x;
                    981:                        XXyoffset = event.xconfigure.y;
                    982:                        if (abs(pixelheight-event.xconfigure.height) < 
                    983:                            XXfonth &&
                    984:                            abs(pixelwidth-event.xconfigure.width) < 
                    985:                            XXfontw)
                    986:                                break;
                    987: 
                    988:                        configure_pending = 1;
                    989: 
                    990:                        rows = event.xconfigure.height/XXfonth;
                    991:                        cols = event.xconfigure.width/XXfontw;
                    992:                        pixelwidth = cols*XXfontw+2*XXInternalBorder;
                    993:                        pixelheight = rows*XXfonth+2*XXInternalBorder;
                    994: 
                    995:                        break;
                    996: 
                    997:                case Expose:
                    998:                        if (configure_pending) {
                    999:                                if (event.xexpose.count)
                   1000:                                        break;
                   1001:                                change_screen_size ((pixelheight-2*XXInternalBorder)/XXfonth,
                   1002:                                                    (pixelwidth-2*XXInternalBorder)/XXfontw);
                   1003:                                configure_pending = 0;
                   1004:                                break;
                   1005:                        } 
                   1006:                        dumprectangle (event.xexpose.y-XXInternalBorder,
                   1007:                                       event.xexpose.x-XXInternalBorder,
                   1008:                                       event.xexpose.height,
                   1009:                                       event.xexpose.width);
                   1010:                        break;
                   1011: 
                   1012:                case GraphicsExpose:
                   1013:                        dumprectangle (event.xgraphicsexpose.y-XXInternalBorder,
                   1014:                                       event.xgraphicsexpose.x-XXInternalBorder,
                   1015:                                       event.xgraphicsexpose.height,
                   1016:                                       event.xgraphicsexpose.width);
                   1017:                        break;
                   1018: 
                   1019:                case NoExpose:
                   1020:                        break;
                   1021:                        
                   1022:                case KeyPress:
                   1023:                        nbytes = 0;
                   1024:                        switch (event.xkey.keycode) {
                   1025:                        case 167:
                   1026:                                strcpy(mapping_buf,"\002");
                   1027:                                nbytes = 1;
                   1028:                                break;
                   1029:                        case 168:
                   1030:                                strcpy(mapping_buf,"\006");
                   1031:                                nbytes = 1;
                   1032:                                break;
                   1033:                        case 170:
                   1034:                                strcpy(mapping_buf,"\020");
                   1035:                                nbytes = 1;
                   1036:                                break;
                   1037:                        case 169:
                   1038:                                strcpy(mapping_buf,"\016");
                   1039:                                nbytes = 1;
                   1040:                                break;
                   1041:                        }
                   1042:                        if (!nbytes) {
                   1043:                                nbytes = XLookupString (&event,
                   1044:                                                        mapping_buf, 20, 0,
                   1045:                                                        &status);
                   1046:                                if (nbytes) {
                   1047:                                        if (event.xkey.state & Mod1Mask)
                   1048:                                                *mapping_buf |= METABIT;
                   1049:                                }
                   1050:                        }
                   1051:                        if (numchars-nbytes > 0) {
                   1052:                                bcopy (mapping_buf, bufp, nbytes);
                   1053:                                bufp += nbytes;
                   1054:                                count += nbytes;
                   1055:                                numchars -= nbytes;
                   1056:                        }
                   1057:                        break;
                   1058: 
                   1059:                case ButtonPress:
                   1060:                case ButtonRelease:
                   1061:                        *bufp++ = (char) 'X' & 037;
                   1062:                        ++count;
                   1063:                        --numchars;
                   1064:                        *bufp++ = (char) '@' & 037;
                   1065:                        ++count;
                   1066:                        --numchars;
                   1067:                        if (XXm_queue_num == XMOUSEBUFSIZE)
                   1068:                                break;
                   1069:                        XXm_queue[XXm_queue_num] = (XEvent *)
                   1070:                                malloc(sizeof(XEvent));
                   1071:                        *XXm_queue[XXm_queue_num++] = event;
                   1072:                        break;
                   1073:                }
                   1074:        } 
                   1075: 
                   1076:        if (CursorExists)
                   1077:                xfixscreen ();
                   1078: 
                   1079:        sigsetmask (mask);
                   1080:        return count;
                   1081: }
                   1082: 
                   1083: #ifdef notdef
                   1084: XBitmapIcon () 
                   1085: {
                   1086:        XWMHints wmhints;
                   1087:        int mask = sigblock (sigmask (SIGIO));
                   1088: 
                   1089:        wmhints.flags = IconPixmapHint|IconMaskHint;
                   1090:        wmhints.icon_pixmap = SinkPixmap;
                   1091:        wmhints.icon_mask = SinkMaskPixmap;
                   1092:        XSetWMHints (XXdisplay, XXwindow, &wmhints);
                   1093: 
                   1094:        sigsetmask (mask);
                   1095: }
                   1096: 
                   1097: XTextIcon () 
                   1098: {
                   1099:        XWMHints wmhints;
                   1100:        int mask = sigblock (sigmask (SIGIO));
                   1101: 
                   1102:        wmhints.flags = 0;
                   1103:        XSetWMHints (XXdisplay, XXwindow, &wmhints);
                   1104: 
                   1105:        sigsetmask (mask);
                   1106: }
                   1107: #endif notdef
                   1108: 
                   1109: /* Interpreting incoming keycodes. Should have table modifiable as needed
                   1110:  * from elisp.
                   1111:  */
                   1112: 
                   1113: /* Exit gracefully from gnuemacs, doing an autosave and giving a status.
                   1114:  */
                   1115: 
                   1116: XExitGracefully ()
                   1117: {
                   1118:        XCleanUp();
                   1119:        exit (70);
                   1120: }
                   1121: 
                   1122: XIgnoreError ()
                   1123: {
                   1124:        return 0;
                   1125: }
                   1126: 
                   1127: xfixscreen ()
                   1128: {
                   1129:        int mask = sigblock (sigmask (SIGIO));
                   1130: 
                   1131:        /* Yes, this is really what I mean -- Check to see if we've
                   1132:         * lost our connection */
                   1133:        
                   1134:        XSetErrorHandler(0);
                   1135:        XSetIOErrorHandler(0);
                   1136:        XNoOp (XXdisplay);
                   1137:        XFlush (XXdisplay);
                   1138:        XSetErrorHandler(handler);
                   1139:        XSetIOErrorHandler(handler);
                   1140:        if (!InUpdate && !CursorExists)
                   1141:                CursorToggle ();
                   1142: 
                   1143:        sigsetmask (mask);
                   1144: }
                   1145: 
                   1146: x_term_init ()
                   1147: {
                   1148:        register char *vardisplay;
                   1149:        register int xxargc;
                   1150:        register char **xxargv;
                   1151:        extern char *getenv ();
                   1152:        char *temp_font;
                   1153:        char *option;
                   1154:        extern XTinterrupt_signal ();
                   1155:        extern char *malloc ();
                   1156:        int reversevideo;
                   1157:        XColor cdef;
                   1158:        XColor cursor_fore, cursor_back;
                   1159:        extern Lisp_Object Vxterm, Vxterm1, Qt;
                   1160:        extern int xargc;
                   1161:        extern char **xargv;
                   1162:        extern void init_sigio (), request_sigio (), unrequest_sigio ();
                   1163:        extern int XIgnoreError();
                   1164: 
                   1165:        vardisplay = (alternate_display ? alternate_display : "");
                   1166:        if (!vardisplay) {
                   1167:                fprintf (stderr, "DISPLAY environment variable must be set\n");
                   1168:                exit (-200);
                   1169:        }
                   1170: 
                   1171:        XXdisplay = XOpenDisplay (vardisplay);
                   1172:        if (XXdisplay == (Display *) 0) {
                   1173:                fprintf (stderr, "X server not responding.  Check your DISPLAY environment variable.\n");
                   1174:                exit (-99);     
                   1175:        }
                   1176: 
                   1177:        XXisColor = DisplayCells(XXdisplay,0)>2;
                   1178:        XXColorMap = DefaultColormap(XXdisplay,0);
                   1179:        
                   1180:        x_init_1 (1);
                   1181:        WindowMapped = 0;
                   1182:        baud_rate = 9600;
                   1183:        min_padding_speed = 10000;
                   1184:        must_write_spaces = 1;
                   1185:        MetaFlag = 1;
                   1186:        visible_bell = 1;
                   1187:        interrupt_input = 1;
                   1188:        inverse_video = 1;
                   1189:        configure_pending = 0;
                   1190:        
                   1191:        fix_screen_hook = xfixscreen;
                   1192:        clear_screen_hook = XTclear_screen;
                   1193:        clear_end_of_line_hook = XTclear_end_of_line;
                   1194:        ins_del_lines_hook = XTins_del_lines;
                   1195:        change_line_highlight_hook = XTchange_line_highlight;
                   1196:        insert_chars_hook = XTinsert_chars;
                   1197:        write_chars_hook = XTwrite_chars;
                   1198:        delete_chars_hook = XTdelete_chars;
                   1199:        ring_bell_hook = XTfeep;
                   1200:        reset_terminal_modes_hook = XTreset_terminal_modes;
                   1201:        set_terminal_modes_hook = XTset_terminal_modes;
                   1202:        update_begin_hook = XTupdate_begin;
                   1203:        update_end_hook = XTupdate_end;
                   1204:        set_terminal_window_hook = XTset_terminal_window;
                   1205:        read_socket_hook = XTread_socket;
                   1206:        topos_hook = XTtopos;
                   1207:        reassert_line_highlight_hook = XTreassert_line_highlight;
                   1208:        scroll_region_ok = 1;   /* we'll scroll partial screens */
                   1209:        char_ins_del_ok = 1;    /* Don't bother */
                   1210:        line_ins_del_ok = 1;    /* we'll just blt 'em */
                   1211:        fast_clear_end_of_line = 1; /* X does this well */
                   1212:        memory_below_screen = 0; /* we don't remember what scrolls 
                   1213:                                  *             off the bottom */
                   1214:        dont_calculate_costs = 1;
                   1215: 
                   1216:        /* New options section */
                   1217:        XXborder = 1;
                   1218:        XXInternalBorder = 1;
                   1219:        screen_width = 80;
                   1220:        screen_height = 66;
                   1221:        reversevideo = 0;
                   1222:        XXxoffset = 0;
                   1223:        XXyoffset = 0;
                   1224:        XXdebug = 0;
                   1225:        XXm_queue_num = 0;
                   1226: 
                   1227:        handler = XIgnoreError;
                   1228:        XSetErrorHandler (handler);
                   1229:        XSetIOErrorHandler (handler);
                   1230:        
                   1231:        progname = xargv[0];
                   1232:        if (rindex(progname,'/'))
                   1233:                progname = rindex(progname,'/')+1;
                   1234:        
                   1235:        if (option = XGetDefault (XXdisplay, progname, "ReverseVideo"))
                   1236:                if (!strcmp (option,"on"))
                   1237:                        reversevideo = 1;
                   1238:        if (option = XGetDefault (XXdisplay, progname, "BorderWidth"))
                   1239:                XXborder = atoi (option);
                   1240:        if (option = XGetDefault (XXdisplay, progname, "InternalBorder"))
                   1241:                XXInternalBorder = atoi (option);
                   1242: 
                   1243:        if (!(brdr_color = XGetDefault (XXdisplay, progname, "Border")))
                   1244:                brdr_color = XGetDefault (XXdisplay, progname, "BorderColor");
                   1245:        back_color = XGetDefault (XXdisplay, progname, "Background");
                   1246:        fore_color = XGetDefault (XXdisplay, progname, "Foreground");
                   1247:        mous_color = XGetDefault (XXdisplay, progname, "Mouse");
                   1248:        curs_color = XGetDefault (XXdisplay, progname, "Cursor");
                   1249: 
                   1250:        temp_font  = XGetDefault (XXdisplay, progname, "BodyFont");
                   1251:        desiredwindow = "";
                   1252:        if (option = XGetDefault (XXdisplay, progname, "Geometry"))
                   1253:                desiredwindow = option;
                   1254:        if (!temp_font)
                   1255:                temp_font = "fixed";
                   1256:        XXcurrentfont = (char *) xmalloc (strlen (temp_font) + 1);
                   1257:        strcpy (XXcurrentfont, temp_font);
                   1258: 
                   1259:        if (XXisColor) {
                   1260:                if (fore_color &&
                   1261:                    XParseColor (XXdisplay, XXColorMap, fore_color, &cdef) &&
                   1262:                    XAllocColor (XXdisplay, XXColorMap, &cdef))
                   1263:                        fore = cdef.pixel;
                   1264:                else {
                   1265:                        fore_color = "black";
                   1266:                        fore = BlackPixel(XXdisplay,0);
                   1267:                }
                   1268: 
                   1269:                if (back_color &&
                   1270:                    XParseColor (XXdisplay, XXColorMap, back_color, &cdef) &&
                   1271:                    XAllocColor (XXdisplay, XXColorMap, &cdef))
                   1272:                        back = cdef.pixel;
                   1273:                else {
                   1274:                        back_color = "white";
                   1275:                        back = WhitePixel(XXdisplay,0);
                   1276:                }
                   1277: 
                   1278:                if (curs_color &&
                   1279:                    XParseColor (XXdisplay, XXColorMap, curs_color, &cdef) &&
                   1280:                    XAllocColor (XXdisplay, XXColorMap, &cdef))
                   1281:                        curs = cdef.pixel;
                   1282:                else {
                   1283:                        curs_color = "black";
                   1284:                        curs = BlackPixel(XXdisplay,0);
                   1285:                }
                   1286: 
                   1287:                if (mous_color &&
                   1288:                    XParseColor (XXdisplay, XXColorMap, mous_color, &cdef) &&
                   1289:                    XAllocColor (XXdisplay, XXColorMap, &cdef))
                   1290:                        mous = cdef.pixel;
                   1291:                else {
                   1292:                        mous_color = "black";
                   1293:                        mous = BlackPixel(XXdisplay,0);
                   1294:                }
                   1295: 
                   1296:                if (brdr_color &&
                   1297:                    XParseColor (XXdisplay, XXColorMap, brdr_color, &cdef) &&
                   1298:                    XAllocColor (XXdisplay, XXColorMap, &cdef))
                   1299:                        brdr = cdef.pixel;
                   1300:                else {
                   1301:                        brdr_color = "black";
                   1302:                        brdr = BlackPixel(XXdisplay,0);
                   1303:                }
                   1304:        }
                   1305:        else {
                   1306:                fore_color  = curs_color = mous_color = brdr_color = "black";
                   1307:                fore = curs = mous = brdr = BlackPixel(XXdisplay,0);
                   1308:                back_color = "white";
                   1309:                back = WhitePixel(XXdisplay,0);
                   1310:        }
                   1311: 
                   1312:        XXpid = getpid ();
                   1313:        default_window = "=80x24+0+0";
                   1314: 
                   1315:        /* Process X command line args...*/
                   1316:        xxargc = xargc;
                   1317:        xxargv = xargv;
                   1318:        xxargc++;
                   1319:        xxargc--;
                   1320:        while (xxargc) {
                   1321:                int sargc;
                   1322:                sargc = xxargc;
                   1323:                if (xxargc && !strcmp (*xxargv, "-r")) {
                   1324:                        reversevideo = !reversevideo;
                   1325:                        xxargc--;
                   1326:                        xxargv++;
                   1327:                }
                   1328:                if ((xxargc > 1) && !strcmp (*xxargv, "-font")) {
                   1329:                        xxargc--;
                   1330:                        xxargv++;
                   1331:                        free(XXcurrentfont);
                   1332:                        XXcurrentfont = (char *) xmalloc (strlen (*xxargv)+1);
                   1333:                        strcpy (XXcurrentfont, *xxargv);
                   1334:                        xxargc--;
                   1335:                        xxargv++;
                   1336:                }
                   1337:                if ((xxargc > 1) && !strcmp (*xxargv, "-b")) {
                   1338:                        xxargc--;
                   1339:                        xxargv++;
                   1340:                        XXborder = atoi (*xxargv);
                   1341:                        xxargc--;
                   1342:                        xxargv++;
                   1343:                }
                   1344:                if ((xxargc > 1) && !strcmp (*xxargv, "-ib")) {
                   1345:                        xxargc--;
                   1346:                        xxargv++;
                   1347:                        XXInternalBorder = atoi (*xxargv);
                   1348:                        xxargc--;
                   1349:                        xxargv++;
                   1350:                }
                   1351:                if ((xxargc > 1) && !strcmp (*xxargv, "-w")) {
                   1352:                        xxargc--;
                   1353:                        xxargv++;
                   1354:                        desiredwindow = (char *) xmalloc (strlen (*xxargv)+1);
                   1355:                        strcpy (desiredwindow, *xxargv);
                   1356:                        xxargc--;
                   1357:                        xxargv++;
                   1358:                }
                   1359:                if (XXisColor) {
                   1360:                        if ((xxargc > 1 && !strcmp (*xxargv, "-fg"))) {
                   1361:                                xxargc--;
                   1362:                                xxargv++;
                   1363:                                if (XParseColor (XXdisplay, XXColorMap,
                   1364:                                                 *xxargv, &cdef) &&
                   1365:                                    XAllocColor (XXdisplay, XXColorMap,
                   1366:                                                 &cdef)) {
                   1367:                                        fore_color = (char *)
                   1368:                                                xmalloc (sizeof (*xxargv)+1);
                   1369:                                        strcpy (fore_color, *xxargv);
                   1370:                                        fore = cdef.pixel;
                   1371:                                }
                   1372:                                xxargc--;
                   1373:                                xxargv++;
                   1374:                        }
                   1375:                        if ((xxargc > 1 && !strcmp (*xxargv, "-bg"))) {
                   1376:                                xxargc--;
                   1377:                                xxargv++;
                   1378:                                if (XParseColor (XXdisplay, XXColorMap,
                   1379:                                                 *xxargv, &cdef) &&
                   1380:                                    XAllocColor (XXdisplay, XXColorMap,
                   1381:                                                 &cdef)) {
                   1382:                                        back_color = (char *)
                   1383:                                                xmalloc (sizeof (*xxargv)+1);
                   1384:                                        strcpy (back_color, *xxargv);
                   1385:                                        back = cdef.pixel;
                   1386:                                }
                   1387:                                xxargc--;
                   1388:                                xxargv++;
                   1389:                        }
                   1390:                        if ((xxargc > 1 && !strcmp (*xxargv, "-bd"))) {
                   1391:                                xxargc--;
                   1392:                                xxargv++;
                   1393:                                if (XParseColor (XXdisplay, XXColorMap,
                   1394:                                                 *xxargv, &cdef) &&
                   1395:                                    XAllocColor (XXdisplay, XXColorMap,
                   1396:                                                 &cdef)) {
                   1397:                                        brdr_color = (char *)
                   1398:                                                xmalloc (sizeof (*xxargv)+1);
                   1399:                                        strcpy (brdr_color, *xxargv);
                   1400:                                        brdr = cdef.pixel;
                   1401:                                }
                   1402:                                xxargc--;
                   1403:                                xxargv++;
                   1404:                        }
                   1405:                        if ((xxargc > 1 && !strcmp (*xxargv, "-cr"))) {
                   1406:                                xxargc--;
                   1407:                                xxargv++;
                   1408:                                if (XParseColor (XXdisplay, XXColorMap,
                   1409:                                                 *xxargv, &cdef) &&
                   1410:                                    XAllocColor (XXdisplay, XXColorMap,
                   1411:                                                 &cdef)) {
                   1412:                                        curs_color = (char *)
                   1413:                                                xmalloc (sizeof (*xxargv)+1);
                   1414:                                        strcpy (curs_color, *xxargv);
                   1415:                                        curs = cdef.pixel;
                   1416:                                }
                   1417:                                xxargc--;
                   1418:                                xxargv++;
                   1419:                        }
                   1420:                        if ((xxargc > 1 && !strcmp (*xxargv, "-ms"))) {
                   1421:                                xxargc--;
                   1422:                                xxargv++;
                   1423:                                if (XParseColor (XXdisplay, XXColorMap,
                   1424:                                                 *xxargv, &cdef) &&
                   1425:                                    XAllocColor (XXdisplay, XXColorMap,
                   1426:                                                 &cdef)) {
                   1427:                                        mous_color = (char *)
                   1428:                                                xmalloc (sizeof (*xxargv)+1);
                   1429:                                        strcpy (mous_color, *xxargv);
                   1430:                                        mous = cdef.pixel;
                   1431:                                }
                   1432:                                xxargc--;
                   1433:                                xxargv++;
                   1434:                        }
                   1435:                }
                   1436:                if (sargc == xxargc) {
                   1437:                        xxargc--;
                   1438:                        xxargv++;
                   1439:                }
                   1440:        }
                   1441: 
                   1442:        if (reversevideo) {
                   1443:                int tempcolor;
                   1444:                char *tempname;
                   1445:                brdr = back;
                   1446:                brdr_color = back_color;
                   1447:                tempcolor = fore;
                   1448:                fore = back;
                   1449:                back = tempcolor;
                   1450:                tempname = fore_color;
                   1451:                fore_color = back_color;
                   1452:                back_color = tempname;
                   1453:                if (curs == WhitePixel(XXdisplay,0)) {
                   1454:                        curs = BlackPixel(XXdisplay,0);
                   1455:                        curs_color = "black";
                   1456:                }
                   1457:                else if (curs == BlackPixel(XXdisplay,0)) {
                   1458:                        curs = WhitePixel(XXdisplay,0);
                   1459:                        curs_color = "white";
                   1460:                }
                   1461:                if (mous == WhitePixel(XXdisplay,0)) {
                   1462:                        mous = BlackPixel(XXdisplay,0);
                   1463:                        mous_color = "black";
                   1464:                }
                   1465:                else if (mous == BlackPixel(XXdisplay,0)) {
                   1466:                        mous = WhitePixel(XXdisplay,0);
                   1467:                        mous_color = "white";
                   1468:                }
                   1469:        }
                   1470: 
                   1471:        if (!XXcurrentfont) {
                   1472:                fprintf (stderr, "Memory allocation failure.\n");
                   1473:                exit (-150);
                   1474:        }
                   1475: 
                   1476:        signal (SIGPIPE, XExitGracefully);
                   1477:        fontinfo = XLoadQueryFont(XXdisplay,XXcurrentfont);
                   1478:        if (fontinfo == (XFontStruct *) 0) {
                   1479:                fprintf (stderr, "No font\n");
                   1480:                exit (-98);
                   1481:        }
                   1482:        
                   1483:        XXfid = fontinfo->fid;
                   1484:        XXfonth = fontinfo->ascent + fontinfo->descent;
                   1485:        XXfontw = fontinfo->max_bounds.width;
                   1486:        XXbase = fontinfo->ascent;
                   1487:        pixelwidth = screen_width * XXfontw + 2 * XXInternalBorder;
                   1488:        pixelheight = screen_height * XXfonth + 2 * XXInternalBorder;
                   1489:        flexlines = screen_height;
                   1490: #ifndef CANNOT_DUMP
                   1491:        if (initialized)
                   1492: #endif                         /* CANNOT_DUMP */
                   1493:                Vxterm = Qt, Vxterm1 = Qt;
                   1494: 
                   1495:        XInitWindow ();
                   1496: 
                   1497:        cursor_fore.pixel = fore;
                   1498:        cursor_fore.flags = 0;
                   1499:        cursor_back.pixel = back;
                   1500:        cursor_back.flags = 0;
                   1501:        
                   1502:        XSelectInput (XXdisplay, XXwindow, KeyPressMask | 
                   1503:                      ExposureMask | ButtonPressMask | ButtonReleaseMask |
                   1504:                      StructureNotifyMask);
                   1505: 
                   1506:        Fset_input_mode (Qt, Qnil);
                   1507:        request_sigio();
                   1508: 
                   1509: #ifdef BIGDEBUG
                   1510:        *debug_string = '\0';
                   1511:        if (1) {
                   1512:                int dump_log();
                   1513:                signal(SIGUSR1,dump_log);
                   1514:        } 
                   1515: #endif BIGDEBUG        
                   1516: }
                   1517: 
                   1518: x_init_1 (unrequest)
                   1519:        int unrequest;
                   1520: {
                   1521: #ifdef F_SETOWN
                   1522:        extern int old_fcntl_owner;
                   1523: #endif
                   1524:        extern void init_sigio (), request_sigio (), unrequest_sigio ();
                   1525: 
                   1526:        dup2 (ConnectionNumber(XXdisplay), 0);
                   1527:        close (ConnectionNumber(XXdisplay));
                   1528:        ConnectionNumber(XXdisplay) = 0;        /* Looks a little strange?
                   1529:                                                 * check the def of the macro;
                   1530:                                                 * it is a genuine lvalue */
                   1531:        init_sigio ();
                   1532:        request_sigio ();
                   1533:        setpgrp (0,getpid());
                   1534:        
                   1535: #ifdef F_SETOWN
                   1536:        old_fcntl_owner = fcntl (0, F_GETOWN, 0);
                   1537:        fcntl (0, F_SETOWN, getpid ());
                   1538: #endif
                   1539:        if (unrequest)
                   1540:                unrequest_sigio ();
                   1541: }
                   1542: 
                   1543: XSetFlash ()
                   1544: {
                   1545:        ring_bell_hook = XTflash;
                   1546: }
                   1547: 
                   1548: XSetFeep ()
                   1549: {
                   1550:        ring_bell_hook = XTfeep;
                   1551: }
                   1552: 
                   1553: XNewFont (newname)
                   1554:      register char *newname;
                   1555: {
                   1556:        XFontStruct *temp;
                   1557:        XSizeHints sizes;
                   1558: 
                   1559:        int mask = sigblock (sigmask (SIGIO));
                   1560: 
                   1561:        XFlush (XXdisplay);
                   1562: 
                   1563:        temp = XLoadQueryFont(XXdisplay, newname);
                   1564:        if (temp == (XFontStruct *) 0) {
                   1565:                sigsetmask (mask);
                   1566:                if (QLength (XXdisplay) > 0)
                   1567:                        read_events_block ();
                   1568:                return -1;
                   1569:        }
                   1570:        XXfid = temp->fid;
                   1571:        XXfonth = temp->ascent + temp->descent;
                   1572:        XXfontw = temp->max_bounds.width;
                   1573:        XXbase = temp->ascent;
                   1574:        XSetFont (XXdisplay, XXgc_norm, XXfid);
                   1575:        XSetFont (XXdisplay, XXgc_rev, XXfid);
                   1576:        XSetFont (XXdisplay, XXgc_curs, XXfid);
                   1577:        XFreeFont (XXdisplay, fontinfo);
                   1578:        fontinfo = temp;
                   1579:        sizes.flags = PResizeInc|PMinSize;
                   1580:        sizes.width_inc = XXfontw;
                   1581:        sizes.height_inc = XXfonth;
                   1582:        sizes.min_width = XXfontw*MINWIDTH+2*XXInternalBorder;
                   1583:        sizes.min_height = XXfonth*MINHEIGHT+2*XXInternalBorder;
                   1584:        XSetNormalHints (XXdisplay, XXwindow, &sizes);
                   1585: 
                   1586:        XSetWindowSize (screen_height, screen_width);
                   1587: 
                   1588:        sigsetmask (mask);
                   1589:        if (QLength (XXdisplay) > 0)
                   1590:                read_events_block ();
                   1591:        
                   1592:        return 0;
                   1593: }
                   1594: 
                   1595: /* Flip foreground/background colors */
                   1596: 
                   1597: XFlipColor ()
                   1598: {
                   1599:        int tempcolor;
                   1600:        char *tempname;
                   1601:        int mask = sigblock (sigmask (SIGIO));
                   1602: 
                   1603:        CursorToggle ();
                   1604:        XSetWindowBackground(XXdisplay, XXwindow, fore);
                   1605:        if (XXborder)
                   1606:                XSetWindowBorder(XXdisplay, XXwindow, back);
                   1607:        brdr = back;
                   1608:        brdr_color = back_color;
                   1609:        tempcolor = fore;
                   1610:        fore = back;
                   1611:        back = tempcolor;
                   1612:        tempname = fore_color ;
                   1613:        fore_color = back_color;
                   1614:        back_color = tempname;
                   1615:        XClearArea (XXdisplay, XXwindow, 0, 0,
                   1616:                    screen_width*XXfontw+2*XXInternalBorder,
                   1617:                    screen_height*XXfonth+2*XXInternalBorder, 0);
                   1618:        XXgc_temp = XXgc_norm;
                   1619:        XXgc_norm = XXgc_rev;
                   1620:        XXgc_rev = XXgc_temp;
                   1621: 
                   1622:        XRedrawDisplay ();
                   1623:        if (curs == WhitePixel(XXdisplay,0)) {
                   1624:                curs = BlackPixel(XXdisplay,0);
                   1625:                curs_color = "black";
                   1626:        }
                   1627:        else
                   1628:                if (curs == BlackPixel(XXdisplay,0)) {
                   1629:                        curs = WhitePixel(XXdisplay,0);
                   1630:                        curs_color = "white";
                   1631:                }
                   1632:        XSetState (XXdisplay, XXgc_curs, back, curs, GXinvert, AllPlanes);
                   1633: 
                   1634:        if (mous == WhitePixel(XXdisplay,0)) {
                   1635:                mous = BlackPixel(XXdisplay,0);
                   1636:                mous_color = "black";
                   1637:        }
                   1638:        else
                   1639:                if (mous == BlackPixel(XXdisplay,0)) {
                   1640:                        mous = WhitePixel(XXdisplay,0);
                   1641:                        mous_color = "white";
                   1642:                }
                   1643:        CursorToggle ();
                   1644:        XFlush (XXdisplay);
                   1645:        sigsetmask (mask);
                   1646: }
                   1647: 
                   1648: /* Change just the size of the window */
                   1649: 
                   1650: XSetWindowSize (rows, cols)
                   1651:      register int rows, cols;
                   1652: {
                   1653:        pixelwidth = cols*XXfontw+2*XXInternalBorder;
                   1654:        pixelheight = rows*XXfonth+2*XXInternalBorder;
                   1655: 
                   1656:        XResizeWindow(XXdisplay, XXwindow, pixelwidth, pixelheight);
                   1657:        XFlush (XXdisplay);
                   1658: 
                   1659:        change_screen_size (rows, cols);
                   1660: }
                   1661: 
                   1662: XInitWindow ()
                   1663: {
                   1664:        int x, y, width, height;
                   1665:        XSizeHints sizes;
                   1666:        XWMHints wmhints;
                   1667:        char iconname[50];
                   1668:        extern int xargc;
                   1669:        extern char **xargv;
                   1670:        
                   1671:        strcpy(iconname,"emacs@");
                   1672:        gethostname(iconname+strlen(iconname),30);
                   1673:        
                   1674:        XGeometry (XXdisplay, 0, (desiredwindow && *desiredwindow) ?
                   1675:                   desiredwindow : default_window,
                   1676:                   default_window, XXborder, XXfontw, XXfonth,
                   1677:                   XXInternalBorder*2, XXInternalBorder*2,
                   1678:                   &x, &y, &width, &height);
                   1679: 
                   1680:        XXwindow = XCreateSimpleWindow(XXdisplay, RootWindow(XXdisplay,0),
                   1681:                                  x, y, width*XXfontw+2*XXInternalBorder,
                   1682:                                  height*XXfonth+2*XXInternalBorder,
                   1683:                                  XXborder, brdr, back);
                   1684: 
                   1685:        if (!XXwindow) {
                   1686:                fprintf (stderr, "Could not create window");
                   1687:                fflush (stderr);
                   1688:                exit (-97);
                   1689:        }
                   1690: 
                   1691:        XXgcv.font = XXfid;
                   1692:        XXgcv.foreground = fore;
                   1693:        XXgcv.background = back; 
                   1694:        XXgc_norm = XCreateGC(XXdisplay, XXwindow,
                   1695:                              GCFont|GCForeground|GCBackground,
                   1696:                              &XXgcv);
                   1697:        XXgcv.foreground = back;
                   1698:        XXgcv.background = fore;
                   1699:        XXgc_rev = XCreateGC(XXdisplay, XXwindow,
                   1700:                             GCFont|GCForeground|GCBackground,
                   1701:                             &XXgcv);
                   1702:        XXgcv.foreground = back;
                   1703:        XXgcv.background = curs;
                   1704:        XXgc_curs = XCreateGC(XXdisplay, XXwindow,
                   1705:                              GCFont|GCForeground|GCBackground,
                   1706:                              &XXgcv);
                   1707: 
                   1708:        XSelectInput (XXdisplay, XXwindow, NoEventMask);
                   1709: 
                   1710:        EmacsCursor = XCreateFontCursor(XXdisplay, XC_left_ptr);
                   1711:        XDefineCursor (XXdisplay, XXwindow, EmacsCursor);
                   1712: 
                   1713:        SinkPixmap = XCreateBitmapFromData (XXdisplay, XXwindow,
                   1714:                                            sink_bits, sink_width,
                   1715:                                            sink_height);
                   1716:        SinkMaskPixmap = XCreateBitmapFromData (XXdisplay, XXwindow,
                   1717:                                                sink_mask_bits,
                   1718:                                                sink_mask_width,
                   1719:                                                sink_mask_height);
                   1720:        wmhints.flags = IconPixmapHint|IconMaskHint;
                   1721:        wmhints.icon_pixmap = SinkPixmap;
                   1722:        wmhints.icon_mask = SinkMaskPixmap;
                   1723:        XSetWMHints (XXdisplay, XXwindow, &wmhints);
                   1724: 
                   1725:        sizes.flags = PResizeInc|PMinSize;
                   1726:        sizes.width_inc = XXfontw;
                   1727:        sizes.height_inc = XXfonth;
                   1728:        sizes.min_width = XXfontw*MINWIDTH+2*XXInternalBorder;
                   1729:        sizes.min_height = XXfonth*MINHEIGHT+2*XXInternalBorder;
                   1730: 
                   1731:        if (!desiredwindow || !*desiredwindow)
                   1732:                sizes.flags |= PPosition|PSize;
                   1733:        else
                   1734:                sizes.flags |= USPosition|USSize;
                   1735:        sizes.x = x;
                   1736:        sizes.y = y;
                   1737:        sizes.width = width*XXfontw+2*XXInternalBorder;
                   1738:        sizes.height = height*XXfonth+2*XXInternalBorder;
                   1739: 
                   1740:        change_screen_size(height,width);
                   1741:        
                   1742:        XXxoffset = x;
                   1743:        XXyoffset = y;
                   1744:        pixelwidth = sizes.width;
                   1745:        pixelheight = sizes.height;
                   1746:        
                   1747:        XSetStandardProperties (XXdisplay, XXwindow, progname, iconname,
                   1748:                                SinkPixmap, xargv, xargc, &sizes);
                   1749: 
                   1750:        CursorExists = 0;
                   1751:        VisibleX = 0;
                   1752:        VisibleY = 0;
                   1753:        XMapWindow (XXdisplay, XXwindow);
                   1754:        XFlush (XXdisplay);
                   1755:        WindowMapped = 1;
                   1756: }
                   1757: 
                   1758: #ifdef BIGDEBUG
                   1759: 
                   1760: my_log(s,a,b,c,d,e,f,g,h)
                   1761:        char *s;
                   1762: {
                   1763:        char bfr[256];
                   1764:        
                   1765:        sprintf(bfr,s,a,b,c,d,e,f,g,h);
                   1766: 
                   1767:        strcat(debug_string,bfr);
                   1768: }
                   1769: 
                   1770: dump_log()
                   1771: {
                   1772:        fputs(debug_string,stderr);
                   1773:        fflush(stderr);
                   1774:        *debug_string = '\0';
                   1775: }
                   1776: 
                   1777: #endif BIGDEBUG
                   1778:        
                   1779: #endif /* HAVE_X_WINDOWS */
                   1780: 
                   1781: /*#include "xundebug.h"*/

unix.superglobalmegacorp.com

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