this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

debug debug more debug

alice e28bd1aa 9bbda6dc

+203 -7
+4 -1
CMakeLists.txt
··· 107 107 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11") 108 108 endif() 109 109 110 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0") 111 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") 112 + 110 113 set(THIRDPARTY_DIR ${CMAKE_SOURCE_DIR}/vendor) 111 114 set(DEMO_CARTS_IN ${CMAKE_SOURCE_DIR}/demos) 112 115 ··· 142 145 include(cmake/n3ds.cmake) 143 146 144 147 include(cmake/stub.cmake) 145 - include(cmake/install.cmake) 148 + include(cmake/install.cmake)
+199 -6
src/studio/screens/console.c
··· 315 315 316 316 static void scrollBuffer(char* buffer) 317 317 { 318 + printf("scrollBuffer start\n"); 319 + // Check for NULL pointer 320 + if (buffer == NULL) 321 + { 322 + printf("Error: buffer is NULL in scrollBuffer\n"); 323 + return; 324 + } 325 + 326 + // Check if memmove source and destination are within buffer bounds 327 + if (buffer + CONSOLE_BUFFER_WIDTH > buffer + CONSOLE_BUFFER_SIZE) 328 + { 329 + printf("Error: memmove source out of bounds in scrollBuffer\n"); 330 + return; 331 + } 332 + 333 + printf("scrollBuffer memmove start\n"); 318 334 memmove(buffer, buffer + CONSOLE_BUFFER_WIDTH, CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH); 335 + printf("scrollBuffer memmove end\n"); 336 + 337 + // Check if memset destination is within buffer bounds 338 + if (buffer + CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH > buffer + CONSOLE_BUFFER_SIZE) 339 + { 340 + printf("Error: memset destination out of bounds in scrollBuffer\n"); 341 + return; 342 + } 343 + 344 + printf("scrollBuffer memset start\n"); 319 345 memset(buffer + CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH, 0, CONSOLE_BUFFER_WIDTH); 346 + printf("scrollBuffer memmove end\n"); 320 347 } 321 348 349 + // static void scrollBuffer(char* buffer) 350 + // { 351 + // memmove(buffer, buffer + CONSOLE_BUFFER_WIDTH, CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH); 352 + // memset(buffer + CONSOLE_BUFFER_SIZE - CONSOLE_BUFFER_WIDTH, 0, CONSOLE_BUFFER_WIDTH); 353 + // } 354 + 355 + // static void scrollConsole(Console* console) 356 + // { 357 + // while(console->cursor.pos.y >= CONSOLE_BUFFER_HEIGHT * CONSOLE_BUFFER_SCREENS) 358 + // { 359 + // scrollBuffer(console->text); 360 + // scrollBuffer((char*)console->color); 361 + 362 + // console->cursor.pos.y--; 363 + // } 364 + 365 + // size_t inputLines = (console->cursor.pos.x + console->input.pos) / CONSOLE_BUFFER_WIDTH; 366 + // s32 minScroll = console->cursor.pos.y + inputLines - CONSOLE_BUFFER_HEIGHT + 1; 367 + // if(console->scroll.pos < minScroll) 368 + // console->scroll.pos = minScroll; 369 + // } 370 + 322 371 static void scrollConsole(Console* console) 323 372 { 373 + printf("scrollConsole start\n"); 374 + printf("Checking if console pointer is NULL...\n"); 375 + // Check for NULL pointer 376 + if (console == NULL) 377 + { 378 + printf("Error: console is NULL in scrollConsole\n"); 379 + return; 380 + } 381 + printf("Console pointer is not NULL, proceeding...\n"); 382 + printf("starting out with console->cursor.pos.y: %d\n", console->cursor.pos.y); 324 383 while(console->cursor.pos.y >= CONSOLE_BUFFER_HEIGHT * CONSOLE_BUFFER_SCREENS) 325 384 { 385 + printf("in scrollConsole\'s while loop!!!\n"); 386 + // Check for valid pointers before calling scrollBuffer 387 + if (console->text == NULL) 388 + { 389 + printf("Error: console->text is NULL in scrollConsole\n"); 390 + return; 391 + } 392 + if (console->color == NULL) 393 + { 394 + printf("Error: console->color is NULL in scrollConsole\n"); 395 + return; 396 + } 397 + 398 + printf("calling scrollBuffer with console->text: %p\n", console->text); 326 399 scrollBuffer(console->text); 400 + printf("calling scrollBuffer with console->color: %p\n", console->color); 327 401 scrollBuffer((char*)console->color); 328 402 329 403 console->cursor.pos.y--; ··· 331 405 332 406 size_t inputLines = (console->cursor.pos.x + console->input.pos) / CONSOLE_BUFFER_WIDTH; 333 407 s32 minScroll = console->cursor.pos.y + inputLines - CONSOLE_BUFFER_HEIGHT + 1; 334 - if(console->scroll.pos < minScroll) 408 + 409 + // Check for valid scroll position before updating 410 + if (console->scroll.pos < 0) 411 + { 412 + printf("Error: console->scroll.pos is negative in scrollConsole\n"); 413 + console->scroll.pos = 0; 414 + } 415 + else if(console->scroll.pos < minScroll) 416 + { 417 + printf("setting console->scroll.pos to minScroll: %d\n", minScroll); 335 418 console->scroll.pos = minScroll; 419 + } 336 420 } 337 421 338 422 static void setSymbol(Console* console, char sym, u8 color, s32 offset) ··· 384 468 { 385 469 char symbol = *ptr; 386 470 471 + printf("calling scrollConsole from consolePrintOffset\n"); 387 472 scrollConsole(console); 388 473 389 474 if (symbol == '\n') ··· 1179 1264 1180 1265 static void addTabCompleteOption(TabCompleteData* data, const char* option) 1181 1266 { 1267 + // Check for NULL pointers 1268 + if (!data || !data->options || !data->commonPrefix) { 1269 + printf("Error: NULL pointer encountered in addTabCompleteOption\n"); 1270 + return; // Early return to avoid dereferencing NULL 1271 + } 1272 + 1182 1273 if (strstr(option, data->incompleteWord) == option) 1183 1274 { 1275 + printf("Adding option: %s\n", option); // Debugging information 1184 1276 // Possibly reduce the common prefix of all possible options. 1185 1277 if (strlen(data->options) == 0) 1186 1278 { 1279 + // Ensure the option length does not exceed the buffer size. 1280 + size_t optionLength = strlen(option); 1281 + if (optionLength >= CONSOLE_BUFFER_SCREEN) { 1282 + printf("Error: option length exceeds buffer size.\n"); 1283 + return; // Early return to prevent buffer overflow 1284 + } 1285 + 1286 + // Debugging information 1287 + printf("Initializing commonPrefix with: %s\n", option); 1288 + 1187 1289 // This is the first option to be added. Initialize the prefix. 1188 - strncpy(data->commonPrefix, option, CONSOLE_BUFFER_SCREEN); 1290 + strncpy(data->commonPrefix, option, CONSOLE_BUFFER_SCREEN - 1); // Leave space for null terminator 1291 + data->commonPrefix[CONSOLE_BUFFER_SCREEN - 1] = '\0'; // Explicitly null-terminate 1189 1292 } 1190 1293 else 1191 1294 { ··· 1223 1326 1224 1327 static void finishTabComplete(const TabCompleteData* data) 1225 1328 { 1329 + printf("finishTabComplete starting\n"); 1330 + if (data == NULL) 1331 + { 1332 + printf("Error: data is NULL in finishTabComplete!! THINGS ARE FUCKED!!\n"); 1333 + return; 1334 + } 1335 + printf("Size of the data passed: %zu bytes\n", sizeof(*data)); 1336 + printf("data->options: %s\n", data->options); 1337 + printf("data->commonPrefix: %s\n", data->commonPrefix); 1338 + printf("data->incompleteWord: %s\n", data->incompleteWord); 1339 + printf("data->console: %p\n", data->console); 1226 1340 bool anyOptions = strlen(data->options) > 0; 1227 1341 if (anyOptions) { 1342 + printf("in if(anyOptions)\n"); 1228 1343 // Adding one at the right because all options end with a space. 1229 1344 bool justOneOptionLeft = strlen(data->options) == strlen(data->commonPrefix)+1; 1230 1345 ··· 1237 1352 1238 1353 if (justOneOptionLeft) 1239 1354 { 1355 + printf("in if(justOneOptionLeft)\n"); 1356 + printf("adding one space to input\n"); 1240 1357 insertInputText(data->console, " "); 1241 1358 } 1242 1359 } ··· 3322 3439 TabCompleteData data = { console, .incompleteWord = incompleteWord }; 3323 3440 data.options = malloc(CONSOLE_BUFFER_SCREEN); 3324 3441 data.commonPrefix = malloc(CONSOLE_BUFFER_SCREEN); 3442 + 3443 + // Check for malloc failure 3444 + if (!data.options || !data.commonPrefix) { 3445 + printf("OOPSIE WHOOPSIE WE MADE A FUCKSIE WUCKSIE\n"); 3446 + // Handle error, for example, by logging and exiting or by setting a default value 3447 + // For simplicity, we'll just free any successful allocation and return an empty struct 3448 + free(data.options); // Safe to call free on NULL 3449 + free(data.commonPrefix); 3450 + return (TabCompleteData){0}; // Return an empty struct or handle error appropriately 3451 + } 3452 + 3325 3453 data.options[0] = '\0'; 3326 3454 data.commonPrefix[0] = '\0'; 3327 3455 ··· 3330 3458 3331 3459 static void processConsoleTab(Console* console) 3332 3460 { 3461 + printf("_____-----!!!-----_____\n"); 3462 + printf("processConsoleTab\n"); 3463 + printf("console: %p\n", (void*)console); 3464 + if (!console) { 3465 + printf("Error: console is NULL\n"); 3466 + return; 3467 + } 3333 3468 char* input = console->input.text; 3469 + printf("input: %s\n", input ? input : "NULL"); 3470 + if (!input) { 3471 + printf("Error: input is NULL\n"); 3472 + return; 3473 + } 3334 3474 char* param = strchr(input, ' '); 3335 - 3475 + if (param == NULL) 3476 + { 3477 + printf("FUCKSIE WUCKSIE POTENTIALLY!!\n"); 3478 + printf("Error: param is NULL in processConsoleTab\n"); 3479 + return; 3480 + } 3481 + printf("param: %s\n", param ? param : "NULL"); 3482 + if (param) { 3483 + printf("param offset from input: %ld\n", param - input); 3484 + } 3485 + printf("input: %s\n", input); 3486 + printf("param: %s\n", param); 3487 + printf("internal C size of param: %zu\n", sizeof(param)); 3336 3488 if(param) 3337 3489 { 3338 3490 // Tab-complete command's parameters. 3339 - param++; 3491 + printf("we have param\n"); 3492 + if (param != NULL) { 3493 + printf("IN IF size of param: %zu\n", strlen(param)); 3494 + printf("IN IF internal C size of param: %zu\n", sizeof(param)); 3495 + param++; 3496 + if (param != NULL) { 3497 + printf("AFTER ++ param: %s\n", param); 3498 + printf("AFTER ++ size of param: %zu\n", strlen(param)); 3499 + printf("AFTER ++ internal C size of param: %zu\n", sizeof(param)); 3500 + } else { 3501 + printf("Error: param becomes NULL after increment\n"); 3502 + } 3503 + } else { 3504 + printf("Error: param is NULL\n"); 3505 + } 3506 + 3340 3507 char* secondParam = strchr(param, ' '); 3341 - if (secondParam) 3508 + if (secondParam) { 3509 + printf("we have second param\n"); 3342 3510 secondParam++; 3343 - 3511 + } 3512 + printf("Commands count: %lu\n", (unsigned long)COUNT_OF(Commands)); 3344 3513 for(s32 i = 0; i < COUNT_OF(Commands); i++) 3345 3514 { 3515 + printf("++++++ counter +++++\n"); 3516 + printf("i: %d\n", i); 3346 3517 s32 commandLen = param-input-1; 3518 + printf("commandLen: %d, Commands[i].name length: %zu, Commands[i].alt length: %zu\n", commandLen, strlen(Commands[i].name), Commands[i].alt ? strlen(Commands[i].alt) : 0); 3347 3519 bool commandMatches = (strlen(Commands[i].name) == commandLen && 3348 3520 strncmp(Commands[i].name, input, commandLen) == 0) || 3349 3521 (Commands[i].alt && ··· 3352 3524 3353 3525 if (commandMatches) 3354 3526 { 3527 + printf("in branch if commandMatches\n"); 3355 3528 if (secondParam) { 3529 + printf("secondParam: %s\n", secondParam); 3530 + printf("secondParam offset from param: %ld\n", secondParam - param); 3356 3531 if (Commands[i].tabComplete2) { 3357 3532 TabCompleteData data = newTabCompleteData(console, secondParam); 3358 3533 Commands[i].tabComplete2(&data); 3359 3534 } 3360 3535 } else { 3536 + printf("in branch if !secondParam\n"); 3537 + // printf("commandLen: %d, Commands[i].name length: %zu, Commands[i].alt length: %zu\n", commandLen, strlen(Commands[i].name), Commands[i].alt ? strlen(Commands[i].alt) : 0); 3538 + printf("Commands[i].tabComplete1: %p\n", (void*)Commands[i].tabComplete1); 3361 3539 if (Commands[i].tabComplete1) { 3540 + printf("Commands[i].tabComplete1 is not NULL\n"); 3541 + printf("calling newTabCompleteData with console: %p, param: %s\n", (void*)console, param); 3362 3542 TabCompleteData data = newTabCompleteData(console, param); 3543 + printf("TabCompleteData data is: %p\n", (void*)&data); 3363 3544 Commands[i].tabComplete1(&data); 3364 3545 } 3365 3546 } ··· 3369 3550 else 3370 3551 { 3371 3552 // Tab-complete commands. 3553 + printf("no param\n"); 3554 + printf("get tab-complete commands\n"); 3372 3555 TabCompleteData data = newTabCompleteData(console, input); 3556 + printf("TabCompleteData created with input: %s\n", input); 3557 + printf("loop thru tab complete data\n"); 3373 3558 for(s32 i = 0; i < COUNT_OF(Commands); i++) 3374 3559 { 3375 3560 addTabCompleteOption(&data, Commands[i].name); 3561 + printf("Added tab complete option for: %s\n", Commands[i].name); 3376 3562 if (Commands[i].alt) 3377 3563 addTabCompleteOption(&data, Commands[i].alt); 3378 3564 } 3379 3565 finishTabComplete(&data); 3566 + printf("Finished tab completion\n"); 3380 3567 } 3568 + printf("Scrolling console\n"); 3381 3569 scrollConsole(console); 3382 3570 } 3383 3571 ··· 3482 3670 { 3483 3671 char symbol = *textPointer++; 3484 3672 3673 + printf("calling scrollConsole from printTable\n"); 3485 3674 scrollConsole(console); 3486 3675 3487 3676 if(symbol == '\n') ··· 4156 4345 if(sym) 4157 4346 { 4158 4347 insertInputText(console, (char[]){sym, '\0'}); 4348 + printf("calling scrollConsole from processKeyboard\n"); 4159 4349 scrollConsole(console); 4160 4350 4161 4351 console->cursor.delay = CONSOLE_CURSOR_DELAY; ··· 4350 4540 { 4351 4541 if(!console->text) console->text = malloc(CONSOLE_BUFFER_SIZE); 4352 4542 if(!console->color) console->color = malloc(CONSOLE_BUFFER_SIZE); 4543 + printf("memsetting baby!\n"); 4544 + memset(console->text, 0, CONSOLE_BUFFER_SIZE); 4545 + memset(console->color, TIC_COLOR_BG, CONSOLE_BUFFER_SIZE); 4353 4546 if(!console->desc) console->desc = malloc(sizeof(CommandDesc)); 4354 4547 4355 4548 *console = (Console)