Merge branch 'refs/heads/char_encode'
# Conflicts: # include/builtins.h # include/data.h # include/editor_op.h # include/file_io.h # include/input.h # include/row_op.h # install.sh # main.c # meson.build # src/builtins.c # src/editor_op.c # src/file_io.c # src/init.c # src/input.c # src/output.c # src/row_op.c
This commit is contained in:
+5
-38
@@ -9,53 +9,19 @@
|
||||
#include "../include/file_io.h"
|
||||
#include "../include/editor_op.h"
|
||||
#include "../include/input.h"
|
||||
#include "include/buffer.h"
|
||||
#include "include/data.h"
|
||||
#include "include/split_screen.h"
|
||||
#include "../include/buffer.h"
|
||||
#include "../include/data.h"
|
||||
#include "../include/split_screen.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern char *strdup(const char *);
|
||||
extern ssize_t getline(char **restrict lineptr, size_t *restrict n,
|
||||
FILE *restrict stream);
|
||||
extern int ftruncate(int fd, off_t length);
|
||||
extern struct editorConfig E;
|
||||
|
||||
/**
|
||||
* @brief Converts all editor rows to a single string buffer
|
||||
* @details Concatenates all row content into a single allocated buffer with
|
||||
* newlines between rows. Useful for file saving and buffer operations.
|
||||
* @param buffer_len Pointer to integer where total buffer length will be stored
|
||||
* @return Pointer to dynamically allocated buffer containing all row data.
|
||||
* Rows are separated by newline characters.
|
||||
* @note Caller is responsible for freeing the returned buffer
|
||||
*/
|
||||
char *bufferRowsToString(struct buffer_t *buf, int *buffer_len) {
|
||||
int tot_len = 0;
|
||||
int j;
|
||||
char *buffer;
|
||||
char *p;
|
||||
|
||||
for (j = 0; j < buf->numrows; ++j) {
|
||||
tot_len += buf->row[j].size + 1;
|
||||
}
|
||||
*buffer_len = tot_len;
|
||||
buffer = malloc(tot_len);
|
||||
p = buffer;
|
||||
for (j = 0; j < buf->numrows; ++j) {
|
||||
memcpy(p, buf->row[j].chars, buf->row[j].size);
|
||||
p += buf->row[j].size;
|
||||
*p = '\n';
|
||||
p++;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes the current file and resets editor state
|
||||
* @details Clears all rows, resets cursor position, scroll offsets, and file
|
||||
@@ -191,3 +157,4 @@ void bufferFind(struct buffer_t *buf) {
|
||||
}
|
||||
free(query);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user