void FAR
ScrnMonitor(void)
{
   /* Signal starter we're here. */
   DosSemClear(&pSharedseg->semStartup);

   /* Remember what session to monitor, and check we haven't already
    * switched. This is to handle timing problems that may result in
    * trying to monitor PM or DOS sessions.
    */
   sgMonitor = pGInfo -> sgCurrent;

   if (sgMonitor == SESS_DOS || sgMonitor == SESS_PM) {
      /* Hm, this is a session we don't monitor.
       * If we are blanked, indicate some event occurred;
       * this will unblank the screen.  That is probably what we want,
       * since otherwise we end up with no monitor running and with
       * no way to unblank. */
      if (pSharedseg->bBlanked)
         DosSemClear(&pSharedseg->semAction);
      DosExit(EXIT_THREAD, 0);
   }

   /*
    * If we have a mouse, start a separate thread to monitor it.
    */
   if (pSharedseg -> bMouse)
      StartThread("MOUSE$");

   /* Continue here to monitor the keyboard. */
   MonitorThread("KBD$");
}
Ejemplo n.º 2
0
static void
mousehandler()
{
    for (;;) {
	MOUEVENTINFO	m;
	unsigned short	status;
	clock_t		start;

#if 0
	if (MouGetDevStatus((PUSHORT) &status, mousenum) != 0
	    ||
	    (status & (MOUSE_UNSUPPORTED_MODE | MOUSE_DISABLED))
	) {
	    hidemouse();
	    (void) MouClose(mousenum);
	    DosExit(EXIT_THREAD, 0);
	}
#endif
	status = MOU_WAIT;
	MouReadEventQue((PMOUEVENTINFO) &m, (PUSHORT) &status, mousenum);
	/*
	 * If we don't get the control semaphore immediately,
	 * we do nothing. Delayed responses to mouse button
	 * presses could be confusing.
	 */
#if 0
	start = clock();
#endif
	if (DosSemRequest(control, SEM_IMMEDIATE_RETURN) != 0)
	    continue;
#if 0
	if (clock() != start) {
	    (void) fprintf(stderr, "mouse thread: %d\n", __LINE__);
	    DosSemClear(control);
	    continue;
	}
#endif
	/*
	 * Start of critical section.
	 */
	if (++keystrokes >= PSVKEYS)
	    lastevent = clock();
	if (State == NORMAL &&
		(m.fs & (MOUSE_BN1_DOWN | MOUSE_BN2_DOWN | MOUSE_BN3_DOWN))) {
	    hidemouse();
	    mouseclick(m.row, m.col);
	    showmouse();
	}
	/*
	 * End of critical section.
	 */
	DosSemClear(control);
    }
}
Ejemplo n.º 3
0
VOID APIENTRY StopApplication( VOID )
{
    StopBuff.Cmd = DBG_C_Stop;
    Call32BitDosDebug( &StopBuff );
    DosSemClear( &StopDoneSem );
    DosExit( 0, 0 );
}
Ejemplo n.º 4
0
static void _Far16 _Cdecl
#else /* !__32BIT__ */
static void _far _loadds
#endif /* __32BIT__ */
NCBPost(USHORT Junk, PNCB16 Ncb)
{
  DosSemClear(&Ncb -> basic_ncb.ncb_semaphore);
}
Ejemplo n.º 5
0
unsigned OnAnotherThreadSimpAccess( unsigned in_len, in_data_p in_data, unsigned out_len, out_data_p out_data )
{
    unsigned    result;

    if( !ToldWinHandle || IsTrapFilePumpingMessageQueue() ) {
        return( TrapSimpAccess( in_len, in_data, out_len, out_data ) );
    } else {
        DosSemClear( &PumpMessageSem );
        result = TrapSimpAccess( in_len, in_data, out_len, out_data );
        WinPostMsg( GUIGetSysHandle( WndGui( WndMain ) ), WM_QUIT, 0, 0 );
        DosSemWait( &PumpMessageDoneSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageDoneSem );
        return( result );
    }
}
Ejemplo n.º 6
0
unsigned OnAnotherThread( unsigned(*rtn)(unsigned,void *,unsigned,void *), unsigned in_len, void *in, unsigned out_len, void *out )
{
    unsigned    result;

    if( !ToldWinHandle || IsTrapFilePumpingMessageQueue() ) {
        return( rtn( in_len, in, out_len, out ) );
    } else {
        DosSemClear( &PumpMessageSem );
        result = rtn( in_len, in, out_len, out );
        WinPostMsg( GUIGetSysHandle( WndGui( WndMain ) ), WM_QUIT, 0, 0 );
        DosSemWait( &PumpMessageDoneSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageDoneSem );
        return( result );
    }
}
Ejemplo n.º 7
0
static VOID APIRET DoDebugRequests( VOID )
{
    for( ;; ) {
        DosSemWait( &DebugReqSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &DebugReqSem );
        InDosDebug = TRUE;
        DebugReqResult = Call32BitDosDebug( DebugReqBuff );
        InDosDebug = FALSE;
        if( IsPMDebugger() ) {
            WinPostMsg( HwndDebugger, WM_QUIT, 0, 0 );
        } else {
            DosSemClear( &DebugDoneSem );
        }
    }
}
Ejemplo n.º 8
0
unsigned OnAnotherThreadAccess( trap_elen in_num, in_mx_entry_p in_mx, trap_elen out_num, mx_entry_p out_mx )
{
    unsigned    result;

    if( !ToldWinHandle || IsTrapFilePumpingMessageQueue() ) {
        return( TrapAccess( in_num, in_mx, out_num, out_mx ) );
    } else {
        DosSemClear( &PumpMessageSem );
        result = TrapAccess( in_num, in_mx, out_num, out_mx );
        WinPostMsg( GUIGetSysHandle( WndGui( WndMain ) ), WM_QUIT, 0, 0 );
        DosSemWait( &PumpMessageDoneSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageDoneSem );
        return( result );
    }
}
VOID main(VOID)
{
   USHORT usReturn_Code;           /*  Dos function Return Code              */

   PSZ    pszName = SHARENAME;              /*  Shareable memory block name  */
   SEL    selMem_Selector;                  /*  Receive Segment selector     */

   PSZ     pszSemName = SEMNAME;            /*  System semaphore name        */
   HSEM    hsemSemHandle;                   /*  System semaphore Handle      */

   WATCH FAR * Watch_Ptr;          /*  WATCH pointer                         */

                                   /* Get Access to Shareable memory Block   */
   usReturn_Code = DosGetShrSeg(pszName, & selMem_Selector);

   if (usReturn_Code == 0) {
      Watch_Ptr = (WATCH FAR *) MAKEP(selMem_Selector,0);

      DosOpenSem( & hsemSemHandle,          /*  Open System semaphore        */
                  pszSemName);

      DosSemRequest(hsemSemHandle,          /*  Waits for shared resources   */
                    SEM_INDEFINITE_WAIT);

                            /* Restore Init value count if WATCHDOG enabled  */
      if (Watch_Ptr->Flag & ENABLE_MASK)
         Watch_Ptr->Counter = Watch_Ptr->Counter_Init_Value ;

      DosSemClear(hsemSemHandle);             /*  Release  shared resources  */

      DosFreeSeg(selMem_Selector);            /*  Freeing Shared memory      */

   } else {
      DosBeep(262,250);DosBeep(330,250);DosBeep(392,250);DosBeep(494,250);
      DosBeep(392,250);DosBeep(330,250);DosBeep(262,250);

#ifdef DEBUG
      printf("\n -*-*- STARTTPS Error Code %04x -*-*-\n",usReturn_Code);
      printf("  -*-    WatchDog not Started    -*-\n");
#endif

   } /* endif */

   DosExit((USHORT) 0,usReturn_Code);         /*  Exit Process              */

} /* end of main program */
Ejemplo n.º 10
0
void RemoteUnLink( void )
{
#ifdef SERVER
    ServerDie = DIE_WANT;
#endif
    IpxCloseSocket( IPXSocket );
#ifdef SERVER
    DosSemClear( &BroadCastStop );
    if( InUse( ConnECB ) ) {
        SpxCancelPacket( &ConnECB );
    }
    while( ServerDie != (DIE_WANT|DIE_BROADCAST|DIE_RESPOND) )  {
        IPXRelinquishControl();
    }
#endif
    SpxCloseSocket( SPXSocket );
}
Ejemplo n.º 11
0
/*
 * This function handles automatic buffer preservation. It runs in its
 * own thread, which is only awake when keystrokes >= PSVKEYS and the
 * main thread is waiting for keyboard input. Even then, it spends
 * most of its time asleep.
 */
