home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / som / include / somport.h < prev    next >
C/C++ Source or Header  |  1999-02-22  |  16KB  |  478 lines

  1. /***!Start!***                                                                     
  2.  *                                                                                 
  3.  *   ORIGINS: 27                                                                   
  4.  *                                                                                 
  5.  *   IBM CONFIDENTIAL -- (IBM Confidential Restricted when                         
  6.  *   combined with the aggregated modules for this product)                        
  7.  *   OBJECT CODE ONLY SOURCE MATERIALS                                             
  8.  *                                                                                 
  9.  *     25H7912  (C)   COPYRIGHT International Business Machines Corp. 1992,1994,1996,1996  
  10.  *   All Rights Reserved                                                           
  11.  *   Licensed Materials - Property of IBM                                          
  12.  *   The source code for this program is not published or otherwise divested       
  13.  *   of its trade secrets, irrespective of what has been deposited with the        
  14.  *   U.S. Copyright Office.                                                        
  15.  *                                                                                 
  16.  ***!End!***/                                                                      
  17.                                                                                    
  18. /*
  19.  *    @(#) 1.10 src/win/win/somport.h, somwin, som2.1 1/3/96 17:05:34 [7/30/96 15:13:48]
  20.  */
  21. /**************************************************************************\
  22.  * SOMPORT.H
  23.  *
  24.  * Header file for functions written by CP for MS Windows 3.1 
  25.  * version of SOM.
  26.  * 
  27.  * Has -> STUBLIB, WINPRINT, FINDORD, GETMSG
  28.  *
  29. \**************************************************************************/
  30. #ifndef _SOMPORT_H_
  31. #define _SOMPORT_H_
  32.  
  33. /**************************************************************************\
  34.  * Short forms of SOM_METHOD_THUNKS, SOM_DATA_THUNKS and SOM_METHOD_STUBS *
  35. \**************************************************************************/
  36.  
  37. #if (defined(_SOM_ALL) || defined(_SOM_MT)) && ! defined(SOM_METHOD_THUNKS)
  38.     #define SOM_METHOD_THUNKS   1
  39. #endif
  40. #if (defined(_SOM_ALL) || defined(_SOM_DT)) && ! defined(SOM_DATA_THUNKS)
  41.     #define SOM_DATA_THUNKS    1
  42. #endif
  43. #if (defined(_SOM_ALL) || defined(_SOM_MS)) && ! defined(SOM_METHOD_STUBS)
  44.     #define SOM_METHOD_STUBS    1
  45. #endif
  46.  
  47. /**************************************************************************\
  48.  * 
  49.  * WINDOWS 16 BIT port specific code for the runtime
  50.  *
  51. \**************************************************************************/
  52. #ifdef _WIN16
  53.   #define FAR _far
  54.   #define SIZET_CAST (size_t)
  55. #else
  56.   #define FAR 
  57.   #define SIZET_CAST 
  58.   #define W16_FAR 
  59. #endif
  60.  
  61. #ifdef _WIN16     
  62.   #define IN
  63.   #define OUT
  64.   #define INOUT
  65.  
  66.   #include <stdarg.h>
  67.   #include <process.h>
  68.   #ifndef WIN16_NOINCL_STDLIB 
  69.   #include <stdlib.h>
  70. #endif
  71.  
  72. #ifdef _WIN16
  73.   #define W16LOADDS __loadds 
  74.   #define W16PASCAL __pascal 
  75.   #if (defined(__ZTC__) && !defined(__SC__)) || defined(MULTINST)
  76.     #undef W16LOADDS
  77.     #define W16LOADDS 
  78.     #undef SOMLINK
  79.     #define SOMLINK 
  80.     #undef SOMDLINK
  81.     #define SOMDLINK
  82.     #undef W16PASCAL
  83.     #define W16PASCAL
  84.   #endif
  85. #endif
  86.  
  87. #include <stdio.h>
  88. #undef FILENAME_MAX
  89. #define FILENAME_MAX 260
  90.  
  91. #include <sys\types.h>
  92. #ifndef __SC__
  93. #include <sys\timeb.h>
  94. #endif
  95. #include <sys\stat.h>
  96. #include <string.h>
  97. #include <stddef.h>
  98.  
  99. #include <windows.h>
  100. #undef ERROR
  101.  
  102. #include <toolhelp.h>
  103.  
  104. /*
  105. ===========================================================================
  106. == Defines
  107. ===========================================================================
  108. */
  109. #ifdef _WINDLL
  110. #define getenv GetDllEnv
  111. #define access _access
  112. #define getcwd _getcwd
  113. #define fdopen _fdopen
  114. #define fstat _fstat
  115. #define stat _stat
  116. #define sopen _sopen
  117. #define open   _open
  118. #define read _read
  119. #define write _write
  120. #define lseek _lseek
  121. #define chsize _chsize
  122. #define close _close
  123. #define ftime _ftime
  124. #define timeb _timeb
  125. #define sscanf somw16sscanf
  126. #define fscanf somw16fscanf
  127. #define fflush somw16fflush
  128. #define fprintf somw16fprintf
  129. #define vsprintf somw16Wvsprintf
  130. #define sprintf somw16Wsprintf
  131. #define LoadModule W16LoadModule
  132. #define exit(x) TerminateApp(0,NO_UAE_BOX);
  133. #define perror somPrintf
  134. #define getpid _getpid 
  135. #define fileno _fileno
  136. #define stdout NULL
  137. #define stderr NULL
  138.  
  139.  
  140. #endif
  141.  
  142. /*
  143. ===========================================================================
  144. == Macros
  145. ===========================================================================
  146. */
  147.  
  148. /*
  149. ===========================================================================
  150. == WIN16THUNKS and WIN16STUBS
  151. ===========================================================================
  152. */
  153. /* WIN16THUNKS and WIN16STUBS. need to call memcpy function and not 
  154.  * intrinsic version that is generated with -Oi (which is needed for floats).
  155.  */
  156. #pragma function(memcpy)   
  157.  
  158. /* Turn off intrinsic function for memcpy. "-Oi" assumes _ThunkStub
  159.  * is in current code segment 
  160.  */
  161. WORD FAR PASCAL SelectorAccessRights(WORD wSel, WORD wOp, WORD wParam);
  162. #define RIGHTS(wSel) (SelectorAccessRights((wSel),0,0))
  163. #define IS_CODE(wSel) (RIGHTS(wSel) & 8)
  164.  
  165. /*
  166. ===========================================================================
  167. == TypeDefs
  168. ===========================================================================
  169. */
  170. typedef unsigned long APIRET;
  171. typedef unsigned long ULONG;
  172.  
  173. /*
  174. ===========================================================================
  175. == Wide string character functions
  176. ===========================================================================
  177. */
  178. size_t wcslen( const wchar_t * w_string);
  179. wchar_t * wcschr( const wchar_t * w_string, wchar_t w_char );
  180.  
  181. /*
  182. ===========================================================================
  183. == DosSleep
  184. ===========================================================================
  185. */
  186. unsigned long _far DosSleep(unsigned long x);
  187.  
  188. /*
  189. ===========================================================================
  190. == WINPRINT
  191. ==
  192. == FUNCTION: Prints a message given in pszMsgString via SOMMSG.EXE
  193. == RETURN  : 0 for success, 1 otherwise
  194. ===========================================================================
  195. */
  196. extern char WinPrintBuf[256]; /* defined in winprint.c */
  197. short _far _pascal WinPrint (char _far * pszMsgString);
  198.  
  199.  
  200. /*
  201. ===========================================================================
  202. == FILEIO
  203. ==
  204. == FUNCTION: Replaces the buffered io with unbuffered
  205. == RETURN  : 
  206. ===========================================================================
  207. */
  208. long __cdecl somw16ftell(FILE *stream);
  209. size_t __cdecl somw16fwrite (const void *buffer,size_t size,size_t count,
  210.                              FILE *stream);
  211. size_t __cdecl somw16fread(void *buffer,size_t size,size_t count,FILE *stream);
  212. int __cdecl somw16fseek(FILE *stream, long offset, int origin);
  213.  
  214.  
  215. /*
  216. ===========================================================================
  217. == SOMW16WSPRINTF,SOMW16WVSPRINTF -> accomodate the %f %g %d *
  218. == SOMW16VSCANF, SOMW16SSCANF, SOMW16FSCANF -> windows implementation
  219. == SOMW16FFLUSH -> null function. No flushing in windows
  220. == 
  221. == Input: same as the sprintf and vsprintf functions
  222. == 
  223. == Returns: num of chars stored in buf
  224. ===========================================================================
  225. */
  226. extern int somw16Wsprintf (char* buffer, char* format, ...);
  227. extern int somw16Wvsprintf (char* buffer, char* format, va_list ap);
  228. extern int somw16vsscanf(const char *s,const char *format, va_list ap);
  229. extern int somw16sscanf(const char *s,const char *format, ...);
  230. extern int somw16fscanf(FILE *fp,const char *format, ...);
  231. extern int somw16fflush(FILE *stream);
  232. extern int somw16fprintf(FILE *fp,const char *format, ...);
  233.  
  234. /*
  235. ===========================================================================
  236. == FINDORD
  237. ==
  238. == FUNCTION: Given an instance of a dll module and a function name, it 
  239. ==           will find the ordinal number in the dll's resident and 
  240. ==           nonresident name tables.
  241. == RETURN  : The ordinal number if successful, 0 otherwise.
  242. ===========================================================================
  243. */
  244. extern WORD somw16FindOrdinal(HINSTANCE hInst, LPSTR lpszFuncName);
  245.  
  246.  
  247. /*
  248. ===========================================================================
  249. == GETMSG
  250. ==
  251. == FUNCTION: Replaces OS2 DosGetMessage. Looks up a message in file 
  252. ==           produced by mconvert.
  253. ==           
  254. == RETURN  : 
  255. ===========================================================================
  256. */
  257. int __far __pascal DosGetMessage( char* [], unsigned long, char*, unsigned long, unsigned long, char*, unsigned long* );
  258. extern char * GetDllEnv(const char * s);
  259. extern void SearchDllEnv(char *, char *, char *);
  260.  
  261. /*
  262.  * Error codes that are returned by DosGetMessage()
  263.  */
  264.  
  265. #ifndef NO_ERROR
  266. #define NO_ERROR                    0
  267. #endif
  268. #define ERROR_FILE_NOT_FOUND        2
  269. #define ERROR_FILENAME_EXCED_RANGE  206
  270. #define ERROR_MR_MSG_TOO_LONG       316
  271. #define ERROR_MR_MID_NOT_FOUND      317
  272. #define ERROR_MR_UN_ACC_MSGF        318
  273. #define ERROR_MR_INV_MSGF_FORMAT    319
  274. #define ERROR_MR_INV_IVCOUNT        320
  275. #define ERROR_MR_UN_PERFORM         321
  276.  
  277. /*
  278. ===========================================================================
  279. == SOMYIELD -> yield control back to Windows, allow Windows to go idle
  280. == 
  281. == Input:   pwRc  - set to exit code from WM_QUIT message
  282. == 
  283. == Returns: TRUE  - Continue processing
  284. ==          FALSE - a WM_QUIT message was posted to the message queue
  285. ===========================================================================
  286. */
  287. extern BOOL somw16Yield(WORD *pwRc);
  288.  
  289.  
  290. /*
  291. ===========================================================================
  292. == SOMW16STARTINVISWIN -> opens an invisible window. Used for queueing.
  293. == 
  294. == Input:   WndProc  - handle to window procedure
  295. ==             data     - window creation data
  296. == 
  297. == Returns: TRUE  - Continue processing
  298. ==          FALSE - Could not create Window.
  299. ===========================================================================
  300. */
  301. extern BOOL somw16StartInvisWin(WNDPROC WndProc, VOID *data);
  302.  
  303. /*
  304. ===========================================================================
  305. == SOMW16ATEXIT-> register a function to be called on program exit, used
  306. ==                only from DLLs
  307. == 
  308. == Input:   func     - ptr to function to be called at program exit
  309. == 
  310. == Returns: N/A
  311. ===========================================================================
  312. */
  313. void somw16Atexit(void (__cdecl *func)(void));
  314.  
  315. #endif /* _WIN16 */
  316.  
  317.  
  318. /**************************************************************************\
  319.  * 
  320.  * WINDOWS 16 BIT port specific code for the SOM COMPILER
  321.  *
  322. \**************************************************************************/
  323. #ifdef _WDOS
  324.  
  325. #ifndef __SOMEMIT__
  326.     #define __SOMEMIT__ 1
  327. #endif
  328.  
  329. /**************************************************************************
  330.  * Includes
  331.  **************************************************************************/
  332. #include <stdio.h>
  333. #undef FILENAME_MAX
  334. #define FILENAME_MAX 260
  335. #undef stderr
  336. #define stderr stdout
  337.  
  338. /**************************************************************************
  339.  * Typedefs
  340.  **************************************************************************/
  341. typedef unsigned long ULONG;
  342. typedef unsigned long APIRET;
  343.  
  344. /**************************************************************************
  345.  * WIDE character string function
  346.  **************************************************************************/
  347. size_t wcslen( const wchar_t * w_string);
  348. wchar_t * wcschr( const wchar_t * w_string, wchar_t w_char );
  349.  
  350. /**************************************************************************
  351.  * GETMSG
  352.  **************************************************************************/
  353. extern int DosGetMessage( char* [], unsigned long, char*, unsigned long, unsigned long, char*, unsigned long* );
  354.  
  355. #define NO_ERROR                    0
  356. #define ERROR_FILE_NOT_FOUND        2
  357. #define ERROR_FILENAME_EXCED_RANGE  206
  358. #define ERROR_MR_MSG_TOO_LONG       316
  359. #define ERROR_MR_MID_NOT_FOUND      317
  360. #define ERROR_MR_UN_ACC_MSGF        318
  361. #define ERROR_MR_INV_MSGF_FORMAT    319
  362. #define ERROR_MR_INV_IVCOUNT        320
  363. #define ERROR_MR_UN_PERFORM         321
  364.  
  365. #define MAXLEN                      256
  366. #define MSGIDLEN                    11
  367. #define FILEOPENMODE                "r"
  368. #define NUMBASE                     48   // 48 is 0 on the ASCII table
  369.  
  370. /**************************************************************************
  371.  * W16MEM
  372.  **************************************************************************/
  373. extern void * somw16Malloc(size_t numbytes);
  374. extern void * somw16Calloc(size_t numelems, size_t sizelem);
  375. extern void * somw16Realloc(void *ptr, size_t size);
  376. extern void somw16Free(void* p);
  377. extern void somw16FreeAll (void);
  378.  
  379. /**************************************************************************
  380.  * FSOPEN for zortech.
  381.  **************************************************************************/
  382. FILE * somw16fsopen(const char *name,const char *mode, int shflag);
  383. #endif /* WDOS */
  384.  
  385. /**************************************************************************
  386.  * Test case macros.
  387.  **************************************************************************/
  388. #ifdef _WIN16
  389. #include <io.h>        /* This is for the quickwin prototypes */
  390. #define WIN16_SETEXIT_NOPERSIST _wsetexit(_WINEXITNOPERSIST);
  391. #define WIN16_SETEXIT_PERSIST   _wsetexit(_WINEXITPERSIST);
  392. #define WIN16_SOMEXIT           atexit(somEnvironmentEnd);
  393. #define somFreeModules          somEnvironmentEnd
  394. #ifndef __cplusplus
  395. #define WIN16_FIX_WINDOW {extern HWND _hWndClient; \
  396.         SetWindowText(GetWindow(_hWndClient,GW_CHILD),""); \
  397.         ShowWindow(GetWindow(_hWndClient,GW_CHILD),SW_SHOWMAXIMIZED);}
  398. #define WIN16_KILL_WINDOW {extern HWND _hWndFrame; \
  399.                            PostMessage(_hWndFrame,WM_CLOSE,0,0L);}
  400. #else
  401. #define WIN16_FIX_WINDOW 
  402. #define WIN16_KILL_WINDOW
  403. #endif
  404. #else
  405. #define WIN16_SETEXIT_NOPERSIST 
  406. #define WIN16_SETEXIT_PERSIST   
  407. #define WIN16_SOMEXIT          
  408. #define WIN16_FIX_WINDOW
  409. #define WIN16_KILL_WINDOW 
  410. #endif
  411.  
  412.  
  413. #if defined(_WIN16) && defined(WIN16_OUTCHAR_OVERRIDES)
  414. #define WIN16_OUTCHAR_SCREEN somSetOutChar(OutCharRoutineScreen);
  415. #define WIN16_OUTCHAR_FILE   somSetOutChar(OutCharRoutineFile);
  416. #define OUTCHAR_BUF 256
  417. static char msgbuf[OUTCHAR_BUF];
  418. static int msgindex=0;
  419.  
  420. #ifdef WIN16_OUTCHAR_FILENAME
  421. char outcharfilename[]=WIN16_OUTCHAR_FILENAME;
  422. #else
  423. char outcharfilename[]="w16chout.fil";
  424. #endif
  425.  
  426. #include <stdio.h>
  427. #include <string.h>
  428. #include <stdlib.h>
  429. #include <errno.h>
  430. #include <share.h>
  431.  
  432. int _loadds OutCharRoutineScreen(char c)    /* Override outchar routine to screen */
  433. {                                                 
  434.     if (c == '\r')
  435.       return 0;
  436.     msgbuf[msgindex++] = c;
  437.     if (c == '\0' || msgindex==OUTCHAR_BUF-1 )
  438.     {
  439.       msgbuf[msgindex] = '\0';
  440.       printf("%s",msgbuf);
  441.       msgindex = 0;
  442.      }
  443.  
  444.     return 0;
  445. }
  446.  
  447. int _loadds OutCharRoutineFile(char c)    /* Override outchar routine to file */
  448. {
  449.     static FILE *pfFile;
  450.     int rc;
  451.      
  452.     if (c == '\r')
  453.       return 1;
  454.     msgbuf[msgindex++] = c;
  455.     if (c == '\0' || msgindex==OUTCHAR_BUF-1 )
  456.     {
  457.       if ((pfFile=_fsopen(outcharfilename, "a", _SH_DENYNO)) == NULL)
  458.           return 1; 
  459.  
  460.       msgbuf[msgindex] = '\0';
  461.       rc = fputs(msgbuf, pfFile);
  462.       printf("%s",msgbuf);
  463.       msgindex = 0;
  464.  
  465.        fclose(pfFile);             /* Close when newline encountered */
  466.      }
  467.  
  468.     return (rc == -1 ? 1 : 0);      /* if -1 then error. 0 = success */
  469. }
  470.  
  471. #else
  472. #define WIN16_OUTCHAR_SCREEN
  473. #define WIN16_OUTCHAR_FILE  
  474. #endif
  475.  
  476.  
  477. #endif /* SOMPORT.H  No more after here */
  478.