home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / common / ibmUtils.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  6KB  |  254 lines

  1. /*
  2.  * $Id: ibmUtils.c,v 1.1 1991/09/20 18:24:03 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1988,1989
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission 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 AND FITNESS, IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25.  
  26. #include "OSio.h"
  27.  
  28. #include "ibmTrace.h"
  29.  
  30. int ibmTrace ;
  31.  
  32. #ifdef NOT_X
  33. #define ErrorF printf
  34. #endif
  35.  
  36. /***==================================================================***/
  37.  
  38. int ibmQuietFlag = 0 ;
  39.  
  40. /*VARARGS1*/
  41. /*ARGSUSED*/
  42. void
  43. ibmInfoMsg( str, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 )
  44.      char *str ;
  45. {
  46.     if ( !ibmQuietFlag )
  47.     (void) ErrorF( str, arg1, arg2, arg3, arg4, arg5,
  48.               arg6, arg7, arg8, arg9 ) ;
  49.     return ;
  50. }
  51.  
  52. /***==================================================================***/
  53.  
  54. void
  55. ddxGiveUp()
  56. {
  57.     TRACE( ( "ddxGiveUp()" ) ) ;
  58.     OS_CapsLockFeedback( 0 ) ;
  59.     OS_GiveUp() ;
  60.     return ;
  61. }
  62.  
  63. /***==================================================================***/
  64.  
  65. void
  66. AbortDDX()
  67. {
  68.     TRACE( ( "AbortDDX()" ) ) ;
  69. #ifdef IBM_PLX
  70.     p_coldstart();
  71. #endif
  72.     OS_CapsLockFeedback( 0 ) ;
  73.     OS_Abort() ;
  74.     return ;
  75. }
  76.  
  77. /***==================================================================***/
  78.  
  79. /*
  80.  * abort the server when someone calls through a bogus pointer, which
  81.  * was usually initialized by the structure assignment method (xxxData.c)
  82.  */
  83. void
  84. ibmAbort()
  85. {
  86.     extern void abort() ;
  87.  
  88.     ErrorF(
  89.        "ibmAbort: invalid call though function pointer\n... FATAL exiting...\n" ) ;
  90.     abort() ;
  91.     /*NOTREACHED*/
  92. }
  93.  
  94. /***==================================================================***/
  95.  
  96. #ifdef IBM_SPECIAL_MALLOC
  97. #include <stdio.h>
  98. #include <signal.h>
  99.  
  100. int ibmShouldDumpArena = 0 ;
  101. static char *ibmArenaFile = 0 ;
  102.  
  103. static
  104. ibmMarkDumpArena()
  105. {
  106.     ibmShouldDumpArena = 1 ;
  107.     return 0;
  108. }
  109.  
  110. ibmDumpArena()
  111. {
  112. FILE  *mfil;
  113. static    char    fileName[100];
  114. static    int    dumpNum= 0;
  115.  
  116.    (void) sprintf( fileName, ibmArenaFile, dumpNum++ ) ;
  117.    mfil = fopen( fileName, "a" ) ;
  118.    if ( !mfil ) {
  119.     ErrorF( "Couldn't open %s to dump arena, ignored\n", fileName ) ;
  120.     return 0 ;
  121.    }
  122.    else {
  123.     ErrorF( "Dumping malloc arena to %s\n", fileName ) ;
  124.     plumber( mfil ) ;
  125.     (void) fflush( mfil ) ;
  126.     (void) fclose( mfil ) ;
  127.    }
  128.    ibmShouldDumpArena = 0 ;
  129.    return 1 ;
  130. }
  131.  
  132. ibmNoteHit()
  133. {
  134. static int old= 4;
  135.  
  136.    ErrorF("received SIGTERM\n");
  137.    old= SetMallocCheckLevel(old);
  138.    return 1 ;
  139. }
  140.  
  141. int
  142. ibmSetupPlumber( name )
  143. register char *name ;
  144. {
  145. extern exit() ;
  146.  
  147.     ibmInfoMsg( "Setting up plumber to dump to %s\n", name ) ;
  148.     (void) unlink( ibmArenaFile = name ) ;
  149.     (void) signal( SIGUSR1, ibmMarkDumpArena ) ;
  150. #if !defined(AIXrt)
  151.     (void) signal( SIGEMT, ibmDumpArena ) ;
  152. #endif
  153.     (void) signal( SIGTERM, ibmNoteHit ) ;
  154.     (void) signal( SIGUSR2, exit ) ;
  155.     return 1 ;
  156. }
  157.  
  158. #endif /* IBM_SPECIAL_MALLOC */
  159.  
  160. /***==================================================================***/
  161. /* Debugging Aids */
  162. /* print_pattern() & print_event() are just for debugging */
  163. #if defined(DEBUG) && !defined(NDEBUG)
  164.  
  165. /* these don't work with AIX compiler */
  166. /* #if !defined(AIXrt) && !defined(AIXps2) && !defined(IBM_OS_HAS_HFT) */
  167. #if !defined(AIXrt) 
  168. #define PUT_BIT(d,b)   (((d)&(((unsigned)1)<<(b)))?ErrorF("*"):ErrorF("."))
  169.  
  170. void
  171. print_pattern(width,height,data)
  172. int    width,height;
  173. char    *data;
  174. {
  175. char    *tmp=data;
  176. int    row,bit;
  177. unsigned data_byte;
  178. int    bits_left;
  179.  
  180.     TRACE(("print_pattern( width= %d, height= %d, data= 0x%x )\n",
  181.         width,height,data));
  182.  
  183.     for (row=0;row<height;row++) {
  184.     ErrorF("0x");
  185.     for (bit=0;bit<(width+7)/8;bit++) {
  186.        ErrorF("%02x",*tmp++);
  187.     }
  188.     ErrorF("\n");
  189.     }
  190.     for (row=0;row<height;row++) {
  191.     for (bits_left=width;bits_left>0;bits_left-=8) {
  192.         data_byte= *data++;
  193.         for (bit=7;bit>=(bits_left>8?0:8-bits_left);bit--) {
  194.         PUT_BIT(data_byte,bit);
  195.         }
  196.     }
  197.     ErrorF("\n");
  198.     }
  199.     return;
  200. }
  201.  
  202. /***==================================================================***/
  203.  
  204. #ifdef IBM_OS_HAS_X_QUEUE
  205.  
  206. /*
  207. #include "X.h"
  208. #include "cursorstr.h"
  209. #include "miscstruct.h"
  210. #include "scrnintstr.h"
  211.  
  212. #include "ibmScreen.h"
  213. */
  214.  
  215. #include "OSio.h"
  216.  
  217. /* SORRY, This just doesn't work anymore ( and I don't know why ! ) *
  218. void
  219. print_event(xE)
  220. XEvent    *xE;
  221. {
  222.  
  223.     TRACE(("print_event( xE= 0x%x )\n",xE));
  224.  
  225.     ErrorF("Event(%d,%d): ",xE->xe_x,xE->xe_y);
  226.     switch (xE->xe_device) {
  227.     case XE_MOUSE:        ErrorF("mouse "); break;
  228.     case XE_DKB:        ErrorF("keyboard "); break;
  229.     case XE_TABLET:        ErrorF("tablet "); break;
  230.     case XE_AUX:        ErrorF("aux "); break;
  231.     case XE_CONSOLE:    ErrorF("console "); break;
  232.     default:        ErrorF("unknown(%d) ",xE->xe_device); break;
  233.     }
  234.     if (xE->xe_type==XE_BUTTON) {
  235.     ErrorF("button ");
  236.     if    (xE->xe_direction==XE_KBTUP)    ErrorF("up ");
  237.     else if    (xE->xe_direction==XE_KBTDOWN)    ErrorF("down ");
  238.     else if    (xE->xe_direction==XE_KBTRAW)    ErrorF("raw ");
  239.     else             ErrorF("unknown(%d) ",xE->xe_direction);
  240.     ErrorF("(key= %d)",xE->xe_key);
  241.     }
  242.     else if (xE->xe_type==XE_MMOTION)    ErrorF("MMOTION");
  243.     else if (xE->xe_type==XE_TMOTION)    ErrorF("TMOTION");
  244.     ErrorF("\n");
  245.     return;
  246. }
  247.  * SORRY, This just doesn't work anymore ( and I don't know why ! ) */
  248.  
  249. #endif /* IBM_OS_HAS_X_QUEUE */
  250.  
  251. #endif /* !AIXrt */
  252.  
  253. #endif /* Debugging Aids */
  254.