static void FAR
psvhandler()
{
    for (;;) {
	long	sleeptime;

	DosSemWait(psvsema, SEM_INDEFINITE_WAIT);
	DosSemRequest(control, SEM_INDEFINITE_WAIT);
	/*
	 * Start of critical section.
	 */
	if (keystrokes < PSVKEYS) {
	    sleeptime = 0;
	    /*
	     * If we haven't had at least PSVKEYS
	     * keystrokes, psvsema should be set.
	     */
	    DosSemSet(psvsema);
	} else if ((sleeptime = (long) Pn(P_preservetime) * 1000 -
		      CLK2MS(clock() - lastevent)) <= 0) {
	    /*
	     * If Pn(P_presevetime) seconds haven't yet
	     * elapsed, sleep until they should have - but
	     * NOT within the critical section (!).
	     *
	     * Otherwise do automatic preserve.
	     *
	     * exPreserveAllBuffers() should reset keystrokes to 0.
	     */
	    (void) exPreserveAllBuffers();
	    sleeptime = 0;
	}
	/*
	 * End of critical section.
	 */
	DosSemClear(control);
	/*
	 * Sleep if we have to.
	 */
	if (sleeptime != 0)
	    DosSleep(sleeptime);
    }
}
Ejemplo n.º 12
0
static void _WCFAR begin_thread_helper( void )
/********************************************/
{
    thread_fn   *_rtn;
    void        _WCFAR *_arg;
    thread_data my_thread_data;

    if( *_threadid > __MaxThreads ) return;
    /* save a copy of the global variables so we can clear the semaphore */
    _rtn = Routine;
    _arg = Argument;
    memset( &my_thread_data, 0, sizeof( thread_data ) );
    my_thread_data.__randnext = 1;
    __ThreadData[*_threadid] = &my_thread_data;
    _STACKLOW = FP_OFF( StackBottom );
    DosSemClear( &data_sem );
    (*_rtn)( _arg );
    _endthread();
}
Ejemplo n.º 13
0
_WCRTLINK void __CloseSemaphore( semaphore_object *obj )
{
#if defined( __RUNTIME_CHECKS__ ) && defined( _M_IX86 )
    // 0 is ok
    // 1 is ok  // JBS I don't think so. I would mean a critical section is active.
                // JBS For every lock, there should be an unlock.
//    if( obj->count >= 2 ) {
//        __fatal_runtime_error( "Semaphore locked too many times", 1 );
//    }
    if( obj->count >= 1 ) {
        __fatal_runtime_error( "Semaphore not unlocked", 1 );
    }
#endif
#if !defined( __NT__ )
  #if defined( _M_I86 )
    if( obj->count > 0 ) {
        DosSemClear( &obj->semaphore );
    }
  #else
    if( obj->initialized != 0 ) {
    #if defined( __NETWARE__ )
        obj->semaphore = 0;
    #elif defined( __QNX__ )
        __qsem_destroy( &obj->semaphore );
    #elif defined( __LINUX__ )
        // TODO: Close the semaphore for Linux!
    #elif defined( __RDOS__ )
        RdosDeleteSection( obj->semaphore );
        obj->semaphore = 0;
    #elif defined( __RDOSDEV__ )
    #else
        DosCloseMutexSem( obj->semaphore );
    #endif
    }
  #endif
    obj->initialized = 0;
    obj->owner = 0;
    obj->count = 0;
#endif
}
Ejemplo n.º 14
0
void __far Reader( void )
{
    int         data;
    USHORT      read;
    int         new_index;

    OverRun = FALSE;
    for( ;; ) {
        DosRead( ComPort, &data, 1, &read );
        if( read == 1 ) {
            new_index = ReadBuffAdd + 1;
            new_index &= BSIZE-1;
            if( new_index == ReadBuffRemove ) {
                OverRun = TRUE;
            } else {
                ReadBuff[ ReadBuffAdd ] = data;
                ReadBuffAdd = new_index;
            }
            DosSemClear( &ReadSemaphore );
        }
    }
}
Ejemplo n.º 15
0
static void far Broadcast( void )
{
    _INITIPXECB( SAP );
    FillArray( SAPHead.destNode, 0xff );
    SAPHead.destSocket = SAP_SOCKET;
    SAPHead.infoType = _SWAPINT( 0x2 );
    SAPHead.serverType = DBG_SERVER_TYPE;
    IpxGetInternetworkAddress( (PUCHAR)&SAPHead.addrNet );
    SAPHead.addrSocket = IPXSocket;
    SAPHead.intermediateNetworks = _SWAPINT( 0x1 );
    AssignArray( SAPECB.immediateAddress, SAPHead.destNode );
    for( ;; ) {
        IpxSend( IPXSocket, &SAPECB );
        DosSemClear( &BroadCastStart );
        DosSemWait( &BroadCastStop, 60000 );
        if( ServerDie ) {
            SAPHead.intermediateNetworks = _SWAPINT( 0x10 );
            IpxSend( IPXSocket, &SAPECB );
            ServerDie |= DIE_BROADCAST;
            DosExit( EXIT_THREAD, 0 );
        }
    }
}
Ejemplo n.º 16
0
_WCRTLINK void __ReleaseSemaphore( semaphore_object *obj )
{
    TID tid;

    tid = GetCurrentThreadId();
#if defined( _NETWARE_CLIB )
    if( tid == 0 )
        return;
#endif
    if( obj->count > 0 ) {
        if( obj->owner != tid ) {
            __fatal_runtime_error( "Semaphore unlocked by wrong owner", 1 );
        }
        if( --obj->count == 0 ) {
            obj->owner = 0;
#if defined( _M_I86 )
            DosSemClear( &obj->semaphore );
#else
  #if defined( __NETWARE__ )
            obj->semaphore = 0;
  #elif defined( __NT__ )
            LeaveCriticalSection( obj->semaphore );
  #elif defined( __QNX__ )
            __qsem_post( &obj->semaphore );
  #elif defined( __LINUX__ )
            // TODO: Relase semaphore under Linux!
  #elif defined( __RDOS__ )
            RdosLeaveSection( obj->semaphore );
  #elif defined( __RDOSDEV__ )
            RdosLeaveKernelSection( &obj->semaphore );
  #else
            DosReleaseMutexSem( obj->semaphore );
  #endif
#endif
        }
    }
}
Ejemplo n.º 17
0
VOID PumpMessageQueue( VOID )
{
    char        class_name[80];
    QMSG        qmsg;
    ERRORID     err;

    for( ;; ) {
        DosSemWait( &PumpMessageSem, SEM_INDEFINITE_WAIT );
        DosSemSet( &PumpMessageSem );
        WinThreadAssocQueue( GUIGetHAB(), GUIPMmq );
        while( WinGetMsg( GUIGetHAB(), &qmsg, 0L, 0, 0 ) ) {
            WinQueryClassName( qmsg.hwnd, sizeof( class_name ), class_name );
            if( strcmp( class_name, "GUIClass" ) == 0 ||
                strcmp( class_name, "WTool" ) == 0 ) {
                WinDefWindowProc( qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2 );
            } else {
                WinDispatchMsg( GUIGetHAB(), &qmsg );
            }
        }
        WinThreadAssocQueue( GUIGetHAB(), NULL );
        err = WinGetLastError( GUIGetHAB() );
        DosSemClear( &PumpMessageDoneSem );
    }
}
Ejemplo n.º 18
0
/*
*  unlockncbpool - unlock pool of async ncbs for use by another thread
*/
void
unlockncbpool(void)
{
#ifndef REALMODE
#ifdef OS2
  register int rc;

  if (rc = DosSemClear((unsigned long FAR *) &async_ncb_pool_sem))
    {
#ifdef DEBUG
      fprintf(stderr, "Bad semaphore clear (%d)\n", rc);
#endif
      exit ( rc );
    }
#else	    // NT

    if ( !ReleaseSemaphore ( async_ncb_pool_sem, 1, NULL )) {
	fprintf(stderr, "Semaphore clear failed (%d)\n", GetLastError() );
	exit ( GetLastError() );
    }

#endif
#endif
}
Ejemplo n.º 19
0
_WCRTLINK int _WCFAR _beginthread( thread_fn *start_address,
                            void _WCFAR *stack_bottom,
                            unsigned stack_size,
                            void _WCFAR *arglist )
