Adds VerifyQuit screen, tidies up memory alloc/free tracing (#37)

* Adds VerifyQuit screen, tidies up very verbose memory alloc/free tracing, extra error checks on SDL calls
This commit is contained in:
Jeff Harris 2020-09-09 07:41:12 -07:00 committed by GitHub
parent 5defeb8a59
commit a7e588d1f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 391 additions and 104 deletions

View File

@ -25,7 +25,8 @@ test: build
@(cd test/build && ./c1tests $$DETHRACE_TEST_ARGS)
install-deps:
sudo apt-get update
sudo apt-get install libsdl2-dev
run: build
@src/DETHRACE/build/c1
@src/DETHRACE/build/c1 $$DETHRACE_ARGS

View File

@ -61,7 +61,7 @@ br_node* BrRemove(br_node* node) {
// Offset: 573
// Size: 39
void BrSimpleNewList(br_simple_list* list) {
LOG_TRACE("(%p)", list);
LOG_TRACE10("(%p)", list);
list->head = NULL;
}

View File

@ -40,7 +40,7 @@ void* BrSwapBlock(void* block, int count, int size) {
br_uint_8* cp;
int i;
int k;
LOG_TRACE("(%p, %d, %d)", block, count, size);
LOG_TRACE9("(%p, %d, %d)", block, count, size);
cp = (br_uint_8*)block;
switch (size) {

View File

@ -121,7 +121,7 @@ int DatafileStackTop;
// EDX: value
// EBX: count
void DfPush(int type, void* value, int count) {
LOG_TRACE("(%d, %p, %d)", type, value, count);
LOG_TRACE9("(%d, %p, %d)", type, value, count);
if (DatafileStackTop >= 1024) {
BrFailure("DatafileStack Overflow");
@ -137,7 +137,7 @@ void DfPush(int type, void* value, int count) {
// EAX: type
// EDX: countp
void* DfPop(int type, int* countp) {
LOG_TRACE("(%d, %p)", type, countp);
LOG_TRACE9("(%d, %p)", type, countp);
if (DatafileStackTop <= 0) {
BrFailure("DatafileStack Underflow");
@ -302,7 +302,7 @@ br_uint_32 DfStructReadBinary(br_datafile* df, br_file_struct* str, void* base)
float f;
} conv;
LOG_TRACE("(%p, %p, %p)", df, str, base);
LOG_TRACE9("(%p, %p, %p)", df, str, base);
for (m = 0; m < str->nmembers; m++) {
@ -617,7 +617,7 @@ int DfChunkWriteBinary(br_datafile* df, br_uint_32 id, br_uint_32 length) {
int DfChunkReadBinary(br_datafile* df, br_uint_32* plength) {
br_uint_32 id;
br_uint_32 l;
LOG_TRACE("(%p, %p)", df, plength);
LOG_TRACE9("(%p, %p)", df, plength);
if (BrFileEof(df->h)) {
return -1;
@ -877,7 +877,7 @@ int DfSkipText(br_datafile* df, br_uint_32 length) {
// EAX: df
// EDX: length
int DfSkipBinary(br_datafile* df, br_uint_32 length) {
LOG_TRACE("(%p, %d)", df, length);
LOG_TRACE9("(%p, %d)", df, length);
BrFileAdvance(length, df->h);
}
@ -891,7 +891,7 @@ int DfChunksInterpret(br_datafile* df, br_chunks_table* table) {
br_uint_32 id;
int r;
int i;
LOG_TRACE("(%p, %p)", df, table);
LOG_TRACE9("(%p, %p)", df, table);
while (1) {
id = df->prims->chunk_read(df, &length);
@ -953,7 +953,7 @@ br_datafile* DfOpen(char* name, int write, br_token scalar_type) {
char c;
br_datafile* df;
void* h;
LOG_TRACE("(\"%s\", %d, %d)", name, write, scalar_type);
LOG_TRACE9("(\"%s\", %d, %d)", name, write, scalar_type);
if (write) {
h = BrFileOpenWrite(name, fw.open_mode);
@ -981,7 +981,6 @@ br_datafile* DfOpen(char* name, int write, br_token scalar_type) {
else
df->prims = &_BrFilePrimsReadText;
}
LOG_DEBUG("pushing %p", df);
DfPush(BR_MEMORY_FILE, df, 1);
return df;
}

View File

@ -20,7 +20,7 @@ void* BrMemAllocate(br_size_t size, br_uint_8 type) {
// Offset: 177
// Size: 106
void BrMemFree(void* block) {
LOG_TRACE("(%p)", block);
LOG_TRACE10("(%p)", block);
fw.mem->free(block);
}

View File

@ -36,7 +36,7 @@ void* BrResAllocate(void* vparent, br_size_t size, br_uint_8 res_class) {
br_int_32 calign;
br_int_32 pad;
br_int_32 actual_pad;
LOG_TRACE("(%p, %d, %d)", vparent, size, res_class);
LOG_TRACE10("(%p, %d, %d)", vparent, size, res_class);
char* tmp;
@ -82,7 +82,7 @@ void* BrResAllocate(void* vparent, br_size_t size, br_uint_8 res_class) {
void BrResInternalFree(resource_header* res, br_boolean callback) {
int c;
void* r;
LOG_TRACE("(%p, %d)", res, callback);
LOG_TRACE10("(%p, %d)", res, callback);
if (res->magic_num != 0xDEADBEEF) {
LOG_PANIC("Bad resource header")
@ -112,7 +112,7 @@ void BrResInternalFree(resource_header* res, br_boolean callback) {
// Offset: 1148
// Size: 79
void BrResFree(void* vres) {
LOG_TRACE("(%p)", vres);
LOG_TRACE10("(%p)", vres);
vres = vres - sizeof(resource_header);
if (((resource_header*)vres)->magic_num != 0xDEADBEEF) {

View File

@ -26,7 +26,7 @@ br_pixelmap* BrPixelmapAllocateSub(br_pixelmap* src, br_int_32 x, br_int_32 y, b
// Offset: 144
// Size: 98
void BrPixelmapFree(br_pixelmap* src) {
LOG_TRACE("(%p)", src);
LOG_TRACE10("(%p)", src);
_M_br_device_pixelmap_mem_free((br_device_pixelmap*)src);
}

View File

@ -119,8 +119,7 @@ void BrStdioPutChar(int c, void* f) {
// Size: 53
br_size_t BrStdioRead(void* buf, br_size_t size, unsigned int n, void* f) {
int i;
LOG_TRACE("(%p, %d, %d, %p)", buf, size, n, f);
LOG_DEBUG("file pos: %d", ftell(f));
LOG_TRACE9("(%p, %d, %d, %p)", buf, size, n, f);
i = fread(buf, size, n, f);
return i;
}

View File

@ -14,7 +14,31 @@
#include <unistd.h>
int gFlic_bunch8[16];
int gFlic_bunch4[22];
int gFlic_bunch4[22] = {
80,
81,
82,
83,
84,
85,
42,
43,
88,
45,
110,
111,
42,
43,
45,
115,
116,
117,
118,
119,
120,
121
};
int gFlic_bunch2[8];
tFlic_spec gMain_flic_list[372] = {
@ -368,7 +392,7 @@ tFlic_descriptor gPanel_flic[2];
br_pixelmap* gPanel_buffer[2];
int gPanel_flic_left[2];
int gFlic_bunch6[51];
int gFlic_bunch7[7];
int gFlic_bunch7[7] = { 130, 131, 132, 42, 43, 135, 45 };
int gFlic_bunch5[5];
int gFlic_bunch3[13];
int gFlic_bunch0[29] = {
@ -517,13 +541,13 @@ int FlicsPlayedFromDisk() {
// Offset: 600
// Size: 44
void TurnOffPanelFlics() {
NOT_IMPLEMENTED();
gPanel_flic_disable = 1;
}
// Offset: 644
// Size: 44
void TurnOnPanelFlics() {
NOT_IMPLEMENTED();
gPanel_flic_disable = 0;
}
// Offset: 688
@ -804,7 +828,7 @@ void DoDeltaTrans(tFlic_descriptor* pFlic_info, tU32 chunk_length) {
tU32 the_row_bytes;
tU16* line_pixel_ptr;
tU16 the_word;
LOG_TRACE("(%p, %d)", pFlic_info, chunk_length);
LOG_TRACE8("(%p, %d)", pFlic_info, chunk_length);
line_count = MemReadU16(&pFlic_info->data);
the_row_bytes = pFlic_info->the_pixelmap->row_bytes;
@ -828,14 +852,18 @@ void DoDeltaTrans(tFlic_descriptor* pFlic_info, tU32 chunk_length) {
the_byte2 = the_word >> 8 & 0xff;
for (k = 0; k < -size_count; k++) {
*line_pixel_ptr = the_word;
if (the_word) {
*line_pixel_ptr = the_word;
}
line_pixel_ptr++;
}
} else {
for (k = 0; k < size_count; k++) {
the_word = *(tU16*)pFlic_info->data;
pFlic_info->data += 2;
*line_pixel_ptr = the_word;
if (the_word) {
*line_pixel_ptr = the_word;
}
line_pixel_ptr++;
}
}
@ -972,7 +1000,7 @@ void DoRunLengthTrans(tFlic_descriptor* pFlic_info, tU32 chunk_length) {
tU8* line_pixel_ptr;
tU8 the_byte;
tU32 the_row_bytes;
LOG_TRACE("(%p, %d)", pFlic_info, chunk_length);
LOG_TRACE8("(%p, %d)", pFlic_info, chunk_length);
the_row_bytes = pFlic_info->the_pixelmap->row_bytes;
pixel_ptr = pFlic_info->first_pixel;
@ -984,19 +1012,20 @@ void DoRunLengthTrans(tFlic_descriptor* pFlic_info, tU32 chunk_length) {
size_count = MemReadS8(&pFlic_info->data);
if (size_count >= 0) {
the_byte = MemReadU8(&pFlic_info->data);
if (the_byte) {
for (k = 0; k < size_count; k++) {
for (k = 0; k < size_count; k++) {
if (the_byte) {
*line_pixel_ptr = the_byte;
line_pixel_ptr++;
}
line_pixel_ptr++;
}
} else {
for (k = 0; k < -size_count; k++) {
the_byte = MemReadU8(&pFlic_info->data);
if (the_byte) {
*line_pixel_ptr = the_byte;
line_pixel_ptr++;
}
line_pixel_ptr++;
}
}
}
@ -1303,7 +1332,11 @@ int LoadFlic(int pIndex) {
// Size: 75
// EAX: pIndex
void UnlockFlic(int pIndex) {
NOT_IMPLEMENTED();
if (pIndex >= 0) {
if (gMain_flic_list[pIndex].data_ptr) {
MAMSUnlock((void**)&gMain_flic_list[pIndex].data_ptr);
}
}
}
// Offset: 7564
@ -1371,6 +1404,8 @@ void RunFlic(int pIndex) {
// EAX: pBunch_index
void PreloadBunchOfFlics(int pBunch_index) {
int i;
LOG_TRACE("(%d)", pBunch_index);
for (i = 0; i < gFlic_bunch[pBunch_index].count; i++) {
LoadFlic(gFlic_bunch[pBunch_index].indexes[i]);
}
@ -1381,7 +1416,13 @@ void PreloadBunchOfFlics(int pBunch_index) {
// EAX: pBunch_index
void UnlockBunchOfFlics(int pBunch_index) {
int i;
NOT_IMPLEMENTED();
for (i = 0; i < gFlic_bunch[pBunch_index].count; i++) {
if (gFlic_bunch[pBunch_index].indexes[i] >= 0) {
if (gMain_flic_list[gFlic_bunch[pBunch_index].indexes[i]].data_ptr) {
MAMSUnlock((void**)&gMain_flic_list[gFlic_bunch[pBunch_index].indexes[i]].data_ptr);
}
}
}
}
// Offset: 8420
@ -1456,8 +1497,47 @@ void ProcessFlicQueue(tU32 pInterval) {
// Offset: 8860
// Size: 138
void FlushFlicQueue() {
tFlic_descriptor* the_flic;
tFlic_descriptor* old_flic;
NOT_IMPLEMENTED();
LOG_TRACE("()");
// JeffH: loop through pending flics until we reach the end or we find one that is `must_finish`.
// If `must_finish`, we process the queue then check again.
// If there are no `must_finish` in the list,
while (gFirst_flic) {
the_flic = gFirst_flic;
while (!the_flic->must_finish) {
the_flic = the_flic->next;
if (!the_flic) {
break;
}
}
if (the_flic) {
RemoveTransientBitmaps(1);
ProcessFlicQueue(gFrame_period);
DoMouseCursor();
PDScreenBufferSwap(0);
} else {
break;
}
}
the_flic = gFirst_flic;
while (the_flic) {
if (the_flic->f) {
BrMemFree(the_flic->data_start);
the_flic->data_start = NULL;
fclose(the_flic->f);
the_flic->f = NULL;
}
if (the_flic->data) {
the_flic->data = NULL;
}
old_flic = the_flic;
the_flic = the_flic->next;
BrMemFree(old_flic);
}
gFirst_flic = NULL;
}
// Offset: 9000

View File

@ -1181,7 +1181,7 @@ void StartMouseCursor() {
// Offset: 27836
// Size: 59
void EndMouseCursor() {
NOT_IMPLEMENTED();
STUB();
}
// Offset: 27896

View File

@ -673,7 +673,28 @@ void LoadInterfaceStuff(int pWithin_race) {
// Offset: 6108
// Size: 272
void UnlockInterfaceStuff() {
NOT_IMPLEMENTED();
int i;
LOG_TRACE("()");
for (i = 0; i < 4; i++) {
if (gCursors[i]) {
BrPixelmapFree(gCursors[i]);
gCursors[i] = NULL;
}
}
PossibleService();
for (i = 0; i < 4; i++) {
if (gCursors[i + 4]) {
BrPixelmapFree(gCursors[i + 4]);
gCursors[i + 4] = NULL;
}
}
PossibleService();
for (i = 0; i < 18; i++) {
if (gCursor_giblet_images[i]) {
BrPixelmapFree(gCursor_giblet_images[i]);
gCursor_giblet_images[i] = NULL;
}
}
}
// Offset: 6380

View File

@ -1,4 +1,5 @@
#include "mainmenu.h"
#include "brender.h"
#include "controls.h"
#include "flicplay.h"
#include "globvars.h"
@ -10,6 +11,10 @@
#include "network.h"
#include "newgame.h"
#include "options.h"
#include "pc-dos/dossys.h"
#include "sound.h"
#include "structur.h"
#include "utility.h"
#include <stdlib.h>
char* gPalette_copy;
@ -36,7 +41,29 @@ int MainMenuDone1(int pCurrent_choice, int pCurrent_mode, int pGo_ahead, int pEs
// EBX: pGo_ahead
// ECX: pEscaped
int MainMenuDone2(int pCurrent_choice, int pCurrent_mode, int pGo_ahead, int pEscaped, int pTimed_out) {
NOT_IMPLEMENTED();
LOG_TRACE("(%d, %d, %d, %d, %d)", pCurrent_choice, pCurrent_mode, pGo_ahead, pEscaped, pTimed_out);
if (pTimed_out) {
return -1;
}
switch (pCurrent_choice) {
case 0:
PreloadBunchOfFlics(4);
break;
case 1:
PreloadBunchOfFlics(5);
break;
case 2:
PreloadBunchOfFlics(1);
break;
case 3:
PreloadBunchOfFlics(3);
break;
case 4:
PreloadBunchOfFlics(7);
break;
}
return pCurrent_choice;
}
// Offset: 360
@ -331,7 +358,12 @@ tMM_result GetMainMenuOption(tU32 pTime_out, int pContinue_allowed) {
// Offset: 1324
// Size: 169
void QuitVerifyStart() {
NOT_IMPLEMENTED();
gPixel_buffer_size = gBack_screen->height * gBack_screen->row_bytes;
gPixels_copy = BrMemAllocate(gPixel_buffer_size, kMem_quit_vfy_pixels);
gPalette_copy = BrMemAllocate(0x400u, kMem_quit_vfy_pal);
memcpy(gPixels_copy, gBack_screen->pixels, gPixel_buffer_size);
memcpy(gPalette_copy, gCurrent_palette_pixels, 0x400u);
FadePaletteDown();
}
// Offset: 1496
@ -341,22 +373,135 @@ void QuitVerifyStart() {
// EBX: pGo_ahead
// ECX: pEscaped
int QuitVerifyDone(int pCurrent_choice, int pCurrent_mode, int pGo_ahead, int pEscaped, int pTimed_out) {
NOT_IMPLEMENTED();
FadePaletteDown();
TurnOnPanelFlics();
if (gMouse_was_started) {
RemoveTransientBitmaps(1);
}
if (gReplace_background) {
if (pCurrent_choice) {
memcpy(gBack_screen->pixels, gPixels_copy, gPixel_buffer_size);
memcpy(gCurrent_palette_pixels, gPalette_copy, 0x400u);
} else {
ClearEntireScreen();
}
PDScreenBufferSwap(0);
FadePaletteUp();
}
BrMemFree(gPixels_copy);
BrMemFree(gPalette_copy);
return pCurrent_choice == 0;
}
// Offset: 1716
// Size: 333
// EAX: pReplace_background
int DoVerifyQuit(int pReplace_background) {
static tFlicette flicker_on[2];
static tFlicette flicker_off[2];
static tFlicette push[2];
static tMouse_area mouse_areas[2];
static tInterface_spec interface_spec;
static tFlicette flicker_on[2] = { { 43, { 181, 362 }, { 124, 298 } }, { 43, { 84, 168 }, { 124, 298 } } };
static tFlicette flicker_off[2] = { { 42, { 181, 362 }, { 124, 298 } }, { 42, { 84, 168 }, { 124, 298 } } };
static tFlicette push[2] = { { 135, { 181, 362 }, { 124, 298 } }, { 45, { 84, 168 }, { 124, 298 } } };
static tMouse_area mouse_areas[2] = {
{ { 181, 362 }, { 124, 298 }, { 244, 488 }, { 144, 346 }, 0, 0, 0, NULL },
{ { 84, 168 }, { 124, 298 }, { 147, 294 }, { 144, 346 }, 1, 0, 0, NULL }
};
static tInterface_spec interface_spec = {
0, // initial_imode
0, // first_opening_flic
0, // second_opening_flic
0, // end_flic_go_ahead
0, // end_flic_escaped
0, // end_flic_otherwise
0, // flic_bunch_to_load
{ 0xFFFFFFFF, 0 }, // move_left_new_mode
{ 0xFFFFFFFF, 0 }, // move_left_delta
{ 0, 0 }, // move_left_min
{ 1, 0 }, // move_left_max
{ NULL, NULL }, // move_left_proc
{ 0xFFFFFFFF, 0 }, // move_right_new_mode
{ 1, 0 }, // move_right_delta
{ 0, 0 }, // move_right_min
{ 1, 0 }, // move_right_max
{ NULL, NULL }, // move_right_proc
{ 0xFFFFFFFF, 0 }, // move_up_new_mode
{ 0, 0 }, // move_up_delta
{ 0, 0 }, // move_up_min
{ 0, 0 }, // move_up_max
{ NULL, NULL }, // move_up_proc
{ 0xFFFFFFFF, 0 }, // move_down_new_mode
{ 0, 0 }, // move_down_delta
{ 0, 0 }, // move_down_min
{ 0, 0 }, // move_down_max
{ NULL, NULL }, // move_down_proc
{ 1, 1 }, // go_ahead_allowed
{ NULL, NULL }, // go_ahead_proc
{ 1, 1 }, // escape_allowed
{ NULL, NULL }, // escape_proc
NULL, // exit_proc
NULL, // draw_proc
0u, // time_out
QuitVerifyStart, // start_proc1
NULL, // start_proc2
QuitVerifyDone, // done_proc
0, // font_needed
{ 0, 0 }, // typeable
NULL, // get_original_string
1, // escape_code
1, // dont_save_or_load
2, // number_of_button_flics
flicker_on, // flicker_on_flics
flicker_off, // flicker_off_flics
push, // pushed_flics
2, // number_of_mouse_areas
mouse_areas, // mouse_areas
0, // number_of_recopy_areas
NULL // recopy_areas
};
int result;
int switched_res;
int woz_in_race;
NOT_IMPLEMENTED();
if (gAusterity_mode) {
return 1;
}
if (gProgram_state.racing) {
FadePaletteDown();
ClearEntireScreen();
GoingToInterfaceFromRace();
woz_in_race = 1;
gProgram_state.racing = 0;
}
result = IRandomBetween(1, 3);
switch (result) {
case 1:
interface_spec.first_opening_flic = 130;
break;
case 2:
interface_spec.first_opening_flic = 131;
break;
case 3:
interface_spec.first_opening_flic = 132;
break;
}
gMouse_was_started = gMouse_started;
if (gMouse_started) {
RemoveTransientBitmaps(1);
EndMouseCursor();
}
TurnOffPanelFlics();
gReplace_background = pReplace_background;
DRS3StopOutletSound(gIndexed_outlets[0]);
LoadInterfaceStuff(woz_in_race);
result = DoInterfaceScreen(&interface_spec, 0, 0);
if (gMouse_was_started) {
LoadInterfaceStuff(woz_in_race);
StartMouseCursor();
}
if (woz_in_race) {
GoingBackToRaceFromInterface();
gProgram_state.racing = 1;
}
return result;
}
// Offset: 2052

View File

@ -95,7 +95,11 @@ void TotalRepair() {
// Offset: 2344
// Size: 64
void DoLogos() {
NOT_IMPLEMENTED();
ClearEntireScreen();
DoSCILogo();
DoOpeningAnimation();
DoSCILogo();
gProgram_state.prog_status = eProg_opening;
}
// Offset: 2408

View File

@ -144,7 +144,8 @@ void EncodeLine(char* pS) {
int IRandomBetween(int pA, int pB) {
int num;
char s[32];
NOT_IMPLEMENTED();
num = (rand() % (pB - pA + 1)) + pA;
return num;
}
// Offset: 816

View File

@ -10,12 +10,16 @@ int _argc;
char** _argv;
int game_thread_func(void* args) {
return original_main(_argc, _argv);
int exit_code;
exit_code = original_main(_argc, _argv);
// TODO: maybe we should be kinder here and post a message to the window thread to shutdown cleanly.
exit(exit_code);
}
int main(int argc, char* argv[]) {
_argc = argc;
_argv = argv;
int result;
Harness_Init(argv[0], &OpenGLRenderer);
@ -24,8 +28,9 @@ int main(int argc, char* argv[]) {
LOG_PANIC("DETHRACE_ROOT_DIR is not set");
}
printf("DETHRACE_ROOT_DIR: %s\n", root_dir);
if (chdir(root_dir) != 0) {
LOG_PANIC("Failed to chdir(%s)", root_dir);
result = chdir(root_dir);
if (result != 0) {
LOG_PANIC("Failed to chdir. Returned %d", result);
}
Harness_RunWindowLoop(&game_thread_func, NULL);

View File

@ -25,7 +25,9 @@ GLuint screen_texture;
GLuint shader_program;
int Harness_GLRenderer_GetWindowFlags() {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE) != 0) {
LOG_PANIC("Failed to set SDL_GL_CONTEXT_PROFILE_MASK attribute. %s", SDL_GetError());
};
return SDL_WINDOW_OPENGL;
}
@ -33,7 +35,7 @@ void Harness_GLRenderer_Init(SDL_Window* window) {
context = SDL_GL_CreateContext(window);
if (!context) {
LOG_PANIC("Failed to create context");
LOG_PANIC("Failed to call SDL_GL_CreateContext. %s", SDL_GetError());
}
}
@ -52,7 +54,10 @@ void CompileShader(GLuint shader_id, const GLchar* source) {
void Harness_GLRenderer_Activate(SDL_Window* window) {
GLuint vs, fs;
SDL_GL_MakeCurrent(window, context);
int result = SDL_GL_MakeCurrent(window, context);
if (result != 0) {
LOG_PANIC("Failed to call SDL_GL_MakeCurrent. %s", SDL_GetError());
}
const char* vs_source = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"

View File

@ -88,6 +88,12 @@ void test_utility_getMiscString() {
// printf("%s\n", GetMiscString(75));
}
void test_utility_IRandomBetween() {
IRandomBetween(1, 5);
IRandomBetween(0, 5);
IRandomBetween(50, 100);
}
void test_utility_suite() {
RUN_TEST(test_utility_EncodeLinex);
RUN_TEST(test_utility_DecodeLine2);
@ -96,4 +102,5 @@ void test_utility_suite() {
RUN_TEST(test_utility_GetALineWithNoPossibleService);
RUN_TEST(test_utility_PathCat);
RUN_TEST(test_utility_getMiscString);
RUN_TEST(test_utility_IRandomBetween);
}

View File

@ -1,9 +1,5 @@
#!/usr/bin/env python3 -u
# Used to discover the key referenced in `KeyIsDown` calls.
# Input: keymap index
# Output: keycode index
import sys
input = sys.argv[1]

View File

@ -1,48 +0,0 @@
#!/usr/bin/env python3 -u
f = open("struct_decl", 'r')
f2 = open("struct_def", 'r')
line = f.readline()
line2 = f2.readline()
print(line, end='')
while True:
line = f.readline()
line2 = f2.readline()
if line == '':
print('error, didnt see end of struct')
break
if line2 == '':
print('error, files should have same number of lines')
break
if '};' in line:
print(line)
break
line = line.rstrip()
line2 = line2.strip()
comment_index = line.find('//')
if comment_index > 0:
line = line[:comment_index]
parts = line2.split(' ')
name = parts[1]
array_index = name.find('[')
if array_index > 0:
name = name[0: array_index]
if name.startswith('(*'):
name = name[2:]
paren_index = name.find(')')
if paren_index > 0:
name = name[0:paren_index]
if ';' in name:
name = name[:-1]
print(line, '\t\t//', name)

72
tools/comment_struct_var.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env python3 -u
# Used to comment each line of a struct variable with the name of the associated field.
# For example:
# tInterface_spec s = {
# 0, // initial_imode
# 0, // first_opening_flic
# };
#
# Usage:
# `tools/comment_struct_var.py 'tInterface_spec s = {
# 0,
# 0,
# };`
import sys
struct_var = sys.argv[1]
lines = struct_var.split('\n')
var_header = lines[0]
tokens = var_header.split(' ')
struct_name = tokens[0]
f = open("src/DETHRACE/dr_types.h", 'r')
match_line = 'typedef struct {0} {{'.format(struct_name)
found = False
while True:
l = f.readline()
if l == "":
break
if l.strip() == match_line:
found = True
break
if found == False:
print('Couldnt find struct in dr_types.h. Looking for', match_line)
sys.exit(1)
print(var_header.strip())
for i in range(1, len(lines)):
var_line = lines[i]
def_line = f.readline().strip()
if '};' in var_line:
print(var_line)
break
# comment_index = line.find('//')
# if comment_index > 0:
# line = line[:comment_index]
parts = def_line.split(' ')
name = parts[1]
array_index = name.find('[')
if array_index > 0:
name = name[0: array_index]
if name.startswith('(*'):
name = name[2:]
paren_index = name.find(')')
if paren_index > 0:
name = name[0:paren_index]
if ';' in name:
name = name[:-1]
print(var_line, '\t\t//', name)