home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / macII / Xrepair.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-05  |  5.4 KB  |  208 lines

  1. /************************************************************ 
  2. Copyright 1988 by Apple Computer, Inc, Cupertino, California
  3.             All Rights Reserved
  4.  
  5. Permission to use, copy, modify, and distribute this software
  6. for any purpose and without fee is hereby granted, provided
  7. that the above copyright notice appear in all copies.
  8.  
  9. APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS,
  10. OR IMPLIED, WITH RESPECT TO THIS SOFTWARE, ITS QUALITY,
  11. PERFORMANCE, MERCHANABILITY, OR FITNESS FOR A PARTICULAR
  12. PURPOSE. AS A RESULT, THIS SOFTWARE IS PROVIDED "AS IS,"
  13. AND YOU THE USER ARE ASSUMING THE ENTIRE RISK AS TO ITS
  14. QUALITY AND PERFORMANCE. IN NO EVENT WILL APPLE BE LIABLE 
  15. FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  16. DAMAGES RESULTING FROM ANY DEFECT IN THE SOFTWARE.
  17.  
  18. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE
  19. AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR
  20. IMPLIED.
  21.  
  22. ************************************************************/
  23.  
  24. /*
  25.  * Under A/UX 2.0 struct video has been "Macintized" and now incorporates
  26.  * a structure called AuxDCE which is defined once and for all in
  27.  * /usr/include/mac. Alas the definition for AuxDCE requires wheeling in
  28.  * lots of Mac stuff including QuickDraw. This is a headache as there are
  29.  * a variety of clashes between X and QuickDraw (they both do windows after
  30.  * all). So we define just what we need here and avoid pulling in the Mac
  31.  * includes. Of course if this ever changes ...
  32.  */
  33.  
  34. #ifndef __OSUTILS__
  35. struct QElem {
  36.     struct QElem *qLink;
  37.     short qType;
  38.     short qData[1];
  39. };
  40.  
  41. typedef struct QElem QElem;
  42.  
  43. typedef QElem *QElemPtr;
  44.  
  45. struct QHdr {
  46.     short qFlags;
  47.     QElemPtr qHead;
  48.     QElemPtr qTail;
  49. };
  50. #define __OSUTILS__
  51. #endif
  52.  
  53. #ifndef __DEVICES__
  54. struct CntrlParam {
  55.         struct QElem *qLink;
  56.         short qType;
  57.         short ioTrap;
  58.         char *ioCmdAddr;
  59.         int (*ioCompletion)();
  60.         short ioResult;
  61.         char *ioNamePtr;
  62.         short ioVRefNum;
  63.         short ioCRefNum;
  64.         short csCode;
  65.         short csParam[11];
  66. };
  67.  
  68. struct DCtlEntry {
  69.         char **dCtlDriver;
  70.         short dCtlFlags;
  71.         struct QHdr dCtlQHdr;
  72.         long dCtlPosition;
  73.         char **dCtlStorage;
  74.         short dCtlRefNum;
  75.         long dCtlCurTicks;
  76.         char *dCtlWindow;
  77.         short dCtlDelay;
  78.         short dCtlEMask;
  79.         short dCtlMenu;
  80.         char dCtlSlot;
  81.         char dCtlSlotId;
  82.         long dCtlDevBase;
  83.         long reserved;
  84.         char dCtlExtDev;
  85.         char fillByte;
  86. };
  87.  
  88. struct AuxDCE {
  89.         char **dCtlDriver;
  90.         short dCtlFlags;
  91.         struct QHdr dCtlQHdr;
  92.         long dCtlPosition;
  93.         char **dCtlStorage;
  94.         short dCtlRefNum;
  95.         long dCtlCurTicks;
  96.         char *dCtlWindow;
  97.         short dCtlDelay;
  98.         short dCtlEMask;
  99.         short dCtlMenu;
  100.         char dCtlSlot;
  101.         char dCtlSlotId;
  102.         long dCtlDevBase;
  103.         long reserved;
  104.         char dCtlExtDev;
  105.         char fillByte;
  106. };
  107.  
  108. #define __DEVICES__
  109. #endif
  110.  
  111. #include <sys/stropts.h>
  112. #include <sys/termio.h>
  113. #include <sys/video.h>
  114. #include <fcntl.h>
  115. #include <sys/ioctl.h>
  116. #include <errno.h>
  117.  
  118. static struct termio d_tio = {
  119.     (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON)&(~IGNBRK)&(~PARMRK)&(~INPCK)&(~INLCR)&
  120.     (~IGNCR)&(~IUCLC)&(~IXANY)&(~IXOFF),
  121.     (OPOST|ONLCR)&(~OLCUC)&(~OCRNL)&(~ONOCR)&(~ONLRET)&(~OFILL)&(~OFDEL),
  122.     (B9600|CS7|CREAD)&(~CSTOPB)&(~PARENB)&(~PARODD)&(~HUPCL)&(~CLOCAL)&(~LOBLK),
  123.     (ISIG|ICANON|ECHO|ECHOE|ECHOK)&(~XCASE)&(~ECHONL)&(~NOFLSH),
  124.     0,
  125.     {CINTR, CQUIT, CERASE, CKILL, CEOF, CNUL, CNUL, CNUL}
  126. };
  127.  
  128. /*
  129.  * Check to see that the server restored the "line" streams module
  130.  * on /dev/console. If so, we'll presume all is well. If not, clear 
  131.  * all stacked modules, push "line", and establish workable stty values.
  132.  */
  133. main()
  134. {
  135.     int fd; int line;
  136.     int iarg;
  137.     struct strioctl ctl;
  138.     char buff[FMNAMESZ+1];
  139.     int errors = 0;
  140.  
  141.     if ((fd = open("/dev/console", O_RDWR)) < 0) {
  142.         printf("Xrepair: can't open /dev/console\n");
  143.     } else if (ioctl(fd, I_FIND, "line") == 0) {
  144. #ifdef CONS_UNDIRECT
  145.             ctl.ic_len = 0;
  146.             ctl.ic_cmd = CONS_UNDIRECT;
  147.             if (ioctl(fd, I_STR, &ctl) < 0) {
  148.                 errors++;
  149.                 printf("Failed to ioctl I_STR CONS_UNDIRECT.\r\n");
  150.             }
  151. #endif
  152.         iarg = 0;
  153.         if (ioctl(fd, FIONBIO, &iarg) < 0) {
  154.         errors++;
  155.         printf("Could not ioctl FIONBIO. \r\n");
  156.         }
  157.         
  158.         iarg = 0;
  159.         if (ioctl(fd, FIOASYNC, &iarg) < 0) {
  160.         errors++;
  161.         printf("Could not ioctl FIOASYNC. \r\n");
  162.         }
  163.         
  164.         if (ioctl(fd, I_FLUSH, FLUSHRW) < 0) {
  165.         errors++;
  166.         printf("Failed to ioctl I_FLUSH FLUSHRW.\r\n");
  167.         }
  168.         
  169.         ctl.ic_len = 0;
  170.         ctl.ic_cmd = VIDEO_NOMOUSE;
  171.         if (ioctl(fd, I_STR, &ctl) < 0) {
  172.         errors++;
  173.         printf("Failed to ioctl I_STR VIDEO_NOMOUSE.\r\n");
  174.         }
  175.         
  176. #ifdef VIDEO_MAC
  177.         ctl.ic_len = 0;
  178.         ctl.ic_cmd = VIDEO_MAC; /* For A/UX 2.0 and later */
  179.         if (ioctl(fd, I_STR, &ctl) < 0) {
  180.             ctl.ic_len = 0;
  181.             ctl.ic_cmd = VIDEO_ASCII; /* A/UX 1.* */
  182.             if (ioctl(fd, I_STR, &ctl) < 0) {
  183.             errors++;
  184.             printf("Failed to ioctl I_STR VIDEO_MAC VIDEO_ASCII.\r\n");
  185.             }
  186.         }
  187. #else
  188.         ctl.ic_len = 0;
  189.         ctl.ic_cmd = VIDEO_ASCII;
  190.         if (ioctl(fd, I_STR, &ctl) < 0) {
  191.         errors++;
  192.         printf("Failed to ioctl I_STR VIDEO_ASCII.\r\n");
  193.         }
  194. #endif
  195.  
  196.         if(ioctl(fd, I_PUSH, "line") < 0) {
  197.         errors++;
  198.         printf("Failed to ioctl I_PUSH.\r\n");
  199.         }
  200.  
  201.         if (ioctl(fd, TCSETA, &d_tio) < 0) {
  202.         errors++;
  203.         printf("Failed to ioctl TCSETA.\r\n");
  204.         }
  205.     }
  206.     exit (errors);
  207. }
  208.