/*****************************************************/
{
    TID         tid;
    APIRET      rc;

    DosSemRequest( &data_sem, -1L );
    Routine = start_address;
    Argument = arglist;
    StackBottom = stack_bottom;
    rc = DosCreateThread( begin_thread_helper, (PTID)&tid,
                          (PBYTE)((char _WCFAR *)stack_bottom + stack_size) );
    if( rc != 0 ) {
        DosSemClear( &data_sem );
        return( -1 );
    }
    if( tid > __MaxThreads ) {
        return( -1 );
    }
    return( tid );
}
Ejemplo n.º 20
0
VOID FAR PMfrThread (VOID)
     {
     int sub_rc;

     habThread = WinInitialize(0);

     WinGetLastError(habThread);

   /* get the memory DC */
   cp.hdcMemory = DevOpenDC (habThread, OD_MEMORY, "*", 0L, NULL, NULL) ;
   /* this says that we don't have a PS yet; not one to destroy */
   cp.hpsMemory = (HPS) NULL;

     /* let each sub-driver have a crack at it now */
     PrintDriverInit();
     CalcDriverInit();

     /* Initialization here is done.
        Post main thread that we are going to work
     */

     WinPostMsg(cp.hwnd, WM_THRD_POST,
                MPFROM2SHORT(SUB_INIT_DONE, 0),
                MPFROMP(NULL) );

     for (;;)
          {  /* wait for something to do */
          DosSemWait (&cp.ulSemTrigger, SEM_INDEFINITE_WAIT) ;

          /* take an early exit for Shutdown */
          if (cp.sSubAction == SUB_ACT_TERM)
             break;

          /* posted out of wait.  do something */

          switch(cp.sSubAction)
                {
                case SUB_ACT_CALC:
                     sub_rc = CalcDriver();
                     break;
                case SUB_ACT_PRINT:
                     sub_rc = PrintDriver();
                     break;
                case SUB_ACT_SAVE:
                     sub_rc = SaveDriver();
                     break;
                case SUB_ACT_LOAD:
                     sub_rc = LoadDriver();
                     break;
                default:
                     sub_rc = 0x9999;   /* let the main task figure it out */
                     break;
                }

          /* test here for shutdown also */
          if (cp.sSubAction == SUB_ACT_TERM)
              break;

          /* not shutdown. */
          /* indicate ready for the next cycle */
          DosSemSet (&cp.ulSemTrigger) ;
          WinPostMsg (cp.hwnd, WM_THRD_POST, MPFROM2SHORT(sub_rc, 0) ,
                         MPFROMP(NULL) ) ;
          }

      /* shutdown has been triggered.
         release resources obtained by us.

         NOTE: Serialize using DosEnterCritSec so that
         the main thread is dormant until we get everything
         cleaned up and go away.  The main thread will be
         re-dispatched following our final DosExit.
      */

      DosEnterCritSec();

      if (cp.hpsMemory != (HPS) 0)
         {  /* protection from a failed WM_CREATE or IDM_GO */
         GpiSetBitmap(cp.hpsMemory, (HBITMAP) NULL);
         GpiDestroyPS(cp.hpsMemory);
         GpiDeleteBitmap (cp.hbmMemory);
         }
      cp.hpsMemory = (HPS) 0;

      if ( cp.pixels != NULL)
         hfree(cp.pixels);
      cp.pixels = NULL;

      if (cp.hdcMemory != (HDC) 0)
         DevCloseDC (cp.hdcMemory);
      cp.hdcMemory = (HDC) 0;

      /* say good-bye to PM */
      WinTerminate(habThread);

      /* flag we done */
      DosSemClear ((HSEM) &cp.ulSemSubEnded);
      /* and go away */
      DosExit(EXIT_THREAD, 0);

      }
