RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 12-Sep-2009 01:21:13 Branch: HEAD Handle: 2009091123211200 Modified files: rpm/tools augtool.c Log: - augtool: permit building without -lreadline. Summary: Revision Changes Path 2.12 +26 -10 rpm/tools/augtool.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/tools/augtool.c ============================================================================ $ cvs diff -u -r2.11 -r2.12 augtool.c --- rpm/tools/augtool.c 18 Jun 2009 21:31:42 -0000 2.11 +++ rpm/tools/augtool.c 11 Sep 2009 23:21:12 -0000 2.12 @@ -22,8 +22,14 @@ #include "system.h" +#if defined(WITH_READLINE) +#if defined(HAVE_READLINE_READLINE_H) #include <readline/readline.h> +#endif +#if defined(HAVE_READLINE_HISTORY_H) #include <readline/history.h> +#endif +#endif #include <rpmiotypes.h> #include <poptIO.h> @@ -55,6 +61,7 @@ return path; } +#if defined(WITH_READLINE) static char *ls_pattern(const char *path) { char *q; @@ -148,8 +155,7 @@ return NULL; } -#define HAVE_RL_COMPLETION_MATCHES /* XXX no AutoFu yet */ -#ifndef HAVE_RL_COMPLETION_MATCHES +#if !defined(HAVE_RL_COMPLETION_MATCHES) typedef char *rl_compentry_func_t(const char *, int); static char **rl_completion_matches(/*...@unused@*/ const char *text, /*...@unused@*/ rl_compentry_func_t *func) @@ -171,10 +177,11 @@ static void readline_init(void) { - rl_readline_name = "augtool"; + rl_readline_name = progname; rl_attempted_completion_function = readline_completion; rl_completion_entry_function = readline_path_generator; } +#endif static int main_loop(void) { @@ -185,14 +192,16 @@ while (1) { const char *buf; +#if defined(WITH_READLINE) if (isatty(fileno(stdin))) { line = readline("augtool> "); - } else if (getline(&line, &len, stdin) == -1) { + } else +#endif + if (getline(&line, &len, stdin) == -1) break; - } cleanstr(line, '\n'); if (line == NULL) { - printf("\n"); + fprintf(stdout, "\n"); break; } if (line[0] == '#') @@ -200,8 +209,10 @@ buf = NULL; if (rpmaugRun(NULL, line, &buf) == RPMRC_OK) { +#if defined(WITH_READLINE) if (isatty(fileno(stdin))) add_history(line); +#endif } if (buf && *buf) fprintf(stdout, "%s", buf); @@ -237,7 +248,7 @@ poptContext optCon = rpmioInit(argc, argv, optionsTable); const char ** av = NULL; int ac; - int r; + int r = -1; if (_rpmaugLoadargv != NULL) _rpmaugLoadpath = argvJoin(_rpmaugLoadargv, PATH_SEP_CHAR); @@ -245,16 +256,20 @@ _rpmaugI = rpmaugNew(_rpmaugRoot, _rpmaugLoadpath, _rpmaugFlags); if (_rpmaugI == NULL) { fprintf(stderr, "Failed to initialize Augeas\n"); - exit(EXIT_FAILURE); + goto exit; } + +#if defined(WITH_READLINE) readline_init(); +#endif av = poptGetArgs(optCon); ac = argvCount(av); if (ac > 0) { // Accept one command from the command line - const char * cmd = argvJoin((const char **)av, ' '); + const char * cmd = argvJoin(av, ' '); const char *buf; + buf = NULL; r = rpmaugRun(NULL, cmd, &buf); cmd = _free(cmd); if (buf && *buf) @@ -263,6 +278,7 @@ r = main_loop(); } +exit: if (_rpmaugLoadargv) _rpmaugLoadpath = _free(_rpmaugLoadpath); _rpmaugLoadargv = argvFree(_rpmaugLoadargv); @@ -270,5 +286,5 @@ optCon = rpmioFini(optCon); - return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + return (r == 0 ? EXIT_SUCCESS : EXIT_FAILURE); } @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org