Reading multiple directories in transcript browser
This commit is contained in:
142
build_file.cpp
142
build_file.cpp
@@ -4,86 +4,46 @@ int main() {
|
|||||||
MA_InitScratch();
|
MA_InitScratch();
|
||||||
SRC_InitCache(Perm, "pdf_browser.cache");
|
SRC_InitCache(Perm, "pdf_browser.cache");
|
||||||
|
|
||||||
Array<S8_String> zlibfiles = {};
|
Array<S8_String> zlib_source = {};
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/adler32.c");
|
zlib_source.add("../src/external/zlib-1.3.1/adler32.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/compress.c");
|
zlib_source.add("../src/external/zlib-1.3.1/compress.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/crc32.c");
|
zlib_source.add("../src/external/zlib-1.3.1/crc32.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/deflate.c");
|
zlib_source.add("../src/external/zlib-1.3.1/deflate.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/gzclose.c");
|
zlib_source.add("../src/external/zlib-1.3.1/gzclose.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/gzlib.c");
|
zlib_source.add("../src/external/zlib-1.3.1/gzlib.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/gzread.c");
|
zlib_source.add("../src/external/zlib-1.3.1/gzread.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/gzwrite.c");
|
zlib_source.add("../src/external/zlib-1.3.1/gzwrite.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/inflate.c");
|
zlib_source.add("../src/external/zlib-1.3.1/inflate.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/infback.c");
|
zlib_source.add("../src/external/zlib-1.3.1/infback.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/inftrees.c");
|
zlib_source.add("../src/external/zlib-1.3.1/inftrees.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/inffast.c");
|
zlib_source.add("../src/external/zlib-1.3.1/inffast.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/trees.c");
|
zlib_source.add("../src/external/zlib-1.3.1/trees.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/uncompr.c");
|
zlib_source.add("../src/external/zlib-1.3.1/uncompr.c");
|
||||||
zlibfiles.add("../src/external/zlib-1.3.1/zutil.c");
|
zlib_source.add("../src/external/zlib-1.3.1/zutil.c");
|
||||||
|
|
||||||
S8_String zlibinc = "../src/external/zlib-1.3.1/";
|
S8_String zlib_include = "../src/external/zlib-1.3.1/";
|
||||||
Array<S8_String> zlibobj = {};
|
Array<S8_String> zlib_objects = {};
|
||||||
zlibobj.add("adler32.obj");
|
zlib_objects.add("adler32.obj");
|
||||||
zlibobj.add("compress.obj");
|
zlib_objects.add("compress.obj");
|
||||||
zlibobj.add("crc32.obj");
|
zlib_objects.add("crc32.obj");
|
||||||
zlibobj.add("deflate.obj");
|
zlib_objects.add("deflate.obj");
|
||||||
zlibobj.add("gzclose.obj");
|
zlib_objects.add("gzclose.obj");
|
||||||
zlibobj.add("gzlib.obj");
|
zlib_objects.add("gzlib.obj");
|
||||||
zlibobj.add("gzread.obj");
|
zlib_objects.add("gzread.obj");
|
||||||
zlibobj.add("gzwrite.obj");
|
zlib_objects.add("gzwrite.obj");
|
||||||
zlibobj.add("inflate.obj");
|
zlib_objects.add("inflate.obj");
|
||||||
zlibobj.add("infback.obj");
|
zlib_objects.add("infback.obj");
|
||||||
zlibobj.add("inftrees.obj");
|
zlib_objects.add("inftrees.obj");
|
||||||
zlibobj.add("inffast.obj");
|
zlib_objects.add("inffast.obj");
|
||||||
zlibobj.add("trees.obj");
|
zlib_objects.add("trees.obj");
|
||||||
zlibobj.add("uncompr.obj");
|
zlib_objects.add("uncompr.obj");
|
||||||
zlibobj.add("zutil.obj");
|
zlib_objects.add("zutil.obj");
|
||||||
|
|
||||||
Array<S8_String> pdfiofiles = {};
|
if (!OS_FileExists(zlib_objects[0])) {
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-aes.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-array.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-common.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-content.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-crypto.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-dict.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-file.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-md5.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-object.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-page.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-rc4.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-sha256.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-stream.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-string.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-token.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/pdfio-value.c");
|
|
||||||
pdfiofiles.add("../src/external/pdfio/ttf.c");
|
|
||||||
|
|
||||||
S8_String pdfio_inc = "../src/external/pdfio";
|
|
||||||
Array<S8_String> pdfio_obj = {};
|
|
||||||
pdfio_obj.add("pdfio-aes.obj");
|
|
||||||
pdfio_obj.add("pdfio-array.obj");
|
|
||||||
pdfio_obj.add("pdfio-common.obj");
|
|
||||||
pdfio_obj.add("pdfio-content.obj");
|
|
||||||
pdfio_obj.add("pdfio-crypto.obj");
|
|
||||||
pdfio_obj.add("pdfio-dict.obj");
|
|
||||||
pdfio_obj.add("pdfio-file.obj");
|
|
||||||
pdfio_obj.add("pdfio-md5.obj");
|
|
||||||
pdfio_obj.add("pdfio-object.obj");
|
|
||||||
pdfio_obj.add("pdfio-page.obj");
|
|
||||||
pdfio_obj.add("pdfio-rc4.obj");
|
|
||||||
pdfio_obj.add("pdfio-sha256.obj");
|
|
||||||
pdfio_obj.add("pdfio-stream.obj");
|
|
||||||
pdfio_obj.add("pdfio-string.obj");
|
|
||||||
pdfio_obj.add("pdfio-token.obj");
|
|
||||||
pdfio_obj.add("pdfio-value.obj");
|
|
||||||
pdfio_obj.add("ttf.obj");
|
|
||||||
|
|
||||||
if (!OS_FileExists(zlibobj[0])) {
|
|
||||||
Array<S8_String> cmd = {};
|
Array<S8_String> cmd = {};
|
||||||
cmd.add("cl.exe -c -nologo -Zi -MP -FC ");
|
cmd.add("cl.exe -c -nologo -Zi -MP -FC ");
|
||||||
cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(zlibinc)));
|
cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(zlib_include)));
|
||||||
cmd += zlibfiles;
|
cmd += zlib_source;
|
||||||
cmd += pdfiofiles;
|
|
||||||
Run(cmd);
|
Run(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,27 +51,27 @@ int main() {
|
|||||||
|
|
||||||
if (0) {
|
if (0) {
|
||||||
Array<S8_String> cmd = {};
|
Array<S8_String> cmd = {};
|
||||||
cmd.add("cl.exe -nologo -Zi -MP -FC -Fe:pdf_browser.exe ");
|
cmd.add("cl.exe -nologo -Zi -MP -FC -Fe:pdf_browser.exe");
|
||||||
cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(zlibinc)));
|
cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(zlib_include)));
|
||||||
cmd += zlibobj;
|
cmd += zlib_objects;
|
||||||
cmd.add(S8_Format(Perm, "-I %.*s ", S8_Expand(pdfio_inc)));
|
|
||||||
cmd += pdfio_obj;
|
|
||||||
cmd += "Advapi32.lib";
|
cmd += "Advapi32.lib";
|
||||||
cmd.add("../src/pdf_browser/main.cpp");
|
cmd.add("../src/pdf_browser/main.cpp");
|
||||||
cmd.add("../src/pdf_browser/win32.cpp");
|
cmd.add("../src/pdf_browser/win32.cpp");
|
||||||
result += Run(cmd);
|
result += Run(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<S8_String> cmd = {};
|
if (1) {
|
||||||
cmd.add("cl.exe -nologo -Zi -MP -FC -Fe:transcript_browser.exe");
|
Array<S8_String> cmd = {};
|
||||||
cmd.add("-I ../src/external/raylib/include");
|
cmd.add("cl.exe -nologo -Zi -MP -FC -Fe:transcript_browser.exe");
|
||||||
cmd.add("-std:c++20");
|
cmd.add("-I ../src/external/raylib/include");
|
||||||
cmd.add("../src/transcript_browser/main.cpp");
|
cmd.add("-std:c++20");
|
||||||
cmd.add("../src/transcript_browser/win32.cpp");
|
cmd.add("../src/transcript_browser/main.cpp");
|
||||||
cmd.add("../src/external/raylib/lib/raylib.lib");
|
cmd.add("../src/transcript_browser/win32.cpp");
|
||||||
cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib");
|
cmd.add("../src/external/raylib/lib/raylib.lib");
|
||||||
cmd.add("/link /NODEFAULTLIB:LIBCMT");
|
cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib");
|
||||||
result += Run(cmd);
|
cmd.add("/link /NODEFAULTLIB:LIBCMT");
|
||||||
|
result += Run(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
OS_DeleteFile("pdf_browser.cache");
|
OS_DeleteFile("pdf_browser.cache");
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
#define BASIC_IMPL
|
#define BASIC_IMPL
|
||||||
#include "basic.h"
|
#include "basic.h"
|
||||||
|
|
||||||
#include "pdfio.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "read_pdf.cpp"
|
#include "read_pdf.cpp"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
InitScratch();
|
||||||
|
Scratch scratch;
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,3 @@
|
|||||||
struct PdfPage {
|
|
||||||
String content;
|
|
||||||
int64_t number;
|
|
||||||
};
|
|
||||||
|
|
||||||
String Merge(Allocator allocator, Array<String> list, String separator = " ") {
|
String Merge(Allocator allocator, Array<String> list, String separator = " ") {
|
||||||
int64_t char_count = 0;
|
int64_t char_count = 0;
|
||||||
For(list) char_count += it.len;
|
For(list) char_count += it.len;
|
||||||
@@ -27,52 +22,3 @@ String Merge(Allocator allocator, Array<String> list, String separator = " ") {
|
|||||||
string.data[size] = 0;
|
string.data[size] = 0;
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<PdfPage> ReadPDF(Allocator allocator, String filename) {
|
|
||||||
Scratch scratch;
|
|
||||||
char buffer[1024];
|
|
||||||
|
|
||||||
char *filename_char = NullTerminate(scratch, filename);
|
|
||||||
pdfio_file_t *file = pdfioFileOpen(filename_char, NULL, NULL, NULL, NULL);
|
|
||||||
if (file == NULL) return {};
|
|
||||||
defer { pdfioFileClose(file); };
|
|
||||||
|
|
||||||
Array<PdfPage> pages = {allocator};
|
|
||||||
for (int i = 0, num_pages = pdfioFileGetNumPages(file); i < num_pages; i++) {
|
|
||||||
pdfio_obj_t *obj = pdfioFileGetPage(file, i);
|
|
||||||
if (obj == NULL) continue;
|
|
||||||
|
|
||||||
PdfPage *page = pages.alloc();
|
|
||||||
page->number = i + 1;
|
|
||||||
|
|
||||||
Array<String> content = {scratch};
|
|
||||||
size_t num_streams = pdfioPageGetNumStreams(obj);
|
|
||||||
for (int j = 0; j < num_streams; j++) {
|
|
||||||
pdfio_stream_t *st = pdfioPageOpenStream(obj, j, true);
|
|
||||||
if (st == NULL) continue;
|
|
||||||
defer { pdfioStreamClose(st); };
|
|
||||||
|
|
||||||
bool first = true;
|
|
||||||
while (pdfioStreamGetToken(st, buffer, sizeof(buffer))) {
|
|
||||||
if (buffer[0] == '(') {
|
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
// content.add(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
content.add(Copy(scratch, buffer + 1));
|
|
||||||
} else if (!strcmp(buffer, "Td") || !strcmp(buffer, "TD") || !strcmp(buffer, "T*") || !strcmp(buffer, "\'") || !strcmp(buffer, "\"")) {
|
|
||||||
// content.add("\n");
|
|
||||||
first = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (!first) content.add("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
page->content = Merge(allocator, content, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
return pages;
|
|
||||||
}
|
|
||||||
16
src/pdf_browser/read_pdf.py
Normal file
16
src/pdf_browser/read_pdf.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import pypdf
|
||||||
|
|
||||||
|
reader = pypdf.PdfReader("C:/Users/Karol/Desktop/Hegels-Logic.pdf")
|
||||||
|
|
||||||
|
f = open("asd.txt", "w", encoding="utf-8")
|
||||||
|
for i in range(len(reader.pages)):
|
||||||
|
page = reader.pages[i]
|
||||||
|
text = page.extract_text()
|
||||||
|
text = text.replace("\n", "")
|
||||||
|
text = text.replace("-", "")
|
||||||
|
|
||||||
|
f.write(f">>>>>>>>{i + 1}<<<<<<<<<\n")
|
||||||
|
f.write(text)
|
||||||
|
f.write("\n")
|
||||||
|
|
||||||
|
f.close()
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <semaphore>
|
#include <semaphore>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
Arena Perm;
|
||||||
|
|
||||||
struct TimeString {
|
struct TimeString {
|
||||||
uint16_t hour;
|
uint16_t hour;
|
||||||
uint16_t minute;
|
uint16_t minute;
|
||||||
@@ -87,21 +89,17 @@ struct XToTimeString {
|
|||||||
uint16_t second;
|
uint16_t second;
|
||||||
String filepath;
|
String filepath;
|
||||||
};
|
};
|
||||||
|
Arena XArena;
|
||||||
|
|
||||||
Arena Perm;
|
void AddFolder(String folder, Array<String> *filenames, Array<XToTimeString> *x_to_time_string) {
|
||||||
Array<XToTimeString> XToTimeStringArray = {Perm};
|
|
||||||
bool AppInitializedWithFolder;
|
|
||||||
Arena XArena;
|
|
||||||
|
|
||||||
Array<String> InitForFolder(String folder) {
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
|
|
||||||
Array<String> filenames = {Perm};
|
|
||||||
Array<String> srt_files = {scratch};
|
Array<String> srt_files = {scratch};
|
||||||
for (FileIter iter = IterateFiles(scratch, folder); IsValid(iter); Advance(&iter)) {
|
for (FileIter iter = IterateFiles(scratch, folder); IsValid(iter); Advance(&iter)) {
|
||||||
filenames.add(Copy(Perm, iter.absolute_path));
|
String file = Copy(Perm, iter.absolute_path);
|
||||||
|
filenames->add(file);
|
||||||
if (EndsWith(iter.filename, ".srt")) {
|
if (EndsWith(iter.filename, ".srt")) {
|
||||||
srt_files.add(Copy(scratch, iter.absolute_path));
|
srt_files.add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,14 +133,11 @@ Array<String> InitForFolder(String folder) {
|
|||||||
For(it_time_file.time_strings) {
|
For(it_time_file.time_strings) {
|
||||||
String s = Copy(XArena, it.string);
|
String s = Copy(XArena, it.string);
|
||||||
s.data[s.len] = ' ';
|
s.data[s.len] = ' ';
|
||||||
XToTimeStringArray.add({s, it.hour, it.minute, it.second, it_time_file.file});
|
x_to_time_string->add({s, it.hour, it.minute, it.second, it_time_file.file});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Release(it_io.arena);
|
Release(it_io.arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppInitializedWithFolder = true;
|
|
||||||
return filenames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -204,13 +199,14 @@ int main() {
|
|||||||
Arena *frame_arena = AllocArena();
|
Arena *frame_arena = AllocArena();
|
||||||
XArena.align = 0;
|
XArena.align = 0;
|
||||||
|
|
||||||
String start_string = "C:/video";
|
String start_string = "read=D:/zizek";
|
||||||
For(start_string) Prompt.add(it);
|
For(start_string) Prompt.add(it);
|
||||||
|
|
||||||
std::thread search_thread(SearchThreadEntry);
|
std::thread search_thread(SearchThreadEntry);
|
||||||
int64_t chosen_text = 0;
|
int64_t chosen_text = 0;
|
||||||
int64_t match_search_offset = 0;
|
int64_t match_search_offset = 0;
|
||||||
Array<String> filenames = {};
|
Array<String> filenames = {};
|
||||||
|
Array<XToTimeString> x_to_time_string = {};
|
||||||
|
|
||||||
InitWindow(1920, 1080, "Transcript Browser");
|
InitWindow(1920, 1080, "Transcript Browser");
|
||||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||||
@@ -261,9 +257,10 @@ int main() {
|
|||||||
match_search_offset = Clamp(match_search_offset, (int64_t)0, Max(Matches.len - 1 - 10, (int64_t)0));
|
match_search_offset = Clamp(match_search_offset, (int64_t)0, Max(Matches.len - 1 - 10, (int64_t)0));
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_ENTER)) {
|
if (IsKeyPressed(KEY_ENTER)) {
|
||||||
if (!AppInitializedWithFolder) {
|
String prompt = {Prompt.data, Prompt.len};
|
||||||
|
if (StartsWith(prompt, "read=")) {
|
||||||
Prompt.add('\0');
|
Prompt.add('\0');
|
||||||
filenames = InitForFolder(Prompt.data);
|
AddFolder(prompt.skip(5), &filenames, &x_to_time_string);
|
||||||
Prompt.clear();
|
Prompt.clear();
|
||||||
} else if (ItemFound) {
|
} else if (ItemFound) {
|
||||||
String base = ChopLastPeriod(ItemFound->filepath); // .srt
|
String base = ChopLastPeriod(ItemFound->filepath); // .srt
|
||||||
@@ -284,7 +281,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
} else if (Matches.len) {
|
} else if (Matches.len) {
|
||||||
String string = Matches[chosen_text];
|
String string = Matches[chosen_text];
|
||||||
For(XToTimeStringArray) {
|
For(x_to_time_string) {
|
||||||
uintptr_t begin = (uintptr_t)(it.string.data);
|
uintptr_t begin = (uintptr_t)(it.string.data);
|
||||||
uintptr_t end = (uintptr_t)(it.string.data + it.string.len);
|
uintptr_t end = (uintptr_t)(it.string.data + it.string.len);
|
||||||
uintptr_t needle = (uintptr_t)string.data;
|
uintptr_t needle = (uintptr_t)string.data;
|
||||||
@@ -303,12 +300,7 @@ int main() {
|
|||||||
float y = 0;
|
float y = 0;
|
||||||
int xwidth = MeasureTextEx(font, "_", font_size, 1).x;
|
int xwidth = MeasureTextEx(font, "_", font_size, 1).x;
|
||||||
|
|
||||||
if (!AppInitializedWithFolder) {
|
if (ItemFound) {
|
||||||
Prompt.add('\0');
|
|
||||||
DrawTextEx(font, "> ", {0, y}, font_size, 1, BLACK);
|
|
||||||
DrawTextEx(font, Prompt.data, {(float)xwidth * 3, y}, font_size, 1, BLACK);
|
|
||||||
Prompt.len -= 1;
|
|
||||||
} else if (ItemFound) {
|
|
||||||
uintptr_t begin_region = (uintptr_t)XArena.data;
|
uintptr_t begin_region = (uintptr_t)XArena.data;
|
||||||
uintptr_t end_region = (uintptr_t)XArena.data + XArena.len;
|
uintptr_t end_region = (uintptr_t)XArena.data + XArena.len;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user