Esempio n. 1
0
BOOL SetRASectors(PSZ pszArg)
{
APIRET rc;
HFILE hDisk;
ULONG ulAction;
USHORT usRASectors;
ULONG  ulDataSize;
BYTE   szDisk[3];

   if (pszArg[1] != ':')
      {
      printf("Invalid argument for /R option.\n");
      DosExit(EXIT_PROCESS, 1);
      }
   memset(szDisk, 0, sizeof szDisk);
   memcpy(szDisk, pszArg, 2);
   strupr(szDisk);
   pszArg+=2;
   if (*pszArg !=',')
      {
      printf("Comma missing in /R:d:,n\n");
      DosExit(EXIT_PROCESS, 1);
      }
   pszArg++;
   usRASectors = atoi(pszArg);

   rc = DosOpen(szDisk,
      &hDisk,
      &ulAction,                          /* action taken */
      0L,                                 /* new size     */
      0L,                                 /* attributes   */
      OPEN_ACTION_OPEN_IF_EXISTS,         /* open flags   */
      OPEN_ACCESS_READONLY |              /* open mode    */
      OPEN_SHARE_DENYNONE |
      OPEN_FLAGS_DASD,
      NULL);                              /* ea data      */

   if (rc)
      {
      printf("Cannot access drive %s, rc = %d\n",
         szDisk, rc);
      DosExit(EXIT_PROCESS, 1);
      }

   ulDataSize = sizeof usRASectors;
   rc = DosDevIOCtl(hDisk,
      IOCTL_FAT32,
      FAT32_SETRASECTORS,
      (PVOID)&usRASectors, ulDataSize, &ulDataSize,
      NULL, 0, NULL);
   if (rc)
      {
      printf("DosDevIOCtl, FAT_SETRASECTORS for drive %s failed, rc = %d\n",
         szDisk, rc);
      DosExit(EXIT_PROCESS, 1);
      }

   DosClose(hDisk);
   return TRUE;
}
Esempio n. 2
0
void ccmdline(void) {
	int p = 0;

	p = pccmdline();
	if (p == 0) return;
  
	if (p == 9) {
    		displayparams();
	}

	if (p == 4) {
		/* printf("Mangled command line, did you forget a parm?\n"); */
		printf("Invalid Commandline!\n");
		DosExit();
	}
  
	if ((p > 9) && (p < 17)) {
		printf(ers[p-10]);
		DosExit();
	}

	if (p == 2) {
		DosExit();
	}
  
	printf("cmdline returned %i\n",p);
	DosExit();
}
VOID CheckSystemConfig( VOID )
{
 // Проверяем настройки в файле "Config.sys".
 CHAR File_name[ SIZE_OF_NAME ] = "*:\\Config.sys"; ULONG Boot_drive = 0;
 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PULONG) &Boot_drive, sizeof( Boot_drive ) );
 File_name[ 0 ] = (CHAR) Boot_drive + 64;

 ULONG Action = OPEN_ACTION_OPEN_IF_EXISTS;
 ULONG Mode = OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYWRITE | OPEN_ACCESS_READONLY;

 HFILE File = NULLHANDLE; ULONG Report = 0;
 APIRET RC = DosOpen( File_name, &File, &Report, 0, FILE_NORMAL, Action, Mode, NULL );

 // Если файл был открыт:
 if( RC == NO_ERROR )
  {
   // Отводим память для текста.
   PCHAR Text = NULL; ULONG Length = 65536;
   if( DosAllocMem( (PPVOID) &Text, Length, PAG_ALLOCATE ) != NO_ERROR )
    {
     DosClose( File );
     DosExit( EXIT_PROCESS, 0 );
    }

   // Читаем настройки.
   memset( Text, 0, Length );
   DosRead( File, Text, Length, &Length );

   // Проверяем, есть ли в настройках путь к каталогу расширителя.
   BYTE Path_is_present = 1; if( !stristr( "NICE\\ENHANCER", Text ) ) Path_is_present = 0;

   // Освобождаем память.
   DosFreeMem( Text ); Text = NULL;

   // Закрываем файл.
   DosClose( File ); File = NULLHANDLE;

   // Если настройки заданы неправильно:
   if( !Path_is_present )
    {
     // Показываем сообщение.
     CHAR Title[ SIZE_OF_TITLE ] = ""; GetEnhancerWindowTitle( Title );

     if( QuerySystemCodePage() == RUSSIAN )
      WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, StrConst_RU_No_path_in_Config_sys, Title, NULLHANDLE, NULLHANDLE );
     else
      WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, StrConst_EN_No_path_in_Config_sys, Title, NULLHANDLE, NULLHANDLE );

     // Выход.
     DosExit( EXIT_PROCESS, 0 );
    }
  }

 // Возврат.
 return;
}
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$");
}
Esempio n. 5
0
/* *************************************************************** */
void _catcher(bundle s)
{
    char    msg[512];
    char   *b[4];
    HMODULE hmod;
    PFNWP   DlgProc;
    int  c  = 0,
         bx = 0;

    if (msgHead != NULL) {
      for (msg[0] = '\0'; *msgHead != NULL; ++msgHead) strcat(msg,*msgHead);
      b[bx++] = msg;
      c = strlen(msg) + 1;
    }
    for (msg[c] = '\0'; *s != NULL; ++s) strcat(&msg[c],*s);
    b[bx++] = &msg[c];
    b[bx++] = "Application will terminate now";
    b[bx]   = NULL;

    if (DosLoadModule(NULL, 0, "GPRTS", &hmod) ||
        DosQueryProcAddr(hmod, 0, "DlgProc", (PFN *)&DlgProc))
      WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
                    "Unable to load error message","GPM Fatal Error",
                    0, MB_ICONHAND | MB_OK);
    else {
      WinAlarm(HWND_DESKTOP, WA_ERROR);
      WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, DlgProc, hmod, GPRTS_DLG, b);
      DosFreeModule(hmod);
    }
    DosExit(EXIT_PROCESS, 0);
}
Esempio n. 6
0
void APIENTRY LoopThread()
  {
  THREAD *pstThd = pstThread;
  CONFIG *pCfg = &pstThd->stCfg;
  THREADCTRL *pThread = &pstThd->stThread;
  int iError;
  CHAR szMessage[81];
  DCB stComDCB;

//  DosSetPriority(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,-32L,0);
  DosSetPriority(PRTYS_THREAD,PRTYC_REGULAR,-14L,0);
  while (!pThread->bStopThread)
    {
    switch (pCfg->wSimulateType)
      {
      case TERMINAL:
        GetDCB(&stIOctlInst,pstThd->hCom,&stComDCB);
        stComDCB.Flags3 &= ~F3_RTO_MASK;
        stComDCB.Flags3 |= F3_WAIT_SOMETHING;
        stComDCB.ReadTimeout = 100;
        SendDCB(&stIOctlInst,pstThd->hCom,&stComDCB);
        TerminalRead(pstThd);
        break;
      case STRING_TRANSFER:
        DoStringTransfer(pstThd);
        break;
      }
    }
  DosPostEventSem(hevKillThreadSem);
  DosExit(EXIT_THREAD,0);
  }
