Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

881 lines
33 KiB

  1. /*****************************************************************************
  2. * *
  3. * _MVUTIL.H *
  4. * *
  5. * Copyright (C) Microsoft Corporation 1992. *
  6. * All Rights reserved. *
  7. * *
  8. ******************************************************************************
  9. * *
  10. * Module Intent *
  11. * *
  12. * Interfile declarations that are internal to MVUT *
  13. * *
  14. ******************************************************************************
  15. * *
  16. * Current Owner: davej *
  17. * *
  18. ******************************************************************************
  19. *
  20. * Revision History:
  21. *
  22. * -- Mar 92 Created DAVIDJES
  23. * -- Aug 95 Merged file system, btree, etc into utilities
  24. *
  25. *****************************************************************************/
  26. // requires mvopsys.h
  27. // requires orkin.h
  28. // requires misc.h
  29. #ifndef __MVUTIL_H__
  30. #define __MVUTIL_H__
  31. #include <mem.h>
  32. #include <objects.h> // for object types and defines
  33. #include <misc.h>
  34. #include <mvsearch.h> // for LFO type
  35. #include <iterror.h>
  36. #include <freelist.h>
  37. #include <fileoff.h>
  38. #include <wrapstor.h>
  39. #include <font.h>
  40. #ifdef __cplusplus
  41. #include <itsort.h>
  42. #endif
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. #pragma pack(1)
  47. /***************************************************************************\
  48. *
  49. * General Defines
  50. *
  51. ****************************************************************************/
  52. // These macros are temporary and will be removed when we typedef
  53. // all our ints where they are supposed to be 16 bits - maha
  54. #ifdef _32BIT
  55. #if defined( _NT )
  56. extern RC RcFromLoadLibErr[];
  57. #endif
  58. #else
  59. typedef HANDLE HINSTANCE;
  60. extern RC RcFromLoadLibErr[HINSTANCE_ERROR];
  61. #endif
  62. /* pointer types */
  63. typedef char FAR * QCH; // Guaranteed far pointer - not an SZ, an ST, or an LPSTR
  64. typedef BYTE FAR * QB;
  65. typedef VOID FAR * QV;
  66. typedef SHORT FAR * QI;
  67. typedef WORD FAR * QW;
  68. typedef LONG FAR * QL;
  69. typedef WORD FAR * QUI;
  70. typedef ULONG FAR * QUL;
  71. typedef DWORD FAR * QDW;
  72. typedef char * PCH; // "Native" pointer (depends on the model) - not an SZ, an ST, or an NPSTR
  73. typedef VOID * PV;
  74. typedef SHORT * PI;
  75. typedef WORD * PW;
  76. typedef LONG * PL;
  77. /* string types */
  78. // These are the two main string types:
  79. typedef unsigned char FAR * SZ; // 0-terminated string
  80. typedef unsigned char FAR * ST; // byte count prefixed string
  81. // Hey, perhaps others want this stuff below?
  82. #ifdef _WIN32
  83. #define _INITIALIZECRITICALSECTION(lpcs) InitializeCriticalSection(lpcs)
  84. #define _ENTERCRITICALSECTION(lpcs) EnterCriticalSection(lpcs)
  85. #define _LEAVECRITICALSECTION(lpcs) LeaveCriticalSection(lpcs)
  86. #define _DELETECRITICALSECTION(lpcs) DeleteCriticalSection(lpcs)
  87. #define _INTERLOCKEDINCREMENT(lplong) InterlockedIncrement(lplong)
  88. #define _INTERLOCKEDDECREMENT(lplong) InterlockedDecrement(lplong)
  89. #else
  90. #define _INITIALIZECRITICALSECTION(lpcs) (*(lpcs)=-1L)
  91. #define _ENTERCRITICALSECTION(lpcs) verify((++(*(lpcs)))==0L)
  92. #define _LEAVECRITICALSECTION(lpcs) (*(lpcs)--)
  93. #define _DELETECRITICALSECTION(lpcs) (*(lpcs)=0L)
  94. #define _INTERLOCKEDINCREMENT(lplong) (++(*(lplong)))
  95. #define _INTERLOCKEDDECREMENT(lplong) (--(*(lplong)))
  96. typedef LONG CRITICAL_SECTION;
  97. #endif
  98. /* other types */
  99. /***************************************************************************\
  100. *
  101. * Misc
  102. *
  103. \***************************************************************************/
  104. /*****************************************************************************
  105. * *
  106. * Defines *
  107. * *
  108. *****************************************************************************/
  109. // Defines for use in compressing topics and decompressing them
  110. #define MAXTEXTBLOCK 32768L // Maximum amount of data in uncompressed block
  111. #define TOPICFILENAME ">%08lX" // we want these to appear before the system files
  112. #define SUBTOPICSFILENAME "#SUBTOPICS" // Subtopics string list filename
  113. #define MAXGROUPID 7000000 // Let's limit groups to 7,000,000 items
  114. /*****************************************************************************
  115. * *
  116. * Prototypes *
  117. * *
  118. *****************************************************************************/
  119. #ifdef MOSMAP // {
  120. // Multithreaded error support
  121. EXTC RC MosSetViewerError(RC rc, LPSTR sz, int l) ;
  122. EXTC RC MosGetViewerError(VOID) ;
  123. #endif // MOSMAP }
  124. /*******************************************************************
  125. * *
  126. * STR.C *
  127. * *
  128. *******************************************************************/
  129. SZ FAR PASCAL SzNzCat( SZ, SZ, WORD);
  130. SHORT FAR PASCAL WCmpiScandSz( SZ, SZ );
  131. SHORT FAR PASCAL WCmpiSz( SZ, SZ, BYTE far * );
  132. SHORT FAR PASCAL WCmpiSnn(SZ, SZ, BYTE far *, SHORT, SHORT);
  133. SHORT FAR PASCAL WCmpSt( ST, ST );
  134. /*******************************************************************
  135. * *
  136. * BTREE.C *
  137. * *
  138. *******************************************************************/
  139. PUBLIC int PASCAL FAR StrFntMappedLigatureComp(SZ, SZ, LPVOID);
  140. /*******************************************************************
  141. * *
  142. * FID.C *
  143. * *
  144. *******************************************************************/
  145. extern WORD _rgwOpenMode[4];
  146. extern WORD _rgwPerm[4] ;
  147. extern WORD _rgwShare[4];
  148. RC FAR PASCAL RcGetDOSError(void);
  149. /*******************************************************************
  150. * *
  151. * VFILE.C *
  152. * *
  153. *******************************************************************/
  154. #define VFF_TEMP 1
  155. #define VFF_FID 2
  156. #define VFF_READ 4
  157. #define VFF_READWRITE 8
  158. #define VFF_DIRTY 16
  159. #define VFOPEN_ASTEMP 1
  160. #define VFOPEN_ASFID 2
  161. #define VFOPEN_READ 4
  162. #define VFOPEN_READWRITE 8
  163. typedef HANDLE HVF;
  164. // @DOC PRIVATE
  165. // @struct SHAREDBUFFER | Memory buffer that can be shared by many
  166. // users. When user is completely finished with memory block,
  167. // the next person waiting for it will be granted permission
  168. // to start using it in a multi-threaded environment.
  169. typedef struct _sharedbuffer_t
  170. {
  171. HANDLE hBuffer;
  172. LPVOID lpvBuffer; // @field Actual buffer memory
  173. LONG lcbBuffer; // @field Size of buffer
  174. LONG lCursor;
  175. CRITICAL_SECTION cs;// @field Critical section for monitoring shared use
  176. } SHAREDBUFFER, FAR * LPSHAREDBUFFER;
  177. // @DOC PRIVATE
  178. // @struct VFILE | Virtual file structure. Files can exist in a temp file
  179. // or inside a parent (M20) file. Information about the file is kept here.
  180. // [P] is important if file is in Parent, [T] for Temporary.
  181. typedef struct _vfile_hr
  182. {
  183. DWORD dwFlags; // @field Any of the VFF_ flags [P, T]
  184. FILEOFFSET foEof; // @field Size of file (loc'n of EOF) [P, T]
  185. FILEOFFSET foCurrent; // @field Current temp file pointer [ T]
  186. FILEOFFSET foBase; // @field Base offset into parent file [P ]
  187. FILEOFFSET foBlock; // Maximum file size in parent [P ]
  188. FM fmTemp; // @field Moniker of temp file [ T]
  189. FID fidParent; // @field Parent File [P ]
  190. FID fidTemp; // @field Temp File [ T]
  191. CRITICAL_SECTION cs; // @field An unused LONG if not in _WIN32
  192. LPSHAREDBUFFER lpsb; // @field Memory to use in tempfile xfers
  193. } VFILE, FAR * QVFILE;
  194. HVF FAR EXPORT_API VFileOpen( FID, FILEOFFSET, FILEOFFSET, FILEOFFSET,
  195. DWORD, LPSHAREDBUFFER, LPERRB );
  196. RC PASCAL FAR EXPORT_API VFileSetTemp( HVF );
  197. RC PASCAL FAR EXPORT_API VFileSetBase( HVF, FID, FILEOFFSET, FILEOFFSET );
  198. RC PASCAL FAR EXPORT_API VFileSetEOF( HVF, FILEOFFSET );
  199. FILEOFFSET PASCAL FAR EXPORT_API VFileGetSize( HVF, LPERRB );
  200. DWORD PASCAL FAR EXPORT_API VFileGetFlags( HVF, LPERRB );
  201. LONG PASCAL FAR EXPORT_API VFileSeekRead( HVF, FILEOFFSET, LPVOID, DWORD, LPERRB );
  202. LONG PASCAL FAR EXPORT_API VFileSeekWrite( HVF, FILEOFFSET, LPVOID, DWORD, LPERRB );
  203. RC PASCAL FAR EXPORT_API VFileClose( HVF );
  204. RC PASCAL FAR EXPORT_API VFileAbandon( HVF );
  205. RC PASCAL FAR EXPORT_API VFileSetBuffer( LPVOID lpvBuffer, LONG lcbBuffer );
  206. /*******************************************************************
  207. * *
  208. * FILESYS.C *
  209. * *
  210. *******************************************************************/
  211. #define wDefaultFreeListSize 510 // 510 entries in free list structure
  212. #define MAXSUBFILES 128 // Start with no more than 128 subfiles opened (can grow)
  213. #define SCRATCHBUFSIZE 60000L // Mainly used for temporary file copying
  214. // @DOC PRIVATE
  215. // @struct SF | Subfile element. An array of these is created by the file system.
  216. // Since the same file can be opened multiple times, each instance needs to
  217. // know where it's own current file pointer is. An HF is simply an index
  218. // into the file system's array of these SF structures.
  219. typedef struct _subfile_t
  220. {
  221. FILEOFFSET foCurrent; // @field Current file pointer.
  222. HSFB hsfb; // @field The actual subfile block for the file in question.
  223. } SF, FAR * QSF;
  224. // GLOBALS
  225. extern SF FAR * mv_gsfa; // Subfile headers (better/faster than globalalloc'ing them)
  226. extern LONG mv_gsfa_count; // User count, equals number of MV titles opened
  227. extern CRITICAL_SECTION mv_gsfa_cs; // Ensure accessing the array is OK in multi-threaded environment
  228. // @DOC PRIVATE
  229. // @struct SFH | System subfile header (only one system file per M20 file, and it's the directory
  230. // btree.
  231. typedef struct _sfh_t
  232. {
  233. FILEOFFSET foBlockSize; // @field Size of file on disk, includes header
  234. BYTE bFlags; // @field SFH_ flags. Depending on flags, more data may follow
  235. BYTE Pad1;
  236. BYTE Pad2;
  237. BYTE Pad3;
  238. } SFH, FAR * QSFH;
  239. // @DOC PRIVATE
  240. // @struct FSH | File System Header. This header is the first item in an M20 file.
  241. typedef struct _fsh_t
  242. {
  243. USHORT wMagic; // @field The magic number for a file system
  244. BYTE bVersion; // @field Version number for this file type.
  245. BYTE bFlags; // @field Any _FSH flags
  246. FILEOFFSET foDirectory; // @field Offset to system btree
  247. FILEOFFSET foFreeList; // @field Offset to free list
  248. FILEOFFSET foEof; // @field Next free spot in M20 file for new info
  249. SFH sfhSystem; // @field System btree file header (for size of sys btree)
  250. } FSH, FAR * QFSH;
  251. // @DOC PRIVATE
  252. // @struct FSHR | File system RAM header. All info important to an opened file system.
  253. typedef struct _fshr_t
  254. {
  255. HBT hbt; // @field File system btree
  256. FID fid; // @field File ID of M20 file
  257. FM fm; // @field Name of M20 file
  258. HFREELIST hfl; // @field Free list
  259. HSFB hsfbFirst; // @field First opened subfile in linked list
  260. HSFB hsfbSystem; // @field System (btree dir)
  261. CRITICAL_SECTION cs; // @field When doing subfile seek/read combos, ensure OK
  262. FSH fsh; // @field File system disk header
  263. SF FAR * sfa; // @field Subfile headers array
  264. SHAREDBUFFER sb; // @field Buffer, used anywhere we need scratch memory
  265. } FSHR, FAR * QFSHR;
  266. // These should be moved to freelist.c once FID's are common in mvutils
  267. HFREELIST PASCAL FAR FreeListInitFromFid ( FID, LPERRB );
  268. LONG PASCAL FAR FreeListWriteToFid ( HFREELIST, FID, LPERRB );
  269. /*******************************************************************
  270. * *
  271. * SUBFILE.C *
  272. * *
  273. *******************************************************************/
  274. // @DOC PRIVATE
  275. // @struct FILE_REC | Mirrors information saved as the data portion in the file
  276. // directory system btree for any particular entry. If any more info is
  277. // added to a directory entry, it should be added here.
  278. typedef struct _file_rec_t
  279. {
  280. char szData[14]; // @field Actual data stored in btree. Max size for variable width offset + length + byte (6 + 6 + 1).
  281. FILEOFFSET foStart; // @field Copy of file offset
  282. FILEOFFSET foSize; // @field Copy of file size
  283. BYTE bFlags; // @field Copy of flags
  284. } FILE_REC;
  285. // @DOC PRIVATE
  286. // @struct SFB | Subfile block RAM header. One per opened subfile.
  287. typedef struct _sfb_t
  288. {
  289. HVF hvf; // @field Virtual file handle - actual data may be in fs or temp
  290. FILEOFFSET foHeader; // @field Points to disk header in fs
  291. HFS hfs; // @field File system this lives in
  292. HSFB hsfbNext; // @field Next subfile (linked list of opened files)
  293. WORD wLockCount; // @field Number of HF's using file
  294. SFH sfh; // @field Copy of disk file header (not extra data)
  295. BYTE bOpenFlags; // @field SFO_ flags
  296. CHAR rgchKey[1]; // @field File key name
  297. } SFB, FAR * QSFB;
  298. RC PASCAL FAR EXPORT_API RcCloseEveryHf(HFS hfs);
  299. RC PASCAL FAR EXPORT_API RcFlushEveryHf(HFS hfs);
  300. /*******************************************************************
  301. * *
  302. * BTREE STUFF *
  303. * *
  304. *******************************************************************/
  305. /***************************************************************************\
  306. *
  307. * BTREE Defines
  308. *
  309. \***************************************************************************/
  310. /* default btree record format */
  311. #define rgchBtreeFormatDefault "z4"
  312. /* cache flags */
  313. #define fCacheDirty 0x01
  314. #define fCacheValid 0x04
  315. #define fBTCompressed 0x08
  316. #define fBTinRam 0x10
  317. /***************************************************************************\
  318. *
  319. * BTREE Macros
  320. *
  321. \***************************************************************************/
  322. /* Get the real size of a cache block */
  323. #define CbCacheBlock( qbthr ) \
  324. ( sizeof( CACHE_BLOCK ) - sizeof( DISK_BLOCK ) + (qbthr)->bth.cbBlock )
  325. /* convert a BK into a file offset */
  326. // We now should only use FoFromBk!!!
  327. //#define LifFromBk( bk, qbthr ) ( (LONG)(bk) * (LONG)(qbthr)->bth.cbBlock + (LONG)sizeof( BTH ) )
  328. /* Btrees are limited to 268 megs for block sizes of 4096... no need for this below
  329. for now, but keep it for the future... */
  330. #define FoFromBk( bk, qbthr) \
  331. (FoAddDw(FoMultDw((DWORD)(bk),(DWORD)(qbthr)->bth.cbBlock),(DWORD)sizeof(BTH)) )
  332. /* get a pointer to the cache block cached for the given level */
  333. #define QCacheBlock( qbthr, wLevel ) \
  334. ((QCB)( (qbthr)->qCache + (wLevel) * CbCacheBlock( qbthr ) ))
  335. /* get and set prev and next BK (defined for leaf blocks only) */
  336. #define BkPrev( qcb ) *(LPUL)((qcb)->db.rgbBlock)
  337. #define BkNext( qcb ) *(((LPUL)((qcb)->db.rgbBlock)) + 1 )
  338. #define SetBkPrev( qcb, bk ) BkPrev( qcb ) = bk
  339. #define SetBkNext( qcb, bk ) BkNext( qcb ) = bk
  340. // For btree map functions: returns byte number of x-th btree map record //
  341. #define LcbFromBk(x) ((LONG)sizeof( short ) + x * sizeof( MAPREC ))
  342. /***************************************************************************\
  343. *
  344. * BTREE Types
  345. *
  346. \***************************************************************************/
  347. // Critical structures that gets messed up in /Zp8
  348. #pragma pack(1)
  349. /* This leading byte to signal the following font number */
  350. #define EMBEDFONT_BYTE_TAG 3
  351. /*
  352. Header of a btree file.
  353. */
  354. typedef struct _btree_header
  355. {
  356. USHORT wMagic;
  357. BYTE bVersion;
  358. BYTE bFlags; // r/o, open r/o, dirty, isdir
  359. SHORT cbBlock; // # bytes in a disk block
  360. CHAR rgchFormat[ wMaxFormat + 1 ]; // key and record format string
  361. BK bkFirst; // first leaf block in tree
  362. BK bkLast; // last leaf block in tree
  363. BK bkRoot; // root block
  364. BK bkFree; // head of free block list
  365. BK bkEOF; // next bk to use if free list empty
  366. SHORT cLevels; // # levels currently in tree
  367. LONG lcEntries; // # keys in btree
  368. //---- New Header Entries For Btree file version 4.0 -----
  369. DWORD dwCodePageID; // ANSI code page no.
  370. LCID lcid; // WIN32 locale ID (used for sorting).
  371. // If rgchFormat[0] != KT_EXTSORT, then the values for the following
  372. // two members are invalid.
  373. DWORD dwExtSortInstID; // External sort object specified by
  374. // btree caller for all key comparisons
  375. // during btree creation and search.
  376. DWORD dwExtSortKeyType; // Identifies the key datatype that the
  377. // sort object understands.
  378. DWORD dwUnused1;
  379. DWORD dwUnused2;
  380. DWORD dwUnused3;
  381. } BTH;
  382. /*
  383. In-memory struct referring to a btree.
  384. */
  385. typedef struct _bthr
  386. {
  387. BTH bth; // copy of header from disk
  388. HF hf; // file handle of open btree file
  389. SHORT cbRecordSize; // 0 means variable size record
  390. HANDLE ghCache; // handle to cache array
  391. QB qCache; // pointer to locked cache
  392. LPVOID FAR *lrglpCharTab; // Pointer to array of LPCHARTAB
  393. // (used by KT_SZMAP).
  394. #ifdef __cplusplus
  395. IITSortKey *pITSortKey; // Pointer to external sort instance
  396. // object (used by KT_EXTSORT).
  397. #else
  398. LPVOID pITSortKey; // Hack to make .c files compile.
  399. #endif
  400. // KT specific routines
  401. BK (FAR PASCAL *BkScanInternal)( BK, KEY, SHORT, struct _bthr FAR *, QW, LPVOID);
  402. RC (FAR PASCAL *RcScanLeaf)( BK, KEY, SHORT, struct _bthr FAR *, QV, QBTPOS );
  403. } BTH_RAM, FAR *QBTHR;
  404. /*
  405. Btree leaf or internal node. Keys and records live in rgbBlock[].
  406. See btree.doc for details.
  407. */
  408. typedef struct _disk_btree_block
  409. {
  410. short cbSlack; // unused bytes in block
  411. short cKeys; // count of keys in block
  412. BYTE rgbBlock[1]; // the block (real size cbBlock - 4)
  413. } DISK_BLOCK;
  414. /*
  415. Btree node as it exists in the in-memory cache.
  416. */
  417. typedef struct _cache_btree_block
  418. {
  419. BK bk; // IDs which block is cached
  420. BYTE bFlags; // dirty, cache valid
  421. BYTE bCompressed; // Is the B-tree compressed?
  422. DISK_BLOCK db;
  423. } CACHE_BLOCK, FAR *QCB;
  424. /*
  425. One record of a btree map.
  426. */
  427. typedef struct _btree_map_record // One record of a btree map
  428. {
  429. LONG cPreviousKeys; // total # of keys in previous blocks
  430. BK bk; // The block number
  431. } MAPREC, FAR *QMAPREC;
  432. /*
  433. Auxiliary index of btree leaves.
  434. Used for indexing a given % of the way into a btree.
  435. */
  436. typedef struct _btree_map
  437. {
  438. short cTotalBk;
  439. MAPREC table[1]; // sorted by MAPREC's cPreviousKeys field
  440. } MAPBT, FAR *QMAPBT; // and is in-order list of leaf nodes
  441. // Critical structures that gets messed up in /Zp8
  442. #pragma pack()
  443. /***************************************************************************\
  444. *
  445. * BTREE Function Prototypes
  446. *
  447. \***************************************************************************/
  448. SHORT PASCAL FAR CbSizeRec ( QV, QBTHR );
  449. QCB PASCAL FAR QFromBk ( BK, SHORT, QBTHR, LPVOID );
  450. RC PASCAL FAR RcGetKey ( QV, KEY, KEY *, KT );
  451. SHORT PASCAL FAR WCmpKey ( KEY, KEY, QBTHR );
  452. SHORT PASCAL FAR CbSizeKey ( KEY, QBTHR, BOOL );
  453. RC PASCAL FAR FReadBlock ( QCB, QBTHR );
  454. RC PASCAL FAR RcWriteBlock ( QCB, QBTHR );
  455. BK PASCAL FAR BkAlloc ( QBTHR, LPVOID);
  456. void PASCAL FAR FreeBk ( QBTHR, BK );
  457. RC PASCAL FAR RcSplitLeaf ( QCB, QCB, QBTHR );
  458. void PASCAL FAR SplitInternal ( QCB, QCB, QBTHR, QW );
  459. RC PASCAL FAR RcInsertInternal( BK, KEY, SHORT, QBTHR );
  460. RC PASCAL FAR RcFlushCache ( QBTHR );
  461. RC FAR PASCAL RcMakeCache ( QBTHR );
  462. // overkill - function to verify integrity of cache
  463. BOOL FAR PASCAL IsCacheValid(QBTHR qbthr, QFSHR qfshr);
  464. // KT specific routines
  465. BK FAR PASCAL BkScanSzInternal( BK, KEY, SHORT, QBTHR, QW , LPVOID);
  466. RC FAR PASCAL RcScanSzLeaf ( BK, KEY, SHORT, QBTHR, QV, QBTPOS );
  467. BK FAR PASCAL BkScanLInternal ( BK, KEY, SHORT, QBTHR, QW , LPVOID);
  468. RC FAR PASCAL RcScanLLeaf ( BK, KEY, SHORT, QBTHR, QV, QBTPOS );
  469. BK FAR PASCAL BkScanSziInternal ( BK, KEY, SHORT, QBTHR, QW, LPVOID );
  470. RC FAR PASCAL RcScanSziLeaf ( BK, KEY, SHORT, QBTHR, QV, QBTPOS );
  471. BK FAR PASCAL BkScanVstiInternal ( BK, KEY, SHORT, QBTHR, QW, LPVOID );
  472. RC FAR PASCAL RcScanVstiLeaf ( BK, KEY, SHORT, QBTHR, QV, QBTPOS );
  473. BK FAR PASCAL BkScanSziScandInternal( BK, KEY, SHORT, QBTHR, QW, LPVOID );
  474. RC FAR PASCAL RcScanSziScandLeaf ( BK, KEY, SHORT, QBTHR, QV, QBTPOS );
  475. RC FAR PASCAL RcScanCMapLeaf(BK, KEY, SHORT, QBTHR, QV, QBTPOS);
  476. BK FAR PASCAL BkScanCMapInternal(BK, KEY, SHORT, QBTHR, QW, LPVOID);
  477. int PASCAL FAR StringJCompare(DWORD, LPBYTE, int, LPBYTE, int);
  478. RC FAR PASCAL RcScanExtSortLeaf(BK, KEY, SHORT, QBTHR, QV, QBTPOS);
  479. BK FAR PASCAL BkScanExtSortInternal(BK, KEY, SHORT, QBTHR, QW, LPVOID);
  480. /***************************************************************************\
  481. *
  482. * IOFTS.C
  483. *
  484. \***************************************************************************/
  485. #ifndef READ
  486. #define READ 0 // File opened for read-only
  487. #endif
  488. #ifdef _32BIT
  489. #define READ_WRITE 2
  490. #endif
  491. typedef HANDLE GHANDLE;
  492. typedef GHANDLE HFPB;
  493. typedef BYTE FAR * LRGB;
  494. /* Compound file system related macros and typedef */
  495. #define FS_SYSTEMFILE 1
  496. #define FS_SUBFILE 2
  497. #define REGULAR_FILE 3
  498. #define cbIO_ERROR ((WORD)-1) // Low-level I/O error return.
  499. #define cbMAX_IO_SIZE ((WORD)32767) // Largest physical I/O I can do.
  500. /*
  501. #ifdef DLL // {
  502. #define LPF_HFCREATEFILEHFS HfCreateFileHfs
  503. #define LPF_RCCLOSEHFS RcCloseHfs
  504. #define LPF_HFOPENHFS HfOpenHfs
  505. #define LPF_RCCLOSEHF RcCloseHf
  506. #define LPF_LCBREADHF LcbReadHf
  507. #define LPF_LCBWRITEHF LcbWriteHf
  508. #define LPF_LSEEKHF DwSeekHf
  509. #define LPF_RCFLUSHHF RcFlushHf
  510. #define LPF_LCBSIZEHF LcbSizeHf
  511. #define LPF_GETFSERR RcGetFSError
  512. #define LPF_HFSOPENSZ HfsOpenSz
  513. #else
  514. #define LPF_HFSCREATEFILESYS VfsCreate
  515. #define LPF_RCCLOSEHFS RcCloseHfs
  516. #define LPF_HFCREATEFILEHFS HfCreateFileHfs
  517. #define LPF_HFSOPENSZ HfsOpenSz
  518. #define LPF_HFOPENHFS HfOpenHfs
  519. #define LPF_RCCLOSEHF RcCloseHf
  520. #define LPF_LCBREADHF LcbReadHf
  521. #define LPF_LCBWRITEHF LcbWriteHf
  522. #define LPF_LSEEKHF DwSeekHf
  523. #define LPF_RCFLUSHHF RcFlushHf
  524. #define LPF_LCBSIZEHF LcbSizeHf
  525. #define LPF_GETFSERR RcGetFSError
  526. #endif // } LOMEM
  527. */
  528. /* The file I/O buffer structure. This is to minimize I/O time
  529. * The allocated buffer should be right after the structure
  530. * ie. the memory allocation call should be:
  531. * alloc (BufSize + sizeof(FBI)
  532. * or everything will fail
  533. */
  534. #ifdef _WIN32
  535. #define HFILE_GENERIC HANDLE
  536. #define HFILE_GENERIC_ERROR ((HANDLE)-1)
  537. #else
  538. #define HFILE_GENERIC HFILE
  539. #define HFILE_GENERIC_ERROR HFILE_ERROR
  540. #endif
  541. typedef struct FileBufInfo {
  542. GHANDLE hStruct; /* Structure's handle. MUST BE 1ST FIELD */
  543. DWORD lcByteWritten; /* How many bytes are written using this buffer */
  544. WORD cbBufSize; /* Size of the buffer */
  545. HFILE_GENERIC hFile; /* DOS file handle */
  546. FILEOFFSET fo;
  547. FILEOFFSET foExtent;
  548. LRGB lrgbBuf;
  549. /* TO BE DELETED */
  550. HFPB hfpb;
  551. WORD ibBuf;
  552. WORD cbBuf;
  553. } FBI,
  554. FAR *LPFBI;
  555. /* File related functions */
  556. PUBLIC RC FAR PASCAL FileExist (HFPB, LPCSTR, int);
  557. PUBLIC HFPB FAR PASCAL FileCreate (HFPB, LPCSTR, int, LPERRB);
  558. PUBLIC HFPB FAR PASCAL FileOpen (HFPB, LPCSTR, int, int, LPERRB);
  559. PUBLIC FILEOFFSET FAR PASCAL FileSeek(HFPB, FILEOFFSET, WORD, LPERRB);
  560. PUBLIC LONG FAR PASCAL FileRead(HFPB, LPV, LONG, LPERRB);
  561. PUBLIC LONG FAR PASCAL FileWrite (HFPB, LPV, LONG, LPERRB);
  562. PUBLIC LONG FAR PASCAL FileSeekRead(HFPB, LPV, FILEOFFSET, LONG, LPERRB);
  563. PUBLIC LONG FAR PASCAL FileSeekWrite (HFPB, LPV, FILEOFFSET, LONG, LPERRB);
  564. PUBLIC FILEOFFSET FAR PASCAL FileSize(HFPB hfpb, LPERRB lperrb);
  565. PUBLIC FILEOFFSET FAR PASCAL FileOffset(HFPB hfpb, LPERRB lperrb);
  566. PUBLIC int FAR PASCAL FileFlush(HFPB);
  567. PUBLIC RC FAR PASCAL FileClose(HFPB);
  568. PUBLIC RC FAR PASCAL FileUnlink (HFPB, LPCSTR, int);
  569. PUBLIC VOID SetFCallBack (HFPB, INTERRUPT_FUNC, LPV);
  570. PUBLIC VOID PASCAL FAR GetFSName(LSZ, LSZ, LSZ FAR *, LSZ);
  571. PUBLIC HFS FAR PASCAL GetHfs(HFPB, LPCSTR, BOOL, LPERRB);
  572. PUBLIC int PASCAL FAR IsFsName (LSZ);
  573. PUBLIC LPSTR FAR PASCAL CreateDefaultFilename(LPCSTR, LPCSTR, LPSTR);
  574. PUBLIC HFS FAR PASCAL HfsFromHfpb(HFPB hfpb);
  575. KEY PASCAL FAR EXPORT_API NewKeyFromSz(LPCSTR sz);
  576. void PASCAL FAR EXPORT_API GetFrData(FILE_REC FAR *pfr);
  577. /* File buffer related functions */
  578. PUBLIC LPFBI PASCAL FAR EXPORT_API FileBufAlloc (HFPB, WORD);
  579. PUBLIC int PASCAL FAR FileBufFlush (LPFBI);
  580. PUBLIC VOID PASCAL FAR FileBufFree (LPFBI);
  581. PUBLIC BOOL FAR PASCAL FileBufFill (LPFBI, LPERRB);
  582. PUBLIC BOOL FAR PASCAL FileBufBackPatch(LPFBI, LPV, FILEOFFSET, WORD);
  583. PUBLIC BOOL FAR PASCAL FileBufRewind(LPFBI);
  584. // Be sure to call FreeHfpb when done with an HFPB that was created
  585. // via one of the FbpFromXXXX calls.
  586. PUBLIC HSFB PASCAL FAR FpbFromHfs(HFS hfsHandle, LPERRB lperrb);
  587. PUBLIC HSFB PASCAL FAR FpbFromHf(HF hfHandle, PHRESULT phr);
  588. PUBLIC DWORD PASCAL FAR FsTypeFromHfpb(HFPB hfpb);
  589. PUBLIC VOID PASCAL FAR FreeHfpb(HFPB hfpb);
  590. /*************************************************************************
  591. *
  592. * Block Memory Management Functions Prototype
  593. *
  594. *************************************************************************/
  595. typedef struct BLOCK {
  596. HANDLE hStruct; /* Handle to this structure */
  597. struct BLOCK FAR *lpNext; /* Pointer to next block */
  598. int wStamp;
  599. } BLOCK, FAR *LPBLOCK;
  600. typedef struct {
  601. HANDLE hStruct; /* Handle to this structure */
  602. int wStamp; /* For block consistency checking */
  603. struct BLOCK FAR *lpHead; /* Head of block list */
  604. struct BLOCK FAR *lpCur; /* Current block */
  605. LPB lpbCurLoc; /* Pointer to current data location */
  606. DWORD cBytePerBlock; /* Number of bytes per block */
  607. DWORD cByteLeft; /* How many bytes left */
  608. DWORD lTotalSize;
  609. WORD wElemSize; /* Element size */
  610. WORD cMaxBlock; /* Maximum number of blocks */
  611. WORD cCurBlockCnt; /* Current number of blocks */
  612. WORD fFlag; /* Various block flags */
  613. } BLOCK_MGR,
  614. FAR *LPBLK;
  615. #define BLOCKMGR_ELEMSIZE(lpblk) ((lpblk)->wElemSize)
  616. #define BLOCKMGR_BLOCKSIZE(lpblk) ((lpblk)->cBytePerBlock)
  617. #define BlockRequest(lpblk, cb, cbExtra) BlockCopy(lpblk, NULL, cb, cbExtra)
  618. LPB PASCAL FAR BlockGetOrdinalBlock (LPVOID lpBlockHead, WORD iBlock);
  619. PUBLIC LPB PASCAL FAR BlockReset (LPV);
  620. PUBLIC VOID PASCAL FAR BlockFree (LPV);
  621. PUBLIC LPV PASCAL FAR BlockInitiate (DWORD, WORD, WORD, int);
  622. PUBLIC LPV PASCAL FAR BlockCopy (LPV, LPB, DWORD, WORD);
  623. PUBLIC LPV PASCAL FAR BlockGetElement(LPV);
  624. PUBLIC int PASCAL FAR BlockGrowth (LPV);
  625. PUBLIC LPB PASCAL FAR BlockGetLinkedList(LPV);
  626. PUBLIC LPVOID PASCAL FAR BlockGetBlock (LPV, DWORD);
  627. PUBLIC VOID PASCAL FAR SetBlockCount (LPV lpBlock, WORD count);
  628. // hashing-related functions
  629. PUBLIC DWORD FAR PASCAL DwordFromSz(LPCSTR szKey);
  630. PUBLIC HASH FAR PASCAL HashFromSz(LPCSTR szKey);
  631. // miscellaneous
  632. PUBLIC int FAR PASCAL StripSpaces(LPSTR szName);
  633. // Byte Packing
  634. int PASCAL FAR EXPORT_API PackBytes (LPB lpbOut, DWORD dwIn);
  635. int PASCAL FAR EXPORT_API UnpackBytes (LPDWORD lpdwOut, LPB lpbIn);
  636. /*******************************************************************
  637. * *
  638. * FCPARSE.C *
  639. * *
  640. *******************************************************************/
  641. // generic FC parsing routine: one command at a time
  642. // arbitrary upper limit on total number of leaf nodes in object tree. Only if heavy use
  643. // is made of tables within tables, will it be possible to reach this limit.
  644. #define cChildLeafMax (cColumnMax * 8)
  645. typedef struct tagFCPARSE
  646. {
  647. LPBYTE lpbNextCmd;
  648. LPCHAR lpchNext;
  649. SHORT iChild;
  650. SHORT iChildMax; // (child and column mean same thing)
  651. LPBYTE rglpbCmd[cChildLeafMax]; // offset into command table (for child objects)
  652. LPCHAR rglpchText[cChildLeafMax]; // offset into command table (for child objects)
  653. } FCPARSE, FAR *LPFCPARSE;
  654. /*************************************************************************
  655. * @doc INTERNAL COMMON
  656. *
  657. * @func BOOL FAR PASCAL | FcParseInit |
  658. * Prepare to parse a MediaView FC
  659. *
  660. * @parm LPBYTE | qbObj |
  661. * Pointer to memory buffer holding MV FC to be parsed
  662. *
  663. * @parm DWORD | dwObj |
  664. * Total buffer's size
  665. *
  666. * @parm LPFCPARSE | lpfcp |
  667. * Pointer to FCPARSE structure to hold parse state
  668. *************************************************************************/
  669. BOOL FAR PASCAL FcParseInit(LPBYTE qbObj, DWORD dwObj, LPFCPARSE lpfcp);
  670. /*************************************************************************
  671. * @doc INTERNAL COMMON
  672. *
  673. * @func LPCHAR FAR PASCAL | FcParseNextCmd |
  674. * Get the next command or text string in the object. The return
  675. * pointer always points to a CHAR in the text section of an Fc. If this
  676. * character is zero, this indicates a command, and the lpbCom param will
  677. * have been filled with a pointer to the corresponding command data, else it
  678. * is NULL.
  679. * It is up to the app to process the command arguments after this function
  680. * returns.
  681. *
  682. * @parm LPFCPARSE | lpfcp |
  683. * Pointer to FCPARSE structure holding current parse state
  684. *
  685. * @parm LPBYTE FAR * | lpbCom |
  686. * NULL if pointing to text, else points to command data
  687. *************************************************************************/
  688. LPCHAR FAR PASCAL FcParseNextCmd(LPFCPARSE lpfcp, LPBYTE FAR *lpbCom);
  689. ////////// FONT TABLE AND CHAR TAB STUFF ///////////////////
  690. HANDLE FAR PASCAL hReadFontTable (HANDLE, VOID FAR *);
  691. PUBLIC VOID PASCAL FAR CharMapOffsetToPointer (QFONTTABLE qFontTable);
  692. PUBLIC VOID PASCAL FAR CharMapPointerToOffset (QFONTTABLE qFontTable);
  693. PUBLIC LPCTAB EXPORT_API FAR PASCAL MVCharTableLoad (HFPB, LSZ, LPERRB);
  694. PUBLIC LPCTAB EXPORT_API FAR PASCAL MVCharTableGetDefault (LPERRB);
  695. PUBLIC VOID EXPORT_API FAR PASCAL MVCharTableDispose (LPCTAB);
  696. PUBLIC ERR EXPORT_API PASCAL FAR MVCharTableFileBuild (HFPB, LPCTAB, LSZ);
  697. PUBLIC LPCTAB EXPORT_API FAR PASCAL MVCharTableIndexLoad(HANDLE, LSZ, LPERRB);
  698. ////////// FILESORT STUFF ///////////////////
  699. typedef HRESULT (PASCAL FAR * FNSCAN)(LPFBI, LPB, LPV);
  700. typedef int (PASCAL FAR * FNSORT)(LPSTR, LPSTR, LPV);
  701. HRESULT PASCAL FileSort (HFPB hfpb, LPB Filename,
  702. STATUS_FUNC PrintStatusFunc, INTERRUPT_FUNC lpfnInterrupt,
  703. LPV lpInterruptParm, FNSORT fnSort, LPVOID lpSortParm,
  704. FNSCAN fnScan, LPVOID lpScanParam);
  705. //-------------------------------------------------------------
  706. //------ COMMON\ITUTILS.CPP STUFF -------
  707. //-------------------------------------------------------------
  708. HRESULT FAR PASCAL ReallocBufferHmem(HGLOBAL *phmemBuf, DWORD *pcbBufCur,
  709. DWORD cbBufNew);
  710. void FAR PASCAL SetGrfFlag(DWORD *pgrf, DWORD fGrfFlag, BOOL fSet);
  711. LPSTR MapSequentialReadFile(LPCSTR szFilename, LPDWORD pdwFileSize);
  712. // We use our own simplified version so that the linker doesn't pull in
  713. // CRT startup code from LIBCMT.LIB.
  714. int __cdecl _it_wcsicmp(const wchar_t *dst, const wchar_t *src);
  715. #pragma pack()
  716. #ifdef __cplusplus
  717. }
  718. #endif
  719. #endif //__MVUTIL_H__