From d2cdf814180531289cea364c56bc2d8c6190758f Mon Sep 17 00:00:00 2001 From: Wvader <34067397+wvader@users.noreply.github.com> Date: Fri, 4 Nov 2022 21:38:12 +0000 Subject: [PATCH] prefer snake case --- main.cpp | 65 +++++++++++++++++++++++++++++++++----------------------- main.h | 22 ++++++++++++------- 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/main.cpp b/main.cpp index f86dc72..4b9f806 100644 --- a/main.cpp +++ b/main.cpp @@ -8,7 +8,7 @@ inline bool path_exists (const std::string& name) { return (stat (name.c_str(), &buffer) == 0); } -CLAPI void* initAug(augSettings settings, int flags) { +CLAPI void* init_aug(augSettings settings, int flags) { if(!path_exists(std::string(settings.root))) { std::cout << "error: root path is invalid." << settings.root << std::endl; @@ -18,31 +18,25 @@ CLAPI void* initAug(augSettings settings, int flags) { return aug_init(settings.root, settings.loadPath, flags); } -CLAPI void closeAug(void* aug) { - aug_close((augeas*)aug); +CLAPI void close_aug(void* aug) { + aug_close((augeas *) aug); } -// Wrapper of aug_preview -CLAPI void printPreview(augeas* aug, const char* matchPath, const char* filePath) { +bool load_file(void* aug, const char* filePath) { + int r = aug_load_file((augeas *) aug,filePath); + return r == 0; +} + + +CLAPI void print_preview(augeas* aug, const char* matchPath, const char* filePath) { if(aug == nullptr) { std::cout << "error: augeas is not initialized." << std::endl; return; } - + int r; char *s; - char *etc_hosts_fn = nullptr; - FILE *hosts_fp = nullptr; - char *hosts_txt = nullptr; - - - r = aug_load_file(aug,filePath); - - if(r != 0) { - std::cout << "Error loading file." << std::endl; - return; - } r = aug_preview(aug,matchPath,&s); @@ -53,13 +47,12 @@ CLAPI void printPreview(augeas* aug, const char* matchPath, const char* filePath std::cout << s << std::endl; - free(hosts_txt); free(s); } // Print tree of the matchPath -CLAPI void printAugTree( +CLAPI void print_tree( augeas *aug, const char* matchPath, const char* filePath @@ -74,13 +67,6 @@ CLAPI void printAugTree( FILE *out = tmpfile(); - r = aug_load_file(aug, filePath); - - if(r != 0) { - std::cout << "error: can't load file." << std::endl; - return; - } - r = aug_print(aug, out,matchPath); if(r != 0) { @@ -125,4 +111,31 @@ CLAPI void printAugTree( } +CLAPI const char* get_node(augeas* aug, char* path ) { + + const char *value; + + /* + * Return 1 if there is exactly one node matching PATH, + * 0 if there is none, and a negative value + * if there is more than one node matching PATH, + * or if PATH is not a legal path expression. + * + * The string *value must not be freed by the caller, + * and is valid as long as its node remains unchanged. + */ + + int rc = aug_get(aug, path, &value); + if (1 == rc) { + if (nullptr != value) { + return value; + } else { + return "NIL"; + } + + } else { + return "NIL"; + } +} + } diff --git a/main.h b/main.h index fca0c16..486303b 100644 --- a/main.h +++ b/main.h @@ -13,15 +13,21 @@ extern "C" { -CLAPI void* initAug (augSettings settings, int flags); +CLAPI void* init_aug (augSettings settings, int flags); -CLAPI void printPreview (augeas* aug, - const char* matchPath, - const char* filePath); +CLAPI void print_preview (augeas* aug, + const char* matchPath, + const char* filePath); + +CLAPI void print_tree (augeas* aug, + const char* matchPath, + const char* filePath); + +CLAPI const char* get_node (augeas* aug, char* path ); + + + +CLAPI void close_aug (void* aug); -CLAPI void printAugTree (augeas* aug, - const char* matchPath, - const char* filePath); -CLAPI void closeAug (void* aug); }