Esempio n. 7
0
VOID APIENTRY StopApplication( VOID )
{
    StopBuff.Cmd = DBG_C_Stop;
    Call32BitDosDebug( &StopBuff );
    DosSemClear( &StopDoneSem );
    DosExit( 0, 0 );
}
Esempio n. 8
0
VOID terminateTimerMgr(HMQ hmq) {
   g.is.expired = 1;
   if (g.timerThrd.hwnd) WinDestroyWindow(g.timerThrd.hwnd);
   WinDestroyMsgQueue(hmq);
   WinTerminate(g.timerThrd.hab);
   DosExit(EXIT_THREAD, 0);
}
Esempio n. 9
0
VOID Finalize(VOID)
{
    APIRET rc;

    // Save Options to INI file
    SaveScoresToIni();
    SaveOptionsToIni();
    WinStoreWindowPos(szAppName, szKeyPosition, hwndFrame);


    // close the game engine and the associated async thread, if any
    Eng_Close();
    dprint("gameEng close\n");

    GfxEng->close();
    dprint("GfxEng close\n");


    // close the sound engine
    // this also takes care of any sound threads
    SndEng->close();
    dprint("SoundEng close");

    if( hrgnInvalid)
	GpiDestroyRegion( hpsClient, hrgnInvalid);
    if( hpsClient)
    {
        GpiAssociate( hpsClient, NULLHANDLE);
        GpiDestroyPS( hpsClient);
    }

    if( hpsPaint)
        GpiDestroyPS( hpsPaint);

    dprint("Destroyed hPS\n");

    DestroyHelpInstance();

    if (hwndFrame)
        WinDestroyWindow( hwndFrame);
    if (hmqMain)
        WinDestroyMsgQueue( hmqMain);
    if (habMain)
        WinTerminate( habMain);
    if (hGame)
        DosClose(hGame);

    dprint("Destroyed handles\n");


    if (debOut)
    {
        fprintf(debOut, "Exiting MakMan/2\n");
        fflush(debOut);
        fclose(debOut);
    }

    DosExit( EXIT_PROCESS, 0);

}   /* end Finalize() */
Esempio n. 10
0
void __CEndThread( void )
/***********************/
{
    __sig_fini_rtn();
    __OS2RemoveThread();
    DosExit( EXIT_THREAD, 0 );
}
Esempio n. 11
0
void Eingang()
{
	DosBeep(3000,300);
	DosSleep(1000);
	DosBeep(4000,200);
	DosExit(0,0);
}
Esempio n. 12
0
void EndItAll( int rc, PDTV pDisk )
{
  pDisk->ulCount   = ( CONST * ITER );
  pDisk->iExitCode = rc;
  DosPostEventSem( pDisk->hevDone );

  DosExit( 0, rc );
}
void main(void) {
  APIRET rc; PVOID myhighmem; ULONG cbWritten;
  rc = DosWrite(HF_STDOUT,"Hello World!\r\n",14,&cbWritten);
  rc = DosAllocMem(&myhighmem, 1024*1024*1024, PAG_READ|PAG_WRITE | OBJ_ANY );  // allocate 1GB of HMA(obj_any) rw-able 
  if(rc==0) { rc = DosWrite(HF_STDOUT,"allocation ok.!\r\n",17,&cbWritten);
    rc = DosFreeMem(myhighmem);
  }
  DosExit(EXIT_PROCESS,rc);
}
Esempio n. 14
0
void APIENTRY ReadLoopThread()
  {
  THREAD *pstThd = pstThread;
  CONFIG *pCfg = &pstThd->stCfg;
  THREADCTRL *pThread = &pstThd->stThread;
  BOOL bReadComplete;
  CHAR *pString;
  APIRET rc;
  BOOL bSkipRead = FALSE;
  char szMessage[80];
  ULONG ulStringLength;
  ULONG ulPostCount;


//  DosSetPriority(PRTYS_THREAD,PRTYC_FOREGROUNDSERVER,-28L,0);
  DosSetPriority(PRTYS_THREAD,PRTYC_REGULAR,-10L,0);
  ulStringLength = pCfg->wReadStringLength;
  DosAllocMem((PPVOID)&pString,10010,(PAG_COMMIT | PAG_WRITE | PAG_READ));
  while (!pThread->bStopThread)
    {
    if (ulStringLength != pCfg->wReadStringLength)
      {
      DosFreeMem(pString);
      ulStringLength = pCfg->wReadStringLength;
      DosAllocMem((PPVOID)&pString,(ulStringLength + 10),(PAG_COMMIT | PAG_WRITE | PAG_READ));
      }
    if (pCfg->bHalfDuplex)
      {
      while ((rc = DosWaitEventSem(hevStartReadSem,10000)) != 0)
        if (rc == ERROR_SEM_TIMEOUT)
          {
          ErrorNotify(pstThd,"Read start semaphore timed out");
          bSkipRead = TRUE;
          }
        else
          {
          sprintf(szMessage,"Read start semaphore error - rc = %u",rc);
          ErrorNotify(pstThd,szMessage);
          }
      DosResetEventSem(hevStartReadSem,&ulPostCount);
      }
    if (bSkipRead)
      bSkipRead = FALSE;
    else
      {
      if (!pCfg->bReadCharacters)
        bReadComplete = ReadString(pstThd,pString);
      else
        bReadComplete = ReadCharacters(pstThd,pString);
      if (bReadComplete)
        DosPostEventSem(hevStartWriteSem);
      }
    }
  DosFreeMem(pString);
  DosPostEventSem(hevKillReadThreadSem);
  DosExit(EXIT_THREAD,0);
  }
