source: trunk/tools/common/kFileInterfaces.cpp@ 8706

Last change on this file since 8706 was 8003, checked in by bird, 24 years ago

New kFile* classes; now in sync with os2tools.

File size: 4.0 KB
Line 
1/* $Id: kFileInterfaces.cpp,v 1.1 2002-02-24 02:47:25 bird Exp $
2 *
3 * kFileInterface.cpp - Interface helpers and workers.
4 *
5 * I've decided that this is the logical place to put many
6 * of those generic worker/helper methods which works on
7 * or with the interfaces. In java this would be impossible
8 * using the real interfaces, but in C++ when we use empty
9 * classes it very possible and quite helpful.
10 *
11 * Copyright (c) 2001 knut st. osmundsen (kosmunds@csc.com)
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include "kTypes.h"
22#include "kError.h"
23#include "kFileInterfaces.h"
24
25
26
27/*******************************************************************************
28* Structures and Typedefs *
29*******************************************************************************/
30/**
31 * XRef status and search info.
32 * kRelocEntry::pv2 points to this structure.
33 */
34typedef struct _XRefState
35{
36 /* Position we wanna find references to. */
37 unsigned long ulSegment;
38 unsigned long offSegment;
39} XREFSTATE, *PXREFSTATE;
40
41
42
43/**
44 * Finds the first reference to a location in the image.
45 *
46 * @returns Success indicator.
47 * TRUE if found anything.
48 * FALSE if nothing
49 * @param ulSegment Segment number (0-based).
50 * Special segment numbers are not supported.
51 * @param offSegment Offset into the segement (ulSegment).
52 * @param preloc The enumeration 'handle.'
53 * @status implemented.
54 * @author knut st. osmundsen (kosmunds@csc.com)
55 * @remark No special segment numbers are supported.
56 */
57KBOOL kRelocI::relocXRefFindFirst(unsigned long ulSegment, unsigned long offSegment, kRelocEntry *preloc)
58{
59 kASSERT(preloc);
60 kASSERT(ulSegment < kRelocEntry::enmFirstSelector);
61
62 /*
63 * Save the target we are searching for references to.
64 */
65 PXREFSTATE pState = new XREFSTATE;
66 pState->ulSegment = ulSegment;
67 pState->offSegment = offSegment;
68 preloc->pv2 = (void*)pState;
69
70 /*
71 * Start searching.
72 */
73 if (relocFindFirst(0, 0, preloc))
74 {
75 kASSERT(ulSegment < kRelocEntry::enmFirstSelector);
76 if ( preloc->isInternal()
77 && preloc->Info.Internal.ulSegment == ulSegment
78 && preloc->Info.Internal.offSegment == offSegment
79 )
80 return TRUE;
81
82 KBOOL fRc = relocXRefFindNext(preloc);
83 if (!fRc)
84 relocXRefFindClose(preloc);
85 return fRc;
86 }
87
88 return FALSE;
89}
90
91
92/**
93 * Finds the next reference to the address.
94 * @returns Success indicator.
95 * Returns FALSE if no more matches.
96 * @param preloc The enumeration 'handle.'
97 * This must be initiated by a call to relocXRefFindFirst.
98 * @status implemented.
99 * @author knut st. osmundsen (kosmunds@csc.com)
100 */
101KBOOL kRelocI::relocXRefFindNext(kRelocEntry *preloc)
102{
103 kASSERT(preloc->pv2 != NULL);
104
105 while (relocFindNext(preloc))
106 {
107 kASSERT(preloc->ulSegment < kRelocEntry::enmFirstSelector);
108 if ( preloc->isInternal()
109 && preloc->Info.Internal.ulSegment == ((PXREFSTATE)preloc->pv2)->ulSegment
110 && preloc->Info.Internal.offSegment == ((PXREFSTATE)preloc->pv2)->offSegment
111 )
112 return TRUE;
113 }
114
115 return FALSE;
116}
117
118
119/**
120 * Closes a find session - this function *must* be called to
121 * clean up resources used internally.
122 *
123 * @param preloc The enumeration 'handle.'
124 * This must be initiated by a call to relocXRefFindFirst.
125 * @status implemented.
126 * @author knut st. osmundsen (kosmunds@csc.com)
127 * @remark
128 */
129void kRelocI::relocXRefFindClose(kRelocEntry *preloc)
130{
131 kASSERT(preloc != NULL);
132 relocFindClose(preloc);
133 delete preloc->pv2;
134 preloc->pv2 = NULL;
135}
136
Note: See TracBrowser for help on using the repository browser.