Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9863f58
Added support for java and python. Also adds capability for adding ot…
vinays6 Feb 13, 2023
d25d562
highlighting for different programming languages (refactored)
alex-s168 Nov 20, 2023
120fd3f
Merge branch 'master' of https://github.com/SuperCraftAlex/ded
alex-s168 Nov 20, 2023
a8ef42d
fix win build
Apr 3, 2024
fcf1472
fix
Apr 3, 2024
96fa2c9
file create
Apr 3, 2024
7729423
Only commit successful directory changes
juniorrantila Mar 3, 2024
1571358
fullscreen
Apr 3, 2024
606daec
Add the ability to delete entire selection area, and disable editor.s…
austinoxyz Mar 13, 2023
8c3474f
pop ups
Apr 3, 2024
acf712a
ctrl+x, more warning stuff, search stuff
Apr 3, 2024
ea034a7
more stuff
Apr 3, 2024
e73c1cc
more stuff
Apr 3, 2024
f3d21ac
fix type_of_file, fix shader load ~joshuang321; other stuff
Apr 3, 2024
a446519
more status bar stuff
Apr 3, 2024
e09621d
auto convert tabs to 4 spaces when load and append new line at save
alex-s168 Apr 3, 2024
c985cdd
fix indenting
alex-s168 Apr 3, 2024
02d0c06
ded fucked up end of file for some reason
alex-s168 Apr 3, 2024
8e9ddca
use better colors for bottom bar and fix segfault when saving empty file
Apr 4, 2024
e89add0
fix some file loading shit
Apr 4, 2024
51768ef
"fix" file writing
Apr 4, 2024
db27eea
ctrl+g = goto line(:col)
Apr 4, 2024
90b7377
fix building and add miniconf
alex-s168 Apr 4, 2024
bb6f5a8
Merge remote-tracking branch 'origin/master'
alex-s168 Apr 4, 2024
3f91efb
fix file write and read?
Apr 5, 2024
8f6d65f
add minifmt; update miniconf; other small changes
alex-s168 Apr 5, 2024
14d625a
config window, pop up, pop ups, input hints
alex-s168 Apr 5, 2024
7154eee
config editor/background, editor/bottom bar
alex-s168 Apr 5, 2024
4f5e38f
config editor/tokens
alex-s168 Apr 5, 2024
4fc1d9a
config done
alex-s168 Apr 5, 2024
7652d96
use minilibs instead of miniconf and minifmt
alex-s168 Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "dependencies/minirent"]
path = dependencies/minirent
url = https://github.com/alex-s168/minirent.git
[submodule "dependencies/freetype"]
path = dependencies/freetype
url = https://github.com/ubawurinna/freetype-windows-binaries.git
[submodule "dependencies/minilibs"]
path = dependencies/minilibs
url = https://github.com/alex-s168/minilibs.git
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Quick Start

## Dependencies
(Automatically downloaded on Windows)

