home *** CD-ROM | disk | FTP | other *** search
- /*
-
-
-
- CAPTURE.c
-
- Copyright (c) 1990 by: Arthur Kevin McGrath
- Contract Engineers
- P. O. Box 128
- Barboursville, VA 22923
-
- 703/832-7025
-
-
- ALL RIGHTS ARE RESERVED. You may not copy this program in any way
- except to make back-up copies FOR YOUR OWN USE. If you copy this
- program for any reason without WRITTEN PERMISSION from the above
- named copyright owner (except to make back-up copies FOR YOUR OWN USE),
- you are breaking the Copyright Laws of the United States. You will go
- to jail for one year and pay a $50,000 fine.
-
-
-
-
- */
-
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
-
-
- #define INCL_BASE
- #define INCL_VIO
- #include <os2.h>
-
- #include "capture.h"
- #include "extern.h"
-
-
-
-
-
-
- /* CAPTURE_THE_SCREEN() takes ASCII characters from the PHYSICAL VIDEO
- BUFFER and transfers copies of them to a text buffer of the user's
- choice. The user has the option of capturing all 256 ASCII
- characters or just the printable ASCII characters (from SPACE
- through 'z').
-
- This function requires the following parameters:
- NOTHING ( VOID )
-
- This function returns the following values:
- NOTHING ( VOID ) */
-
- PFNTHREAD capture_the_screen( void )
- {
- HQUEUE q;
- char file[ LONGEST_PATH_NAME + LONGEST_FILE_NAME ];
- char *screen_text;
- unsigned end_of_screen;
- unsigned source, destination, column;
- VIOMODEINFO mode;
- VIOPHYSBUF physical_screen;
- struct screen_text *display;
- UCHAR status;
- HFILE FileHandle;
- USHORT error, ActionTaken, attributes = ARCHIVE;
- USHORT OpenFlag = 0x0011, OpenMode = 0x0122;
- USHORT BytesWritten, owner;
- SEL selector;
- struct stack_selector *thread;
- PIDINFO this_thread;
-
-
- /* Where is our video buffer and how big is it. */
- mode.cb = ( USHORT )sizeof( mode );
- error = VioGetMode( &mode, DEFAULT_SCREEN_HANDLE );
-
- physical_screen.pBuf = ( PBYTE )mode.buf_addr;
- physical_screen.cb = mode.buf_length;
-
- /* The text portion of any screen takes up only half of
- the actual video buffer. The other half, of course,
- is made up of attribute bytes. We will grab enough
- memory to hold the text we are about to extract from
- the screen PLUS one NEWLINE character for each
- line on the screen. */
- end_of_screen = ( int )
- ( mode.buf_length / ( long )sizeof( struct screen_text ) );
- error = DosAllocSeg( ( end_of_screen + mode.row ),
- &selector,
- NOSHARE_NODISCARD );
- screen_text = ( char *)MAKEP( selector, 0 );
-
-
- /* If SCREEN_TEXT is not a NULL, then MALLOC() was successful.
- Otherwise, we have a problem and the user must be informed. */
- if( !error )
- {
- /* Lock the screen so that nobody changes sessions while we
- are playing with the Physical Video Buffer. */
- error = VioScrLock( LOCKIO_WAIT, &status, DEFAULT_SCREEN_HANDLE );
-
-
- /* Don't do any of this stuff if we cannot lock the screen. */
- if( ( error == NO_ERROR ) && ( status == LOCK_SUCCESS ) )
- {
- error = VioGetPhysBuf( &physical_screen, RESERVED );
-
-
-
- /* Now that we have a selector that we can use to address the
- Physical Video Buffer, let us convert that selector into
- a Pointer. We will then pretend that an array of
- SCREEN_TEXT structures lives at that address. */
- display = ( struct screen_text *)MAKEP( physical_screen.asel[0], 0 );
-
-
- /* Let us copy the characters from the screen to our text buffer. */
- for( source = destination = column = 0;
- source < end_of_screen;
- source++, destination++ )
- {
- /* Here we will insert code that:
- 1. Checks to see if we have reached the end of
- a line,
- 2. If we have reached the end of a line:
- a. strip off any trailing spaces,
- b. append a newline character. */
- if( column < mode.col )
- {
- column++;
-
- }
- else
- {
- do
- {
- destination--;
- column--;
-
- }while( ( column > 0 )
- &&
- ( screen_text[ destination ] == ' ' ) );
-
-
- /* Our array index can go no lower than ZERO.
- Hence, we have a special case when one or more
- lines are filled with blanks. If the a line is
- filled with SPACES all the way back to the first
- column, then we put a NEWLINE character in the
- first column. Otherwise, we preserve the
- NON-BLANK character that lives there. */
- if( screen_text[ destination ] != ' ' )
- {
- destination++;
-
- }
-
- screen_text[ destination ] = '\n';
- destination++;
-
- column = 1; /* Because we are going to move one character
- on this trip. */
-
- }
-
-
- if( printable_only )
- {
- screen_text[ destination ] = ( char )(isprint( display[ source ].letter ) ? display[ source ].letter : '.' );
-
- }
- else
- {
- screen_text[ destination ] = display[ source ].letter;
-
- }
-
- }
-
-
- /* Now that we have finished playing with the screen, we
- can release our lock on the PHYSICAL VIDEO BUFFER. */
- error = VioScrUnLock( DEFAULT_SCREEN_HANDLE );
-
-
- error = pop_up(GET_FILE_NAME, file, error );
-
- /* Now, let us write the text to a file. */
- error = DosOpen( file,
- &FileHandle,
- &ActionTaken,
- ( ULONG )destination,
- attributes,
- OpenFlag,
- OpenMode,
- ( ULONG )RESERVED );
-
- if( error == NO_ERROR )
- {
- error = DosWrite( FileHandle,
- screen_text,
- destination,
- &BytesWritten );
-
- }
-
- if( error == NO_ERROR )
- {
- error = DosClose( FileHandle );
-
-
- }
-
- error = pop_up( RESULTS, file, error );
- DosFreeSeg( selector );
- }
-
- }
- else
- {
- /* We can only get here if MALLOC() fails. */
- pop_up( RESULTS, file, MALLOC_ERROR );
-
- }
-
-
-
- /* Get some information we have to pass back to the
- FREE_THE_STACK() thread so it can release
- our stack segment. */
- error = DosAllocSeg( sizeof( struct stack_selector ),
- &selector,
- SEG_NONSHARED );
-
- thread = ( struct stack_selector *)MAKEP( selector, 0 );
-
-
- thread -> stack = stack_segment();
- error = DosGetPID( &this_thread );
- thread -> id = this_thread.tid;
-
-
- /* Let the program know we are ready to release
- our stack segment. */
- error = DosOpenQueue( &owner,
- &q,
- STACK_KILLER_QUEUE );
-
- error = DosWriteQueue( q,
- ( USHORT )NULL,
- sizeof( thread ),
- ( BYTE *)thread,
- ( UCHAR )10 );
-
-
-
- /* Let the monitor function know that it is OK to start
- another CAPTURE thread. */
- capturing = FALSE;
-
- DosExit( EXIT_THREAD, NO_ERROR );
-
-
- }