utf8 processing without struct
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void abAppend(struct abuf *ab, const unsigned char *s, int len);
|
||||
void abAppend(struct abuf *ab, const char *s, int len);
|
||||
|
||||
void abFree(struct abuf *ab);
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ Lisp editorPrintC(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp addPackage(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorDelRow_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorFind_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
Lisp editorReadChar_L(Lisp args, LispError *e, LispContext ctx);
|
||||
|
||||
+8
-29
@@ -8,23 +8,17 @@
|
||||
#include "lisp.h"
|
||||
|
||||
|
||||
typedef struct{
|
||||
unsigned char c[4];
|
||||
char len;
|
||||
} utf_8_char_t;
|
||||
|
||||
/**
|
||||
* \struct erow
|
||||
* \struct row_t
|
||||
* \brief Store one editor row
|
||||
* \param
|
||||
* */
|
||||
|
||||
typedef struct erow {
|
||||
typedef struct row {
|
||||
int size; /**< Size of the line */
|
||||
int rsize; /**< Size of the render line */
|
||||
utf_8_char_t *chars; /**< Characters of the line */
|
||||
utf_8_char_t *render; /**< The actual line we will print */
|
||||
} erow;
|
||||
int cap; /**< Size of the render line */
|
||||
char *chars; /**< Characters of the line */
|
||||
} row_t;
|
||||
|
||||
enum editorStatus_e {
|
||||
IDLE,
|
||||
@@ -57,24 +51,9 @@ typedef enum {
|
||||
MOD_CTRL = 4
|
||||
} KeyModifier;
|
||||
|
||||
// Key information structure
|
||||
typedef struct {
|
||||
KeyType type;
|
||||
int modifiers; // Bitmask of KeyModifier
|
||||
union {
|
||||
unsigned int codepoint; // For KEY_CHAR
|
||||
char ctrl_char; // For KEY_CTRL (A-Z)
|
||||
char alt_char; // For KEY_ALT
|
||||
char arrow; // For KEY_ARROW (U/D/L/R)
|
||||
int function_num; // For KEY_FUNCTION (1-12)
|
||||
char special; // For KEY_SPECIAL and KEY_NAVIGATION
|
||||
} data;
|
||||
utf_8_char_t c; // Raw bytes
|
||||
} KeyInfo;
|
||||
|
||||
|
||||
struct keyBind_t {
|
||||
KeyInfo *key_sequence;
|
||||
char *key_sequence;
|
||||
Lisp command;
|
||||
};
|
||||
|
||||
@@ -90,7 +69,7 @@ struct editorConfig {
|
||||
int screenrows; /**< Terminal height*/
|
||||
int screencols; /**< Terminal width*/
|
||||
int numrows; /**< Number of rows contained */
|
||||
erow *row; /**< Store all the rows printed */
|
||||
row_t *rows; /**< Store all the rows printed */
|
||||
int dirty;
|
||||
char *filename;
|
||||
enum editorStatus_e state;
|
||||
@@ -118,7 +97,7 @@ struct editorConfig {
|
||||
* */
|
||||
|
||||
struct abuf {
|
||||
unsigned char *b; /**< Text that will be printed */
|
||||
char *b; /**< Text that will be printed */
|
||||
int len; /**< Length of the text */
|
||||
};
|
||||
|
||||
|
||||
+12
-1
@@ -11,7 +11,18 @@
|
||||
#define TAB "\x09"
|
||||
#define SPACE "\x20"
|
||||
|
||||
|
||||
enum editorKey_e {
|
||||
BACKSPACE = 127,
|
||||
ARROW_LEFT = 1000,
|
||||
ARROW_RIGHT,
|
||||
ARROW_UP,
|
||||
ARROW_DOWN,
|
||||
DEL_KEY,
|
||||
BEG_LINE,
|
||||
END_LINE,
|
||||
PAGE_UP,
|
||||
PAGE_DOWN,
|
||||
};
|
||||
|
||||
#define ABUF_INIT {NULL, 0}
|
||||
|
||||
|
||||
+1
-3
@@ -2,9 +2,7 @@
|
||||
#define EDITOR_OP_H_
|
||||
|
||||
#include "data.h"
|
||||
void editorInsertChar(utf_8_char_t *c);
|
||||
|
||||
void editorInsertNewLine(void);
|
||||
void editorInsertChar(int c);
|
||||
|
||||
void editorDelChar();
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
char *editorRowsToString(int *buffer_len);
|
||||
|
||||
|
||||
void editorCloseFile(void);
|
||||
|
||||
void editorOpen(char *filename);
|
||||
|
||||
+2
-4
@@ -22,11 +22,9 @@
|
||||
|
||||
char *editorPrompt(char *prompt, char * PlaceHolder, char bPathMode);
|
||||
|
||||
char *key_to_string(int key);
|
||||
void editorMoveCursor(int key);
|
||||
|
||||
void editorMoveCursor(KeyInfo * key);
|
||||
|
||||
int executeKeyBind(KeyInfo *key_sequence);
|
||||
int executeKeyBind(char *key_sequence);
|
||||
|
||||
/**
|
||||
* \fn void editorProcessKeypress()
|
||||
|
||||
+6
-12
@@ -8,22 +8,16 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int editorRowCxToRx(erow *row, int cursor_x);
|
||||
void editorInsertRow(int at, char *s, int len);
|
||||
|
||||
int editorRowRxToCx(erow *row, int rx);
|
||||
void editorFreeRow(row_t *row);
|
||||
|
||||
void editorUpdateRow(erow *row);
|
||||
int editorRowCxToByte(const row_t *row, int cursor_x);
|
||||
|
||||
void editorInsertRow(int at, char *s, size_t len);
|
||||
int editorRowCharCount(row_t *row);
|
||||
|
||||
void editorFreeRow(erow *row);
|
||||
void editorRowInsertBytes(row_t *row, int at, const char *src, int len);
|
||||
|
||||
void editorDelRow(int at);
|
||||
|
||||
void editorRowInsertChar(erow *row, int at, utf_8_char_t c);
|
||||
|
||||
void editorRowAppendString(erow *row, char *s, size_t len);
|
||||
|
||||
void editorRowDelchar(erow *row, int at);
|
||||
void editorRowDelByte(row_t *row, int at, int n);
|
||||
|
||||
#endif // ROW_OP_H_
|
||||
|
||||
+3
-3
@@ -25,12 +25,12 @@ void disableRawMode();
|
||||
|
||||
void enableRawMode();
|
||||
|
||||
KeyInfo * editorReadKey();
|
||||
int editorReadKey();
|
||||
|
||||
int getCursorPosition(int *rows, int *cols);
|
||||
|
||||
KeyInfo *stringToCodepoint(const char *string);
|
||||
|
||||
int getWindowSize(int *rows, int *cols);
|
||||
|
||||
char *key_to_string(int key);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by Giorgio on 01/05/2026.
|
||||
//
|
||||
|
||||
#ifndef BELUGA_UTF8_H
|
||||
#define BELUGA_UTF8_H
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t readUtf8Char(void);
|
||||
int utf8Encode(uint32_t cp, char *buf);
|
||||
int utf8Seqlen(unsigned char c);
|
||||
int codepointWidth(uint32_t codepoint);
|
||||
uint32_t utf8Decode(const char** s);
|
||||
|
||||
|
||||
#endif //BELUGA_UTF8_H
|
||||
Reference in New Issue
Block a user