home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DIRPORT.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  10KB  |  298 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*====================================================================
  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.     __BORLANDC__    Borland C++
  9.     __ZTC__         Zortech C and C++
  10.     __SC__          Symantec C++
  11.     __WATCOMC__     WATCOM C
  12.     __POWERC        Mix Power C
  13.     __GNUC__        Gnu C
  14.     __EMX__         Emx Gnu C
  15.  
  16.     Revised:
  17.  
  18.     Original   Scott Ladd   Now obsolete
  19.     14-Sep-93  Fred Cole    Moved MK_FP() macro to end of file to avoid
  20.                             redefinition error when dos.h gets included
  21.                             at the in/outport definitions for __TURBOC__
  22.     15-Sep-93  Thad Smith   Add conditional code for TC 2.01
  23.                             Fix findfirst/findnext support for ZTC 3.0
  24.     15-Oct-93  Bob Stout    Revise find first/next support
  25.     02-Dec-93  David Nugent Additions for findfirst/findnext support for
  26.                             MSC6 (& 7) for OS/2
  27.                             Added FIND_END macro for use under OS/2 to
  28.                             be nice about closing the directory handle
  29.                             DOSFileData members should be accessed via
  30.                             the new ff_*() macros for portability
  31.                             Note: use -DOS2 when compiling under OS/2
  32.     03-Apr-94  Bob Stout    Add Power C support, FAR
  33.     19-Aug-95  Bob Stout    Add NEAR, PASCAL, CDECL, and portable attributes
  34.     06-Sep-95  Phi Nguyen   Add DOSFileTime, DOSFileDate, & supporting macros
  35.                Bob Stout    (ff_yr/mo/day(), ff_hr/min/tsec())
  36.     08-Sep-95  Bob Nelson   Add __GNUCC__ and PAK macro
  37.     21-Sep-95  Bob Stout    Renamed to PC-PORT.H, revised directory stuff
  38.     25-Sep-95  Bob Stout    Split out EXTKWORD.H
  39.     26-Sep-95  Jerry Coffin Added Win32 support.
  40.     21-Oct-95  Bob Stout    Resolve struct dirent incompatibilities,
  41.                             move port I/O macros to PCHWIO.H,
  42.                             move MK_FP() cover to SNIPTYPE.H,
  43.                             rename to DIRPORT.H(!!!)
  44.     15-May-96  David Nugent Added 32-bit OS/2 support (Watcom/emx)
  45.     04-Jul-96  Bob Stout    Fixed attribute redefinition problems w/ TC 3.x
  46.     28-Jul-96  Bob Stout    Fixed error in definition of ff_sec() in DOS
  47.     20-Aug-96  Bob Stout    Eliminate Win32 conflicts
  48. ======================================================================*/
  49.  
  50.  
  51. /* prevent multiple inclusions of this header file */
  52.  
  53. #if !defined(DIRPORT__H)
  54. #define DIRPORT__H
  55.  
  56. #if defined(__OS2__)
  57.  #define OS2
  58. #endif
  59.  
  60. #if defined(__EMX__)
  61.  #undef OS2
  62.  #define OS2
  63. #endif
  64.  
  65. #if defined(OS2)
  66.  #undef MSDOS
  67. #endif
  68.  
  69. #include "extkword.h"         /* Extended keywords header   */
  70.  
  71. #undef dirent
  72. #define dirent DIRENT_
  73.  
  74. /*
  75. **  Correct file attributes
  76. */
  77.  
  78. #if defined(__POWERC) || (defined(__TURBOC__) && !defined(__BORLANDC__))
  79.  #ifndef FA_NORMAL
  80.   #define FA_NORMAL 0x00
  81.  #endif
  82.  
  83.  #undef  _A_NORMAL
  84.  #undef  _A_RDONLY
  85.  #undef  _A_HIDDEN
  86.  #undef  _A_SYSTEM
  87.  #undef  _A_VOLID
  88.  #undef  _A_SUBDIR
  89.  #undef  _A_ARCH
  90.  #undef  _A_ANY
  91.  
  92.  #define _A_NORMAL      FA_NORMAL
  93.  #define _A_RDONLY      FA_RDONLY
  94.  #define _A_HIDDEN      FA_HIDDEN
  95.  #define _A_SYSTEM      FA_SYSTEM
  96.  #define _A_VOLID       FA_LABEL
  97.  #define _A_SUBDIR      FA_DIREC
  98.  #define _A_ARCH        FA_ARCH
  99.  #define _A_ANY   FA_NORMAL | FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_LABEL | \
  100.                   FA_DIREC | FA_ARCH
  101. #else
  102.  #ifdef OS2
  103.   #define _A_NORMAL     FILE_NORMAL
  104.   #define _A_RDONLY     FILE_READONLY
  105.   #define _A_HIDDEN     FILE_HIDDEN
  106.   #define _A_SYSTEM     FILE_SYSTEM
  107.   #define _A_SUBDIR     FILE_DIRECTORY
  108.   #define _A_VOLID      0
  109.   #define _A_ARCH       FILE_ARCHIVED
  110.   #define _A_ANY  FILE_NORMAL | FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | \
  111.                   FILE_DIRECTORY | FILE_ARCHIVED
  112.  #elif defined(_WIN32) || defined(WIN32)
  113.   #define WIN32_LEAN_AND_MEAN
  114.   #define NOGDI
  115.   #define NOSERVICE
  116.   #undef INC_OLE1
  117.   #undef INC_OLE2
  118.   #include <windows.h>
  119.   #include <dos.h>    /* #define's most _A_* file attribute macros    */
  120.  
  121.   #define _A_VOLID   0
  122.   #define _A_ANY     _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | \
  123.      _A_SUBDIR | _A_ARCH
  124.  
  125.   #define ff_name(x)     (x)->file.cFileName
  126.   #define ff_size(x)     (x)->file.nFileSizeLow
  127.   #define ff_attr(x)     (x)->file.dwFileAttributes
  128.  
  129.   typedef struct dirent {
  130.      WIN32_FIND_DATA file;
  131.      HANDLE handle;
  132.   } DOSFileData;
  133.  
  134.   WORD ff_date(DOSFileData *f);
  135.   WORD ff_yr(DOSFileData *f);
  136.   WORD ff_mo(DOSFileData *f);
  137.   WORD ff_day(DOSFileData *f);
  138.   WORD ff_time(DOSFileData *f);
  139.   WORD ff_hr(DOSFileData *f);
  140.   WORD ff_min(DOSFileData *f);
  141.   WORD ff_tsec(DOSFileData *f);
  142.  
  143.   int FIND_FIRST(char *spec, unsigned attr, DOSFileData *ff);
  144.   int FIND_NEXT(DOSFileData *ff);
  145.   int FIND_END(DOSFileData *ff);
  146.  #elif defined(__MSDOS__) || defined(MSDOS)
  147.   #define _A_ANY  _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_VOLID | \
  148.                   _A_SUBDIR | _A_ARCH
  149.  #endif
  150. #endif
  151.  
  152. /*--------------------------------------------------------------------
  153.     Directory search macros and data structures
  154.  
  155.     DOSFileData         MS-DOS file data structure
  156.     DOSFileDate         MS-DOS file date structure
  157.     DOSFileTime         MS-DOS file time structure
  158.     FIND_FIRST          MS-DOS function 0x4E -- find first matching spec
  159.     FIND_NEXT           MS-DOS function 0x4F -- find subsequent files
  160. ----------------------------------------------------------------------*/
  161.  
  162. /* make sure the structure is packed on byte boundary */
  163.  
  164. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  165.     #pragma pack(1)
  166. #elif defined(__ZTC__)
  167.     #pragma ZTC align 1
  168. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  169.     #pragma option -a-
  170. #endif
  171.  
  172. #ifdef __GNUC__
  173.  #define PAK      __attribute__((packed))
  174. #else
  175.  #define PAK
  176. #endif
  177.  
  178. /*
  179. **  Structures to access dates and times
  180. */
  181.  
  182. typedef struct {
  183.             unsigned tsecs:   5;
  184.             unsigned mins:    6;
  185.             unsigned hours:   5;
  186.       } DOSFileTime;
  187.  
  188. typedef struct {
  189.             unsigned day:     5;
  190.             unsigned month:   4;
  191.             unsigned year:    7;
  192.       } DOSFileDate;
  193.  
  194. /*
  195. **  Use this structure in place of compiler-defined file structure.
  196. **  Always use the ff_xxxx() macros to access structure members.
  197. */
  198.  
  199. #if defined(OS2)
  200.  #define INCL_DOS
  201.  #include "os2.h"
  202.  #undef TRUE
  203.  #undef FALSE
  204.  #undef  _SYSINT
  205.  #if defined(__FLAT__) || defined(__EMX__)
  206.  #undef  _FILEFINDBUF
  207.  #define _FILEFINDBUF _FILEFINDBUF3
  208.  #define _SYSINT ULONG
  209.  #define FINDLVL FIL_STANDARD
  210.  #else
  211.  #define _SYSINT USHORT
  212.  #define FINDLVL 0L
  213.  #endif
  214.  
  215.  typedef struct dirent {
  216.       HDIR dh;
  217.       struct _FILEFINDBUF f;
  218.       } DOSFileData;
  219.  
  220.  #define d_name         achName     /* For struct dirent portability    */
  221.  #define d_size         cbFile
  222.  
  223.  #define ff_name(x)     (x)->f.d_name
  224.  #define ff_size(x)     (x)->f.d_size
  225.  #define ff_attr(x)     (x)->f.attrFile
  226.  #define ff_date(x)     *((DOSFileDate *)(&(x)->f.fdateLastWrite))
  227.  #define ff_yr(x)       *((DOSFileDate *)(&(x)->f.fdateLastWrite)).year
  228.  #define ff_mo(x)       *((DOSFileDate *)(&(x)->f.fdateLastWrite)).month
  229.  #define ff_day(x)      *((DOSFileDate *)(&(x)->f.fdateLastWrite)).day
  230.  #define ff_time(x)     *((DOSFileTime *)(&(x)->f.ftimeLastWrite))
  231.  #define ff_hr(x)       *((DOSFileTime *)(&(x)->f.ftimeLastWrite)).hours
  232.  #define ff_min(x)      *((DOSFileTime *)(&(x)->f.ftimeLastWrite)).mins
  233.  #define ff_tsec(x)     *((DOSFileTime *)(&(x)->f.ftimeLastWrite)).tsecs
  234. #elif !(defined(WIN32) || defined(_WIN32)) /* Not OS/2  or Win32 */
  235.  
  236.  typedef struct dirent {
  237.       char              reserved[21];
  238.       char              attrib;
  239.       DOSFileTime       time;
  240.       DOSFileDate       date;
  241.       long              d_size;
  242.       char              d_name[13];
  243.       } DOSFileData;
  244.  
  245.  #define ff_name(x)     (x)->d_name
  246.  #define ff_size(x)     (x)->d_size
  247.  #define ff_attr(x)     (x)->attrib
  248.  #define ff_date(x)     (x)->date
  249.  #define ff_yr(x)       (x)->date.year
  250.  #define ff_mo(x)       (x)->date.month
  251.  #define ff_day(x)      (x)->date.day
  252.  #define ff_time(x)     (x)->time
  253.  #define ff_hr(x)       (x)->time.hours
  254.  #define ff_min(x)      (x)->time.mins
  255.  #define ff_sec(x)      (x)->time.tsecs
  256. #endif
  257.  
  258. /* set structure alignment to default */
  259.  
  260. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  261.  #pragma pack()
  262. #elif defined (__ZTC__)
  263.  #pragma ZTC align
  264. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  265.  #pragma option -a.
  266. #endif
  267.  
  268. /* include proper header files and create macros */
  269.  
  270. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__) || defined(__EMX__)
  271.  #if defined( OS2 )
  272.   int FIND_FIRST (char * spec, unsigned attr, DOSFileData *ff);
  273.   int FIND_NEXT (DOSFileData *ff);
  274.   int FIND_END (DOSFileData *ff);
  275.  
  276.  #elif !(defined(_WIN32) || defined(WIN32))
  277.   #include "dos.h"
  278.   #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr, \
  279.         (struct find_t *)buf)
  280.   #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  281.   #define FIND_END(buf)
  282.  #endif
  283. #elif defined (__TURBOC__) || defined (__BORLANDC__) || defined (__POWERC)
  284.  #include "dir.h"
  285.  #include "dos.h"
  286.  #define FIND_FIRST(spec,attr,buf) findfirst(spec,(struct ffblk *)buf,attr)
  287.  #define FIND_NEXT(buf) findnext((struct ffblk *)buf)
  288.  #define FIND_END(buf)
  289. #elif defined(__SC__) || defined(__WATCOMC__) || defined(__ZTC__)
  290.  #include "dos.h"
  291.  #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr, \
  292.        (struct find_t *)buf)
  293.  #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  294.  #define FIND_END(buf)
  295. #endif
  296.  
  297. #endif /* DIRPORT__H */
  298.