| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | detecting OS/2 and share support etc |
> How can I detect whether my program is running under a multitasker
----- TASKER.H begins -----
/*
** Tasker.H
**
** public domain by David Gibbs
*/
#ifndef DG_TASKER
#define DG_TASKER
struct ts_os_ver {
int maj;
int min;
};
#define TOT_OS 5
#define DOS 0
#define OS2 1
#define DV 2
#define WINS 3
#define WIN3 4
/* 76543210 */
#define is_DOS 0x01 /* b'00000001' */
#define is_OS2 0x02 /* b'00000010' */
#define is_DV 0x04 /* b'00000100' */
#define is_WINS 0x08 /* b'00001000' */
#define is_WIN3 0x10 /* b'00010000' */
extern int t_os_type;
extern int t_os;
extern const char *t_os_name[TOT_OS];
extern struct ts_os_ver t_os_ver[TOT_OS];
/* Function prototypes */
int get_os();
void t_slice();
#endif /* DG_TASKER */
----- TASKER.H ends -----
----- TASKER.C begins -----
/*
** Tasker.C
**
** public domain by David Gibbs
*/
struct ts_os_ver t_os_ver[TOT_OS];
int t_os_type;
int t_os;
const char *t_os_name[TOT_OS] = {
"DOS",
"OS/2 DOS",
"DESQview",
"Windows Std",
"Windows 386"
};
int get_os (void)
{
union REGS t_regs;
t_os_type = 0;
t_os = 0;
/* test for DOS or OS/2 */
if (_osmajor < 10)
{
t_os_ver[DOS].maj = _osmajor;
t_os_ver[DOS].min = _osminor;
t_os_type = t_os_type | is_DOS;
}
else
{
t_os_type = t_os_type | is_OS2;
t_os_ver[OS2].maj = _osmajor/10;
t_os_ver[OS2].min = _osminor;
}
/* test for Windows */
t_regs.x.ax = 0x4680;
int86(0x2F, &t_regs, &t_regs);
if (t_regs.x.ax == 0x0000)
{
t_os_ver[WINS].maj = 3;
t_os_ver[WINS].min = 0;
t_os_type = t_os_type | is_WINS;
}
else
{
t_regs.x.ax = 0x1600 ;
int86(0x2F, &t_regs, &t_regs);
switch (t_regs.h.al)
{
case 0x00 :
case 0x80 :
case 0x01 :
case 0xFF :
break;
default :
t_os_type = t_os_type | is_WIN3;
t_os_ver[WIN3].maj = t_regs.h.al;
t_os_ver[WIN3].min = t_regs.h.ah;
break ;
} /* endswitch */
} /* endif */
/* Test for DESQview */
t_regs.x.cx = 0x4445; /* load incorrect date */
t_regs.x.dx = 0x5351;
t_regs.x.ax = 0x2B01; /* DV set up call */
intdos(&t_regs, &t_regs);
if (t_regs.h.al != 0xFF)
{
t_os_type = t_os_type | is_DV;
t_os_ver[DV].maj = t_regs.h.bh;
t_os_ver[DV].min = t_regs.h.bl;
}
if(t_os_type & is_DOS)
t_os = DOS;
if(t_os_type & is_WINS)
t_os = WINS;
if(t_os_type & is_WIN3)
t_os = WIN3;
if(t_os_type & is_DV)
t_os = DV;
if(t_os_type & is_OS2)
t_os = OS2;
return(t_os-1);
}
void t_slice(void)
{
union REGS t_regs;
switch (t_os)
{
case DOS :
break;
case OS2 :
case WIN3 :
case WINS :
t_regs.x.ax = 0x1680;
int86(0x2f,&t_regs,&t_regs);
break;
case DV :
t_regs.x.ax = 0x1000;
int86(0x15,&t_regs,&t_regs);
break;
} /* switch(t_os) */
}
----- TASKER.C ends -----
----- TASKER.TXT begins -----
Multi-Tasker Detection Routines
by David Gibbs
FidoNet: 1:115/439.0
Internet: David.Gibbs{at}f439.n115.z1.fidonet.org
The following is a set of C routines that will enable a programmer to
detect a mutli-tasking environment and release the time slice when
desired. Currently DESQview, Windows, & OS/2 are the environments
supported.
Routines consist of two functions, two global int variables, one global
structure, and a table of character pointers.
void t_get_os(); This routines detects the operating environment, sets
on the appropriate bits in the t_os_type field, and sets the t_os field
to the dominant environment.
void t_slice(); This routine will release the remainder of the current
tasks time slice in the manner appropriate to the dominant envionment.
The following fields & structures are available...
int t_os_type; is a bit mapped integer that indicates the presence of
various operating envionments. If Bit 0 is on, DOS is present, Bit 1 =
OS2, bit 2 = DESQview, bit 3 = Windows standard, bit 4 = Windows 386
Enh. These bits can be tested by using logical operations with the
symbolic constants is_DOS, is_OS2, is_DV, is_WINS, and is_WIN3.
int t_os; represents the dominant environment. The dominant envionment
is defined as the multi-tasking system that takes precidence. For
instance, you can run Windows *UNDER* DESQview, but DESQview would be
dominant, the same goes true for OS/2 & Windows. This value can be
tested by comparing to the symbolic constants: DOS, OS2, DV, WINS, and
WIN3.
struct t_os_ver ts_os_ver[]; indicates the versions of the various
environments present. Major & minor versions are found in the
structure members 'maj' and 'min'. The structure is subscripted, so you
can access the version of envionments using the symbolic constants use
in 't_os'.
const char *t_os_name[]; contains the names of the environments
detectable. These too are subscripted and can be accessed using the
symbolic constants above.
A sample program that uses these routines follows:
#include
#include "tasker.h"
void main() {
get_os();
printf("%s %d.%d detected",t_os_name[t_os],
t_os_ver[t_os].maj,
t_os_ver[t_os].min);
while(!kbhit()) {
printf("Hit a key!\r\n");
t_slice();
}
}
Special thanks go to Geoffery Booher (1:2270/233) for assistance with
Windows & OS/2 detection & Time slicing.
This routine is released to the public as CommentWare - If you use it,
please send me a comment as to what you thought of it... oh yeah, you
might think of giving me credit for the routines.
Also, if you can think of a enhancement or correction, please let me
know. I can be reached at the above mentioned email addresses.
Copyrights: DESQview by Quarterdeck Office Systems
Windows by Microsoft
OS/2 by IBM
TurboC++ by Borland
----- TASKER.TXT ends -----
> or if SHARE support is present etc?
----- XCLIB.H begins -----
/*
* XCLIB.H
*
* ---------------------------------------------------------------------------
*
* LEGAL NOTICE:
*
* This software was written by Scott Pitcher. It is presented without
* copyright, so anyone may use this code for what ever reason they wish
* without restriction, as long as they understand that the author gives
* no guarantee, warrantee, or statement of suitability or fitness for
* use of any kind.
*
* ---------------------------------------------------------------------------
*
* Extended C library functions and defs.
*/
#if !defined(__XCLIB_H)
#define __XCLIB_H
#include
#include
/* types */
#if __TURBOC__
#if __TINY__ || __SMALL__ || __COMPACT__
#define _FuncPtr near *
#else
#define _FuncPtr far *
#endif /* memory model */
#if __CDECL__
#define _FuncType cdecl
#define _DataType cdecl
#elif __PASCAL__
#define _FuncType pascal
#define _DataType pascal
#else
#define _FuncType cdecl
#define _DataType cdecl
#endif /* language type */
#else
#define _FuncPtr *
#define _FuncType
#define _DataType
#endif /* __TURBOC__ */
#ifdef __cplusplus
extern "C" {
#endif
/* universal status function constants */
#define STATUS_ON 1
#define STATUS_OFF 0
/* ansi colours and attributes */
#define ANSI_NORMAL 0
#define ANSI_INTENSE 1
#define ANSI_UNDERSCORE 4
#define ANSI_BLINKING 5
#define ANSI_REVERSE 7
#define ANSI_INVISIBLE 8
#define ANSI_BLACK 0
#define ANSI_RED 1
#define ANSI_GREEN 2
#define ANSI_YELLOW 3
#define ANSI_BLUE 4
#define ANSI_MAGENTA 5
#define ANSI_CYAN 6
#define ANSI_LIGHTGREY 7
#define ANSI_GREY 8
#define ANSI_LIGHTRED 9
#define ANSI_LIGHTGREEN 10
#define ANSI_LIGHTYELLOW 11
#define ANSI_LIGHTBLUE 12
#define ANSI_LIGHTMAGENTA 13
#define ANSI_LIGHTCYAN 14
#define ANSI_WHITE 15
/* config file parser return constants */
#define NOCFGFILE -1
#define OPENCFGFAILURE -2
#define READCFGFAILURE -3
#define ENDOFCFGFILE -4
#define CFGLINETOOLONG -5
#define MISSINGCFGPARAM -6
#define ILLEGALCFGARG -7
#define MISSINGCFGARG -8
void _FuncType ParseConfigFile(void (*AppConfigProc)(char *, char *, int, int),
char **pArgs,
char *filename,
int case_flag);
/* command line parser return constants */
#define NOTASWITCH -1
#define ILLEGALSWITCH -2
#define EXTRAPARAMS -3
void _FuncType ParseCommandLine(void (*AppCmdProc)(char *,char *,int),
char **pArgv,
char **pArgs,
int bCaseFlag);
/* config and command line constants */
#define NOIGNORECASE 0
#define IGNORECASE 1
/* extended file structure */
typedef struct {
char *path;
int fd;
} GFILE;
/* Ansi terminal functions */
char * _FuncType AnsiCursorLeft(int n);
char * _FuncType AnsiCursorRight(int n);
char * _FuncType AnsiCursorDown(int n);
char * _FuncType AnsiCursorUp(int n);
char * _FuncType AnsiSetCursor(int x, int y);
char * _FuncType AnsiCursorRestore(void);
char * _FuncType AnsiCursorSave(void);
char * _FuncType AnsiClrEol(void);
char * _FuncType AnsiClrScrn(void);
int _FuncType AnsiPrintf(const char *format, ...);
int _FuncType AnsiPutch(int ch);
char * _FuncType AnsiAttribute(unsigned attrib);
char * _FuncType AnsiColour(int fore, int back);
/* file lock notification types */
#define FL_OPEN 1
#define FL_WRITE 2
#define FL_READ 3
#define FL_LOCK 4
#define FL_UNLOCK 5
/* Extended low level file functions */
GFILE * _FuncType gsopen(char *path, unsigned access, unsigned share, unsigned mode);
int _FuncType gclose(GFILE *gfd);
int _FuncType gwrite(GFILE *gfd, void *buf, unsigned len);
int _FuncType gread(GFILE *gfd, void *buf, unsigned len);
int _FuncType glock(GFILE *pFile, long offset, long length);
int _FuncType gunlock(GFILE *pFile, long offset, long length);
int _FuncType GetLockRetryCount(void);
void _FuncType SetLockRetryCount(int n);
void _FuncType SetFileLockAppHook(int (* _FuncType)(char *,int,int));
void _FuncPtr GetFileLockAppHook(void);
/* extended memory allocation & heap functions */
void * _FuncType gmalloc(size_t size);
void _FuncType gfree(void *p);
void _FuncType MemHeapDump(char *fn_name);
void _FuncType SetHeapFreeDebugStatus(int iStatus);
void _FuncType SetHeapAllocDebugStatus(int iStatus);
void _FuncType SetHeapDebugStatus(int iStatus);
int _FuncType GetHeapAllocDebugStatus(void);
int _FuncType GetHeapFreeDebugStatus(void);
int _FuncType GetTotalMallocCount(void);
long _FuncType GetTotalMallocSize(void);
/* general functions */
int _FuncType IsShareInstalled(void);
/* communications data structures */
extern int _DataType iComIoPort;
extern unsigned _DataType uComIoCtrl;
extern unsigned _DataType uComStatus;
struct FossilDriverInfo {
unsigned uFossilInfoSize;
char bFossilVersion;
char bFossilRevision;
char far *szFossilDriverName;
unsigned uFossilInBufferSize;
unsigned uFossilInBufUsed;
unsigned uFossilOutBufSize;
unsigned uFossilOutBufUsed;
char bScreenCols;
char bScreenRows;
char bBaudRate;
};
/* modem status bits */
#define FS_DELTA_CTS 0x0001 /* change in clear to send */
#define FS_DELTA_DSR 0x0002 /* change in data set ready */
#define FS_EDGE_DETECT 0x0004 /* trailing edge of ring indicator */
#define FS_DELTA_CD 0x0008 /* change in receive line signal */
#define FS_CTS 0x0010 /* clear to send */
#define FS_DSR 0x0020 /* data set ready */
#define FS_RING_DETECT 0x0040 /* ring detected */
#define FS_CD 0x0080 /* carrier detect */
/* rs232 status bits */
#define FS_DATA_READY 0x0100 /* data ready */
#define FS_OVERRUN_ERR 0x0200 /* data overrun error */
#define FS_PARITY_ERR 0x0400 /* data parity error */
#define FS_FRAME_ERR 0x0800 /* framing error */
#define FS_BRK_DETECT 0x1000 /* break detected */
#define FS_TBUFREG_EMP 0x2000 /* transmission buffer reg empty */
#define FS_BUF_FREE 0x2000 /* fossil - buffer space available */
#define FS_TSFTREG_EMP 0x4000 /* transmission shift register empty */
#define FS_BUF_EMPTY 0x4000 /* fossil - buffer empty */
#define FS_TIME_OUT 0x8000 /* time out - other bits invalid */
/* fossil initialise control bits */
#define FC_BPS_19200 0x00
#define FC_BPS_38400 0x20
#define FC_BPS_300 0x40
#define FC_BPS_600 0x60
#define FC_BPS_1200 0x80
#define FC_BPS_2400 0xA0
#define FC_BPS_4800 0xC0
#define FC_BPS_9600 0xE0
#define FC_PARITY_NONE 0x00
#define FC_PARITY_ODD 0x08
#define FC_PARITY_EVEN 0x18
#define FC_STOP_BIT_1 0x00
#define FC_STOP_BIT_2 0x04
#define FC_DATA_BIT_5 0x00
#define FC_DATA_BIT_6 0x01
#define FC_DATA_BIT_7 0x02
#define FC_DATA_BIT_8 0x03
/* fossil/comms. library control flag bits */
#define ENABLE_CON_IN 0x0001
#define ENABLE_CON_OUT 0x0002
#define ENABLE_FOS_IN 0x0004
#define ENABLE_FOS_OUT 0x0008
#define REMOTE_ACTIVE 0x0010
#define FOSSIL_INIT 0x0020
#define UART_INIT 0x0040 /* not yet implemented */
#define ENABLE_CDWATCH 0x0080
#define LOCAL_READ 0x0100
#define LOCAL_WRITE 0x0200
#define REMOTE_READ 0x0400
#define REMOTE_WRITE 0x0800
#define IO_STATUS_MASK 0x0F00
/* comms init constants */
#define COM_INIT_DETECT 0
#define COM_INIT_FOSSIL 1
#define COM_INIT_UART 2 /* not yet implemented */
/* fossil driver functions */
int _FuncType FossilDriverInit(void);
int _FuncType FossilDriverUnInit(void);
int _FuncType FossilGetDriverInfo(struct FossilDriverInfo *finf);
int _FuncType FossilWriteBlock(int n, char *buf);
int _FuncType FossilReadBlock(int n, char *buf);
int _FuncType FossilTimerTickChain(int action, void far interrupt (*fn)());
int _FuncType FossilCarrierWatchDog(int action);
int _FuncType FossilPurgeInBuffer(void);
int _FuncType FossilPurgeOutBuffer(void);
int _FuncType FossilFlushOutBuffer(void);
long _FuncType FossilGetTickParameters(void);
unsigned int _FuncType FossilRequestStatus(void);
int _FuncType FossilReadChar(void);
int _FuncType FossilWriteChar(char c);
int _FuncType FossilWaitReadChar(void);
int _FuncType FossilWaitWriteChar(char c);
int _FuncType FossilSetDtr(int i);
/* higher level comms functions */
int _FuncType ComInit(int iType, int iPort);
void _FuncType ComUnInit(void);
void _FuncType ComSetPort(int n);
int _FuncType ComGetPort(void);
int _FuncType ComPuts(const char *s);
int _FuncType ComPrintf(const char *format, ...);
int _FuncType ComPutc(int c);
int _FuncType ComGetc(void);
int _FuncType ComKbhit(void);
unsigned _FuncType ComPollInStr(void);
void _FuncType ComPollDualInStr(unsigned int *, unsigned int *);
clock_t _FuncType GetLastKeyTime(void);
void _FuncType SetLastKeyTime(clock_t kt);
int _FuncType GetExtendedKeyDelay(void);
void _FuncType SetExtendedKeyDelay(int iDelay);
int _FuncType GetCarrierDropStatus(void);
void _FuncType SetCarrierDropStatus(int);
void _FuncPtr _FuncType GetCarrierDropProc(void);
void _FuncType SetCarrierDropProc(void (* _FuncType)(void));
int _FuncType GetTimerStatus(void);
void _FuncType SetTimerStatus(int);
void _FuncPtr _FuncType GetTimerProc(void);
void _FuncType SetTimerProc(void (* _FuncType)(clock_t,clock_t));
int _FuncType GetCpuIdleStatus(void);
void _FuncType SetCpuIdleStatus(int iStatus);
void _FuncPtr _FuncType GetCpuIdleProc(void);
void _FuncType SetCpuIdleProc(void (* _FuncType pCpuIdleProc)(void));
int _FuncType GetAppHotKeyStatus(unsigned char cHotKey);
void _FuncType SetAppHotKeyStatus(int iStatus, unsigned char cHotKey);
void _FuncPtr _FuncType GetAppHotKeyProc(unsigned char cHotKey);
void _FuncType SetAppHotKeyProc(void (* _FuncType pAppHotKeyProc)(void),
unsigned char cHotKey);
void _FuncType SetConOutProc(int (* _FuncType pConOutProc)(int));
void _FuncType SetConInProc(int (* _FuncType pConInProc)(void));
void _FuncType SetConReadyProc(int (* _FuncType pConRdyProc)(void));
int _FuncPtr _FuncType GetConOutProc(void);
int _FuncPtr _FuncType GetConInProc(void);
int _FuncPtr _FuncType GetConReadyProc(void);
/* in stream control macros */
#define ComEnableLocalInStr() (uComIoCtrl |= ENABLE_CON_IN)
#define ComDisableLocalInStr() (uComIoCtrl &= ~ENABLE_CON_IN)
#define ComEnableRemoteInStr() (uComIoCtrl |= ENABLE_FOS_IN)
#define ComDisableRemoteInStr() (uComIoCtrl &= ~ENABLE_FOS_IN)
/* out stream control macros */
#define ComEnableLocalOutStr() (uComIoCtrl |= ENABLE_CON_OUT)
#define ComDisableLocalOutStr() (uComIoCtrl &= ~ENABLE_CON_OUT)
#define ComEnableRemoteOutStr() (uComIoCtrl |= ENABLE_FOS_OUT)
#define ComDisableRemoteOutStr() (uComIoCtrl &= ~ENABLE_FOS_OUT)
/* i/o stream control macros */
#define ComEnableLocalStr() ComEnableLocalInStr(); ComEnableLocalOutStr();
#define ComDisableLocalStr() ComDisableLocalInStr(); ComDisableLocalOutStr();
#define ComEnableRemoteStr() ComEnableRemoteInStr(); ComEnableRemoteOutStr();
#define ComDisableRemoteStr() ComDisableRemoteInStr();
ComDisableRemoteOutStr();
/* i/o stream status macros */
#define ComGetLocalInStrStatus() (uComIoCtrl & ENABLE_CON_IN)
#define ComGetLocalOutStrStatus() (uComIoCtrl & ENABLE_CON_OUT)
#define ComGetRemoteInStrStatus() (uComIoCtrl & ENABLE_FOS_IN)
#define ComGetRemoteOutStrStatus() (uComIoCtrl & ENABLE_FOS_OUT)
/* i/o stream flag status macros */
#define ComIsLocalRead() (uComIoCtrl & LOCAL_READ)
#define ComIsLocalWrite() (uComIoCtrl & LOCAL_WRITE)
#define ComIsRemoteRead() (uComIoCtrl & REMOTE_READ)
#define ComIsRemoteWrite() (uComIoCtrl & REMOTE_WRITE)
/* general macros */
#define ComGetCarrierStatus() (FossilRequestStatus() & FS_CD ? 1 : 0)
#define ComGetRemoteActiveStatus() (uComIoCtrl & REMOTE_ACTIVE ? 1 : 0)
#define ComIsFossilInstalled() (uComIoCtrl & FOSSIL_INIT ? 1 : 0)
#define ComIsUartInstalled() (uComIoCtrl & UART_INIT ? 1 : 0)
#ifdef __cplusplus
}
#endif
#endif /* __XCLIB_H */
----- XCLIB.H ends -----
----- ISHARE.C begins -----
/*
* ISHARE.C
*
* ---------------------------------------------------------------------------
*
* LEGAL NOTICE:
*
* This software was written by Scott Pitcher. It is presented without
* copyright, so anyone may use this code for what ever reason they wish
* without restriction, as long as they understand that the author gives
* no guarantee, warrantee, or statement of suitability or fitness for
* use of any kind.
*
* ---------------------------------------------------------------------------
*
* Test if file sharing support installed (SHARE.EXE). Returns TRUE (1) if
* SHARE was detected, else FALSE (0).
*
* HISTORY:
* 05-Oct-93 ... first implemented.
* 27-Oct-94 Andrew Clarke: changed "EZM" tempnam() kludge to
"LOCK".
*/
#include
#include
#include
#include
#include
#include
#include
int _FuncType IsShareInstalled()
{
int i, fd;
char *pName = NULL, *pTmpDir;
/* attempt to use TEMP - if fails then TMP used by default */
pTmpDir = getenv("TEMP");
/* make 100 attempts to create a unique file name */
i = 0;
while(i < 100 && !pName) {
if((pName = tempnam(pTmpDir,"LOCK")) != NULL) {
if((fd = sopen(pName,O_RDWR | O_CREAT | O_TRUNC, SH_DENYRW, S_IREAD |
S_IWRITE)) != -1) {
free(pName);
/* file opened ok, now try to lock it */
if(lock(fd,0L,1) == -1 && errno == EINVAL) {
close(fd);
unlink(pName);
return 0;
}
else {
/* sharing support must be installed! */
unlock(fd,0L,1);
close(fd);
unlink(pName);
return 1;
}
}
}
++i;
}
return 0;
}
----- ISHARE.C ends -----
For those interested: FREQ "XLIB" from 3:633/267{at}fidonet (The
Programmer's Corner), for the remaining code contained in Scott Pitcher's
XLIB routines.
ZeeYa...
Andrew.
---
* Origin: Blizzard of Ozz, Long Beach City, Melbourne, OZ (3:633/267.1)SEEN-BY: 50/99 54/54 620/243 623/630 624/50 632/348 386 998 633/104 251 252 SEEN-BY: 633/253 259 260 262 267 269 371 373 634/384 635/301 502 503 541 544 SEEN-BY: 636/100 639/100 711/401 409 410 430 510 807 808 809 932 934 942 SEEN-BY: 712/623 713/888 714/906 800/1 @PATH: 633/267 252 371 635/503 50/99 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.