Esempio n. 15
0
// Here's the deal with BeginThreadHelper() and the event sem: each thread
// is given its own thread_data structure. BeginThreadHelper() gets a pointer
// to the data passed in but it has to copy the data to its own (thread
// specific) stack. The event sem must be used to prevent the creating thread
// from trashing the data before the thread is done copying it.
// Note: Currently thread_data only contains a single HMQ field. We could
// just pass it as a thread argument and skip these shenanigans. But hey,
// it's fun and it would be needed anyway if thread_data were extended.
static VOID APIENTRY BeginThreadHelper( ULONG arg )
{
    thread_data tdata;
    thread_data *_arg = (thread_data*)arg;

    tdata = *_arg;
    DosPostEventSem( BeginThreadSem );
    SoftModeThread( &tdata );
    DosExit( EXIT_THREAD, 0 );
}
Esempio n. 16
0
static void sht_exit (j_common_ptr cinfo)
{
  /* Always display the message */
  (*cinfo->err->output_message) (cinfo);

  /* Let the memory manager delete any temp files before we die */
  jpeg_destroy(cinfo);

  DosExit(EXIT_THREAD,EXIT_FAILURE);
}
VOID Changer_ChangerThread( VOID )
{
 // Определяем поток в системе.
 HAB Thread = WinInitialize( 0 );

 // Если это сделать не удалось - выход.
 if( Thread == NULLHANDLE )
  {
   // При создании потока произошла ошибка.
   Thread_responds.Thread_is_created = -1;

   // Выход.
   return;
  }

 // Создаем очередь сообщений - она должна быть в каждом потоке.
 HMQ Message_queue = WinCreateMsgQueue( Thread, 0 ); Enhancer.Modules.Changer->Message_queue = Message_queue;

 // Если очередь создать не удалось - выход.
 if( Enhancer.Modules.Changer->Message_queue == NULLHANDLE )
  {
   // Завершаем работу потока.
   WinTerminate( Thread );

   // При создании потока произошла ошибка.
   Thread_responds.Thread_is_created = -1;

   // Выход.
   return;
  }

 // Поток создан успешно.
 Thread_responds.Thread_is_created = 1;

 // Получение и обработка сообщений, приходящих в поток.
 QMSG Message = {0};
 while( WinGetMsg( Thread, &Message, 0, 0, 0 ) )
  {
   // Проверяем, не идет ли следом такое же сообщение.
   QMSG Next_message = {0};
   WinPeekMsg( Thread, &Next_message, NULLHANDLE, Message.msg, Message.msg, PM_NOREMOVE );
   if( Next_message.msg == Message.msg )
    if( Next_message.mp1 == Message.mp1 )
     if( Next_message.mp2 == Message.mp2 )
      if( Next_message.hwnd == Message.hwnd ) continue;

   // Обрабатываем сообщение.
   Changer_ChangerMessageProcessing( &Message );
  }

 // Завершаем работу потока.
 WinDestroyMsgQueue( Message_queue );
 WinTerminate( Thread );
 DosExit( EXIT_THREAD, 0 );
}
Esempio n. 18
0
_WCRTLINK void  __exit( unsigned ret_code )
/*****************************************/
{
    __FiniRtns( 0, FINI_PRIORITY_EXIT-1 );
#ifdef __SW_BD
    RetCode = ret_code;
    longjmp( JmpBuff, 1 );
#else
    DosExit( EXIT_PROCESS, ret_code );
#endif
}
ULONG Init(VOID)
#endif
{
    /* Add ExitProc to the exit list to handle the exit processing.  If
     * there is an error, then terminate the process since there have
     * not been any resources allocated yet
     */
   if (DosExitList(EXLST_ADD, (PFNEXITLIST)ExitProc))
   {
       MessageBox(HWND_DESKTOP,
                  IDMSG_CANNOTLOADEXITLIST, 0,
                  MB_OK | MB_ERROR,
                  TRUE);
       DosExit(EXIT_PROCESS, RETURN_ERROR);
   }

   /* load application name from resource file */
   if(0==WinLoadString(vhab, (HMODULE)NULL, IDS_APPNAME, CCHAPPNAME, szAppName))
       return IDMSG_CANNOTLOADSTRING;

   /* register the main client window class */
   if (!WinRegisterClass(vhab,
                szAppName,
                (PFNWP)MainWndProc,
                0L,
                0))
       return IDMSG_INITFAILED;

   /*
    * create main application window & detach scrollbars
    */
   if (!InitMainWindow())
       return IDMSG_MAINWINCREATEFAILED;

   /*
    * set up globals used for sizing & system pointers
    */
   if (!InitGlobalVars())
      return IDMSG_INITFAILED;

   /*
    * this function prepares the application for loading images
    */
   InitClientArea(vhwndClient);

   /*
    * initialize help mechanism
    */
#ifdef HELP_MANAGER_ENABLED
   HelpInit();
#endif

   return NO_ERROR;
}  /* End of Init */
Esempio n. 20
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);
    }
}
Esempio n. 21
0
/*
 * main - main entry point for PM
 */