Ejemplo n.º 21
0
unsigned int CallDosDebug( dos_debug __far *buff )
{
    QMSG        qmsg;
    int         num_paints;
    int         i;
    struct {
        RECTL   rcl;
        HWND    hwnd;
    }           paints[MAX_PAINTS];
    HPS         ps;
    char        class_name[80];
    TID         tid;

    if( !IsPMDebugger() ) {
        return( Call32BitDosDebug( buff ) );
    }

    switch( buff->Cmd ) {
    case DBG_C_ClearWatch:
    case DBG_C_Freeze:
    case DBG_C_LinToSel:
    case DBG_C_NumToAddr:
    case DBG_C_ReadCoRegs:
    case DBG_C_ReadMemBuf:
    case DBG_C_ReadMem_D:
    case DBG_C_ReadReg:
    case DBG_C_SelToLin:
    case DBG_C_SetWatch:
    case DBG_C_ThrdStat:
    case DBG_C_WriteCoRegs:
    case DBG_C_WriteMemBuf:
    case DBG_C_WriteMem_D:
    case DBG_C_WriteReg:
        return( Call32BitDosDebug( buff ) );
    }
    switch( buff->Cmd ) {
    case DBG_C_Go:
    case DBG_C_SStep:
    case DBG_C_Term:
        ReleaseQueue( buff->Pid, buff->Tid );
    }
    DebugReqBuff = buff;
    StopBuff = *buff;
    DosSemSet( &DebugDoneSem );
    DosSemClear( &DebugReqSem );
    num_paints = 0;
    if( IsPMDebugger() ) {
        while( WinGetMsg( HabDebugger, &qmsg, 0L, 0, 0 ) || InDosDebug ) {
            WinQueryClassName( qmsg.hwnd, MAX_CLASS_NAME, class_name );
            switch( qmsg.msg ) {
            case WM_CHAR:
                if( ( SHORT1FROMMP( qmsg.mp1 ) & KC_VIRTUALKEY ) &&
                    ( SHORT2FROMMP( qmsg.mp2 ) == VK_BREAK ) ) {
                    SetBrkPending();
                    DosCreateThread( StopApplication, &tid, stack2 + STACK_SIZE );
                    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 10, tid );
                    WakeThreads( StopBuff.Pid );
                    DosSemWait( &StopDoneSem, SEM_INDEFINITE_WAIT );
                    DosSemSet( &StopDoneSem );
                }
                break;
            case WM_COMMAND:
                CantDoIt();
                break;
            default:
                if( strcmp( class_name, "GUIClass" ) == 0 ||
                    strcmp( class_name, "WTool" ) == 0 ) {
                    switch( qmsg.msg ) {
                    case WM_PAINT:
                        if( num_paints >= MAX_PAINTS ) --num_paints;
                        paints[num_paints].hwnd = qmsg.hwnd;
                        ps = WinBeginPaint( qmsg.hwnd, 0, &paints[ num_paints ].rcl );
                        GpiErase( ps );
                        WinEndPaint( ps );
                        num_paints++;
                        break;
                    case WM_BUTTON1DOWN:
                    case WM_BUTTON2DOWN:
                    case WM_BUTTON3DOWN:
                        CantDoIt();
                        break;
                    case WM_MOUSEMOVE:
                    {
                        HPOINTER hourglass = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE );
                        if( WinQueryPointer( HWND_DESKTOP ) != hourglass ) {
                            WinSetPointer( HWND_DESKTOP, hourglass );
                        }
                        break;
                    }
                    default:
                        WinDefWindowProc( qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2 );
                    }
                } else {
                    WinDispatchMsg( HabDebugger, &qmsg );
                }
            }
        }
    } else {
        DosSemWait( &DebugDoneSem, SEM_INDEFINITE_WAIT );
    }
    switch( buff->Cmd ) {
    case DBG_N_Exception:
    case DBG_N_AsyncStop:
    case DBG_N_Watchpoint:
        AssumeQueue( buff->Pid, buff->Tid );
        break;
    }
    for( i = 0; i < num_paints; ++i ) {
        WinInvalidateRect( paints[i].hwnd, &paints[i].rcl, FALSE );
    }
    return( DebugReqResult );
}
/* This function is called from two threads, one each to monitor the
 * keyboard and mouse messages.
 * All packets are passed on unchanged.  The thread just clears a
 * semaphore to alert the main background process that there has been some
 * activity, which means it won't blank or will restore the screen if
 * it is already blanked.
 *
 * Parameter is name of device to be monitored.
 */
