@@ -136,18 +136,23 @@ string generate_call_details_string(const char* current_block, const char* curre
136
136
return e;
137
137
}
138
138
139
- string generate_filename_and_line (const char * current_file, int current_line_no )
139
+ string get_pretty_filename (const char * current_file)
140
140
{
141
141
// RPG Hacker: One could make an argument that we shouldn't shorten paths
142
142
// here, since some IDEs support jumping to files by double-clicking their
143
143
// paths. However, AFAIK, no IDE supports this for Asar yet, and if it's
144
144
// ever desired, we could just make it a command line option. Until then,
145
145
// I think it's more important to optimize for pretty command line display.
146
- return STR shorten_to_relative_path (get_top_level_directory (), current_file)
146
+ return shorten_to_relative_path (get_top_level_directory (), current_file);
147
+ }
148
+
149
+ string generate_filename_and_line (const char * current_file, int current_line_no)
150
+ {
151
+ return STR current_file
147
152
+ (current_line_no>=0 ?STR " :" +dec (current_line_no+1 ):" " );
148
153
}
149
154
150
- void push_stack_line (autoarray< string>* lines, const char * current_file, const char * current_block, const char * current_call, int current_line_no , int stack_frame_index)
155
+ string format_stack_line ( const printable_callstack_entry& entry , int stack_frame_index)
151
156
{
152
157
string indent = " \n | " ;
153
158
indent += dec (stack_frame_index);
@@ -156,10 +161,19 @@ void push_stack_line(autoarray<string>* lines, const char* current_file, const c
156
161
// hundreds even, so this very specific, lazy solution suffices.
157
162
if (stack_frame_index < 100 ) indent += " " ;
158
163
if (stack_frame_index < 10 ) indent += " " ;
159
- lines->append (indent
160
- + generate_filename_and_line (current_file, current_line_no)
161
- + generate_call_details_string (current_block, current_call, 12 , true )
162
- );
164
+ return indent
165
+ + generate_filename_and_line (entry.prettypath , entry.lineno )
166
+ + entry.details ;
167
+ }
168
+
169
+ void push_stack_line (autoarray<printable_callstack_entry>* out, const char * current_file, const char * current_block, const char * current_call, int current_line_no, int indentation, bool add_lines)
170
+ {
171
+ printable_callstack_entry new_entry;
172
+ new_entry.fullpath = current_file;
173
+ new_entry.prettypath = get_pretty_filename (current_file);
174
+ new_entry.lineno = current_line_no;
175
+ new_entry.details = strip_whitespace (generate_call_details_string (current_block, current_call, indentation, add_lines).raw ());
176
+ out->append (new_entry);
163
177
}
164
178
165
179
void get_current_line_details (string* location, string* details, bool exclude_block)
@@ -175,7 +189,7 @@ void get_current_line_details(string* location, string* details, bool exclude_bl
175
189
case callstack_entry_type::FILE:
176
190
current_file = callstack[i].content ;
177
191
if (exclude_block) current_block = nullptr ;
178
- *location = generate_filename_and_line (current_file, current_line_no);
192
+ *location = generate_filename_and_line (get_pretty_filename ( current_file) , current_line_no);
179
193
*details = generate_call_details_string (current_block, current_call, 4 , false );
180
194
return ;
181
195
case callstack_entry_type::MACRO_CALL:
@@ -194,9 +208,9 @@ void get_current_line_details(string* location, string* details, bool exclude_bl
194
208
*details = " " ;
195
209
}
196
210
197
- string get_full_callstack ( )
211
+ void get_full_printable_callstack (autoarray<printable_callstack_entry>* out, int indentation, bool add_lines )
198
212
{
199
- autoarray<string> lines ;
213
+ out-> reset () ;
200
214
const char * current_file = nullptr ;
201
215
const char * current_block = nullptr ;
202
216
const char * current_call = nullptr ;
@@ -208,7 +222,7 @@ string get_full_callstack()
208
222
case callstack_entry_type::FILE:
209
223
if (current_file != nullptr )
210
224
{
211
- push_stack_line (&lines , current_file, current_block, current_call, current_line_no, lines. count );
225
+ push_stack_line (out , current_file, current_block, current_call, current_line_no, indentation, add_lines );
212
226
}
213
227
current_file = callstack[i].content ;
214
228
current_block = nullptr ;
@@ -228,16 +242,21 @@ string get_full_callstack()
228
242
break ;
229
243
}
230
244
}
231
- // RPG Hacker: This pop here is incorrect, because with the
232
- // way we traverse the call stack, the highest level is
233
- // already automatically excluded, anyways.
234
- // if (lines.count > 0) lines.remove(lines.count-1);
235
-
245
+ }
246
+
247
+ string get_full_callstack ()
248
+ {
249
+ autoarray<printable_callstack_entry> printable_stack;
250
+ get_full_printable_callstack (&printable_stack, 12 , true );
251
+
236
252
string e;
237
- if (lines .count > 0 )
253
+ if (printable_stack .count > 0 )
238
254
{
239
255
e += " \n Full call stack:" ;
240
- for (int i = lines.count -1 ; i >= 0 ; --i) e += lines[i];
256
+ for (int i = printable_stack.count -1 ; i >= 0 ; --i)
257
+ {
258
+ e += format_stack_line (printable_stack[i], i);
259
+ }
241
260
}
242
261
return e;
243
262
}
@@ -293,7 +312,7 @@ string get_simple_callstack()
293
312
string e;
294
313
if (current_call != nullptr && current_file != nullptr )
295
314
{
296
- e += STR " \n called from: " + generate_filename_and_line (current_file, current_line_no)
315
+ e += STR " \n called from: " + generate_filename_and_line (get_pretty_filename ( current_file) , current_line_no)
297
316
+ " : [%" + current_call + " ]" ;
298
317
}
299
318
return e;
@@ -1156,38 +1175,6 @@ const char* get_current_block()
1156
1175
return nullptr ;
1157
1176
}
1158
1177
1159
- const char * get_previous_file_name ()
1160
- {
1161
- int num_files = 0 ;
1162
- for (int i = callstack.count -1 ; i >= 0 ; --i)
1163
- {
1164
- if (callstack[i].type == callstack_entry_type::FILE)
1165
- {
1166
- num_files++;
1167
- if (num_files > 1 ) return callstack[i].content .raw ();
1168
- }
1169
- }
1170
- return nullptr ;
1171
- }
1172
-
1173
- int get_previous_file_line_no ()
1174
- {
1175
- int num_files = 0 ;
1176
- for (int i = callstack.count -1 ; i >= 0 ; --i)
1177
- {
1178
- if (callstack[i].type == callstack_entry_type::FILE)
1179
- {
1180
- num_files++;
1181
- if (num_files > 1 ) return -1 ;
1182
- }
1183
- else if (callstack[i].type == callstack_entry_type::LINE)
1184
- {
1185
- if (num_files == 1 ) return callstack[i].lineno ;
1186
- }
1187
- }
1188
- return -1 ;
1189
- }
1190
-
1191
1178
1192
1179
void reseteverything ()
1193
1180
{
0 commit comments