int main( int argc, char *argv[] )
{
    HMQ         hmq;
    QMSG        qmsg;
    HAB         hab;

    hab = WinInitialize( 0 );
    if(!hab) {
        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
        DosExit(EXIT_PROCESS, RETURN_ERROR);
    }

    hmq = WinCreateMsgQueue( hab, 0 );
    if(!hmq) {
        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
        WinTerminate(hab);
        DosExit(EXIT_PROCESS, RETURN_ERROR);
    }

    if( !imgEditInit( hab ) ) {
        DosBeep(BEEP_WARN_FREQ, BEEP_WARN_DUR);
        WinTerminate(hab);
        DosExit(EXIT_PROCESS, RETURN_ERROR);
    }

    IEEnableMenuInput( TRUE );

    if( argc > 1 ) {
        parseCmdLine( argc, argv );
    }

    while ( WinGetMsg(hab, &qmsg, 0, 0, 0) ) {
        WinDispatchMsg( hab, &qmsg );
    }

    imgeditFini( hmq );

    return 0;
} /* main */
/****************************************************************\
 * Routine for consumer threads.                                *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:     ThreadConsumer(PVOID)                             *
 *                                                              *
 *  Purpose:  There are NUMUSERS copies of this thread to act   *
 *            as consumers of the resource. The thread waits for*
 *            exclusive access to the resource and colors it.   *
 *                                                              *
 *  Usage:    Threads created by StartSemExample.               *
 *                                                              *
 *  Method:   Waits for mutex to gain ownership of resource.    *
 *            Releases resource when user event. Dies when      *
 *            Stop event.                                       *
 *  Returns:                                                    *
 *                                                              *
\****************************************************************/
VOID ThreadConsumer( PVOID pvMyID )
{
   ULONG  ulPostCnt;
   ULONG  ulUser=0L;
   ULONG  rc;
   HAB    habb;
   HMQ    hmqq;

   /* Need a message queue for any thread that wants to print messages. */
   habb = WinInitialize(0);
   hmqq = WinCreateMsgQueue(habb,0);

   /* while the user has not selected stop ... */
   while ((DosWaitEventSem(hevStop,SEM_IMMEDIATE_RETURN)) == ERROR_TIMEOUT)
   {
      /* Wait for exclusive ownership of resource */

      DosRequestMutexSem(hmtxOwnResource,SEM_INDEFINITE_WAIT);

      /* the following check is necessary because the stop semaphore
       * may have been posted  while we were waiting on the mutex
       */
      if (DosWaitEventSem(hevStop, SEM_IMMEDIATE_RETURN) == ERROR_TIMEOUT)
      {
      /*********************************************************************\
       * an item is ready, which one?  don't wait forever because there is *
       * a possibility that the stop semaphore was posted and that no more *
       * resource is forthcoming. we wait twice as long as we think is     *
       * necessary.                                                        *
      \*********************************************************************/
         if (!DosWaitMuxWaitSem (hmuxResource, max (ulTimeout << 1,
            TIMEOUTPERIOD) , &ulUser))
         {
            MyMove ((ULONG) pvMyID, ulUser);
            DosResetEventSem(aSquares[ulUser].hev, &ulPostCnt);
         }
      }
                               /* Let some other thread have resource. */
      rc = DosReleaseMutexSem(hmtxOwnResource);
      if (rc)
      {
         SemError("DosReleaseMutexSem",rc);
      }
   }
   /* hevStop was posted, kill this thread */
   WinDestroyMsgQueue (hmqq);
   WinTerminate (habb);
   DosExit(EXIT_THREAD, 0);
   return;
}
Esempio n. 23
0
int main(
/*******/
    void
) {
    QMSG                qmsg;

    Main_hab = WinInitialize( 0 );
    if( !Main_hab ) {
        return( FALSE );
    }

    Main_hmq = WinCreateMsgQueue( Main_hab, 0 );
    if( !Main_hmq ) {
        return( FALSE );
    }

    if( !init_app( Main_hab ) ) {
        return( FALSE );
    }

    /* Perform initializations that apply to a specific instance */

    three_d_init();
    define_room();
    if (!init_instance( SWP_SHOW | SWP_ACTIVATE ) ) {
        finish_room();
        three_d_fini();
        return( FALSE );
    }

    /* Acquire and dispatch messages until a WM_QUIT message is received. */

    while( WinGetMsg( Main_hab, &qmsg, NULL, NULL, NULL) ) {
        WinDispatchMsg( Main_hab, &qmsg );
    }
    finish_room();
    three_d_fini();

    if( Main_hmq ) {
      WinDestroyMsgQueue( Main_hmq );
    }
    if( Main_hab ) {
      WinTerminate( Main_hab );
    }

    DosExit( EXIT_PROCESS, 0);

    return( SHORT1FROMMP( qmsg.mp1 ) );
}
Esempio n. 24
0
_WCRTLINK _NORETURN void __exit( unsigned ret_code )
{
    __OS2Fini(); // must be done before following finalizers get called
    if( __Is_DLL ) {
        if( __process_fini != NULL ) {
            (*__process_fini)( 0, FINI_PRIORITY_EXIT - 1 );
        }
    } else {
        __FiniRtns( 0, FINI_PRIORITY_EXIT - 1 );
        __shutdown_stack_checking();
    }

    DosExit( EXIT_PROCESS, ret_code );
    // never return
}
/****************************************************************\
 * Routine to run Auto mode.                                    *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:     RunAuto(PVOID pvArg)                              *
 *                                                              *
 *  Purpose:  Posts user event at fixed time interval to signal *
 *            consumers to release resource.                    *
 *                                                              *
 *  Usage:    Thread created by SetAutoMode.                    *
 *                                                              *
 *  Method:   Kills itself when StopAutoMode semaphore is       *
 *            posted.                                           *
 *                                                              *
 *  Returns:                                                    *
 *                                                              *
\****************************************************************/
VOID RunAuto( PVOID pvArg )
{
   ULONG rcWait;
   HAB habLocal;
   HMQ hmqLocal;
   INT i;

   /* Need a message queue for any thread that wants to print messages. */

   habLocal = WinInitialize(0);
   hmqLocal = WinCreateMsgQueue(habLocal,0);

   /* while stop auto semaphore not posted, post user event semaphore. */

      /***************************************************************
       * Don't check return code from DosPostEventSem(hevUserEvent)  *
       * since we just want the resource to change hands.  We don't  *
       * care if it changes hands exactly every time it goes through *
       * the loop.                                                   *
       *                                                             *
       * The event may already be posted if the system is busy and   *
       * the resource threads don't finish with it fast enough.      *
       * This is not a problem in this case.                         *
       ***************************************************************/

   do {                      /* if ulTimeout is zero, still waitevent
                                 for 1 msec to force yielding of CPU. */
       rcWait = DosWaitEventSem(hevStopAuto, max (ulTimeout, 1));
       if (rcWait == ERROR_TIMEOUT)
       {
           i = rand () % MAXRESOURCES;      /* generate it */
           DosPostEventSem (aSquares[i].hev);
       }
   } while (rcWait == ERROR_TIMEOUT);

   /* If there was an error, print a message */

   if (rcWait)
   {
      SemError("DosWaitEventSem",rcWait);
   }

   WinDestroyMsgQueue (hmqLocal);
   WinTerminate (habLocal);
   DosExit(EXIT_THREAD,0);

   return;
}
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 */
Esempio n. 27
0
int main (VOID) {

   ULONG   aulFSInfoBuf[40] = {0};         /* File system info buffer     */

   APIRET  rc               = NO_ERROR;    /* Return code                 */



   rc = DosQueryFSInfo(3L,                     /* Drive number 3 (C:)     */

                       FSIL_ALLOC,             /* Level 1 allocation info */

                       (PVOID)aulFSInfoBuf,    /* Buffer                  */

                       sizeof(aulFSInfoBuf));  /* Size of buffer          */



   if (rc != NO_ERROR) {

      printf("DosQueryFSInfo error: return code = %u\n", rc);

      return 1;

   } else {

      printf ("%12ld bytes in each allocation unit.\n",

               aulFSInfoBuf[1] * (USHORT)aulFSInfoBuf[4]);

             /* (Sectors per allocation unit) * (Bytes per sector) */

      printf ("%12ld total allocation units.\n", aulFSInfoBuf[2]);

      printf ("%12ld available allocation units on disk.\n", aulFSInfoBuf[3]);

   }

   DosExit(EXIT_THREAD,aulFSInfoBuf[3]);  /* Return available allocation units

                                             to the initiating process      */

   return NO_ERROR;

}
Esempio n. 28
0
  /* --- error handler ---
  **       parameter is disk handle as returned from opendrive()
  **       prints system error message if possible, closes the disk
  **        handle if neccessary, gets a key stroke, and exits.
  */
void errorexit(HFILE hf)
  {
  USHORT cbBuf;
  CHAR   *msgBuf;

  if (_DosError == DSKCPY_ERROR_WRONG_FORMAT)
    {
    /* Special handling for this non-fatal error */
    fprintf(stderr, "\nThe TARGET disk is not the correct format!");
    fprintf(stderr, "\nStrike any key to return to menu..");
    getch();
    fprintf(stderr, "\n\n");
    return;
    }

#if defined (DSKCPY_ERROR_CANT_FORMAT)
  if (_DosError == DSKCPY_ERROR_CANT_FORMAT)
    {
    /* Special handling for this non-fatal error */
    fprintf(stderr, "\nThe TARGET disk must be preformatted!");
    fprintf(stderr, "\nStrike any key to return to menu..");
    getch();
    fprintf(stderr, "\n\n");
    return;
    }
#endif

  puts("");
  if ((msgBuf = (PCHAR)calloc(BUFSIZE, sizeof(CHAR))) != NULL)
    {
    DosGetMessage(NULL, 0, msgBuf, BUFSIZE, _DosError, "oso001.msg", &cbBuf);
    fputs(msgBuf, stderr);
    free(msgBuf);
    }
  else
    fprintf(stderr, "SYS%04d: error text unavailable\n", _DosError);

  if (hf) DosClose(hf);
  fprintf(stderr, "Strike any key to exit..");
  getch();
  fprintf(stderr, "\n");
  DosExit(EXIT_PROCESS, _DosError);
  }
