prefer snake case

This commit is contained in:
Wvader 2022-11-04 21:38:12 +00:00
parent 6992624b19
commit d2cdf81418
2 changed files with 53 additions and 34 deletions

View File

@ -8,7 +8,7 @@ inline bool path_exists (const std::string& name) {
return (stat (name.c_str(), &buffer) == 0); 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))) { if(!path_exists(std::string(settings.root))) {
std::cout << "error: root path is invalid." << settings.root << std::endl; std::cout << "error: root path is invalid." << settings.root << std::endl;
@ -18,12 +18,17 @@ CLAPI void* initAug(augSettings settings, int flags) {
return aug_init(settings.root, settings.loadPath, flags); return aug_init(settings.root, settings.loadPath, flags);
} }
CLAPI void closeAug(void* aug) { CLAPI void close_aug(void* aug) {
aug_close((augeas *) aug); aug_close((augeas *) aug);
} }
// Wrapper of aug_preview bool load_file(void* aug, const char* filePath) {
CLAPI void printPreview(augeas* aug, const char* matchPath, 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) { if(aug == nullptr) {
std::cout << "error: augeas is not initialized." << std::endl; std::cout << "error: augeas is not initialized." << std::endl;
@ -32,17 +37,6 @@ CLAPI void printPreview(augeas* aug, const char* matchPath, const char* filePath
int r; int r;
char *s; 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); 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; std::cout << s << std::endl;
free(hosts_txt);
free(s); free(s);
} }
// Print tree of the matchPath // Print tree of the matchPath
CLAPI void printAugTree( CLAPI void print_tree(
augeas *aug, augeas *aug,
const char* matchPath, const char* matchPath,
const char* filePath const char* filePath
@ -74,13 +67,6 @@ CLAPI void printAugTree(
FILE *out = tmpfile(); 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); r = aug_print(aug, out,matchPath);
if(r != 0) { 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";
}
}
} }

14
main.h
View File

@ -13,15 +13,21 @@
extern "C" { extern "C" {
CLAPI void* initAug (augSettings settings, int flags); CLAPI void* init_aug (augSettings settings, int flags);
CLAPI void printPreview (augeas* aug, CLAPI void print_preview (augeas* aug,
const char* matchPath, const char* matchPath,
const char* filePath); const char* filePath);
CLAPI void printAugTree (augeas* aug, CLAPI void print_tree (augeas* aug,
const char* matchPath, const char* matchPath,
const char* filePath); const char* filePath);
CLAPI void closeAug (void* aug); CLAPI const char* get_node (augeas* aug, char* path );
CLAPI void close_aug (void* aug);
} }