home *** CD-ROM | disk | FTP | other *** search
- /*
-
-
-
-
- POPUP.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"
-
-
-
-
-
-
- /* GET_FILE_NAME() gets the following information from the user:
- 1. What FILE_NAME will hold the data we are about
- to capture?
- 2. What directory will hold this file?
- 3. What drive will this directory live on?
-
- THE CALLING FUNCTION IS RESPONSIBLE FOR ENSURING THAT THE
- POP UP WINDOW DIMENSIONS ARE AT LEAST AS LARGE AS THE TEXT
- PLACED INSIDE!!!!!
-
- This function requires the following parameters:
- LEFT the column number of the first column
- of text in the pop up
- RIGHT the column number of the last column
- of text in the pop up
- TOP the row number of the first line of text in the pop up
- FILE_NAME The address of a string that will
- hold the name of a file that will
- receive the captured data from the
- PHYSICAL VIDEO BUFFER.
-
- This function returns the following return codes:
- NOTHING ( VOID ) */
- void get_file_name( USHORT left,
- USHORT right,
- USHORT top,
- char *file_name )
- {
- UCHAR ok = FALSE, attribute = NORMAL_TEXT_COLOR;
- USHORT error;
- USHORT column, row;
- USHORT length;
- char drive_letter[ 2 ], directory_name[ LONGEST_PATH_NAME ];
- char file[ LONGEST_FILE_NAME ];
- char current_path[ LONGEST_PATH_NAME ];
- KBDKEYINFO character;
- HKBD keyboard;
- struct screen_text response, back_slash, colon;
- USHORT drive_number;
- ULONG drive_map, x;
- unsigned valid_drive;
-
-
-
- /* Initialize the back_slash structure. */
- back_slash.letter = ( UCHAR )'\\';
- back_slash.attribute = NORMAL_TEXT_COLOR;
-
- /* Initialize the colon structure. */
- colon.letter = ( UCHAR )':';
- colon.attribute = NORMAL_TEXT_COLOR;
-
- /* Find out what other drives exist on this system. */
- error = DosQCurDisk( &drive_number, &drive_map );
-
- /* Find out the current drive and path. */
- length = ( USHORT )sizeof( current_path );
- error = DosQCurDir( drive_number,
- ( BYTE *)current_path,
- &length );
-
- /* Initialize our default path name. If the user has specified
- a default path at the command line, use that. If not, use
- the current path as the default. */
- if( default_path_name[0] == '\0' )
- {
- thread_copy( default_path_name, current_path );
-
- }
-
- /* Make sure the drive string ends in a NULL character. */
- drive_letter[1] = '\0';
-
- /* Initialize our drive prompt. */
- if( default_drive_name != '\0' )
- {
- drive_letter[0] = default_drive_name;
-
- }
- else
- {
- drive_letter[0] = ( char )('@' + drive_number);
-
- }
-
- response.attribute = NORMAL_TEXT_COLOR;
- response.letter = ( UCHAR )drive_letter[0];
-
- /* Label the pop up window. */
- length = thread_strlen( get_file_popup_title );
- column = left + center_the_line( left,
- right,
- length );
- error = VioWrtCharStrAtt( get_file_popup_title,
- length,
- top, column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
-
-
- /* Put the prompts on the screen in the correct locations. */
- row = top + 2;
- error = VioWrtCharStrAtt( drive_prompt, thread_strlen( drive_prompt ),
- row, left,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- /* Echo the character back to the screen. */
- column = left + thread_strlen( drive_prompt ) + 3;
- error = VioWrtNCell( ( BYTE *)&response,
- 1,
- row,
- column,
- DEFAULT_SCREEN_HANDLE );
-
- /* Put the colon in the column next to the DRIVE LETTER. */
- column++;
- error = VioWrtNCell( ( BYTE *)&colon,
- 1,
- row,
- column,
- DEFAULT_SCREEN_HANDLE );
-
-
-
- /* Prompt for the DIRECTORY NAME. */
- row += 2;
- length = thread_strlen( directory_prompt );
- column = left + center_the_line( left,
- right,
- length );
- error = VioWrtCharStrAtt( directory_prompt,
- length,
- row, column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
-
-
-
- /* Prompt for the FILE NAME. */
- row += 3;
- column = left + center_the_line( left,
- right,
- length );
-
- length = thread_strlen( file_prompt );
-
- error = VioWrtCharStrAtt( file_prompt,
- length,
- row, column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
-
-
- /* Ask if everything is OK. */
- row += 3;
- column = left;
- error = VioWrtCharStrAtt( ok_prompt,
- thread_strlen( ok_prompt ),
- row, column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
-
-
-
- /* Get the responses to the above prompts. */
- error = KbdOpen( &keyboard );
-
- error = KbdGetFocus( IO_WAIT, keyboard );
-
- while( !ok )
- {
- /* Position the cursor. */
- row = top + 2;
- column = left + thread_strlen( drive_prompt ) + 3;
-
- for( valid_drive = FALSE; !valid_drive; )
- {
- response.letter = ( UCHAR )drive_letter[0];
- error = VioSetCurPos( row, column, DEFAULT_SCREEN_HANDLE );
-
- /* Get the DRIVE letter. */
- error = KbdCharIn( &character, IO_WAIT, keyboard );
-
- if( ( character.chChar == '\n' ) || ( character.chChar == '\r' ) )
- {
- drive_letter[0] = response.letter;
-
- }
- else
- {
- drive_letter[0] = response.letter = ( UCHAR )toupper( character.chChar );
-
- }
-
- /* Echo the character back to the screen. */
- error = VioWrtNCell( ( BYTE *)&response,
- 1,
- row,
- column,
- DEFAULT_SCREEN_HANDLE );
-
- /* Make sure we got a valid drive letter. */
- x = ( ULONG )( 1L << ( drive_letter[0] - 'A' ) );
-
- /* If this is TRUE, we have a valid drive. */
- if( x & drive_map )
- {
- valid_drive = TRUE;
-
- }
- else
- {
- valid_drive = FALSE;
-
- }
-
-
- }
-
- /* Position the cursor. */
- row += 3;
- column = left + 1;
-
- /* Put the BACK SLASH character on the screen just before the DIRECTORY name. */
- error = VioWrtNCell( ( BYTE *)&back_slash,
- 1,
- row,
- column,
- DEFAULT_SCREEN_HANDLE );
-
- /* Get the DIRECTORY NAME. */
- column++;
-
- get_string( default_path_name,
- directory_name,
- sizeof( directory_name ),
- row,
- column, right - 2 - left,
- keyboard );
-
- /* Position the cursor. */
- row += 3;
- column--;
-
- /* Put the BACK SLASH character on the screen just before the FILE name. */
- error = VioWrtNCell( ( BYTE *)&back_slash,
- 1,
- row,
- column,
- DEFAULT_SCREEN_HANDLE );
-
- /* Get tye FILE NAME. */
- column++;
-
- get_string( default_file_name,
- file,
- sizeof( file ),
- row,
- column, right - 2 - left,
- keyboard );
-
- /* Trap the keyboard. Limit input to the YES character
- or the NO character. */
- row += 2;
- column = left + thread_strlen( ok_prompt ) + 3;
-
- do
- {
- /* Position the cursor. */
- error = VioSetCurPos( row, column, DEFAULT_SCREEN_HANDLE );
-
-
- /* Find out if everything is OK. */
- error = KbdCharIn( &character, IO_WAIT, keyboard );
- character.chChar = ( UCHAR )toupper( character.chChar );
-
- response.letter = character.chChar;
-
- /* Echo the character back to the screen. */
- error = VioWrtNCell( ( BYTE *)&response,
- 1,
- row,
- column,
- DEFAULT_SCREEN_HANDLE );
-
- }while( ( character.chChar != yes)
- &&
- ( character.chChar != no ) );
-
-
- ok = ( character.chChar == yes ) ? ( UCHAR )TRUE : ( UCHAR )FALSE;
- error = KbdFlushBuffer( keyboard );
-
-
- }
-
- if( directory_name[0] != '\0' )
- {
- /* Combine the DRIVE, DIRECTORY, and FILE NAME
- into one fully qualified file name. */
- sprintf( file_name, "%s:\\%s\\%s\0",
- drive_letter,
- directory_name,
- file );
-
- }
- else
- {
- /* Combine the DRIVE and FILE NAME
- into one fully qualified file name. */
- sprintf( file_name, "%s:\\%s\0",
- drive_letter,
- file );
-
- }
-
-
- error = KbdFreeFocus( keyboard );
- error = KbdClose( keyboard );
-
-
- return;
-
- }
-
-
-
-
-
-
- /* RESULTS() tells the user:
- 1. that the screen capture is complete,
- 2. that it was a success or a failure.
-
- It requires the following parameters:
- LEFT the column number of the first column
- of text in the pop up
- RIGHT the column number of the last column
- of text in the pop up
- TOP the row number of the first line of text in the pop up
- FAILURE a Boolean flag that tells this function:
- 1. if the screen was successfully
- copied.
- 2. if the data was successfully written
- to the user specified file.
-
- It returns the following error codes:
- NOTHING ( VOID ) */
- void results( USHORT left,
- USHORT right,
- USHORT top,
- unsigned failure )
- {
- USHORT error;
- BYTE attribute;
- USHORT next_column, next_row;
- USHORT columns_remaining;
- USHORT length;
- KBDKEYINFO character;
- HKBD keyboard;
- char *error_msg;
-
-
- next_column = left;
-
- /* Center the line on the pop up. */
- next_column += center_the_line( left,
- right,
- ( sizeof( RESULTS_1 ) + sizeof( RESULTS_FAILURE ) ) );
-
- columns_remaining = right - next_column;
- next_row = top;
- attribute = NORMAL_TEXT_COLOR;
-
- /* Truncate the text, if necessary, to the size of the pop up. */
- length = MIN( sizeof( RESULTS_1 ), columns_remaining );
-
-
- /* Write the first line of text. */
- error = VioWrtCharStrAtt(
- RESULTS_1,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- next_column += sizeof( RESULTS_1 );
- columns_remaining -= sizeof( RESULTS_1 );
-
- if ( failure )
- {
- attribute = ERROR_TEXT_COLOR;
- length = MIN( sizeof( RESULTS_FAILURE ), columns_remaining );
-
-
-
- error = VioWrtCharStrAtt(
- RESULTS_FAILURE,
- sizeof( RESULTS_FAILURE ),
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- /* Write the next line. Describe the error. */
- next_row +=2;
- next_column = left;
- columns_remaining = right - left;
- attribute = NORMAL_TEXT_COLOR;
- next_column += center_the_line( left,
- right,
- sizeof( ERROR_INTRO ) );
-
- error = VioWrtCharStrAtt(
- ERROR_INTRO,
- sizeof( ERROR_INTRO ),
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- /* Describe the error on the final line. */
- next_row ++;
- next_column = left;
- columns_remaining = right - left;
- attribute = ERROR_TEXT_COLOR;
-
- switch( failure )
- {
- case ERROR_FILE_NOT_FOUND :
- error_msg = "Cannot find the file you entered." ;
- break;
-
- case ERROR_PATH_NOT_FOUND :
- error_msg = "Drive or directory does not exist.";
- break;
-
- case ERROR_TOO_MANY_OPEN_FILES :
- error_msg = "The system cannot open any more files.";
- break;
-
- case ERROR_ACCESS_DENIED :
- error_msg = "Access to this file is DENIED by OS/2.";
- break;
-
- case ERROR_INVALID_ACCESS :
- error_msg = "This file cannot be opened for WRITTING at this time.";
- break;
-
- case ERROR_NOT_DOS_DISK :
- error_msg = "OS/2 does not recognize the format of this disk.";
- break;
-
- case ERROR_SHARING_VIOLATION :
- error_msg = "Sharing violation.";
- break;
-
- case ERROR_SHARING_BUFFER_EXCEEDED :
- error_msg = "OS/2 sharing buffer has no more space.";
- break;
-
- case ERROR_CANNOT_MAKE :
- error_msg = "OS/2 cannot make this file.";
- break;
-
- case ERROR_INVALID_PARAMETER :
- error_msg = "Invalid parameter.";
- break;
-
- case ERROR_DRIVE_LOCKED :
- error_msg = "The entire drive is locked.";
- break;
-
- case ERROR_OPEN_FAILED :
- error_msg = "DosOpen failed.";
- break;
-
- case ERROR_DISK_FULL :
- error_msg = "This disk is full.";
- break;
-
- case ERROR_FILENAME_EXCED_RANGE :
- error_msg = "The file name you entered is too big.";
- break;
-
- case ERROR_PIPE_BUSY :
- error_msg = "The pipe you named is busy.";
- break;
-
- /* case ERROR_DEVICE_IN_USE :
- error_msg = "The device you named is in use.";
- break; */
-
- case ERROR_INVALID_HANDLE :
- error_msg = "Invalid handle. Call the programmer.";
- break;
-
- case ERROR_LOCK_VIOLATION :
- error_msg = "This file is locked at the moment.";
- break;
-
- case ERROR_BROKEN_PIPE :
- error_msg = "Your pipe is broken.";
- break;
-
- case MALLOC_ERROR :
- error_msg = "MALLOC() failed. Call the programmer.";
- break;
-
- default:
- error_msg = "An unknown error occurred.";
- break;
-
- }
-
- /* Truncate the message, if necessary, to the length
- of one line of our pop up window. */
- length = MIN( ( unsigned )thread_strlen( error_msg ), columns_remaining );
-
- /* Center the line on the pop up. */
- next_column += center_the_line( left,
- right,
- length );
-
- error = VioWrtCharStrAtt(
- error_msg,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- }
- else
- {
- attribute = HILITE_TEXT_COLOR;
- length = MIN( sizeof( RESULTS_SUCCESS ), columns_remaining );
-
- error = VioWrtCharStrAtt(
- RESULTS_SUCCESS,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- }
-
-
-
- next_row += 2;
- attribute = NORMAL_TEXT_COLOR;
- next_column = left + 3;
- length = thread_strlen( pause_prompt );
-
- /* Center the line on the pop up. */
- next_column += center_the_line( left,
- right,
- length );
-
- error = VioWrtCharStrAtt(
- pause_prompt,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- /* Get the responses to the above prompts. */
- error = KbdOpen( &keyboard );
-
- error = KbdGetFocus( IO_WAIT, keyboard );
-
-
- /* Get a keystroke from the keyboard just to force the operator to respond. */
- error = KbdCharIn( &character, IO_WAIT, keyboard );
-
- error = KbdFreeFocus( keyboard );
- error = KbdClose( keyboard );
-
-
-
-
- return;
-
- }
-
-
-
-
-
- /* FAREWELL() tells the user:
- 1. that the screen capture is complete,
- 2. that it was a success or a failure.
-
- It requires the following parameters:
- LEFT the column number of the first column
- of text in the pop up
- RIGHT the column number of the last column
- of text in the pop up
- TOP the row number of the first line of text in the pop up
-
- It returns the following error codes:
- NOTHING ( VOID ) */
- void farewell( USHORT left,
- USHORT right,
- USHORT top )
- {
- USHORT error;
- BYTE attribute;
- USHORT next_column, next_row;
- USHORT columns_remaining;
- USHORT length;
- KBDKEYINFO character;
- HKBD keyboard;
-
-
- next_column = left;
- length = thread_strlen( program_name );
-
- /* Center the line on the pop up. */
- next_column += center_the_line( left,
- right,
- ( length + sizeof( FAREWELL_STRING ) ) );
-
- columns_remaining = right - next_column;
- next_row = top;
- attribute = NORMAL_TEXT_COLOR;
-
- /* Truncate the displayed text, if necessary, to the size of the pop up. */
- length = MIN( length, columns_remaining );
-
-
- /* Write the program name. */
- error = VioWrtCharStrAtt(
- program_name,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- next_column += length;
- columns_remaining -= length;
- length = MIN( sizeof( FAREWELL_STRING ), columns_remaining );
-
- /* Write the rest of the first line of text. */
- error = VioWrtCharStrAtt(
- FAREWELL_STRING,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- next_row += 2;
- attribute = NORMAL_TEXT_COLOR;
- next_column = left + 3;
- length = thread_strlen( pause_prompt );
-
- /* Center the line on the pop up. */
- next_column += center_the_line( left,
- right,
- length );
-
- error = VioWrtCharStrAtt(
- pause_prompt,
- length,
- next_row,
- next_column,
- &attribute,
- DEFAULT_SCREEN_HANDLE );
-
- /* Get the responses to the above prompts. */
- error = KbdOpen( &keyboard );
-
- error = KbdGetFocus( IO_WAIT, keyboard );
-
-
- /* Get a keystroke from the keyboard just to force the operator to respond. */
- error = KbdCharIn( &character, IO_WAIT, keyboard );
-
- error = KbdFreeFocus( keyboard );
- error = KbdClose( keyboard );
-
-
-
- }
-
-
-
-
-
-
-
-
- /* POP_UP() does the following things:
- 1. issues the three calls ALL pop ups in this program must issue:
- VioPopUp
- VioGetConfig
- VioEndPopUp
- 2. calls the correct pop up code
-
- It requires the following parameters:
- TYPE which pop up are we calling.
- FILE_NAME this is the name of the file that will hold the
- captured screen data.
- SUCCESS a Boolean flag that tells this function:
- 1. if the screen was successfully
- copied.
- 2. if the data was successfully written
- to the user specified file.
-
- It returns the following error codes:
- NO_ERROR everything went well
- anything else (probably the return code from VioPopUp) */
- int pop_up( unsigned type, char *file_name, unsigned failure )
- {
- USHORT error, options, left, right, top, bottom;
- VIOMODEINFO screen;
- struct screen_text fill_character;
-
- /* Initialize... */
- fill_character.letter = ' ';
- fill_character.attribute = POPUP_BACKGROUND_COLOR;
- screen.cb = sizeof( screen );
-
- /* Begin the popup session. */
- options = VP_TRANSPARENT | VP_WAIT;
- error = VioPopUp( &options, DEFAULT_SCREEN_HANDLE );
-
-
- if( error == NO_ERROR )
- {
- /* Find out what our screen dimensions are. */
- error = VioGetMode( &screen, DEFAULT_SCREEN_HANDLE );
-
- left = screen.col / 5;
- right = (left << 2);
- top = screen.row >> 2;
-
- switch( type )
- {
- case MALLOC_ERROR :
- case GET_FILE_NAME :
- bottom = top * 3;
- break;
-
- case RESULTS :
- if( failure )
- {
- bottom = top + 7;
-
- }
- else
- {
- bottom = top + 5;
-
- }
- break;
-
- case FAREWELL :
- bottom = top + 5;
- break;
-
- }
-
-
- /* Scroll the pop up. */
- error = VioScrollUp( top, left, bottom, right, 0xFFFF, ( PBYTE )&fill_character, DEFAULT_SCREEN_HANDLE );
- left += 2;
- right -= 2;
- top++;
- bottom--;
-
-
- if( type == GET_FILE_NAME )
- {
- get_file_name( left, right, top, file_name );
-
- }
-
-
- if( type == FAREWELL )
- {
- farewell( left, right, top );
-
- }
-
- if( type == RESULTS )
- {
- results( left, right, top, failure );
-
- }
-
-
-
- /* End the popup session. */
- error = VioEndPopUp( DEFAULT_SCREEN_HANDLE );
-
- }
-
- return( error );
-
- }