1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 7 * 8 * See the COPYRIGHT file distributed with this work for additional 9 * information regarding copyright ownership. 10 */ 11 12 #pragma once 13 14 /* 15 * A little wrapper around readline(), add_history() and free() to make using 16 * the readline code simpler. 17 */ 18 19 #if defined(HAVE_READLINE_LIBEDIT) 20 #include <editline/readline.h> 21 #elif defined(HAVE_READLINE_EDITLINE) 22 #include <editline.h> 23 #elif defined(HAVE_READLINE_READLINE) 24 /* Prevent deprecated functions being declared. */ 25 #define _FUNCTION_DEF 1 26 /* Ensure rl_message() gets prototype. */ 27 #define USE_VARARGS 1 28 #define PREFER_STDARG 1 29 #include <readline/history.h> 30 #include <readline/readline.h> 31 #endif 32 33 #if !defined(HAVE_READLINE_LIBEDIT) && !defined(HAVE_READLINE_EDITLINE) && \ 34 !defined(HAVE_READLINE_READLINE) 35 36 #include <stdio.h> 37 #include <stdlib.h> 38 39 #define RL_MAXCMD (128 * 1024) 40 41 static inline char * readline(const char * prompt)42readline(const char *prompt) { 43 char *line, *buf = malloc(RL_MAXCMD); 44 fprintf(stdout, "%s", prompt); 45 fflush(stdout); 46 line = fgets(buf, RL_MAXCMD, stdin); 47 if (line == NULL) { 48 free(buf); 49 return (NULL); 50 } 51 return (buf); 52 }; 53 54 #define add_history(line) 55 56 #endif 57