home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / csplit21.zip / PORTABLE.H < prev   
Text File  |  1995-11-14  |  7KB  |  206 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.     08/19/95  Fred Cole  Changed date and time types in the DosFileData
  25.                          structure from unsigned to unsigned short to
  26.                          avoid portability problems between 16/32 bit
  27.                          int platforms
  28. ======================================================================*/
  29.  
  30.  
  31. /* prevent multiple inclusions of this header file */
  32.  
  33. #if !defined(PORTABLE_H)
  34. #define PORTABLE_H
  35.  
  36. /*--------------------------------------------------------------------
  37.     Directory search macros and data structures
  38.  
  39.     DOSFileData         MS-DOS file data structure
  40.     FIND_FIRST          MS-DOS function 0x4E -- find first matching spec
  41.     FIND_NEXT           MS-DOS function 0x4F -- find subsequent files
  42. ----------------------------------------------------------------------*/
  43.  
  44. /* make sure the structure is packed on byte boundary */
  45.  
  46. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOM__)
  47.     #pragma pack(1)
  48. #elif defined(__ZTC__)
  49.     #pragma ZTC align 1
  50. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  51.     #pragma option -a-
  52. #endif
  53.  
  54. /* use this structure in place of compiler-defined file structure */
  55.  
  56. # if defined( OS2 )
  57. # define INCL_DOS
  58. # include "os2.h"
  59. # undef TRUE
  60. # undef FALSE
  61. typedef struct {
  62.       USHORT dh;
  63.       struct _FILEFINDBUF f;
  64.       } DOSFileData;
  65. # define ff_name(x)     (x)->f.achName
  66. # define ff_size(x)     (x)->f.cbFile
  67. # define ff_attr(x)     (x)->f.attrFile
  68. # define ff_date(x)     *(USHORT *)(&(x)->f.fdateLastWrite)
  69. # define ff_time(x)     *(USHORT *)(&(x)->f.ftimeLastWrite)
  70. # else
  71. typedef struct {
  72.       char             reserved[21];
  73.       char             attrib;
  74.       unsigned short   time;
  75.       unsigned short   date;
  76.       long             size;
  77.       char             name[13];
  78.       } DOSFileData;
  79. # define ff_name(x)     (x)->name
  80. # define ff_size(x)     (x)->size
  81. # define ff_attr(x)     (x)->attrib
  82. # define ff_date(x)     (x)->date
  83. # define ff_time(x)     (x)->time
  84. #endif
  85.  
  86. /* set structure alignment to default */
  87.  
  88. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  89.  #pragma pack()
  90. #elif defined (__ZTC__)
  91.  #pragma ZTC align
  92. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  93.  #pragma option -a.
  94. #endif
  95.  
  96. /* include proper header files and create macros */
  97.  
  98. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC)
  99.  #include "direct.h"
  100.  #if defined( OS2 )
  101.   __inline int
  102.   FIND_FIRST (char * spec, unsigned attr, DOSFileData *ff)
  103.   {
  104.     USHORT cnt = 1;
  105.     ff->dh = (HDIR) -1;
  106.     return (int) DosFindFirst ((PSZ)spec, &ff->dh, (USHORT)attr, &ff->f, (USHORT)sizeof(struct _FILEFINDBUF), &cnt, 0L);
  107.   }
  108.   __inline int
  109.   FIND_NEXT (DOSFileData *ff)
  110.   {
  111.     USHORT cnt = 1;
  112.     return (int) DosFindNext (ff->dh, &ff->f, sizeof(struct _FILEFINDBUF), &cnt);
  113.   }
  114.   __inline int
  115.   FIND_END (DOSFileData *ff)
  116.   {
  117.     return (int) DosFindClose (ff->dh);
  118.   }
  119.  #else
  120.   #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr, (struct find_t *)buf)
  121.   #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  122.   #define FIND_END(buf)
  123.  # endif
  124. #elif defined (__TURBOC__)
  125.  #include "dir.h"
  126.  #define FIND_FIRST(spec,attr,buf) findfirst(spec,(struct ffblk *)buf,attr)
  127.  #define FIND_NEXT(buf) findnext((struct ffblk *)buf)
  128.  #define FIND_END(buf)
  129. #elif defined (__ZTC__)
  130.  #include "dos.h"
  131.  #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr, (struct find_t *)buf)
  132.  #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  133.  #define FIND_END(buf)
  134. #endif
  135.  
  136. /*--------------------------------------------------------------------
  137.     I/O Port Macros
  138.  
  139.     IN_PORT     read byte from I/O port
  140.     IN_PORTW    read word from I/O port
  141.     OUT_PORT    write byte to I/O port
  142.     OUT_PORTW   write word to I/O port
  143. ----------------------------------------------------------------------*/
  144.  
  145. #if defined(__TURBOC__)
  146.  #include "dos.h"
  147.  #define IN_PORT(port)           inportb(port)
  148.  #define IN_PORTW(port)          inport(port)
  149.  #define OUT_PORT(port, val)     outportb(port, val)
  150.  #define OUT_PORTW(port, val)    outport(port, val)
  151. #else
  152.  #include "conio.h"
  153.  
  154.  #define IN_PORT(port)           inp(port)
  155.  #define IN_PORTW(port)          inpw(port)
  156.  #define OUT_PORT(port, val)     outp(port, val)
  157.  #define OUT_PORTW(port, val)    outpw(port, val)
  158.  
  159. /*--------------------------------------------------------------------
  160.     Borland pseudo register macros
  161.  
  162.     These macros replace references to Borland's pseudo register
  163.     variables and geninterrup() funciton with traditional struct
  164.     REGS/int86 references.
  165. ----------------------------------------------------------------------*/
  166.  
  167. #if !defined(__TURBOC__)
  168.  #include "dos.h"
  169.  
  170.  union REGS CPURegs;
  171.  
  172.  #define _AX CPURegs.x.ax
  173.  #define _BX CPURegs.x.bx
  174.  #define _CX CPURegs.x.cx
  175.  #define _DX CPURegs.x.dx
  176.  
  177.  #define _AH CPURegs.x.ah
  178.  #define _AL CPURegs.x.al
  179.  #define _BH CPURegs.x.bh
  180.  #define _BL CPURegs.x.bl
  181.  #define _CH CPURegs.x.ch
  182.  #define _CL CPURegs.x.cl
  183.  #define _DH CPURegs.x.dh
  184.  #define _DL CPURegs.x.dl
  185.  
  186.  #define geninterrupt(n) int86(n,&CPURegs,&CPURegs);
  187.  #define O_DENYALL   0x10
  188.  #define O_DENYWRITE 0x20
  189.  #define O_DENYREAD  0x30
  190.  #define O_DENYNONE  0x40
  191. #endif
  192.  
  193. #endif
  194.  
  195. /*--------------------------------------------------------------------
  196.     Pointer-related macros
  197.  
  198.     MK_FP   creates a far pointer from segment and offset values
  199. ----------------------------------------------------------------------*/
  200.  
  201. #if !defined(MK_FP)
  202.     #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  203. #endif
  204.  
  205. #endif
  206.