/*static char *SCCSID = "@(#)cmchkdos.c	6.3 91/07/27";*/
/* static char *SCCSID = "@(#)cmchkdos.c	6.3 91/07/27"; */

/*********************************************************************/
/*	 IBM/Microsoft Confidential				     */
/*								     */
/*	 Copyright (c) IBM Corporation 1987, 1989		     */
/*	 Copyright (c) Microsoft Corporation 1987, 1989 	     */
/*								     */
/*	 All Rights Reserved					     */
/*********************************************************************/

/************ START OF SPECIFICATIONS ******** IBM CONFIDENTIAL ******/
/*								     */
/* SOURCE FILE NAME: CMCHKDOS					     */
/*								     */
/* DESCRIPTIVE NAME: VERIFY CORRECT DOS VERSION 		     */
/*								     */
/* FUNCTION:							     */
/*								     */
/*   - Check if the current DOS is a correct version.		     */
/*								     */
/*   - Check if the enviroment to support NLS is ready by	     */
/*     calling a reserved common subroutine "com_settbl", which      */
/*     calls DOSGETDBCS and DOSCASEMAP and then establishes	     */
/*     DBCS enviroment vector table, and casemap table. 	     */
/*     When any error is detected in com_settble routine,	     */
/*     NLS enviroment is not ready. The return code of com_settbl    */
/*     explains what is wrong. This return code will be returned     */
/*     to the calling routine as return code of comcheckdosver.      */
/*								     */
/* NOTES:							     */
/*								     */
/* ENTRY POINTS:  comcheckdosver				     */
/*								     */
/* EXTERNAL REFERENCE:						     */
/*								     */
/*	       DOSGETVERSION  - get the DOS version number	     */
/*	       com_settbl     - set up the table for DBCS support    */
/*								     */
/* RELEASE:							     */
/*								     */
/*   VERSION		DATE	       REASON			     */
/*								     */
/*     1.00	  3/25/1986	 initial version		     */
/*     2.00	  3/26/1986	 the first version for dirver 1      */
/*     2.01	  4/14/1986	 correct version is 5.00 only	     */
/*     2.02	  4/15/1986	 version bug fix		     */
/*     3.00	  4/15/1986	 the first intigration version	     */
/*     3.01	  05/01/1986	 add two more error include files.   */
/*				     <utlerror.h> and <error2.h>     */
/*     3.02	  06/17/1986	 enable SCCSID tag		     */
/*     3.03	  06/30/1986	 replace "doscall.h" with            */
/*				 "doscalls.h".                       */
/*     3.04	  08/18/1986	 call internal DBCS common routine   */
/*				 to check if NLS resuoce is OK.      */
/*     4.00	  11/13/1986	 refer to ..\inc\dosver.h to get     */
/*				 valid DOS version.		     */
/*     4.01	  12/09/1986	 add debug macro		     */
/*     5.00	  05/25/1988   ##Add setbuf(stdout,0) statement      */
/*				 This fix is need to fix redirection */
/*				 problem with the new C run time     */
/*				 library (Microsoft C compiler 5.0)  */
/*				 see ptm770 on OS/2 1.2 data base    */
/*								     */
/* B014 B721792 07/24/91 fgw Dasd reduction of Common Subroutines    */
/*			     [removed setbuf(..,0) calls]	     */
/*********************************************************************/
#include <doscall.h>		       /* cp/dos external define	    */
#include <comsub.h>		       /* common subroutine including file  */
#include <error.h>		       /* define return code		    */
#include <error2.h>		       /*				    */
#include <utlerror.h>		       /*				    */
#include <dosver.h>		       /* valid DOS version		    */
#include <stdio.h>
#include "cmdbcs.h"                    /* DBCS support include file         */
#include "cmdebug.h"                   /* macro for debugging               */
/*********************************************************************/
/*								     */
/* SUBROUTINE NAME:  comcheckdosver				     */
/*								     */
/* DESCRIPTIVE NAME: verify correct dos version 		     */
/*								     */
/* FUNCTION:							     */
/*								     */
/*	Get the current DOS version and check its veridity.	     */
/*	If it is not correct, set a return code of "ERROR_INVALID_   */
/*	DOSVER".                                                     */
/*								     */
/* NOTES:							     */
/*								     */
/* ENTRY POINT:  comcheckdosver 				     */
/*   LINKAGE  :  near						     */
/*								     */
/* INPUT:   none						     */
/*								     */
/* EXIT-NORMAL: 						     */
/*   RETURN CODE SYMBOL:  OK					     */
/*								     */
/* EXIT-ERROR:							     */
/*   RETURN CODE SYMBOL:					     */
/*								     */
/*	   ERROR_INVALID_DOSVER     - invalid DOS version	     */
/*	   or other API function error code			     */
/*								     */
/* EFFECTS:							     */
/*								     */
/* INTERNAL REFERENCES:   none					     */
/*   ROUTINES:							     */
/*								     */
/* EXTERNAL REFERENCES: 					     */
/*   ROUTINES:							     */
/*	       DOSGETVERSION  - get the DOS version number	     */
/*	       com_settbl     - set up the table for DBCS support    */
/*								     */
/******************* END OF SPECIFICATIONS ***************************/
unsigned
comcheckdosver()
{
  int rc;					 /* return code to caller	    */
  unsigned current_dosver;			 /* current dos vers from system    */
						 /*				    */
/*************************************/
/*				     */
/*    verify DOS version	     */
/*				     */
/*************************************/

  /*;BD014;   setbuf(stdout,0); 		       put in for 1.2 PTM 770 */
  /*;BD014;   setbuf(stderr,0); 		       put in for 1.2 PTM 770 */

  DCALL(DOSGETVERSION); 			 /*				    */
  if ((rc =					 /*				    */
       DOSGETVERSION((unsigned far *)		 /* get the DOS version number	    */
			&current_dosver))	 /*				    */
				!= OK)		 /*				    */
    {						 /*				    */
     DRETCD;					 /*				    */
     return(rc);				 /*				    */
    }						 /*				    */
  DRETCD;					 /*				    */
  if (current_dosver != DOS_VERSION)		 /* valid DOS version? from constant*/
    {						 /*				    */
     return(ERROR_INVALID_DOSVER);		 /* no -> invalid DOS version error */
    }						 /*				    */
						 /*				    */
/*************************************/
/*				     */
/*    verify NLS enviroment	     */
/*				     */
/*************************************/
						 /*				    */
  DCALL(COM_SETTBL);				 /*				    */
  rc = com_settbl();				 /* NLS is enable?		    */
  DRETCD;					 /*				    */
  return(rc);					 /* return any error		    */
}
