home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / common / ibmUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  6.1 KB  |  248 lines

  1. /*
  2.  * $XConsortium: ibmUtils.c,v 1.2 91/07/16 13:10:58 jap Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989,1990,1991
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * License to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND 
  18.  * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
  19.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23.  * SOFTWARE.
  24.  *
  25. */
  26.  
  27. #include "X.h"
  28. #include "cursorstr.h"
  29. #include "miscstruct.h"
  30. #include "scrnintstr.h"
  31.  
  32. #include "ibmScreen.h"
  33. #include "OSio.h"
  34. #include "ibmTrace.h"
  35.  
  36. #ifdef TRACE_X
  37. int    ibmTrace ;
  38. int    ibmTraceSync ;
  39. #endif
  40.  
  41. int ibmQuietFlag = 0 ;
  42.  
  43. void
  44. ibmInfoMsg( str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 )
  45. char *str ;
  46. {
  47. if ( !ibmQuietFlag )
  48.     (void) ErrorF( str, arg1, arg2, arg3, arg4, arg5,
  49.                arg6, arg7, arg8, arg9 ) ;
  50. return ;
  51. }
  52.  
  53. /***==================================================================***/
  54.  
  55.     /* 
  56.      * XXX!!! HACK HACK HACKITY HACK HACK!!!
  57.      * 11/4/88 (ef) -- when the server exits, it first kills any active
  58.      * clients, which will paint the root window background where they
  59.      * used to be.  This has a nasty tendency to write on the currently
  60.      * active hft.   Rather than doing something clever to notice
  61.      * that we are inactive when repainting the background, we just
  62.      * exit the server because we "know" that no more real cleanup
  63.      * need be done.
  64.      */
  65.  
  66. static void
  67. ibmAbortInactiveScreens()
  68. {
  69. int    scrn;
  70.     TRACE(("ibmAbortInactiveScreens()\n"));
  71.     for (scrn = 0; scrn < ibmNumScreens; scrn++) {
  72.     if (ibmScreenState(scrn)!=SCREEN_ACTIVE) {
  73.         exit(0);
  74.     }
  75.     }
  76.     return;
  77. }
  78.  
  79. /***==================================================================***/
  80.  
  81. void
  82. ddxGiveUp()
  83. {
  84.  
  85.     TRACE(("ddxGiveUp()"));
  86.  
  87. #ifdef AIXV3
  88.     rcmGiveUp();
  89.     OS_GiveUp();
  90.     ibmAbortInactiveScreens();
  91. #endif
  92.  
  93. #ifdef AIXps2
  94.     OS_CapsLockFeedback(0);    
  95.     OS_GiveUp();
  96. #endif
  97.  
  98.     return;
  99. }
  100.  
  101. /*
  102.  * abort the server when someone calls through a bogus pointer, which
  103.  * was usually initialized by the structure assignment method (xxxData.c)
  104.  */
  105.  
  106. void
  107. ibmAbort()
  108. {
  109. extern void abort() ;
  110.  
  111.     ErrorF(
  112.    "ibmAbort: invalid call though function pointer\n... FATAL exiting...\n" ) ;
  113.     abort() ;
  114.     /*NOTREACHED*/
  115. }
  116.  
  117. /***==================================================================***/
  118.  
  119. void
  120. AbortDDX()
  121. {
  122.     TRACE(("AbortDDX()"));
  123.  
  124. #ifdef AIXV3
  125.     OS_Abort();
  126.     ibmAbortInactiveScreens();
  127. #endif
  128. #ifdef AIXps2
  129.     OS_CapsLockFeedback(0) ;
  130.     OS_Abort();
  131. #endif
  132.  
  133.     return;
  134. }
  135.  
  136. ddxUseMsg()
  137. {
  138. int    i;
  139.  
  140.     TRACE(("ddxUseMsg()\n"));
  141. #ifdef AIXV3
  142.     AIXUseMsg();
  143. #else
  144.     ErrorF("    -D string    color database file \n");
  145.     ErrorF("    -c #        key-click volume (0-100)\n");
  146.     ErrorF("Recognized screens are:\n");
  147.     ErrorF("    -all        opens all attached, supported screens\n");
  148.     for (i=0;(ibmPossibleScreens[i]!=NULL);i++) {
  149.     ErrorF("    %s\n",ibmPossibleScreens[i]->ibm_ScreenFlag);
  150.     }
  151.     ErrorF("Other device dependent options are:\n");
  152.     ErrorF("    -bs        turn on backing store for windows that request it\n");
  153.     ErrorF("    -D <file>    specify color database file\n");
  154. #if defined(IBM_GSL)
  155.     ErrorF("    -dd <dev>    specify a default display for GSL\n");
  156. #endif /* defined(IBM_GSL) */
  157. #ifdef IBM_SPECIAL_MALLOC
  158.     ErrorF("    -malloc #    set malloc check level (0-5)\n");
  159. #endif
  160.     ErrorF("    -n :num        specify connection number (0-255)\n");
  161.     ErrorF("    -nobs        always deny backing store\n");
  162.     ErrorF("    -nohdwr        use generic functions where applicable\n");
  163.     ErrorF("    -pckeys        swap CAPS LOCK and CTRL (for touch typists)\n");
  164. #ifdef IBM_SPECIAL_MALLOC
  165.     ErrorF("    -plumber string    dump malloc arena to named file\n");
  166. #endif
  167.     ErrorF("    -quiet        do not print informational messages\n");
  168.     ErrorF("    -rtkeys        use CAPS LOCK and CTRL as labelled\n");
  169.     ErrorF("    -T        disable CTRL-ALT_BACKSPACE key sequence\n");
  170. #ifdef TRACE_X
  171.     ErrorF("    -trace        trace execution of IBM specific functions\n");
  172. #endif
  173.     ErrorF("    -verbose    print informational messages\n");
  174.     ErrorF("    -wrap        wrap mouse in both dimensions\n");
  175.     ErrorF("    -wrapx        wrap mouse in X only\n");
  176.     ErrorF("    -wrapy        wrap mouse in Y only\n");
  177.     ErrorF("See Xibm(1) for a more complete description\n");
  178. #endif
  179. }
  180.  
  181. /***==================================================================***/
  182.  
  183. #ifdef IBM_SPECIAL_MALLOC
  184. #include <stdio.h>
  185. #include <signal.h>
  186.  
  187. int    ibmShouldDumpArena= 0;
  188. static    char    *ibmArenaFile= 0;
  189.  
  190. static
  191. ibmMarkDumpArena()
  192. {
  193.  
  194.     (void) signal( SIGUSR1, ibmMarkDumpArena ) ;
  195.     ibmShouldDumpArena= 1;
  196.  
  197.     return 0;
  198. }
  199.  
  200. ibmDumpArena()
  201. {
  202. FILE  *mfil;
  203. static    char    fileName[100];
  204. static    int    dumpNum= 0;
  205.  
  206.    (void) signal( SIGUSR2, ibmDumpArena ) ;
  207.    (void) sprintf(fileName,ibmArenaFile,dumpNum++);
  208.  
  209.    mfil= fopen(fileName,"a");
  210.    if (!mfil) {
  211.     ErrorF("Couldn't open %s to dump arena, ignored\n",fileName);
  212.     return 0 ;
  213.    }
  214.    else {
  215.     ErrorF("Dumping malloc arena to %s\n",fileName);
  216.     plumber(mfil);
  217.     (void) fflush(mfil);
  218.     (void) fclose(mfil);
  219.    }
  220.    ibmShouldDumpArena= 0;
  221.    return 1 ;
  222. }
  223.  
  224. ibmNoteHit()
  225. {
  226. static int old= 4;
  227.  
  228.    ErrorF("received SIGTERM\n");
  229.    old= SetMallocCheckLevel(old);
  230.    return 1 ;
  231. }
  232.  
  233. int
  234. ibmSetupPlumber( name )
  235. register char *name ;
  236. {
  237. extern exit() ;
  238.  
  239.     ibmInfoMsg( "Setting up plumber to dump to %s\n", name ) ;
  240.     (void) unlink( ibmArenaFile = name ) ;
  241.     (void) signal( SIGUSR1, ibmMarkDumpArena ) ;
  242.     (void) signal( SIGUSR2, ibmDumpArena ) ;
  243.     (void) signal( SIGTERM, ibmNoteHit ) ;
  244.     return 1 ;
  245. }
  246.  
  247. #endif /* IBM_SPECIAL_MALLOC */
  248.