- [SDL2 2.0.9+](https://www.libsdl.org/)
- [FreeType 2.13.0+](https://freetype.org/)
Expand All @@ -18,10 +19,20 @@ $ ./ded src/main.c
```

## Windows MSVC

In any PowerShell or CMD console
```console
> .\setup_dependencies.bat
```
In a bash console
```console
$ ./setup_other.sh
```
In a MSVC console (VS developer x64 prompt)
```console
> .\build_msvc.bat
```
Then
```console
> .\ded.exe src\main.c
```

Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ set -xe

CC="${CXX:-cc}"
PKGS="sdl2 glew freetype2"
CFLAGS="-Wall -Wextra -std=c11 -pedantic -ggdb"
CFLAGS="-std=c11 -pedantic -ggdb -Idependencies/minilibs -Idependencies/minirent"
LIBS=-lm
SRC="src/main.c src/la.c src/editor.c src/file_browser.c src/free_glyph.c src/simple_renderer.c src/common.c src/lexer.c"

if [ `uname` = "Darwin" ]; then
CFLAGS+=" -framework OpenGL"
fi

$CC $CFLAGS `pkg-config --cflags $PKGS` -o ded $SRC $LIBS `pkg-config --libs $PKGS`
$CC $CFLAGS `pkg-config --cflags $PKGS` -g -o ded $SRC $LIBS `pkg-config --libs $PKGS`
8 changes: 5 additions & 3 deletions build_msvc.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
@echo off
rem launch this from msvc-enabled console

set CFLAGS=/W4 /WX /std:c11 /wd4996 /wd5105 /FC /TC /Zi /nologo
set INCLUDES=/I dependencies\SDL2\include /I dependencies\GLFW\include /I dependencies\GLEW\include
set CFLAGS=/W4 /std:c11 /wd4996 /wd5105 /FC /TC /Zi /nologo
set INCLUDES=/I dependencies\SDL2\include /I dependencies\freetype\include /I dependencies\minirent /I dependencies\GLFW\include /I dependencies\GLEW\include /I dependencies\minilibs

set LIBS=dependencies\SDL2\lib\x64\SDL2.lib ^
dependencies\SDL2\lib\x64\SDL2main.lib ^
dependencies\GLFW\lib\glfw3.lib ^
dependencies\GLEW\lib\glew32s.lib ^
"dependencies\freetype\release static\vs2015-2022\win64\freetype.lib" ^
opengl32.lib User32.lib Gdi32.lib Shell32.lib

cl.exe %CFLAGS% %INCLUDES% /Feded src\main.c src\la.c src\editor.c src\file_browser.c src\free_glyph.c src\simple_renderer.c src\common.c /link %LIBS% -SUBSYSTEM:windows
cl.exe %CFLAGS% %INCLUDES% /Feded src\main.c src\la.c src\editor.c src\file_browser.c src\free_glyph.c src\simple_renderer.c src\common.c src\lexer.c /link %LIBS% -SUBSYSTEM:windows
4 changes: 2 additions & 2 deletions build_msys2_mingw64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -xe

PKGS="--static sdl2 glew freetype2"
CFLAGS="-Wall -Wextra -pedantic -ggdb -DGLEW_STATIC `pkg-config --cflags $PKGS` -Isrc -Dassert(expression)=((void)0) "
CFLAGS="-Wall -Wextra -pedantic -ggdb -DGLEW_STATIC `pkg-config --cflags $PKGS` -Isrc -Idependencies/minilibs -Idependencies/minirent -Dassert(expression)=((void)0) "
LIBS="-lm -lopengl32 `pkg-config --libs $PKGS`"
SRC="src/main.c src/la.c src/editor.c src/file_browser.c src/free_glyph.c src/simple_renderer.c src/common.c"
SRC="src/main.c src/la.c src/editor.c src/file_browser.c src/free_glyph.c src/simple_renderer.c src/common.c src/lexer.c"
OBJ=$(echo "$SRC" | sed "s/\.c/\.o/g")
OBJ=$(echo "$OBJ" | sed "s/src\// /g")

Expand Down
72 changes: 72 additions & 0 deletions ded.miniconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
window:
font: "./fonts/iosevka-regular.ttf
title: "ded
x: 100
y: 100
w: 800
h: 600

pop up:
scale: 0.6
fade in: 300

pop ups:
save ok:
str: "Saved file!
color: x009966FF
last: 1000
invalid goto:
str: "Invalid line(:col)
color: xFF2400FF
last: 2000
can not cd:
str: "Can't change directory to "{path}"!
color: xFF2400FF
last: 2000
can not open:
str: "Can't open file "{path}"!
color: xFF2400FF
last: 2000
can not save:
str: "Can't save file: {err}!
color: xFF2400FF
last: 2000

input hints:
find: "find
save as: "path
save: "path
goto: "line

editor:
background: x181818FF
color: xFFFFFFFF
bottom bar:
scale: 0.6
background: xE7E7E7FF
input:
hint:
color: x5B5B5BFF
fmt: "({hint})
spacing: 20.0
content:
color: x181818FF
stats:
enabled: true
fmt: "{lang} {row}:{col} / {max-row}
color: x181818FF
tokens:
preprocessor directive: x95A99FFF
keyword: xFFDD33FF
comment: xCC8C3CFF
string: x73C936FF
cursor:
blink:
treshold: 500
period: 1000
color: xFFFFFFFF
width: 5.0
selection:
color: x434343FF
search selection:
color: x191943FF
72 changes: 72 additions & 0 deletions default.miniconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
window:
font: "./fonts/iosevka-regular.ttf
title: "ded
x: 100
y: 100
w: 800
h: 600

pop up:
scale: 0.6
fade in: 300

pop ups:
save ok:
str: "Saved file!
color: x009966FF
last: 1000
invalid goto:
str: "Invalid line(:col)
color: xFF2400FF
last: 2000
can not cd:
str: "Can't change directory to "{path}"!
color: xFF2400FF
last: 2000
can not open:
str: "Can't open file "{path}"!
color: xFF2400FF
last: 2000
can not save:
str: "Can't save file: {err}!
color: xFF2400FF
last: 2000

input hints:
find: "find
save as: "path
save: "path
goto: "line

editor:
background: x181818FF
color: xFFFFFFFF
bottom bar:
scale: 0.6
background: xE7E7E7FF
input:
hint:
color: x5B5B5BFF
fmt: "({hint})
spacing: 20.0
content:
color: x181818FF
stats:
enabled: true
fmt: "{lang} {row}:{col} / {max-row}
color: x181818FF
tokens:
preprocessor directive: x95A99FFF
keyword: xFFDD33FF
comment: xCC8C3CFF
string: x73C936FF
cursor:
blink:
treshold: 500
period: 1000
color: xFFFFFFFF
width: 5.0
selection:
color: x434343FF
search selection:
color: x191943FF
1 change: 1 addition & 0 deletions dependencies/freetype
Submodule freetype added at d6fb49
1 change: 1 addition & 0 deletions dependencies/minilibs
Submodule minilibs added at f3a1f4
1 change: 1 addition & 0 deletions dependencies/minirent
Submodule minirent added at dbbc30
2 changes: 2 additions & 0 deletions setup_other.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cp dependencies/SDL2/lib/x64/SDL2.dll .
dos2unix shaders/*
84 changes: 47 additions & 37 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include "./arena.h"
#define SV_IMPLEMENTATION
#include "sv.h"
#define FILELIB_IMPL
#include <filelib.h>
#define MINICONF_IMPL
#include <miniconf.h>
#define MINIFMT_IMPL
#include <minifmt.h>

static Arena temporary_arena = {0};

Expand Down Expand Up @@ -64,56 +70,50 @@ Errno read_entire_dir(const char *dir_path, Files *files)
Errno write_entire_file(const char *file_path, const char *buf, size_t buf_size)
{
Errno result = 0;
FILE *f = NULL;
if (buf == NULL)
return result;

f = fopen(file_path, "wb");
FILE *f = fopen(file_path, "wb");
if (f == NULL) return_defer(errno);

fwrite(buf, 1, buf_size, f);
// TODO: why are there extra nulls at the end of the buf (buf_size)??
// that's why we strlen it here to get the size without these nulls
size_t real_buf_size = strlen(buf);
if (buf_size < real_buf_size)
real_buf_size = buf_size;
fwrite(buf, 1, real_buf_size, f);
if (get_last(buf, real_buf_size) != '\n') {
fputc('\n', f);
}
if (ferror(f)) return_defer(errno);

defer:
if (f) fclose(f);
return result;
}

static Errno file_size(FILE *file, size_t *size)
{
long saved = ftell(file);
if (saved < 0) return errno;
if (fseek(file, 0, SEEK_END) < 0) return errno;
long result = ftell(file);
if (result < 0) return errno;
if (fseek(file, saved, SEEK_SET) < 0) return errno;
*size = (size_t) result;
return 0;
}

Errno read_entire_file(const char *file_path, String_Builder *sb)
{
Errno result = 0;
FILE *f = NULL;

f = fopen(file_path, "r");
if (f == NULL) return_defer(errno);

size_t size;
Errno err = file_size(f, &size);
if (err != 0) return_defer(err);

if (sb->capacity < size) {
sb->capacity = size;
sb->items = realloc(sb->items, sb->capacity*sizeof(*sb->items));
assert(sb->items != NULL && "Buy more RAM lol");
FILE *f = fopen(file_path, "r+");
if (f == NULL)
return 1;

int c;
while ((c = fgetc(f)) != EOF && c != '\0') {
if (c == '\t') {
da_append(sb, ' ');
da_append(sb, ' ');
da_append(sb, ' ');
da_append(sb, ' ');
} else if (c == '\r') {
continue;
} else {
da_append(sb, (char) c);
}
}

fread(sb->items, size, 1, f);
if (ferror(f)) return_defer(errno);
sb->count = size;

defer:
if (f) fclose(f);
return result;
fclose(f);
return 0;
}

Vec4f hex_to_vec4f(uint32_t color)
Expand All @@ -133,7 +133,17 @@ Vec4f hex_to_vec4f(uint32_t color)
Errno type_of_file(const char *file_path, File_Type *ft)
{
#ifdef _WIN32
#error "TODO: type_of_file() is not implemented for Windows"
DWORD file_obj_type = GetFileAttributesA(file_path);
if (file_obj_type & FILE_ATTRIBUTE_DIRECTORY) {
*ft = FT_DIRECTORY;
}
// I have no idea why, but a 'normal' file is considered an archive file?
else if (file_obj_type & FILE_ATTRIBUTE_ARCHIVE) {
*ft = FT_REGULAR;
}
else {
*ft = FT_OTHER;
}
#else
struct stat sb = {0};
if (stat(file_path, &sb) < 0) return errno;
Expand Down
6 changes: 3 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <stdint.h>
#include "./la.h"

#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define FPS 60
#define DELTA_TIME (1.0f / FPS)
#define CURSOR_OFFSET 0.13f
Expand Down Expand Up @@ -88,7 +86,9 @@ typedef struct {
size_t n = strlen(s); \
da_append_many(sb, s, n); \
} while (0)
#define sb_append_null(sb) da_append_many(sb, "", 1)
#define get_last(items, count) ((count) > 0 ? (items)[(count) - 1] : '\0')
#define sb_get_last(sb) get_last((sb).items, (sb).count)
#define sb_append_null(sb) da_append_many((sb), "", 1)

#define sb_to_sv(sb) sv_from_parts((sb).items, (sb).count)

Expand Down
Loading