diff --git a/editor/Makefile b/editor/Makefile
index 74870a19..48d6f674 100644
--- a/editor/Makefile
+++ b/editor/Makefile
@@ -5,10 +5,10 @@ include ../build-aux/version.mak
include ../build-aux/dirs.mak
OPTLEVEL?=$(DEFAULT_OPTLEVEL)
-CXXFLAGS?=$(OPTLEVEL)
+CFLAGS?=$(OPTLEVEL)
CPPFLAGS:=$(CPPFLAGS) -DVERSIONSTR=\"$(VERSION)\"
-CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti
+CFLAGS:=$(CFLAGS) -Wall -Wextra
BINARY=editor
@@ -28,10 +28,10 @@ all: $(BINARY)
.PHONY: all install clean
$(BINARY): $(OBJS)
- $(CXX) $(OBJS) -o $(BINARY) $(CXXFLAGS) $(LIBS)
+ $(CC) $(CFLAGS) $(OBJS) -o $(BINARY) $(LIBS)
-%.o: %.c++
- $(CXX) -std=gnu++11 $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
+%.o: %.c
+ $(CC) -std=gnu11 $(CFLAGS) $(CPPFLAGS) -c $< -o $@
install: all
mkdir -p $(DESTDIR)$(BINDIR)
diff --git a/editor/command.c++ b/editor/command.c
similarity index 96%
rename from editor/command.c++
rename to editor/command.c
index 3b376bcd..fbbad899 100644
--- a/editor/command.c++
+++ b/editor/command.c
@@ -15,28 +15,25 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- command.c++
+ command.c
Editor commands.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#include
+#include
#include
#include
#include
#include
#include
-#include "command.h++"
-#include "cursor.h++"
-#include "display.h++"
-#include "editor.h++"
-#include "multibyte.h++"
-#include "terminal.h++"
+#include "command.h"
+#include "cursor.h"
+#include "display.h"
+#include "editor.h"
+#include "multibyte.h"
+#include "terminal.h"
void editor_type_newline(struct editor* editor)
{
@@ -45,10 +42,11 @@ void editor_type_newline(struct editor* editor)
if ( editor->lines_used == editor->lines_length )
{
size_t new_length = editor->lines_length ? 2 * editor->lines_length : 8;
- struct line* new_lines = new struct line[new_length];
+ struct line* new_lines = (struct line*)
+ malloc(sizeof(struct line) * new_length);
for ( size_t i = 0; i < editor->lines_used; i++ )
new_lines[i] = editor->lines[i];
- delete[] editor->lines;
+ free(editor->lines);
editor->lines = new_lines;
editor->lines_length = new_length;
}
@@ -65,19 +63,19 @@ void editor_type_newline(struct editor* editor)
struct line* keep_line = &editor->lines[editor->cursor_row];
struct line* move_line = &editor->lines[editor->cursor_row+1];
- keep_line->data = new wchar_t[keep_length];
+ keep_line->data = (wchar_t*) malloc(sizeof(wchar_t) * keep_length);
keep_line->used = keep_length;
keep_line->length = keep_length;
memcpy(keep_line->data, old_line.data + 0, sizeof(wchar_t) * keep_length);
- move_line->data = new wchar_t[move_length];
+ move_line->data = (wchar_t*) malloc(sizeof(wchar_t) * move_length);
move_line->used = move_length;
move_line->length = move_length;
memcpy(move_line->data, old_line.data + keep_length, sizeof(wchar_t) * move_length);
editor_cursor_set(editor, editor->cursor_row+1, 0);
- delete[] old_line.data;
+ free(old_line.data);
}
void editor_type_delete_selection(struct editor* editor);
@@ -96,7 +94,7 @@ void editor_type_combine_with_last(struct editor* editor)
wchar_t* gone_line_data = gone_line->data;
size_t new_length = keep_line->used + gone_line->used;
- wchar_t* new_data = new wchar_t[new_length];
+ wchar_t* new_data = (wchar_t*) malloc(sizeof(wchar_t) * new_length);
memcpy(new_data, keep_line_data, sizeof(wchar_t) * keep_line->used);
memcpy(new_data + keep_line->used, gone_line_data, sizeof(wchar_t) * gone_line->used);
@@ -153,7 +151,7 @@ void editor_type_combine_with_next(struct editor* editor)
wchar_t* gone_line_data = gone_line->data;
size_t new_length = keep_line->used + gone_line->used;
- wchar_t* new_data = new wchar_t[new_length];
+ wchar_t* new_data = (wchar_t*) malloc(sizeof(wchar_t) * new_length);
memcpy(new_data, keep_line_data, sizeof(wchar_t) * keep_line->used);
memcpy(new_data + keep_line->used, gone_line_data, sizeof(wchar_t) * gone_line->used);
@@ -706,10 +704,10 @@ void editor_type_raw_character(struct editor* editor, wchar_t c)
if ( current_line->used == current_line->length )
{
size_t new_length = current_line->length ? 2 * current_line->length : 8;
- wchar_t* new_data = new wchar_t[new_length];
+ wchar_t* new_data = (wchar_t*) malloc(sizeof(wchar_t) * new_length);
for ( size_t i = 0; i < current_line->used; i++ )
new_data[i] = current_line->data[i];
- delete[] current_line->data;
+ free(current_line->data);
current_line->data = new_data;
current_line->length = new_length;
}
@@ -728,7 +726,7 @@ void editor_type_copy(struct editor* editor)
editor->cursor_column == editor->select_column )
return;
- delete[] editor->clipboard;
+ free(editor->clipboard);
size_t start_row;
size_t start_column;
@@ -767,7 +765,7 @@ void editor_type_copy(struct editor* editor)
}
}
- editor->clipboard = new wchar_t[length + 1];
+ editor->clipboard = (wchar_t*) malloc(sizeof(wchar_t) * (length + 1));
size_t offset = 0;
for ( size_t row = start_row, column = start_column;
is_row_column_lt(row, column, end_row, end_column); )
diff --git a/editor/command.h++ b/editor/command.h
similarity index 98%
rename from editor/command.h++
rename to editor/command.h
index d4a2c046..be764c0e 100644
--- a/editor/command.h++
+++ b/editor/command.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- command.h++
+ command.h
Editor commands.
*******************************************************************************/
-#ifndef EDITOR_COMMAND_HXX
-#define EDITOR_COMMAND_HXX
+#ifndef EDITOR_COMMAND_H
+#define EDITOR_COMMAND_H
#include
diff --git a/editor/cursor.c++ b/editor/cursor.c
similarity index 95%
rename from editor/cursor.c++
rename to editor/cursor.c
index 253bdafa..435b24a7 100644
--- a/editor/cursor.c++
+++ b/editor/cursor.c
@@ -15,21 +15,18 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- cursor.c++
+ cursor.c
Editor cursor.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#include
+#include
#include
-#include "cursor.h++"
-#include "display.h++"
-#include "editor.h++"
+#include "cursor.h"
+#include "display.h"
+#include "editor.h"
size_t editor_select_column_set(struct editor* editor, size_t x)
{
diff --git a/editor/cursor.h++ b/editor/cursor.h
similarity index 96%
rename from editor/cursor.h++
rename to editor/cursor.h
index 2eff56db..762b8726 100644
--- a/editor/cursor.h++
+++ b/editor/cursor.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- cursor.h++
+ cursor.h
Editor cursor.
*******************************************************************************/
-#ifndef EDITOR_CURSOR_HXX
-#define EDITOR_CURSOR_HXX
+#ifndef EDITOR_CURSOR_H
+#define EDITOR_CURSOR_H
#include
diff --git a/editor/display.c++ b/editor/display.c
similarity index 96%
rename from editor/display.c++
rename to editor/display.c
index 4cdcc3c9..d43bb808 100644
--- a/editor/display.c++
+++ b/editor/display.c
@@ -15,24 +15,21 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- display.c++
+ display.c
Display handling.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
+#include
#include
#include
#include
#include
-#include "display.h++"
-#include "editor.h++"
-#include "multibyte.h++"
-#include "terminal.h++"
+#include "display.h"
+#include "editor.h"
+#include "multibyte.h"
+#include "terminal.h"
size_t editor_display_column_of_line_offset(struct editor* editor,
const struct line* line,
@@ -93,17 +90,18 @@ struct display_char* expand_tabs(const wchar_t* str, size_t len, uint8_t* colors
size_t tabsize)
{
size_t ret_len = displayed_string_length(str, len, tabsize);
- struct display_char* ret = new struct display_char[ret_len+1];
+ struct display_char* ret = (struct display_char*)
+ malloc(sizeof(struct display_char) * (ret_len + 1));
for ( size_t i = 0, j = 0; i < len; i++ )
{
uint8_t color = i < colors_len ? colors[i] : 7;
if ( str[i] == L'\t' )
- do ret[j++] = { L' ', color};
+ do ret[j++] = (struct display_char) { L' ', color};
while ( j % tabsize );
else
- ret[j++] = { str[i], color };
+ ret[j++] = (struct display_char) { str[i], color };
}
- ret[ret_len] = { L'\0', 0 };
+ ret[ret_len] = (struct display_char) { L'\0', 0 };
if ( ret_len_ptr )
*ret_len_ptr = ret_len;
return ret;
@@ -238,7 +236,7 @@ void render_editor(struct editor* editor, struct terminal_state* state)
is_blank && at_margin ? make_terminal_datum(L'|', 0x01) :
make_terminal_datum(c, color);
}
- delete[] expanded;
+ free(expanded);
}
// Set the rest of the terminal state.
diff --git a/editor/display.h++ b/editor/display.h
similarity index 96%
rename from editor/display.h++
rename to editor/display.h
index 6ad6c9d3..c278a8ab 100644
--- a/editor/display.h++
+++ b/editor/display.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- display.h++
+ display.h
Display handling.
*******************************************************************************/
-#ifndef EDITOR_DISPLAY_HXX
-#define EDITOR_DISPLAY_HXX
+#ifndef EDITOR_DISPLAY_H
+#define EDITOR_DISPLAY_H
#include
#include
diff --git a/editor/editor.c++ b/editor/editor.c
similarity index 93%
rename from editor/editor.c++
rename to editor/editor.c
index fd448255..5c3b3a2f 100644
--- a/editor/editor.c++
+++ b/editor/editor.c
@@ -15,15 +15,11 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- editor.c++
+ editor.c
Editor.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#include
#include
@@ -32,6 +28,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -39,14 +36,14 @@
#include
#include
-#include "command.h++"
-#include "cursor.h++"
-#include "display.h++"
-#include "editor.h++"
-#include "highlight.h++"
-#include "input.h++"
-#include "modal.h++"
-#include "terminal.h++"
+#include "command.h"
+#include "cursor.h"
+#include "display.h"
+#include "editor.h"
+#include "highlight.h"
+#include "input.h"
+#include "modal.h"
+#include "terminal.h"
void initialize_editor(struct editor* editor)
{
@@ -80,7 +77,8 @@ void initialize_editor(struct editor* editor)
editor->lines_used = 1;
editor->lines_length = 1;
- editor->lines = new struct line[editor->lines_length];
+ editor->lines =
+ (struct line*) malloc(sizeof(struct line) * editor->lines_length);
editor->lines[0].data = NULL;
editor->lines[0].used = 0;
editor->lines[0].length = 0;
@@ -134,12 +132,13 @@ void editor_load_config(struct editor* editor)
void editor_reset_contents(struct editor* editor)
{
for ( size_t i = 0; i < editor->lines_used; i++ )
- delete[] editor->lines[i].data;
- delete[] editor->lines;
+ free(editor->lines[i].data);
+ free(editor->lines);
editor->lines_used = 1;
editor->lines_length = 1;
- editor->lines = new struct line[editor->lines_length];
+ editor->lines =
+ (struct line*) malloc(sizeof(struct line) * editor->lines_length);
editor->lines[0].data = NULL;
editor->lines[0].used = 0;
editor->lines[0].length = 0;
@@ -197,7 +196,8 @@ bool editor_load_file_contents(struct editor* editor, FILE* fp)
bool editor_load_file(struct editor* editor, const char* path)
{
- if ( FILE* fp = fopen(path, "r") )
+ FILE* fp;
+ if ( (fp = fopen(path, "r")) )
{
bool success = editor_load_file_contents(editor, fp);
fclose(fp);
diff --git a/editor/editor.h++ b/editor/editor.h
similarity index 96%
rename from editor/editor.h++
rename to editor/editor.h
index 7bef0c0a..2d0bbbbc 100644
--- a/editor/editor.h++
+++ b/editor/editor.h
@@ -15,19 +15,19 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- editor.h++
+ editor.h
Editor.
*******************************************************************************/
-#ifndef EDITOR_EDITOR_HXX
-#define EDITOR_EDITOR_HXX
+#ifndef EDITOR_EDITOR_H
+#define EDITOR_EDITOR_H
#include
#include
#include
-#include "highlight.h++"
+#include "highlight.h"
struct line
{
diff --git a/editor/highlight.c++ b/editor/highlight.c
similarity index 96%
rename from editor/highlight.c++
rename to editor/highlight.c
index ecb90895..9d428028 100644
--- a/editor/highlight.c++
+++ b/editor/highlight.c
@@ -15,23 +15,21 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- highlight.c++
+ highlight.c
Syntax highlighting.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
+#include
#include
#include
+#include
#include
#include
#include
-#include "editor.h++"
-#include "highlight.h++"
+#include "editor.h"
+#include "highlight.h"
enum language language_of_path(const char* path)
{
@@ -143,8 +141,8 @@ void editor_colorize(struct editor* editor)
editor->highlight_source == LANGUAGE_NONE )
{
for ( size_t i = 0; i < editor->color_lines_used; i++ )
- delete[] editor->color_lines[i].data;
- delete[] editor->color_lines;
+ free(editor->color_lines[i].data);
+ free(editor->color_lines);
editor->color_lines_used = 0;
editor->color_lines_length = 0;
editor->color_lines = NULL;
@@ -155,7 +153,9 @@ void editor_colorize(struct editor* editor)
if ( !editor->color_lines )
{
- if ( !(editor->color_lines = new struct color_line[editor->lines_used]) )
+ editor->color_lines = (struct color_line*)
+ malloc(sizeof(struct color_line) * editor->lines_used);
+ if ( !editor->color_lines )
return;
editor->color_lines_used = editor->lines_used;
editor->color_lines_length = editor->lines_used;
@@ -169,11 +169,12 @@ void editor_colorize(struct editor* editor)
if ( editor->color_lines[i].length == editor->lines[i].used )
continue;
- if ( !(editor->color_lines[i].data = new uint8_t[editor->lines[i].used]) )
+ editor->color_lines[i].data = (uint8_t*) malloc(editor->lines[i].used);
+ if ( !editor->color_lines[i].data )
{
for ( size_t n = 0; n < i; i++ )
- delete[] editor->color_lines[n].data;
- delete[] editor->color_lines;
+ free(editor->color_lines[n].data);
+ free(editor->color_lines);
editor->color_lines_used = 0;
editor->color_lines_length = 0;
editor->color_lines = NULL;
diff --git a/editor/highlight.h++ b/editor/highlight.h
similarity index 93%
rename from editor/highlight.h++
rename to editor/highlight.h
index 11ce5fb9..1376ff24 100644
--- a/editor/highlight.h++
+++ b/editor/highlight.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- highlight.h++
+ highlight.h
Syntax highlighting.
*******************************************************************************/
-#ifndef EDITOR_HIGHLIGHT_HXX
-#define EDITOR_HIGHLIGHT_HXX
+#ifndef EDITOR_HIGHLIGHT_H
+#define EDITOR_HIGHLIGHT_H
struct editor;
diff --git a/editor/input.c++ b/editor/input.c
similarity index 95%
rename from editor/input.c++
rename to editor/input.c
index d0e671d0..93a9a07d 100644
--- a/editor/input.c++
+++ b/editor/input.c
@@ -15,28 +15,25 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- input.c++
+ input.c+
Keyboard input.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#if defined(__sortix__)
#include
#include
#endif
+#include
#include
#include
#include
-#include "command.h++"
-#include "editor.h++"
-#include "input.h++"
-#include "modal.h++"
+#include "command.h"
+#include "editor.h"
+#include "input.h"
+#include "modal.h"
void editor_codepoint(struct editor* editor, uint32_t codepoint)
{
@@ -184,7 +181,8 @@ void editor_input_process(struct editor_input* editor_input,
uint32_t input;
if ( read(0, &input, sizeof(input)) != sizeof(input) )
return;
- if ( int kbkey = KBKEY_DECODE(input) )
+ int kbkey;
+ if ( (kbkey = KBKEY_DECODE(input)) )
editor_kbkey(editor, kbkey);
else
editor_codepoint(editor, input);
diff --git a/editor/input.h++ b/editor/input.h
similarity index 95%
rename from editor/input.h++
rename to editor/input.h
index 2adaa3db..dad7d6b6 100644
--- a/editor/input.h++
+++ b/editor/input.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- input.h++
+ input.h
Keyboard input.
*******************************************************************************/
-#ifndef EDITOR_INPUT_HXX
-#define EDITOR_INPUT_HXX
+#ifndef EDITOR_INPUT_H
+#define EDITOR_INPUT_H
struct editor;
diff --git a/editor/modal.c++ b/editor/modal.c
similarity index 97%
rename from editor/modal.c++
rename to editor/modal.c
index 97de8edb..97665d3d 100644
--- a/editor/modal.c++
+++ b/editor/modal.c
@@ -15,28 +15,25 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- modal.c++
+ modal.c
Modal commands.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#include
+#include
#include
#include
#include
#include
#include
-#include "command.h++"
-#include "cursor.h++"
-#include "editor.h++"
-#include "highlight.h++"
-#include "modal.h++"
-#include "multibyte.h++"
+#include "command.h"
+#include "cursor.h"
+#include "editor.h"
+#include "highlight.h"
+#include "modal.h"
+#include "multibyte.h"
static void editor_reset_modal(struct editor* editor)
{
diff --git a/editor/modal.h++ b/editor/modal.h
similarity index 97%
rename from editor/modal.h++
rename to editor/modal.h
index c5f0fb54..63bccd2e 100644
--- a/editor/modal.h++
+++ b/editor/modal.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- modal.h++
+ modal.h
Modal commands.
*******************************************************************************/
-#ifndef EDITOR_MODAL_HXX
-#define EDITOR_MODAL_HXX
+#ifndef EDITOR_MODAL_H
+#define EDITOR_MODAL_H
struct editor;
diff --git a/editor/multibyte.c++ b/editor/multibyte.c
similarity index 96%
rename from editor/multibyte.c++
rename to editor/multibyte.c
index 2f113685..3dab053c 100644
--- a/editor/multibyte.c++
+++ b/editor/multibyte.c
@@ -15,22 +15,19 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- multibyte.c++
+ multibyte.c
Conversion from multibyte strings to wide strings.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#include
+#include
#include
#include
#include
#include
-#include "multibyte.h++"
+#include "multibyte.h"
wchar_t* convert_mbs_to_wcs(const char* mbs)
{
diff --git a/editor/multibyte.h++ b/editor/multibyte.h
similarity index 93%
rename from editor/multibyte.h++
rename to editor/multibyte.h
index 10a4f966..e8d1e26f 100644
--- a/editor/multibyte.h++
+++ b/editor/multibyte.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- multibyte.h++
+ multibyte.h
Conversion from multibyte strings to wide strings.
*******************************************************************************/
-#ifndef EDITOR_MULTIBYTE_HXX
-#define EDITOR_MULTIBYTE_HXX
+#ifndef EDITOR_MULTIBYTE_H
+#define EDITOR_MULTIBYTE_H
#include
diff --git a/editor/terminal.c++ b/editor/terminal.c
similarity index 97%
rename from editor/terminal.c++
rename to editor/terminal.c
index 5348109d..db9b03f2 100644
--- a/editor/terminal.c++
+++ b/editor/terminal.c
@@ -15,16 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- terminal.c++
+ terminal.c
Terminal handling.
*******************************************************************************/
-#define __STDC_CONSTANT_MACROS
-#define __STDC_FORMAT_MACROS
-#define __STDC_LIMIT_MACROS
-
#include
+#include
#include
#include
#include
@@ -33,7 +30,7 @@
#include
#include
-#include "terminal.h++"
+#include "terminal.h"
void update_terminal_color(FILE* fp, uint8_t desired_color,
struct terminal_state* current)
diff --git a/editor/terminal.h++ b/editor/terminal.h
similarity index 97%
rename from editor/terminal.h++
rename to editor/terminal.h
index acc60643..9b8d101e 100644
--- a/editor/terminal.h++
+++ b/editor/terminal.h
@@ -15,13 +15,13 @@
You should have received a copy of the GNU General Public License along with
this program. If not, see .
- terminal.h++
+ terminal.h
Terminal handling.
*******************************************************************************/
-#ifndef EDITOR_TERMINAL_HXX
-#define EDITOR_TERMINAL_HXX
+#ifndef EDITOR_TERMINAL_H
+#define EDITOR_TERMINAL_H
#include
#include