void CALLBACK
MonitorThread(NPSZ npName)
{
   int             rc;
   MONIN           mnin;        /* monitor buffers */
   MONOUT          mnout;
   HMONITOR        hmon;
   char            bDataBuf[sizeof(MONIN)];  /* buffer used */
   USHORT          cbDataBufLen;
   PIDINFO         pidi;

   /* It has to be time-critical, so it doesn't impact response. */
   DosGetPID(&pidi);
   DosSetPrty(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, pidi.tid);

   /* Initialize the lengths of the monitor buffer structures. */
   mnin.cb = sizeof(MONIN);
   mnout.cb = sizeof(MONOUT);

   /*
    * Register for the current session.
    */
   TRACE(tpMonOpen, TRUE, 0, npName);
   if (rc = DosMonOpen(npName, &hmon))
      ERRORCHK("DosMonOpen", rc);
   TRACE(tpMonReg, TRUE, 0, npName);
   rc = DosMonReg(hmon,
                  (PBYTE) & mnin,
                  (PBYTE) & mnout,
                  MONITOR_BEGIN, sgMonitor);
   TRACE(tpMonReg, FALSE, rc, npName);
   if (rc == 0)
      /*
       * Loop, passing on data and signalling main thread.
       */
      for (;;) {
         cbDataBufLen = sizeof(MONIN);
         if (DosMonRead((PBYTE) & mnin, DCWW_WAIT, bDataBuf, &cbDataBufLen))
            break;
         /* We shouldn't get a length 0 return, but best to check, before
          * testing the first byte... */
         if (cbDataBufLen > 0) {
            if (DosMonWrite((PBYTE) & mnout, bDataBuf, cbDataBufLen))
               break;
            /* Test for open/close/flush packets and ignore them;
             * they don't represent mouse/keyboard actions. */
            if (!(bDataBuf[0] & 0x07)) {
               TRACE(tpMonAction, FALSE, cbDataBufLen, npName);
               DosSemClear(&pSharedseg->semAction);
            }
         }
      }
   else {
      /* Failed to register */
      WtiLStrCpy(bDataBuf, "DosMonReg for ");
      WtiLStrCat(bDataBuf, npName);
      ERRORCHK(bDataBuf, rc);
   }

   /* If blanked, undo it, whatever the reason we're leaving... */
   if (pSharedseg->bBlanked)
      DosSemClear(&pSharedseg->semAction);

   /* Told to withdraw */
   DosExit(EXIT_THREAD, 0);
}
Ejemplo n.º 23
0
 xType2 ehnConnect(int thisConnect)
{
 char       Work[40];
 int        wasCode;
 unsigned   returnCode=OK,unLength;

 if (thisDB.connecting) 
     DosSemRequest(&thisDB.gate,SEM_INDEFINITE_WAIT);

 thisDB.connecting = TRUE;
 
 DosSemSet(&thisDB.gate);

 if (!thisDB.channel) thisDB.channel = DEFAULT_CHANNEL;
 
 if (debug >= 5000) return(OK);

 if (!thisState->actualCarrierLinked)
 {returnCode=EHNRQSTART(thisDB.channel,commit_mode,MAX_SQL_TEXT);
  if (!returnCode || returnCode==RQ_ALRDY_INIT)
    {xsqlLogPrint("%s connected to AS400 OK.",thisDB.subject);
     returnCode = thisConnect;
     EHNRQSETROWS(200);
     if (!thisSQLstate) 
     {thisSQLstate = malloc(sizeof(struct sqlca));
      memset(thisSQLstate,'\0',sizeof(struct sqlca));
     }
    }
  else
  {xsqlLogPrint("%s Couldn't connect to %s.",thisDB.subject,thisDB.channel);
   xsqlLogPrint("%s EHNRQSTART returned %d.",thisDB.subject,returnCode);
   returnCode   = FALSE;
  }
 }

 thisState->actualCarrierLinked = TRUE;
 thisDB.cursorIneligibility     = SQL_INSERT;

 if ((thisDB.accessMode == DRDA_PC_SUPPORT) ||
     (thisDB.accessMode == DDM_PC_SUPPORT))
 {char connectStatement[200];
 
  if (!thisDB.object)
    {xsqlLogPrint("%s Didn't name an object to connect to.",thisDB.subject);
     returnCode = OK;
    }
  else {sprintf(connectStatement,
    //            "CONNECT TO %s USER DAUGHERJ USING 'BEOBACHT'",
                  "CONNECT TO %s ",
                thisDB.object);
        xsqlLogPrint(connectStatement);
        returnCode=EHNRQCONNECT(connectStatement,NULL,&unLength);
        if (!returnCode || returnCode==RQ_ALRDY_INIT)
           {xsqlLogPrint("%s Connected to %s OK.",
                       thisDB.subject,thisDB.object);
            returnCode = thisConnect;
            thisDB.connected = TRUE;
           }    
        else
        {xsqlLogPrint("%s Couldn't connect to %s.",
                    thisDB.subject,thisDB.object);
         xsqlLogPrint("%s EHNRQCONNECT returned %d.",
                    thisDB.subject,returnCode);
         if (returnCode == 8)
             ehnError(returnCode,"EHNRQCONNECT",thisConnect);
         returnCode   = FALSE;
        }
       }
 } else thisDB.connected = TRUE;

 thisDB.connecting = FALSE;
 DosSemClear(&thisDB.gate);
 return(returnCode);

}  
Ejemplo n.º 24
0
MRESULT PMfrCommands (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
     /*
        These are the routnes that handle the commands issued by
        the FRACTINT for PM menus.

        In most cases, they call another support routine to
        handle or schedule the event requested by the user.
     */

     SHORT sCommand = SHORT1FROMMP(mp1);


     switch (sCommand)
          {
          case IDM_GO:
               /* fire up the subtask */
               cp.fContinueCalc = TRUE ;
               if (npNewParms.fNewParms)
                  {
                  CopyParmsToBase();
                  /* GetMemoryBitmap(); */
                  SetSwitchEntry (hwnd, szTitleBar,
                                  GetFractalName(cp.iFractType) );
                  }

               cp.sSubAction = SUB_ACT_CALC;   /* we want a Calculation */

               DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

               sStatus = STATUS_WORKING ;
               /* WinInvalidateRect (hwnd, NULL, FALSE) ; */
               UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
               EnableMenuItem (hwnd, IDM_GO, FALSE) ;
               EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
               /* WinStartTimer (hab, hwnd, ID_TIMER, 5000); */
               return 0 ;

          case IDM_PAN:
               /* Pan selected.  Pan to where the cross hairs were */
               PanNewCenter(hwnd);
               fGoodPan = FALSE;
               return 0;

          case IDM_ZIN_WIN:
               /* Zoom to the Window selected. */
               EraseZoomBox(hwnd);
               ZoomNewWindow(hwnd, TRUE);   /* zoom in */
               fGoodZoom = FALSE;
               return 0;

          case IDM_ZOUT_WIN:
               /* Zoom to the Window selected. */
               EraseZoomBox(hwnd);
               ZoomNewWindow(hwnd, FALSE);   /* zoom out */
               fGoodZoom = FALSE;
               return 0;

          case IDM_FREEZE_HALT:
               if (sStatus == STATUS_WORKING)
                  {
                  /* schedule the subthread to find a stopping place */
                  cp.fContinueCalc = FALSE ;
                  EnableMenuItem (hwnd, IDM_FREEZE_HALT, FALSE) ;
                  }
               if (sStatus == STATUS_READY)
                  {
                  /* we Freeze to play with parms repeatedly */
                  /* make a copy to play with.  We will keep */
                  /* working with only this copy */
                  InitNewParms(NULL);
                  /* now change state */
                  sStatus = STATUS_FROZEN;
                  EnableMenuItem (hwnd, IDM_FREEZE_HALT, FALSE);
                  }

               return 0 ;

          case IDM_ABOUT:
               /* send up the About box */
               WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc,
                    (HMODULE) 0, IDD_ABOUT, NULL) ;

               return 0 ;

          case IDM_NEW_FRACTAL:
               /*
                * send up the Select Fractal Type box.
                * On OK return, schedule the new parameters.
                * Handle the special cases needing files or other data
                * as part of exiting the initial dialog box.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SelFractalDlgProc,
                       (HMODULE) 0, IDD_SET_FRACTTYPE, NULL) )
                  ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_PARAMS:
               /*
                * send up the Set Paramters box.
                * On OK return, schedule the new parameters.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SetParametersDlgProc,
                       (HMODULE) 0, IDD_SET_PARAMS, NULL) )
               ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_OPTIONS:
               /*
                * send up the Set Options box.
                * On OK return, schedule the new parameters.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SetOptionsDlgProc,
                       (HMODULE) 0, IDD_SET_OPTIONS, NULL) )
               ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_IMAGE:
               /*
                * send up the Set Image box.
                * On OK return, schedule the new parameters.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SetImageDlgProc,
                       (HMODULE) 0, IDD_SET_IMAGE, NULL) )
               ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_PALETTE:
               /*
                * send up the Set Palette box.
                * Return is not checked because effects are immediate
               */
               WinDlgBox (HWND_DESKTOP, hwnd, SetPaletteDlgProc,
                       (HMODULE) 0, IDD_SET_PALETTE, NULL) ;

               return 0 ;

          case IDM_ZIN_PICK:
          case IDM_ZOUT_PICK:
               /*
                * Send up the Zoom Value dialog box.
                * On OK return, schedule the new parameters.
               */
               if ( WinDlgBox (HWND_DESKTOP, hwnd, ZoomValueDlgProc,
                        (HMODULE) 0, IDD_NUMBER_PICK,
                        MPFROMP((PVOID) &COMMANDMSG(&msg)->cmd)) )
                  ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_ZIN_2:
          case IDM_ZIN_5:
          case IDM_ZIN_10:
               /*
                * Zoom in by fixed value.
                * Schedule the new parameters.
               */
               InitNewParms(NULL);
               CalcZoomValues(&npNewParms,
                      (double) (sCommand), TRUE );
               npNewParms.fNewParms = TRUE;
               ScheduleNewParms(hwnd);

               return 0;

          case IDM_ZOUT_2:
          case IDM_ZOUT_5:
          case IDM_ZOUT_10:
               /*
                * Zoom out by fixed value.
                * Schedule the new parameters.
               */
               InitNewParms(NULL);
               CalcZoomValues(&npNewParms,
                      (double) (sCommand - 10), FALSE );
               npNewParms.fNewParms = TRUE;
               ScheduleNewParms(hwnd);

               return 0;

          case IDM_SET_EXTENTS:
               /*
                * Send up the Set Extents dialog box.
                * On OK return, schedule the new parameters.
               */
               if ( WinDlgBox (HWND_DESKTOP, hwnd, SetExtentsDlgProc,
                      (HMODULE) 0, IDD_SET_EXTENTS, NULL) )
                   ScheduleNewParms (hwnd);

               return 0;

          case IDM_SET_SWAP:
               /* swap Mandel for Julia or vice versa.
                  Handle it as a parm change */
               InitNewParms(NULL);
               if (fractalspecific[npNewParms.iFractType].tojulia != NOFRACTAL
                      && npNewParms.param[0] == 0.0
                      && npNewParms.param[1] == 0.0)
                  {
                  /* switch to corresponding Julia set */
                  npNewParms.iFractType =
                         fractalspecific[npNewParms.iFractType].tojulia;
                  npNewParms.param[0] = npNewParms.XCenter;
                  npNewParms.param[1] = npNewParms.YCenter;

                  npNewParms.mxXL = fractalspecific[npNewParms.iFractType].xmin;
                  npNewParms.mxXR = fractalspecific[npNewParms.iFractType].xmax;
                  npNewParms.mxYB = fractalspecific[npNewParms.iFractType].ymin;
                  npNewParms.mxYT = fractalspecific[npNewParms.iFractType].ymax;

                  }

               else if (fractalspecific[npNewParms.iFractType].tomandel != NOFRACTAL)
                  {
                  /* switch to corresponding Mandel set */
                  npNewParms.iFractType =
                         fractalspecific[npNewParms.iFractType].tomandel;
                  npNewParms.param[0] = 0.0;
                  npNewParms.param[1] = 0.0;
                  npNewParms.mxXL = fractalspecific[npNewParms.iFractType].xmin;
                  npNewParms.mxXR = fractalspecific[npNewParms.iFractType].xmax;
                  npNewParms.mxYB = fractalspecific[npNewParms.iFractType].ymin;
                  npNewParms.mxYT = fractalspecific[npNewParms.iFractType].ymax;
                  }

               npNewParms.fNewParms = TRUE;
               ScheduleNewParms (hwnd);
               return 0;

          case IDM_SET_RESET:
               /* copy the work copy of the parms back from the
                  set used by the calculation engine.
                  This resets any dicking around done with the
                  dialogs.
                  Note: this is only active during FREEZE mode.
               */

               CopyParmsToNew();

               return 0;

          case IDM_HELP_INTRO:
               /* basic Introductory Help */
               SimpleHelp(hab, hwnd, szTitleBar,
                         (HMODULE) 0, IDT_TEXT, IDT_HELP_INTRO);
               return 0;

          case IDM_HELP_FRACTTYPE:
               /* Fractal list Help */
               SimpleHelp(hab, hwnd, szTitleBar,
                         (HMODULE) 0, IDT_TEXT, IDT_HELP_TYPES);
               return 0;

          case IDM_HELP_OPERATE:
               /* Menu Help */
               SimpleHelp(hab, hwnd, szTitleBar,
                       (HMODULE) 0, IDT_TEXT, IDT_HELP_OPERATE);
               return 0;

          case IDM_PRINT_FILE:
               /* Send up the Print Where Dialog.
                  On OK return, fire up the subtask */
               if ( WinDlgBox(HWND_DESKTOP, hwnd, PrintOptionsDlgProc,
                    (HMODULE) 0, IDD_PRINT, NULL) )
                  {
                  /* fire up the subtask */
                  cp.sSubAction = SUB_ACT_PRINT;   /* we want a Print */

                  cp.fContinueCalc = TRUE;
                  DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

                  sStatus = STATUS_WORKING ;
                  UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
                  EnableMenuItem (hwnd, IDM_GO, FALSE) ;
                  EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
                  cp.fSuppressPaint = TRUE;
                  WinInvalidateRect(hwnd, NULL, FALSE);
                  }

               return 0 ;

          case IDM_READ_FILE:
               /* Send up the Load/Save Format Dialog to find
                  out the format we will read.
                  Then send up the generic Open File dialog.
                  On OK return, fire up the subtask */
               {
               DLF dlf;
               HFILE hfDummy;
               PSZ pszExt;

               if ( WinDlgBox(HWND_DESKTOP, hwnd, LoadSaveFmtDlgProc,
                    (HMODULE) 0, IDD_LOADSAVE_TYPE, szLoadWhatFmt) )
                  {

                  FileFmtExt (&pszExt);

                  SetupDLF (&dlf, DLG_OPENDLG, &hfDummy,
                            pszExt, szTitleBar,
                            szOpenTitle, szOpenHelp);

                  if (TDF_OLDOPEN == DlgFile(hwnd, &dlf) )
                     {
                     /* close the dummy file handle */
                     DosClose(hfDummy);
                     /* fire up the subtask */
                     cp.sSubAction = SUB_ACT_LOAD;   /* we want a Load */
                     cp.sSubFunction = cp.sLastLoadSaveType;
                     _fstrcpy(cp.szFileName, dlf.szOpenFile);

                     cp.fContinueCalc = TRUE;
                     DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

                     sStatus = STATUS_WORKING ;
                     UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
                     EnableMenuItem (hwnd, IDM_GO, FALSE) ;
                     EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
                     cp.fSuppressPaint = TRUE;
                     WinInvalidateRect(hwnd, NULL, FALSE);
                     }
                  }

               return 0 ;
               }

          case IDM_SAVE_FILE:
               /* Send up the Load/Save Format Dialog to find
                  out the format we will be writing.
                  Then send up the generic Save File dialog.
                  On OK return, fire up the subtask */
               {
               DLF dlf;
               HFILE hfDummy;
               PSZ pszExt;

               if ( WinDlgBox(HWND_DESKTOP, hwnd, LoadSaveFmtDlgProc,
                    (HMODULE) 0, IDD_LOADSAVE_TYPE, szSaveWhatFmt) )
                  {

                  FileFmtExt (&pszExt);

                  SetupDLF (&dlf, DLG_SAVEDLG, &hfDummy,
                            pszExt, szTitleBar,
                            szOpenTitle, szOpenHelp);
                  _fstrcpy(dlf.szOpenFile, cp.szFileName);

                  if (TDF_NOSAVE != DlgFile(hwnd, &dlf) )
                     {
                     /* close the dummy file handle */
                     DosClose(hfDummy);
                     /* and delete the dummy file */
                     DosDelete(dlf.szOpenFile, 0);
                     /* fire up the subtask */
                     cp.sSubAction = SUB_ACT_SAVE;   /* we want a Save */
                     cp.sSubFunction = cp.sLastLoadSaveType;
                     _fstrcpy(cp.szFileName, dlf.szOpenFile);

                     cp.fContinueCalc = TRUE;
                     DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

                     sStatus = STATUS_WORKING ;
                     UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
                     EnableMenuItem (hwnd, IDM_GO, FALSE) ;
                     EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
                     cp.fSuppressPaint = TRUE;
                     WinInvalidateRect(hwnd, NULL, FALSE);
                     }
                 }

               return 0 ;
               }

          case IDM_READ_COLORMAP:
               /* Send up the generic Open File dialog.
                  On OK return, read in the file via subroutine. */
               {
               DLF dlf;
               HFILE hfDummy;

               SetupDLF (&dlf, DLG_OPENDLG, &hfDummy,
                         "\\*.map", szTitleBar,
                         szColorMapTitle, szColorMapHelp);

               if (TDF_OLDOPEN == DlgFile(hwnd, &dlf) )
                  {
                  /* close the dummy file handle */
                  DosClose(hfDummy);
                  /* throw up the hour-glass */
                  WinSetCapture(HWND_DESKTOP, hwnd);
                  WinSetPointer(HWND_DESKTOP, hptrWait);
                  /* read it in */
                  LoadColorMap(dlf.szOpenFile);
                  /* now clean up */
                  WinSetPointer(HWND_DESKTOP, hptrArrow);
                  WinSetCapture(HWND_DESKTOP, (HWND) NULL);
                  }
               }

               return 0;

          case IDM_WRITE_COLORMAP:
               /* Send up the generic Save File dialog.
                  On OK return, write the file via subroutine */
               {
               DLF dlf;
               HFILE hfDummy;

               SetupDLF (&dlf, DLG_SAVEDLG, &hfDummy,
                         "\\*.map", szTitleBar,
                         szColorMapTitle, szColorMapHelp);

               if (TDF_NOSAVE != DlgFile(hwnd, &dlf) )
                  {
                  /* close the dummy file handle */
                  DosClose(hfDummy);
                  /* throw up the hour-glass */
                  WinSetCapture(HWND_DESKTOP, hwnd);
                  WinSetPointer(HWND_DESKTOP, hptrWait);
                  /* write it out */
                  SaveColorMap(dlf.szOpenFile);
                  /* now clean up */
                  WinSetPointer(HWND_DESKTOP, hptrArrow);
                  WinSetCapture(HWND_DESKTOP, (HWND) NULL);
                  }
               }

               return 0;

          case IDM_CLEAR_CLPB:
               /* clear the current contents of the clipboard */
               WinOpenClipbrd (hab);
               WinEmptyClipbrd (hab);
               WinCloseClipbrd (hab);

               return 0;

          case IDM_PASTE:
               {  /* paste from the clipboard into us */
               USHORT usClipBrdInfo;

               if ( WinQueryClipbrdFmtInfo(hab, CF_BITMAP, &usClipBrdInfo) )
                  {  /* we have a bitmap to fetch */
                  /* draw the curtain over the display */
                  cp.fSuppressPaint = TRUE;
                  WinInvalidateRect(hwnd, NULL, FALSE);
                  WinUpdateWindow(hwnd);
                  /* throw up the hour-glass */
                  WinSetCapture(HWND_DESKTOP, hwnd);
                  WinSetPointer(HWND_DESKTOP, hptrWait);
                  /* fetch the bitmap */
                  PMfrFetchClipbrdBmp(hab);
                  /* now clean up */
                  WinSetPointer(HWND_DESKTOP, hptrArrow);
                  WinSetCapture(HWND_DESKTOP, (HWND) NULL);
                  /* and schedule redrawing the window */
                  SetSwitchEntry (hwnd, szTitleBar,
                                  GetFractalName(cp.iFractType) );
                  cp.fSuppressPaint = FALSE;
                  WinInvalidateRect(hwnd, NULL, FALSE);
                  }
               }

               return 0;

          case IDM_COPY_BMP:
               {  /* copy to the clipboard from us */

               /* throw up the hour-glass */
               WinSetCapture(HWND_DESKTOP, hwnd);
               WinSetPointer(HWND_DESKTOP, hptrWait);
               /* write the bitmap */
               PMfrWriteClipbrdBmp(hab);
               /* now clean up */
               WinSetPointer(HWND_DESKTOP, hptrArrow);
               WinSetCapture(HWND_DESKTOP, (HWND) NULL);

               }

               return 0;

          }

     return 0;

     }
