printPreview: Augea way of previewing config file
This commit is contained in:
parent
99763104a2
commit
7ed1c3e8bb
16
main.cpp
16
main.cpp
|
@ -1,10 +1,11 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <augeas.h>
|
#include <augeas.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
// This file is currently for testing and training using augeas with C++
|
|
||||||
|
|
||||||
|
// Testing and training using augeas with C++
|
||||||
// https://github.com/hercules-team/augeas/blob/master/tests/test-api.c
|
// https://github.com/hercules-team/augeas/blob/master/tests/test-api.c
|
||||||
|
|
||||||
static const char *abs_top_srcdir;
|
static const char *abs_top_srcdir;
|
||||||
|
@ -29,7 +30,8 @@ static void testGet() {
|
||||||
aug_close(aug);
|
aug_close(aug);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void readHostsFile() {
|
// This prints the actual file
|
||||||
|
static void printPreview(const std::string& matchPath, const std::string& filePath) {
|
||||||
struct augeas *aug;
|
struct augeas *aug;
|
||||||
int r;
|
int r;
|
||||||
char *s;
|
char *s;
|
||||||
|
@ -39,8 +41,8 @@ static void readHostsFile() {
|
||||||
|
|
||||||
aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD);
|
aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD);
|
||||||
|
|
||||||
r = aug_load_file(aug, "/etc/hosts");
|
r = aug_load_file(aug, filePath.c_str());
|
||||||
r = aug_preview(aug, "/files/etc/hosts/1", &s);
|
r = aug_preview(aug, matchPath.c_str(), &s);
|
||||||
|
|
||||||
std::cout << s << std::endl;
|
std::cout << s << std::endl;
|
||||||
|
|
||||||
|
@ -105,6 +107,10 @@ static void printAugTree(const std::string& matchPath, const std::string& filePa
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
//testGet();
|
//testGet();
|
||||||
|
|
||||||
|
printPreview("/files/etc/hosts/1", "/etc/hosts");
|
||||||
|
//printPreview("/files/etc/ssh/sshd_config/*", "/etc/ssh/sshd_config");
|
||||||
|
|
||||||
printAugTree("/files/etc/hosts/*", "/etc/hosts");
|
printAugTree("/files/etc/hosts/*", "/etc/hosts");
|
||||||
printAugTree("/files/etc/ssh/sshd_config/*", "/etc/ssh/sshd_config");
|
printAugTree("/files/etc/ssh/sshd_config/*", "/etc/ssh/sshd_config");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue