Ignore:
Timestamp:
Oct 20, 2000, 1:46:48 PM (25 years ago)
Author:
sandervl
Message:

basic support for VIO console command line apps added + FormatMessage addition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/console.cpp

    r3976 r4502  
    1 /* $Id: console.cpp,v 1.21 2000-08-10 02:19:54 phaller Exp $ */
     1/* $Id: console.cpp,v 1.22 2000-10-20 11:46:46 sandervl Exp $ */
    22
    33/*
     
    6565#define  INCL_DOSMODULEMGR
    6666#define  INCL_VIO
     67#define  INCL_KBD
    6768#define  INCL_AVIO
    6869#include <os2wrap.h>         //Odin32 OS/2 api wrappers
    6970
    7071#include <win32type.h>
     72#include <win32api.h>
    7173#include <misc.h>
    7274
     
    8082#include "conout.h"
    8183#include "conbuffer.h"
     84#include "conbuffervio.h"
    8285
    8386#include "conprop.h"
     
    8588#include "heapstring.h"
    8689
    87 #define DBG_LOCALLOG    DBG_console
     90#define DBG_LOCALLOG    DBG_console
    8891#include "dbglocal.h"
    8992
    90 
    91 /***********************************
    92  * PH: fixups for missing os2win.h *
    93  ***********************************/
    94 
    9593#include <os2sel.h>
    96 
    97 extern "C"
    98 {
    99   void   _System _O32_SetLastError(DWORD  dwError);
    100   DWORD  _System _O32_GetLastError(void);
    101   LPSTR  _System _O32_GetCommandLine(void);
    102   void   _System _O32_ExitProcess(UINT exitcode);
    103   HANDLE _System _O32_GetStdHandle(DWORD dwDevice);
    104   DWORD  _System _O32_GetFileType(HANDLE hFile);
    105 
    106 inline void SetLastError(DWORD a)
    107 {
    108  USHORT sel = GetFS();
    109 
    110     _O32_SetLastError(a);
    111     SetFS(sel);
    112 }
    113 
    114 inline DWORD GetLastError()
    115 {
    116  DWORD yyrc;
    117  USHORT sel = GetFS();
    118 
    119     yyrc = _O32_GetLastError();
    120     SetFS(sel);
    121 
    122     return yyrc;
    123 }
    124 
    125 inline LPSTR GetCommandLine()
    126 {
    127  LPSTR yyrc;
    128  USHORT sel = GetFS();
    129 
    130     yyrc = _O32_GetCommandLine();
    131     SetFS(sel);
    132 
    133     return yyrc;
    134 }
    135 
    136 inline void ExitProcess(UINT a)
    137 {
    138  USHORT sel = GetFS();
    139 
    140     _O32_ExitProcess(a);
    141     SetFS(sel);
    142 }
    143 
    144 inline HANDLE GetStdHandle(DWORD a)
    145 {
    146  HANDLE yyrc;
    147  USHORT sel = GetFS();
    148 
    149     yyrc = _O32_GetStdHandle(a);
    150     SetFS(sel);
    151 
    152     return yyrc;
    153 }
    154 
    155 inline DWORD GetFileType(HANDLE a)
    156 {
    157  DWORD yyrc;
    158  USHORT sel = GetFS();
    159 
    160     yyrc = _O32_GetFileType(a);
    161     SetFS(sel);
    162 
    163     return yyrc;
    164 }
    165 
    166 }
    16794
    16895/*****************************************************************************
     
    181108static ICONSOLEGLOBALS ConsoleGlobals;
    182109static ICONSOLEINPUT   ConsoleInput;
    183 
     110       BOOL            flVioConsole = FALSE;
    184111
    185112/*****************************************************************************
     
    247174 *****************************************************************************/
    248175
    249 APIRET iConsoleInit(void)               /* creation of the console subsystem */
    250 {
    251   APIRET rc;                                              /* API return code */
     176APIRET iConsoleInit(BOOL fVioConsole)              /* creation of the console subsystem */
     177{
     178  APIRET rc;                                       /* API return code */
    252179  ULONG  ulPostCount;                              /* semaphore post counter */
    253180
    254181
     182  flVioConsole = fVioConsole;
    255183
    256184  if (ConsoleGlobals.hevConsole != NULLHANDLE) /* we're already initialized ?*/
    257185    return (NO_ERROR);                             /* then abort immediately */
    258186
    259                                  /* create console synchronization semaphore */
    260   rc = DosCreateEventSem (NULL,
    261                           &ConsoleGlobals.hevConsole,
    262                           0L,                        /* semaphore is private */
    263                           FALSE);                             /* reset state */
    264   if (rc != NO_ERROR)                                       /* other error ? */
    265     return (rc);                                    /* raise error condition */
    266 
    267 
    268                                      /* create console input queue semaphore */
    269   rc = DosCreateEventSem (NULL,
    270                           &ConsoleInput.hevInputQueue,
    271                           0L,                        /* semaphore is private */
    272                           FALSE);                             /* reset state */
    273   if (rc != NO_ERROR)                                       /* other error ? */
     187  if(flVioConsole == TRUE)
    274188  {
    275     DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
    276     return (rc);                                    /* raise error condition */
     189    /***************************************************************************
     190    * Create pseudo-devices and initialize ConsoleGlobals                     *
     191    ***************************************************************************/
     192
     193    rc = iConsoleDevicesRegister();                /* ensure devices are there */
     194    if (rc != NO_ERROR)                                    /* check for errors */
     195    {
     196        return (rc);                                    /* raise error condition */
     197    }
     198    rc = DosCreateMutexSem(NULL,
     199                             &ConsoleInput.hmtxInputQueue,
     200                             0L,
     201                             FALSE);
     202    if (rc != NO_ERROR)                                       /* other error ? */
     203    {
     204        return (rc);                                    /* raise error condition */
     205    }
     206
     207    return NO_ERROR;
    277208  }
    278 
    279 
    280   rc = DosCreateMutexSem(NULL,
    281                          &ConsoleInput.hmtxInputQueue,
    282                          0L,
    283                          FALSE);
    284   if (rc != NO_ERROR)                                       /* other error ? */
    285   {
    286     DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
    287     DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
    288     return (rc);                                    /* raise error condition */
     209  else {
     210    /* create console synchronization semaphore */
     211    rc = DosCreateEventSem (NULL,
     212                            &ConsoleGlobals.hevConsole,
     213                            0L,                        /* semaphore is private */
     214                            FALSE);                             /* reset state */
     215    if (rc != NO_ERROR)                                       /* other error ? */
     216        return (rc);                                    /* raise error condition */
     217
     218
     219                                         /* create console input queue semaphore */
     220    rc = DosCreateEventSem (NULL,
     221                              &ConsoleInput.hevInputQueue,
     222                              0L,                        /* semaphore is private */
     223                              FALSE);                             /* reset state */
     224    if (rc != NO_ERROR)                                       /* other error ? */
     225    {
     226        DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
     227        return (rc);                                    /* raise error condition */
     228    }
     229
     230
     231    rc = DosCreateMutexSem(NULL,
     232                             &ConsoleInput.hmtxInputQueue,
     233                             0L,
     234                             FALSE);
     235    if (rc != NO_ERROR)                                       /* other error ? */
     236    {
     237        DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
     238        DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
     239        return (rc);                                    /* raise error condition */
     240    }
     241
     242    /***************************************************************************
     243    * Create pseudo-devices and initialize ConsoleGlobals                     *
     244    ***************************************************************************/
     245
     246    rc = iConsoleDevicesRegister();                /* ensure devices are there */
     247    if (rc != NO_ERROR)                                    /* check for errors */
     248    {
     249        DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
     250        DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
     251        return (rc);                                    /* raise error condition */
     252    }
     253
     254
     255    /***************************************************************************
     256    * Presentation Manager Initialization phase                               *
     257    ***************************************************************************/
     258
     259        /* OK, we're about to initialize the console subsystem for this process. */
     260                               /* start message thread for console object window */
     261    ConsoleGlobals.tidConsole = _beginthread(iConsoleMsgThread,
     262                                               NULL,
     263                                               12288,
     264                                               NULL);
     265                                       /* has the thread been created properly ? */
     266    if (ConsoleGlobals.tidConsole == -1)
     267    {
     268        DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
     269        DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close event semaphore */
     270        ConsoleGlobals.hevConsole = NULLHANDLE;         /* for ConsoleIsActive() */
     271        return (rc);                                    /* raise error condition */
     272    }
     273    else
     274        DosSetPriority(PRTYS_THREAD,                             /* set priority */
     275                       ConsoleGlobals.Options.ulConsoleThreadPriorityClass,
     276                       ConsoleGlobals.Options.ulConsoleThreadPriorityDelta,
     277                       ConsoleGlobals.tidConsole);
     278
     279
     280                          /* wait for the child thread to do it's initialization */
     281                                                  /* timeout isn't really useful */
     282    rc = DosWaitEventSem(ConsoleGlobals.hevConsole,
     283                           SEM_INDEFINITE_WAIT);
     284    if (rc != NO_ERROR)                                    /* check for errors */
     285    {
     286        DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
     287        DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close event semaphore */
     288        ConsoleGlobals.hevConsole = NULLHANDLE;         /* for ConsoleIsActive() */
     289        return (rc);                                    /* raise error condition */
     290    }
     291
     292    DosResetEventSem(ConsoleGlobals.hevConsole,       /* reset event semaphore */
     293                       &ulPostCount);
     294
     295    rc = ConsoleGlobals.rcConsole;   /* pass thru console thread's return code */
     296
     297    return (rc);                                                         /* OK */
    289298  }
    290 
    291   /***************************************************************************
    292    * Create pseudo-devices and initialize ConsoleGlobals                     *
    293    ***************************************************************************/
    294 
    295   rc = iConsoleDevicesRegister();                /* ensure devices are there */
    296   if (rc != NO_ERROR)                                    /* check for errors */
    297   {
    298     DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close other semaphore */
    299     DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
    300     return (rc);                                    /* raise error condition */
    301   }
    302 
    303 
    304   /***************************************************************************
    305    * Presentation Manager Initialization phase                               *
    306    ***************************************************************************/
    307 
    308     /* OK, we're about to initialize the console subsystem for this process. */
    309                            /* start message thread for console object window */
    310   ConsoleGlobals.tidConsole = _beginthread(iConsoleMsgThread,
    311                                            NULL,
    312                                            12288,
    313                                            NULL);
    314                                    /* has the thread been created properly ? */
    315   if (ConsoleGlobals.tidConsole == -1)
    316   {
    317     DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
    318     DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close event semaphore */
    319     ConsoleGlobals.hevConsole = NULLHANDLE;         /* for ConsoleIsActive() */
    320     return (rc);                                    /* raise error condition */
    321   }
    322   else
    323     DosSetPriority(PRTYS_THREAD,                             /* set priority */
    324                    ConsoleGlobals.Options.ulConsoleThreadPriorityClass,
    325                    ConsoleGlobals.Options.ulConsoleThreadPriorityDelta,
    326                    ConsoleGlobals.tidConsole);
    327 
    328 
    329                       /* wait for the child thread to do it's initialization */
    330                                               /* timeout isn't really useful */
    331   rc = DosWaitEventSem(ConsoleGlobals.hevConsole,
    332                        SEM_INDEFINITE_WAIT);
    333   if (rc != NO_ERROR)                                    /* check for errors */
    334   {
    335     DosCloseEventSem(ConsoleInput.hevInputQueue);   /* close other semaphore */
    336     DosCloseEventSem(ConsoleGlobals.hevConsole);    /* close event semaphore */
    337     ConsoleGlobals.hevConsole = NULLHANDLE;         /* for ConsoleIsActive() */
    338     return (rc);                                    /* raise error condition */
    339   }
    340 
    341   DosResetEventSem(ConsoleGlobals.hevConsole,       /* reset event semaphore */
    342                    &ulPostCount);
    343 
    344   rc = ConsoleGlobals.rcConsole;   /* pass thru console thread's return code */
    345 
    346   return (rc);                                                         /* OK */
    347299}
    348300
     
    397349  ConsoleGlobals.coordWindowPos.X                = 0;
    398350  ConsoleGlobals.coordWindowPos.Y                = 0;
     351  if(flVioConsole == TRUE) {
     352        VIOMODEINFO videoinfo;
     353
     354        videoinfo.cb = sizeof(VIOMODEINFO);
     355        rc = VioGetMode(&videoinfo, 0);
     356        if(rc == 0) {
     357            dprintf(("video mode (%d,%d)", videoinfo.col, videoinfo.row));
     358            ConsoleGlobals.coordWindowSize.X = videoinfo.col;
     359            ConsoleGlobals.coordWindowSize.Y = videoinfo.row;
     360        }
     361  }
    399362
    400363
     
    410373
    411374                                                   /* generate copy of title */
    412   ConsoleGlobals.pszWindowTitle = strdup(GetCommandLine());
     375  ConsoleGlobals.pszWindowTitle = strdup(GetCommandLineA());
    413376
    414377                                    /* obtain module handle to our resources */
     
    428391
    429392
    430   // defaults are effective, try to read and apply stored properties
    431   if (ConsolePropertyLoad(&ConsoleGlobals.Options) == NO_ERROR)
    432     ConsolePropertyApply(&ConsoleGlobals.Options);
     393  if (flVioConsole == FALSE)
     394  {
     395    // defaults are effective, try to read and apply stored properties
     396    if (ConsolePropertyLoad(&ConsoleGlobals.Options) == NO_ERROR)
     397        ConsolePropertyApply(&ConsoleGlobals.Options);
     398  }
    433399
    434400
     
    437403   ***************************************************************************/
    438404
    439                    /* create devices and register devices with handlemanager */
    440 
    441     pHMDeviceConsoleIn  = new HMDeviceConsoleInClass("CONIN$",
    442                                                      &ConsoleInput,
    443                                                      &ConsoleGlobals);
    444     rc = HMDeviceRegister ("CONIN$",
    445                            pHMDeviceConsoleIn);
    446     if (rc != NO_ERROR)                                  /* check for errors */
     405  /* create devices and register devices with handlemanager */
     406  pHMDeviceConsoleIn  = new HMDeviceConsoleInClass("CONIN$",
     407                                                   &ConsoleInput,
     408                                                   &ConsoleGlobals);
     409
     410  rc = HMDeviceRegister ("CONIN$",
     411                         pHMDeviceConsoleIn);
     412  if (rc != NO_ERROR)                                  /* check for errors */
    447413      dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONIN$ failed with %u.\n",
    448414               rc));
    449415
    450416
    451     pHMDeviceConsoleOut = new HMDeviceConsoleOutClass("CONOUT$",
    452                                                       &ConsoleInput,
    453                                                       &ConsoleGlobals);
    454     rc = HMDeviceRegister ("CONOUT$",
    455                            pHMDeviceConsoleOut);
    456     if (rc != NO_ERROR)                                  /* check for errors */
     417  pHMDeviceConsoleOut = new HMDeviceConsoleOutClass("CONOUT$",
     418                                                    &ConsoleInput,
     419                                                    &ConsoleGlobals);
     420  rc = HMDeviceRegister ("CONOUT$",
     421                         pHMDeviceConsoleOut);
     422  if (rc != NO_ERROR)                                  /* check for errors */
    457423      dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONOUT$ failed with %u.\n",
    458424               rc));
    459425
    460 
    461     pHMDeviceConsoleBuffer = new HMDeviceConsoleBufferClass("CONBUFFER$",
    462                                                             &ConsoleInput,
    463                                                             &ConsoleGlobals);
    464     rc = HMDeviceRegister ("CONBUFFER$",
    465                            pHMDeviceConsoleBuffer);
    466     if (rc != NO_ERROR)                                  /* check for errors */
     426  if(flVioConsole == TRUE)
     427  {
     428        pHMDeviceConsoleBuffer = (HMDeviceConsoleBufferClass *)new HMDeviceConsoleVioBufferClass("CONBUFFER$",
     429                                                                                                 &ConsoleInput,
     430                                                                                                 &ConsoleGlobals);
     431  }
     432  else {
     433        pHMDeviceConsoleBuffer = new HMDeviceConsoleBufferClass("CONBUFFER$",
     434                                                                &ConsoleInput,
     435                                                                &ConsoleGlobals);
     436  }
     437  rc = HMDeviceRegister ("CONBUFFER$",
     438                         pHMDeviceConsoleBuffer);
     439  if (rc != NO_ERROR)                                  /* check for errors */
    467440      dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONBUFFER$ failed with %u.\n",
    468441               rc));
    469442
    470443
    471       /***********************************************************************
    472        * initialize stdin handle                                             *
    473        ***********************************************************************/
    474       hStandardIn = GetStdHandle(STD_INPUT_HANDLE);
    475       dwType = GetFileType(hStandardIn);
    476       if (dwType == FILE_TYPE_CHAR)                /* is handle redirected ? */
    477         hStandardIn = HMCreateFile("CONIN$",
    478                                    GENERIC_READ | GENERIC_WRITE,
    479                                    FILE_SHARE_READ | FILE_SHARE_WRITE,
    480                                    NULL,
    481                                    0,
    482                                    CONSOLE_TEXTMODE_BUFFER,
    483                                    0);
    484 
    485       HMSetStdHandle(STD_INPUT_HANDLE,
    486                      hStandardIn);
    487 
    488       /***********************************************************************
    489        * initialize stdout handle                                            *
    490        ***********************************************************************/
    491       hStandardOut = GetStdHandle(STD_OUTPUT_HANDLE);
    492       dwType = GetFileType(hStandardOut);
    493       if (dwType == FILE_TYPE_CHAR)                /* is handle redirected ? */
    494         hStandardOut = HMCreateFile("CONOUT$",
    495                                    GENERIC_READ | GENERIC_WRITE,
    496                                    FILE_SHARE_READ | FILE_SHARE_WRITE,
    497                                    NULL,
    498                                    0,
    499                                    CONSOLE_TEXTMODE_BUFFER,
    500                                    0);
    501 
    502       HMSetStdHandle(STD_OUTPUT_HANDLE,
    503                      hStandardOut);
    504 
    505 
    506       /***********************************************************************
    507        * initialize stderr handle                                            *
    508        ***********************************************************************/
    509       hStandardError = GetStdHandle(STD_ERROR_HANDLE);
    510       dwType = GetFileType(hStandardError);
    511       if (dwType == FILE_TYPE_CHAR)                /* is handle redirected ? */
    512         hStandardError = HMCreateFile("CONOUT$",
    513                                    GENERIC_READ | GENERIC_WRITE,
    514                                    FILE_SHARE_READ | FILE_SHARE_WRITE,
    515                                    NULL,
    516                                    0,
    517                                    CONSOLE_TEXTMODE_BUFFER,
    518                                    0);
    519 
    520       HMSetStdHandle(STD_ERROR_HANDLE,
    521                      hStandardError);
     444  /***********************************************************************
     445   * initialize stdin handle                                             *
     446   ***********************************************************************/
     447  hStandardIn = GetStdHandle(STD_INPUT_HANDLE);
     448  dwType = GetFileType(hStandardIn);
     449  if (dwType == FILE_TYPE_CHAR)                /* is handle redirected ? */
     450    hStandardIn = HMCreateFile("CONIN$",
     451                               GENERIC_READ | GENERIC_WRITE,
     452                               FILE_SHARE_READ | FILE_SHARE_WRITE,
     453                               NULL,
     454                               0,
     455                               CONSOLE_TEXTMODE_BUFFER,
     456                               0);
     457
     458  HMSetStdHandle(STD_INPUT_HANDLE,
     459                 hStandardIn);
     460
     461  /***********************************************************************
     462   * initialize stdout handle                                            *
     463   ***********************************************************************/
     464  hStandardOut = GetStdHandle(STD_OUTPUT_HANDLE);
     465  dwType = GetFileType(hStandardOut);
     466  if (dwType == FILE_TYPE_CHAR)                /* is handle redirected ? */
     467    hStandardOut = HMCreateFile("CONOUT$",
     468                                GENERIC_READ | GENERIC_WRITE,
     469                                FILE_SHARE_READ | FILE_SHARE_WRITE,
     470                                NULL,
     471                                0,
     472                                CONSOLE_TEXTMODE_BUFFER,
     473                                0);
     474
     475  HMSetStdHandle(STD_OUTPUT_HANDLE,
     476                 hStandardOut);
     477
     478  /***********************************************************************
     479   * initialize stderr handle                                            *
     480   ***********************************************************************/
     481  hStandardError = GetStdHandle(STD_ERROR_HANDLE);
     482  dwType = GetFileType(hStandardError);
     483  if (dwType == FILE_TYPE_CHAR)                /* is handle redirected ? */
     484    hStandardError = HMCreateFile("CONOUT$",
     485                                  GENERIC_READ | GENERIC_WRITE,
     486                                  FILE_SHARE_READ | FILE_SHARE_WRITE,
     487                                  NULL,
     488                                  0,
     489                                  CONSOLE_TEXTMODE_BUFFER,
     490                                  0);
     491
     492  HMSetStdHandle(STD_ERROR_HANDLE,
     493                 hStandardError);
    522494
    523495  return (NO_ERROR);                                                   /* OK */
     
    542514ULONG iConsoleTerminate(VOID)
    543515{
    544   APIRET rc;
     516  APIRET rc = NO_ERROR;
     517
     518  if(flVioConsole == FALSE)
     519  {
     520    DosCloseEventSem(ConsoleGlobals.hevConsole);      /* close other semaphore */
     521    DosCloseEventSem(ConsoleInput.hevInputQueue);     /* close other semaphore */
     522
     523
     524    WinPostMsg (ConsoleGlobals.hwndFrame,         /* force thread to terminate */
     525                WM_CLOSE,
     526                (MPARAM)NULL,
     527                (MPARAM)NULL);
     528
     529    rc = DosWaitThread(&ConsoleGlobals.tidConsole,/* wait until thd terminates */
     530                       DCWW_WAIT);
     531
     532  }
     533  DosCloseMutexSem(ConsoleInput.hmtxInputQueue);          /* close semaphore */
     534
     535  /* close the consolebuffer handle */
     536  HMCloseHandle(ConsoleGlobals.hConsoleBufferDefault);
     537  free(ConsoleGlobals.pszWindowTitle);   /* free previously allocated memory */
     538
     539  return (rc);                                                         /* OK */
     540}
     541
     542
     543/*****************************************************************************
     544 * Name      : static void ConsoleWaitClose
     545 * Purpose   : Wait for the user to close console window
     546 * Parameters: VOID
     547 * Variables :
     548 * Result    :
     549 * Remark    :
     550 * Status    :
     551 *
     552 * Author    : Patrick Haller [Tue, 1998/02/10 01:55]
     553 *****************************************************************************/
     554
     555void iConsoleWaitClose(void)
     556{
     557  CHAR szBuffer[128];                                /* buffer for the title */
     558  BOOL fResult;                /* result from subsequent calls to Win32 APIs */
     559
     560                                /* check if there is a console window at all */
     561  if (iConsoleIsActive() == FALSE)
     562    return;                                                          /* nope */
     563
     564  if(flVioConsole == TRUE)  //no need to wait for VIO session
     565    return;
     566
     567  strcpy (szBuffer,               /* indicate console process has terminated */
     568          "Completed: ");
     569
     570  fResult = GetConsoleTitleA(szBuffer + 11,/* 11 is length of Completed:_ */
     571                                sizeof(szBuffer) - 11);
     572
     573
     574                                /* Set new title: Win32 Console - Terminated */
     575  fResult = SetConsoleTitleA(szBuffer);
    545576
    546577  DosCloseEventSem(ConsoleGlobals.hevConsole);      /* close other semaphore */
     
    549580
    550581
    551   WinPostMsg (ConsoleGlobals.hwndFrame,         /* force thread to terminate */
    552               WM_CLOSE,
    553               (MPARAM)NULL,
    554               (MPARAM)NULL);
    555 
    556   rc = DosWaitThread(&ConsoleGlobals.tidConsole,/* wait until thd terminates */
    557                      DCWW_WAIT);
    558 
    559                                            /* close the consolebuffer handle */
    560   HMCloseHandle(ConsoleGlobals.hConsoleBufferDefault);
    561   free(ConsoleGlobals.pszWindowTitle);   /* free previously allocated memory */
    562 
    563   return (rc);                                                         /* OK */
    564 }
    565 
    566 
    567 /*****************************************************************************
    568  * Name      : static void ConsoleWaitClose
    569  * Purpose   : Wait for the user to close console window
    570  * Parameters: VOID
    571  * Variables :
    572  * Result    :
    573  * Remark    :
    574  * Status    :
    575  *
    576  * Author    : Patrick Haller [Tue, 1998/02/10 01:55]
    577  *****************************************************************************/
    578 
    579 void iConsoleWaitClose(void)
    580 {
    581   CHAR szBuffer[128];                                /* buffer for the title */
    582   BOOL fResult;                /* result from subsequent calls to Win32 APIs */
    583 
    584                                 /* check if there is a console window at all */
    585   if (iConsoleIsActive() == FALSE)
    586     return;                                                          /* nope */
    587 
    588   strcpy (szBuffer,               /* indicate console process has terminated */
    589           "Completed: ");
    590 
    591   fResult = GetConsoleTitleA(szBuffer + 11,/* 11 is length of Completed:_ */
    592                                 sizeof(szBuffer) - 11);
    593 
    594 
    595                                 /* Set new title: Win32 Console - Terminated */
    596   fResult = SetConsoleTitleA(szBuffer);
    597 
    598   DosCloseEventSem(ConsoleGlobals.hevConsole);      /* close other semaphore */
    599   DosCloseEventSem(ConsoleInput.hevInputQueue);     /* close other semaphore */
    600   DosCloseMutexSem(ConsoleInput.hmtxInputQueue);          /* close semaphore */
    601 
    602 
    603582                                          /* terminate console immediately ? */
    604583  if (ConsoleGlobals.Options.fTerminateAutomatically == FALSE) {
    605         if(getenv("ODIN_AUTOEXITCONSOLE") == NULL) {
    606             DosWaitThread(&ConsoleGlobals.tidConsole,   /* wait until thd terminates */
    607                           DCWW_WAIT);
    608         }
     584    if(getenv("ODIN_AUTOEXITCONSOLE") == NULL) {
     585        DosWaitThread(&ConsoleGlobals.tidConsole,   /* wait until thd terminates */
     586                      DCWW_WAIT);
     587    }
    609588  }
    610589}
     
    625604BOOL iConsoleIsActive(void)
    626605{
     606  if(flVioConsole == TRUE) //actually, this isn't needed in VIO mode
     607     return TRUE;
     608
    627609  return (NULLHANDLE != ConsoleGlobals.hevConsole);
    628610}
     
    854836                       0,
    855837                       0,
    856                        ConsoleGlobals.Options.coordDefaultPosition.X *
     838                       ConsoleGlobals.Options.coordDefaultSize.X *
    857839                         ConsoleGlobals.sCellCX +
    858840                         2 * WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER),
    859                        ConsoleGlobals.Options.coordDefaultPosition.Y *
     841                       ConsoleGlobals.Options.coordDefaultSize.Y *
    860842                         ConsoleGlobals.sCellCY +
    861843                         WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) +
     
    14081390         pInputRecord,
    14091391         sizeof (INPUT_RECORD) );
    1410                                                   /* unblock reading threads */
    1411   rc = DosPostEventSem(ConsoleInput.hevInputQueue);
     1392
     1393  if(flVioConsole == FALSE)
     1394  {     /* unblock reading threads */
     1395        rc = DosPostEventSem(ConsoleInput.hevInputQueue);
     1396  }
     1397  else  rc = 0;
    14121398  return (rc);                                                         /* OK */
    14131399}
     
    19731959 *****************************************************************************/
    19741960
    1975 ULONG iConsoleInputQueryEvents (void)
    1976 {
     1961ULONG iConsoleInputQueryEvents(PICONSOLEINPUT pConsoleInput, int fWait)
     1962{
     1963 ULONG ulPostCounter;                   /* semaphore post counter - ignored */
     1964 APIRET rc;                                               /* API returncode */
     1965
     1966  if(flVioConsole)
     1967  {
     1968    KBDKEYINFO keyinfo;
     1969
     1970        rc = KbdCharIn(&keyinfo, IO_NOWAIT, 0); //grab key if present; don't wait
     1971        if((rc || !(keyinfo.fbStatus & 0x40)) && fWait == QUERY_EVENT_WAIT && ConsoleInput.ulEvents == 0) {
     1972                rc = KbdCharIn(&keyinfo, IO_WAIT, 0);
     1973        }
     1974        while(rc == 0 && (keyinfo.fbStatus & 0x40))
     1975        {
     1976                INPUT_RECORD InputRecord = {0};
     1977
     1978                InputRecord.EventType = KEY_EVENT;
     1979                InputRecord.Event.KeyEvent.wRepeatCount = 1;
     1980                InputRecord.Event.KeyEvent.bKeyDown     = 1;
     1981                InputRecord.Event.KeyEvent.dwControlKeyState = 0;
     1982
     1983                if(keyinfo.fbStatus & 2)
     1984                        InputRecord.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY;
     1985
     1986                if(keyinfo.fsState & (KBDSTF_RIGHTSHIFT|KBDSTF_LEFTSHIFT))
     1987                        InputRecord.Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
     1988
     1989                if(keyinfo.fsState & KBDSTF_LEFTALT)
     1990                        InputRecord.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
     1991
     1992                if(keyinfo.fsState & KBDSTF_RIGHTALT)
     1993                        InputRecord.Event.KeyEvent.dwControlKeyState |= RIGHT_ALT_PRESSED;
     1994
     1995                if(keyinfo.fsState & KBDSTF_LEFTCONTROL)
     1996                    InputRecord.Event.KeyEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
     1997
     1998                if(keyinfo.fsState & KBDSTF_RIGHTCONTROL)
     1999                    InputRecord.Event.KeyEvent.dwControlKeyState |= RIGHT_CTRL_PRESSED;
     2000
     2001                if(keyinfo.fsState & KBDSTF_CAPSLOCK_ON)
     2002                    InputRecord.Event.KeyEvent.dwControlKeyState |= CAPSLOCK_ON;
     2003
     2004                if(keyinfo.fsState & KBDSTF_SCROLLLOCK_ON)
     2005                    InputRecord.Event.KeyEvent.dwControlKeyState |= SCROLLLOCK_ON;
     2006
     2007                if(keyinfo.fsState & KBDSTF_NUMLOCK_ON)
     2008                    InputRecord.Event.KeyEvent.dwControlKeyState |= NUMLOCK_ON;
     2009
     2010                InputRecord.Event.KeyEvent.wVirtualKeyCode  = 0;
     2011                InputRecord.Event.KeyEvent.wVirtualScanCode = keyinfo.chScan;
     2012                InputRecord.Event.KeyEvent.uChar.AsciiChar  = keyinfo.chChar;
     2013
     2014                rc = iConsoleInputEventPush(&InputRecord);          /* add it to the queue */
     2015                if(rc) {
     2016                    dprintf(("WARNING: lost key!!"));
     2017                    break;
     2018                }
     2019
     2020                rc = KbdCharIn(&keyinfo, IO_NOWAIT, 0); //grab key if present; don't wait
     2021        }
     2022  }
     2023  else
     2024  if(fWait == QUERY_EVENT_WAIT && ConsoleInput.ulEvents == 0)
     2025  {
     2026        rc = DosWaitEventSem(pConsoleInput->hevInputQueue,      /* wait for input */
     2027                             SEM_INDEFINITE_WAIT);
     2028        DosResetEventSem(pConsoleInput->hevInputQueue,         /* reset semaphore */
     2029                         &ulPostCounter);              /* post counter - ignored */
     2030  }
    19772031  return (ConsoleInput.ulEvents);        /* return number of events in queue */
    19782032}
     
    22772331#endif
    22782332
    2279   rc = iConsoleInit();                   /* initialize subsystem if required */
    2280   if (rc != NO_ERROR)                                    /* check for errors */
     2333  rc = iConsoleInit(flVioConsole);               /* initialize subsystem if required */
     2334  if (rc != NO_ERROR)                            /* check for errors */
    22812335  {
    22822336    SetLastError(rc);                            /* pass thru the error code */
     
    23102364
    23112365HANDLE WIN32API CreateConsoleScreenBuffer(DWORD  dwDesiredAccess,
    2312                                              DWORD  dwShareMode,
    2313                                              LPVOID lpSecurityAttributes,
    2314                                              DWORD  dwFlags,
    2315                                              LPVOID lpScreenBufferData)
     2366                                          DWORD  dwShareMode,
     2367                                          LPVOID lpSecurityAttributes,
     2368                                          DWORD  dwFlags,
     2369                                          LPVOID lpScreenBufferData)
    23162370{
    23172371  HANDLE hResult;
     
    25392593
    25402594BOOL WIN32API GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
    2541                                           DWORD dwProcessGroupId)
     2595                                       DWORD dwProcessGroupId)
    25422596{
    25432597#ifdef DEBUG_LOCAL2
     
    26762730
    26772731BOOL WIN32API GetConsoleScreenBufferInfo(HANDLE                      hConsoleOutput,
    2678                                             PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
     2732                                         PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
    26792733{
    26802734  BOOL fResult;
     
    28192873
    28202874BOOL WIN32API GetNumberOfConsoleInputEvents(HANDLE  hConsoleInput,
    2821                                                LPDWORD lpNumberOfEvents)
     2875                                            LPDWORD lpNumberOfEvents)
    28222876{
    28232877  BOOL fResult;
     
    29212975
    29222976BOOL WIN32API PeekConsoleInputA(HANDLE        hConsoleInput,
    2923                                    PINPUT_RECORD pirBuffer,
    2924                                    DWORD         cInRecords,
    2925                                    LPDWORD       lpcRead)
     2977                                PINPUT_RECORD pirBuffer,
     2978                                DWORD         cInRecords,
     2979                                LPDWORD       lpcRead)
    29262980{
    29272981  BOOL fResult;
     
    29593013
    29603014BOOL WIN32API ReadConsoleA(HANDLE  hConsoleInput,
    2961                               LPVOID  lpvBuffer,
    2962                               DWORD   cchToRead,
    2963                               LPDWORD lpcchRead,
    2964                               LPVOID  lpvReserved)
     3015                           LPVOID  lpvBuffer,
     3016                           DWORD   cchToRead,
     3017                           LPDWORD lpcchRead,
     3018                           LPVOID  lpvReserved)
    29653019{
    29663020  BOOL fResult;
     
    29993053
    30003054BOOL WIN32API ReadConsoleW(HANDLE  hConsoleInput,
    3001                               LPVOID  lpvBuffer,
    3002                               DWORD   cchToRead,
    3003                               LPDWORD lpcchRead,
    3004                               LPVOID  lpvReserved)
     3055                           LPVOID  lpvBuffer,
     3056                           DWORD   cchToRead,
     3057                           LPDWORD lpcchRead,
     3058                           LPVOID  lpvReserved)
    30053059{
    30063060  BOOL fResult;
     
    30393093
    30403094BOOL WIN32API ReadConsoleInputA(HANDLE        hConsoleInput,
    3041                                    PINPUT_RECORD pirBuffer,
    3042                                    DWORD         cInRecords,
    3043                                    LPDWORD       lpcRead)
     3095                                PINPUT_RECORD pirBuffer,
     3096                                DWORD         cInRecords,
     3097                                LPDWORD       lpcRead)
    30443098{
    30453099  BOOL fResult;
     
    30773131
    30783132BOOL WIN32API ReadConsoleInputW(HANDLE        hConsoleInput,
    3079                                    PINPUT_RECORD pirBuffer,
    3080                                    DWORD         cInRecords,
    3081                                    LPDWORD       lpcRead)
     3133                                PINPUT_RECORD pirBuffer,
     3134                                DWORD         cInRecords,
     3135                                LPDWORD       lpcRead)
    30823136{
    30833137  BOOL fResult;
     
    31153169
    31163170BOOL WIN32API ReadConsoleOutputA(HANDLE      hConsoleOutput,
    3117                                     PCHAR_INFO  pchiDestBuffer,
    3118                                     COORD       coordDestBufferSize,
    3119                                     COORD       coordDestBufferCoord,
    3120                                     PSMALL_RECT psrctSourceRect)
     3171                                 PCHAR_INFO  pchiDestBuffer,
     3172                                 COORD       coordDestBufferSize,
     3173                                 COORD       coordDestBufferCoord,
     3174                                 PSMALL_RECT psrctSourceRect)
    31213175{
    31223176  BOOL fResult;
     
    31553209
    31563210BOOL WIN32API ReadConsoleOutputW(HANDLE      hConsoleOutput,
    3157                                     PCHAR_INFO  pchiDestBuffer,
    3158                                     COORD       coordDestBufferSize,
    3159                                     COORD       coordDestBufferCoord,
    3160                                     PSMALL_RECT psrctSourceRect)
     3211                                 PCHAR_INFO  pchiDestBuffer,
     3212                                 COORD       coordDestBufferSize,
     3213                                 COORD       coordDestBufferCoord,
     3214                                 PSMALL_RECT psrctSourceRect)
    31613215{
    31623216  BOOL fResult;
     
    31953249
    31963250BOOL WIN32API ReadConsoleOutputAttribute(HANDLE  hConsoleOutput,
    3197                                             LPWORD  lpwAttribute,
    3198                                             DWORD   cReadCells,
    3199                                             COORD   coordReadCoord,
    3200                                             LPDWORD lpcNumberRead)
     3251                                         LPWORD  lpwAttribute,
     3252                                         DWORD   cReadCells,
     3253                                         COORD   coordReadCoord,
     3254                                         LPDWORD lpcNumberRead)
    32013255{
    32023256  BOOL fResult;
     
    32353289
    32363290BOOL WIN32API ReadConsoleOutputCharacterA(HANDLE  hConsoleOutput,
    3237                                              LPTSTR  lpReadBuffer,
    3238                                              DWORD   cchRead,
    3239                                              COORD   coordReadCoord,
    3240                                              LPDWORD lpcNumberRead)
     3291                                          LPTSTR  lpReadBuffer,
     3292                                          DWORD   cchRead,
     3293                                          COORD   coordReadCoord,
     3294                                          LPDWORD lpcNumberRead)
    32413295{
    32423296  BOOL fResult;
     
    32753329
    32763330BOOL WIN32API ReadConsoleOutputCharacterW(HANDLE  hConsoleOutput,
    3277                                              LPTSTR  lpReadBuffer,
    3278                                              DWORD   cchRead,
    3279                                              COORD   coordReadCoord,
    3280                                              LPDWORD lpcNumberRead)
     3331                                          LPTSTR  lpReadBuffer,
     3332                                          DWORD   cchRead,
     3333                                          COORD   coordReadCoord,
     3334                                          LPDWORD lpcNumberRead)
    32813335{
    32823336  BOOL fResult;
     
    33153369
    33163370BOOL WIN32API ScrollConsoleScreenBufferA(HANDLE      hConsoleOutput,
    3317                                             PSMALL_RECT psrctSourceRect,
    3318                                             PSMALL_RECT psrctClipRect,
    3319                                             COORD       coordDestOrigin,
    3320                                             PCHAR_INFO  pchiFill)
     3371                                         PSMALL_RECT psrctSourceRect,
     3372                                         PSMALL_RECT psrctClipRect,
     3373                                         COORD       coordDestOrigin,
     3374                                         PCHAR_INFO  pchiFill)
    33213375{
    33223376  BOOL fResult;
     
    33553409
    33563410BOOL WIN32API ScrollConsoleScreenBufferW(HANDLE      hConsoleOutput,
    3357                                             PSMALL_RECT psrctSourceRect,
    3358                                             PSMALL_RECT psrctClipRect,
    3359                                             COORD       coordDestOrigin,
    3360                                             PCHAR_INFO  pchiFill)
     3411                                         PSMALL_RECT psrctSourceRect,
     3412                                         PSMALL_RECT psrctClipRect,
     3413                                         COORD       coordDestOrigin,
     3414                                         PCHAR_INFO  pchiFill)
    33613415{
    33623416  BOOL fResult;
     
    37073761  if (lpszTitle == NULL)                                 /* check parameters */
    37083762    return FALSE;
    3709  
     3763
    37103764  if (ConsoleGlobals.pszWindowTitle != NULL)           /* previously set name */
    37113765    free (ConsoleGlobals.pszWindowTitle);                     /* then free it */
    3712  
     3766
    37133767  /* create an ascii copy of the lpszTitle */
    37143768  int iLength = UniStrlen(lpszTitle);
    3715  
     3769
    37163770  ConsoleGlobals.pszWindowTitle = (PSZ)malloc(iLength+1);
    37173771  ConsoleGlobals.pszWindowTitle[iLength] = 0;
     
    37403794
    37413795BOOL WIN32API SetConsoleWindowInfo(HANDLE      hConsoleOutput,
    3742                                       BOOL        fAbsolute,
    3743                                       PSMALL_RECT psrctWindowRect)
     3796                                   BOOL        fAbsolute,
     3797                                   PSMALL_RECT psrctWindowRect)
    37443798{
    37453799  BOOL fResult;
     
    37763830
    37773831BOOL WIN32API WriteConsoleA(HANDLE      hConsoleOutput,
    3778                                CONST VOID* lpvBuffer,
    3779                                DWORD       cchToWrite,
    3780                                LPDWORD     lpcchWritten,
    3781                                LPVOID      lpvReserved)
     3832                            CONST VOID* lpvBuffer,
     3833                            DWORD       cchToWrite,
     3834                            LPDWORD     lpcchWritten,
     3835                            LPVOID      lpvReserved)
    37823836{
    37833837  BOOL fResult;
     
    38163870
    38173871BOOL WIN32API WriteConsoleW(HANDLE      hConsoleOutput,
    3818                                CONST VOID* lpvBuffer,
    3819                                DWORD       cchToWrite,
    3820                                LPDWORD     lpcchWritten,
    3821                                LPVOID      lpvReserved)
     3872                            CONST VOID* lpvBuffer,
     3873                            DWORD       cchToWrite,
     3874                            LPDWORD     lpcchWritten,
     3875                            LPVOID      lpvReserved)
    38223876{
    38233877  BOOL fResult;
     
    38563910
    38573911BOOL WIN32API WriteConsoleInputA(HANDLE        hConsoleInput,
    3858                                     PINPUT_RECORD pirBuffer,
    3859                                     DWORD         cInRecords,
    3860                                     LPDWORD       lpcWritten)
     3912                                 PINPUT_RECORD pirBuffer,
     3913                                 DWORD         cInRecords,
     3914                                 LPDWORD       lpcWritten)
    38613915{
    38623916  BOOL fResult;
     
    38943948
    38953949BOOL WIN32API WriteConsoleInputW(HANDLE        hConsoleInput,
    3896                                     PINPUT_RECORD pirBuffer,
    3897                                     DWORD         cInRecords,
    3898                                     LPDWORD       lpcWritten)
     3950                                 PINPUT_RECORD pirBuffer,
     3951                                 DWORD         cInRecords,
     3952                                 LPDWORD       lpcWritten)
    38993953{
    39003954  BOOL fResult;
     
    39323986
    39333987BOOL WIN32API WriteConsoleOutputA(HANDLE      hConsoleOutput,
    3934                                      PCHAR_INFO  pchiSrcBuffer,
    3935                                      COORD       coordSrcBufferSize,
    3936                                      COORD       coordSrcBufferCoord,
    3937                                      PSMALL_RECT psrctDestRect)
     3988                                  PCHAR_INFO  pchiSrcBuffer,
     3989                                  COORD       coordSrcBufferSize,
     3990                                  COORD       coordSrcBufferCoord,
     3991                                  PSMALL_RECT psrctDestRect)
    39383992{
    39393993  BOOL fResult;
     
    39724026
    39734027BOOL WIN32API WriteConsoleOutputW(HANDLE      hConsoleOutput,
    3974                                      PCHAR_INFO  pchiSrcBuffer,
    3975                                      COORD       coordSrcBufferSize,
    3976                                      COORD       coordSrcBufferCoord,
    3977                                      PSMALL_RECT psrctDestRect)
     4028                                  PCHAR_INFO  pchiSrcBuffer,
     4029                                  COORD       coordSrcBufferSize,
     4030                                  COORD       coordSrcBufferCoord,
     4031                                  PSMALL_RECT psrctDestRect)
    39784032{
    39794033  BOOL fResult;
     
    40114065
    40124066BOOL WIN32API WriteConsoleOutputAttribute(HANDLE  hConsoleOutput,
    4013                                              LPWORD  lpwAttribute,
    4014                                              DWORD   cWriteCells,
    4015                                              COORD   coordWriteCoord,
    4016                                              LPDWORD lpcNumberWritten)
     4067                                          LPWORD  lpwAttribute,
     4068                                          DWORD   cWriteCells,
     4069                                          COORD   coordWriteCoord,
     4070                                          LPDWORD lpcNumberWritten)
    40174071{
    40184072  BOOL fResult;
     
    40514105
    40524106BOOL WIN32API WriteConsoleOutputCharacterA(HANDLE  hConsoleOutput,
    4053                                               LPTSTR  lpWriteBuffer,
    4054                                               DWORD   cchWrite,
    4055                                               COORD   coordWriteCoord,
    4056                                               LPDWORD lpcWritten)
     4107                                           LPTSTR  lpWriteBuffer,
     4108                                           DWORD   cchWrite,
     4109                                           COORD   coordWriteCoord,
     4110                                           LPDWORD lpcWritten)
    40574111{
    40584112  BOOL fResult;
     
    40914145
    40924146BOOL WIN32API WriteConsoleOutputCharacterW(HANDLE  hConsoleOutput,
    4093                                               LPTSTR  lpWriteBuffer,
    4094                                               DWORD   cchWrite,
    4095                                               COORD   coordWriteCoord,
    4096                                               LPDWORD lpcWritten)
     4147                                           LPTSTR  lpWriteBuffer,
     4148                                           DWORD   cchWrite,
     4149                                           COORD   coordWriteCoord,
     4150                                           LPDWORD lpcWritten)
    40974151{
    40984152  BOOL fResult;
Note: See TracChangeset for help on using the changeset viewer.