Ejemplo n.º 25
0
void PASCAL init_list ()
{
//       unsigned       rc;
//       USHORT i;
    LPVOID      lpParameter = NULL;
    DWORD       dwThreadId;

//       char   c;


    /*
     * Init Misc
     */
    DosSemSet (vSemSync);
    DosSemSet (vSemMoreData);



    /*
     * Init screen parameters
     */

    GetConsoleScreenBufferInfo( vStdOut,
                                &vConsoleOrigScrBufferInfo );

    vConsoleOrigScrBufferInfo.dwSize.X=
        vConsoleOrigScrBufferInfo.srWindow.Right-
        vConsoleOrigScrBufferInfo.srWindow.Left + 1;
    vConsoleOrigScrBufferInfo.dwSize.Y=
        vConsoleOrigScrBufferInfo.srWindow.Bottom-
        vConsoleOrigScrBufferInfo.srWindow.Top + 1;
    vConsoleOrigScrBufferInfo.dwMaximumWindowSize=
        vConsoleOrigScrBufferInfo.dwSize;




    set_mode( 0, 0, 0 );



    /*
     *  Start reading the first file. Displaying can't start until
     *  the ini file (if one is found) is processed.
     */
    vReaderFlag = F_NEXT;

    /*
     *  Init priority setting for display & reader thread.
     *
     *      THREAD_PRIORITY_NORMAL       = reader thread normal pri.
     *      THREAD_PRIORITY_ABOVE_NORMAL = display thread pri
     *      THREAD_PRIORITY_HIGHEST      = reader thread in boosted pri.
     */
    vReadPriNormal = THREAD_PRIORITY_NORMAL;
    SetThreadPriority( GetCurrentThread(),
                       THREAD_PRIORITY_ABOVE_NORMAL );
    vReadPriBoost = THREAD_PRIORITY_NORMAL;


    /*
     *  Start reader thread
     */
    CreateThread( NULL,
                  STACKSIZE,
                  (LPTHREAD_START_ROUTINE) ReaderThread,
                  NULL, // lpParameter,
                  0, // THREAD_ALL_ACCESS,
                  &dwThreadId );


    /*
     *  Read INI information.
     */
    vSetWidth = vWidth;                     /* Set defaults             */
    vSetLines = vLines + 2;

    FindIni ();
    if (vSetBlks < vMaxBlks)
        vSetBlks  = DEFBLKS;

    vSetThres = (long) (vSetBlks/2-2) * BLOCKSIZE;

    /*
     *  Must wait for reader thread to at least read in the
     *  first block. Also, if the file was not found and only
     *  one file was specifed the reader thread will display
     *  an error and exit... if we don't wait we could have
     *  changed the screen before this was possible.
     */
    DosSemRequest (vSemMoreData, WAITFOREVER);


    /*
     *  Now that ini file has been read. Set parameters.
     *  Pause reader thread while adjusting buffer size.
     */
    SyncReader ();

    vMaxBlks    = vSetBlks;
    vThreshold  = vSetThres;
    vReaderFlag = F_CHECK;
    DosSemClear   (vSemReader);


    /*
     *  Now set to user's default video mode
     */

    set_mode (vSetLines, vSetWidth, 0);


    SetConsoleActiveScreenBuffer( vhConsoleOutput );

    //
    //      davegi/jaimes - 08/26/91
    //
    // Make List think it has one less line than the screen buffer.
    // This 'solves' the scrolling problem when Enter is pressed for a
    // command.
    // This is necessary because list uses the ReadFile() API to read
    // a string. ReadFile() echoes the carriage return and line feed
    // to the screen, and as the cursor is in the last line, the screen
    // is scolled one line up. By leaving one empty line after the
    // command line, this problem is eliminated.
    //

// T-HeathH 06/23/94
//
// Moved the hack to set_mode, where it will be used whenever that
// code thinks it has resized the display.
//
// That change subsumed this onld one.
//
//    vLines--;



}
Ejemplo n.º 26
0
/*
 * inchar() - get a character from the keyboard.
 *
 * Timeout not implemented yet for OS/2.
 */
