home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / safeout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  4.5 KB  |  144 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    s a f e o u t . c                                               */
  3. /*                                                                    */
  4. /*    Console I/O functions for use during interrupt processing       */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: safeout.c 1.6 1993/10/12 00:49:39 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: safeout.c $
  24.  *     Revision 1.6  1993/10/12  00:49:39  ahd
  25.  *     Normalize comments
  26.  *
  27.  *     Revision 1.5  1993/10/03  00:05:32  ahd
  28.  *     Only define currentfile() under Windows NT
  29.  *
  30.  *     Revision 1.4  1993/09/20  04:39:51  ahd
  31.  *     OS/2 2.x support
  32.  *
  33.  *     Revision 1.3  1993/07/20  21:42:43  dmwatt
  34.  *     Don't rely on standard I/O under Windows/NT
  35.  *
  36.  */
  37.  
  38. /*--------------------------------------------------------------------*/
  39. /*    Since C I/O functions are not safe inside signal routines,      */
  40. /*    the code uses conditionals to use system-level DOS and OS/2     */
  41. /*    services.  Another option is to set global flags and do any     */
  42. /*    I/O operations outside the signal handler.                      */
  43. /*--------------------------------------------------------------------*/
  44.  
  45. #define __MSC                 /* Make Borland C++ 2.0 act like MS C   */
  46.  
  47. #include <stdio.h>
  48.  
  49. #ifdef WIN32
  50.     #include <windows.h>
  51.     #include <string.h>
  52.  
  53. #elif defined( FAMILYAPI ) || defined(__OS2__)
  54.  
  55.     #define INCL_NOCOMMON
  56.     #define INCL_NOPM
  57.     #define INCL_VIO
  58.     #define INCL_KBD
  59.     #include <os2.h>
  60.     #include <string.h>
  61.  
  62. #else
  63.  
  64.     #include <dos.h>
  65.     #include <bios.h>
  66.     #include <conio.h>
  67.  
  68. #endif /* FAMILYAPI */
  69.  
  70. /*--------------------------------------------------------------------*/
  71. /*                    UUPC/extended include files                     */
  72. /*--------------------------------------------------------------------*/
  73.  
  74. #include "lib.h"
  75. #include "safeio.h"
  76.  
  77. /*--------------------------------------------------------------------*/
  78. /*                          Global variables                          */
  79. /*--------------------------------------------------------------------*/
  80.  
  81. #if defined(WIN32)
  82. currentfile();
  83. #endif
  84.  
  85. #if defined(WIN32)
  86. static HANDLE hConsoleOut = INVALID_HANDLE_VALUE;
  87.  
  88. void InitConsoleOutputHandle(void)
  89. {
  90.    hConsoleOut = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
  91.       FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
  92.       FILE_ATTRIBUTE_NORMAL, 0);
  93.  
  94.    if (hConsoleOut == INVALID_HANDLE_VALUE) {
  95.       printmsg(0, "InitConsoleHandles:  could not open console handles!");
  96.       panic();
  97.    }
  98. }
  99. #endif
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*    s a f e o u t                                                   */
  103. /*                                                                    */
  104. /*    Outputs a string using system level calls. from MicroSoft       */
  105. /*    Programmer's Workbench QuickHelp samples                        */
  106. /*--------------------------------------------------------------------*/
  107.  
  108. void safeout( char *str )
  109. {
  110.  
  111. #ifdef _Windows
  112.  
  113.    fputs( str , stdout );
  114.    return;
  115.  
  116. #elif defined( WIN32 )
  117.  
  118.    DWORD dwBytesWritten;
  119.  
  120.    if (hConsoleOut == INVALID_HANDLE_VALUE)
  121.       InitConsoleOutputHandle();
  122.  
  123.    WriteFile(hConsoleOut, str, (DWORD)strlen(str), &dwBytesWritten, NULL);
  124.    return;
  125.  
  126. #elif defined( FAMILYAPI ) || defined(__OS2__)
  127.  
  128.    VioWrtTTY( str, strlen( str ), 0 );
  129.  
  130. #else
  131.     union REGS inregs, outregs;
  132.  
  133.     inregs.h.ah = 0x0e;
  134.     while( *str )
  135.     {
  136.         inregs.h.al = *str++;
  137.         int86( 0x10, &inregs, &outregs );
  138.     }
  139.  
  140.     safeflush();              /* Flush keyboard                       */
  141.  
  142. #endif /* _Windows */
  143. } /* safeout */
  144.