VOID Installer_InstallerThread( VOID )
{
 // Определяем поток в системе.
 HAB Thread = WinInitialize( 0 );
 Installer_Thread.Installer_anchor = Thread;

 // Если это сделать не удалось - выход.
 if( Thread == NULLHANDLE ) return;

 // Создаем очередь сообщений - она должна быть в каждом потоке.
 {
  HMQ Messages_queue = WinCreateMsgQueue( Thread, 0 );
  Installer_Thread.Installer_queue = Messages_queue;

  // Если очередь создать не удалось - выход.
  if( Messages_queue == NULLHANDLE )
   {
    WinTerminate( Thread );
    return;
   }
 }

 // Отключаем кнопки
 WinPostMsg( Installer.Client_window, MY_ENABLE_BUTTONS, 0, 0 );

 // Вызываем приложение на Rexx.
 Installer_ExecuteScript();

 // Включаем кнопки
 WinPostMsg( Installer.Client_window, MY_ENABLE_BUTTONS, (MPARAM) 1, 0 );

 // Закрываем окно.
 WinPostMsg( Installer.Frame_window, WM_SYSCOMMAND, (MPARAM) SC_CLOSE, 0 );

 // Поток завершен.
 Installer_Thread.Processing = 0;

 // Завершаем поток.
 WinDestroyMsgQueue( Installer_Thread.Installer_queue );
 WinTerminate( Installer_Thread.Installer_anchor );
 Installer_Thread.Installer = NULLHANDLE;
 DosExit( EXIT_THREAD, 0 );
}
/****************************************************************\
 * Routine to really stop semaphore example.                    *
 *--------------------------------------------------------------*
 *                                                              *
 *  Name:     StopSemaphore( PVOID pvArg )                      *
 *                                                              *
 *  Purpose:  Waits for threads to complete,                    *
 *            Sends message to message thread to indicate this  *
 *            has occurred, and exits.                          *
 *                                                              *
 *  Usage:    Exec'd from BeginStop when user selects Stop from *
 *            Semaphore menu.                                   *
 *                                                              *
 *  Method:   Turns off Auto mode, if present by posting auto   *
 *            semaphore.  Then stop event is posted.  Waits     *
 *            for threads to die.                               *
 *  Returns:                                                    *
 *                                                              *
\****************************************************************/
VOID StopSemaphore( PVOID pvArg )
{
   ULONG rc,usCount, i;
   PULONG pfAutoMode = (PULONG)pvArg;

   if (*pfAutoMode)
   {
      rc = DosWaitThread(&tidAutoThread,0L);
      if (rc && (rc != ERROR_INVALID_THREADID))
      {
         SemError("DosWaitThread",rc);
      }
      *pfAutoMode = FALSE;
   }
   /* Wait for usConsumer threads to die.  Order of death not important. */

   for (usCount = 0; usCount < usConsumerThreadsCreated; usCount++)
   {
      rc = DosWaitThread(&thrConsumers[usCount].tid,0L);

      /* rc is ERROR_INVALID_THREADID the thread is already dead.*\
      \* This is OK and not a error.                             */

      if (rc && (rc != ERROR_INVALID_THREADID))
      {
         SemError("DosWaitThread",rc);
      }
   }
                /* Threads dead so we don't need semaphores any more.  */
   DosCloseEventSem(hevStopAuto);
   DosCloseEventSem(hevStop);
   DosCloseMutexSem(hmtxOwnResource);
   for (i = 0; i < MAXRESOURCES; i++)
   {
      DosCloseEventSem(aSquares[i].hev);
   }
   DosCloseMuxWaitSem (hmuxResource);
   WinPostMsg (hwndMain, WM_COMMAND, (MPARAM)IDM_STOPFINISHED, (MPARAM)NULL);
   DosExit (EXIT_THREAD, 0);
   return;
}