int
inchar(long mstimeout)
{
    for (;;) {
	KBDKEYINFO k;
	bool_t	mstatus,
		psvstatus;

	flush_output();

	mstatus = (usemouse && State == NORMAL);
	psvstatus = (keystrokes >= PSVKEYS);
	/*
	 * We don't have to give control to any other thread
	 * if neither of these conditions is true.
	 */
	if (mstatus || psvstatus) {
#ifndef NOMOUSE
	    if (mstatus)
		showmouse();
#endif
	    if (psvstatus && DosSemWait(psvsema, SEM_IMMEDIATE_RETURN)
						    == ERROR_SEM_TIMEOUT) {
		/*
		 * If psvsema is set, clear it.
		 */
		DosSemClear(psvsema);
	    }
	    DosSemClear(control);
	}
	/*
	 * Start of non-critical section.
	 *
	 * Wait for character from keyboard.
	 */
	KbdCharIn((PKBDKEYINFO) &k, IO_WAIT, 0);
	/*
	 * End of non-critical section.
	 */
	if (mstatus || psvstatus) {
	    DosSemRequest(control, SEM_INDEFINITE_WAIT);
#ifndef NOMOUSE
	    if (mstatus)
		hidemouse();
#endif
	}
	if (++keystrokes >= PSVKEYS)
	    lastevent = clock();
	/*
	 * Now deal with the keypress information.
	 */
	if ((unsigned char) k.chChar == (unsigned char) 0xe0) {
	/*
	 * It's (probably) a function key.
	 */
	    if (k.chScan == 0x53)
		/*
		 * It's the delete key.
		 */
		return State == NORMAL ? 'x' : '\b';
	     /* else */
	    if (State == NORMAL) {
		/*
		 * Assume it must be a function key.
		 */
		switch (k.chScan) {
		    case 0x3b: return(K_HELP);	  /* F1 key */
		    case 0x47: return(K_HOME);	  /* home key */
		    case 0x48: return(K_UARROW);  /* up arrow key */
		    case 0x49: return(K_PGUP);	  /* page up key */
		    case 0x4b: return(K_LARROW);  /* left arrow key */
		    case 0x4d: return(K_RARROW);  /* right arrow key */
		    case 0x4f: return(K_END);	  /* end key */
		    case 0x50: return(K_DARROW);  /* down arrow key */
		    case 0x51: return(K_PGDOWN)); /* page down key */
		    case 0x52: return(K_INSERT);  /* insert key */
		    default:
			/* just ignore it ... */
			continue;
		}
		/*
		 * If we aren't in command mode, 0xe0
		 * is a perfectly legitimate
		 * character, & we can't really tell
		 * whether or not it's supposed to be
		 * a function key, so we just have to
		 * return it as is.
		 */
	    }
	}
	return (unsigned char) k.chChar;
    }
}