home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / csp0194b.zip / PORTABLE.H < prev    next >
Text File  |  1994-01-02  |  7KB  |  202 lines

  1. /*====================================================================
  2.  
  3.     portable.h   v1.00      Written by Scott Robert Ladd.
  4.  
  5.     _MSC_VER        Microsoft C 6.0 and later
  6.     _QC             Microsoft Quick C 2.51 and later
  7.     __TURBOC__      Borland Turbo C, Turbo C++ and BC++
  8.     __ZTC__         Zortech C and C++
  9.     __WATCOM__      WATCOM C
  10.  
  11.     Revised:
  12.     09/14/93  Fred Cole  Moved MK_FP() macro to end of file to avoid
  13.                          redefinition error when dos.h gets included
  14.                          at the in/outport definitions for __TURBOC__
  15.     09/15/93  Thad Smith Add conditional code for TC 2.01
  16.                          Fix findfirst/findnext support for ZTC 3.0
  17.     02Dec93 david nugent Additions for findfirst/findnext support for
  18.                          MSC6 (& 7) for OS/2
  19.                          Added FIND_END macro for use under OS/2 to
  20.                          be nice about closing the directory handle
  21.                          DOSFileData members should be accessed via
  22.                          the new ff_*() macros for portability
  23.                          Note: use -DOS2 when compiling under OS/2
  24. ======================================================================*/
  25.  
  26.  
  27. /* prevent multiple inclusions of this header file */
  28.  
  29. #if !defined(PORTABLE_H)
  30. #define PORTABLE_H
  31.  
  32. /*--------------------------------------------------------------------
  33.     Directory search macros and data structures
  34.  
  35.     DOSFileData         MS-DOS file data structure
  36.     FIND_FIRST          MS-DOS function 0x4E -- find first matching spec
  37.     FIND_NEXT           MS-DOS function 0x4F -- find subsequent files
  38. ----------------------------------------------------------------------*/
  39.  
  40. /* make sure the structure is packed on byte boundary */
  41.  
  42. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOM__)
  43.     #pragma pack(1)
  44. #elif defined(__ZTC__)
  45.     #pragma ZTC align 1
  46. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  47.     #pragma option -a-
  48. #endif
  49.  
  50. /* use this structure in place of compiler-defined file structure */
  51.  
  52. # if defined( OS2 )
  53. # define INCL_DOS
  54. # include "os2.h"
  55. # undef TRUE
  56. # undef FALSE
  57. typedef struct {
  58.       USHORT dh;
  59.       struct _FILEFINDBUF f;
  60.       } DOSFileData;
  61. # define ff_name(x)     (x)->f.achName
  62. # define ff_size(x)     (x)->f.cbFile
  63. # define ff_attr(x)     (x)->f.attrFile
  64. # define ff_date(x)     *(USHORT *)(&(x)->f.fdateLastWrite)
  65. # define ff_time(x)     *(USHORT *)(&(x)->f.ftimeLastWrite)
  66. # else
  67. typedef struct {
  68.       char        reserved[21];
  69.       char        attrib;
  70.       unsigned    time;
  71.       unsigned    date;
  72.       long        size;
  73.       char        name[13];
  74.       } DOSFileData;
  75. # define ff_name(x)     (x)->name
  76. # define ff_size(x)     (x)->size
  77. # define ff_attr(x)     (x)->attrib
  78. # define ff_date(x)     (x)->date
  79. # define ff_time(x)     (x)->time
  80. #endif
  81.  
  82. /* set structure alignment to default */
  83.  
  84. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  85.  #pragma pack()
  86. #elif defined (__ZTC__)
  87.  #pragma ZTC align
  88. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  89.  #pragma option -a.
  90. #endif
  91.  
  92. /* include proper header files and create macros */
  93.  
  94. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC)
  95.  #include "direct.h"
  96.  #if defined( OS2 )
  97.   __inline int
  98.   FIND_FIRST (char * spec, unsigned attr, DOSFileData *ff)
  99.   {
  100.     USHORT cnt = 1;
  101.     ff->dh = (HDIR) -1;
  102.     return (int) DosFindFirst ((PSZ)spec, &ff->dh, (USHORT)attr, &ff->f, (USHORT)sizeof(struct _FILEFINDBUF), &cnt, 0L);
  103.   }
  104.   __inline int
  105.   FIND_NEXT (DOSFileData *ff)
  106.   {
  107.     USHORT cnt = 1;
  108.     return (int) DosFindNext (ff->dh, &ff->f, sizeof(struct _FILEFINDBUF), &cnt);
  109.   }
  110.   __inline int
  111.   FIND_END (DOSFileData *ff)
  112.   {
  113.     return (int) DosFindClose (ff->dh);
  114.   }
  115.  #else
  116.   #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr, (struct find_t *)buf)
  117.   #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  118.   #define FIND_END(buf)
  119.  # endif
  120. #elif defined (__TURBOC__)
  121.  #include "dir.h"
  122.  #define FIND_FIRST(spec,attr,buf) findfirst(spec,(struct ffblk *)buf,attr)
  123.  #define FIND_NEXT(buf) findnext((struct ffblk *)buf)
  124.  #define FIND_END(buf)
  125. #elif defined (__ZTC__)
  126.  #include "dos.h"
  127.  #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr, (struct find_t *)buf)
  128.  #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  129.  #define FIND_END(buf)
  130. #endif
  131.  
  132. /*--------------------------------------------------------------------
  133.     I/O Port Macros
  134.  
  135.     IN_PORT     read byte from I/O port
  136.     IN_PORTW    read word from I/O port
  137.     OUT_PORT    write byte to I/O port
  138.     OUT_PORTW   write word to I/O port
  139. ----------------------------------------------------------------------*/
  140.  
  141. #if defined(__TURBOC__)
  142.  #include "dos.h"
  143.  #define IN_PORT(port)           inportb(port)
  144.  #define IN_PORTW(port)          inport(port)
  145.  #define OUT_PORT(port, val)     outportb(port, val)
  146.  #define OUT_PORTW(port, val)    outport(port, val)
  147. #else
  148.  #include "conio.h"
  149.  
  150.  #define IN_PORT(port)           inp(port)
  151.  #define IN_PORTW(port)          inpw(port)
  152.  #define OUT_PORT(port, val)     outp(port, val)
  153.  #define OUT_PORTW(port, val)    outpw(port, val)
  154.  
  155. /*--------------------------------------------------------------------
  156.     Borland pseudo register macros
  157.  
  158.     These macros replace references to Borland's pseudo register
  159.     variables and geninterrup() funciton with traditional struct
  160.     REGS/int86 references.
  161. ----------------------------------------------------------------------*/
  162.  
  163. #if !defined(__TURBOC__)
  164.  #include "dos.h"
  165.  
  166.  union REGS CPURegs;
  167.  
  168.  #define _AX CPURegs.x.ax
  169.  #define _BX CPURegs.x.bx
  170.  #define _CX CPURegs.x.cx
  171.  #define _DX CPURegs.x.dx
  172.  
  173.  #define _AH CPURegs.x.ah
  174.  #define _AL CPURegs.x.al
  175.  #define _BH CPURegs.x.bh
  176.  #define _BL CPURegs.x.bl
  177.  #define _CH CPURegs.x.ch
  178.  #define _CL CPURegs.x.cl
  179.  #define _DH CPURegs.x.dh
  180.  #define _DL CPURegs.x.dl
  181.  
  182.  #define geninterrupt(n) int86(n,&CPURegs,&CPURegs);
  183.  #define O_DENYALL   0x10
  184.  #define O_DENYWRITE 0x20
  185.  #define O_DENYREAD  0x30
  186.  #define O_DENYNONE  0x40
  187. #endif
  188.  
  189. #endif
  190.  
  191. /*--------------------------------------------------------------------
  192.     Pointer-related macros
  193.  
  194.     MK_FP   creates a far pointer from segment and offset values
  195. ----------------------------------------------------------------------*/
  196.  
  197. #if !defined(MK_FP)
  198.     #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  199. #endif
  200.  
  201. #endif
  202.