|
1 /* |
|
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <assert.h> |
|
20 #include <string.h> |
|
21 #include <stdlib.h> |
|
22 #include "ASTRING.H" |
|
23 #include "FILELINE.H" |
|
24 #include "NUMVAL.H" |
|
25 #include "TOKENS.H" |
|
26 |
|
27 #ifdef __LINUX__ |
|
28 #include <linux/limits.h> |
|
29 #define _MAX_PATH PATH_MAX |
|
30 #endif //__LINUX__ |
|
31 |
|
32 #ifdef __VC32__ |
|
33 #pragma warning( push, 1 ) // MS STL libraries do not compile cleanly, temporarily set warning level to 1 |
|
34 #pragma warning( disable : 4710 ) // function not inlined. |
|
35 #endif |
|
36 FileLineManager::FileLineManager(): |
|
37 iOffsetLineNumber(0) {} |
|
38 FileLineManager::~FileLineManager() {} |
|
39 void FileLineManager::SetCurrentFile(const String& a) |
|
40 { |
|
41 iCurrentFileName = &*(iAllFileNames.insert(a).first); |
|
42 } |
|
43 #ifdef __VC32__ |
|
44 #pragma warning( pop ) |
|
45 #endif |
|
46 |
|
47 void FileLineManager::SetBase(const String& aFileName,int aLineNumber) |
|
48 { |
|
49 SetCurrentFile(aFileName); |
|
50 iBaseFileName = iCurrentFileName; |
|
51 iOffsetLineNumber=aLineNumber; |
|
52 } |
|
53 |
|
54 void FileLineManager::SetPath(const String& aDriveAndDirectory) |
|
55 { |
|
56 iBasePath=aDriveAndDirectory; |
|
57 } |
|
58 |
|
59 String FileLineManager::ExtractFileName( const String & Text) |
|
60 { |
|
61 |
|
62 // The string that is passed to this procedure is expected to contain |
|
63 // a file specification followed by a " followed by other stuff that |
|
64 // is generated by the preprocessor. We can discard the latter stuff. |
|
65 // This will leave either an empty string (implying the base file name) |
|
66 // or a unix-format relative file specification. |
|
67 |
|
68 // This string class has very little functionality, so we end up |
|
69 // doing traditional C-style stuff on a char buffer to achieve |
|
70 // what we need {sigh}... |
|
71 |
|
72 char buffer[_MAX_PATH +1]; |
|
73 // (older version of this code used heap allocation but I prefer |
|
74 // this way which is safer and does less heap-churning) |
|
75 |
|
76 |
|
77 String result; // This is what we will pass back |
|
78 |
|
79 // Copy the text to our working buffer |
|
80 |
|
81 int n = Text.Length(); |
|
82 if ( n >= _MAX_PATH ) n = _MAX_PATH; // Unlikely, but you never know |
|
83 strncpy(buffer, Text.GetAssertedNonEmptyBuffer(), n); |
|
84 buffer[n] = '\0'; // add zero terminator |
|
85 |
|
86 // truncate to the expected double quote character |
|
87 |
|
88 char * pquote = strchr(buffer, '"'); |
|
89 if ( pquote != NULL ) * pquote = '\0'; |
|
90 |
|
91 n = strlen(buffer); |
|
92 |
|
93 |
|
94 // If we now have an empty string then replace it with the |
|
95 // base filename string that should already be defined. |
|
96 |
|
97 if ( n == 0 ) |
|
98 { |
|
99 n = iBaseFileName->Length(); |
|
100 if ( n > _MAX_PATH ) n = _MAX_PATH; |
|
101 if (n>0) strncpy(buffer, iBaseFileName->GetAssertedNonEmptyBuffer(), n); |
|
102 buffer[n] = '\0'; |
|
103 } |
|
104 |
|
105 #ifndef __LINUX__ |
|
106 // Replace all the unix-like forward slashes with DOS-like backslashes |
|
107 |
|
108 while ( n > 0 ) |
|
109 { |
|
110 n -=1; |
|
111 if ( buffer[n] == '/' ) buffer[n] = '\\'; |
|
112 } |
|
113 #endif //__LINUX__ |
|
114 |
|
115 result = buffer; |
|
116 return result; |
|
117 } |
|
118 |
|
119 void FileLineManager::SetInclude(const String& aNameText,int aLineNumber) |
|
120 { |
|
121 SetCurrentFile(ExtractFileName(aNameText)); |
|
122 iOffsetLineNumber = aLineNumber; |
|
123 } |
|
124 |
|
125 void FileLineManager::PostInclude( char* aNameText, char * aRealLineNumber, int aLineNumber) |
|
126 { // Returning to a file (after having included another file). |
|
127 SetCurrentFile(ExtractFileName(aNameText)); |
|
128 int val = atoi(aRealLineNumber); |
|
129 iOffsetLineNumber=aLineNumber - val + 1; |
|
130 } |
|
131 |
|
132 int FileLineManager::GetErrorLine(int aCurrentLineNumber) const |
|
133 { |
|
134 return aCurrentLineNumber-iOffsetLineNumber; |
|
135 } |
|
136 |
|
137 const String* FileLineManager::GetCurrentFile() const |
|
138 { |
|
139 return iCurrentFileName; |
|
140 } |
|
141 |