1: #include <X/mit-copyright.h>
   2: 
   3: /* Copyright    Massachusetts Institute of Technology    1985	*/
   4: #ifndef lint
   5: static char *rcsid_dispatch_c = "$Header: dispatch.c,v 10.13 86/02/01 15:15:41 tony Rel $";
   6: #endif
   7: 
   8: #include <dbm.h>
   9: #undef NULL
  10: #include "Xint.h"
  11: #include <errno.h>
  12: #include <sys/time.h>
  13: #include <netinet/in.h>
  14: #include "rgb.h"
  15: 
  16: extern int errno;
  17: extern RESOURCE **Resources;
  18: extern int MaxResource;
  19: extern DEVICE device;
  20: extern int havemask[];
  21: extern int havestate;
  22: extern int rr_counter;
  23: extern int requestId[];
  24: extern char *bufptr[];
  25: extern int bufcnt[];
  26: #ifdef DUALTCP
  27: extern int swapped[];
  28: #endif
  29: extern WINDOW *rootwindow;
  30: extern CURSOR *rootcursor;
  31: extern CURSOR *cursor;
  32: extern short blank_video;
  33: extern struct timeval waittime;
  34: extern struct timeval longtime;
  35: extern int havergb;
  36: 
  37: char *Xalloc(), *Read_segment();
  38: long Add_resource();
  39: PIXMAP *Do_PixmapSave(), *StorePixmap(), *MakePixmap();
  40: FONT *Get_font();
  41: BITMAP *StoreBitmap(), *CharBitmap();
  42: CURSOR *Store_cursor();
  43: WINDOW *Unmap_window();
  44: 
  45: u_char Xstatus;     /* Holds error code */
  46: short base_feep;    /* Base value for X_Feep */
  47: 
  48: /* The main read/dispatch loop */
  49: 
  50: Dispatcher()
  51: {
  52:     register XReq *req;
  53:     XRep rep;
  54:     int client;
  55:     register RESOURCE *rptr, **res;
  56:     register WINDOW *w;
  57:     register int n;
  58:     register FONT *font;
  59:     char *data1, *data2;
  60:     PIXMAP *pix1, *pix2;
  61:     BITMAP *bit1, *bit2;
  62:     WINDOW *icon, *sw;
  63:     CURSOR *cur;
  64:     vsCursor mcursor;
  65:     int count;
  66:     datum dbent;
  67:     RGB color;
  68: #define ILLEGAL(rval,typ) (((n = RESIDX(rval)) <= 0) || \
  69:                (n >= MaxResource) || \
  70:                (((rptr=res[n])->id) != rval) || \
  71:                (rptr->type != typ))
  72: #define REPLY Write (client, (caddr_t) &rep, sizeof (XRep))
  73: 
  74:     rep.code = X_Reply;
  75: 
  76:     /* Just keep receiving a message and dispatching on it. */
  77: 
  78:     while (1) {
  79:         /* If not exactly one ready, or have events, go receive/schedule */
  80:         if (havestate != rr_counter ||
  81:         device.queue->head != device.queue->tail)
  82:         Receive ();
  83: 
  84:         client = n = rr_counter;
  85:         req = (XReq *) bufptr[n];
  86:         bufptr[n] += sizeof (XReq);
  87:         if ((bufcnt[n] -= sizeof (XReq)) < sizeof (XReq)) {
  88:         bitclear(havemask, n);
  89:         if (havestate < 0)
  90:             havestate++;
  91:         else
  92:             havestate = 0;
  93:         }
  94:         requestId[n]++;
  95: #ifdef DUALTCP
  96:         if (swapped[client])
  97:         Swap_request (req);
  98: #endif
  99:         Xstatus = 0;
 100:         res = Resources;
 101: 
 102:         /* Check that the window pointer points to a real window */
 103:         if (req->code < X_SetUp) {
 104:         if ILLEGAL(req->windowId, RT_WINDOW) {
 105:             /* get segment size */
 106:             switch (req->code) {
 107:             case X_StoreName:
 108:                 if ((n = req->param.s[0]) > 0)
 109:                 n = BytePad(n);
 110:                 break;
 111:             case X_PixmapBitsPut:
 112:                 n = Pix_size (req->param.s[4],
 113:                       req->param.s[0], req->param.s[1]);
 114:                 break;
 115:             case X_BitmapBitsPut:
 116:                 n = Bit_size (req->param.s[0], req->param.s[1]);
 117:                 break;
 118:             case X_Text:
 119:             case X_TextMask:
 120:                 if ((n = req->param.s[6]) > 0)
 121:                 n = BytePad(n);
 122:                 break;
 123:             case X_Draw:
 124:             case X_DrawFilled:
 125:                 if ((n = req->param.s[0] * sizeof (Vertex)) > 0)
 126:                 n = WordPad(n);
 127:                 break;
 128:             default:
 129:                 n = 0;
 130:             }
 131:             if (n <= 0 || Read_segment (client, n)) {
 132:             Xstatus = BadWindow;
 133:             Oops (client, req);
 134:             }
 135:             continue;
 136:         } else
 137:             w = (WINDOW *) rptr->value;
 138:         }
 139:         /* Here we verify and convert resource id's to real resources,
 140: 	     * then call the appropriate routine (or do it inline).
 141: 	     * This makes the routine huge, but it minimizes the spread of
 142: 	     * protocol-specifics to other modules.
 143: 	     */
 144:         switch (req->code) {
 145:         case X_CreateWindow:
 146:             if (req->func == 0)
 147:             pix1 = NULL;
 148:             else if ILLEGAL(req->param.l[2], RT_PIXMAP) {
 149:             Xstatus = BadPixmap;
 150:             break;
 151:             } else
 152:             pix1 = (PIXMAP *) rptr->value;
 153:             if (req->param.l[3] == 0)
 154:             pix2 = NULL;
 155:             else if ILLEGAL(req->param.l[3], RT_PIXMAP) {
 156:             Xstatus = BadPixmap;
 157:             break;
 158:             } else
 159:             pix2 = (PIXMAP *) rptr->value;
 160:             rep.param.l[0] = Create_window (req->param.s[0],
 161:                     req->param.s[1], req->param.s[2],
 162:                     req->param.s[3], (int) req->func,
 163:                     pix1, pix2, IsOpaque, w, client);
 164:             if (Xstatus) break;
 165: #ifdef DUALTCP
 166:             if (swapped[client]) {
 167:             pswapl(&rep, 0);
 168:             }
 169: #endif
 170:             REPLY;
 171:             break;
 172: 
 173:         case X_CreateTransparency:
 174:             rep.param.l[0] = Create_window (req->param.s[0],
 175:                     req->param.s[1], req->param.s[2],
 176:                     req->param.s[3], 0,
 177:                     (PIXMAP *) NULL, (PIXMAP *) NULL,
 178:                     IsTransparent, w, client);
 179:             if (Xstatus) break;
 180: #ifdef DUALTCP
 181:             if (swapped[client]) {
 182:             pswapl(&rep, 0);
 183:             }
 184: #endif
 185:             REPLY;
 186:             break;
 187: 
 188:         case X_DestroyWindow:
 189:             if (w != rootwindow) {
 190:             Free_resource (rptr);
 191:             Deal_with_movement ();
 192:             }
 193:             break;
 194: 
 195:         case X_DestroySubwindows:
 196:             if (w->first_child) {
 197:             Remove_subwindows (w, 1, 1);
 198:             Deal_with_movement ();
 199:             }
 200:             break;
 201: 
 202:         case X_MapWindow:
 203:             if FALSE(w->mapped) {
 204:             Map_window (w);
 205:             Deal_with_movement ();
 206:             }
 207:             break;
 208: 
 209:         case X_MapSubwindows:
 210:             Map_subwindows (w, 0, 1);
 211:             Deal_with_movement ();
 212:             break;
 213: 
 214:         case X_UnmapWindow:
 215:             if (w != rootwindow) {
 216:             if TRUE(w->mapped) {
 217:                 Stash_simple (w, (long) UnmapWindow, 0);
 218:                 Unmap_window (w, 1);
 219:                 Deal_with_movement ();
 220:             }
 221:             w->should_be_mapped = 0;
 222:             }
 223:             break;
 224: 
 225:         case X_UnmapSubwindows:
 226:             Unmap_subwindows (w);
 227:             Deal_with_movement ();
 228:             break;
 229: 
 230:         case X_UnmapTransparent:
 231:             if (w != rootwindow) {
 232:             if TRUE(w->mapped) {
 233:                 Unmap_window (w, -1);
 234:                 Deal_with_movement ();
 235:             }
 236:             w->should_be_mapped = 0;
 237:             }
 238:             break;
 239: 
 240:         case X_RaiseWindow:
 241:             if (w != rootwindow) {
 242:             Raise_window (w);
 243:             Deal_with_movement ();
 244:             }
 245:             break;
 246: 
 247:         case X_LowerWindow:
 248:             if (w != rootwindow) {
 249:             Lower_window (w);
 250:             Deal_with_movement ();
 251:             }
 252:             break;
 253: 
 254:         case X_CircWindowUp:
 255:             Circulate_window_up (w);
 256:             Deal_with_movement ();
 257:             break;
 258: 
 259:         case X_MoveWindow:
 260:             if (w != rootwindow) {
 261:             Move_window (w, req->param.s[0], req->param.s[1]);
 262:             Deal_with_movement ();
 263:             }
 264:             break;
 265: 
 266:         case X_ChangeWindow:
 267:             if (w == rootwindow) break;
 268:             Change_window (w, w->full.left - w->bwidth -
 269:                       ((w->mapped) ? w->parent->full.left : 0),
 270:                       w->full.top - w->bwidth -
 271:                       ((w->mapped) ? w->parent->full.top : 0),
 272:                       req->param.s[0], req->param.s[1]);
 273:             Deal_with_movement ();
 274:             break;
 275: 
 276:         case X_ConfigureWindow:
 277:             if (w == rootwindow) break;
 278:             Change_window (w, req->param.s[2], req->param.s[3],
 279:                       req->param.s[0], req->param.s[1]);
 280:             Deal_with_movement ();
 281:             break;
 282: 
 283:         case X_ChangeBackground:
 284:             if (req->param.l[0] == 0)
 285:             Change_background (w, (PIXMAP *) NULL);
 286:             else if ILLEGAL(req->param.l[0], RT_PIXMAP)
 287:             Xstatus = BadPixmap;
 288:             else
 289:             Change_background (w, (PIXMAP *) rptr->value);
 290:             break;
 291: 
 292:         case X_ChangeBorder:
 293:             if ILLEGAL(req->param.l[0], RT_PIXMAP)
 294:             Xstatus = BadPixmap;
 295:             else
 296:             Change_border (w, (PIXMAP *) rptr->value);
 297:             break;
 298: 
 299:         case X_TileMode:
 300:             if (req->func > 1)
 301:             Xstatus = BadValue;
 302:             else if (w != rootwindow)
 303:             w->tilemode = req->func;
 304:             break;
 305: 
 306:         case X_ClipMode:
 307:             if (req->func <= 1)
 308:             w->clipmode = req->func;
 309:             else
 310:             Xstatus = BadValue;
 311:             break;
 312: 
 313:         case X_QueryWindow:
 314:             rep.param.s[0] = w->full.bottom - w->full.top;
 315:             rep.param.s[1] = w->full.right - w->full.left;
 316:             rep.param.s[2] = w->full.left - w->bwidth;
 317:             rep.param.s[3] = w->full.top - w->bwidth;
 318:             if (TRUE(w->mapped) && w->parent) {
 319:             rep.param.s[2] -= w->parent->full.left;
 320:             rep.param.s[3] -= w->parent->full.top;
 321:             }
 322:             rep.param.s[4] = w->bwidth;
 323:             if (TRUE(w->should_be_mapped) && FALSE(w->mapped))
 324:             rep.param.b[10] = IsInvisible;
 325:             else
 326:             rep.param.b[10] = w->mapped;
 327:             rep.param.b[11] = w->kind;
 328:             if (w->icon)
 329:             rep.param.l[3] = w->icon->rid;
 330:             else
 331:             rep.param.l[3] = 0;
 332: #ifdef DUALTCP
 333:             if (swapped[client]) {
 334:             pswaps(&rep, 0);
 335:             pswaps(&rep, 1);
 336:             pswaps(&rep, 2);
 337:             pswaps(&rep, 3);
 338:             pswaps(&rep, 4);
 339:             pswapl(&rep, 3);
 340:             }
 341: #endif
 342:             REPLY;
 343:             break;
 344: 
 345:         case X_StoreName:
 346:             if ((n = req->param.s[0]) < 0)
 347:             Xstatus = BadValue;
 348:             else if (data1 = Read_segment (client, BytePad(n))) {
 349:             if (w->name) {
 350:                 free (w->name);
 351:                 w->name = NULL;
 352:             }
 353:             w->name = Xalloc (n + 1);
 354:             bcopy (data1, w->name, n);
 355:             w->name[n] = '\0';
 356:             }
 357:             break;
 358: 
 359:         case X_FetchName:
 360:             rep.param.s[0] = count = w->name ? strlen (w->name) : 0;
 361: #ifdef DUALTCP
 362:             if (swapped[client]) {
 363:             pswaps(&rep, 0);
 364:             }
 365: #endif
 366:             REPLY;
 367:             if (n = count)
 368:             Write (client, w->name, BytePad(n));
 369:             break;
 370: 
 371:         case X_SetIconWindow:
 372:             if (w->kind != IsOpaque)
 373:             Xstatus = BadMatch;
 374:             else if (req->param.l[0] == 0) {
 375:             if (icon = w->icon) {
 376:                 icon->kind = IsOpaque;
 377:                 icon->icon = NULL;
 378:                 w->icon = NULL;
 379:             }
 380:             } else if ILLEGAL(req->param.l[0], RT_WINDOW)
 381:             Xstatus = BadWindow;
 382:             else {
 383:             icon = (WINDOW *) rptr->value;
 384:             if (icon->kind != IsOpaque || icon == w ||
 385:                 icon->parent != w->parent)
 386:                 Xstatus = BadMatch;
 387:             else {
 388:                 icon->kind = IsIcon;
 389:                 icon->icon = w;
 390:                 w->icon = icon;
 391:             }
 392:             }
 393:             break;
 394: 
 395:         case X_SetResizeHint:
 396:             if (req->param.s[0] < 0 || req->param.s[1] <= 0 ||
 397:             req->param.s[2] < 0 || req->param.s[3] <= 0)
 398:             Xstatus = BadValue;
 399:             else {
 400:             w->height0 = req->param.s[0];
 401:             w->heightinc = req->param.s[1];
 402:             w->width0 = req->param.s[2];
 403:             w->widthinc = req->param.s[3];
 404:             }
 405:             break;
 406: 
 407:         case X_GetResizeHint:
 408:             rep.param.s[0] = w->height0;
 409:             rep.param.s[1] = w->heightinc;
 410:             rep.param.s[2] = w->width0;
 411:             rep.param.s[3] = w->widthinc;
 412: #ifdef DUALTCP
 413:             if (swapped[client]) {
 414:             pswaps(&rep, 0);
 415:             pswaps(&rep, 1);
 416:             pswaps(&rep, 2);
 417:             pswaps(&rep, 3);
 418:             }
 419: #endif
 420:             REPLY;
 421:             break;
 422: 
 423:         case X_DefineCursor:
 424:             if (req->param.l[0] == 0) {
 425:             if (w == rootwindow)
 426:                 Register_cursor (w, rootcursor);
 427:             else
 428:                 Unregister_cursor (w);
 429:             } else if ILLEGAL(req->param.l[0], RT_CURSOR)
 430:             Xstatus = BadCursor;
 431:             else
 432:             Register_cursor (w, (CURSOR *) rptr->value);
 433:             break;
 434: 
 435:         case X_SelectInput:
 436:             Select_input (w, client, req->param.l[0]);
 437:             break;
 438: 
 439:         case X_GrabMouse:
 440:             if ILLEGAL(req->param.l[0], RT_CURSOR)
 441:             Xstatus = BadCursor;
 442:             else {
 443:             Grab_mouse (w, (CURSOR *) rptr->value,
 444:                     req->param.l[1], client);
 445:             if (Xstatus) break;
 446:             REPLY;
 447:             }
 448:             break;
 449: 
 450:         case X_GrabButton:
 451:             if ILLEGAL(req->param.l[0], RT_CURSOR)
 452:             Xstatus = BadCursor;
 453:             else {
 454:             Grab_button (w, (CURSOR *) rptr->value, req->mask,
 455:                      req->param.l[1], client);
 456:             if (Xstatus) break;
 457:             REPLY;
 458:             }
 459:             break;
 460: 
 461:         case X_QueryMouse:
 462:             mcursor = *device.mouse;
 463:             Interpret_locator (w, mcursor.x + cursor->xoff,
 464:                        mcursor.y + cursor->yoff, &rep);
 465: #ifdef DUALTCP
 466:             if (swapped[client]) {
 467:             pswapl(&rep, 0);
 468:             pswaps(&rep, 2);
 469:             pswaps(&rep, 3);
 470:             pswaps(&rep, 4);
 471:             }
 472: #endif
 473:             REPLY;
 474:             break;
 475: 
 476:         case X_InterpretLocator:
 477:             Interpret_locator (w,
 478: #ifdef vax
 479:                        req->param.s[1], req->param.s[0],
 480: #else
 481: #ifdef mc68000
 482:                        req->param.s[0], req->param.s[1],
 483: #else
 484:                        req->param.l[0] >> 16,
 485:                        req->param.l[0] & 0xffff,
 486: #endif
 487: #endif
 488:                        &rep);
 489: #ifdef DUALTCP
 490:             if (swapped[client]) {
 491:             pswapl(&rep, 0);
 492:             pswaps(&rep, 2);
 493:             pswaps(&rep, 3);
 494:             }
 495: #endif
 496:             REPLY;
 497:             break;
 498: 
 499:         case X_WarpMouse:
 500:             if ILLEGAL(req->param.l[1], RT_WINDOW)
 501:             Xstatus = BadWindow;
 502:             else
 503:             Warp_mouse (w, req->param.s[0], req->param.s[1],
 504:                     (WINDOW *) rptr->value,
 505:                     (REGION *) &req->param.s[4]);
 506:             break;
 507: 
 508:         case X_FocusKeyboard:
 509:             Focus_keyboard (w);
 510:             break;
 511: 
 512:         case X_CircWindowDown:
 513:             Circulate_window_down (w);
 514:             Deal_with_movement ();
 515:             break;
 516: 
 517:         case X_QueryTree:
 518:             count = 0;
 519:             for (sw = w->first_child; sw; sw = sw->next_sib)
 520:             count++;
 521:             rep.param.l[0] = w->parent ? w->parent->rid : 0;
 522:             rep.param.l[1] = count;
 523: #ifdef DUALTCP
 524:             if (swapped[client]) {
 525:             pswapl(&rep, 0);
 526:             pswapl(&rep, 1);
 527:             }
 528: #endif
 529:             REPLY;
 530:             if (n = count) {
 531:             data1 = Xalloc (n << 2);
 532:             n = 0;
 533:             for (sw = w->first_child; sw; sw = sw->next_sib) {
 534:                 ((Window *)data1)[n] = sw->rid;
 535:                 n++;
 536:             }
 537: #ifdef DUALTCP
 538:             if (swapped[client])
 539:                 Swap_longs ((long *) data1, n);
 540: #endif
 541:             Write (client, data1, n << 2);
 542:             free (data1);
 543:             }
 544:             break;
 545: 
 546:         case X_Clear:
 547:             Do_background (w, 1);
 548:             break;
 549: 
 550:         case X_PixFill:
 551:             if (req->param.l[3] == 0)
 552:             bit1 = NULL;
 553:             else if ILLEGAL(req->param.l[3], RT_BITMAP) {
 554:             Xstatus = BadBitmap;
 555:             break;
 556:             } else
 557:             bit1 = (BITMAP *) rptr->value;
 558:             Do_PixFill (w, req, bit1);
 559:             break;
 560: 
 561:         case X_TileFill:
 562:             if (req->param.l[3] == 0)
 563:             bit1 = NULL;
 564:             else if ILLEGAL(req->param.l[3], RT_BITMAP) {
 565:             Xstatus = BadBitmap;
 566:             break;
 567:             } else
 568:             bit1 = (BITMAP *) rptr->value;
 569:             if ILLEGAL(req->param.l[2], RT_PIXMAP)
 570:             Xstatus = BadPixmap;
 571:             else
 572:             Do_TileFill (w, req, (PIXMAP *) rptr->value, bit1);
 573:             break;
 574: 
 575:         case X_PixmapPut:
 576:             if ILLEGAL(req->param.l[2], RT_PIXMAP)
 577:             Xstatus = BadPixmap;
 578:             else
 579:             Do_PixmapPut (w, req, (PIXMAP *) rptr->value);
 580:             break;
 581: 
 582:         case X_PixmapBitsPut:
 583:             if ((n = Pix_size (req->param.s[4],
 584:                        req->param.s[0], req->param.s[1])) == 0 ||
 585:             (data1 = Read_segment (client, n)) == NULL)
 586:             break;
 587: #ifdef DUALTCP
 588:             if (swapped[client] &&
 589:             (req->param.s[4] == XYFormat || device.planes > 8))
 590:             Swap_shorts ((short *) data1, n >> 1);
 591: #endif
 592:             if (req->param.l[3] == 0)
 593:             bit1 = NULL;
 594:             else if ILLEGAL(req->param.l[3], RT_BITMAP) {
 595:             Xstatus = BadBitmap;
 596:             break;
 597:             } else
 598:             bit1 = (BITMAP *) rptr->value;
 599:             Do_PixmapBitsPut (w, req, data1, bit1);
 600:             break;
 601: 
 602:         case X_BitmapBitsPut:
 603:             if ((n = Bit_size (req->param.s[0], req->param.s[1])) == 0 ||
 604:             (data1 = Read_segment (client, n)) == NULL)
 605:             break;
 606: #ifdef DUALTCP
 607:             if (swapped[client])
 608:             Swap_shorts ((short *) data1, n >> 1);
 609: #endif
 610:             if (req->param.l[3] == 0)
 611:             bit1 = NULL;
 612:             else if ILLEGAL(req->param.l[3], RT_BITMAP) {
 613:             Xstatus = BadBitmap;
 614:             break;
 615:             } else
 616:             bit1 = (BITMAP *) rptr->value;
 617:             Do_BitmapBitsPut (w, req, data1, bit1);
 618:             break;
 619: 
 620:         case X_CopyArea:
 621:             Do_CopyArea (w, req);
 622:             break;
 623: 
 624:         case X_Text:
 625:             if ((n = req->param.s[6]) < 0)
 626:             Xstatus = BadValue;
 627:             else if (data1 = Read_segment (client, BytePad(n))) {
 628:             if ILLEGAL(req->param.l[1], RT_FONT)
 629:                 Xstatus = BadFont;
 630:             else if (TRUE(w->unobscured) &&
 631:                  w->kind != IsTransparent &&
 632:                  TRUE(w->mapped) && req->func < funclim &&
 633:                  req->param.s[6] > 0)
 634:                 /* We special case this just to make it faster */
 635:                 PrintText (data1, req->param.s[6],
 636:                        (FONT *) rptr->value,
 637:                        (int) req->param.u[4],
 638:                        (int) req->param.u[5],
 639:                        req->param.b[14], req->param.b[15],
 640:                        req->param.s[0] + w->full.left,
 641:                        req->param.s[1] + w->full.top,
 642:                        &w->clip, 1,
 643:                        (int) req->func, (int) req->mask);
 644:             else
 645:                 Do_Text (w, req, data1, (FONT *) rptr->value);
 646:             }
 647:             break;
 648: 
 649:         case X_TextMask:
 650:             if ((n = req->param.s[6]) < 0)
 651:             Xstatus = BadValue;
 652:             else if (data1 = Read_segment (client, BytePad(n))) {
 653:             if ILLEGAL(req->param.l[1], RT_FONT)
 654:                 Xstatus = BadFont;
 655:             else
 656:                 Do_TextMask (w, req, data1, (FONT *) rptr->value);
 657:             }
 658:             break;
 659: 
 660:         case X_Line:
 661:             Do_Line (w, req);
 662:             break;
 663: 
 664:         case X_Draw:
 665:             if ((n = (req->param.s[0] * sizeof (Vertex))) < 0)
 666:             Xstatus = BadValue;
 667:             else if (data1 = Read_segment (client, WordPad(n))) {
 668: #ifdef DUALTCP
 669:             if (swapped[client])
 670:                 Swap_shorts ((short *) data1, n >> 1);
 671: #endif
 672:             Do_Draw (w, req, (Vertex *) data1);
 673:             }
 674:             break;
 675: 
 676:         case X_DrawFilled:
 677:             if ((n = (req->param.s[0] * sizeof (Vertex))) < 0)
 678:             Xstatus = BadValue;
 679:             else if (data1 = Read_segment (client, WordPad(n))) {
 680:             if (req->param.l[1] == 0)
 681:                 pix1 = NULL;
 682:             else if ILLEGAL(req->param.l[1], RT_PIXMAP) {
 683:                 Xstatus = BadPixmap;
 684:                 break;
 685:             } else
 686:                 pix1 = (PIXMAP *) rptr->value;
 687: #ifdef DUALTCP
 688:             if (swapped[client])
 689:                 Swap_shorts ((short *) data1,
 690:                      req->param.s[0] * (sizeof (Vertex) /
 691:                                 sizeof (short)));
 692: #endif
 693:             Do_DrawFilled (w, req, (Vertex *) data1, pix1);
 694:             }
 695:             break;
 696: 
 697:         case X_PixmapSave:
 698:             pix1 = Do_PixmapSave (w, req);
 699:             if (Xstatus) break;
 700:             rep.param.l[0] = Add_resource (RT_PIXMAP, client,
 701:                            (caddr_t) pix1);
 702: #ifdef DUALTCP
 703:             if (swapped[client]) {
 704:             pswapl(&rep, 0);
 705:             }
 706: #endif
 707:             REPLY;
 708:             break;
 709: 
 710:         case X_PixmapGet:
 711:             Do_PixmapGet (w, req, client);
 712:             break;
 713: 
 714:         case X_SetUp:
 715:             rep.param.l[0] = rootwindow->rid;
 716:             rep.param.s[2] = X_PROTOCOL;
 717:             rep.param.s[3] = device.id;
 718:             rep.param.s[4] = device.planes;
 719:             rep.param.u[5] = device.entries;
 720: #ifdef DUALTCP
 721:             if (swapped[client]) {
 722:             pswapl(&rep, 0);
 723:             pswaps(&rep, 2);
 724:             pswaps(&rep, 3);
 725:             pswaps(&rep, 4);
 726:             pswaps(&rep, 5);
 727:             }
 728: #endif
 729:             REPLY;
 730:             break;
 731: 
 732:         case X_UngrabMouse:
 733:             Ungrab_mouse (client);
 734:             break;
 735: 
 736:         case X_UngrabButton:
 737:             Ungrab_button (req->mask, client);
 738:             break;
 739: 
 740:         case X_GetColor:
 741:             if (rep.param.u[0] = Get_color (client, req->param.u[0],
 742:                             req->param.u[1], req->param.u[2])) {
 743: #ifdef DUALTCP
 744:             if (swapped[client]) {
 745:                 pswaps(&rep, 0);
 746:             }
 747: #endif
 748:             REPLY;
 749:             }
 750:             break;
 751: 
 752:         case X_GetColorCells:
 753:             if (req->func > 1 ||
 754:             req->param.s[0] < 0 || req->param.s[1] < 0) {
 755:             Xstatus = BadValue;
 756:             break;
 757:             }
 758:             rep.param.u[0] = Get_cells (client, (int) req->func,
 759:                         req->param.s[0], req->param.s[1],
 760:                         (ushort **) &data1);
 761:             if (!Xstatus) {
 762: #ifdef DUALTCP
 763:             if (swapped[client]) {
 764:                 pswaps(&rep, 0);
 765:                 Swap_shorts ((short *) data1, req->param.s[0]);
 766:             }
 767: #endif
 768:             REPLY;
 769:             if (n = req->param.s[0]) {
 770:                 Write (client, data1, WordPad(n << 1));
 771: #ifdef DUALTCP
 772:                 if (swapped[client])
 773:                 Swap_shorts ((short *) data1, n);
 774: #endif
 775:             }
 776:             }
 777:             break;
 778: 
 779:         case X_FreeColors:
 780:             if ((n = req->param.s[0]) < 0)
 781:             Xstatus = BadValue;
 782:             else if (data1 = Read_segment (client, WordPad(n << 1))) {
 783: #ifdef DUALTCP
 784:             if (swapped[client])
 785:                 Swap_shorts ((short *) data1, n);
 786: #endif
 787:             Free_colors (client, n, (ushort *) data1, req->mask);
 788:             }
 789:             break;
 790: 
 791:         case X_StoreColors:
 792:             if ((n = req->param.s[0]) < 0)
 793:             Xstatus = BadValue;
 794:             else if (data1 = Read_segment (client, n * sizeof (ColorDef))) {
 795: #ifdef DUALTCP
 796:             if (swapped[client])
 797:                 Swap_shorts ((short *) data1, n * (sizeof (ColorDef) / sizeof (short)));
 798: #endif
 799:             Store_colors (n, (ColorDef *) data1);
 800:             }
 801:             break;
 802: 
 803:         case X_QueryColor:
 804:             Query_color (req->param.u[0], rep.param.u+0,
 805:                  rep.param.u+1, rep.param.u+2);
 806:             if (!Xstatus) {
 807: #ifdef DUALTCP
 808:             if (swapped[client]) {
 809:                 pswaps(&rep, 0);
 810:                 pswaps(&rep, 1);
 811:                 pswaps(&rep, 2);
 812:             }
 813: #endif
 814:             REPLY;
 815:             }
 816:             break;
 817: 
 818:         case X_GetFont:
 819:             if ((n = req->param.s[0]) <= 0)
 820:             Xstatus = BadValue;
 821:             else if (data1 = Read_segment (client, BytePad(n))) {
 822:             data2 = Xalloc (n + 1);
 823:             bcopy (data1, data2, n);
 824:             data2[n] = '\0';
 825:             font = Get_font (data2);
 826:             free (data2);
 827:             if (Xstatus) break;
 828:             rep.param.l[0] = Add_resource (RT_FONT, client,
 829:                                (caddr_t) font);
 830: #ifdef DUALTCP
 831:             if (swapped[client]) {
 832:                 pswapl(&rep, 0);
 833:             }
 834: #endif
 835:             REPLY;
 836:             }
 837:             break;
 838: 
 839:         case X_FreeFont:
 840:             if ILLEGAL(req->param.l[0], RT_FONT)
 841:             Xstatus = BadFont;
 842:             else
 843:             Free_resource (rptr);
 844:             break;
 845: 
 846:         case X_QueryFont:
 847:             if ILLEGAL(req->param.l[0], RT_FONT)
 848:             Xstatus = BadFont;
 849:             else {
 850:             font = (FONT *) rptr->value;
 851:             rep.param.s[0] = font->height;
 852:             rep.param.s[1] = font->avg_width;
 853:             rep.param.s[2] = font->first;
 854:             rep.param.s[3] = font->last;
 855:             rep.param.s[4] = font->base;
 856:             rep.param.s[5] = font->fixed;
 857: #ifdef DUALTCP
 858:             if (swapped[client]) {
 859:                 pswaps(&rep, 0);
 860:                 pswaps(&rep, 1);
 861:                 pswaps(&rep, 2);
 862:                 pswaps(&rep, 3);
 863:                 pswaps(&rep, 4);
 864:                 pswaps(&rep, 5);
 865:             }
 866: #endif
 867:             REPLY;
 868:             }
 869:             break;
 870: 
 871:         case X_CharWidths:
 872:             if ((n = req->param.s[2]) < 0)
 873:             Xstatus = BadValue;
 874:             else if (data1 = Read_segment (client, BytePad(n))) {
 875:             if ILLEGAL(req->param.l[0], RT_FONT)
 876:                 Xstatus = BadFont;
 877:             else {
 878:                 font = (FONT *) rptr->value;
 879:                 n = req->param.s[2];
 880:                 data2 = Xalloc ((int) WordPad(count = n << 1));
 881:                 while (--n >= 0)
 882:                 ((short *)data2)[n] = CharWidth (((u_char *) data1)[n],
 883:                                  font);
 884:                 rep.param.l[0] = count;
 885: #ifdef DUALTCP
 886:                 if (swapped[client]) {
 887:                 pswapl(&rep, 0);
 888:                 Swap_shorts ((short *) data2, req->param.s[2]);
 889:                 }
 890: #endif
 891:                 REPLY;
 892:                 Write (client, data2, WordPad(count));
 893:                 free (data2);
 894:             }
 895:             }
 896:             break;
 897: 
 898:         case X_StringWidth:
 899:             if ((n = req->param.s[2]) < 0)
 900:             Xstatus = BadValue;
 901:             else if (data1 = Read_segment (client, BytePad(n))) {
 902:             if ILLEGAL(req->param.l[0], RT_FONT)
 903:                 Xstatus = BadFont;
 904:             else {
 905:                 rep.param.s[0] = TextWidth (data1, req->param.s[2],
 906:                             0, (FONT *) rptr->value);
 907: #ifdef DUALTCP
 908:                 if (swapped[client]) {
 909:                 pswaps(&rep, 0);
 910:                 }
 911: #endif
 912:                 REPLY;
 913:             }
 914:             }
 915:             break;
 916: 
 917:         case X_FontWidths:
 918:             if ILLEGAL(req->param.l[0], RT_FONT)
 919:             Xstatus = BadFont;
 920:             else {
 921:             font = (FONT *) rptr->value;
 922:             n = font->last - font->first + 1;
 923:             data1 = Xalloc ((int) WordPad(count = n << 1));
 924:             while (--n >= 0)
 925:                 ((short *)data1)[n] = CharWidth ((unsigned) font->first + n,
 926:                                  font);
 927:             rep.param.l[0] = count;
 928: #ifdef DUALTCP
 929:             if (swapped[client]) {
 930:                 pswapl(&rep, 0);
 931:                 Swap_shorts ((short *) data1, count >> 1);
 932:             }
 933: #endif
 934:             REPLY;
 935:             Write (client, data1, WordPad(count));
 936:             free (data1);
 937:             }
 938:             break;
 939: 
 940:         case X_StoreBitmap:
 941:             if ((n = Bit_size (req->param.s[0], req->param.s[1])) > 0 &&
 942:             (data1 = Read_segment (client, n))) {
 943: #ifdef DUALTCP
 944:             if (swapped[client])
 945:             Swap_shorts ((short *) data1, n >> 1);
 946: #endif
 947:             bit1 = StoreBitmap (req->param.s[1], req->param.s[0],
 948:                         data1);
 949:             if (bit1 == NULL)
 950:                 Xstatus = BadAlloc;
 951:             else {
 952:                 rep.param.l[0] = Add_resource (RT_BITMAP, client,
 953:                                (caddr_t) bit1);
 954: #ifdef DUALTCP
 955:                 if (swapped[client]) {
 956:                 pswapl(&rep, 0);
 957:                 }
 958: #endif
 959:                 REPLY;
 960:             }
 961:             }
 962:             break;
 963: 
 964:         case X_FreeBitmap:
 965:             if ILLEGAL(req->param.l[0], RT_BITMAP)
 966:             Xstatus = BadBitmap;
 967:             else
 968:             Free_resource (rptr);
 969:             break;
 970: 
 971:         case X_CharBitmap:
 972:             if ILLEGAL(req->param.l[0], RT_FONT)
 973:             Xstatus = BadFont;
 974:             else {
 975:             bit1 = CharBitmap ((unsigned) req->param.s[2],
 976:                        (FONT *) rptr->value);
 977:             if (bit1) {
 978:                 rep.param.l[0] = Add_resource (RT_BITMAP, client,
 979:                                (caddr_t) bit1);
 980: #ifdef DUALTCP
 981:                 if (swapped[client]) {
 982:                 pswapl(&rep, 0);
 983:                 }
 984: #endif
 985:                 REPLY;
 986:             } else if (errno == ENOMEM)
 987:                 Xstatus = BadAlloc;
 988:             else
 989:                 Xstatus = BadValue;
 990:             }
 991:             break;
 992: 
 993:         case X_StorePixmap:
 994:             if ((n = Pix_size ((int) req->func,
 995:                        req->param.s[0], req->param.s[1])) > 0 &&
 996:             (data1 = Read_segment (client, n))) {
 997: #ifdef DUALTCP
 998:             if (swapped[client] &&
 999:             (req->func == XYFormat || device.planes > 8))
1000:             Swap_shorts ((short *) data1, n >> 1);
1001: #endif
1002:             pix1 = StorePixmap (req->param.s[1], req->param.s[0],
1003:                         (int) req->func, data1);
1004:             if (pix1 == NULL)
1005:                 Xstatus = BadAlloc;
1006:             else {
1007:                 rep.param.l[0] = Add_resource (RT_PIXMAP, client,
1008:                                (caddr_t) pix1);
1009: #ifdef DUALTCP
1010:                 if (swapped[client]) {
1011:                 pswapl(&rep, 0);
1012:                 }
1013: #endif
1014:                 REPLY;
1015:             }
1016:             }
1017:             break;
1018: 
1019:         case X_FreePixmap:
1020:             if ILLEGAL(req->param.l[0], RT_PIXMAP)
1021:             Xstatus = BadBitmap;
1022:             else
1023:             Free_resource (rptr);
1024:             break;
1025: 
1026:         case X_MakePixmap:
1027:             if (req->param.l[0] == 0) {
1028:             bit1 = NULL;
1029:             if (req->param.u[2] > WhitePixel &&
1030:                 req->param.u[2] >= device.entries) {
1031:                 Xstatus = BadValue;
1032:                 break;
1033:             }
1034:             } else if ILLEGAL(req->param.l[0], RT_BITMAP) {
1035:             Xstatus = BadBitmap;
1036:             break;
1037:             } else if ((req->param.u[2] > WhitePixel &&
1038:                 req->param.u[2] >= device.entries) ||
1039:                    (req->param.u[3] > WhitePixel &&
1040:                 req->param.u[3] >= device.entries)) {
1041:             Xstatus = BadValue;
1042:             break;
1043:             } else
1044:             bit1 = (BITMAP *) rptr->value;
1045:             pix1 = MakePixmap (bit1, (int) req->param.u[2],
1046:                        (int) req->param.u[3]);
1047:             if (pix1 == NULL)
1048:             Xstatus = BadAlloc;
1049:             else {
1050:             rep.param.l[0] = Add_resource (RT_PIXMAP, client,
1051:                                (caddr_t) pix1);
1052: #ifdef DUALTCP
1053:             if (swapped[client]) {
1054:                 pswapl(&rep, 0);
1055:             }
1056: #endif
1057:             REPLY;
1058:             }
1059:             break;
1060: 
1061:         case X_QueryShape:
1062:             if (req->func > 2 ||
1063:             req->param.s[0] <= 0 || req->param.s[1] <= 0)
1064:             Xstatus = BadValue;
1065:             else {
1066:             QueryShape ((int) req->func,
1067:                     req->param.s, req->param.s+1);
1068:             rep.param.s[0] = req->param.s[0];
1069:             rep.param.s[1] = req->param.s[1];
1070: #ifdef DUALTCP
1071:             if (swapped[client]) {
1072:                 pswaps(&rep, 0);
1073:                 pswaps(&rep, 1);
1074:             }
1075: #endif
1076:             REPLY;
1077:             }
1078:             break;
1079: 
1080:         case X_StoreCursor:
1081:             if ILLEGAL(req->param.l[0], RT_BITMAP) {
1082:             Xstatus = BadBitmap;
1083:             break;
1084:             }
1085:             bit1 = (BITMAP *) rptr->value;
1086:             if (req->param.l[2] == 0)
1087:             bit2 = NULL;
1088:             else if ILLEGAL(req->param.l[2], RT_BITMAP) {
1089:             Xstatus = BadBitmap;
1090:             break;
1091:             } else
1092:             bit2 = (BITMAP *) rptr->value;
1093:             cur = Store_cursor (bit1, bit2, (int) req->param.u[2],
1094:                     (int) req->param.u[3],
1095:                     req->param.s[6], req->param.s[7],
1096:                     req->func);
1097:             if (Xstatus) break;
1098:             rep.param.l[0] = Add_resource (RT_CURSOR, client,
1099:                            (caddr_t) cur);
1100: #ifdef DUALTCP
1101:             if (swapped[client]) {
1102:             pswapl(&rep, 0);
1103:             }
1104: #endif
1105:             REPLY;
1106:             break;
1107: 
1108:         case X_FreeCursor:
1109:             if ILLEGAL(req->param.l[0], RT_CURSOR)
1110:             Xstatus = BadCursor;
1111:             else
1112:             Free_resource (rptr);
1113:             break;
1114: 
1115:         case X_MouseControl:
1116:             if (req->param.s[0] <= 0 || req->param.s[1] < 0)
1117:             Xstatus = BadValue;
1118:             else
1119:             SetMouseCharacteristics (req->param.s[1],
1120:                          req->param.s[0]);
1121:             break;
1122: 
1123:         case X_FeepControl:
1124:             if (req->func > 7)
1125:             Xstatus = BadValue;
1126:             else
1127:             base_feep = req->func;
1128:             break;
1129: 
1130:         case X_Feep:
1131:             n = req->param.s[0];
1132:             if (n < -7 || n > 7)
1133:             Xstatus = BadValue;
1134:             else {
1135:             n += base_feep;
1136:             if (n < 0)
1137:                 n = 0;
1138:             else if (n > 7)
1139:                 n = 7;
1140:             SoundBell (n);
1141:             }
1142:             break;
1143: 
1144:         case X_ShiftLock:
1145:             if (req->func > 1)
1146:             Xstatus = BadValue;
1147:             else
1148:             Set_shiftlock ((int) req->func);
1149:             break;
1150: 
1151:         case X_KeyClick:
1152:             if (req->func > 8)
1153:             Xstatus = BadValue;
1154:             else
1155:             SetKeyClick ((int) req->func);
1156:             break;
1157: 
1158:         case X_AutoRepeat:
1159:             if (req->func > 1)
1160:             Xstatus = BadValue;
1161:             else
1162:             SetAutoRepeat ((int) req->func);
1163:             break;
1164: 
1165:         case X_ScreenSaver:
1166:             if (req->func > 1 ||
1167:             req->param.s[0] <= 0 || req->param.s[1] <= 0)
1168:             Xstatus = BadValue;
1169:             else {
1170:             blank_video = 1 - req->func;
1171:             waittime.tv_sec = 60 * req->param.s[0];
1172:             longtime.tv_sec = 60 * req->param.s[1];
1173:             }
1174:             break;
1175: 
1176:         case X_StoreBytes:
1177:             if ((n = req->param.s[0]) < 0)
1178:             Xstatus = BadValue;
1179:             else if (data1 = Read_segment (client, BytePad(n)))
1180:             Store_cut (req->func, data1, n);
1181:             break;
1182: 
1183:         case X_FetchBytes:
1184:             if ((count = Fetch_cut (req->func, &data1)) >= 0) {
1185:             rep.param.s[0] = count;
1186: #ifdef DUALTCP
1187:             if (swapped[client]) {
1188:                 pswaps(&rep, 0);
1189:             }
1190: #endif
1191:             REPLY;
1192:             if (n = count)
1193:                 Write (client, data1, BytePad(n));
1194:             }
1195:             break;
1196: 
1197:         case X_RotateCuts:
1198:             Rotate_cuts (req->func);
1199:             break;
1200: 
1201:         case X_AddHost:
1202:             Add_host (client, (short) req->func, req->param.b);
1203:             break;
1204: 
1205:         case X_RemoveHost:
1206:             Remove_host (client, (short) req->func, req->param.b);
1207:             break;
1208: 
1209:         case X_GetHosts:
1210:             if ((count = Get_hosts ((short) req->func, &data1)) < 0)
1211:             break;
1212:             rep.param.l[0] = count;
1213: #ifdef DUALTCP
1214:             if (swapped[client]) {
1215:             pswapl(&rep, 0);
1216:             }
1217: #endif
1218:             REPLY;
1219:             if (count) {
1220:             Write (client, data1, count);
1221:             free (data1);
1222:             }
1223:             break;
1224: 
1225:         case X_GrabServer:
1226:             Grab_server (client);
1227:             break;
1228: 
1229:         case X_UngrabServer:
1230:             Ungrab_server ();
1231:             break;
1232: 
1233:         case X_LookupColor:
1234:             if ((n = req->param.s[0]) < 0)
1235:             Xstatus = BadValue;
1236:             else if (data1 = Read_segment (client, BytePad(n))) {
1237:             if TRUE(havergb) {
1238:                 dbent.dptr = data1;
1239:                 dbent.dsize = n;
1240:                 dbent = fetch (dbent);
1241:                 if (dbent.dptr) {
1242:                 bcopy(dbent.dptr, (caddr_t)&color, sizeof (RGB));
1243:                 rep.param.u[0] = color.red;
1244:                 rep.param.u[1] = color.green;
1245:                 rep.param.u[2] = color.blue;
1246:                 rep.param.u[3] = rep.param.u[0];
1247:                 rep.param.u[4] = rep.param.u[1];
1248:                 rep.param.u[5] = rep.param.u[2];
1249:                 ResolveColor (rep.param.u+3, rep.param.u+4,
1250:                           rep.param.u+5);
1251: #ifdef DUALTCP
1252:                 if (swapped[client]) {
1253:                     pswaps(&rep, 0);
1254:                     pswaps(&rep, 1);
1255:                     pswaps(&rep, 2);
1256:                     pswaps(&rep, 3);
1257:                     pswaps(&rep, 4);
1258:                     pswaps(&rep, 5);
1259:                 }
1260: #endif
1261:                 REPLY;
1262:                 } else
1263:                 Xstatus = BadColor;
1264:             } else
1265:                 Xstatus = BadColor;
1266:             }
1267:             break;
1268: 
1269:         default:
1270:             Xstatus = BadRequest;
1271:             break;
1272:         }
1273: 
1274:         if (Xstatus) Oops (client, req);
1275:     }
1276: }
1277: 
1278: #ifdef DUALTCP
1279: /* Byte swap a request */
1280: 
1281: Swap_request (req)
1282:     register XReq *req;
1283: {
1284:     register swaptype n;
1285: 
1286:     switch (req->code) {
1287:         case X_CreateWindow:
1288:         swapl(&req->windowId);
1289:         pswaps(req, 0);
1290:         pswaps(req, 1);
1291:         pswaps(req, 2);
1292:         pswaps(req, 3);
1293:         pswapl(req, 2);
1294:         pswapl(req, 3);
1295:         break;
1296: 
1297:         case X_CreateTransparency:
1298:         case X_ConfigureWindow:
1299:         case X_SetResizeHint:
1300:         case X_PixmapSave:
1301:         case X_PixmapGet:
1302:         swapl(&req->windowId);
1303:         pswaps(req, 0);
1304:         pswaps(req, 1);
1305:         pswaps(req, 2);
1306:         pswaps(req, 3);
1307:         break;
1308: 
1309:         case X_DestroyWindow:
1310:         case X_DestroySubwindows:
1311:         case X_MapWindow:
1312:         case X_MapSubwindows:
1313:         case X_UnmapWindow:
1314:         case X_UnmapSubwindows:
1315:         case X_UnmapTransparent:
1316:         case X_RaiseWindow:
1317:         case X_LowerWindow:
1318:         case X_CircWindowUp:
1319:         case X_TileMode:
1320:         case X_ClipMode:
1321:         case X_QueryWindow:
1322:         case X_FetchName:
1323:         case X_GetResizeHint:
1324:         case X_QueryMouse:
1325:         case X_FocusKeyboard:
1326:         case X_CircWindowDown:
1327:         case X_QueryTree:
1328:         case X_Clear:
1329:         swapl(&req->windowId);
1330:         break;
1331: 
1332:         case X_MoveWindow:
1333:         case X_ChangeWindow:
1334:         swapl(&req->windowId);
1335:         pswaps(req, 0);
1336:         pswaps(req, 1);
1337:         break;
1338: 
1339:         case X_ChangeBackground:
1340:         case X_ChangeBorder:
1341:         case X_SetIconWindow:
1342:         case X_DefineCursor:
1343:         case X_SelectInput:
1344:         case X_InterpretLocator:
1345:         swapl(&req->windowId);
1346:         pswapl(req, 0);
1347:         break;
1348: 
1349:         case X_StoreName:
1350:         swapl(&req->windowId);
1351:         pswaps(req, 0);
1352:         break;
1353: 
1354:         case X_GrabMouse:
1355:         swapl(&req->windowId);
1356:         pswapl(req, 0);
1357:         pswapl(req, 1);
1358:         break;
1359: 
1360:         case X_GrabButton:
1361:         swaps(&req->mask);
1362:         swapl(&req->windowId);
1363:         pswapl(req, 0);
1364:         pswapl(req, 1);
1365:         break;
1366: 
1367:         case X_WarpMouse:
1368:         swapl(&req->windowId);
1369:         pswaps(req, 0);
1370:         pswaps(req, 1);
1371:         pswapl(req, 1);
1372:         pswaps(req, 4);
1373:         pswaps(req, 5);
1374:         pswaps(req, 6);
1375:         pswaps(req, 7);
1376:         break;
1377: 
1378:         case X_PixFill:
1379:         case X_PixmapBitsPut:
1380:         swaps(&req->mask);
1381:         swapl(&req->windowId);
1382:         pswaps(req, 0);
1383:         pswaps(req, 1);
1384:         pswaps(req, 2);
1385:         pswaps(req, 3);
1386:         pswaps(req, 4);
1387:         pswapl(req, 3);
1388:         break;
1389: 
1390:         case X_TileFill:
1391:         swaps(&req->mask);
1392:         swapl(&req->windowId);
1393:         pswaps(req, 0);
1394:         pswaps(req, 1);
1395:         pswaps(req, 2);
1396:         pswaps(req, 3);
1397:         pswapl(req, 2);
1398:         pswapl(req, 3);
1399:         break;
1400: 
1401:         case X_PixmapPut:
1402:         swaps(&req->mask);
1403:         swapl(&req->windowId);
1404:         pswaps(req, 0);
1405:         pswaps(req, 1);
1406:         pswaps(req, 2);
1407:         pswaps(req, 3);
1408:         pswapl(req, 2);
1409:         pswaps(req, 6);
1410:         pswaps(req, 7);
1411:         break;
1412: 
1413:         case X_BitmapBitsPut:
1414:         swaps(&req->mask);
1415:         swapl(&req->windowId);
1416:         pswaps(req, 0);
1417:         pswaps(req, 1);
1418:         pswaps(req, 2);
1419:         pswaps(req, 3);
1420:         pswaps(req, 4);
1421:         pswaps(req, 5);
1422:         pswapl(req, 3);
1423:         break;
1424: 
1425:         case X_CopyArea:
1426:         swaps(&req->mask);
1427:         swapl(&req->windowId);
1428:         pswaps(req, 0);
1429:         pswaps(req, 1);
1430:         pswaps(req, 2);
1431:         pswaps(req, 3);
1432:         pswaps(req, 6);
1433:         pswaps(req, 7);
1434:         break;
1435: 
1436:         case X_Text:
1437:         swaps(&req->mask);
1438:         swapl(&req->windowId);
1439:         pswaps(req, 0);
1440:         pswaps(req, 1);
1441:         pswapl(req, 1);
1442:         pswaps(req, 4);
1443:         pswaps(req, 5);
1444:         pswaps(req, 6);
1445:         break;
1446: 
1447:         case X_TextMask:
1448:         swaps(&req->mask);
1449:         swapl(&req->windowId);
1450:         pswaps(req, 0);
1451:         pswaps(req, 1);
1452:         pswapl(req, 1);
1453:         pswaps(req, 4);
1454:         pswaps(req, 6);
1455:         break;
1456: 
1457:         case X_Line:
1458:         swaps(&req->mask);
1459:         swapl(&req->windowId);
1460:         pswaps(req, 0);
1461:         pswaps(req, 1);
1462:         pswaps(req, 2);
1463:         pswaps(req, 3);
1464:         pswaps(req, 4);
1465:         break;
1466: 
1467:         case X_Draw:
1468:         swaps(&req->mask);
1469:         swapl(&req->windowId);
1470:         pswaps(req, 0);
1471:         pswaps(req, 1);
1472:         pswaps(req, 3);
1473:         pswaps(req, 4);
1474:         pswaps(req, 5);
1475:         pswaps(req, 6);
1476:         pswaps(req, 7);
1477:         break;
1478: 
1479:         case X_DrawFilled:
1480:         swaps(&req->mask);
1481:         swapl(&req->windowId);
1482:         pswaps(req, 0);
1483:         pswaps(req, 1);
1484:         pswapl(req, 1);
1485:         break;
1486: 
1487:         case X_UngrabButton:
1488:         swaps(&req->mask);
1489:         break;
1490: 
1491:         case X_GetColor:
1492:         pswaps(req, 0);
1493:         pswaps(req, 1);
1494:         pswaps(req, 2);
1495:         break;
1496: 
1497:         case X_GetColorCells:
1498:         case X_StoreBitmap:
1499:         case X_StorePixmap:
1500:         case X_QueryShape:
1501:         case X_MouseControl:
1502:         case X_ScreenSaver:
1503:         pswaps(req, 0);
1504:         pswaps(req, 1);
1505:         break;
1506: 
1507:         case X_FreeColors:
1508:         swaps(&req->mask);
1509:         pswaps(req, 0);
1510:         break;
1511: 
1512:         case X_StoreColors:
1513:         case X_QueryColor:
1514:         case X_GetFont:
1515:         case X_Feep:
1516:         case X_StoreBytes:
1517:         case X_LookupColor:
1518:         pswaps(req, 0);
1519:         break;
1520: 
1521:         case X_FreeFont:
1522:         case X_QueryFont:
1523:         case X_FontWidths:
1524:         case X_FreeBitmap:
1525:         case X_FreePixmap:
1526:         case X_FreeCursor:
1527:         pswapl(req, 0);
1528:         break;
1529: 
1530:         case X_CharWidths:
1531:         case X_StringWidth:
1532:         case X_CharBitmap:
1533:         pswapl(req, 0);
1534:         pswaps(req, 2);
1535:         break;
1536: 
1537:         case X_MakePixmap:
1538:         pswapl(req, 0);
1539:         pswaps(req, 2);
1540:         pswaps(req, 3);
1541:         break;
1542: 
1543:         case X_StoreCursor:
1544:         pswapl(req, 0);
1545:         pswaps(req, 2);
1546:         pswaps(req, 3);
1547:         pswapl(req, 2);
1548:         pswaps(req, 6);
1549:         pswaps(req, 7);
1550:         break;
1551:     }
1552: }
1553: 
1554: /* Byte swap a list of longs */
1555: 
1556: Swap_longs (list, count)
1557:     register long *list;
1558:     register int count;
1559: {
1560:     register swaptype n;
1561: 
1562:     while (count >= 8) {
1563:         swapl(list+0);
1564:         swapl(list+1);
1565:         swapl(list+2);
1566:         swapl(list+3);
1567:         swapl(list+4);
1568:         swapl(list+5);
1569:         swapl(list+6);
1570:         swapl(list+7);
1571:         list += 8;
1572:         count -= 8;
1573:     }
1574:     while (--count >= 0) {
1575:         swapl(list);
1576:         list++;
1577:     }
1578: }
1579: #endif
1580: 
1581: /* Byte swap a list of shorts */
1582: 
1583: Swap_shorts (list, count)
1584:     register short *list;
1585:     register int count;
1586: {
1587:     register swaptype n;
1588: 
1589:     while (count >= 16) {
1590:         swaps(list+0);
1591:         swaps(list+1);
1592:         swaps(list+2);
1593:         swaps(list+3);
1594:         swaps(list+4);
1595:         swaps(list+5);
1596:         swaps(list+6);
1597:         swaps(list+7);
1598:         swaps(list+8);
1599:         swaps(list+9);
1600:         swaps(list+10);
1601:         swaps(list+11);
1602:         swaps(list+12);
1603:         swaps(list+13);
1604:         swaps(list+14);
1605:         swaps(list+15);
1606:         list += 16;
1607:         count -= 16;
1608:     }
1609:     while (--count >= 0) {
1610:         swaps(list);
1611:         list++;
1612:     }
1613: }
1614: 
1615: /* Send an Error back to the client. */
1616: 
1617: Oops (client, req)
1618:     int client;
1619:     register XReq *req;
1620: {
1621:     XRep rep;
1622: #ifdef DUALTCP
1623:     register swaptype n;
1624: #endif
1625: 
1626:     rep.code = X_Error;
1627:     rep.param.l[0] = requestId[client];
1628:     rep.param.b[4] = Xstatus;
1629:     rep.param.b[5] = req->code;
1630:     rep.param.b[6] = req->func;
1631:     rep.param.l[2] = req->windowId;
1632: #ifdef DUALTCP
1633:     if (swapped[client]) {
1634:         pswapl(&rep, 0);
1635:         pswapl(&rep, 2);
1636:     }
1637: #endif
1638:     Write (client, (caddr_t) &rep, sizeof (XRep));
1639: }

Defined functions

Dispatcher defined in line 50; used 1 times
Oops defined in line 1617; used 2 times
Swap_longs defined in line 1556; used 1 times
Swap_request defined in line 1281; used 2 times
Swap_shorts defined in line 1583; used 12 times

Defined variables

base_feep defined in line 46; used 3 times
rcsid_dispatch_c defined in line 5; never used

Defined macros

ILLEGAL defined in line 68; used 31 times
REPLY defined in line 72; used 29 times
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3478
Valid CSS Valid XHTML 1.0 Strict