Working version.
This commit is contained in:
parent
e0c4d650c6
commit
8d0ed4f185
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
all: build build_rd build_free build_rpylib run_free
|
all: build build_rd build_free build_rpylib run
|
||||||
|
|
||||||
# Variables for compiler and flags
|
# Variables for compiler and flags
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
12
indexer.h
12
indexer.h
@ -13,7 +13,15 @@
|
|||||||
|
|
||||||
static const char *extensions[] = {
|
static const char *extensions[] = {
|
||||||
".c", ".cpp", ".h", ".py", ".java", ".js", ".mk", ".html",
|
".c", ".cpp", ".h", ".py", ".java", ".js", ".mk", ".html",
|
||||||
"Makefile", ".css", ".json", ".cs", ".csproj", ".sln", ".toml", ".rs"
|
"Makefile", ".css", ".json", ".cs", ".csproj", ".sln", ".toml", ".rs",
|
||||||
|
".go", ".rb", ".swift", ".php", ".pl", ".sh", ".bash", ".sql",
|
||||||
|
".xml", ".yaml", ".yml", ".kt", ".dart", ".scala", ".clj", ".asm",
|
||||||
|
".m", ".r", ".lua", ".groovy", ".v", ".pas", ".d", ".f90", ".f95",
|
||||||
|
".for", ".s", ".tcl", ".vhdl", ".verilog", ".coffee", ".less", ".scss",
|
||||||
|
".ps1", ".psm1", ".cmd", ".bat", ".json5", ".cxx", ".cc", ".hpp",
|
||||||
|
".hxx", ".inc", ".nsi", ".ninja", ".cmake", ".cmake.in", ".mk.in",
|
||||||
|
".make", ".makefile", ".gyp", ".gypi", ".pro", ".qml", ".ui", ".wxs",
|
||||||
|
".wxl", ".wxi", ".wxl", ".wxs", ".wxi", ".wxl", ".wxs", ".wxi"
|
||||||
};
|
};
|
||||||
static const size_t ext_count = sizeof(extensions) / sizeof(extensions[0]);
|
static const size_t ext_count = sizeof(extensions) / sizeof(extensions[0]);
|
||||||
|
|
||||||
@ -101,4 +109,4 @@ char *index_directory(const char *dir_path) {
|
|||||||
char *result = strdup(json_object_to_json_string(jarray));
|
char *result = strdup(json_object_to_json_string(jarray));
|
||||||
json_object_put(jarray);
|
json_object_put(jarray);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
2
main.c
2
main.c
@ -139,6 +139,7 @@ void repl() {
|
|||||||
line = line_read("> ");
|
line = line_read("> ");
|
||||||
if (!line || !*line) continue;
|
if (!line || !*line) continue;
|
||||||
|
|
||||||
|
|
||||||
if (!strncmp(line, "!dump", 5)) {
|
if (!strncmp(line, "!dump", 5)) {
|
||||||
printf("%s\n", message_json());
|
printf("%s\n", message_json());
|
||||||
continue;
|
continue;
|
||||||
@ -218,7 +219,6 @@ void init() {
|
|||||||
line_init();
|
line_init();
|
||||||
auth_init();
|
auth_init();
|
||||||
db_initialize();
|
db_initialize();
|
||||||
|
|
||||||
char *schema = db_get_schema();
|
char *schema = db_get_schema();
|
||||||
char payload[1024 * 1024] = {0};
|
char payload[1024 * 1024] = {0};
|
||||||
snprintf(payload, sizeof(payload),
|
snprintf(payload, sizeof(payload),
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "json-c/json.h"
|
#include "json-c/json.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "db_utils.h"
|
||||||
struct json_object *message_array = NULL;
|
struct json_object *message_array = NULL;
|
||||||
|
|
||||||
struct json_object *message_list() {
|
struct json_object *message_list() {
|
||||||
@ -77,6 +77,9 @@ void message_add_object(json_object *message) {
|
|||||||
json_object_array_add(messages, message);
|
json_object_array_add(messages, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct json_object *message_add(const char *role, const char *content);
|
||||||
|
|
||||||
struct json_object *message_add(const char *role, const char *content) {
|
struct json_object *message_add(const char *role, const char *content) {
|
||||||
struct json_object *messages = message_list();
|
struct json_object *messages = message_list();
|
||||||
struct json_object *message = json_object_new_object();
|
struct json_object *message = json_object_new_object();
|
||||||
|
85
utils.h
85
utils.h
@ -20,38 +20,77 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
char *expand_home_directory(const char *path) {
|
|
||||||
if (path == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (path[0] == '~' && path[1] == '/') {
|
|
||||||
const char *home_dir = getenv("HOME");
|
|
||||||
if (home_dir == NULL) {
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
#endif
|
||||||
struct passwd *pw = getpwuid(getuid());
|
|
||||||
if (pw == NULL)
|
void get_current_directory() {
|
||||||
return NULL;
|
char buffer[PATH_MAX];
|
||||||
home_dir = pw->pw_dir;
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
DWORD length = GetCurrentDirectory(PATH_MAX, buffer);
|
||||||
|
if (length > 0 && length < PATH_MAX) {
|
||||||
|
printf("Current Directory: %s\n", buffer);
|
||||||
|
} else {
|
||||||
|
printf("Error getting current directory.\n");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (getcwd(buffer, sizeof(buffer)) != NULL) {
|
||||||
|
printf("Current Directory: %s\n", buffer);
|
||||||
|
} else {
|
||||||
|
perror("Error getting current directory");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
char* expand_home_directory(const char* path) {
|
||||||
|
if (path[0] != '~') {
|
||||||
|
return strdup(path); // Return the original path if it doesn't start with ~
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t home_len = strlen(home_dir);
|
char* home_dir;
|
||||||
size_t path_len = strlen(path) - 1;
|
|
||||||
char *expanded_path = malloc(home_len + path_len + 1);
|
|
||||||
|
|
||||||
if (expanded_path == NULL)
|
#ifdef _WIN32
|
||||||
return NULL;
|
home_dir = getenv("USERPROFILE"); // Get home directory on Windows
|
||||||
|
#else
|
||||||
|
struct passwd* pw = getpwuid(getuid());
|
||||||
|
home_dir = pw->pw_dir; // Get home directory on Linux
|
||||||
|
#endif
|
||||||
|
|
||||||
strcpy(expanded_path, home_dir);
|
if (home_dir == NULL) {
|
||||||
strcat(expanded_path, path + 1);
|
return NULL; // Error getting home directory
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate memory for the expanded path
|
||||||
|
size_t expanded_size = strlen(home_dir) + strlen(path);
|
||||||
|
char* expanded_path = (char *)malloc(expanded_size);
|
||||||
|
if (expanded_path == NULL) {
|
||||||
|
return NULL; // Memory allocation error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct the expanded path
|
||||||
|
snprintf(expanded_path, expanded_size, "%s%s", home_dir, path + 1);
|
||||||
return expanded_path;
|
return expanded_path;
|
||||||
} else {
|
|
||||||
return strdup(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long hash(const char *str) {
|
||||||
|
unsigned long hash = 5381; // Starting value
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while ((c = *str++)) {
|
||||||
|
hash = ((hash << 5) + hash) + c; // hash * 33 + c
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *read_file(const char *path) {
|
char *read_file(const char *path) {
|
||||||
char *expanded_path = expand_home_directory(path);
|
char *expanded_path = expand_home_directory(path);
|
||||||
FILE *file = fopen(expanded_path, "r");
|
FILE *file = fopen(expanded_path, "r");
|
||||||
|
Loading…
Reference in New Issue
Block a user