00001 #ifndef __SYSIO_H__ 00002 #define __SYSIO_H__ 00003 /*============================================================================= 00004 Module : sysio.h 00005 Purpose : Encapsulate operating system specific i/o routines. Currently 00006 only Win32 supported. 00007 Author : Doug Ehlenberger, CNIC Mt. Sinai School of Medicine 00008 00009 ==============================================================================*/ 00010 #include <stdlib.h> 00011 #include <stdio.h> 00012 #include <ctype.h> 00013 00014 #ifdef _WIN32 00015 00016 #ifndef vCONSOLE 00017 #include <windows.h> 00018 #endif 00019 00020 #include <direct.h> 00021 #include <io.h> 00022 00023 #endif 00024 00025 #include "configure.h" 00026 00027 00028 typedef enum 00029 { 00030 vSYSIO_NO_ERROR, 00031 vSYSIO_ERROR_CWD, 00032 vSYSIO_ERROR_CHDIR, 00033 vSYSIO_ERROR_MKDIR, 00034 vSYSIO_ERROR_RMDIR, 00035 vSYSIO_ERROR_NO_FILES, 00036 vSYSIO_ERROR_INVALID_DIR, 00037 vSYSIO_ERROR_INVALID_SPEC 00038 } 00039 vSYSIO_ERROR_CODE; 00040 00041 00042 typedef struct tagFileSearch_t 00043 { 00044 vSTRING directory; 00045 vSTRING fileSpec; 00046 00047 #ifdef _WIN32 00048 struct _finddata_t fileInfo; 00049 long searchHandle; 00050 #else 00051 #error Platform Not Supported ( sysio.h ) 00052 #endif 00053 } 00054 FileSearch_t; 00055 00056 00057 /*----------------------------------------------------------------------------- 00058 Call to change the current directory. 00059 -----------------------------------------------------------------------------*/ 00060 vBOOL ChangeDirectory 00061 ( 00062 vSTRING directory 00063 ); 00064 00065 00066 #ifdef vCONSOLE 00067 00068 /*----------------------------------------------------------------------------- 00069 Obtain the current working directory. In this function the buffer 00070 SHOULD NOT be NULL!! 00071 -----------------------------------------------------------------------------*/ 00072 vBOOL GetCurrentDirectory 00073 ( 00074 vSTRING directory, 00075 vINT bufferLength 00076 ); 00077 00078 00079 /*----------------------------------------------------------------------------- 00080 Remove a directory. 00081 -----------------------------------------------------------------------------*/ 00082 vBOOL RemoveDirectory 00083 ( 00084 vSTRING directory 00085 ); 00086 00087 #endif 00088 00089 00090 /*----------------------------------------------------------------------------- 00091 Create a directory. 00092 -----------------------------------------------------------------------------*/ 00093 vBOOL MakeDirectory 00094 ( 00095 vSTRING directory 00096 ); 00097 00098 00099 #define vDRIVE_CHAR_TO_INT( driveChar ) ( driveChar - 'A' + 1 ) 00100 #define vDRIVE_INT_TO_CHAR( driveInt ) ( 'A' + driveInt - 1 ) 00101 00102 /*----------------------------------------------------------------------------- 00103 Get current working drive. 1 = A, 2 = B, etc... 00104 -----------------------------------------------------------------------------*/ 00105 vINT GetCurrentDrive 00106 ( 00107 vVOID 00108 ); 00109 00110 00111 /*----------------------------------------------------------------------------- 00112 Change current working drive. 1 = A, 2 = B, etc... 00113 Returns 0 on success, -1 on error. 00114 -----------------------------------------------------------------------------*/ 00115 vINT ChangeCurrentDrive 00116 ( 00117 vINT drive 00118 ); 00119 00120 00121 /*----------------------------------------------------------------------------- 00122 Split a full path into components drive, dircetroy, file name, and 00123 extension. Pass NULL for any component not needed. The size of the buffers 00124 should be the constants defined in configure.h. 00125 -----------------------------------------------------------------------------*/ 00126 vVOID SplitPath 00127 ( 00128 const vSTRING fullPath, 00129 vSTRING drive, 00130 vSTRING directory, 00131 vSTRING fileName, 00132 vSTRING extension 00133 ); 00134 00135 00136 /*----------------------------------------------------------------------------- 00137 Begin a search for files. If the directory field is NULL, the search occurs 00138 in the current working directory. If the file spec field is NULL then 00139 everything, including directories, will be found. Upon success, call 00140 GetSearchFileName() to obtain the name of the first file found. 00141 -----------------------------------------------------------------------------*/ 00142 vSYSIO_ERROR_CODE BeginFileSearch 00143 ( 00144 FileSearch_t *search_t 00145 ); 00146 00147 00148 /*----------------------------------------------------------------------------- 00149 Continue the search for matching files. Upon success call 00150 GetSearchFileName(). 00151 -----------------------------------------------------------------------------*/ 00152 vSYSIO_ERROR_CODE NextFileSearch 00153 ( 00154 FileSearch_t *search_t 00155 ); 00156 00157 00158 /*----------------------------------------------------------------------------- 00159 Terminate the file search. Cleans up any memory and system resources. 00160 -----------------------------------------------------------------------------*/ 00161 vVOID EndFileSearch 00162 ( 00163 FileSearch_t *search_t 00164 ); 00165 00166 00167 vCHAR* GetSearchFileName 00168 ( 00169 FileSearch_t *search_t 00170 ); 00171 00172 00173 #endif /* __SYSIO_H__ */ 00174
1.5.8