diff options
| author | Albert Cervin <albert@acervin.com> | 2024-05-22 00:00:29 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2024-09-12 20:17:56 +0200 |
| commit | 405da5f84b072ea97b69359454899f45d92d24b6 (patch) | |
| tree | 20525b4bc44a5d8cbab4d62abe8413e174731db6 /src/dged/path.h | |
| parent | 4ab7e453e26afc6e9f4938c65f89463fbba9e267 (diff) | |
| download | dged-405da5f84b072ea97b69359454899f45d92d24b6.tar.gz dged-405da5f84b072ea97b69359454899f45d92d24b6.tar.xz dged-405da5f84b072ea97b69359454899f45d92d24b6.zip | |
WIP LSP client
This contains the start of an LSP client.
Nothing (except starting the LSP server) works
at the moment and the feature is disabled by default.
Diffstat (limited to 'src/dged/path.h')
| -rw-r--r-- | src/dged/path.h | 69 |
1 files changed, 7 insertions, 62 deletions
diff --git a/src/dged/path.h b/src/dged/path.h index 8ea9977..6168e42 100644 --- a/src/dged/path.h +++ b/src/dged/path.h @@ -1,65 +1,10 @@ -#include <limits.h> -#include <stdlib.h> -#include <string.h> +#ifndef _PATH_H +#define _PATH_H -static char *expanduser(const char *path) { - // replace tilde - char *res = NULL; - char *tilde_pos = strchr(path, '~'); - if (tilde_pos != NULL) { - char *home = getenv("HOME"); - if (home != NULL) { - // allocate a new string based with the new len - size_t home_len = strlen(home); - size_t path_len = strlen(path); - size_t total_len = path_len + home_len; - res = malloc(total_len); - size_t initial_len = tilde_pos - path; - strncpy(res, path, initial_len); +char *expanduser(const char *path); +char *to_abspath(const char *path); +const char *join_path_with_delim(const char *p1, const char *p2, + const char delim); +const char *join_path(const char *p1, const char *p2); - strncpy(res + initial_len, home, home_len); - - size_t rest_len = path_len - initial_len - 1; - strncpy(res + initial_len + home_len, path + initial_len + 1, rest_len); - res[total_len - 1] = '\0'; - } - } - - return res != NULL ? res : strdup(path); -} - -static char *to_abspath(const char *path) { - char *exp = expanduser(path); - char *p = realpath(path, NULL); - if (p != NULL) { - free(exp); - return p; - } else { - return exp; - } -} - -static const char *join_path_with_delim(const char *p1, const char *p2, - const char delim) { - size_t len1 = strlen(p1); - size_t len2 = strlen(p2); - - char *path = malloc(len1 + len2 + 2); - uint32_t idx = 0; - memcpy(&path[idx], p1, len1); - idx += len1; - path[idx++] = '/'; - memcpy(&path[idx], p2, len2); - idx += len2; - path[idx++] = '\0'; - - return path; -} - -static const char *join_path(const char *p1, const char *p2) { -#ifdef __unix__ - return join_path_with_delim(p1, p2, '/'); -#elif defined(_WIN32) || defined(WIN32) - return join_path_with_delim(p1, p2, '\\'); #endif -} |
