MCPcopy Create free account
hub / github.com/TheOfficialFloW/VitaShell / textViewer

Function textViewer

text.c:507–1034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505}
506
507int textViewer(const char *file) {
508 TextEditorState *s = malloc(sizeof(TextEditorState));
509 if (!s)
510 return VITASHELL_ERROR_NO_MEMORY;
511
512 char *buffer_base = memalign(4096, BIG_BUFFER_SIZE);
513 if (!buffer_base)
514 return VITASHELL_ERROR_NO_MEMORY;
515
516 s->running = 1;
517 s->hex_viewer = 0;
518 s->n_copied_lines = 0;
519 s->copy_reset = 0;
520 s->modify_allowed = 1;
521 s->offset_list[0] = 0;
522 s->count_lines_running = 0;
523 s->n_lines = 0;
524 s->search_running = 0;
525 s->edit_line = -1;
526
527 if (isInArchive()) {
528 s->size = ReadArchiveFile(file, buffer_base, BIG_BUFFER_SIZE);
529 s->modify_allowed = 0;
530 } else {
531 s->size = ReadFile(file, buffer_base, BIG_BUFFER_SIZE);
532 }
533
534 if (s->size < 0) {
535 free(buffer_base);
536 return s->size;
537 }
538
539 s->buffer = buffer_base;
540
541 int has_utf8_bom = 0;
542 char utf8_bom[3] = {0xEF, 0xBB, 0xBF};
543 if (s->size >= 3 && memcmp(buffer_base, utf8_bom, 3) == 0) {
544 s->buffer += 3;
545 has_utf8_bom = 1;
546 s->size -= 3;
547 }
548
549 if (s->size == 0) {
550 s->size = 1;
551 s->buffer[0] = '\n';
552 }
553
554 if (s->buffer[s->size - 1] != '\n') {
555 s->buffer[s->size++] = '\n';
556 }
557
558 s->base_pos = 0;
559 s->rel_pos = 0;
560 s->n_selections = 0;
561 memset(&s->list, 0, sizeof(TextList));
562
563 // Init context menu param
564 context_menu_text.context = s;

Callers 3

hexViewerFunction · 0.85
handleFileFunction · 0.85
fileBrowserHandleSymlinkFunction · 0.85

Calls 15

isInArchiveFunction · 0.85
ReadArchiveFileFunction · 0.85
ReadFileFunction · 0.85
textReadLineFunction · 0.85
textListAddEntryFunction · 0.85
readPadFunction · 0.85
isImeDialogRunningFunction · 0.85
isMessageDialogRunningFunction · 0.85
getContextMenuModeFunction · 0.85
contextMenuCtrlFunction · 0.85
setContextMenuFunction · 0.85

Tested by

no test coverage detected