home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
api111.zip
/
ROPS
/
SMPUTILS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-18
|
9KB
|
225 lines
/* Miscellaneous Utility routines needed for SPA Router sample programs.
OS/2 Remote Operations
SPA Router SPCF API Sample Test program utility providing source
code file.
COPYRIGHT:
----------
(C) Copyright International Business Machines Corporation 1991
REVISION LEVEL: 1.0
---------------
Send a run command reply request code 0x0302
*/
#define INCL_BASE
#include <os2.h>
/* #include "acssvcc.h" to get OS/2 Communications Manager/2 Common Services
verb info here. We just include what we need here for our sample program
*/
/****************************************************************************/
/* 32 Bit Support */
/****************************************************************************/
#ifdef __32BIT__ /* 32-bit Compiler Options */
#pragma pack(1)
#define STRUCT16 struct
#define CALL16 _Far16 _Pascal
#define PTR16 * _Seg16
#define TYPECAST PVOID
#else /* 16-bit Compiler Options */
#define STRUCT16 struct
#define CALL16 far pascal
#define PTR16 far *
#define TYPECAST long
#endif
#ifdef __32BIT__ /* Structures aligned on 64KB boundary */
#pragma seg16(get_cp_convert_table)
#endif
#ifdef __32BIT__
extern void CALL16 ACSSVC(void PTR16);
extern USHORT APIENTRY16 Dos16GetCp(USHORT, USHORT PTR16, USHORT PTR16);
#else
extern void CALL16 ACSSVC(long);
#endif
#define SV_ASCII_TO_EBCDIC 0x00
#define SV_EBCDIC_TO_ASCII 0x01
#define SV_ROUND_TRIP 0x01
/*************************************************************/
/* Operation Codes */
/*************************************************************/
#define SV_GET_CP_CONVERT_TABLE 0x0019
/*************************************************************/
/* Service Structures */
/*************************************************************/
STRUCT16 get_cp_convert_table
{
unsigned short opcode; /* Verb operation code */
unsigned char opext; /* Verb extension code */
unsigned char reserv2; /* Reserved */
unsigned short primary_rc; /* Primary RETURN_CODE */
unsigned long secondary_rc; /* Secondary RETURN_CODE */
unsigned short source_cp; /* SOURCE_CODE_PAGE */
unsigned short target_cp; /* TARGET_CODE_PAGE */
unsigned char PTR16 conv_tbl_addr; /* CONVERT_TABLE_ADDR */
unsigned char char_not_fnd; /* CHARACTER_NOT_FOUND */
/* SV_SUBSTITUTE */
/* SV_ROUND_TRIP */
unsigned char substitute_char; /* SUBSTITUTE_CHARACTER */
};
BYTE xlatetbl[512] ; /* first 256 bytes ascii-to-ebcdic translation table */
/* next 256 bytes ebcdic-to-ascii translation table */
USHORT hostcodepage = 0; /* ebcdic host code page */
USHORT curcodepage = 0; /* ascii code page of our NetView sim process */
/* Convert Ebcdic <-> Ascii by using CONVERT VERB of OS/2 EE Comm Mgr */
/* Users call ConvertEtoA() or ConvertAtoE() macros which then get */
/* translated to this function call. */
USHORT convertEbcAscii ( sourceaddr, destinaddr, len , tarlen, dowhat )
BYTE *sourceaddr ;
BYTE *destinaddr ;
USHORT len ;
USHORT *tarlen ; /* target length, to be updated after trasnlation */
BYTE dowhat ;
{
BYTE *converttbl ; /* point to ebcdic-ascii convertion table */
USHORT ctr ;
if ( dowhat == SV_EBCDIC_TO_ASCII )
converttbl = xlatetbl+256 ; /* ebcdic to */
/* ascii table space is the last */
/* 256 bytes in table */
else
/* it is ascii to ebcdic convertion */
converttbl = xlatetbl ; /* ascii to ebcdic */
/* table space is the first */
/* 256 bytes in table */
for ( ctr = 0; ctr < len ; ctr++ )
destinaddr[ctr] = converttbl [ sourceaddr[ctr] ] ;
*tarlen = len ; /* update target byte length xlated, src=target for SBCS */
return (0) ; /* return OK */
}
/* Setup ascii-ebcdic translation tables by calling Comm Mgr/2 */
/* Get_CP_Convert_table verb. Ascii code page is obtained by calling the */
/* system's current code page. "ebcdiccp" is the EBCDIC code page to use */
/* to build the translation tables ; 1 from ascii to ebcdic, the other for */
/* ebcdic to ascii table. */
USHORT RoprXlateSetup ( ebcdiccp )
USHORT ebcdiccp ;
{
USHORT len ;
STRUCT16 get_cp_convert_table convtblvcb ; /* convert table cp verb ctl blk */
/**************************************************************************/
/* doscall to get current default ascii code page */
/**************************************************************************/
#ifdef __32BIT__
Dos16GetCp(2,
&curcodepage,
&len
);
#else
DosGetCp(2, /* we want current code page only */
&curcodepage,
&len /* len returned */
);
#endif
hostcodepage = ebcdiccp ; /* store ebcdic NetView code page for later use */
/* we will build the ascii <-> ebcdic tables now by calling */
/* OS/2 Comm Mgr/2. */
convtblvcb.opcode = SV_GET_CP_CONVERT_TABLE ; /* get convert table opcode */
convtblvcb.opext = 0x00 ; /* reserved */
convtblvcb.reserv2 = 0x00 ; /* reserved */
/* ascii to ebcdic table first */
convtblvcb.source_cp = curcodepage ; /* source code page */
convtblvcb.target_cp = ebcdiccp ; /* target code page */
convtblvcb.conv_tbl_addr = xlatetbl ; /* ascii to ebcdic table space */
convtblvcb.char_not_fnd = SV_ROUND_TRIP ; /* if char not found */
convtblvcb.substitute_char = 0x40 ; /* substitute char is 'space' in ebcdic */
/* call Com Mgr/2 for get_cp_convert_table verb ) */
ACSSVC( (TYPECAST) &convtblvcb ) ; /* AX register returned code is not set */
if ( convtblvcb.primary_rc )
return ( convtblvcb.primary_rc ) ; /* error occurred */
/* else build ebcdic to ascii table */
convtblvcb.opcode = SV_GET_CP_CONVERT_TABLE ; /* get convert table opcode */
convtblvcb.opext = 0x00 ; /* reserved */
convtblvcb.reserv2 = 0x00 ; /* reserved */
/* ebcdic to ascii table in the next space */
convtblvcb.source_cp = ebcdiccp ; /* source code page is ebcdic */
convtblvcb.target_cp = curcodepage ; /* target code page is ascii */
convtblvcb.conv_tbl_addr = xlatetbl+256 ; /* ebcdic to */
/* ascii table space is the next */
/* 256 bytes in table */
convtblvcb.char_not_fnd = SV_ROUND_TRIP ; /* if char not found */
convtblvcb.substitute_char = 0x20 ; /* substitute char is 'space' in ascii */
/* call Com Mgr/2 for get_cp_convert_table verb ) */
ACSSVC( (TYPECAST) &convtblvcb ) ; /* AX register returned code is not set */
if ( convtblvcb.primary_rc )
return ( convtblvcb.primary_rc ) ; /* error occurred */
else
return 0 ;
}
/* Copy "len" bytes from source to destination. */
void bytecopy ( source, destin, len )
BYTE *source ;
BYTE *destin ;
USHORT len ;
{
while ( len > 0 ) {
*destin++ = *source++ ;
len-- ;
}
}
/* swap bytes in an unsigned short */
void swapbytes( us_num)
USHORT *us_num ;
{
USHORT ustmp ;
ustmp = *us_num >> 8 ; /* get the high byte */
*us_num = ( *us_num << 8 ) ; /* put the low byte in high byte */
*us_num = *us_num | ustmp ; /* put the high byte in low */
}