/*@P************************************************************************
 * File           : TSTMOV.C
 * Project        : EVERLOCK EVMOVDX.DLL BCEXT16 Test Application
 * Compiler       : Borland C++ v4.52
 * Description    :
 *
 * Copyright (c) 1994-97 Az-Tech Software, Inc.
 * ALL RIGHTS RESERVED
 ************************************************************************P@*/

#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <dos.h>
#include <conio.h>
#include "sb.h"

/***************************************************************************
 * Function Prototypes.
 ***************************************************************************/
int __far __pascal DoEvmov3( SB __far *lpUserSB );
int NormalizeStatus( int status );

/***************************************************************************
 * Global Variables.
 ***************************************************************************/
SB sb;

//@PB
#pragma argsused
int main( int argc, char **argv )
{
   int comp_status;

   // announce our presence to the users
   printf( "\nEVERLOCK EVMOVDX.DLL BCEXT16 Test Application\n\n" );

   // zero out the contents of the SB structure
   memset( &sb, 0, sizeof( SB ) );

   // initialize the contents of the SB buffer
   strncpy( sb.id, "AZSB", 4 );

   // parse out the command line parameters
   strncpy( sb.source, argv[1], 63 );
   strncpy( sb.target, argv[2], 63 );

   // get the initial information about the move operation
   sb.func = 0;
   comp_status = DoEvmov3( &sb );

   // display the results of the check
   if ( comp_status )
   {
      // display the error message
      printf( "EVMOVDX.DLL Error %04X!\n", comp_status );

      // return to the OS
      return NormalizeStatus( comp_status );

   } else if ( sb.stat1 ) {

      // display the error message
      printf( "Security Error %04X-%04X-%04X!\n", sb.stat1,
               sb.stat2, sb.stat3 );

      // return to the OS
      return NormalizeStatus( sb.stat1 );
   }

   // get rid of any extra keystrokes
   while ( kbhit() )
      getch();

   // display the confirmation message
   printf( "%s authorization from %s to %s...\n",
           sb.uninst ? "Uninstalling" : "Installing", sb.source,
           sb.target );

   printf( "Do you wish to continue? " );

   // ask the user if they would like to move
   comp_status = getch();
   printf( "%c\n\n", comp_status );

   // check the user's response
   if ( 'Y' != comp_status && 'y' != comp_status )
   {
      // let the user know that they cancelled
      printf( "Ending EVMOVE at user's request.\n" );

      // return to the operating system
      return 1;
   }

   // do we need to get the non-verified registration info?
   if ( sb.reg && !sb.uninst )
   {
      // yep, so get the registration name
      printf( "Registration Name: " );
      gets( sb.rname );

      // get the registration company
      printf( "          Company: " );
      gets( sb.rcomp );

      // get the registration location
      printf( "         Location: " );
      gets( sb.rloc );

      printf( "\n" );
   }

   // perform the actual move operation
   sb.func = 1;
   comp_status = DoEvmov3( &sb );

   // display the results of the check
   if ( comp_status )
   {
      // display the error message
      printf( "EVMOVDX.DLL Error %04X!\n", comp_status );

      // return to the OS
      return NormalizeStatus( comp_status );

   } else if ( sb.stat1 ) {

      // display the error message
      printf( "Security Error %04X-%04X-%04X!\n", sb.stat1,
               sb.stat2, sb.stat3 );

      // return to the OS
      return NormalizeStatus( sb.stat1 );
   }

   // let the user know we were successfull
   printf( "Authorization Move Successfull!\n" );

   // return to the OS
   return 0;
}

//@PB
int NormalizeStatus( int status )
{
   int temp;

   // get the hundreds digit from the error code
   temp = ( ( status & 0x0F00 ) >> 8 ) * 100;

   // add in the tens digit from the error code
   temp += ( ( status & 0x00F0 ) >> 4 ) * 10;

   // finally, add in the ones digit
   temp += status & 0x000F;

   // return the normalized status value to our caller
   return temp;
}
